少し前からご利用いただいている皆さんが、新しいコードを実行しようとすると発生します。
エラーメッセージ
以下を実行すると...
compute_target = ws.get_default_compute_target(type="GPU")
# use get_status() to get a detailed status for the current cluster.
print(compute_target.get_status().serialize())
といって、エラーになる方向けのお話です😅
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-566686268911> in <module>
2
3 # use get_status() to get a detailed status for the current cluster.
----> 4 print(compute_target.get_status().serialize())
AttributeError: 'NoneType' object has no attribute 'get_status'
背景
2019/4/26 に Azure ML Services SDK 1.0.33
がリリースされました。
新機能として、デフォルトの Compute 環境が設定できるようになり、それを前提にしたサンプルコードが提供されています。
- Workspace.create メソッドは、CPU および GPU クラスターの既定のクラスター構成を受け入れるようになりました。
リリースノート:
問題は、サンプルコードの中の、学習ジョブ実行時の AmlCompute
環境設定が、以下の主に2通りが提供されています。そのため、過去 作成したワークスペースでは (私のように)、その値が NONE
になっているので、取得できません。
(ご参考): Workspace.create(引数たくさん)
対応策
1. AmlCompute を直接指定する
以下の例では、gpucsluter と個別に作ったものを指定しています。
compute_target = ws.compute_targets["gpucluster"]
その代わり、get_default_compute_target(type="xxx") は使わない、という前提です。
2. Workspace を作り直す
抜本解決ですが。データも飛びます。
from azureml.core import Workspace
# Create the workspace using the specified parameters
ws = Workspace.create(name = workspace_name,
subscription_id = subscription_id,
resource_group = resource_group,
location = workspace_region,
default_cpu_compute_target=Workspace.DEFAULT_CPU_CLUSTER_CONFIGURATION,
default_gpu_compute_target=Workspace.DEFAULT_GPU_CLUSTER_CONFIGURATION,
create_resource_group = True,
exist_ok = True)
ws.get_details()
# write the details of the workspace to a configuration file to the notebook library
ws.write_config()
デフォルト作成された AmlCompute
以下がデフォルト作成です。
(途中から)
Deploying Compute Target with name cpu-cluster
Deploying Compute Target with name gpu-cluster
Deployed Compute Target with name cpu-cluster
Deployed Compute Target with name gpu-cluster
- priority = dedicated
- min = 0
- max = 2
で作成されていますね。
私の好きな max 値ではないですね。残念ですが😎
私の施策
残念ですが、Azure ML の Workspace を再作成しました...今日時点 (2019/5/28)、Azure Portal からワークスペースを作成する際に、この設定が出来ません。
Workspace の 再作成用のコード
こんな感じですね。Azure Notebook
など JyputerNotebook でも動きます。
# 1. AzureML SDK のロード
import azureml.core
print("This notebook was created using version 1.0.41 of the Azure ML SDK")
print("You are currently using version", azureml.core.VERSION, "of the Azure ML SDK")
# 2. Azure ML Workspace 作成用
import os
subscription_id = os.getenv("SUBSCRIPTION_ID", default="<Your Subscription>")
resource_group = os.getenv("RESOURCE_GROUP", default="<Your Resource Group Name>")
workspace_name = os.getenv("WORKSPACE_NAME", default="<Your Azure ML Workspace Name>")
workspace_region = os.getenv("WORKSPACE_REGION", default="<ex. westus2>")
# 3. Compute Target の作成
from azureml.core.compute import ComputeTarget, AmlCompute
from azureml.core.compute_target import ComputeTargetException
# Specify the configuration for the new cluster
cpu_compute_config = AmlCompute.provisioning_configuration(vm_size="Standard_DS2_v2",
min_nodes=0,
max_nodes=10,
idle_seconds_before_scaledown=600,
vm_priority='lowpriority') ## vm_priority='lowpriority' | `dedicated'
# Specify the configuration for the new cluster
gpu_compute_config = AmlCompute.provisioning_configuration(vm_size="Standard_NC6s_v3", ## Standard_NC6s_v3
min_nodes=0,
max_nodes=20,
idle_seconds_before_scaledown=600,
vm_priority='lowpriority') ## vm_priority='lowpriority' | `dedicated'
# 4. Azure ML Workspace の作成
from azureml.core import Workspace
# Create the workspace using the specified parameters
ws = Workspace.create(name = workspace_name,
subscription_id = subscription_id,
resource_group = resource_group,
location = workspace_region,
default_cpu_compute_target=cpu_compute_config,
default_gpu_compute_target=gpu_compute_config,
create_resource_group = True,
exist_ok = True)
# write the details of the workspace to a configuration file to the notebook library
ws.write_config()
AmlCompute の仮想マシンのサイズ一覧:
https://docs.microsoft.com/ja-jp/azure/templates/Microsoft.Compute/2019-03-01/virtualMachines?toc=%2Fen-us%2Fazure%2Fazure-resource-manager%2Ftoc.json&bc=%2Fen-us%2Fazure%2Fbread%2Ftoc.json#hardwareprofile-object