AmlCompute 类

在 Azure 机器学习中管理 Azure 机器学习计算。

Azure 机器学习计算 (AmlCompute) 是托管的计算基础结构,可轻松创建单节点或多节点计算。 该计算是在工作区区域内创建的资源,可与其他用户共享。 有关详细信息,请参阅什么是 Azure 机器学习中的计算目标?

类 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 目标添加标识类型和/或标识 ID。

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

更新此 AmlCompute 目标的 ScaleSettings

update_quotas

更新工作区中 VM 系列的配额。

wait_for_completion

等待 AmlCompute 群集完成预配。

这可以配置为等待最小数量的节点,并在设定的时间段后超时。

add_identity

为此 AmlCompute 目标添加标识类型和/或标识 ID。

add_identity(identity_type, identity_id=None)

参数

identity_type
string
必需

可能的值包括:

  • SystemAssigned - 系统分配的标识

  • UserAssigned - 用户分配的标识。 需要设置标识 ID。

identity_id
list[str]
默认值: None

用户分配标识的资源 ID 列表。 例如 ['/subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity /userAssignedIdentities/']

注解

仅当 identity_type == UserAssigned 时,才应指定 identity_id

delete

从其关联的工作区删除 AmlCompute 对象。

delete()

例外

注解

如果此对象是通过 Azure 机器学习创建的,则相应的基于云的对象也将被删除。 如果此对象是在外部创建的,并且仅附加到工作区,则此方法会引发 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 优先级:“dedicated”或“lowpriority”。

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 - 用户分配的标识。 需要设置标识 ID。

identity_id
list[str]
默认值: None

用户分配标识的资源 ID 列表。 例如 ['/subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities/']

location
str
默认值: None

要在其中预配群集的位置。

enable_node_public_ip
bool
默认值: True

启用节点公共 IP。 可能的值包括:

  • True - 启用节点公共 IP。

  • False - 禁用节点公共 IP。

  • NotSpecified - 启用节点公共 IP。

返回

创建计算对象时要使用的配置对象。

返回类型

例外

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

更新此 AmlCompute 目标的 ScaleSettings

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

指示操作是否为删除操作。

例外