Install and set up the CLI (v2)

APPLIES TO: Azure CLI ml extension v2 (current)

The ml extension to the Azure CLI is the enhanced interface for Azure Machine Learning. It enables you to train and deploy models from the command line, with features that accelerate scaling data science up and out while tracking the model lifecycle.

Prerequisites

  • To use the CLI, you must have an Azure subscription. If you don't have an Azure subscription, create a Trial before you begin. Try the free or paid version of Azure Machine Learning today.
  • To use the CLI commands in this document from your local environment, you need the Azure CLI.

Installation

The new Machine Learning extension requires Azure CLI version >=2.38.0. Ensure this requirement is met:

az version

If it isn't, upgrade your Azure CLI.

Check the Azure CLI extensions that are installed:

az extension list

Remove any existing installation of the ml extension and also the CLI v1 azure-cli-ml extension:

az extension remove -n azure-cli-ml
az extension remove -n ml

Now, install the ml extension:

az extension add -n ml -y

Run the help command to verify your installation and see available subcommands:

az ml -h

You can upgrade the extension to the latest version:

az extension update -n ml

Installation on Linux

If you're using Debian or Ubuntu, the fastest way to install the necessary CLI version and the Machine Learning extension is:

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash 
az extension add -n ml -y

For information on how to install on other Linux distributions, visit Install the Azure CLI for Linux.

Set up

Sign in:

az login

If you have access to multiple Azure subscriptions, you can set your active subscription:

az account set -s "<YOUR_SUBSCRIPTION_NAME_OR_ID>"

Optionally, setup common variables in your shell for usage in subsequent commands:

GROUP="azureml-examples"

LOCATION="chinaeast"

WORKSPACE="main"

Warning

This uses Bash syntax for setting variables. Adjust as needed for your shell. You can also replace the values in commands in the following examples inline rather than using variables.

If it doesn't already exist, you can create the Azure resource group:

az group create -n $GROUP -l $LOCATION

And create a machine learning workspace:

az ml workspace create -n $WORKSPACE -g $GROUP -l $LOCATION

Machine learning subcommands require the --workspace/-w and --resource-group/-g parameters. To avoid typing these repeatedly, configure defaults:

az configure --defaults group=$GROUP workspace=$WORKSPACE location=$LOCATION

Tip

Most code examples assume you have set a default workspace and resource group. You can override these on the command line.

You can show your current defaults using --list-defaults/-l:

az configure -l -o table

Tip

Combining with --output/-o allows for more readable output formats.

Secure communications

The ml CLI extension (sometimes called 'CLI v2') for Azure Machine Learning sends operational data (YAML parameters and metadata) over the public internet. All the ml CLI extension commands communicate with the Azure Resource Manager. This communication is secured using HTTPS/TLS 1.2.

Data in a data store that is secured in a virtual network isn't_ sent over the public internet. For example, if your training data is located in the default storage account for the workspace, and the storage account is in a virtual network.

Note

With the previous extension (azure-cli-ml, sometimes called 'CLI v1'), only some of the commands communicate with the Azure Resource Manager. Specifically, commands that create, update, delete, list, or show Azure resources. Operations such as submitting a training job communicate directly with the Azure Machine Learning workspace. If your workspace is secured with a private endpoint, that is enough to secure commands provided by the azure-cli-ml extension.

If your Azure Machine Learning workspace is public (that is, not behind a virtual network), then there's no extra configuration required. Communications are secured using HTTPS/TLS 1.2

Next steps