Train with MLflow Projects in Azure Machine Learning (Preview)

In this article, learn how to submit training jobs with MLflow Projects that uses Azure Machine Learning workspaces for tracking. You can submit jobs and only track them with Azure Machine Learning or migrate your runs to the cloud to run completely on 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.

Learn more about the MLflow and Azure Machine Learning integration.

Prerequisites

  • Using Azure Machine Learning as backend for MLflow projects requires the package azureml-core:

    pip install azureml-core
    

Connect to your workspace

If you're working outside Azure Machine Learning, you need to configure MLflow to point to your Azure Machine Learning workspace's tracking URI. You can find the instructions at Configure MLflow for Azure Machine Learning.

Track MLflow Projects in Azure Machine Learning workspaces

This example shows how to submit MLflow projects and track them Azure Machine Learning.

  1. 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.

    conda.yaml

    name: mlflow-example
    channels:
      - defaults
    dependencies:
      - numpy>=1.14.3
      - pandas>=1.0.0
      - scikit-learn
      - pip:
        - mlflow
        - azureml-mlflow
    
  2. Submit the local run and ensure you set the parameter backend = "azureml", which adds support of automatic tracking, model's capture, log files, snapshots, and printed errors in your workspace. In this example we assume the MLflow project you are trying to run is in the same folder you currently are, uri=".".

    mlflow run . --experiment-name  --backend azureml --env-manager=local -P alpha=0.3
    

    View your runs and metrics in the Azure Machine Learning studio.

Train MLflow projects in Azure Machine Learning jobs

This example shows how to submit MLflow projects as a job running on Azure Machine Learning compute.

  1. Create the backend configuration object, in this case we are going to indicate COMPUTE. This parameter references the name of your remote compute cluster you want to use for running your project. If COMPUTE is present, the project will be automatically submitted as an Azure Machine Learning job to the indicated compute.

    backend_config.json

    {
        "COMPUTE": "cpu-cluster"
    }
    
    
  2. 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.

    conda.yaml

    name: mlflow-example
    channels:
      - defaults
    dependencies:
      - numpy>=1.14.3
      - pandas>=1.0.0
      - scikit-learn
      - pip:
        - mlflow
        - azureml-mlflow
    
  3. Submit the local run and ensure you set the parameter backend = "azureml", which adds support of automatic tracking, model's capture, log files, snapshots, and printed errors in your workspace. In this example we assume the MLflow project you are trying to run is in the same folder you currently are, uri=".".

    mlflow run . --backend azureml --backend-config backend_config.json -P alpha=0.3
    

    Note

    Since Azure Machine Learning jobs always run in the context of environments, the parameter env_manager is ignored.

    View your runs and metrics in the Azure Machine Learning studio.

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:

  1. In the Azure portal, select Resource groups on the far left.

    Image showing how to delete an Azure resource group.

  2. From the list, select the resource group you created.

  3. Select Delete resource group.

  4. 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