Skip to content

Commit bfd1cf8

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

File tree

1 file changed

+97
-103
lines changed

1 file changed

+97
-103
lines changed

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

Lines changed: 97 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -58,120 +58,114 @@ To track a run that is not running on Azure Machine Learning compute, you need t
5858
5959
1. Getting the Azure Machine Learning Tracking URI:
6060

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)
79-
80-
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
81-
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.
83-
84-
1. Login into your workspace using the `MLClient`. The easier way to do that is by using the workspace config file:
85-
86-
```python
87-
from azure.ai.ml import MLClient
88-
from azure.identity import DefaultAzureCredential
89-
90-
ml_client = MLClient.from_config(credential=DefaultAzureCredential())
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>
9170
```
92-
93-
> [!TIP]
94-
> You can download the workspace configuration file by:
95-
> 1. Navigate to [Azure ML studio](https://ml.azure.com)
96-
> 2. Click on the uper-right corner of the page -> Download config file.
97-
> 3. Save the file `config.json` in the same directory where you are working on.
98-
99-
1. Alternatively, you can use the subscription ID, resource group name and workspace name to get it:
100-
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)
79+
80+
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
81+
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.
83+
84+
1. Login into your workspace using the `MLClient`. The easier way to do that is by using the workspace config file:
85+
86+
```python
87+
from azure.ai.ml import MLClient
88+
from azure.identity import DefaultAzureCredential
89+
90+
ml_client = MLClient.from_config(credential=DefaultAzureCredential())
91+
```
92+
93+
> [!TIP]
94+
> You can download the workspace configuration file by:
95+
> 1. Navigate to [Azure ML studio](https://ml.azure.com)
96+
> 2. Click on the uper-right corner of the page -> Download config file.
97+
> 3. Save the file `config.json` in the same directory where you are working on.
98+
99+
1. Alternatively, you can use the subscription ID, resource group name and workspace name to get it:
100+
101+
```python
102+
from azure.ai.ml import MLClient
103+
from azure.identity import DefaultAzureCredential
104+
105+
#Enter details of your AzureML workspace
106+
subscription_id = '<SUBSCRIPTION_ID>'
107+
resource_group = '<RESOURCE_GROUP>'
108+
workspace_name = '<AML_WORKSPACE_NAME>'
109+
110+
ml_client = MLClient(credential=DefaultAzureCredential(),
111+
subscription_id=subscription_id,
112+
resource_group_name=resource_group)
113+
```
114+
115+
> [!IMPORTANT]
116+
> `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.
117+
118+
1. Get the Azure Machine Learning Tracking URI:
119+
120+
```python
121+
mlflow_tracking_uri = ml_client.workspaces.get(ml_client.workspace_name).mlflow_tracking_uri
122+
```
123+
124+
# [Studio](#tab/studio)
125+
126+
Use the Azure Machine Learning portal to get the tracking URI:
127+
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__.
132+
133+
# [Manually](#tab/manual)
134+
135+
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:
136+
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+
101140
```python
102-
from azure.ai.ml import MLClient
103-
from azure.identity import DefaultAzureCredential
104-
105-
#Enter details of your AzureML workspace
141+
region = "<LOCATION>"
106142
subscription_id = '<SUBSCRIPTION_ID>'
107143
resource_group = '<RESOURCE_GROUP>'
108144
workspace_name = '<AML_WORKSPACE_NAME>'
109-
110-
ml_client = MLClient(credential=DefaultAzureCredential(),
111-
subscription_id=subscription_id,
112-
resource_group_name=resource_group)
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}"
113147
```
114148

115-
> [!IMPORTANT]
116-
> `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.
117-
118-
1. Get the Azure Machine Learning Tracking URI:
149+
1. Configuring the tracking URI:
119150

151+
# [Using an environment variable](#tab/environ)
152+
153+
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.
154+
155+
```bash
156+
MLFLOW_TRACKING_URI=$(az ml workspace show --query mlflow_tracking_uri | sed 's/"//g')
157+
```
158+
159+
# [Using MLflow SDK](#tab/mlflow)
160+
161+
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.
162+
120163
```python
121-
mlflow_tracking_uri = ml_client.workspaces.get(ml_client.workspace_name).mlflow_tracking_uri
164+
import mlflow
165+
166+
mlflow.set_tracking_uri(mlflow_tracking_uri)
122167
```
123168

124-
# [Studio](#tab/studio)
125-
126-
Use the Azure Machine Learning portal to get the tracking URI:
127-
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__.
132-
133-
# [Manually](#tab/manual)
134-
135-
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:
136-
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-
140-
```python
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)
156-
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.
158-
159-
```bash
160-
MLFLOW_TRACKING_URI=$(az ml workspace show --query mlflow_tracking_uri | sed 's/"//g')
161-
```
162-
163-
# [Using MLflow SDK](#tab/mlflow)
164-
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.
166-
167-
```python
168-
import mlflow
169-
170-
mlflow.set_tracking_uri(mlflow_tracking_uri)
171-
```
172-
173-
---
174-
175169
### Set experiment name
176170

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

0 commit comments

Comments
 (0)