AmlCompute 類別

在 Azure Machine Learning 中管理 Azure Machine Learning 計算。

Azure Machine Learning Compute (AmlCompute) 是受控計算基礎結構,可讓您輕鬆地建立單一或多節點計算。 計算會在工作區區域內建立為可與其他使用者共用的資源。 如需詳細資訊,請參閱 什麼是 Azure Machine Learning 中的計算目標?

類別 ComputeTarget 建構函式。

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

繼承
AmlCompute

建構函式

AmlCompute(workspace, name)

參數

workspace
Workspace
必要

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

name
str
必要

要擷取的 AmlCompute 物件名稱。

workspace
Workspace
必要

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

name
str
必要

要擷取之 Compute 物件的 名稱。

備註

在下列範例中,會建立 所 AmlCompute 布建的持續性計算目標。 provisioning_configuration此範例中的 參數的類型為 AmlComputeProvisioningConfiguration ,這是 的 ComputeTargetProvisioningConfiguration 子類別。


   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

方法

add_identity

為此 AmlCompute 目標新增識別類型和/或識別識別碼。

delete

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

deserialize

將 JSON 物件轉換成 AmlCompute 物件。

detach

AmlCompute 物件不支援卸離。 請改用 delete

get

傳回計算物件。

get_active_runs

傳回這個計算的執行產生器。

get_status

擷取 AmlCompute 叢集目前的詳細狀態。

list_nodes

取得 (的詳細資料,例如 IP 位址、埠等) 計算目標中的所有計算節點。

list_quotas

根據指定工作區和訂用帳戶的 VMFamily 取得目前指派的工作區配額。

list_usages

取得目前使用量資訊,以及指定工作區和訂用帳戶的 AML 資源限制。

provisioning_configuration

建立組態物件以布建 AmlCompute 目標。

refresh_state

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

此方法會根據對應雲端物件的目前狀態來更新屬性。 這主要用於手動輪詢計算狀態。

remove_identity

移除計算上的身分識別。

serialize

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

supported_vmsizes

列出區域中支援的 VM 大小。

update

ScaleSettings更新這個 AmlCompute 目標的 。

update_quotas

更新工作區中 VM 系列配額。

wait_for_completion

等候 AmlCompute 叢集完成布建。

這可以設定為等候最少的節點數目,並在一段設定的時間之後逾時。

add_identity

為此 AmlCompute 目標新增識別類型和/或識別識別碼。

add_identity(identity_type, identity_id=None)

參數

identity_type
string
必要

可能的值包括:

  • SystemAssigned - 系統指派的身分識別

  • UserAssigned - 使用者指派的身分識別。 需要設定身分識別識別碼。

identity_id
list[str]
預設值: None

使用者指派身分識別的資源識別碼清單。 例如 ['/subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity /userAssignedIdentities/']

備註

只有在identity_type == UserAssigned 時,才應該指定identity_id

delete

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

delete()

例外狀況

備註

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

deserialize

將 JSON 物件轉換成 AmlCompute 物件。

static deserialize(workspace, object_dict)

參數

workspace
Workspace
必要

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

object_dict
dict
必要

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

傳回

所提供 JSON 物件的 AmlCompute 標記法。

傳回類型

例外狀況

備註

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

detach

AmlCompute 物件不支援卸離。 請改用 delete

detach()

例外狀況

get

傳回計算物件。

get()

get_active_runs

傳回這個計算的執行產生器。

get_active_runs(type=None, tags=None, properties=None, status=None)

參數

type
str
預設值: None

依提供的型別篩選所傳回的執行產生器。 如需建立執行類型,請參閱 add_type_provider

tags
strdict
預設值: None

依 「tag」 或 {「tag」: 「value」} 篩選執行

properties
strdict
預設值: None

依 「property」 或 {「property」 篩選執行:「value」}

status
str
預設值: None

執行狀態 - 「執行中」或「已排入佇列」

傳回

~_restclient.models.RunDto 的產生器

傳回類型

<xref:builtin.generator>

get_status

擷取 AmlCompute 叢集目前的詳細狀態。

get_status()

傳回

叢集的詳細狀態物件

傳回類型

list_nodes

取得 (的詳細資料,例如 IP 位址、埠等) 計算目標中的所有計算節點。

list_nodes()

傳回

計算目標中所有計算節點的詳細資料。

傳回類型

list_quotas

根據指定工作區和訂用帳戶的 VMFamily 取得目前指派的工作區配額。

static list_quotas(workspace, location=None)

參數

workspace
Workspace
必要
location
str
預設值: None

配額的位置。 如果未指定,則會預設為工作區位置。

傳回

根據 VMFamily 目前指派的工作區配額清單

傳回類型

list_usages

取得目前使用量資訊,以及指定工作區和訂用帳戶的 AML 資源限制。

static list_usages(workspace, show_all=False, location=None)

參數

workspace
Workspace
必要
show_all
預設值: False

指定是否需要子資源的詳細使用方式。 預設為 False

location
str
預設值: None

資源的位置。 如果未指定,則會預設為工作區位置。

傳回

目前使用量資訊的清單以及 AML 資源的限制

傳回類型

provisioning_configuration

建立組態物件以布建 AmlCompute 目標。

static provisioning_configuration(vm_size='', vm_priority='dedicated', min_nodes=0, max_nodes=None, idle_seconds_before_scaledown=1800, admin_username=None, admin_user_password=None, admin_user_ssh_key=None, vnet_resourcegroup_name=None, vnet_name=None, subnet_name=None, tags=None, description=None, remote_login_port_public_access='NotSpecified', identity_type=None, identity_id=None, location=None, enable_node_public_ip=True)

參數

vm_size
str
必要

代理程式 VM 的大小。 如需詳細資訊,請參閱: https://aka.ms/azureml-vm-details 。 請注意,並非所有大小都可在所有區域中使用,如上一個連結中所述。 如果未指定,預設為 Standard_NC6。

vm_priority
str
預設值: dedicated

VM 優先順序、 專用低許可權

min_nodes
int
預設值: 0

要在叢集上使用的節點數目下限。 如果未指定,則預設為 0。

max_nodes
int
預設值: None

要在叢集上使用的節點數目上限。 如果未指定,則預設為 4。

idle_seconds_before_scaledown
int
預設值: 1800

縮小叢集之前的節點閒置時間 (秒)。 如果未指定,則預設為 1800。

admin_username
str
預設值: None

可用來透過 SSH 連線到節點的系統管理員使用者帳戶名稱。

admin_user_password
str
預設值: None

管理員使用者帳戶的密碼。

admin_user_ssh_key
str
預設值: None

管理員使用者帳戶的 SSH 公開金鑰。

vnet_resourcegroup_name
str
預設值: None

虛擬網路所在的資源組名。

vnet_name
str
預設值: None

虛擬網路的名稱。

subnet_name
str
預設值: None

VNet 內子網的名稱。

tags
dict[str, str]
預設值: None

要提供給計算物件的索引鍵值標記字典。

description
str
預設值: None

要提供給計算物件的描述。

remote_login_port_public_access
str
預設值: NotSpecified

公用 SSH 埠的狀態。 可能的值包括:

  • 已停用 - 指出叢集的所有節點上已關閉公用 SSH 埠。

  • 已啟用 - 指出叢集的所有節點上都已開啟公用 SSH 埠。

  • NotSpecified - 指出如果已定義 VNet,則叢集的所有節點上都會關閉公用 SSH 埠,否則會開啟所有公用節點。 它只能在叢集建立期間使用這個預設值。 建立之後,將會啟用或停用。

identity_type
string
預設值: None

可能的值包括:

  • SystemAssigned - 系統指派的身分識別

  • UserAssigned - 使用者指派的身分識別。 需要設定身分識別識別碼。

identity_id
list[str]
預設值: None

使用者指派身分識別的資源識別碼清單。 例如 ['/subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities/']

location
str
預設值: None

布建叢集的位置。

enable_node_public_ip
bool
預設值: True

啟用節點公用 IP。 可能的值包括:

  • True - 啟用節點公用 IP。

  • False - 停用節點公用 IP。

  • NotSpecified - 啟用節點公用 IP。

傳回

建立 Compute 物件時要使用的組態物件。

傳回類型

例外狀況

refresh_state

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

此方法會根據對應雲端物件的目前狀態來更新屬性。 這主要用於手動輪詢計算狀態。

refresh_state()

remove_identity

移除計算上的身分識別。

remove_identity(identity_id=None)

參數

identity_id
list[str]
預設值: None

使用者指派的身分識別

備註

如果未指定identity_id,系統指派的身分識別會自動移除

serialize

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

serialize()

傳回

這個 AmlCompute 物件的 JSON 表示。

傳回類型

supported_vmsizes

列出區域中支援的 VM 大小。

static supported_vmsizes(workspace, location=None)

參數

workspace
Workspace
必要
location
str
預設值: None

叢集的位置。 如果未指定,則會預設為工作區位置。

傳回

區域中支援的 VM 大小清單,其中包含 VM、VCPU 和 RAM 的名稱。

傳回類型

update

ScaleSettings更新這個 AmlCompute 目標的 。

update(min_nodes=None, max_nodes=None, idle_seconds_before_scaledown=None)

參數

min_nodes
int
預設值: None

要在叢集上使用的節點數目下限。

max_nodes
int
預設值: None

要在叢集上使用的節點數目上限。

idle_seconds_before_scaledown
int
預設值: None

相應減少叢集之前的節點閒置時間,以秒為單位。

update_quotas

更新工作區中 VM 系列配額。

static update_quotas(workspace, vm_family, limit=None, location=None)

參數

workspace
Workspace
必要
vm_family
str
必要

VM 系列名稱

limit
int
預設值: None

資源允許的配額上限

location
str
預設值: None

配額的位置。 如果未指定,則會預設為工作區位置。

wait_for_completion

等候 AmlCompute 叢集完成布建。

這可以設定為等候最少的節點數目,並在一段設定的時間之後逾時。

wait_for_completion(show_output=False, min_node_count=None, timeout_in_minutes=25, is_delete_operation=False)

參數

show_output
bool
預設值: False

布林值以提供更詳細的輸出。

min_node_count
int
預設值: None

在考慮布建完成之前,要等候的節點數目下限。 這不一定等於已布建計算的最小節點數目,但不應該大於該數目。

timeout_in_minutes
int
預設值: 25

在考慮布建失敗之前,等候幾分鐘的持續時間。

is_delete_operation
bool
預設值: False

指出作業是否要刪除。

例外狀況