创建训练任务(CreateTrain)
基本信息
Action:/qai/aicp/trains/namespaces/{namespace}/create
Method: POST
Content-Type:application/json
请求参数
参数 | 类型 | 说明 | 必填 |
---|---|---|---|
charge_mode |
string |
计费模式,弹性计费(elastic)或者包年包月(monthly) |
yes |
duration |
integer |
购买时长,弹性为 3600,包年包月为 1-60 |
yes |
auto_renew |
integer |
自动续费标识 (0为不自动续费,1 为自动续费) |
no |
next_charge_mode |
string |
下次计费模式,用于变更计费模式 (elastic/monthly) |
no |
user_id |
string |
用户系统 ID |
yes |
root_user_id |
string |
主账户 ID |
no |
namespace |
string |
资源所属命名空间 |
yes |
image |
string |
运行时镜像名称 |
yes |
image_type |
string |
镜像类型标识,可输入 official,user,custom |
yes |
name |
string |
训练任务名称 |
yes |
endpoint |
string |
作业类型,用户可通过调用 GetEndpoint API 获取 |
yes |
command |
string |
启动命令 |
yes |
priority |
integer |
任务优先级 |
no |
restart_policy |
string |
容器重启策略,可输入 |
no |
backoff_limit |
integer |
重试次数限制 |
no |
ttl_seconds_after_finished |
integer |
完成后存活时间(秒) |
no |
active_deadline_seconds |
integer |
最大运行时间(秒) |
no |
envs |
array<object> |
环境变量配置 |
no |
envs.name |
string |
环境变量名 |
yes (若使用 envs) |
envs.value |
string |
环境变量值 |
yes (若使用 envs) |
code_path_uuid |
string(uuid) |
代码存储路径 UUID |
no |
user_name |
string |
提交人姓名 |
no |
project_category |
string |
项目分类名称 |
no |
project_category_key |
string |
项目分类标识 |
no |
job_type |
string |
任务类型标识 |
no |
replica_specs |
array<object> |
计算副本配置 |
yes |
replica_specs.replicas |
integer |
副本数量 |
yes |
replica_specs.specs |
string |
规格描述文本 |
no |
replica_specs.replica_type |
string |
副本类型标识 |
no |
replica_specs.rg_id |
string |
资源组 ID |
no |
replica_specs.custom_cpu |
integer |
自定义 CPU 核数 |
no |
replica_specs.custom_memory |
integer |
自定义内存 |
no |
replica_specs.custom_gpu |
integer |
GPU 卡数量 |
no |
replica_specs.custom_gpu_list |
array<string> |
指定 GPU 设备 ID 列表 |
no |
replica_specs.custom_gpu_name |
string |
GPU 型号名称 |
no |
replica_specs.custom_gpu_memory |
string |
GPU 显存大小 |
no |
replica_specs.custom_gpu_type |
string |
GPU 类型标识 |
no |
replica_specs.custom_system_disk_size |
integer |
系统盘大小 |
no |
replica_specs.custom_data_disk_size |
integer |
数据盘大小 |
no |
replica_specs.custom_infiniband |
integer |
是否启用 InfiniBand(0/1) |
no |
replica_specs.custom_aipods_type |
string |
AI 加速器类型 |
no |
replica_specs.custom_hashrate_allocation |
integer |
算力分配值 |
no |
replica_specs.custom_network_description |
string |
网络配置描述 |
no |
replica_specs.custom_cpu_model |
string |
CPU 具体型号 |
no |
replica_specs.custom_cpu_manufacturer |
string |
CPU 制造商 |
no |
replica_specs.template_id |
integer |
配置模板 ID |
no |
volume_specs |
array<object> |
存储卷挂载配置 |
no |
volume_specs.file_set |
string |
文件集名称 |
yes (若使用 volume_specs) |
volume_specs.mount_path |
string |
容器内挂载路径 |
yes (若使用 volume_specs) |
volume_specs.volume_type |
string |
存储类型(如 GPFS) |
yes (若使用 volume_specs) |
volume_specs.file_type |
string |
文件类型(Directory/File) |
no |
volume_specs.quota |
integer |
存储配额 |
no |
volume_specs.permission |
string |
访问权限(rw/ro) |
no |
volume_specs.owner |
string |
存储卷所有者 |
no |
custom_image_secret |
object |
私有镜像仓库认证 |
no |
custom_image_secret.has_auth |
boolean |
是否启用认证 |
no |
custom_image_secret.username |
string |
仓库用户名 |
yes (若 has_auth=true) |
custom_image_secret.password |
string |
仓库密码 |
yes (若 has_auth=true) |
响应参数
此接口包含的公共响应参数,可参见前文内容,其他参数介绍如下:
参数 | 类型 | 描述 |
---|---|---|
data.kuid |
string |
Kubernetes 资源的唯一标识符。 |
data.status |
string |
任务当前状态(如 |
data.reason |
string |
任务状态的详细原因(如错误信息)。 |
data.created_at |
string |
任务创建时间。 |
data.updated_at |
string |
任务最后更新时间。 |
data.user_id |
string |
任务所属用户的 ID。 |
data.root_user_id |
string |
根用户 ID。 |
data.namespace |
string |
命名空间。 |
data.image |
string |
任务使用的容器镜像地址。 |
data.image_type |
string |
镜像类型,如 official,user,custom。 |
data.name |
string |
任务名称。 |
data.endpoint |
string |
任务类型。 |
data.command |
string |
容器启动命令。 |
data.priority |
integer |
任务优先级。 |
data.restart_policy |
string |
重启策略。 |
data.backoff_limit |
integer |
任务失败后的最大重试次数。 |
data.ttl_seconds_after_finished |
integer |
任务完成后自动删除的延迟时间(秒,此处为 |
data.active_deadline_seconds |
integer |
任务允许运行的最长时间(秒, |
data.envs |
array |
环境变量列表(空数组表示未设置额外环境变量)。 |
data.code_path_uuid |
string |
关联的代码存储路径唯一标识。 |
data.user_name |
string |
用户名称。 |
data.project_category |
string |
项目分类名称。 |
data.project_category_key |
string |
项目分类键值。 |
data.job_type |
string |
任务类型标识。 |
data.uuid |
string |
任务的全局唯一 ID。 |
data.running_at |
string |
任务开始运行的时间。 |
data.ended_at |
string |
任务结束时间。 |
请求示例
curl -X 'POST' \
'https://ai.coreshub.cn/qai/aicp/trains/namespaces/usr-jaswgjdn/create' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"user_id": "usr-jaswGjDn",
"name": "tf-job-example1",
"endpoint": "tfjobs",
"namespace": "usr-jaswgjdn",
"command": "python /home/yangzhou111/tfjob.py",
"image": "registry.cn-beijing.aliyuncs.com/danchey/tensorflow:1.0.1",
"image_type": "user",
"restart_policy": "Never",
"ttl_seconds_after_finished": 3000,
"replica_specs": [
{
"replicas": 1,
"specs": "sku_vGX4NGO7vOKk",
"replica_type": "Worker"
}
],
"volume_specs": [],
"envs": [
{
"name": "env1",
"value": "value1"
}
],
"custom_image_secret": {
"has_auth": true,
"username": "",
"password": ""
}
}'
响应示例
{
"ret_code": 0,
"message": "success",
"meta": {
"X_REQUEST_ID": "string",
"X_REQUEST_USER": "string"
},
"data": {
"kuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"status": "string",
"reason": "string",
"created_at": "2025-04-08T08:42:52.585Z",
"updated_at": "2025-04-08T08:42:52.585Z",
"user_id": "string",
"root_user_id": "",
"namespace": "string",
"image": "string",
"image_type": "string",
"name": "训练任务",
"endpoint": "string",
"command": "string",
"priority": 3,
"restart_policy": "Never",
"backoff_limit": 0,
"ttl_seconds_after_finished": 60,
"active_deadline_seconds": 84000,
"envs": [],
"code_path_uuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"user_name": "",
"project_category": "",
"project_category_key": "",
"job_type": "AI",
"uuid": "string",
"running_at": "2025-04-08T08:42:52.585Z",
"ended_at": "2025-04-08T08:42:52.585Z"
}
}