RemoteCompute 類別

管理遠端計算目標,以用於 Azure Machine Learning。

Azure Machine Learning 支援使用將遠端計算資源附加至您的工作區。 只要 Azure Machine Learning 可存取資源,遠端資源可以是 Azure VM、組織中的遠端伺服器或內部部署。 如需詳細資訊,請參閱 什麼是 Azure Machine Learning 中的計算目標?

類別 ComputeTarget 建構函式。

擷取與所提供工作區相關聯的 Compute 物件的雲端標記法。 傳回對應至所擷取之 Compute 物件之特定類型的子類別實例。

繼承
RemoteCompute

建構函式

RemoteCompute(workspace, name)

參數

workspace
Workspace
必要

包含要擷取之 RemoteCompute 物件的工作區物件。

name
str
必要

要擷取之 RemoteCompute 物件的 名稱。

workspace
Workspace
必要

包含要擷取之 Compute 物件的工作區物件。

name
str
必要

要擷取之 Compute 物件的 名稱。

備註

下列 Azure 區域不支援使用虛擬機器或 HDInsight 叢集的公用 IP 位址來連結計算目標。

  • 美國東部

  • 美國西部 2

  • 美國中南部

請改用 VM 或 HDInsight 叢集的 Azure Resource Manager識別碼。 您可以使用下列字串格式來建構 VM 的資源識別碼:/subscriptions/ < subscription_id/resourceGroups/ < resource_group >> /providers/Microsoft.Compute/virtualMachines/ < vm_name > 。

下列範例示範如何建立和附加資料科學虛擬機器 (DSVM) 作為計算目標。


   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 > 」。

您也可以使用subscription_id、resource_group和vm_name,而不建構 resourceId。 如需詳細資訊,請參閱 https://aka.ms/azureml-compute-vm

delete

RemoteCompute 物件不支援 Delete。 請改用 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
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 > 」。

您也可以使用subscription_id、resource_group和vm_name,而不建構 resourceId。 如需詳細資訊,請參閱 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
預設值: None

虛擬機器所在的 Azure 訂用帳戶識別碼。

resource_group
str
預設值: None

虛擬機器所在的資源組名。

vm_name
str
預設值: None

虛擬機器名稱。

resource_id
str
預設值: None

現有資源的 Azure Resource Manager (ARM) 資源識別碼。

address
str
預設值: None

現有資源的位址。

ssh_port
int
預設值: 22

資源的公開端口。 預設為 22。

password
str
必要

存取資源所需的密碼。

private_key_file
str
必要

包含資源私密金鑰的檔案路徑。

private_key_passphrase
str
必要

存取資源所需的私密金鑰片語。

傳回

附加 Compute 物件時要使用的組態物件。

傳回類型

例外狀況

delete

RemoteCompute 物件不支援 Delete。 請改用 detach

delete()

例外狀況

deserialize

將 JSON 物件轉換成 RemoteCompute 物件。

static deserialize(workspace, object_dict)

參數

workspace
Workspace
必要

RemoteCompute 物件的工作區物件與 相關聯。

object_dict
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 表示。

傳回類型

例外狀況