Skip to content

Commit 3ae1724

Browse files
authored
Update how-to-use-mlflow-cli-runs.md
1 parent a02d198 commit 3ae1724

File tree

1 file changed

+69
-41
lines changed

1 file changed

+69
-41
lines changed

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

Lines changed: 69 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,43 @@ 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)
58+
59+
1. Getting the Azure Machine Learning Tracking URI:
60+
61+
# [Bash](#tab/cli)
62+
63+
[!INCLUDE [cli v2](../../includes/machine-learning-cli-v2.md)]
64+
65+
1. Login and configure your workspace:
66+
67+
```bash
68+
az account set --subscription <subscription>
69+
az configure --defaults workspace=<workspace> group=<resource-group> location=<location>
70+
```
71+
72+
1. You can get the tracking URI using the `az ml workspace` command:
73+
74+
```bash
75+
MLFLOW_TRACKING_URI=$(az ml workspace show --query mlflow_tracking_uri | sed 's/"//g')
76+
```
77+
78+
# [Python](#tab/python)
6179

6280
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
6381

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.
82+
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.
6583

66-
1. Using the workspace configuration file:
84+
1. Login into your workspace using the `MLClient`. The easier way to do that is by using the workspace config file:
6785

68-
```Python
86+
```python
6987
from azure.ai.ml import MLClient
7088
from azure.identity import DefaultAzureCredential
71-
import mlflow
7289

7390
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)
7691
```
7792

7893
> [!TIP]
@@ -81,68 +96,81 @@ You can get the Azure ML MLflow tracking URI using the [Azure Machine Learning S
8196
> 2. Click on the uper-right corner of the page -> Download config file.
8297
> 3. Save the file `config.json` in the same directory where you are working on.
8398

84-
1. Using the subscription ID, resource group name and workspace name:
99+
1. Alternatively, you can use the subscription ID, resource group name and workspace name to get it:
85100

86-
```Python
101+
```python
87102
from azure.ai.ml import MLClient
88103
from azure.identity import DefaultAzureCredential
89-
import mlflow
90104

91105
#Enter details of your AzureML workspace
92106
subscription_id = '<SUBSCRIPTION_ID>'
93107
resource_group = '<RESOURCE_GROUP>'
94-
workspace_name = '<AZUREML_WORKSPACE_NAME>'
108+
workspace_name = '<AML_WORKSPACE_NAME>'
95109

96110
ml_client = MLClient(credential=DefaultAzureCredential(),
97111
subscription_id=subscription_id,
98112
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)
102113
```
103114

104115
> [!IMPORTANT]
105116
> `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.
106117

107-
# [Using an environment variable](#tab/environ)
118+
1. Get the Azure Machine Learning Tracking URI:
108119

109-
[!INCLUDE [cli v2](../../includes/machine-learning-cli-v2.md)]
120+
```python
121+
mlflow_tracking_uri = ml_client.workspaces.get(ml_client.workspace_name).mlflow_tracking_uri
122+
```
110123

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.
124+
# [Studio](#tab/studio)
112125

113-
```Azure CLI
114-
export MLFLOW_TRACKING_URI=$(az ml workspace show --query mlflow_tracking_uri | sed 's/"//g')
115-
```
126+
Use the Azure Machine Learning portal to get the tracking URI:
116127

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.
128+
1. Open the [Azure Machine Learning studio portal](https://ml.azure.com) and log in using your credentials.
129+
1. In the upper right corner, click on the name of your workspace to show the __Directory + Subscription + Workspace__ blade.
130+
1. Click on __View all properties in Azure Portal__.
131+
1. On the __Essentials__ section, you will find the property __MLflow tracking URI__.
119132

120-
# [Building the MLflow tracking URI](#tab/build)
133+
# [Manually](#tab/manual)
121134

122135
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:
123136

137+
> [!WARNING]
138+
> 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.
139+
124140
```python
125-
import mlflow
141+
region = "<LOCATION>"
142+
subscription_id = '<SUBSCRIPTION_ID>'
143+
resource_group = '<RESOURCE_GROUP>'
144+
workspace_name = '<AML_WORKSPACE_NAME>'
145+
146+
mlflow_tracking_uri = f"azureml://{region}.api.azureml.ms/mlflow/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}"
147+
```
148+
149+
---
150+
151+
1. Configuring the tracking URI:
152+
153+
There are two main ways to configure your environment to work with Azure Machine Learning with Mlflow.
154+
155+
# [Using an environment variable](#tab/environ)
126156

127-
region = ""
128-
subscription_id = ""
129-
resource_group = ""
130-
workspace_name = ""
157+
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.
131158

132-
azureml_mlflow_uri = f"azureml://{region}.api.azureml.ms/mlflow/v1.0/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.MachineLearningServices/workspaces/{workspace_name}"
133-
mlflow.set_tracking_uri(azureml_mlflow_uri)
159+
```bash
160+
MLFLOW_TRACKING_URI=$(az ml workspace show --query mlflow_tracking_uri | sed 's/"//g')
134161
```
135162

136-
> [!WARNING]
137-
> 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.
163+
# [Using MLflow SDK](#tab/mlflow)
138164

139-
---
165+
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.
140166

141-
> [!NOTE]
142-
> You can also get this URL by:
143-
> 1. Navigate to [Azure ML studio](https://ml.azure.com)
144-
> 2. Click on the upper-right corner of the page -> View all properties in Azure Portal -> MLflow tracking URI.
145-
> 3. Copy the URI and use it with the method `mlflow.set_tracking_uri`.
167+
```python
168+
import mlflow
169+
170+
mlflow.set_tracking_uri(mlflow_tracking_uri)
171+
```
172+
173+
---
146174

147175
### Set experiment name
148176

0 commit comments

Comments
 (0)