你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
源 JSON 架构可在 https://azuremlschemas.azureedge.net/latest/commandJob.schema.json 中找到。
注释
本文档中详细介绍的 YAML 语法基于最新版本的 ML CLI v2 扩展的 JSON 架构。 此语法必定仅适用于最新版本的 ML CLI v2 扩展。 可以在 https://azuremlschemasprod.azureedge.net/ 上查找早期扩展版本的架构。
YAML 语法
密钥 | 类型 | DESCRIPTION | 允许的值 | 默认值 |
---|---|---|---|---|
$schema |
字符串 | YAML 架构。 如果使用 Azure 机器学习 VS Code 扩展来创作 YAML 文件,则可通过在文件顶部包含 $schema 来调用架构和资源完成操作。 |
||
type |
常量 | 作业类型。 | command |
command |
name |
字符串 | 作业的名称。 对工作区中的所有作业必须唯一。 如果省略此项,Azure 机器学习将为该名称自动生成一个 GUID。 | ||
display_name |
字符串 | 作业在工作室 UI 中的显示名称。 在工作区中可以不唯一。 如果省略此项,Azure 机器学习将为显示名称自动生成人类可读的形容词-名词标识符。 | ||
experiment_name |
字符串 | 用于对作业进行组织的试验名称。 每个作业的运行记录都按工作室的“试验”选项卡中的相应试验进行组织。如果省略,Azure 机器学习会将它默认为创建作业的工作目录的名称。 | ||
description |
字符串 | 作业的说明。 | ||
tags |
物体 | 作业的标记字典。 | ||
command |
字符串 | 要执行的命令。 | ||
code |
字符串 | 要上传并用于作业的源代码目录的本地路径。 | ||
environment |
字符串或对象 | 用于作业的环境。 可以是对工作区中现有版本控制环境的引用,也可以是内联环境规范。 若要引用现有环境,请使用 azureml:<environment_name>:<environment_version> 语法或 azureml:<environment_name>@latest (引用环境的最新版本)。 若要以内联方式定义环境,请遵循环境架构。 排除 name 和 version 属性,因为内联环境不支持这些属性。在 CLI 或 SDK 中使用特选环境时,特选的环境名称以 AzureML- 开头。 使用 Azure 机器学习工作室时,特选的环境名称没有此前缀。 造成这种差异的原因是工作室 UI 在单独的选项卡上显示特选环境和自定义环境,因此不需要前缀。 CLI 和 SDK 没有这种分离,因此使用前缀来区分特选环境和自定义环境。 |
||
environment_variables |
物体 | 要在执行命令的进程上设置的环境变量键/值对的字典。 | ||
distribution |
物体 | 分布式训练方案的分布配置。 MpiConfiguration、PyTorchConfiguration 或 TensorFlowConfiguration。 | ||
compute |
字符串 | 要在其上执行作业的计算目标的名称。 可以是对工作区中现有计算(使用 azureml:<compute_name> 语法)的引用,也可以 local 指定本地执行。
注意:管道中的作业不支持local compute |
local |
|
resources.instance_count |
整数 | 用于作业的节点数。 | 1 |
|
resources.instance_type |
字符串 | 要用于作业的实例类型。 适用于在已启用 Azure Arc 的 Kubernetes 计算上运行的作业(其中字段中指定的compute 计算目标为)。type: kubernentes 如果省略,则默认为 Kubernetes 群集的默认实例类型。 有关详细信息,请参阅 “创建并选择 Kubernetes 实例类型”。 |
||
resources.shm_size |
字符串 | docker 容器的共享内存块的大小。 应采用 <number><unit> 数字必须大于 0 的格式,单位可以是 b (字节)、(千字节)、 k m (兆字节)或 g (千兆字节)。 |
2g |
|
limits.timeout |
整数 | 允许作业运行的最大时间(以秒为单位)。 达到此限制后,系统会取消作业。 | ||
inputs |
物体 | 作业的输入字典。 键是作业上下文中的输入名称,值是输入值。 可以在 command 中使用 ${{ inputs.<input_name> }} 表达式引用输入。 |
||
inputs.<input_name> |
数字、整数、布尔值、字符串或对象 | 文字值(数字、整数、布尔值或字符串类型)或包含作业输入数据规范的对象之一。 | ||
outputs |
物体 | 作业的输出配置字典。 键是作业上下文中的输出名称,值是输出配置。 可以在 command 中使用 ${{ outputs.<output_name> }} 表达式引用输出。 |
||
outputs.<output_name> |
物体 | 可以将对象留空,在这种情况下,输出的类型为, uri_folder Azure 机器学习会生成输出的输出位置。 输出目录的文件通过读写装载写入。 如果要为输出指定不同的模式,请提供一个包含作业输出规范的对象。 |
||
identity |
物体 | 此标识用于数据访问。 可以是 UserIdentityConfiguration、 ManagedIdentityConfiguration 或 None。 如果 UserIdentityConfiguration,则使用作业提交者的标识来访问、输入数据和写入输出文件夹的结果,否则将使用计算目标的托管标识。 |
分布配置
MpiConfiguration
密钥 | 类型 | DESCRIPTION | 允许的值 |
---|---|---|---|
type |
常量 | 必填。 分布类型。 | mpi |
process_count_per_instance |
整数 | 必填。 要为作业启动的每节点进程数。 |
PyTorchConfiguration
密钥 | 类型 | DESCRIPTION | 允许的值 | 默认值 |
---|---|---|---|---|
type |
常量 | 必填。 分布类型。 | pytorch |
|
process_count_per_instance |
整数 | 要为作业启动的每节点进程数。 | 1 |
TensorFlowConfiguration
密钥 | 类型 | DESCRIPTION | 允许的值 | 默认值 |
---|---|---|---|---|
type |
常量 | 必填。 分布类型。 | tensorflow |
|
worker_count |
整数 | 要为作业启动的工作线程数。 | 默认为 resources.instance_count 。 |
|
parameter_server_count |
整数 | 要为作业启动的参数服务器数。 | 0 |
作业输入
密钥 | 类型 | DESCRIPTION | 允许的值 | 默认值 |
---|---|---|---|---|
type |
字符串 | 作业输入的类型。 为指向单个文件源的输入数据指定 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:// 请参阅 Core yaml 语法。 - 要用作输入的现有已注册的 Azure 机器学习数据资产。 若要引用已注册的数据资产,请使用 azureml:<data_name>:<data_version> 语法或 azureml:<data_name>@latest (用于引用数据资产的最新版本),例如 path: azureml:cifar10-data:1 或 path: azureml:cifar10-data@latest 。 |
||
mode |
字符串 | 将数据传送到计算目标的模式。 对于只读装载( ro_mount ),该数据将用作装载路径。 文件夹是文件夹装载的,而文件则作为文件装载。 Azure 机器学习会将输入解析为装载路径。 对于 download 模式,数据将下载到计算目标。 Azure 机器学习会将输入解析为下载的路径。 如果只需要数据项目的存储位置的 URL,而不是装载或下载数据本身,则可以使用模式 direct 。 此模式作为作业输入传入存储位置的 URL。 在这种情况下,你全权负责处理凭证以访问存储。 MLTable eval_mount 是唯一的, eval_download 并将数据装载为路径或将数据下载到计算目标。 有关模式的详细信息,请参阅 作业中的 Access 数据 |
ro_mount 、download 、direct 、eval_download 、eval_mount |
ro_mount |
作业输出
密钥 | 类型 | DESCRIPTION | 允许的值 | 默认值 |
---|---|---|---|---|
type |
字符串 | 作业输出的类型。 对于默认的 uri_folder 类型,输出对应于某个文件夹。 |
.'. . | uri_folder |
mode |
字符串 | 输出文件如何传送到目标存储的模式。 对于读写装载模式(rw_mount ),输出目录是装载的目录。 对于上传模式,写入的文件会在作业结束时上传。 |
rw_mount 、upload |
rw_mount |
标识配置
UserIdentityConfiguration
密钥 | 类型 | DESCRIPTION | 允许的值 |
---|---|---|---|
type |
常量 | 必填。 标识类型。 | user_identity |
ManagedIdentityConfiguration
密钥 | 类型 | DESCRIPTION | 允许的值 |
---|---|---|---|
type |
常量 | 必填。 标识类型。 |
managed 或 managed_identity |
注解
az ml job
命令可用于管理 Azure 机器学习作业。
例子
示例 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.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:通过纸机的笔记本
$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.2-cuda12.1@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.