AmlCompute Class

Manages an Azure Machine Learning compute in Azure Machine Learning.

An Azure Machine Learning Compute (AmlCompute) is a managed-compute infrastructure that allows you to easily create a single or multi-node compute. The compute is created within your workspace region as a resource that can be shared with other users. For more information, see What are compute targets in Azure Machine Learning?

Class ComputeTarget constructor.

Retrieve a cloud representation of a Compute object associated with the provided workspace. Returns an instance of a child class corresponding to the specific type of the retrieved Compute object.

Inheritance
AmlCompute

Constructor

AmlCompute(workspace, name)

Parameters

workspace
Workspace
Required

The workspace object containing the AmlCompute object to retrieve.

name
str
Required

The name of the AmlCompute object to retrieve.

workspace
Workspace
Required

The workspace object containing the Compute object to retrieve.

name
str
Required

The name of the of the Compute object to retrieve.

Remarks

In the following example, a persistent compute target provisioned by AmlCompute is created. The provisioning_configuration parameter in this example is of type AmlComputeProvisioningConfiguration, which is a child class of ComputeTargetProvisioningConfiguration.


   from azureml.core.compute import ComputeTarget, AmlCompute
   from azureml.core.compute_target import ComputeTargetException

   # Choose a name for your CPU cluster
   cpu_cluster_name = "cpu-cluster"

   # Verify that cluster does not exist already
   try:
       cpu_cluster = ComputeTarget(workspace=ws, name=cpu_cluster_name)
       print('Found existing cluster, use it.')
   except ComputeTargetException:
       compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_D2_V2',
                                                              max_nodes=4)
       cpu_cluster = ComputeTarget.create(ws, cpu_cluster_name, compute_config)

   cpu_cluster.wait_for_completion(show_output=True)

Full sample is available from https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/training/train-on-amlcompute/train-on-amlcompute.ipynb

Methods

add_identity

Add Identity Type and/or Identity Ids for this AmlCompute target.

delete

Remove the AmlCompute object from its associated workspace.

deserialize

Convert a JSON object into an AmlCompute object.

detach

Detach is not supported for AmlCompute object. Use delete instead.

get

Return compute object.

get_active_runs

Return a generator of the runs for this compute.

get_status

Retrieve the current detailed status for the AmlCompute cluster.

list_nodes

Get the details (e.g., IP address, port, etc.) of all the compute nodes in the compute target.

list_quotas

Get the currently assigned Workspace quotas based on VMFamily for given workspace and subscription.

list_usages

Get the current usage information as well as limits for AML resources for given workspace and subscription.

provisioning_configuration

Create a configuration object for provisioning an AmlCompute target.

refresh_state

Perform an in-place update of the properties of the object.

This method updates the properties based on the current state of the corresponding cloud object. This is primarily used for manual polling of compute state.

remove_identity

Remove the identity on the compute.

serialize

Convert this AmlCompute object into a JSON serialized dictionary.

supported_vmsizes

List the supported VM sizes in a region.

update

Update the ScaleSettings for this AmlCompute target.

update_quotas

Update quota for a VM family in workspace.

wait_for_completion

Wait for the AmlCompute cluster to finish provisioning.

This can be configured to wait for a minimum number of nodes, and to timeout after a set period of time.

add_identity

Add Identity Type and/or Identity Ids for this AmlCompute target.

add_identity(identity_type, identity_id=None)

Parameters

identity_type
string
Required

Possible values are:

  • SystemAssigned - System assigned identity

  • UserAssigned - User assigned identity. Requires identity id to be set.

identity_id
list[str]
default value: None

List of resource ids for the user assigned identity. eg. ['/subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity /userAssignedIdentities/']

Remarks

identity_id should only be specified when identity_type == UserAssigned

delete

Remove the AmlCompute object from its associated workspace.

delete()

Exceptions

Remarks

If this object was created through Azure Machine Learning, the corresponding cloud-based objects will also be deleted. If this object was created externally and only attached to the workspace, this method raises a ComputeTargetException and nothing is changed.

deserialize

Convert a JSON object into an AmlCompute object.

static deserialize(workspace, object_dict)

Parameters

workspace
Workspace
Required

The workspace object the AmlCompute object is associated with.

object_dict
dict
Required

A JSON object to convert to an AmlCompute object.

Returns

The AmlCompute representation of the provided JSON object.

Return type

Exceptions

Remarks

Raises a ComputeTargetException if the provided workspace is not the workspace the Compute is associated with.

detach

Detach is not supported for AmlCompute object. Use delete instead.

detach()

Exceptions

get

Return compute object.

get()

get_active_runs

Return a generator of the runs for this compute.

get_active_runs(type=None, tags=None, properties=None, status=None)

Parameters

type
str
default value: None

Filter the returned generator of runs by the provided type. See add_type_provider for creating run types.

tags
str or dict
default value: None

Filter runs by "tag" or {"tag": "value"}

properties
str or dict
default value: None

Filter runs by "property" or {"property": "value"}

status
str
default value: None

Run status - either "Running" or "Queued"

Returns

a generator of ~_restclient.models.RunDto

Return type

<xref:builtin.generator>

get_status

Retrieve the current detailed status for the AmlCompute cluster.

get_status()

Returns

A detailed status object for the cluster

Return type

list_nodes

Get the details (e.g., IP address, port, etc.) of all the compute nodes in the compute target.

list_nodes()

Returns

The details of all the compute nodes in the compute target.

Return type

list_quotas

Get the currently assigned Workspace quotas based on VMFamily for given workspace and subscription.

static list_quotas(workspace, location=None)

Parameters

workspace
Workspace
Required
location
str
default value: None

The location of the quotas. If not specified, will default to workspace location.

Returns

List of currently assigned Workspace Quotas based on VMFamily

Return type

list_usages

Get the current usage information as well as limits for AML resources for given workspace and subscription.

static list_usages(workspace, show_all=False, location=None)

Parameters

workspace
Workspace
Required
show_all
default value: False

Specifies if detailed usages of child resources are required. Defaults to False

location
str
default value: None

The location of the resources. If not specified, will default to workspace location.

Returns

List of current usage information as well as limits for AML resources

Return type

provisioning_configuration

Create a configuration object for provisioning an AmlCompute target.

static provisioning_configuration(vm_size='', vm_priority='dedicated', min_nodes=0, max_nodes=None, idle_seconds_before_scaledown=1800, admin_username=None, admin_user_password=None, admin_user_ssh_key=None, vnet_resourcegroup_name=None, vnet_name=None, subnet_name=None, tags=None, description=None, remote_login_port_public_access='NotSpecified', identity_type=None, identity_id=None, location=None, enable_node_public_ip=True)

Parameters

vm_size
str
Required

The size of agent VMs. More details can be found here: https://aka.ms/azureml-vm-details. Note that not all sizes are available in all regions, as detailed in the previous link. If not specified, defaults to Standard_NC6.

vm_priority
str
default value: dedicated

The VM priority, dedicated or lowpriority.

min_nodes
int
default value: 0

The minimum number of nodes to use on the cluster. If not specified, defaults to 0.

max_nodes
int
default value: None

The maximum number of nodes to use on the cluster. If not specified, defaults to 4.

idle_seconds_before_scaledown
int
default value: 1800

Node idle time in seconds before scaling down the cluster. If not specified, defaults to 1800.

admin_username
str
default value: None

The name of the administrator user account which can be used to SSH into nodes.

admin_user_password
str
default value: None

The password of the administrator user account.

admin_user_ssh_key
str
default value: None

The SSH public key of the administrator user account.

vnet_resourcegroup_name
str
default value: None

The name of the resource group where the virtual network is located.

vnet_name
str
default value: None

The name of the virtual network.

subnet_name
str
default value: None

The name of the subnet inside the VNet.

tags
dict[str, str]
default value: None

A dictionary of key value tags to provide to the compute object.

description
str
default value: None

A description to provide to the compute object.

remote_login_port_public_access
str
default value: NotSpecified

State of the public SSH port. Possible values are:

  • Disabled - Indicates that the public ssh port is closed on all nodes of the cluster.

  • Enabled - Indicates that the public ssh port is open on all nodes of the cluster.

  • NotSpecified - Indicates that the public ssh port is closed on all nodes of the cluster if VNet is defined, else is open all public nodes. It can be this default value only during cluster creation time. After creation, it will be either enabled or disabled.

identity_type
string
default value: None

Possible values are:

  • SystemAssigned - System assigned identity

  • UserAssigned - User assigned identity. Requires identity id to be set.

identity_id
list[str]
default value: None

List of resource ids for the user assigned identity. eg. ['/subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities/']

location
str
default value: None

Location to provision cluster in.

enable_node_public_ip
bool
default value: True

Enable node public IP. Possible values are:

  • True - Enable node public IP.

  • False - Disable node public IP.

  • NotSpecified - Enable node public IP.

Returns

A configuration object to be used when creating a Compute object.

Return type

Exceptions

refresh_state

Perform an in-place update of the properties of the object.

This method updates the properties based on the current state of the corresponding cloud object. This is primarily used for manual polling of compute state.

refresh_state()

remove_identity

Remove the identity on the compute.

remove_identity(identity_id=None)

Parameters

identity_id
list[str]
default value: None

User assigned identities

Remarks

System Assigned identity will be removed automatically if identity_id is not specified

serialize

Convert this AmlCompute object into a JSON serialized dictionary.

serialize()

Returns

The JSON representation of this AmlCompute object.

Return type

supported_vmsizes

List the supported VM sizes in a region.

static supported_vmsizes(workspace, location=None)

Parameters

workspace
Workspace
Required
location
str
default value: None

The location of cluster. If not specified, will default to workspace location.

Returns

A list of supported VM sizes in a region with names of the VM, VCPUs, and RAM.

Return type

update

Update the ScaleSettings for this AmlCompute target.

update(min_nodes=None, max_nodes=None, idle_seconds_before_scaledown=None)

Parameters

min_nodes
int
default value: None

The minimum number of nodes to use on the cluster.

max_nodes
int
default value: None

The maximum number of nodes to use on the cluster.

idle_seconds_before_scaledown
int
default value: None

The node idle time in seconds before scaling down the cluster.

update_quotas

Update quota for a VM family in workspace.

static update_quotas(workspace, vm_family, limit=None, location=None)

Parameters

workspace
Workspace
Required
vm_family
str
Required

VM family name

limit
int
default value: None

The maximum permitted quota of the resource

location
str
default value: None

The location of the quota. If not specified, will default to workspace location.

wait_for_completion

Wait for the AmlCompute cluster to finish provisioning.

This can be configured to wait for a minimum number of nodes, and to timeout after a set period of time.

wait_for_completion(show_output=False, min_node_count=None, timeout_in_minutes=25, is_delete_operation=False)

Parameters

show_output
bool
default value: False

Boolean to provide more verbose output.

min_node_count
int
default value: None

Minimum number of nodes to wait for before considering provisioning to be complete. This doesn't have to equal the minimum number of nodes that the compute was provisioned with, however it should not be greater than that.

timeout_in_minutes
int
default value: 25

The duration in minutes to wait before considering provisioning to have failed.

is_delete_operation
bool
default value: False

Indicates whether the operation is meant for deleting.

Exceptions