Train ML models with MLflow Projects and Azure Machine Learning (preview)
Important
This feature is currently in public preview. This preview version is provided without a service-level agreement, and it's not recommended for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
In this article, learn how to enable MLflow's tracking URI and logging API, collectively known as MLflow Tracking, to submit training jobs with MLflow Projects and Azure Machine Learning backend support. You can submit jobs locally with Azure Machine Learning tracking or migrate your runs to the cloud like via an Azure Machine Learning Compute.
MLflow Projects allow for you to organize and describe your code to let other data scientists (or automated tools) run it. MLflow Projects with Azure Machine Learning enable you to track and manage your training runs in your workspace.
MLflow is an open-source library for managing the life cycle 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.
Learn more about the MLflow and Azure Machine Learning integration..
Tip
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.
Prerequisites
- Install the
azureml-mlflowpackage. - Create an Azure Machine Learning Workspace.
- Configure MLflow for tracking in Azure Machine Learning, as explained in the next section.
Set up tracking environment
To configure MLflow for working with Azure Machine Learning, you need to point your MLflow environment to the Azure Machine Learning MLflow Tracking URI.
Note
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.
APPLIES TO:
Python SDK azure-ai-ml v2 (preview)
You can get the Azure ML MLflow tracking URI using the Azure Machine Learning SDK v2 for Python. 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() points the MLflow tracking URI to that URI.
Using the workspace configuration file:
from azure.ai.ml import MLClient from azure.identity import DefaultAzureCredential import mlflow ml_client = MLClient.from_config(credential=DefaultAzureCredential() azureml_mlflow_uri = ml_client.workspaces.get(ml_client.workspace_name).mlflow_tracking_uri mlflow.set_tracking_uri(azureml_mlflow_uri)Tip
You can download the workspace configuration file by:
- Navigate to Azure ML studio
- Click on the uper-right corner of the page -> Download config file.
- Save the file
config.jsonin the same directory where you are working on.
Using the subscription ID, resource group name and workspace name:
from azure.ai.ml import MLClient from azure.identity import DefaultAzureCredential import mlflow #Enter details of your AzureML workspace subscription_id = '<SUBSCRIPTION_ID>' resource_group = '<RESOURCE_GROUP>' workspace_name = '<AZUREML_WORKSPACE_NAME>' ml_client = MLClient(credential=DefaultAzureCredential(), subscription_id=subscription_id, resource_group_name=resource_group) azureml_mlflow_uri = ml_client.workspaces.get(workspace_name).mlflow_tracking_uri mlflow.set_tracking_uri(azureml_mlflow_uri)Important
DefaultAzureCredentialwill 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 useInteractiveBrowserCredentialor any other method available inazure.identitypackage.
Train MLflow Projects on local compute
This example shows how to submit MLflow projects locally with Azure Machine Learning.
Create the backend configuration object to store necessary information for the integration such as, the compute target and which type of managed environment to use.
backend_config = {"USE_CONDA": False}
Add the azureml-mlflow package as a pip dependency to your environment configuration file in order to track metrics and key artifacts in your workspace.
name: mlflow-example
channels:
- defaults
- anaconda
- conda-forge
dependencies:
- python=3.6
- scikit-learn=0.19.1
- pip
- pip:
- mlflow
- azureml-mlflow
Submit the local run and ensure you set the parameter backend = "azureml" . With this setting, you can submit runs locally and get the added support of automatic output tracking, log files, snapshots, and printed errors in your workspace.
View your runs and metrics in the Azure Machine Learning studio.
local_env_run = mlflow.projects.run(uri=".",
parameters={"alpha":0.3},
backend = "azureml",
use_conda=False,
backend_config = backend_config,
)
Train MLflow projects with remote compute
This example shows how to submit MLflow projects on a remote compute with Azure Machine Learning tracking.
Create the backend configuration object to store necessary information for the integration such as, the compute target and which type of managed environment to use.
The integration accepts "COMPUTE" and "USE_CONDA" as parameters where "COMPUTE" is set to the name of your remote compute cluster and "USE_CONDA" which creates a new environment for the project from the environment configuration file. If "COMPUTE" is present in the object, the project will be automatically submitted to the remote compute and ignore "USE_CONDA". MLflow accepts a dictionary object or a JSON file.
# dictionary
backend_config = {"COMPUTE": "cpu-cluster", "USE_CONDA": False}
Add the azureml-mlflow package as a pip dependency to your environment configuration file in order to track metrics and key artifacts in your workspace.
name: mlflow-example
channels:
- defaults
- anaconda
- conda-forge
dependencies:
- python=3.6
- scikit-learn=0.19.1
- pip
- pip:
- mlflow
- azureml-mlflow
Submit the mlflow project run and ensure you set the parameter backend = "azureml" . With this setting, you can submit your run to your remote compute and get the added support of automatic output tracking, log files, snapshots, and printed errors in your workspace.
View your runs and metrics in the Azure Machine Learning studio.
remote_mlflow_run = mlflow.projects.run(uri=".",
parameters={"alpha":0.3},
backend = "azureml",
backend_config = backend_config,
)
Clean up resources
If you don't plan to use the logged metrics and artifacts in your workspace, the ability to delete them individually is currently unavailable. Instead, delete the resource group that contains the storage account and workspace, so you don't incur any charges:
In the Azure portal, select Resource groups on the far left.

From the list, select the resource group you created.
Select Delete resource group.
Enter the resource group name. Then select Delete.
Example notebooks
The MLflow with Azure ML notebooks demonstrate and expand upon concepts presented in this article.
Note
A community-driven repository of examples using mlflow can be found at https://github.com/Azure/azureml-examples.
Next steps
- Deploy models with MLflow.
- Monitor your production models for data drift.
- Track Azure Databricks runs with MLflow.
- Manage your models.
Povratne informacije
Pošalјite i prikažite povratne informacije za