RemoteCompute 类

管理用于 Azure 机器学习的远程计算目标。

Azure 机器学习支持使用将远程计算资源附加到工作区。 只要 Azure 机器学习可以访问该资源,远程资源就可以是 Azure VM、组织中的远程服务器或本地。 有关详细信息,请参阅 什么是 Azure 机器学习中的计算目标?

类 ComputeTarget 构造函数。

检索与提供的工作区关联的计算对象的云表示形式。 返回与检索的计算对象的特定类型对应的子类的实例。

构造函数

RemoteCompute(workspace, name)

参数

名称 说明
workspace
必需

包含要检索的 RemoteCompute 对象的工作区对象。

name
必需
str

要检索的 RemoteCompute 对象的名称。

workspace
必需

包含要检索的 Compute 对象的工作区对象。

name
必需
str

要检索的 Compute 对象的名称。

注解

以下 Azure 区域不支持使用虚拟机或 HDInsight 群集的公共 IP 地址来附加计算目标。

  • 美国东部

  • 美国西部 2

  • 美国中南部

请改用 VM 或 HDInsight 群集的 Azure 资源管理器 ID。 可以使用以下字符串格式使用订阅 ID、资源组名称和 VM 名称构造 VM 的资源 ID:/subscriptions/subscription_id</resourceGroups>/<resource_group>/providers/Microsoft.Compute/virtualMachines/<vm_name>。

以下示例演示如何创建 Data Science Virtual Machine 并将其附加为计算目标。


   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)

完整示例可从 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/training/train-on-remote-vm/train-on-remote-vm.ipynb

方法

attach

荒废的。 请改用该方法 attach_configuration

将现有远程计算资源与提供的工作区相关联。

attach_configuration

创建用于附加远程计算目标的配置对象。

不再支持使用 VM 的公共 IP 地址附加虚拟机。 请改用 VM 的 resourceId。 可以使用以下字符串格式构造 VM 的 resourceId:“/subscriptions/subscription_id/<resourceGroups/>resource_group<>/ providers/Microsoft.Compute/virtualMachines/<vm_name>”。

还可以在不构造 resourceId 的情况下使用subscription_id、resource_group和vm_name。 有关详细信息,请参阅 https://aka.ms/azureml-compute-vm

delete

RemoteCompute 对象不支持删除。 请改用 detach

deserialize

将 JSON 对象转换为 RemoteCompute 对象。

detach

从其关联的工作区中分离 RemoteCompute 对象。

基础云对象不会被删除,只会删除关联。

get_credentials

检索 RemoteCompute 目标的凭据。

refresh_state

对对象的属性执行就地更新。

此方法根据相应云对象的当前状态更新属性。 这主要用于手动轮询计算状态。

serialize

将此 RemoteCompute 对象转换为 JSON 序列化字典。

attach

荒废的。 请改用该方法 attach_configuration

将现有远程计算资源与提供的工作区相关联。

static attach(workspace, name, username, address, ssh_port=22, password='', private_key_file='', private_key_passphrase='')

参数

名称 说明
workspace
必需

要与计算资源关联的工作区对象。

name
必需
str

要与提供的工作区中的计算资源关联的名称。 不必与要附加的计算资源的名称匹配。

username
必需
str

访问资源所需的用户名。

address
必需
str

要附加的资源的地址。

ssh_port
int

资源的公开端口。 默认值为 22。

默认值: 22
password
必需
str

访问资源所需的密码。

private_key_file
必需
str

包含资源的私钥的文件的路径。

private_key_passphrase
必需
str

访问资源所需的私钥短语。

返回

类型 说明

计算对象的 RemoteCompute 对象表示形式。

例外

类型 说明

attach_configuration

创建用于附加远程计算目标的配置对象。

不再支持使用 VM 的公共 IP 地址附加虚拟机。 请改用 VM 的 resourceId。 可以使用以下字符串格式构造 VM 的 resourceId:“/subscriptions/subscription_id/<resourceGroups/>resource_group<>/ providers/Microsoft.Compute/virtualMachines/<vm_name>”。

还可以在不构造 resourceId 的情况下使用subscription_id、resource_group和vm_name。 有关详细信息,请参阅 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='')

参数

名称 说明
username
必需
str

访问资源所需的用户名。

subscription_id
str

虚拟机所在的 Azure 订阅 ID。

默认值: None
resource_group
str

虚拟机所在的资源组的名称。

默认值: None
vm_name
str

虚拟机名称。

默认值: None
resource_id
str

现有资源的 Azure 资源管理器 (ARM) 资源 ID。

默认值: None
address
str

现有资源的地址。

默认值: None
ssh_port
int

资源的公开端口。 默认值为 22。

默认值: 22
password
必需
str

访问资源所需的密码。

private_key_file
必需
str

包含资源的私钥的文件的路径。

private_key_passphrase
必需
str

访问资源所需的私钥短语。

返回

类型 说明

附加计算对象时要使用的配置对象。

delete

RemoteCompute 对象不支持删除。 请改用 detach

delete()

例外

类型 说明

deserialize

将 JSON 对象转换为 RemoteCompute 对象。

static deserialize(workspace, object_dict)

参数

名称 说明
workspace
必需

RemoteCompute 对象与之关联的工作区对象。

object_dict
必需

要转换为 RemoteCompute 对象的 JSON 对象。

返回

类型 说明

提供的 JSON 对象的 RemoteCompute 表示形式。

例外

类型 说明

注解

如果提供的工作区不是计算与之关联的工作区,则引发该 ComputeTargetException 工作区。

detach

从其关联的工作区中分离 RemoteCompute 对象。

基础云对象不会被删除,只会删除关联。

detach()

例外

类型 说明

get_credentials

检索 RemoteCompute 目标的凭据。

get_credentials()

返回

类型 说明

RemoteCompute 目标的凭据。

例外

类型 说明

refresh_state

对对象的属性执行就地更新。

此方法根据相应云对象的当前状态更新属性。 这主要用于手动轮询计算状态。

refresh_state()

serialize

将此 RemoteCompute 对象转换为 JSON 序列化字典。

serialize()

返回

类型 说明

此 RemoteCompute 对象的 JSON 表示形式。