You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/machine-learning/how-to-use-mlflow-cli-runs.md
+88-90Lines changed: 88 additions & 90 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ Azure Machine Learning workspaces are MLflow-compatible. This compatibility mean
53
53
54
54
## Configure the experiment
55
55
56
-
MLflow organizes information in experiments and runs. Runs are called *jobs* in Azure Machine Learning. By default, runs are logged to an experiment named **Default** that is automatically created for you. You can configure the experiment to track.
56
+
MLflow organizes information in experiments and runs. Runs are called *jobs* in Azure Machine Learning. By default, runs are logged to an experiment named **Default** that's automatically created for you. You can configure the experiment to track.
57
57
58
58
# [Notebooks](#tab/interactive)
59
59
@@ -76,137 +76,137 @@ To submit jobs by using the Azure Machine Learning CLI or SDK, set the experimen
76
76
77
77
Azure Machine Learning tracks any training job in what MLflow calls a run. Use runs to capture all the processing that your job performs.
78
78
79
-
# [Working interactively](#tab/interactive)
79
+
# [Notebooks](#tab/interactive)
80
80
81
-
When you're working interactively, MLflow starts tracking your training routine as soon as you try to log information that requires an active run. For instance, MLflow tracking starts when you log a metric, a parameter, or start a training cycle, and Mlflow's autologging functionality is enabled. However, it's usually helpful to start the run explicitly, specially if you want to capture the total time for your experiment in the __Duration__ field. To start the run explicitly, use `mlflow.start_run()`.
81
+
When you work interactively, MLflow starts tracking your training routine as soon as you try to log information that requires an active run. For instance, if Mlflow's autologging functionality is enabled, MLflow tracking starts when you log a metric or parameter, or start a training cycle.
82
82
83
-
Whether you start the run manually or not, you eventually need to stop the run, so that MLflow knows that your experiment run is done and can mark the run's status as __Completed__. To stop a run, use `mlflow.end_run()`.
83
+
However, it's usually helpful to start the run explicitly, especially if you want to capture the total time for your experiment in the **Duration** field. To start the run explicitly, use `mlflow.start_run()`.
84
84
85
-
We strongly recommend starting runs manually, so that you don't forget to end them when you're working in notebooks.
85
+
Whether you start the run manually or not, you eventually need to stop the run, so that MLflow knows that your experiment run is done and can mark the run's status as **Completed**. To stop a run, use `mlflow.end_run()`.
86
86
87
-
- To start a run manually and end it when you're done working in the notebook:
87
+
The following code starts a run manually and ends it at the end of the notebook:
88
88
89
-
```python
90
-
mlflow.start_run()
91
-
92
-
# Your code
93
-
94
-
mlflow.end_run()
95
-
```
89
+
```python
90
+
mlflow.start_run()
96
91
97
-
- It's usually helpful to use the context manager paradigm to help you remember to end the run:
92
+
# Your code
93
+
94
+
mlflow.end_run()
95
+
```
98
96
99
-
```python
100
-
with mlflow.start_run() as run:
101
-
# Your code
102
-
```
97
+
It's best to start runs manually so you don't forget to end them. You can use the context manager paradigm to help you remember to end the run.
98
+
99
+
```python
100
+
with mlflow.start_run() as run:
101
+
# Your code
102
+
```
103
103
104
-
-When you start a new run with`mlflow.start_run()`, it can be useful to specify the `run_name` parameter, which later translates to the name of the run in the Azure Machine Learning user interfaceandhelpyou to identify the run quicker:
104
+
When you start a new run with `mlflow.start_run()`, it can be useful to specify the `run_name` parameter, which later translates to the name of the run in the Azure Machine Learning user interface. This practice helps you identify the run more quickly.
105
105
106
-
```python
107
-
with mlflow.start_run(run_name="hello-world-example") as run:
108
-
# Your code
109
-
```
106
+
```python
107
+
with mlflow.start_run(run_name="hello-world-example") as run:
108
+
# Your code
109
+
```
110
110
111
-
# [Working with jobs](#tab/jobs)
111
+
# [Jobs](#tab/jobs)
112
112
113
113
Azure Machine Learning jobs allow you to submit long-running training or inference routines as isolated and reproducible executions.
114
114
115
115
### Create a training routine
116
116
117
-
When working with jobs, you typically place all your training logic as files inside a folder, for instance `src`. One of these files is a Python filewith your training code entry point. The following example shows a `hello_world.py` example:
117
+
When you work with jobs, you typically place all your training logic as files inside a folder, such as *src*. One of the files is a Python file with your training code entry point. The following example shows a *hello_world.py* example:
The previous code example doesn't uses `mlflow.start_run()` but if used, MLflow reuses the current active run. Therefore, you don't need to remove the line that uses `mlflow.start_run()`if you're migrating code to Azure Machine Learning.
121
+
The previous code example doesn't use`mlflow.start_run()` but if used, MLflow reuses the current active run. Therefore, you don't need to remove the `mlflow.start_run()`line if you migrate code to Azure Machine Learning.
122
122
123
123
### Add tracking to your routine
124
124
125
-
Use the MLflow SDK to track any metric, parameter, artifacts, or models. For examples about how to log these, see [Log metrics, parameters, and files with MLflow](how-to-log-view-metrics.md).
125
+
Use the MLflow SDK to track any metric, parameter, artifacts, or models. For examples, see [Log metrics, parameters, and files with MLflow](how-to-log-view-metrics.md).
126
126
127
127
### Ensure your job's environment has MLflow installed
128
128
129
-
All Azure Machine Learning environments already have MLflow installedfor you, so no action is required if you're using a curated environment. However, if you want to use a custom environment:
129
+
All Azure Machine Learning curated environments already have MLflow installed. However, if you use a custom environment, create a *conda.yaml* file that has the dependencies you need, as follows:
130
130
131
-
1. Create a `conda.yaml`filewith the dependencies you need:
1. Reference the environment in the job you're using.
133
+
Reference the environment in your job.
136
134
137
-
### Configure your job's name
135
+
### Configure your job name
138
136
139
-
Use the Azure Machine Learning jobs parameter `display_name` to configure the name of the run.
137
+
Use the Azure Machine Learning jobs parameter `display_name` to configure the name of the run. Make sure not to use `mlflow.start_run(run_name="")` inside your training routine.
140
138
141
139
1. Use the `display_name` property to configure the job.
142
140
143
-
# [Azure CLI](#tab/cli)
144
-
145
-
To submit the job, create a YAMLfilewith your job definition in a `job.yml`file. This file should be created outside the `src` directory.
1. First, connect to the Azure Machine Learning workspace where you'll work.
165
+
The workspace is the top-level resource for Azure Machine Learning, providing a centralized place to work with the artifacts you create. Jobs that use MLflow and run on Azure Machine Learning automatically log any tracking information to the workspace. In this section, you connect to the workspace and do deployment tasks.
166
+
167
+
1. Connect to your Azure Machine Learning workspace.
168
+
169
+
# [Azure CLI](#tab/cli)
170
+
171
+
```azurecli
172
+
az account set --subscription <subscription>
173
+
az configure --defaults workspace=<workspace> group=<resource-group> location=<location>
174
+
```
175
+
176
+
# [Python SDK](#tab/python)
168
177
169
-
# [Azure CLI](#tab/cli)
170
-
171
-
```azurecli
172
-
az account set--subscription <subscription>
173
-
az configure --defaults workspace=<workspace> group=<resource-group> location=<location>
174
-
```
175
-
176
-
# [Python SDK](#tab/python)
177
-
178
-
The workspace is the top-level resource for Azure Machine Learning, providing a centralized place to work withall the artifacts you create when you use Azure Machine Learning. In this section, you connect to the workspace where you'll perform deployment tasks.
179
-
180
-
1. Import the required libraries:
181
-
182
-
```python
183
-
from azure.ai.ml import MLClient
184
-
from azure.identity import DefaultAzureCredential
185
-
```
186
178
187
-
2. Configure workspace details and get a handle to the workspace:
Use the Azure Machine Learning CLI[to submit your job](how-to-train-model.md). Jobs that use MLflow and run on Azure Machine Learning automatically log any tracking information to the workspace. Open your terminal anduse the following code to submit the job.
201
+
Use the Azure Machine Learning CLI to [submit your job](how-to-train-model.md). Open your terminal andenter the following code:
202
202
203
203
```azurecli
204
204
az ml job create -f job.yml --web
205
205
```
206
206
207
207
# [Python SDK](#tab/python)
208
208
209
-
Use the Python SDK[to submit your job](how-to-train-model.md). Jobs that use MLflow and run on Azure Machine Learning automatically log any tracking information to the workspace.
209
+
Use the Python SDK to [submit your job](how-to-train-model.md).
@@ -219,7 +219,7 @@ Use the Azure Machine Learning jobs parameter `display_name` to configure the na
219
219
220
220
## Enable MLflow autologging
221
221
222
-
You can [log metrics, parameters, and files with MLflow](how-to-log-view-metrics.md) manually. However, you can also rely on MLflow's automatic logging capability. Each machine learning framework supported by MLflow decides what to track automatically for you.
222
+
You can [log metrics, parameters, and files with MLflow](how-to-log-view-metrics.md) manually, and you can also rely on MLflow's automatic logging capability. Each machine learning framework supported by MLflow determines what to track automatically for you.
223
223
224
224
To enable [automatic logging](https://mlflow.org/docs/latest/tracking.html#automatic-logging), insert the following code before your training code:
225
225
@@ -229,19 +229,17 @@ mlflow.autolog()
229
229
230
230
## View metrics and artifacts in your workspace
231
231
232
-
The metrics and artifacts from MLflow logging are tracked in your workspace. You can view and access them inthe studio anytimeor access them programatically via the MLflow SDK.
232
+
The metrics and artifacts from MLflow logging are tracked in your workspace. You can view and access them in Azure Machine Learning studio or access them programatically via the MLflow SDK.
233
233
234
234
To view metrics and artifacts in the studio:
235
235
236
-
1. Go to [Azure Machine Learning studio](https://ml.azure.com).
237
-
1. Navigate to your workspace.
238
-
1. Find the experiment by name in your workspace.
239
-
1. Select the logged metrics to render charts on the right side. You can customize the charts by applying smoothing, changing the color, or plotting multiple metrics on a single graph. You can also resize and rearrange the layout as you wish.
240
-
1. Once you've created your desired view, save it for future use and share it with your teammates, using a direct link.
236
+
1. On the **Jobs** page in your workspace, find the experiment by name.
237
+
1. Select logged metrics to render charts on the right side. You can customize the charts by applying smoothing, changing the color, or plotting multiple metrics on a single graph. You can also resize and rearrange the layout.
238
+
1. Once you create your desired view, save it for future use and share it with your teammates by using a direct link.
241
239
242
-
:::image type="content"source="media/how-to-log-view-metrics/metrics.png" alt-text="Screenshot of the metrics view."lightbox="media/how-to-log-view-metrics/metrics.png":::
240
+
:::image type="content" source="media/how-to-log-view-metrics/metrics.png" alt-text="Screenshot of the metrics view." lightbox="media/how-to-log-view-metrics/metrics.png":::
243
241
244
-
To __accessorquery__ metrics, parameters, and artifacts programatically via the MLflow SDK, use [mlflow.get_run()](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.get_run).
242
+
To access or query metrics, parameters, and artifacts programatically via the MLflow SDK, use [mlflow.get_run()](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.get_run).
>For metrics, the previous example code will only returnthe last value of a given metric. If you want to retrieve all the values of a given metric, use the `mlflow.get_metric_history` method. For more information on retrieving values of a metric, see [Getting params and metrics from a run](how-to-track-experiments-mlflow.md#get-params-and-metrics-from-a-run).
257
+
> The preceding example returns only the last value of a given metric. To retrieve all the values of a given metric, use the `mlflow.get_metric_history` method. For more information on retrieving metrics values, see [Get params and metrics from a run](how-to-track-experiments-mlflow.md#get-params-and-metrics-from-a-run).
260
258
261
-
To __download__ artifacts you've logged, such as files and models, use [mlflow.artifacts.download_artifacts()](https://www.mlflow.org/docs/latest/python_api/mlflow.artifacts.html#mlflow.artifacts.download_artifacts).
259
+
To download artifacts you logged, such as files and models, use [mlflow.artifacts.download_artifacts()](https://www.mlflow.org/docs/latest/python_api/mlflow.artifacts.html#mlflow.artifacts.download_artifacts).
For more information about how to __retrieveorcompare__ information from experiments and runs in Azure Machine Learning, using MLflow, see [Query & compare experiments and runs with MLflow](how-to-track-experiments-mlflow.md).
265
+
For more information about how to retrieve or compare information from experiments and runs in Azure Machine Learning by using MLflow, see [Query & compare experiments and runs with MLflow](how-to-track-experiments-mlflow.md).
0 commit comments