ma-cli ma-job训练作业支持的命令
使用ma-cli ma-job命令可以提交训练作业,查询训练作业日志、事件、使用的AI引擎、资源规格及停止训练作业等。
$ ma-cli ma-job -h Usage: ma-cli ma-job [OPTIONS] COMMAND [ARGS]... ModelArts job submission and query jod details. Options: -h, -H, --help Show this message and exit. Commands: delete Delete training job by job id. get-engine Get job engines. get-event Get job running event. get-flavor Get job flavors. get-job Get job details. get-log Get job log details. get-pool Get job engines. stop Stop training job by job id. submit Submit training job.
|
命令 |
命令详情 |
|---|---|
|
get-job |
查询ModelArts训练作业列表及详情。 |
|
get-log |
查询ModelArts训练作业运行日志。 |
|
get-engine |
查询ModelArts训练AI引擎。 |
|
get-event |
查询ModelArts训练作业事件。 |
|
get-flavor |
查询ModelArts训练资源规格。 |
|
get-pool |
查询ModelArts训练专属池。 |
|
stop |
停止ModelArts训练作业。 |
|
submit |
提交ModelArts训练作业。 |
|
delete |
删除指定作业id的训练作业。 |
使用ma-cli ma-job get-job命令查询ModelArts训练作业
使用ma-cli ma-job get-job命令可以查看训练作业列表或某个作业详情。
$ ma-cli ma-job get-job -h
Usage: ma-cli ma-job get-job [OPTIONS]
Get job details.
Example:
# Get train job details by job name
ma-cli ma-job get-job -n ${job_name}
# Get train job details by job id
ma-cli ma-job get-job -i ${job_id}
# Get train job list
ma-cli ma-job get-job --page-size 5 --page-num 1
Options:
-i, --job-id TEXT Get training job details by job id.
-n, --job-name TEXT Get training job details by job name.
-pn, --page-num INTEGER Specify which page to query. [x>=1]
-ps, --page-size INTEGER RANGE The maximum number of results for this query. [1<=x<=50]
-v, --verbose Show detailed information about training job details.
-C, --config-file TEXT Configure file path for authorization.
-D, --debug Debug Mode. Shows full stack trace when error occurs.
-P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT".
-h, -H, --help Show this message and exit.
|
参数名 |
参数类型 |
是否必选 |
参数说明 |
|---|---|---|---|
|
-i / --job-id |
String |
否 |
查询指定训练作业ID的任务详情。 |
|
-n / --job-name |
String |
否 |
查询指定任务名称的训练作业或根据任务名称关键字过滤训练作业。 |
|
-pn / --page-num |
Int |
否 |
页面索引,默认是第1页。 |
|
-ps / --page-size |
Int |
否 |
每页显示的训练作业数量,默认是10。 |
|
-v / --verbose |
Bool |
否 |
显示详细的信息开关,默认关闭。 |
- 示例:查询指定任务ID的训练作业。
ma-cli ma-job get-job -i b63e90xxx

- 示例:根据任务名称关键字“auto”过滤训练作业。
ma-cli ma-job get-job -n auto

使用ma-cli ma-job submit命令提交ModelArts训练作业
执行ma-cli ma-job submit命令提交ModelArts训练作业。
ma-cli ma-job submit命令需要指定一个位置参数YAML_FILE表示作业的配置文件路径,如果不指定该参数,则表示配置文件为空。配置文件是一个YAML格式的文件,里面的参数就是命令的option参数。此外,如果用户在命令行中同时指定YAML_FILE配置文件和option参数,命令行中指定的option参数的值将会覆盖配置文件相同的值。
$ma-cli ma-job submit -h
Usage: ma-cli ma-job submit [OPTIONS] [YAML_FILE]...
Submit training job.
Example:
ma-cli ma-job submit --code-dir obs://your_bucket/code/
--boot-file main.py
--framework-type PyTorch
--working-dir /home/ma-user/modelarts/user-job-dir/code
--framework-version pytorch_1.8.0-cuda_10.2-py_3.7-ubuntu_18.04-x86_64
--data-url obs://your_bucket/dataset/
--log-url obs://your_bucket/logs/
--train-instance-type modelarts.vm.cpu.8u
--train-instance-count 1
Options:
--name TEXT Job name.
--description TEXT Job description.
--image-url TEXT Full swr custom image path.
--uid TEXT Uid for custom image (default: 1000).
--working-dir TEXT ModelArts training job working directory.
--local-code-dir TEXT ModelArts training job local code directory.
--user-command TEXT Execution command for custom image.
--pool-id TEXT Dedicated pool id.
--train-instance-type TEXT Train worker specification.
--train-instance-count INTEGER Number of workers.
--data-url TEXT OBS path for training data.
--log-url TEXT OBS path for training log.
--code-dir TEXT OBS path for source code.
--output TEXT Training output parameter with OBS path.
--input TEXT Training input parameter with OBS path.
--env-variables TEXT Env variables for training job.
--parameters TEXT Training job parameters (only keyword parameters are supported).
--boot-file TEXT Training job boot file path behinds `code_dir`.
--framework-type TEXT Training job framework type.
--framework-version TEXT Training job framework version.
--workspace-id TEXT The workspace where you submit training job(default "0")
--policy [regular|economic|turbo|auto]
Training job policy, default is regular.
--volumes TEXT Information about the volumes attached to the training job.
-q, --quiet Exit without waiting after submit successfully.
-C, --config-file PATH Configure file path for authorization.
-D, --debug Debug Mode. Shows full stack trace when error occurs.
-P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT".
-H, -h, --help Show this message and exit.
|
参数名 |
参数类型 |
是否必选 |
参数说明 |
|---|---|---|---|
|
YAML_FILE |
String |
否 |
表示训练作业的配置文件,如果不传则表示配置文件为空。 |
|
--code-dir |
String |
是 |
训练源代码的OBS路径。 |
|
--data-url |
String |
是 |
训练数据的OBS路径。 |
|
--log-url |
String |
是 |
存放训练生成日志的OBS路径。 |
|
--train-instance-count |
String |
是 |
训练作业实例数,默认是1,表示单节点。 |
|
--boot-file |
String |
否 |
当使用自定义镜像或自定义命令时可以省略,当使用预置命令提交训练作业时需要指定该参数。 |
|
--name |
String |
否 |
训练作业名称。 |
|
--description |
String |
否 |
训练作业描述信息。 |
|
--image-url |
String |
否 |
自定义镜像SWR地址,遵循organization/image_name:tag |
|
--uid |
String |
否 |
自定义镜像运行的UID,默认值1000。 |
|
--working-dir |
String |
否 |
运行算法时所在的工作目录。 |
|
--local-code-dir |
String |
否 |
算法的代码目录下载到训练容器内的本地路径。 |
|
--user-command |
String |
否 |
自定义镜像执行命令。需为/home下的目录。 当code-dir以file://为前缀时,当前字段不生效。 |
|
--pool-id |
String |
否 |
训练作业选择的资源池ID。可在ModelArts管理控制台,单击左侧“专属资源池”,在专属资源池列表中查看资源池ID。 |
|
--train-instance-type |
String |
否 |
训练作业选择的资源规格。 |
|
--output |
String |
否 |
训练的输出信息,指定后,训练作业将会把训练脚本中指定输出参数对应训练容器的输出目录上传到指定的OBS路径。如果需要指定多个参数,可以使用--output output1=obs://bucket/output1 --output output2=obs://bucket/output2 |
|
--input |
String |
否 |
训练的输入信息,指定后,训练作业将会把对应OBS上的数据下载到训练容器,并将数据存储路径通过指定的参数传递给训练脚本。如果需要指定多个参数,可以使用--input data_path1=obs://bucket/data1 --input data_path2=obs://bucket/data2 |
|
--env-variables |
String |
否 |
训练时传入的环境变量,如果需要指定多个参数,可以使用--env-variables ENV1=env1 --env-variables ENV2=env2 |
|
--parameters |
String |
否 |
训练入参,可以通过--parameters "--epoch 0 --pretrained"指定多个参数。 |
|
--framework-type |
String |
否 |
训练作业选择的引擎规格。 |
|
--framework-version |
String |
否 |
训练作业选择的引擎版本。 |
|
-q / --quiet |
Bool |
否 |
提交训练作业成功后直接退出,不再同步打印作业状态。 |
|
--workspace-id |
String |
否 |
作业所处的工作空间,默认值为“0”。 |
|
--policy |
String |
否 |
训练资源规格模式,可选值regular、economic、turbo、auto。 |
|
--volumes |
String |
否 |
挂载EFS,如果需要指定多个参数,可以使用--volumes。 "local_path=/xx/yy/zz;read_only=false;nfs_server_path=xxx.xxx.xxx.xxx:/" -volumes "local_path=/xxx/yyy/zzz;read_only=false;nfs_server_path=xxx.xxx.xxx.xxx:/" |
示例:基于ModelArts预置镜像提交训练作业
指定命令行options参数提交训练作业
ma-cli ma-job submit --code-dir obs://your-bucket/mnist/code/ \
--boot-file main.py \
--framework-type PyTorch \
--working-dir /home/ma-user/modelarts/user-job-dir/code \
--framework-version pytorch_1.8.0-cuda_10.2-py_3.7-ubuntu_18.04-x86_64 \
--data-url obs://your-bucket/mnist/dataset/MNIST/ \
--log-url obs://your-bucket/mnist/logs/ \
--train-instance-type modelarts.vm.cpu.8u \
--train-instance-count 1 \
-q
使用预置镜像的train.yaml样例:
# .ma/train.yaml样例(预置镜像)
# pool_id: pool_xxxx
train-instance-type: modelarts.vm.cpu.8u
train-instance-count: 1
data-url: obs://your-bucket/mnist/dataset/MNIST/
code-dir: obs://your-bucket/mnist/code/
working-dir: /home/ma-user/modelarts/user-job-dir/code
framework-type: PyTorch
framework-version: pytorch_1.8.0-cuda_10.2-py_3.7-ubuntu_18.04-x86_64
boot-file: main.py
log-url: obs://your-bucket/mnist/logs/
##[Optional] Uncomment to set uid when use custom image mode
uid: 1000
##[Optional] Uncomment to upload output file/dir to OBS from training platform
output:
- name: output_dir
obs_path: obs://your-bucket/mnist/output1/
##[Optional] Uncomment to download input file/dir from OBS to training platform
input:
- name: data_url
obs_path: obs://your-bucket/mnist/dataset/MNIST/
##[Optional] Uncomment pass hyperparameters
parameters:
- epoch: 10
- learning_rate: 0.01
- pretrained:
##[Optional] Uncomment to use dedicated pool
pool_id: pool_xxxx
##[Optional] Uncomment to use volumes attached to the training job
volumes:
- efs:
local_path: /xx/yy/zz
read_only: false
nfs_server_path: xxx.xxx.xxx.xxx:/
示例:基于自定义镜像创建训练作业
指定命令行options参数提交训练作业
ma-cli ma-job submit --image-url atelier/pytorch_1_8:pytorch_1.8.0-cuda_10.2-py_3.7-ubuntu_18.04-x86_64-20220926104358-041ba2e \
--code-dir obs://your-bucket/mnist/code/ \
--user-command "export LD_LIBRARY_PATH=/usr/local/cuda/compat:$LD_LIBRARY_PATH && cd /home/ma-user/modelarts/user-job-dir/code && /home/ma-user/anaconda3/envs/PyTorch-1.8/bin/python main.py" \
--data-url obs://your-bucket/mnist/dataset/MNIST/ \
--log-url obs://your-bucket/mnist/logs/ \
--train-instance-type modelarts.vm.cpu.8u \
--train-instance-count 1 \
-q
使用自定义镜像的train.yaml样例:
# .ma/train.yaml样例(自定义镜像)
image-url: atelier/pytorch_1_8:pytorch_1.8.0-cuda_10.2-py_3.7-ubuntu_18.04-x86_64-20220926104358-041ba2e
user-command: export LD_LIBRARY_PATH=/usr/local/cuda/compat:$LD_LIBRARY_PATH && cd /home/ma-user/modelarts/user-job-dir/code && /home/ma-user/anaconda3/envs/PyTorch-1.8/bin/python main.py
train-instance-type: modelarts.vm.cpu.8u
train-instance-count: 1
data-url: obs://your-bucket/mnist/dataset/MNIST/
code-dir: obs://your-bucket/mnist/code/
log-url: obs://your-bucket/mnist/logs/
##[Optional] Uncomment to set uid when use custom image mode
uid: 1000
##[Optional] Uncomment to upload output file/dir to OBS from training platform
output:
- name: output_dir
obs_path: obs://your-bucket/mnist/output1/
##[Optional] Uncomment to download input file/dir from OBS to training platform
input:
- name: data_url
obs_path: obs://your-bucket/mnist/dataset/MNIST/
##[Optional] Uncomment pass hyperparameters
parameters:
- epoch: 10
- learning_rate: 0.01
- pretrained:
##[Optional] Uncomment to use dedicated pool
pool_id: pool_xxxx
##[Optional] Uncomment to use volumes attached to the training job
volumes:
- efs:
local_path: /xx/yy/zz
read_only: false
nfs_server_path: xxx.xxx.xxx.xxx:/
使用ma-cli ma-job get-log命令查询ModelArts训练作业日志
执行ma-cli ma-job get-log命令查询ModelArts训练作业日志。
$ ma-cli ma-job get-log -h
Usage: ma-cli ma-job get-log [OPTIONS]
Get job log details.
Example:
# Get job log by job id
ma-cli ma-job get-log --job-id ${job_id}
Options:
-i, --job-id TEXT Get training job details by job id. [required]
-t, --task-id TEXT Get training job details by task id (default "worker-0").
-C, --config-file TEXT Configure file path for authorization.
-D, --debug Debug Mode. Shows full stack trace when error occurs.
-P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT".
-h, -H, --help Show this message and exit.
|
参数名 |
参数类型 |
是否必选 |
参数说明 |
|---|---|---|---|
|
-i / --job-id |
String |
是 |
查询指定训练作业ID的任务日志。 |
|
-t / --task-id |
String |
否 |
查询指定task的日志,默认是work-0。 |
示例:查询指定训练作业ID的作业日志。
ma-cli ma-job get-log --job-id b63e90baxxx

使用ma-cli ma-job get-event命令查询ModelArts训练作业事件
执行ma-cli ma-job get-event命令查看ModelArts训练作业事件。
$ ma-cli ma-job get-event -h
Usage: ma-cli ma-job get-event [OPTIONS]
Get job running event.
Example:
# Get training job running event
ma-cli ma-job get-event --job-id ${job_id}
Options:
-i, --job-id TEXT Get training job event by job id. [required]
-C, --config-file TEXT Configure file path for authorization.
-D, --debug Debug Mode. Shows full stack trace when error occurs.
-P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT".
-H, -h, --help Show this message and exit.
|
参数名 |
参数类型 |
是否必选 |
参数说明 |
|---|---|---|---|
|
-i / --job-id |
String |
是 |
查询指定训练作业ID的事件。 |
示例:查看指定ID的训练作业的事件详情等。
ma-cli ma-job get-event --job-id b63e90baxxx

使用ma-cli ma-job get-engine命令查询ModelArts训练AI引擎
执行ma-cli ma-job get-engine命令查询ModelArts训练使用的AI引擎。
$ ma-cli ma-job get-engine -h Usage: ma-cli ma-job get-engine [OPTIONS] Get job engine info. Example: # Get training job engines ma-cli ma-job get-engine Options: -v, --verbose Show detailed information about training engines. -C, --config-file TEXT Configure file path for authorization. -D, --debug Debug Mode. Shows full stack trace when error occurs. -P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT". -H, -h, --help Show this message and exit.
|
参数名 |
参数类型 |
是否必选 |
参数说明 |
|---|---|---|---|
|
-v / --verbose |
Bool |
否 |
显示详细的信息开关,默认关闭。 |
示例:查看训练作业的AI引擎。
ma-cli ma-job get-engine

使用ma-cli ma-job get-flavor命令查询ModelArts训练资源规格
执行ma-cli ma-job get-flavor命令查询ModelArts训练的资源规格。
$ ma-cli ma-job get-flavor -h
Usage: ma-cli ma-job get-flavor [OPTIONS]
Get job flavor info.
Example:
# Get training job flavors
ma-cli ma-job get-flavor
Options:
-t, --flavor-type [CPU|GPU|Ascend]
Type of training job flavor.
-v, --verbose Show detailed information about training flavors.
-C, --config-file TEXT Configure file path for authorization.
-D, --debug Debug Mode. Shows full stack trace when error occurs.
-P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT".
-H, -h, --help Show this message and exit.
|
参数名 |
参数类型 |
是否必选 |
参数说明 |
|---|---|---|---|
|
-t / --flavor-type |
String |
否 |
资源规格类型,如果不指定默认返回所有的资源规格。 |
|
-v / --verbose |
Bool |
否 |
显示详细的信息开关,默认关闭。 |
示例:查看训练作业的资源规格及类型。
ma-cli ma-job get-flavor

使用ma-cli ma-job stop命令停止ModelArts训练作业
执行ma-cli ma-job stop命令,可停止指定作业id的训练作业。
$ ma-cli ma-job stop -h
Usage: ma-cli ma-job stop [OPTIONS]
Stop training job by job id.
Example:
Stop training job by job id
ma-cli ma-job stop --job-id ${job_id}
Options:
-i, --job-id TEXT Get training job event by job id. [required]
-y, --yes Confirm stop operation.
-C, --config-file TEXT Configure file path for authorization.
-D, --debug Debug Mode. Shows full stack trace when error occurs.
-P, --profile TEXT CLI connection profile to use. The default profile is "DEFAULT".
-H, -h, --help Show this message and exit.
|
参数名 |
参数类型 |
是否必选 |
参数说明 |
|---|---|---|---|
|
-i / --job-id |
String |
是 |
ModelArts训练作业ID。 |
|
-y / --yes |
Bool |
否 |
强制关闭指定训练作业。 |
示例:停止运行中的训练作业。
ma-cli ma-job stop --job-id efd3e2f8xxx