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
In this article, learn how to enable MLflow's tracking URI and logging API, collectively known as [MLflow Tracking](https://mlflow.org/docs/latest/quickstart.html#using-the-tracking-api), to connect Azure Machine Learning as the backend of your MLflow experimentswith the [Azure Machine Learning CLI (v2)](how-to-train-cli.md). You also learn how to use [MLflow's Model Registry](https://mlflow.org/docs/latest/model-registry.html) capabilities with Azure Machine Learning.
20
+
In this article, learn how to enable MLflow's tracking URI and logging API, collectively known as [MLflow Tracking](https://mlflow.org/docs/latest/quickstart.html#using-the-tracking-api), to connect Azure Machine Learning as the backend of your MLflow experiments. You can accomplish this connection with either the MLflow Python API or the [Azure Machine Learning CLI (v2)](how-to-train-cli.md). You also learn how to use [MLflow's Model Registry](https://mlflow.org/docs/latest/model-registry.html) capabilities with Azure Machine Learning.
21
21
22
22
[MLflow](https://www.mlflow.org) is an open-source library for managing the lifecycle of your machine learning experiments. MLFlow Tracking is a component of MLflow that logs and tracks your training run metrics and model artifacts, no matter your experiment's environment--locally on your computer, on a remote compute target, a virtual machine, or an [Azure Databricks cluster](how-to-use-mlflow-azure-databricks.md).
23
23
24
24
See [MLflow and Azure Machine Learning](concept-mlflow.md) for all supported MLflow and Azure Machine Learning functionality including MLflow Project support (preview) and model deployment.
25
25
26
+
26
27
> [!TIP]
27
28
> The information in this document is primarily for data scientists and developers who want to monitor the model training process. If you are an administrator interested in monitoring resource usage and events from Azure Machine Learning, such as quotas, completed training runs, or completed model deployments, see [Monitoring Azure Machine Learning](monitor-azure-machine-learning.md).
28
29
29
-
> [!NOTE]
30
+
> [!NOTE]
30
31
> You can use the [MLflow Skinny client](https://github.com/mlflow/mlflow/blob/master/README_SKINNY.rst) which is a lightweight MLflow package without SQL storage, server, UI, or data science dependencies. This is recommended for users who primarily need the tracking and logging capabilities without importing the full suite of MLflow features including deployments.
31
32
32
33
## Prerequisites
33
34
34
-
* Install the `azureml-mlflow` package.
35
-
* This package automatically brings in `azureml-core` of the [The Azure Machine Learning Python SDK](/python/api/overview/azure/ml/install), which provides the connectivity for MLflow to access your workspace.
36
-
37
35
*[Create an Azure Machine Learning Workspace](how-to-manage-workspace.md).
38
36
* See which [access permissions you need to perform your MLflow operations with your workspace](how-to-assign-roles.md#mlflow-operations).
39
37
40
-
* Install and [set up CLI (v2)](how-to-configure-cli.md#prerequisites).
38
+
* Install and [set up CLI (v2)](how-to-configure-cli.md#prerequisites) and make sure you install the ml extension
41
39
42
40
## Track runs from your local machine
43
41
44
42
MLflow Tracking with Azure Machine Learning lets you store the logged metrics and artifacts runs that were executed on your local machine into your Azure Machine Learning workspace.
45
43
46
-
### Setting up tracking environment to track local run
44
+
### Set up tracking environment
47
45
48
-
First, you need to point your local machine to the Azure Machine Learning MLFlow Tracking URI.
46
+
To track a local run, you need to point your local machine to the Azure Machine Learning MLFlow Tracking URI.
49
47
50
-
This can be done in a couple ways. You can import the `mlflow` and [`subprocess`](https://docs.python.org/3/library/subprocess.html) classes to access MLflow's tracking URI.
48
+
>[!NOTE]
49
+
>The tracking URI is valid up to an hour or less. If you restart your script after some idle time, use the get_mlflow_tracking_uri API to get a new URI.
51
50
52
-
The following code, uses the subprocess class in Python to run the Azure Machine Learning CLI (v2) command to retrieve the unique MLFLow tracking URI associated with your workspace, and [`set_tracking_uri()`](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_tracking_uri) points the MLflow tracking URI to that URI.
51
+
# [MLflow](#tab/mlflow)
52
+
53
+
The following code uses `mlflow` and the [`subprocess`](https://docs.python.org/3/library/subprocess.html) classes in Python to run the Azure Machine Learning CLI (v2) command to retrieve the unique MLFLow tracking URI associated with your workspace. Then the method [`set_tracking_uri()`](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_tracking_uri) points the MLflow tracking URI to that URI.
Another option is to set one of the MLflow environment variables [MLFLOW_TRACKING_URI](https://mlflow.org/docs/latest/tracking.html#logging-to-a-tracking-server) directly in your terminal.
64
67
65
-
```Bash
68
+
```Azure CLI
66
69
# Configure MLflow to communicate with a Azure Machine Learning-hosted tracking server
70
+
67
71
export MLFLOW_TRACKING_URI=$(az ml workspace show --query mlflow_tracking_uri | sed 's/"//g')
68
72
```
73
+
---
69
74
70
-
>[!NOTE]
71
-
>The tracking URI is valid up to an hour or less. If you restart your script after some idle time, use the get_mlflow_tracking_uri API to get a new URI.
72
75
73
-
Next, you set the experiment name.
76
+
### Set experiment name
74
77
75
-
All MLflow runs are logged to the active experiment, which can be set using any of the following ways:
78
+
All MLflow runs are logged to the active experiment, which can be set using MLflow or the Azure CLI.
76
79
77
-
* You can use the [mlflow.set_experiment()](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_experiment) command.
80
+
# [MLflow](#tab/mlflow)
81
+
82
+
With MLflow you can use the [`mlflow.set_experiment()`](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_experiment) command.
78
83
79
84
```Python
80
85
experiment_name = 'experiment_with_mlflow'
81
86
mlflow.set_experiment(experiment_name)
82
87
```
83
88
84
-
* You can use the `experiment_id` parameter in the [mlflow.start_run()](https://www.mlflow.org/docs/latest/python_api/mlflow.html#mlflow.start_run) command.
89
+
Another option is to use the `experiment_id` parameter in the [mlflow.start_run()](https://www.mlflow.org/docs/latest/python_api/mlflow.html#mlflow.start_run) command.
85
90
86
91
```Python
87
92
experiment_name = 'experiment_with_mlflow'
88
93
with mlflow.start_run(experiment_id=experiment_name) as mlflow_run:
89
94
mlflow.log_param("hello_param", "world")
90
95
```
96
+
# [Azure CLI](#tab/azure-cli)
91
97
92
-
* Another option is to set one of the MLflow environment variables [MLFLOW_EXPERIMENT_NAMEorMLFLOW_EXPERIMENT_ID](https://mlflow.org/docs/latest/cli.html#cmdoption-mlflow-run-arg-uri).
98
+
With the Azure CLI, set one of the MLflow environment variables [MLFLOW_EXPERIMENT_NAME or MLFLOW_EXPERIMENT_ID](https://mlflow.org/docs/latest/cli.html#cmdoption-mlflow-run-arg-uri) with the experiment name.
93
99
94
-
```Bash
100
+
```Azure CLI
95
101
# Configure MLflow to communicate with a Azure Machine Learning-hosted tracking server
After you set the MLflow experiment name, you can start your training run with `start_run()`. Then use `log_metric()` to activate the MLflow logging API and begin logging your training run metrics.
100
109
@@ -113,7 +122,7 @@ with mlflow.start_run() as mlflow_run:
113
122
114
123
Remote runs (jobs) let you train your models on more powerful computes, such as GPU enabled virtual machines, or Machine Learning Compute clusters. See [Use compute targets for model training](how-to-set-up-training-targets.md) to learn about different compute options.
115
124
116
-
MLflow Tracking with Azure Machine Learning lets you store the logged metrics and artifacts from your remote runs into your Azure Machine Learning workspace. Any run with MLflow Tracking code in it will have metrics logged automatically to the workspace.
125
+
MLflow Tracking with Azure Machine Learning lets you store the logged metrics and artifacts from your remote runs into your Azure Machine Learning workspace. Any run with MLflow Tracking code in it logs metrics automatically to the workspace.
117
126
118
127
First, you should create a `src` subdirectory and create a file with your training code in a `train.py` file in the `src` subdirectory. All your training code will go into the `src` subdirectory, including `train.py`.
119
128
@@ -142,7 +151,7 @@ if __name__ == "__main__":
142
151
main()
143
152
```
144
153
145
-
Use the [Azure Machine Learning CLI (v2)](how-to-train-cli.md) to submit a run. When using the Azure Machine Learning CLI (v2), the MLflow tracking URIand experiment name isset automatically and directs the logging from MLflow to your Workspace. Learn more about [logging Azure Machine Learning CLI (v2) experiments with MLflow](how-to-train-cli.md#model-tracking-with-mlflow)
154
+
Use the [Azure Machine Learning CLI (v2)](how-to-train-cli.md) to submit a run. When using the Azure Machine Learning CLI (v2), the MLflow tracking URI and experiment name are set automatically and directs the logging from MLflow to your workspace. Learn more about [logging Azure Machine Learning CLI (v2) experiments with MLflow](how-to-train-cli.md#model-tracking-with-mlflow)
146
155
147
156
Create a YAML file with your job definition in a `job.yml` file. This file should be created outside the `src` directory. Copy this code into the file:
148
157
@@ -162,7 +171,7 @@ compute: azureml:MyCluster
162
171
163
172
Open your terminal and use the following to submit the job.
164
173
165
-
```Bash
174
+
```Azure CLI
166
175
az ml job create -f job.yml --web
167
176
```
168
177
@@ -172,7 +181,7 @@ The metrics and artifacts from MLflow logging are tracked in your workspace. To
172
181
173
182
Retrieve run metric using MLFlow [get_run()](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.get_run).
174
183
175
-
```python
184
+
```Python
176
185
from mlflow.tracking import MlflowClient
177
186
# Use MlFlow to retrieve the run that was just completed
178
187
client = MlflowClient()
@@ -189,21 +198,22 @@ print(metrics,tags,params)
189
198
### Retrieve artifacts with MLFLow
190
199
191
200
To view the artifacts of a run, you can use [MlFlowClient.list_artifacts()](https://mlflow.org/docs/latest/python_api/mlflow.tracking.html#mlflow.tracking.MlflowClient.list_artifacts)
192
-
```python
201
+
202
+
```Python
193
203
client.list_artifacts(run_id)
194
204
```
195
205
196
206
To download an artifact to the current directory, you can use [MLFlowClient.download_artifacts()](https://www.mlflow.org/docs/latest/python_api/mlflow.tracking.html#mlflow.tracking.MlflowClient.download_artifacts)
0 commit comments