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 syntax

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

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

環境をインラインで定義するには、環境スキーマに従います。 name プロパティと version プロパティは、インライン環境ではサポートされていないため、除外します。

CLI または SDK でキュレーションされた環境を使用する場合、キュレーションされた環境名は AzureML-で始まります。 Azure Machine Learning Studio を使用する場合、キュレーションされた環境名にはこのプレフィックスはありません。 この違いの理由は、スタジオUIがキュレーションされた環境とカスタム環境を別々のタブに表示するため、接頭辞が必要ないことです。 CLIとSDKにはこの分離がありません。そのため、プレフィックスを使用して、キュレーションされた環境とカスタム環境を区別します。
environment_variables オブジェクト コマンドが実行されるプロセスに設定する環境変数のキーと値のペアの辞書。
distribution オブジェクト 分散トレーニング シナリオの配布構成。 MpiConfiguration、PyTorchConfiguration、TensorFlowConfiguration、RayConfiguration のいずれか。
compute 文字列 ジョブを実行するコンピューティング先の名前。 ワークスペース内の既存のコンピューティングへの参照 ( azureml:<compute_name> 構文を使用) または local してローカル実行を指定できます。 注: パイプライン内のジョブは、次のように local をサポートしていません compute local
resources.instance_count 整数 ジョブに使用するノードの数。 1
resources.instance_type 文字列 ジョブに使用するインスタンスの種類。 Azure Arc 対応 Kubernetes コンピューティングで実行されているジョブに適用されます ( compute フィールドで指定されたコンピューティング 先は type: kubernetes)。 省略すると、Kubernetes クラスターの既定のインスタンスの種類が既定値になります。 詳細については、「インスタンスの種類の作成と管理」を参照してください。
resources.shm_size 文字列 Docker コンテナーの共有メモリ ブロックのサイズ。 数値を 0 より大きくする必要があり、単位は <number><unit> (バイト)、b (キロバイト)、k (メガバイト)、またはm (ギガバイト) のいずれかであるgの形式にする必要があります。 2g
resources.docker_args 文字列 Docker run コマンドに渡す追加の引数。
resources.locations アレイ ジョブの実行が許可されているリージョンの場所の一覧。
resources.max_instance_count 整数 ジョブに使用するノードの最大数 (エラスティック分散トレーニング用)。
limits.timeout 整数 ジョブの実行が許可される最大時間 (秒)。 この制限に達すると、システムはジョブを取り消します。
inputs オブジェクト ジョブへの入力の辞書。 キーは、ジョブのコンテキスト内の入力の名前であり、値は入力値です。

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

出力は、command 式を使用して ${{ outputs.<output_name> }} で参照できます。
outputs.<output_name> オブジェクト オブジェクトは空のままにしておくことができます。この場合、既定では出力の種類は uri_folder になり、Azure Machine Learning によって出力の出力場所が生成されます。 出力ディレクトリへのファイルは、読み取り/書き込みマウントを使用して書き込まれます。 出力に別のモードを指定する場合は、ジョブ出力仕様を含むオブジェクトを指定します。
queue_settings オブジェクト ジョブのキュー設定。 ジョブ層とスケジュールの優先順位を構成します。 「キューの設定」を参照してください。
services オブジェクト 対話型ジョブ サービス (エンドポイント) のディクショナリ。 サポートされているサービスの種類: ssh、 tensor_board、 vs_code、 jupyter_lab。
identity オブジェクト ID は、データアクセスに使用されます。 UserIdentityConfiguration、ManagedIdentityConfiguration、AMLTokenIdentityConfiguration、または None を指定できます。 UserIdentityConfiguration の場合、ジョブ送信者の ID を使用して入力データにアクセスし、結果を出力フォルダーに書き込みます。それ以外の場合は、コンピューティング 先のマネージド ID が使用されます。

Distribution configurations

MpiConfiguration

Key タイプ Description Allowed values
type const Required. Distribution type. mpi
process_count_per_instance 整数 Required. ジョブに対して起動するノードあたりのプロセスの数。

PyTorchConfiguration

Key タイプ Description Allowed values Default value
type const Required. Distribution type. pytorch
process_count_per_instance 整数 ジョブに対して起動するノードあたりのプロセスの数。 1

TensorFlowConfiguration

Key タイプ Description Allowed values Default value
type const Required. Distribution type. tensorflow
worker_count 整数 ジョブに対して起動するワーカーの数。 既定値は resources.instance_count です。
parameter_server_count 整数 ジョブに対して起動するパラメーター サーバーの数。 0

RayConfiguration

Key タイプ Description Allowed values Default value
type const Required. Distribution type. ray
address 文字列 接続先の既存の Ray クラスターのアドレス。 省略すると、Azure Machine Learning によって新しい Ray クラスターが開始されます。
port 整数 ヘッド レイ プロセスのポート。
dashboard_port 整数 Ray ダッシュボード プロセスのポート。
include_dashboard boolean Ray ダッシュボードを開始するかどうか。
head_node_additional_args 文字列 ヘッド ノード上の ray start に渡される追加の引数。
worker_node_additional_args 文字列 ワーカー ノード上の ray start に渡される追加の引数。

Job inputs

Key タイプ Description Allowed values Default value
type 文字列 ジョブ入力の種類。 1 つのファイル ソースを指す入力データの場合は uri_file、フォルダー ソースを指す入力データの場合は uri_folder を指定します。 uri_file、 uri_folder、 mlflow_model、 custom_model uri_folder
path 文字列 入力として使用するデータのパス。 いくつかの方法で指定できます。

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

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

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

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

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

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

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

モードの詳細については、「ジョブ内のデータへのアクセス」を参照してください。
ro_mount、 download、 direct、 eval_download、 eval_mount ro_mount

Job outputs

Key タイプ Description Allowed values Default value
type 文字列 ジョブ出力の種類。 既定の uri_folder の種類の場合、出力はフォルダーに対応します。 uri_folder 、 mlflow_model、 custom_model uri_folder
mode 文字列 出力ファイルを宛先ストレージに配信する方法のモード。 読み取り/書き込みマウント モード (rw_mount) の場合、出力ディレクトリはマウントされたディレクトリです。 アップロード モードの場合、書き込まれたファイルはジョブの最後にアップロードされます。 rw_mount、upload rw_mount

Identity configurations

UserIdentityConfiguration

Key タイプ Description Allowed values
type const Required. Identity type. user_identity

ManagedIdentityConfiguration

Key タイプ Description Allowed values
type const Required. Identity type. managed または managed_identity

AMLTokenIdentityConfiguration

Key タイプ Description Allowed values
type const Required. Identity type. このジョブでは、データ アクセスにワークスペースの Azure Machine Learning トークンが使用されます。 aml_token

Queue settings

Key タイプ Description Allowed values Default value
job_tier 文字列 ジョブ層。 spot では、割り込み可能なコンピューティングを低コストで使用します。 spot、 basic、 standard、 premium
priority 文字列 選択したレベル内のスケジュールの優先順位。 low、medium、high

Remarks

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

Examples

例は、GitHub リポジトリの例にあります。 次のセクションでは、いくつかの例を示します。

YAML:こんにちは、世界

$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.5/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.5/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.5/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.5/labels/latest

YAML: Papermill 経由のノートブック

$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.5/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: >
  source /usr/venv/bin/activate
  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-2.8-cuda12.6@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.16-cuda12@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.

Next steps