Work with models in Azure Machine Learning

APPLIES TO: Azure CLI ml extension v2 (current) Python SDK azure-ai-ml v2 (preview)

Azure Machine Learning allows you to work with different types of models. In this article, you learn about using Azure Machine Learning to work with different model types, such as custom, MLflow, and Triton. You also learn how to register a model from different locations, and how to use the Azure Machine Learning SDK, the user interface (UI), and the Azure Machine Learning CLI to manage your models.

Tip

If you have model assets created that use the SDK/CLI v1, you can still use those with SDK/CLI v2. Full backward compatibility is provided. All models registered with the V1 SDK are assigned the type custom.

Prerequisites

Supported paths

When you provide a model you want to register, you'll need to specify a path parameter that points to the data or job location. Below is a table that shows the different data locations supported in Azure Machine Learning and examples for the path parameter:

Location Examples
A path on your local computer mlflow-model/model.pkl
A path on an AzureML Datastore azureml://datastores/<datastore-name>/paths/<path_on_datastore>
A path from an AzureML job azureml://jobs/<job-name>/outputs/<output-name>/paths/<path-to-model-relative-to-the-named-output-location>
A path from an MLflow job runs:/<run-id>/<path-to-model-relative-to-the-root-of-the-artifact-location>

Supported modes

When you run a job with model inputs/outputs, you can specify the mode - for example, whether you would like the model to be read-only mounted or downloaded to the compute target. The table below shows the possible modes for different type/mode/input/output combinations:

Type Input/Output direct download ro_mount
custom file Input
custom folder Input
mlflow Input
custom file Output
custom folder Output
mlflow Output

Create a model in the model registry

Model registration allows you to store and version your models in the Azure cloud, in your workspace. The model registry helps you organize and keep track of your trained models.

The code snippets in this section cover how to:

  • Register your model as an asset in Machine Learning by using the CLI.
  • Register your model as an asset in Machine Learning by using the SDK.
  • Register your model as an asset in Machine Learning by using the UI.

These snippets use custom and mlflow.

  • custom is a type that refers to a model file or folder trained with a custom standard not currently supported by Azure ML.
  • mlflow is a type that refers to a model trained with mlflow. MLflow trained models are in a folder that contains the MLmodel file, the model file, the conda dependencies file, and the requirements.txt file.

Register your model as an asset in Machine Learning by using the CLI

Use the following tabs to select where your model is located.

$schema: https://azuremlschemas.azureedge.net/latest/model.schema.json
name: local-file-example
path: mlflow-model/model.pkl
description: Model created from local file.
az ml model create -f <file-name>.yml

For a complete example, see the model YAML.

Register your model as an asset in Machine Learning by using the SDK

Use the following tabs to select where your model is located.

from azure.ai.ml.entities import Model
from azure.ai.ml.constants import ModelType

file_model = Model(
    path="mlflow-model/model.pkl",
    type=ModelType.CUSTOM,
    name="local-file-example",
    description="Model created from local file."
)
ml_client.models.create_or_update(file_model)

Register your model as an asset in Machine Learning by using the UI

To create a model in Machine Learning, from the UI, open the Models page. Select Register model, and select where your model is located. Fill out the required fields, and then select Register.

Screenshot of the UI to register a model.

Next steps