Skip to content

Commit 3ee0043

Browse files
committed
edit
1 parent 7b4be53 commit 3ee0043

File tree

1 file changed

+88
-90
lines changed

1 file changed

+88
-90
lines changed

articles/machine-learning/how-to-use-mlflow-cli-runs.md

Lines changed: 88 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Azure Machine Learning workspaces are MLflow-compatible. This compatibility mean
5353

5454
## Configure the experiment
5555

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.
5757

5858
# [Notebooks](#tab/interactive)
5959

@@ -76,137 +76,137 @@ To submit jobs by using the Azure Machine Learning CLI or SDK, set the experimen
7676

7777
Azure Machine Learning tracks any training job in what MLflow calls a run. Use runs to capture all the processing that your job performs.
7878

79-
# [Working interactively](#tab/interactive)
79+
# [Notebooks](#tab/interactive)
8080

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.
8282

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()`.
8484

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()`.
8686

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:
8888

89-
```python
90-
mlflow.start_run()
91-
92-
# Your code
93-
94-
mlflow.end_run()
95-
```
89+
```python
90+
mlflow.start_run()
9691

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+
```
9896

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+
```
103103

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 and help you 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.
105105

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+
```
110110

111-
# [Working with jobs](#tab/jobs)
111+
# [Jobs](#tab/jobs)
112112

113113
Azure Machine Learning jobs allow you to submit long-running training or inference routines as isolated and reproducible executions.
114114

115115
### Create a training routine
116116

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 file with 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:
118118

119119
:::code language="python" source="~/azureml-examples-main/cli/jobs/basics/src/hello-mlflow.py" highlight="9-10,12":::
120120

121-
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.
122122

123123
### Add tracking to your routine
124124

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).
126126

127127
### Ensure your job's environment has MLflow installed
128128

129-
All Azure Machine Learning environments already have MLflow installed for 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:
130130

131-
1. Create a `conda.yaml` file with the dependencies you need:
131+
:::code language="yaml" source="~/azureml-examples-main/sdk/python/using-mlflow/deploy/environment/conda.yaml" highlight="7-8" range="1-12":::
132132

133-
:::code language="yaml" source="~/azureml-examples-main/sdk/python/using-mlflow/deploy/environment/conda.yaml" highlight="7-8" range="1-12":::
134-
135-
1. Reference the environment in the job you're using.
133+
Reference the environment in your job.
136134

137-
### Configure your job's name
135+
### Configure your job name
138136

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.
140138

141139
1. Use the `display_name` property to configure the job.
142140

143-
# [Azure CLI](#tab/cli)
144-
145-
To submit the job, create a YAML file with your job definition in a `job.yml` file. This file should be created outside the `src` directory.
141+
# [Azure CLI](#tab/cli)
146142

147-
:::code language="yaml" source="~/azureml-examples-main/cli/jobs/basics/hello-world-org.yml" highlight="7" range="1-9":::
143+
Create a YAML file with your job definition in a *job.yml* file outside the *src* directory.
148144

149-
# [Python SDK](#tab/python)
145+
:::code language="yaml" source="~/azureml-examples-main/cli/jobs/basics/hello-world-org.yml" highlight="7" range="1-9":::
150146

151-
```python
152-
from azure.ai.ml import command, Environment
147+
# [Python SDK](#tab/python)
153148

154-
command_job = command(
155-
code="src",
156-
command="echo "hello world",
157-
environment=Environment(image="library/python:latest"),
158-
compute="cpu-cluster",
159-
display_name="hello-world-example"
160-
)
161-
```
149+
Create the command job as follows:
162150

163-
2. Ensure you're not using `mlflow.start_run(run_name="")` inside your training routine.
151+
```python
152+
from azure.ai.ml import command, Environment
153+
154+
command_job = command(
155+
code="src",
156+
command="echo "hello world",
157+
environment=Environment(image="library/python:latest"),
158+
compute="cpu-cluster",
159+
display_name="hello-world-example"
160+
)
161+
```
164162

165163
### Submit the job
166164

167-
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)
168177

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 with all 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-
```
186178

187-
2. Configure workspace details and get a handle to the workspace:
179+
180+
1. Import the required libraries:
188181

189-
```python
190-
subscription_id = "<subscription>"
191-
resource_group = "<resource-group>"
192-
workspace = "<workspace>"
193-
194-
ml_client = MLClient(DefaultAzureCredential(), subscription_id, resource_group, workspace)
195-
```
182+
```python
183+
from azure.ai.ml import MLClient
184+
from azure.identity import DefaultAzureCredential
185+
```
186+
187+
1. Configure workspace details and get a handle to the workspace:
188+
189+
```python
190+
subscription_id = "<subscription>"
191+
resource_group = "<resource-group>"
192+
workspace = "<workspace>"
193+
194+
ml_client = MLClient(DefaultAzureCredential(), subscription_id, resource_group, workspace)
195+
```
196196

197197
1. Submit the job
198198

199199
# [Azure CLI](#tab/cli)
200200

201-
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 and use 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 and enter the following code:
202202

203203
```azurecli
204204
az ml job create -f job.yml --web
205205
```
206206

207207
# [Python SDK](#tab/python)
208208

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).
210210

211211
```python
212212
returned_job = ml_client.jobs.create_or_update(command_job)
@@ -219,7 +219,7 @@ Use the Azure Machine Learning jobs parameter `display_name` to configure the na
219219

220220
## Enable MLflow autologging
221221

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.
223223

224224
To enable [automatic logging](https://mlflow.org/docs/latest/tracking.html#automatic-logging), insert the following code before your training code:
225225

@@ -229,19 +229,17 @@ mlflow.autolog()
229229

230230
## View metrics and artifacts in your workspace
231231

232-
The metrics and artifacts from MLflow logging are tracked in your workspace. You can view and access them in the studio anytime or 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.
233233

234234
To view metrics and artifacts in the studio:
235235

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.
241239

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":::
243241

244-
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).
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).
245243

246244
```python
247245
import mlflow
@@ -256,15 +254,15 @@ print(metrics, params, tags)
256254
```
257255

258256
> [!TIP]
259-
> For metrics, the previous example code will only return the 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).
260258
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).
262260

263261
```python
264262
mlflow.artifacts.download_artifacts(run_id="<RUN_ID>", artifact_path="helloworld.txt")
265263
```
266264

267-
For more information about how to __retrieve or compare__ 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).
268266

269267
## Related content
270268

0 commit comments

Comments
 (0)