BatchCompute 类

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

Azure Batch 用于在云中高效运行大规模并行高性能计算 (HPC) 应用程序。 BatchCompute 在 Azure 机器学习管道中使用,使用 a AzureBatchStep将作业提交到 Azure Batch 计算机池。 有关详细信息,请参阅 什么是 Azure 机器学习中的计算目标?

类 ComputeTarget 构造函数。

检索与提供的工作区关联的计算对象的云表示形式。 返回与检索的计算对象的特定类型对应的子类的实例。

构造函数

BatchCompute(workspace, name)

参数

名称 说明
workspace
必需

包含要检索的 BatchCompute 对象的工作区对象。

name
必需
str

要检索的 BatchCompute 对象的名称。

workspace
必需

包含要检索的 Compute 对象的工作区对象。

name
必需
str

要检索的 Compute 对象的名称。

注解

使用 Azure Batch 帐户之前,请先创建一个 Azure Batch 帐户。 若要创建一 个帐户,请参阅使用 Azure 门户创建 Batch 帐户

以下示例演示如何使用 attach_configuration 将 Azure Batch 计算帐户附加到工作区。


   batch_compute_name = 'mybatchcompute' # Name to associate with new compute in workspace

   # Batch account details needed to attach as compute to workspace
   batch_account_name = "<batch_account_name>" # Name of the Batch account
   batch_resource_group = "<batch_resource_group>" # Name of the resource group which contains this account

   try:
       # check if already attached
       batch_compute = BatchCompute(ws, batch_compute_name)
   except ComputeTargetException:
       print('Attaching Batch compute...')
       provisioning_config = BatchCompute.attach_configuration(resource_group=batch_resource_group,
                                                               account_name=batch_account_name)
       batch_compute = ComputeTarget.attach(ws, batch_compute_name, provisioning_config)
       batch_compute.wait_for_completion()
       print("Provisioning state:{}".format(batch_compute.provisioning_state))
       print("Provisioning errors:{}".format(batch_compute.provisioning_errors))

   print("Using Batch compute:{}".format(batch_compute.cluster_resource_id))

完整示例可从 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/machine-learning-pipelines/intro-to-pipelines/aml-pipelines-how-to-use-azurebatch-to-run-a-windows-executable.ipynb

方法

attach_configuration

创建用于附加 Batch 计算目标的配置对象。

delete

BatchCompute 对象不支持删除。 请改用 detach

deserialize

将 JSON 对象转换为 BatchCompute 对象。

detach

从其关联的工作区中分离 Batch 对象。

基础云对象不会被删除,只会删除关联。

refresh_state

对对象的属性执行就地更新。

此方法根据相应云对象的当前状态更新属性。 这主要用于手动轮询计算状态。

serialize

将此 BatchCompute 对象转换为 JSON 序列化字典。

attach_configuration

创建用于附加 Batch 计算目标的配置对象。

static attach_configuration(resource_group=None, account_name=None, resource_id=None)

参数

名称 说明
resource_group
str

Batch 帐户所在的资源组的名称。

默认值: None
account_name
str

Batch 帐户名称。

默认值: None
resource_id
str

要附加的计算资源的 Azure 资源 ID。

默认值: None

返回

类型 说明

附加计算对象时要使用的配置对象。

delete

BatchCompute 对象不支持删除。 请改用 detach

delete()

例外

类型 说明

deserialize

将 JSON 对象转换为 BatchCompute 对象。

static deserialize(workspace, object_dict)

参数

名称 说明
workspace
必需

BatchCompute 对象与之关联的工作区对象。

object_dict
必需

要转换为 BatchCompute 对象的 JSON 对象。

返回

类型 说明

提供的 JSON 对象的 BatchCompute 表示形式。

例外

类型 说明

注解

如果提供的工作区不是计算与之关联的工作区,则引发该 ComputeTargetException 工作区。

detach

从其关联的工作区中分离 Batch 对象。

基础云对象不会被删除,只会删除关联。

detach()

例外

类型 说明

refresh_state

对对象的属性执行就地更新。

此方法根据相应云对象的当前状态更新属性。 这主要用于手动轮询计算状态。

refresh_state()

serialize

将此 BatchCompute 对象转换为 JSON 序列化字典。

serialize()

返回

类型 说明

此 BatchCompute 对象的 JSON 表示形式。