ComputeTarget 類別

Azure Machine Learning 所管理之所有計算目標的抽象父類別。

計算目標是您執行定型腳本或裝載服務部署的指定計算資源/環境。 這個位置可能是您的本機電腦或雲端式計算資源。 如需詳細資訊,請參閱 什麼是 Azure Machine Learning 中的計算目標?

類別 ComputeTarget 建構函式。

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

繼承
ComputeTarget

建構函式

ComputeTarget(workspace, name)

參數

workspace
Workspace
必要

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

name
str
必要

要擷取的 Compute 物件名稱。

workspace
Workspace
必要

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

name
str
必要

要擷取之 Compute 物件的 名稱。

備註

使用 ComputeTarget 建構函式擷取與所提供工作區相關聯之 Compute 物件的雲端標記法。 建構函式會傳回對應至所擷取之 Compute 物件之特定類型的子類別實例。 如果找不到 Compute 物件, ComputeTargetException 則會引發 。

方法

attach

使用指定的名稱和組態資訊,將 Compute 物件附加至工作區。

create

藉由指定計算類型和相關組態來布建 Compute 物件。

此方法會建立新的計算目標,而不是附加現有的計算目標。

delete

從其相關聯的工作區中移除 Compute 物件。

這個抽象方法是由 的 ComputeTarget 子類別所實作。

deserialize

將 JSON 物件轉換成 Compute 物件。

detach

將 Compute 物件與其相關聯的工作區中斷連結。

這個抽象方法是由 的 ComputeTarget 子類別所實作。 基礎雲端物件不會刪除,只會移除其關聯。

get_status

擷取 Compute 物件的目前布建狀態。

list

列出工作區中的所有 ComputeTarget 物件。

傳回對應至特定計算類型的具現化子物件清單。 物件是 的子系 ComputeTarget

refresh_state

執行 物件的屬性就地更新。

根據對應雲端物件的目前狀態更新屬性。 這適用于手動輪詢計算狀態。

這個抽象方法是由 的 ComputeTarget 子類別所實作。

serialize

將此 Compute 物件轉換成 JSON 序列化字典。

wait_for_completion

等候目前的布建作業在叢集上完成。

如果輪詢計算物件時發生問題,這個方法會傳 ComputeTargetException 回 。

attach

使用指定的名稱和組態資訊,將 Compute 物件附加至工作區。

static attach(workspace, name, attach_configuration)

參數

workspace
Workspace
必要

要附加 Compute 物件的工作區物件。

name
str
必要

要與 Compute 物件建立關聯的名稱。

attach_configuration
ComputeTargetAttachConfiguration
必要

ComputeTargetAttachConfiguration 物件,用來判斷要附加的 Compute 物件類型,以及如何進行設定。

傳回

對應至附加物件類型的 ComputeTarget 子系實例。

傳回類型

例外狀況

備註

要傳遞至 參數 attach_configuration 的物件類型是使用 ComputeTargetAttachConfiguration 函式在 的任何子類別 ComputeTarget 上建置 attach_configuration 的物件。

下列範例示範如何使用 AdlaCompute 的 方法來將 ADLA 帳戶附加至工作區 attach_configuration


   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))

完整範例可從 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

藉由指定計算類型和相關組態來布建 Compute 物件。

此方法會建立新的計算目標,而不是附加現有的計算目標。

static create(workspace, name, provisioning_configuration)

參數

workspace
Workspace
必要

要建立 Compute 物件的工作區物件。

name
str
必要

要與 Compute 物件建立關聯的名稱。

provisioning_configuration
ComputeTargetProvisioningConfiguration
必要

ComputeTargetProvisioningConfiguration 物件,用來判斷要布建的 Compute 物件類型,以及如何進行設定。

傳回

對應至所布建物件類型的 ComputeTarget 子系實例。

傳回類型

例外狀況

備註

布建的物件類型取決於提供的布建組態。

在下列範例中,會建立 所 AmlCompute 布建的永續性計算目標。 provisioning_configuration此範例中的 參數的類型為 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)

完整範例可從 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/training/train-on-amlcompute/train-on-amlcompute.ipynb

delete

從其相關聯的工作區中移除 Compute 物件。

這個抽象方法是由 的 ComputeTarget 子類別所實作。

abstract delete()

例外狀況

備註

如果此物件是透過 Azure Machine Learning 建立的,也會刪除對應的雲端式物件。 如果此物件是在外部建立,而且只附加至工作區,則這個方法會引發例外狀況,而且不會變更任何內容。

deserialize

將 JSON 物件轉換成 Compute 物件。

abstract static deserialize(workspace, object_dict)

參數

workspace
Workspace
必要

計算物件相關聯的工作區物件。

object_dict
dict
必要

要轉換成 Compute 物件的 JSON 物件。

傳回

所提供 JSON 物件的計算表示。

傳回類型

例外狀況

備註

ComputeTargetException如果提供的工作區不是計算相關聯的工作區,則引發 。

detach

將 Compute 物件與其相關聯的工作區中斷連結。

這個抽象方法是由 的 ComputeTarget 子類別所實作。 基礎雲端物件不會刪除,只會移除其關聯。

abstract detach()

例外狀況

get_status

擷取 Compute 物件的目前布建狀態。

get_status()

傳回

目前的 provisioning_state

傳回類型

str

例外狀況

備註

傳回的值會列在 ProvisioningState的 Azure REST API 參考中。

list

列出工作區中的所有 ComputeTarget 物件。

傳回對應至特定計算類型的具現化子物件清單。 物件是 的子系 ComputeTarget

static list(workspace)

參數

workspace
Workspace
必要

包含要列出之物件的工作區物件。

傳回

工作區內的計算目標清單。

傳回類型

例外狀況

refresh_state

執行 物件的屬性就地更新。

根據對應雲端物件的目前狀態更新屬性。 這適用于手動輪詢計算狀態。

這個抽象方法是由 的 ComputeTarget 子類別所實作。

abstract refresh_state()

例外狀況

serialize

將此 Compute 物件轉換成 JSON 序列化字典。

abstract serialize()

傳回

這個 Compute 物件的 JSON 表示。

傳回類型

例外狀況

wait_for_completion

等候目前的布建作業在叢集上完成。

如果輪詢計算物件時發生問題,這個方法會傳 ComputeTargetException 回 。

wait_for_completion(show_output=False, is_delete_operation=False)

參數

show_output
bool
預設值: False

指出是否要提供更詳細的輸出。

is_delete_operation
bool
預設值: False

指出作業是否用於刪除。

例外狀況