Skip to content

Commit 669d894

Browse files
authored
Merge pull request #220928 from santiagxf/santiagxf-patch-1
Update tracking instructions
2 parents e353585 + 48bc32a commit 669d894

File tree

1 file changed

+113
-78
lines changed

1 file changed

+113
-78
lines changed

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

Lines changed: 113 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -51,115 +51,150 @@ Tracking using MLflow with Azure Machine Learning lets you store the logged metr
5151

5252
### Set up tracking environment
5353

54-
To track a run that is not running on Azure Machine Learning compute (from now on referred to as *"local compute"*), you need to point your local compute to the Azure Machine Learning MLflow Tracking URI.
55-
54+
To track a run that is not running on Azure Machine Learning compute, you need to point MLflow to the Azure Machine Learning MLflow Tracking URI.
5655

5756
> [!NOTE]
5857
> When running on Azure Compute (Azure Notebooks, Jupyter Notebooks hosted on Azure Compute Instances or Compute Clusters) you don't have to configure the tracking URI. It's automatically configured for you.
59-
60-
# [Using the Azure ML SDK v2](#tab/azuremlsdk)
61-
62-
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
63-
64-
You can get the Azure ML MLflow tracking URI using the [Azure Machine Learning SDK v2 for Python](concept-v2.md). Ensure you have the library `azure-ai-ml` installed in the cluster you are using. The following sample gets 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.
65-
66-
1. Using the workspace configuration file:
67-
68-
```Python
69-
from azure.ai.ml import MLClient
70-
from azure.identity import DefaultAzureCredential
71-
import mlflow
7258
73-
ml_client = MLClient.from_config(credential=DefaultAzureCredential())
74-
azureml_mlflow_uri = ml_client.workspaces.get(ml_client.workspace_name).mlflow_tracking_uri
75-
mlflow.set_tracking_uri(azureml_mlflow_uri)
59+
1. Getting the Azure Machine Learning Tracking URI:
60+
61+
# [Python](#tab/python)
62+
63+
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
64+
65+
You can get the Azure ML MLflow tracking URI using the [Azure Machine Learning SDK v2 for Python](concept-v2.md). Ensure you have the library `azure-ai-ml` installed in the compute you are using. The following sample gets the unique MLFLow tracking URI associated with your workspace.
66+
67+
1. Login into your workspace using the `MLClient`. The easier way to do that is by using the workspace config file:
68+
69+
```python
70+
from azure.ai.ml import MLClient
71+
from azure.identity import DefaultAzureCredential
72+
73+
ml_client = MLClient.from_config(credential=DefaultAzureCredential())
74+
```
75+
76+
> [!TIP]
77+
> You can download the workspace configuration file by:
78+
> 1. Navigate to [Azure ML studio](https://ml.azure.com)
79+
> 2. Click on the uper-right corner of the page -> Download config file.
80+
> 3. Save the file `config.json` in the same directory where you are working on.
81+
82+
1. Alternatively, you can use the subscription ID, resource group name and workspace name to get it:
83+
84+
```python
85+
from azure.ai.ml import MLClient
86+
from azure.identity import DefaultAzureCredential
87+
88+
#Enter details of your AzureML workspace
89+
subscription_id = '<SUBSCRIPTION_ID>'
90+
resource_group = '<RESOURCE_GROUP>'
91+
workspace_name = '<AML_WORKSPACE_NAME>'
92+
93+
ml_client = MLClient(credential=DefaultAzureCredential(),
94+
subscription_id=subscription_id,
95+
resource_group_name=resource_group)
96+
```
97+
98+
> [!IMPORTANT]
99+
> `DefaultAzureCredential` will try to pull the credentials from the available context. If you want to specify credentials in a different way, for instance using the web browser in an interactive way, you can use `InteractiveBrowserCredential` or any other method available in `azure.identity` package.
100+
101+
1. Get the Azure Machine Learning Tracking URI:
102+
103+
```python
104+
mlflow_tracking_uri = ml_client.workspaces.get(ml_client.workspace_name).mlflow_tracking_uri
105+
```
106+
107+
# [Azure CLI](#tab/cli)
108+
109+
[!INCLUDE [cli v2](../../includes/machine-learning-cli-v2.md)]
110+
111+
You can use the Azure ML CLI v2 to get the MLflow tracking URI.
112+
113+
1. Login and configure your workspace:
114+
115+
```bash
116+
az account set --subscription <subscription>
117+
az configure --defaults workspace=<workspace> group=<resource-group> location=<location>
118+
```
119+
120+
1. You can get the tracking URI using the `az ml workspace` command:
121+
122+
```bash
123+
az ml workspace show --query mlflow_tracking_uri
76124
```
77125

78-
> [!TIP]
79-
> You can download the workspace configuration file by:
80-
> 1. Navigate to [Azure ML studio](https://ml.azure.com)
81-
> 2. Click on the uper-right corner of the page -> Download config file.
82-
> 3. Save the file `config.json` in the same directory where you are working on.
83-
84-
1. Using the subscription ID, resource group name and workspace name:
85-
86-
```Python
87-
from azure.ai.ml import MLClient
88-
from azure.identity import DefaultAzureCredential
89-
import mlflow
126+
# [Studio](#tab/studio)
127+
128+
Use the Azure Machine Learning portal to get the tracking URI:
129+
130+
1. Open the [Azure Machine Learning studio portal](https://ml.azure.com) and log in using your credentials.
131+
1. In the upper right corner, click on the name of your workspace to show the __Directory + Subscription + Workspace__ blade.
132+
1. Click on __View all properties in Azure Portal__.
133+
1. On the __Essentials__ section, you will find the property __MLflow tracking URI__.
90134

91-
#Enter details of your AzureML workspace
135+
136+
# [Manually](#tab/manual)
137+
138+
The Azure Machine Learning Tracking URI can be constructed using the subscription ID, region of where the resource is deployed, resource group name and workspace name. The following code sample shows how:
139+
140+
> [!WARNING]
141+
> If you are working in a private link-enabled workspace, the MLflow endpoint will also use a private link to communicate with Azure Machine Learning. As a consequence, the tracking URI will look different as proposed here. On those cases, you need to get the tracking URI using the Azure ML SDK or CLI v2.
142+
143+
```python
144+
region = "<LOCATION>"
92145
subscription_id = '<SUBSCRIPTION_ID>'
93146
resource_group = '<RESOURCE_GROUP>'
94-
workspace_name = '<AZUREML_WORKSPACE_NAME>'
95-
96-
ml_client = MLClient(credential=DefaultAzureCredential(),
97-
subscription_id=subscription_id,
98-
resource_group_name=resource_group)
99-
100-
azureml_mlflow_uri = ml_client.workspaces.get(workspace_name).mlflow_tracking_uri
101-
mlflow.set_tracking_uri(azureml_mlflow_uri)
147+
workspace_name = '<AML_WORKSPACE_NAME>'
148+
149+
mlflow_tracking_uri = f"azureml://{region}.api.azureml.ms/mlflow/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}"
102150
```
103151

104-
> [!IMPORTANT]
105-
> `DefaultAzureCredential` will try to pull the credentials from the available context. If you want to specify credentials in a different way, for instance using the web browser in an interactive way, you can use `InteractiveBrowserCredential` or any other method available in `azure.identity` package.
106-
107-
# [Using an environment variable](#tab/environ)
108-
109-
[!INCLUDE [cli v2](../../includes/machine-learning-cli-v2.md)]
110-
111-
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.
152+
1. Configuring the tracking URI:
112153

113-
```Azure CLI
114-
export MLFLOW_TRACKING_URI=$(az ml workspace show --query mlflow_tracking_uri | sed 's/"//g')
115-
```
116-
117-
>[!IMPORTANT]
118-
> Make sure you are logged in to your Azure account on your local machine, otherwise the tracking URI returns an empty string. If you are using any Azure ML compute the tracking environment and experiment name is already configured.
119-
120-
# [Building the MLflow tracking URI](#tab/build)
121-
122-
The Azure Machine Learning Tracking URI can be constructed using the subscription ID, region of where the resource is deployed, resource group name and workspace name. The following code sample shows how:
123-
124-
125-
```python
126-
import mlflow
154+
# [Using MLflow SDK](#tab/mlflow)
155+
156+
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.
157+
158+
```python
159+
import mlflow
160+
161+
mlflow.set_tracking_uri(mlflow_tracking_uri)
162+
```
127163

128-
region = ""
129-
subscription_id = ""
130-
resource_group = ""
131-
workspace_name = ""
164+
# [Using an environment variable](#tab/environ)
165+
166+
You can set the MLflow environment variables [MLFLOW_TRACKING_URI](https://mlflow.org/docs/latest/tracking.html#logging-to-a-tracking-server) in your compute to make any interaction with MLflow in that compute to point by default to Azure Machine Learning.
167+
168+
```bash
169+
MLFLOW_TRACKING_URI=$(az ml workspace show --query mlflow_tracking_uri | sed 's/"//g')
170+
```
132171

133-
azureml_mlflow_uri = f"azureml://{region}.api.azureml.ms/mlflow/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}"
134-
mlflow.set_tracking_uri(azureml_mlflow_uri)
135-
```
172+
### Set experiment name
136173

137-
> [!NOTE]
138-
> You can also get this URL by:
139-
> 1. Navigate to [Azure ML studio](https://ml.azure.com)
140-
> 2. Click on the uper-right corner of the page -> View all properties in Azure Portal -> MLflow tracking URI.
141-
> 3. Copy the URI and use it with the method `mlflow.set_tracking_uri`.
174+
All MLflow runs are logged to the active experiment. By default, runs are logged to an experiment named `Default` that is automatically created for you. You can configure the experiment where tracking is happening.
142175

143-
---
176+
> [!TIP]
177+
> When submitting jobs using Azure ML CLI v2, you can set the experiment name using the property `experiment_name` in the YAML definition of the job. You don't have to configure it on your training script. See [YAML: display name, experiment name, description, and tags](reference-yaml-job-command.md#yaml-display-name-experiment-name-description-and-tags) for details.
144178

145-
### Set experiment name
179+
# [MLflow SDK](#tab/mlflow)
146180

147-
All MLflow runs are logged to the active experiment. By default, runs are logged to an experiment named `Default` that is automatically created for you. To configure the experiment you want to work on use MLflow command [`mlflow.set_experiment()`](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_experiment).
181+
To configure the experiment you want to work on use MLflow command [`mlflow.set_experiment()`](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_experiment).
148182

149183
```Python
150184
experiment_name = 'experiment_with_mlflow'
151185
mlflow.set_experiment(experiment_name)
152186
```
153187

154-
> [!TIP]
155-
> When submitting jobs using Azure ML CLI v2, you can set the experiment name using the property `experiment_name` in the YAML definition of the job. You don't have to configure it on your training script. See [YAML: display name, experiment name, description, and tags](reference-yaml-job-command.md#yaml-display-name-experiment-name-description-and-tags) for details.
188+
# [Using an environment variable](#tab/environ)
156189

157190
You can also 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.
158191

159192
```bash
160193
export MLFLOW_EXPERIMENT_NAME="experiment_with_mlflow"
161194
```
162195

196+
---
197+
163198
### Start training job
164199

165200
After you set the MLflow experiment name, you can start your training job with `start_run()`. Then use `log_metric()` to activate the MLflow logging API and begin logging your training job metrics.

0 commit comments

Comments
 (0)