RemoteCompute Class
Manages a remote compute target for use in Azure Machine Learning.
Azure Machine Learning supports using attaching a remote compute resource to your workspace. The remote resource can can be an Azure VM, a remote server in your organization, or on-premises, as long as the resource is accessible to Azure Machine Learning. 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
-
RemoteCompute
Constructor
RemoteCompute(workspace, name)
Parameters
Remarks
The following Azure regions do not support using the public IP address of a virtual machine or HDInsight cluster to attach the compute target.
US East
US West 2
US South Central
Instead, use the Azure Resource Manager ID of the VM or HDInsight cluster. The resource ID of the VM can be constructed using the subscription ID, resource group name, and VM name using the following string format: /subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>.
The following example show how to create and attach a Data Science Virtual Machine (DSVM) as a compute target.
from azureml.core.compute import ComputeTarget, RemoteCompute
from azureml.core.compute_target import ComputeTargetException
username = os.getenv('AZUREML_DSVM_USERNAME', default='<my_username>')
address = os.getenv('AZUREML_DSVM_ADDRESS', default='<ip_address_or_fqdn>')
compute_target_name = 'cpudsvm'
# if you want to connect using SSH key instead of username/password you can provide parameters private_key_file and private_key_passphrase
try:
attached_dsvm_compute = RemoteCompute(workspace=ws, name=compute_target_name)
print('found existing:', attached_dsvm_compute.name)
except ComputeTargetException:
attach_config = RemoteCompute.attach_configuration(address=address,
ssh_port=22,
username=username,
private_key_file='./.ssh/id_rsa')
# Attaching a virtual machine using the public IP address of the VM is no longer supported.
# Instead, use resourceId of the VM.
# The resourceId of the VM can be constructed using the following string format:
# /subscriptions/<subscription_id>/resourceGroups/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>.
# You can also use subscription_id, resource_group and vm_name without constructing resourceId.
attach_config = RemoteCompute.attach_configuration(resource_id='<resource_id>',
ssh_port=22,
username='username',
private_key_file='./.ssh/id_rsa')
attached_dsvm_compute = ComputeTarget.attach(ws, compute_target_name, attach_config)
attached_dsvm_compute.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-remote-vm/train-on-remote-vm.ipynb
Methods
attach |
DEPRECATED. Use the Associate an existing remote compute resource with the provided workspace. |
attach_configuration |
Create a configuration object for attaching a remote compute target. Attaching a virtual machine using the public IP address of the VM is no longer supported. Instead, use the resourceId of the VM. The resourceId of the VM can be constructed using the following string format: "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/ providers/Microsoft.Compute/virtualMachines/<vm_name>". You can also use subscription_id, resource_group and vm_name without constructing resourceId. For more information, see https://aka.ms/azureml-compute-vm. |
delete |
Delete is not supported for a RemoteCompute object. Use detach instead. |
deserialize |
Convert a JSON object into a RemoteCompute object. |
detach |
Detach the RemoteCompute object from its associated workspace. Underlying cloud objects are not deleted, only the association is removed. |
get_credentials |
Retrieve the credentials for the RemoteCompute 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. |
serialize |
Convert this RemoteCompute object into a JSON serialized dictionary. |
attach
DEPRECATED. Use the attach_configuration
method instead.
Associate an existing remote compute resource with the provided workspace.
static attach(workspace, name, username, address, ssh_port=22, password='', private_key_file='', private_key_passphrase='')
Parameters
- name
- str
The name to associate with the compute resource inside the provided workspace. Does not have to match the name of the compute resource to be attached.
Returns
A RemoteCompute object representation of the compute object.
Return type
Exceptions
attach_configuration
Create a configuration object for attaching a remote compute target.
Attaching a virtual machine using the public IP address of the VM is no longer supported. Instead, use the resourceId of the VM. The resourceId of the VM can be constructed using the following string format: "/subscriptions/<subscription_id>/resourceGroups/<resource_group>/ providers/Microsoft.Compute/virtualMachines/<vm_name>".
You can also use subscription_id, resource_group and vm_name without constructing resourceId. For more information, see https://aka.ms/azureml-compute-vm.
static attach_configuration(username, subscription_id=None, resource_group=None, vm_name=None, resource_id=None, address=None, ssh_port=22, password='', private_key_file='', private_key_passphrase='')
Parameters
- subscription_id
- str
The Azure subscription ID in which virtual machine is located.
- resource_group
- str
The name of the resource group in which virtual machine is located.
- resource_id
- str
The Azure Resource Manager (ARM) resource ID for the existing resource.
Returns
A configuration object to be used when attaching a Compute object.
Return type
Exceptions
delete
deserialize
Convert a JSON object into a RemoteCompute object.
static deserialize(workspace, object_dict)
Parameters
Returns
The RemoteCompute 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 RemoteCompute object from its associated workspace.
Underlying cloud objects are not deleted, only the association is removed.
detach()
Exceptions
get_credentials
Retrieve the credentials for the RemoteCompute target.
get_credentials()
Returns
The credentials for the RemoteCompute target.
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()
Exceptions
serialize
Convert this RemoteCompute object into a JSON serialized dictionary.
serialize()
Returns
The JSON representation of this RemoteCompute object.
Return type
Exceptions
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for