ComputeInstance Class

Manages a cloud-based, optimized ML development environment in Azure Machine Learning.

An Azure Machine Learning compute instance is a fully-configured and managed development environment in the cloud that is optimized for machine learning development workflows. ComputeInstance is typically used to create a development environment or as a compute target for training and inference for development and testing. With a ComputeInstance you can author, train, and deploy models in a fully integrated notebook experience in your workspace. For more information, see What is an Azure Machine Learning compute instance?.

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
ComputeInstance

Constructor

ComputeInstance(workspace, name)

Parameters

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.

Methods

delete

Remove the ComputeInstance object from its associated workspace.

deserialize

Convert a JSON object into a ComputeInstance object.

This fails if the provided workspace is not the workspace the ComputeInstance is associated with.

detach

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

get

Return ComputeInstance object.

get_active_runs

Return a generator of the runs for this compute.

get_docs_url

Url to the documentation for this class.

get_status

Retrieve the current detailed status for the ComputeInstance.

provisioning_configuration

Create a configuration object for provisioning a ComputeInstance 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 useful for manual polling of compute state.

restart

Restart the ComputeInstance.

serialize

Convert this ComputeInstance object into a JSON serialized dictionary.

start

Start the ComputeInstance.

stop

Stop the ComputeInstance.

supported_vmsizes

List the supported VM sizes in a region.

wait_for_completion

Wait for the ComputeInstance to finish provisioning.

delete

Remove the ComputeInstance object from its associated workspace.

delete(wait_for_completion=False, show_output=False)

Parameters

wait_for_completion
default value: False
show_output
default value: False

Exceptions

Remarks

If this object was created through Azure ML, the corresponding cloud based objects will also be deleted. If this object was created externally and only attached to the workspace, it will raise exception and nothing will be changed.

deserialize

Convert a JSON object into a ComputeInstance object.

This fails if the provided workspace is not the workspace the ComputeInstance is associated with.

static deserialize(workspace, object_dict)

Parameters

workspace
Workspace
Required

The workspace object the ComputeInstance object is associated with.

object_dict
dict
Required

A JSON object to convert to a ComputeInstance object.

Returns

The ComputeInstance representation of the provided JSON object.

Return type

Exceptions

detach

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

detach()

Exceptions

The operation is not supproted.

get

Return ComputeInstance object.

get()

Returns

The ComputeInstance representation of the provided JSON object.

Return type

Exceptions

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, can be "Running" or "Queued".

Returns

A generator of azureml._restclient.models.RunDto

Return type

<xref:builtin.generator>

Exceptions

get_docs_url

Url to the documentation for this class.

get_docs_url()

Returns

url

Return type

str

Exceptions

get_status

Retrieve the current detailed status for the ComputeInstance.

get_status()

Returns

A detailed status object for the compute

Return type

Exceptions

provisioning_configuration

Create a configuration object for provisioning a ComputeInstance target.

static provisioning_configuration(vm_size='', ssh_public_access=False, admin_user_ssh_public_key=None, vnet_resourcegroup_name=None, vnet_name=None, subnet_name=None, tags=None, description=None, assigned_user_object_id=None, assigned_user_tenant_id=None)

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. Defaults to Standard_NC6.

ssh_public_access
bool
default value: False

Indicates the state of the public SSH port. Possible values are:

  • False - The public SSH port is closed.
  • True - The public SSH port is open.
admin_user_ssh_public_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

An optional dictionary of key value tags to associate with the compute object.

description
str
default value: None

An optional description for the compute object.

assigned_user_object_id
str
default value: None

The AAD Object ID of the assigned user (preview).

assigned_user_tenant_id
str
default value: None

The AAD Tenant ID of the assigned user (preview).

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 useful for manual polling of compute state.

refresh_state()

Exceptions

restart

Restart the ComputeInstance.

restart(wait_for_completion=False, show_output=False)

Parameters

wait_for_completion
bool
default value: False

Boolean to wait for the state update. Defaults to False.

show_output
bool
default value: False

Boolean to provide more verbose output. Defaults to False.

Returns

None

Return type

Exceptions

azureml.exceptions.ComputeTargetException:

serialize

Convert this ComputeInstance object into a JSON serialized dictionary.

serialize()

Returns

The JSON representation of this ComputeInstance object.

Return type

Exceptions

start

Start the ComputeInstance.

start(wait_for_completion=False, show_output=False)

Parameters

wait_for_completion
bool
default value: False

Whether to wait for the state update. Defaults to False.

show_output
bool
default value: False

Whether to provide more verbose output. Defaults to False.

Returns

None

Return type

Exceptions

stop

Stop the ComputeInstance.

stop(wait_for_completion=False, show_output=False)

Parameters

wait_for_completion
bool
default value: False

Whether to wait for the state update. Defaults to False.

show_output
bool
default value: False

Whether to provide more verbose output. Defaults to False.

Returns

None

Return type

Exceptions

supported_vmsizes

List the supported VM sizes in a region.

static supported_vmsizes(workspace, location=None)

Parameters

workspace
Workspace
Required

The workspace.

location
str
default value: None

The location of the instance. If not specified, the default is the workspace location.

Returns

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

Return type

Exceptions

wait_for_completion

Wait for the ComputeInstance to finish provisioning.

wait_for_completion(show_output=False, is_delete_operation=False)

Parameters

show_output
bool
default value: False

Whether to provide more verbose output. Defaults to False.

is_delete_operation
bool
default value: False

Indicates whether the operation is meant for deleting.

Exceptions