ComputeTarget 類別
Azure Machine Learning 所管理之所有計算目標的抽象父類別。
計算目標是您執行定型腳本或裝載服務部署的指定計算資源/環境。 此位置可能是本機電腦或雲端式計算資源。 如需詳細資訊,請參閱 什麼是 Azure Machine Learning 中的計算目標?
類別 ComputeTarget 建構函式。
擷取與所提供工作區相關聯的 Compute 物件的雲端表示法。 傳回對應至所擷取之 Compute 物件特定型別之子類別的實例。
建構函式
ComputeTarget(workspace, name)
參數
名稱 | Description |
---|---|
workspace
必要
|
包含要擷取之 Compute 物件的工作區物件。 |
name
必要
|
要擷取的 Compute 物件名稱。 |
workspace
必要
|
包含要擷取之 Compute 物件的工作區物件。 |
name
必要
|
要擷取之 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)
參數
名稱 | Description |
---|---|
workspace
必要
|
要附加 Compute 物件的工作區物件。 |
name
必要
|
要與 Compute 對象產生關聯的名稱。 |
attach_configuration
必要
|
ComputeTargetAttachConfiguration 物件,用來判斷要附加的 Compute 物件類型,以及如何進行設定。 |
傳回
類型 | Description |
---|---|
ComputeTarget 子系的實例,對應至附加的物件類型。 |
例外狀況
類型 | Description |
---|---|
備註
要傳遞至 參數 attach_configuration
的物件類型,是 ComputeTargetAttachConfiguration 使用 attach_configuration
函式建置在 的任何 子類別 ComputeTarget上的物件。
下列範例示範如何使用 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))
create
藉由指定計算類型和相關的組態來布建 Compute 物件。
此方法會建立新的計算目標,而不是附加現有的計算目標。
static create(workspace, name, provisioning_configuration)
參數
名稱 | Description |
---|---|
workspace
必要
|
要建立計算物件的工作區物件。 |
name
必要
|
要與 Compute 對象產生關聯的名稱。 |
provisioning_configuration
必要
|
ComputeTargetProvisioningConfiguration 物件,用來判斷要布建的 Compute 物件類型,以及如何進行設定。 |
傳回
類型 | Description |
---|---|
ComputeTarget 子系的實例,對應至布建的物件類型。 |
例外狀況
類型 | Description |
---|---|
備註
布建的物件類型取決於提供的布建組態。
在下列範例中,會建立 所 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)
delete
從其相關聯的工作區中移除 Compute 物件。
這個抽象方法是由的 ComputeTarget子類別實作。
abstract delete()
備註
如果此對像是透過 Azure Machine Learning 建立的,也會刪除對應的雲端式物件。 如果這個物件是在外部建立,而且只附加至工作區,這個方法會引發例外狀況,而且不會變更任何專案。
deserialize
將 JSON 物件轉換成 Compute 物件。
abstract static deserialize(workspace, object_dict)
參數
名稱 | Description |
---|---|
workspace
必要
|
Compute 對象相關聯的工作區物件。 |
object_dict
必要
|
要轉換成 Compute 物件的 JSON 物件。 |
傳回
類型 | Description |
---|---|
所提供 JSON 對象的計算表示法。 |
備註
ComputeTargetException如果提供的工作區不是計算相關聯的工作區,則引發 。
detach
get_status
擷取 Compute 物件的目前布建狀態。
get_status()
傳回
類型 | Description |
---|---|
目前的 |
備註
傳回的值會列在 ProvisioningState 的 Azure REST API 參考中。
list
列出工作區中的所有 ComputeTarget 物件。
傳回對應至特定計算類型的具現化子物件清單。 物件是 的 ComputeTarget子系。
static list(workspace)
參數
名稱 | Description |
---|---|
workspace
必要
|
包含要列出之物件的工作區物件。 |
傳回
類型 | Description |
---|---|
工作區內的計算目標清單。 |
例外狀況
類型 | Description |
---|---|
refresh_state
執行物件的屬性就地更新。
根據對應雲端物件的目前狀態更新屬性。 這對於手動輪詢計算狀態很有用。
這個抽象方法是由的 ComputeTarget子類別實作。
abstract refresh_state()
serialize
wait_for_completion
等候目前的布建作業在叢集上完成。
如果輪詢計算物件時發生問題,這個方法會 ComputeTargetException 傳回 。
wait_for_completion(show_output=False, is_delete_operation=False)
參數
名稱 | Description |
---|---|
show_output
|
指出是否要提供更詳細的輸出。 預設值: False
|
is_delete_operation
|
指出作業是否要刪除。 預設值: False
|
例外狀況
類型 | Description |
---|---|