Train On Amlcompute
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
![]()
Train using Azure Machine Learning Compute
- Initialize a Workspace
- Create an Experiment
- Introduction to AmlCompute
- Submit an AmlCompute run in a few different ways
- Provision as a persistent compute target (Basic)
- Provision as a persistent compute target (Advanced)
- Additional operations to perform on AmlCompute
- Find the best model in the run
Prerequisites
If you are using an Azure Machine Learning Notebook VM, you are all set. Otherwise, go through the configuration Notebook first if you haven't already to establish your connection to the AzureML Workspace.
Initialize a Workspace
Initialize a workspace object from persisted configuration
Create An Experiment
Experiment is a logical container in an Azure ML Workspace. It hosts run records which can include run metrics and output artifacts from your experiments.
Introduction to AmlCompute
Azure Machine Learning Compute is managed compute infrastructure that allows the user to easily create single to multi-node compute of the appropriate VM Family. It is created within your workspace region and is a resource that can be used by other users in your workspace. It autoscales by default to the max_nodes, when a job is submitted, and executes in a containerized environment packaging the dependencies as specified by the user.
Since it is managed compute, job scheduling and cluster management are handled internally by Azure Machine Learning service.
For more information on Azure Machine Learning Compute, please read this article
If you are an existing BatchAI customer who is migrating to Azure Machine Learning, please read this article
Note: As with other Azure services, there are limits on certain resources (for eg. AmlCompute quota) associated with the Azure Machine Learning service. Please read this article on the default limits and how to request more quota.
The training script train.py is already created for you. Let's have a look.
Submit an AmlCompute run in a few different ways
First lets check which VM families are available in your region. Azure is a regional service and some specialized SKUs (especially GPUs) are only available in certain regions. Since AmlCompute is created in the region of your workspace, we will use the supported_vms () function to see if the VM family we want to use ('STANDARD_D2_V2') is supported.
You can also pass a different region to check availability and then re-create your workspace in that region through the configuration notebook.
Create project directory
Create a directory that will contain all the necessary code from your local machine that you will need access to on the remote resource. This includes the training script, and any additional files your training script depends on
Create environment
Create Docker based environment with scikit-learn installed.
Provision as a persistent compute target (Basic)
Note that if you have an AzureML Data Scientist role, you will not have permission to create compute resources. Talk to your workspace or IT admin to create the compute targets described in this section, if they do not already exist.
You can provision a persistent AmlCompute resource by simply defining two parameters thanks to smart defaults. By default it autoscales from 0 nodes and provisions dedicated VMs to run your job in a container. This is useful when you want to continously re-use the same target, debug it between jobs or simply share the resource with other users of your workspace.
vm_size: VM family of the nodes provisioned by AmlCompute. Simply choose from the supported_vmsizes() abovemax_nodes: Maximum nodes to autoscale to while running a job on AmlCompute
Configure & Run
Note: if you need to cancel a run, you can follow these instructions.
Provision as a persistent compute target (Advanced)
Note that if you have an AzureML Data Scientist role, you will not have permission to create compute resources. Talk to your workspace or IT admin to create the compute targets described in this section, if they do not already exist.
You can also specify additional properties or change defaults while provisioning AmlCompute using a more advanced configuration. This is useful when you want a dedicated cluster of 4 nodes (for example you can set the min_nodes and max_nodes to 4), or want the compute to be within an existing VNet in your subscription.
In addition to vm_size and max_nodes, you can specify:
min_nodes: Minimum nodes (default 0 nodes) to downscale to while running a job on AmlComputevm_priority: Choose between 'dedicated' (default) and 'lowpriority' VMs when provisioning AmlCompute. Low Priority VMs use Azure's excess capacity and are thus cheaper but risk your run being pre-emptedidle_seconds_before_scaledown: Idle time (default 120 seconds) to wait after run completion before auto-scaling to min_nodesvnet_resourcegroup_name: Resource group of the existing VNet within which AmlCompute should be provisionedvnet_name: Name of VNetsubnet_name: Name of SubNet within the VNetadmin_username: Name of Admin user account which will be created on all the nodes of the clusteradmin_user_password: Password that you want to set for the user account aboveadmin_user_ssh_key: SSH Key for the user account above. You can specify either a password or an SSH key or bothremote_login_port_public_access: Flag to enable or disable the public SSH port. If you dont specify, AmlCompute will smartly close the port when deploying inside a VNetidentity_type: Compute Identity type that you want to set on the cluster, which can either be SystemAssigned or UserAssignedidentity_id: Resource ID of identity in case it is a UserAssigned identity, optional otherwise
Configure & Run
Additional operations to perform on AmlCompute
You can perform more operations on AmlCompute such as updating the node counts or deleting the compute.
Success!
Great, you are ready to move on to the remaining notebooks.