次の方法で共有


CLI (v2) コマンド ジョブ YAML スキーマ

適用対象: Azure CLI ML 拡張機能 v2 (現行)

ソース JSON スキーマは https://azuremlschemas.azureedge.net/latest/commandJob.schema.json にあります。

Note

このドキュメントで詳しく説明されている YAML 構文は、最新バージョンの ML CLI v2 拡張機能の JSON スキーマに基づいています。 この構文は、ML CLI v2 拡張機能の最新バージョンでのみ動作することが保証されています。 以前のバージョンの拡張機能のスキーマについては、https://azuremlschemasprod.azureedge.net/ でご確認いただけます。

YAML 構文

キー Type 説明 使用できる値 既定値
$schema string YAML スキーマ。 Azure Machine Learning 用 VS Code 拡張機能を使用して YAML ファイルを作成する場合は、ファイルの先頭に $schema を含めることで、スキーマとリソースの入力候補を呼び出すことができます。
type const ジョブの種類。 command command
name string ジョブの名前。 ワークスペース内のすべてのジョブで一意である必要があります。 省略した場合、Azure Machine Learning によって名前の GUID が自動生成されます。
display_name string スタジオ UI でのジョブの表示名。 ワークスペース内で一意ではない場合があります。 省略した場合、Azure Machine Learning により、表示名として、人間が判読できる形容詞と名詞の識別子が自動生成されます。
experiment_name string ジョブを整理するための実験名。 各ジョブの実行レコードは、スタジオの [実験] タブの対応する実験の下に整理されます。省略した場合、Azure Machine Learning により、既定で、ジョブが作成された作業ディレクトリの名前が設定されます。
description string ジョブの説明。
tags object ジョブのタグの辞書。
command string 必須です (component フィールドを使用しない場合)。 実行するコマンドです。
code string アップロードしてジョブに使用するソース コード ディレクトリへのローカル パス。
environment 文字列またはオブジェクト 必須です (component フィールドを使用しない場合)。 ジョブに使用する環境。 これは、ワークスペース内のバージョン管理される既存の環境への参照、またはインライン環境仕様のいずれかになります。

既存の環境を参照するには、azureml:<environment_name>:<environment_version> 構文または azureml:<environment_name>@latest (環境の最新バージョンを参照する場合) を使用します。

環境のインラインを定義するには、環境スキーマに従います。 name プロパティと version プロパティは、インライン環境ではサポートされていないため、除外します。
environment_variables object コマンドが実行されるプロセスに設定する環境変数のキーと値のペアの辞書。
distribution object 分散トレーニング シナリオの配布構成。 MpiConfigurationPyTorchConfigurationTensorFlowConfiguration のいずれか。
compute string ジョブを実行するコンピューティング先の名前。 これは、ワークスペース内の既存のコンピューティングへの参照 (azureml:<compute_name> 構文を使用) または local でローカル実行を指定する場合があります。 注: パイプライン内のジョブでは localcompute としてサポートしていませんでした local
resources.instance_count 整数 (integer) ジョブに使用するノードの数。 1
resources.instance_type string ジョブに使用するインスタンスの種類。 Azure Arc 対応 Kubernetes コンピューティングで実行されているジョブに適用されます (compute フィールドに指定されたコンピューティング先は type: kubernentes のものです)。 省略した場合、これは既定で Kubernetes クラスターの既定のインスタンスの種類になります。 詳細については、Kubernetes インスタンスの種類を作成して選択に関するページを参照してください。
resources.shm_size string Docker コンテナーの共有メモリ ブロックのサイズ。 これは <number><unit> の形式である必要があります。ここで、number は 0 より大きくする必要があり、unit には b (バイト)、k (キロバイト)、m (メガバイト)、または g (ギガバイト) のいずれかを指定できます。 2g
limits.timeout 整数 (integer) ジョブを実行できる最大時間 (秒単位)。 この制限に達すると、システムによってジョブが取り消されます。
inputs object ジョブへの入力の辞書。 キーは、ジョブのコンテキスト内の入力の名前であり、値は入力値です。

入力は、${{ inputs.<input_name> }} 式を使用して command で参照できます。
inputs.<input_name> 数値、整数、ブール値、文字列、またはオブジェクト リテラル値 (型番号、整数、ブール値、または文字列) のいずれか、またはジョブ入力データ仕様を含むオブジェクト。
outputs object ジョブの出力構成の辞書。 キーはジョブのコンテキスト内の出力の名前であり、値は出力構成です。

出力は、${{ outputs.<output_name> }} 式を使用して command で参照できます。
outputs.<output_name> object オブジェクトは空のままにしておくことができます。この場合、既定では出力の種類は uri_folder になり、Azure Machine Learning では出力の出力場所がシステム生成されます。 出力ディレクトリへのファイルは、読み取り/書き込みマウントを使用して書き込まれます。 出力に別のモードを指定する場合は、ジョブ出力仕様を含むオブジェクトを指定します。
identity object ID は、データアクセスに使用されます。 UserIdentityConfigurationManagedIdentityConfiguration、または None を指定できます。 UserIdentityConfiguration の場合、ジョブの送信者の ID を使用して入力データにアクセスし、結果を出力フォルダーに書き込みます。それ以外の場合は、コンピューティング 先のマネージド ID が使用されます。

配布構成

MpiConfiguration

キー Type 説明 使用できる値
type const 必須。 配布の種類。 mpi
process_count_per_instance 整数 (integer) 必須。 ジョブに対して起動するノードあたりのプロセスの数。

PyTorchConfiguration

キー Type 説明 使用できる値 既定値
type const 必須。 配布の種類。 pytorch
process_count_per_instance 整数 (integer) ジョブに対して起動するノードあたりのプロセスの数。 1

TensorFlowConfiguration

キー Type 説明 使用できる値 既定値
type const 必須。 配布の種類。 tensorflow
worker_count 整数 (integer) ジョブに対して起動するワーカーの数。 既定値は resources.instance_count です。
parameter_server_count 整数 (integer) ジョブに対して起動するパラメーター サーバーの数。 0

ジョブの入力

キー Type 説明 使用できる値 既定値
type string ジョブ入力の種類。 1 つのファイル ソースを指す入力データの場合は uri_file、フォルダー ソースを指す入力データの場合は uri_folder を指定します。 uri_fileuri_folder、、 mlflow_modelcustom_model uri_folder
path string 入力として使用するデータのパス。 これは、いくつかの方法で指定できます。

- データ ソース ファイルまたはフォルダーへのローカル パス (例: path: ./iris.csv)。 データはジョブの送信中にアップロードされます。

- 入力として使用するファイルまたはフォルダーへのクラウド パスの URI。 サポートされる URI の種類は azuremlhttpswasbsabfssadl です。 azureml:// URI 形式の使用方法の詳細については、コア yaml 構文に関するページを参照してください。

- 入力として使用する既存の登録済み Azure Machine Learning データ資産。 登録済みデータ資産を参照するには、azureml:<data_name>:<data_version> 構文または azureml:<data_name>@latest (そのデータ資産の最新バージョンを参照する場合) を使用します。(例: path: azureml:cifar10-data:1 または path: azureml:cifar10-data@latest)。
mode string コンピューティング先にデータを配信する方法のモード。

読み取り専用マウントの場合 (ro_mount)、データはマウント パスとして使用されます。 フォルダーはフォルダーとしてマウントされ、ファイルはファイルとしてマウントされます。 Azure Machine Learning では、マウント パスへの入力が解決されます。

download モードの場合、データはコンピューティング先にダウンロードされます。 Azure Machine Learning では、ダウンロードされたパスへの入力が解決されます。

データ自体をマウントまたはダウンロードするのではなく、データ成果物の保存場所の URL のみが必要な場合は、モード direct を使用できます。 これにより、保存場所の URL がジョブ入力として渡されます。 この場合、ストレージにアクセスするための資格情報を処理する責任があることに注意してください。

eval_mountモードと eval_download モードは MLTable に固有であり、データをパスとしてマウントするか、コンピューティング 先にデータをダウンロードします。

詳細については、「ジョブ内データへのアクセス」 を参照してください
ro_mountdownload, direct, eval_downloadeval_mount ro_mount

ジョブ出力

キー Type 説明 使用できる値 既定値
type string ジョブ出力の種類。 既定の uri_folder 種類の場合、出力はフォルダーに対応します。 uri_foldermlflow_modelcustom_model uri_folder
mode string 出力ファイルを宛先ストレージに配信する方法のモード。 読み取り/書き込みマウント モード (rw_mount) の場合、出力ディレクトリはマウントされたディレクトリになります。 アップロード モードの場合、書き込まれたファイルがジョブの最後にアップロードされます。 rw_mount, upload rw_mount

ID の構成

UserIdentityConfiguration

キー Type 説明 使用できる値
type const 必須です。 ID の型。 user_identity

ManagedIdentityConfiguration

キー Type 説明 使用できる値
type const 必須です。 ID の型。 managed または managed_identity

解説

az ml job コマンドは、Azure Machine Learning ジョブを管理するために使用できます。

例は、GitHub リポジトリの例にあります。 以下にいくつか示します。

YAML: hello world

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: echo "hello world"
environment:
  image: library/python:latest

YAML: 表示名、実験名、説明、タグ

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: echo "hello world"
environment:
  image: library/python:latest
tags:
  hello: world
display_name: hello-world-example
experiment_name: hello-world-example
description: |
  # Azure Machine Learning "hello world" job

  This is a "hello world" job running in the cloud via Azure Machine Learning!

  ## Description

  Markdown is supported in the studio for job descriptions! You can edit the description there or via CLI.

YAML: 環境変数

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: echo $hello_env_var
environment:
  image: library/python:latest
environment_variables:
  hello_env_var: "hello world"

YAML: ソース コード

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: ls
code: src
environment:
  image: library/python:latest

YAML: リテラル入力

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: |
  echo ${{inputs.hello_string}}
  echo ${{inputs.hello_number}}
environment:
  image: library/python:latest
inputs:
  hello_string: "hello world"
  hello_number: 42

YAML: 既定の出力への書き込み

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: echo "hello world" > ./outputs/helloworld.txt
environment:
  image: library/python:latest

YAML: 名前付きデータ出力に書き込む

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: echo "hello world" > ${{outputs.hello_output}}/helloworld.txt
outputs:
  hello_output:
environment:
  image: python

YAML: データストア URI ファイルの入力

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: |
  echo "--iris-csv: ${{inputs.iris_csv}}"
  python hello-iris.py --iris-csv ${{inputs.iris_csv}}
code: src
inputs:
  iris_csv:
    type: uri_file 
    path: azureml://datastores/workspaceblobstore/paths/example-data/iris.csv
environment: azureml://registries/azureml/environments/sklearn-1.0/labels/latest

YAML: データストア URI フォルダーの入力

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: |
  ls ${{inputs.data_dir}}
  echo "--iris-csv: ${{inputs.data_dir}}/iris.csv"
  python hello-iris.py --iris-csv ${{inputs.data_dir}}/iris.csv
code: src
inputs:
  data_dir:
    type: uri_folder 
    path: azureml://datastores/workspaceblobstore/paths/example-data/
environment: azureml://registries/azureml/environments/sklearn-1.0/labels/latest

YAML: URI ファイルの入力

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: |
  echo "--iris-csv: ${{inputs.iris_csv}}"
  python hello-iris.py --iris-csv ${{inputs.iris_csv}}
code: src
inputs:
  iris_csv:
    type: uri_file 
    path: https://azuremlexamples.blob.core.windows.net/datasets/iris.csv
environment: azureml://registries/azureml/environments/sklearn-1.0/labels/latest

YAML: URI フォルダーの入力

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: |
  ls ${{inputs.data_dir}}
  echo "--iris-csv: ${{inputs.data_dir}}/iris.csv"
  python hello-iris.py --iris-csv ${{inputs.data_dir}}/iris.csv
code: src
inputs:
  data_dir:
    type: uri_folder 
    path: wasbs://datasets@azuremlexamples.blob.core.windows.net/
environment: azureml://registries/azureml/environments/sklearn-1.0/labels/latest

YAML: 紙を使用したノートブック

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: |
  pip install ipykernel papermill
  papermill hello-notebook.ipynb outputs/out.ipynb -k python
code: src
environment:
  image: library/python:3.11.6

YAML: 基本的な Python モデル トレーニング

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
code: src
command: >-
  python main.py 
  --iris-csv ${{inputs.iris_csv}}
  --C ${{inputs.C}}
  --kernel ${{inputs.kernel}}
  --coef0 ${{inputs.coef0}}
inputs:
  iris_csv: 
    type: uri_file
    path: wasbs://datasets@azuremlexamples.blob.core.windows.net/iris.csv
  C: 0.8
  kernel: "rbf"
  coef0: 0.1
environment: azureml://registries/azureml/environments/sklearn-1.0/labels/latest
compute: azureml:cpu-cluster
display_name: sklearn-iris-example
experiment_name: sklearn-iris-example
description: Train a scikit-learn SVM on the Iris dataset.

YAML: ローカル Docker ビルド コンテキストを使用した基本的な R モデル トレーニング

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
command: >
  Rscript train.R 
  --data_folder ${{inputs.iris}}
code: src
inputs:
  iris: 
    type: uri_file
    path: https://azuremlexamples.blob.core.windows.net/datasets/iris.csv
environment:
  build:
    path: docker-context
compute: azureml:cpu-cluster
display_name: r-iris-example
experiment_name: r-iris-example
description: Train an R model on the Iris dataset.

YAML: 分散 PyTorch

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
code: src
command: >-
  python train.py
  --epochs ${{inputs.epochs}}
  --learning-rate ${{inputs.learning_rate}}
  --data-dir ${{inputs.cifar}}
inputs:
  epochs: 1
  learning_rate: 0.2
  cifar:
     type: uri_folder
     path: azureml:cifar-10-example@latest
environment: azureml:AzureML-acpt-pytorch-1.13-cuda11.7@latest
compute: azureml:gpu-cluster
distribution:
  type: pytorch
  process_count_per_instance: 1
resources:
  instance_count: 2
display_name: pytorch-cifar-distributed-example
experiment_name: pytorch-cifar-distributed-example
description: Train a basic convolutional neural network (CNN) with PyTorch on the CIFAR-10 dataset, distributed via PyTorch.

YAML: 分散 TensorFlow

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
code: src
command: >-
  python train.py
  --epochs ${{inputs.epochs}}
  --model-dir ${{inputs.model_dir}}
inputs:
  epochs: 1
  model_dir: outputs/keras-model
environment: azureml:AzureML-tensorflow-2.12-cuda11@latest
compute: azureml:gpu-cluster
resources:
  instance_count: 2
distribution:
  type: tensorflow
  worker_count: 2
display_name: tensorflow-mnist-distributed-example
experiment_name: tensorflow-mnist-distributed-example
description: Train a basic neural network with TensorFlow on the MNIST dataset, distributed via TensorFlow.

YAML: 分散 MPI

$schema: https://azuremlschemas.azureedge.net/latest/commandJob.schema.json
code: src
command: >-
  python train.py
  --epochs ${{inputs.epochs}}
inputs:
  epochs: 1
environment: azureml:AzureML-tensorflow-2.12-cuda11@latest
compute: azureml:gpu-cluster
resources:
  instance_count: 2
distribution:
  type: mpi
  process_count_per_instance: 1
display_name: tensorflow-mnist-distributed-horovod-example
experiment_name: tensorflow-mnist-distributed-horovod-example
description: Train a basic neural network with TensorFlow on the MNIST dataset, distributed via Horovod.

次の手順