Azure AI Machine Learning CLI (az ml)

The Azure Machine Learning CLI provides a powerful set of commands to manage experiments, datasets, compute resources, and deployments directly from your terminal.

Table of Contents

Installation

Install the CLI using pip or conda. The most common method is via pip:

pip install azure-cli
az extension add -n ml

Verify the installation:

az ml -h

Authentication

Log in to Azure and set your default subscription:

az login
az account set --subscription <subscription-id>

Authenticate the ML extension to your workspace:

az ml workspace set -w <workspace-name> -g <resource-group>

Compute Management

Create a new compute cluster:

az ml compute create -n mycluster -t amlcompute --min-instances 0 --max-instances 4

List compute resources:

az ml compute list

Datasets

Register a dataset from a storage account:

az ml data create -n mydata -p "{'path':'https://myaccount.blob.core.windows.net/data/train.csv'}"

Download a dataset locally:

az ml data download -n mydata -f ./data/

Model Management

Register a model artifact:

az ml model create -n mymodel -p ./outputs/model.pkl

List registered models:

az ml model list

Deployments

Deploy a model as an online endpoint:

az ml endpoint create -n myendpoint -f endpoint.yml
az ml deployment create -e myendpoint -n blue -f deployment.yml

Test the endpoint:

az ml endpoint invoke -n myendpoint -i '{"data": [1,2,3]}'

Examples

Run an experiment from a YAML file:

az ml job create -f job.yml

Submit a Python script as a job:

az ml job submit -c mycluster -f script.py --environment azureml:python-3.8

Command Reference

Below is a filtered list of the most frequently used commands. For the full reference, see the CLI Commands page.

CommandDescription
az ml compute createCreate a new compute target.
az ml compute listList compute resources.
az ml data createRegister a new dataset.
az ml data downloadDownload a dataset locally.
az ml model createRegister a model artifact.
az ml model listList models in the workspace.
az ml endpoint createCreate an online endpoint.
az ml deployment createCreate a deployment for an endpoint.
az ml job createCreate a job from a YAML spec.
az ml job submitRun a job from a script.