ComputeTarget class

Definition

Abstract parent class for all compute targets managed by Azure Machine Learning service.

A compute target is a designated compute resource/environment where you run your training script or host your service deployment. This location may be your local machine or a cloud-based compute resource. For more information, see What are compute targets in Azure Machine Learning?

ComputeTarget(workspace, name)
Inheritance
builtins.object
ComputeTarget

Parameters

workspace
Workspace

The workspace object containing the Compute object to retrieve.

name
str

The name of the of the Compute object to retrieve.

Remarks

Use the ComputeTarget constructor to retrieve the cloud representation of a Compute object associated with the provided workspace. The constructor returns an instance of a child class corresponding to the specific type of the retrieved Compute object. If the Compute object is not found, a ComputeTargetException is raised.

Methods

attach(workspace, name, attach_configuration)

Attach a Compute object to a workspace using the specified name and configuration information.

create(workspace, name, provisioning_configuration)

Provision a Compute object by specifying a compute type and related configuration.

This method creates a new compute target rather than attaching an existing one.

delete()

Remove the Compute object from its associated workspace.

This abstract method is implemented by child classes of ComputeTarget.

deserialize(workspace, object_dict)

Convert a JSON object into a Compute object.

detach()

Detach the Compute object from its associated workspace.

This abstract method is implemented by child classes of ComputeTarget. Underlying cloud objects are not deleted, only their associations are removed.

get_status()

Retrieve the current provisioning state of the Compute object.

list(workspace)

List all ComputeTarget objects within the workspace.

Return a list of instantiated child objects corresponding to the specific type of Compute. Objects are children of ComputeTarget.

refresh_state()

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

Update properties based on the current state of the corresponding cloud object. This is useful for manual polling of compute state.

This abstract method is implemented by child classes of ComputeTarget.

serialize()

Convert this Compute object into a JSON serialized dictionary.

wait_for_completion(show_output=False)

Wait for the current provisioning operation to finish on the cluster.

This method returns a ComputeTargetException if there is a problem polling the compute object.

attach(workspace, name, attach_configuration)

Attach a Compute object to a workspace using the specified name and configuration information.

attach(workspace, name, attach_configuration)

Parameters

workspace
Workspace

The workspace object to attach the Compute object to.

name
str

The name to associate with the Compute object.

attach_configuration
ComputeTargetAttachConfiguration

A ComputeTargetAttachConfiguration object that is used to determine the type of Compute object to attach, and how to configure it.

Returns

An instance of a child of ComputeTarget corresponding to the type of object attached.

Return type

Exceptions

Remarks

The type of object to pass to the parameter attach_configuration is a ComputeTargetAttachConfiguration object built using the attach_configuration function on any of the child classes of ComputeTarget.

The following example shows how to attach an ADLA account to a workspace using the attach_configuration(resource_group=None, account_name=None, resource_id=None) method of AdlaCompute.


   adla_compute_name = 'testadl' # Name to associate with new compute in workspace

   # ADLA account details needed to attach as compute to workspace
   adla_account_name = "<adla_account_name>" # Name of the Azure Data Lake Analytics account
   adla_resource_group = "<adla_resource_group>" # Name of the resource group which contains this account

   try:
       # check if already attached
       adla_compute = AdlaCompute(ws, adla_compute_name)
   except ComputeTargetException:
       print('attaching adla compute...')
       attach_config = AdlaCompute.attach_configuration(resource_group=adla_resource_group, account_name=adla_account_name)
       adla_compute = ComputeTarget.attach(ws, adla_compute_name, attach_config)
       adla_compute.wait_for_completion()

   print("Using ADLA compute:{}".format(adla_compute.cluster_resource_id))
   print("Provisioning state:{}".format(adla_compute.provisioning_state))
   print("Provisioning errors:{}".format(adla_compute.provisioning_errors))

Full sample is available from https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-use-adla-as-compute-target.ipynb

create(workspace, name, provisioning_configuration)

Provision a Compute object by specifying a compute type and related configuration.

This method creates a new compute target rather than attaching an existing one.

create(workspace, name, provisioning_configuration)

Parameters

workspace
Workspace

The workspace object to create the Compute object under.

name
str

The name to associate with the Compute object.

provisioning_configuration
ComputeTargetProvisioningConfiguration

A ComputeTargetProvisioningConfiguration object that is used to determine the type of Compute object to provision, and how to configure it.

Returns

An instance of a child of ComputeTarget corresponding to the type of object provisioned.

Return type

Exceptions

Remarks

The type of object provisioned is determined by the provisioning configuration provided.

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


   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

delete()

Remove the Compute object from its associated workspace.

This abstract method is implemented by child classes of ComputeTarget.

delete()

Exceptions

Remarks

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

deserialize(workspace, object_dict)

Convert a JSON object into a Compute object.

deserialize(workspace, object_dict)

Parameters

workspace
Workspace

The workspace object the Compute object is associated with.

object_dict
dict

A JSON object to convert to a Compute object.

Returns

The Compute 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 the Compute object from its associated workspace.

This abstract method is implemented by child classes of ComputeTarget. Underlying cloud objects are not deleted, only their associations are removed.

detach()

Exceptions

get_status()

Retrieve the current provisioning state of the Compute object.

get_status()

Returns

The current provisioning_state.

Return type

str

Exceptions

list(workspace)

List all ComputeTarget objects within the workspace.

Return a list of instantiated child objects corresponding to the specific type of Compute. Objects are children of ComputeTarget.

list(workspace)

Parameters

workspace
Workspace

The workspace object containing the objects to list.

Returns

List of compute targets within the workspace.

Return type

Exceptions

refresh_state()

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

Update properties based on the current state of the corresponding cloud object. This is useful for manual polling of compute state.

This abstract method is implemented by child classes of ComputeTarget.

refresh_state()

Exceptions

serialize()

Convert this Compute object into a JSON serialized dictionary.

serialize()

Returns

The JSON representation of this Compute object.

Return type

Exceptions

wait_for_completion(show_output=False)

Wait for the current provisioning operation to finish on the cluster.

This method returns a ComputeTargetException if there is a problem polling the compute object.

wait_for_completion(show_output=False)

Parameters

show_output
bool

Indicates whether to provide more verbose output.

default value: False

Exceptions