Skip to content

Commit 5b16e7e

Browse files
authored
Merge pull request #1639 from JKirsch1/update-mlflow-configuration-article
Freshness - Machine Learning HowTo 180 days
2 parents 38f544a + ab47cf3 commit 5b16e7e

File tree

3 files changed

+136
-111
lines changed

3 files changed

+136
-111
lines changed
Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,91 @@
11
---
22
title: Configure MLflow for Azure Machine Learning
33
titleSuffix: Azure Machine Learning
4-
description: Connect MLflow to Azure Machine Learning workspaces to log metrics, artifacts, and deploy models.
4+
description: Find out how to connect MLflow to an Azure Machine Learning workspace to log metrics, track artifacts, and deploy models.
55
services: machine-learning
66
author: msakande
77
ms.author: mopeakande
88
ms.reviewer: fasantia
99
ms.service: azure-machine-learning
1010
ms.subservice: mlops
11-
ms.date: 01/19/2024
11+
ms.date: 11/20/2024
1212
ms.topic: how-to
1313
ms.custom: mlflow, cliv2, devplatv2
1414
ms.devlang: azurecli
15+
# customer intent: As a developer, I want to see how to configure MLflow so that I can run MLflow training routines in Azure Machine Learning.
1516
---
1617

1718
# Configure MLflow for Azure Machine Learning
1819

19-
This article explains how you can configure MLflow to connect to an Azure Machine Learning workspace for tracking, registries, and deployment.
20+
This article explains how to configure MLflow to connect to an Azure Machine Learning workspace for tracking, registry management, and deployment.
2021

21-
Azure Machine Learning workspaces are MLflow-compatible, which means they can act as an MLflow server without any extra configuration. Each workspace has an MLflow tracking URI that MLflow can use to connect to the workspace. Azure Machine Learning workspaces **are already configured to work with MLflow** so no extra configuration is required.
22+
Azure Machine Learning workspaces are MLflow-compatible, which means they can act as MLflow servers without any extra configuration. Each workspace has an MLflow tracking URI that MLflow can use to connect to the workspace. Azure Machine Learning workspaces **are already configured to work with MLflow**, so no extra configuration is required.
2223

23-
However, if you work outside of Azure Machine Learning (like your local machine, Azure Synapse Analytics, or Azure Databricks), you need to configure MLflow to point to the workspace.
24+
However, if you work outside Azure Machine Learning, you need to configure MLflow to point to the workspace. Affected environments include your local machine, Azure Synapse Analytics, and Azure Databricks.
2425

2526
> [!IMPORTANT]
26-
> When running on Azure Compute (Azure Machine Learning Notebooks, Jupyter notebooks hosted on Azure Machine Learning compute instances, or jobs running on Azure Machine Learning compute clusters), you don't have to configure the tracking URI. **It's automatically configured for you**.
27+
> When you use Azure compute infrastructure, you don't have to configure the tracking URI. **It's automatically configured for you**. Environments with automatic configuration include Azure Machine Learning notebooks, Jupyter notebooks that are hosted on Azure Machine Learning compute instances, and jobs that run on Azure Machine Learning compute clusters.
2728
2829
## Prerequisites
2930

30-
You need the following prerequisites to follow this tutorial:
31+
- The MLflow SDK `mlflow` package and the Azure Machine Learning `azureml-mlflow` plugin for MLflow. You can use the following command to install this software:
3132

32-
[!INCLUDE [mlflow-prereqs](includes/machine-learning-mlflow-prereqs.md)]
33+
```bash
34+
pip install mlflow azureml-mlflow
35+
```
3336

37+
> [!TIP]
38+
> Instead of `mlflow`, consider using [`mlflow-skinny`](https://github.com/mlflow/mlflow/blob/master/README_SKINNY.rst). This package is a lightweight MLflow package without SQL storage, server, UI, or data science dependencies. It's recommended for users who primarily need MLflow tracking and logging capabilities but don't want to import the full suite of features, including deployments.
3439
35-
## Configure MLflow tracking URI
40+
- An Azure Machine Learning workspace. To create a workspace, see [Create resources you need to get started](quickstart-create-resources.md).
3641

37-
To connect MLflow to an Azure Machine Learning workspace, you need the tracking URI for the workspace. Each workspace has its own tracking URI and it has the protocol `azureml://`.
42+
- Access permissions for performing MLflow operations in your workspace. For a list of operations and required permissions, see [MLflow operations](how-to-assign-roles.md#mlflow-operations).
43+
44+
## Configure the MLflow tracking URI
45+
46+
To do remote tracking, or track experiments running outside Azure Machine Learning, configure MLflow to point to the tracking URI of your Azure Machine Learning workspace.
47+
48+
To connect MLflow to an Azure Machine Learning workspace, you need the tracking URI of the workspace. Each workspace has its own tracking URI, which starts with the protocol `azureml://`.
3849

3950
[!INCLUDE [mlflow-configure-tracking](includes/machine-learning-mlflow-configure-tracking.md)]
4051

4152
## Configure authentication
4253

43-
Once the tracking is set, you also need to configure the authentication method for the associated workspace. By default, the Azure Machine Learning plugin for MLflow performs interactive authentication by opening the default browser to prompt for credentials.
54+
After you set up tracking, you also need to configure the authentication method for the associated workspace.
55+
56+
By default, the Azure Machine Learning plugin for MLflow performs interactive authentication by opening the default browser to prompt for credentials. But the plugin also supports several other authentication mechanisms. The `azure-identity` package provides this support. This package is installed as a dependency of the `azureml-mlflow` plugin.
4457

45-
The Azure Machine Learning plugin for MLflow supports several authentication mechanisms through the package `azure-identity`, which is installed as a dependency for the plugin `azureml-mlflow`. The following authentication methods are tried one by one until one of them succeeds:
58+
The authentication process tries the following methods, one after another, until one succeeds:
4659

47-
1. __Environment__: Reads account information specified via environment variables and uses it to authenticate.
48-
1. __Managed Identity__: If the application is deployed to an Azure host with Managed Identity enabled, it authenticates with it.
49-
1. __Azure CLI__: If a user signs in via the Azure CLI `az login` command, it authenticates as that user.
50-
1. __Azure PowerShell__: If a user signs in via Azure PowerShell's `Connect-AzAccount` command, it authenticates as that user.
51-
1. __Interactive browser__: Interactively authenticates a user via the default browser.
60+
1. **Environment**: Account information that's specified via environment variables is read and used for authentication.
61+
1. **Managed identity**: If the application is deployed to an Azure host with a managed identity enabled, the managed identity is used for authentication.
62+
1. **Azure CLI**: If you use the Azure CLI `az login` command to sign in, your credentials are used for authentication.
63+
1. **Azure PowerShell**: If you use the Azure PowerShell `Connect-AzAccount` command to sign in, your credentials are used for authentication.
64+
1. **Interactive browser**: The user is interactively authenticated via the default browser.
5265

5366
[!INCLUDE [mlflow-configure-auth](includes/machine-learning-mlflow-configure-auth.md)]
5467

55-
If you'd rather use a certificate instead of a secret, you can configure the environment variables `AZURE_CLIENT_CERTIFICATE_PATH` to the path to a `PEM` or `PKCS12` certificate file (including private key) and
56-
`AZURE_CLIENT_CERTIFICATE_PASSWORD` with the password of the certificate file, if any.
68+
If you'd rather use a certificate than a secret, you can configure the following environment variables:
69+
70+
- Set `AZURE_CLIENT_CERTIFICATE_PATH` to the path of a file that contains the certificate and private key pair in Privacy Enhanced Mail (PEM) or Public-Key Cryptography Standards 12 (PKCS #12) format.
71+
- Set `AZURE_CLIENT_CERTIFICATE_PASSWORD` to the password of the certificate file, if it uses a password.
5772

5873
### Configure authorization and permission levels
5974

60-
Some [default roles](how-to-assign-roles.md#default-roles) like *AzureML Data Scientist* or *Contributor* are already configured to perform MLflow operations in an Azure Machine Learning workspace. If using a custom role, you need the following permissions:
75+
Some [default roles](how-to-assign-roles.md#default-roles) like AzureML Data Scientist and Contributor are already configured to perform MLflow operations in an Azure Machine Learning workspace. If you use a custom role, you need the following permissions:
6176

62-
* **To use MLflow tracking:**
63-
* `Microsoft.MachineLearningServices/workspaces/experiments/*`
64-
* `Microsoft.MachineLearningServices/workspaces/jobs/*`
77+
- **To use MLflow tracking:**
78+
- `Microsoft.MachineLearningServices/workspaces/experiments/*`
79+
- `Microsoft.MachineLearningServices/workspaces/jobs/*`
6580

66-
* **To use MLflow model registry:**
67-
* `Microsoft.MachineLearningServices/workspaces/models/*/*`
81+
- **To use the MLflow model registry:**
82+
- `Microsoft.MachineLearningServices/workspaces/models/*/*`
6883

69-
To learn how to grant access for the service principal you created or user account to your workspace, see [Grant access](/azure/role-based-access-control/quickstart-assign-role-user-portal#grant-access).
84+
To see how to grant access to your workspace to a service principal that you create or to your user account, see [Grant access](/azure/role-based-access-control/quickstart-assign-role-user-portal#grant-access).
7085

71-
### Troubleshooting authentication
86+
### Troubleshoot authentication issues
7287

73-
MLflow tries to authenticate to Azure Machine Learning on the first operation that interacts with the service, like `mlflow.set_experiment()` or `mlflow.start_run()`. If you find issues or unexpected authentication prompts during the process, you can increase the logging level to get more details about the error:
88+
MLflow tries to authenticate to Azure Machine Learning on the first operation that interacts with the service, like `mlflow.set_experiment()` or `mlflow.start_run()`. If you experience issues or unexpected authentication prompts during the process, you can increase the logging level to get more details about the error:
7489

7590
```python
7691
import logging
@@ -80,44 +95,45 @@ logging.getLogger("azure").setLevel(logging.DEBUG)
8095

8196
## Set experiment name (optional)
8297

83-
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.
98+
All MLflow runs are logged to the active experiment. By default, runs are logged to an experiment named `Default` that's automatically created for you. You can configure the experiment that's used for tracking.
8499

85100
> [!TIP]
86-
> When submitting jobs using Azure Machine Learning 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.
101+
>
102+
> When you use the Azure Machine Learning CLI v2 to submit jobs, you can set the experiment name by using the `experiment_name` property in the YAML definition of the job. You don't have to configure it in your training script. For more information, see [YAML: display name, experiment name, description, and tags](reference-yaml-job-command.md#yaml-display-name-experiment-name-description-and-tags).
87103
88104

89105
# [MLflow SDK](#tab/mlflow)
90106

91-
Configure your experiment by using MLflow command [`mlflow.set_experiment()`](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_experiment).
107+
Use the MLflow [`mlflow.set_experiment()`](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_experiment) command to configure your experiment.
92108

93-
```Python
94-
experiment_name = 'experiment_with_mlflow'
109+
```python
110+
experiment_name = "experiment_with_mlflow"
95111
mlflow.set_experiment(experiment_name)
96112
```
97113

98-
# [Using environment variables](#tab/environ)
114+
# [Environment variables](#tab/environ)
99115

100-
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.
116+
Use the MLflow `MLFLOW_EXPERIMENT_NAME` or `MLFLOW_EXPERIMENT_ID` environment variable to configure your experiment. For more information, see [Command-Line Interface](https://mlflow.org/docs/latest/cli.html) or [mlflow.start_run](https://mlflow.org/docs/latest/python_api/mlflow.html#mlflow.start_run).
101117

102118
```bash
103119
export MLFLOW_EXPERIMENT_NAME="experiment_with_mlflow"
104120
```
105121

106122
---
107123

108-
## Nonpublic Azure Clouds support
124+
## Configure support for a nonpublic Azure cloud
109125

110-
The Azure Machine Learning plugin for MLflow is configured by default to work with the global Azure cloud. However, you can configure the Azure cloud you're using by setting the environment variable `AZUREML_CURRENT_CLOUD`.
126+
The Azure Machine Learning plugin for MLflow is configured by default to work with the global Azure cloud. However, you can configure the Azure cloud you're using by setting the `AZUREML_CURRENT_CLOUD` environment variable:
111127

112128
# [MLflow SDK](#tab/mlflow)
113129

114-
```Python
130+
```python
115131
import os
116132

117133
os.environ["AZUREML_CURRENT_CLOUD"] = "AzureChinaCloud"
118134
```
119135

120-
# [Using environment variables](#tab/environ)
136+
# [Environment variables](#tab/environ)
121137

122138
```bash
123139
export AZUREML_CURRENT_CLOUD="AzureChinaCloud"
@@ -133,11 +149,11 @@ az cloud list
133149

134150
The current cloud has the value `IsActive` set to `True`.
135151

136-
## Next steps
152+
## Related content
137153

138154
Now that your environment is connected to your workspace in Azure Machine Learning, you can start to work with it.
139155

140-
- [Track ML experiments and models with MLflow](how-to-use-mlflow-cli-runs.md)
141-
- [Manage models registries in Azure Machine Learning with MLflow](how-to-manage-models-mlflow.md)
142-
- [Train with MLflow Projects (Preview)](how-to-train-mlflow-projects.md)
156+
- [Track experiments and models with MLflow](how-to-use-mlflow-cli-runs.md)
157+
- [Manage models registry in Azure Machine Learning with MLflow](how-to-manage-models-mlflow.md)
158+
- [Train with MLflow Projects in Azure Machine Learning (preview)](how-to-train-mlflow-projects.md)
143159
- [Guidelines for deploying MLflow models](how-to-deploy-mlflow-models.md)

articles/machine-learning/includes/machine-learning-mlflow-configure-auth.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,40 @@
22
author: santiagxf
33
ms.service: azure-machine-learning
44
ms.topic: include
5-
ms.date: 08/16/2024
5+
ms.date: 11/20/2024
66
ms.author: fasantia
77
---
88

9-
For interactive jobs where there's a user connected to the session, you can rely on Interactive Authentication and hence no further action is required.
9+
For interactive jobs where there's a user connected to the session, you can rely on interactive authentication. No further action is required.
1010

1111
> [!WARNING]
12-
> *Interactive browser* authentication blocks code execution when it prompts for credentials. This approach isn't suitable for authentication in unattended environments like training jobs. We recommend that you configure a different authentication mode.
12+
> *Interactive browser* authentication blocks code execution when it prompts for credentials. This approach isn't suitable for authentication in unattended environments like training jobs. We recommend that you configure a different authentication mode in those environments.
1313
14-
For those scenarios where unattended execution is required, you have to configure a service principal to communicate with Azure Machine Learning.
14+
For scenarios that require unattended execution, you need to configure a service principal to communicate with Azure Machine Learning. For information about creating a service principal, see [Configure a service principal](../how-to-setup-authentication.md#configure-a-service-principal).
15+
16+
Use the tenant ID, client ID, and client secret of your service principal in the following code:
1517

1618
# [MLflow SDK](#tab/mlflow)
1719

1820
```python
1921
import os
2022

21-
os.environ["AZURE_TENANT_ID"] = "<AZURE_TENANT_ID>"
22-
os.environ["AZURE_CLIENT_ID"] = "<AZURE_CLIENT_ID>"
23-
os.environ["AZURE_CLIENT_SECRET"] = "<AZURE_CLIENT_SECRET>"
23+
os.environ["AZURE_TENANT_ID"] = "<Azure-tenant-ID>"
24+
os.environ["AZURE_CLIENT_ID"] = "<Azure-client-ID>"
25+
os.environ["AZURE_CLIENT_SECRET"] = "<Azure-client-secret>"
2426
```
2527

26-
# [Using environment variables](#tab/environ)
28+
# [Environment variables](#tab/environ)
2729

2830
```bash
29-
export AZURE_TENANT_ID="<AZURE_TENANT_ID>"
30-
export AZURE_CLIENT_ID="<AZURE_CLIENT_ID>"
31-
export AZURE_CLIENT_SECRET="<AZURE_CLIENT_SECRET>"
31+
export AZURE_TENANT_ID="<Azure-tenant-ID>"
32+
export AZURE_CLIENT_ID="<Azure-client-ID>"
33+
export AZURE_CLIENT_SECRET="<Azure-client-secret>"
3234
```
3335

3436
---
3537

3638
> [!TIP]
37-
> When working on shared environments, we recommend that you configure these environment variables at the compute. As a best practice, manage them as secrets in an instance of Azure Key Vault.
39+
> When you work in shared environments, we recommend that you configure these environment variables at the compute level. As a best practice, manage them as secrets in an instance of Azure Key Vault.
3840
>
39-
> For instance, in Azure Databricks you can use secrets in environment variables as follows in the cluster configuration: `AZURE_CLIENT_SECRET={{secrets/<scope-name>/<secret-name>}}`. For more information about implementing this approach in Azure Databricks, see [Reference a secret in an environment variable](/azure/databricks/security/secrets/secrets#reference-a-secret-in-an-environment-variable) or refer to documentation for your platform.
41+
> For instance, in an Azure Databricks cluster configuration, you can use secrets in environment variables in the following way: `AZURE_CLIENT_SECRET={{secrets/<scope-name>/<secret-name>}}`. For more information about implementing this approach in Azure Databricks, see [Reference a secret in an environment variable](/azure/databricks/security/secrets/secrets#reference-a-secret-in-an-environment-variable), or refer to documentation for your platform.

0 commit comments

Comments
 (0)