次の方法で共有


ComputeTarget クラス

Azure Machine Learning によって管理されるすべてのコンピューティング ターゲットの抽象親クラス。

コンピューティング ターゲットは、トレーニング スクリプトを実行するか、サービスのデプロイをホストする、指定されたコンピューティング リソース/環境です。 この場所は、ローカル コンピューターでも、クラウドベースのコンピューティング リソースでもかまいません。 詳細については、「Azure Machine Learning のコンピューティング先とは」を参照してください。

Class ComputeTarget コンストラクター。

指定されたワークスペースに関連付けられている Compute オブジェクトのクラウド表現を取得します。 取得した Compute オブジェクトの特定の型に対応する子クラスのインスタンスを返します。

コンストラクター

ComputeTarget(workspace, name)

パラメーター

名前 説明
workspace
必須

取得する Compute オブジェクトを含むワークスペース オブジェクト。

name
必須
str

取得する Compute オブジェクトの名前。

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 オブジェクトを一覧表示します。

特定の種類の Compute に対応するインスタンス化された子オブジェクトの一覧を返します。 オブジェクトは ComputeTargetの子です。

refresh_state

オブジェクトのプロパティのインプレース更新を実行します。

対応するクラウド オブジェクトの現在の状態に基づいてプロパティを更新します。 これは、コンピューティング状態の手動ポーリングに役立ちます。

この抽象メソッドは、 ComputeTargetの子クラスによって実装されます。

serialize

この Compute オブジェクトを JSON シリアル化ディクショナリに変換します。

wait_for_completion

現在のプロビジョニング操作がクラスターで完了するまで待ちます。

このメソッドは、コンピューティング オブジェクトのポーリングで問題が発生した場合に ComputeTargetException を返します。

attach

指定した名前と構成情報を使用して、Compute オブジェクトをワークスペースにアタッチします。

static attach(workspace, name, attach_configuration)

パラメーター

名前 説明
workspace
必須

Compute オブジェクトをアタッチするワークスペース オブジェクト。

name
必須
str

Compute オブジェクトに関連付ける名前。

attach_configuration
必須

アタッチする Compute オブジェクトの種類と構成方法を決定するために使用される ComputeTargetAttachConfiguration オブジェクト。

戻り値

説明

アタッチされたオブジェクトの種類に対応する ComputeTarget の子のインスタンス。

例外

説明

注釈

パラメーター attach_configurationに渡すオブジェクトの型は、ComputeTargetAttachConfigurationのいずれかの子クラスでattach_configuration関数を使用して構築されたComputeTarget オブジェクトです。

次の例は、AdlaCompute の attach_configuration メソッドを使用して、ADLA アカウントをワークスペースにアタッチする方法を示しています。


   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
必須

コンピューティング オブジェクトを作成するワークスペース オブジェクト。

name
必須
str

Compute オブジェクトに関連付ける名前。

provisioning_configuration
必須

プロビジョニングする Compute オブジェクトの種類と構成方法を決定するために使用される ComputeTargetProvisioningConfiguration オブジェクト。

戻り値

説明

プロビジョニングされたオブジェクトの種類に対応する 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
必須

Compute オブジェクトが関連付けられているワークスペース オブジェクト。

object_dict
必須

Compute オブジェクトに変換する JSON オブジェクト。

戻り値

説明

指定された JSON オブジェクトのコンピューティング表現。

注釈

指定されたワークスペースがコンピューティングが関連付けられているワークスペースでない場合は、 ComputeTargetException を発生させます。

detach

関連付けられているワークスペースから Compute オブジェクトをデタッチします。

この抽象メソッドは、 ComputeTargetの子クラスによって実装されます。 基になるクラウド オブジェクトは削除されず、関連付けだけが削除されます。

abstract detach()

get_status

Compute オブジェクトの現在のプロビジョニング状態を取得します。

get_status()

戻り値

説明
str

現在の provisioning_state です。

注釈

返される値は、 ProvisioningState の Azure REST API リファレンスに記載されています。

list

ワークスペース内のすべての ComputeTarget オブジェクトを一覧表示します。

特定の種類の Compute に対応するインスタンス化された子オブジェクトの一覧を返します。 オブジェクトは ComputeTargetの子です。

static list(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

より詳細な出力を提供するかどうかを示します。

規定値: False
is_delete_operation

操作が削除対象かどうかを示します。

規定値: False

例外

説明