九章智算云
创建训练任务

创建一个训练任务并进入排队,支持直接创建(params.createType 为 DIRECT)、复制已有任务(COPY)、按模板创建(TEMPLATE)三种方式。该接口为异步接口:服务端完成准入校验(名称格式、同名查重、存储、环境变量与重试/超时配置、并行度、余额)后立即返回 resultKey,再调用(GET /api/osm/v1/subscription/sku/training/result/{resultKey})轮询:IN_PROGRESS 表示处理中,继续轮询;SUCCESS 表示任务已创建(状态为 Queued);FAILED 时按 resources[].errorCode / errorMessage 判断失败原因。注意:创建时必须挂载存储,即 params.storageConfigEnable 为 true 且 params.storageMounts 非空,否则拒绝创建。

POSThttps://api.alayanew.com/api/osm/v1/subscription/sku/training/create

鉴权(Authorizations)

AuthorizationString必填

用户获取Authorization请求头后,通过该请求头完成身份认证。例如:Authorization: [your-auth-header]。

Request body

aidcIdLong必填

智算中心 ID。例如:1。

skuCodeString必填

训练规格 SKU 编码,决定训练任务的算力规格。可从可售规格列表获取。例如:SKU-HPT-L40S-8C64G。

billingModeIdLong

计费方式 ID。不传时取该规格的默认计费方式,取值可参考规格响应中的 billingModes[].billingModeId。例如:1。

paramsObject必填

训练任务参数。

显示 properties
nameString必填

训练任务名称。4~32 位,以字母开头,可包含数字、下划线、连字符;同租户内不允许重名。例如:llama3-8b-sft。

createTypeString

创建类型:DIRECT(直接创建)、COPY(复制创建)、TEMPLATE(按模板创建)。

descriptionString

任务描述,最长 200 个字符。例如:Llama3-8B 指令微调。

priorityInteger

任务优先级,取值 1~3,数值越小优先级越高,不传默认 3。

trainingTypeString

训练类型。例如:pre_training。

trainingFrameworkString

训练框架。例如:pytorch、deepspeed、mpi、tensorflow。

imageTypeString

镜像类型。例如:general(基础镜像)、application(应用镜像),需与 image 对应。

imageString

镜像地址。例如:registry.example.com/public/pytorch:2.3.0-cuda12.1。

workerCountInteger必填

Worker 节点数,必须为正整数。单机填 1,4 机填 4。

storageConfigEnableBoolean必填

是否启用存储配置,必须为 true,否则拒绝创建。

storageMountsArray必填

存储挂载配置,至少一项,最多 20 项。

显示 properties
storageIdString必填

挂载的存储实例 ID。例如:72a2a885-e45e-4c79-aaf3-e1fa05abdb92。

mountPathString

容器内挂载路径。为空时使用该存储自身的默认挂载路径。例如:/root/nas/datasets。

envObject

环境变量键值对,最多 20 项;键为大写字母开头的字母与下划线,最长 30 个字符。

enableAutoRetryBoolean

是否启用失败自动重试。例如:true。

maxRetryCountInteger

最大重试次数,启用自动重试时必须为正数且有上限校验。例如:3。

enableTimeoutCancelBoolean

是否启用超时自动结束。例如:true。

timeoutHoursInteger

超时小时数,启用超时自动结束时必须为正数。例如:24。

startCommandString

容器启动命令。例如:python3 -m torch.distributed.run train.py --data /root/nas/datasets。

computeResourceTypeString

算力资源类型:ELASTIC(弹性)、EXCLUSIVE(独占)。不传按 ELASTIC 处理。

exclusiveResourceIdString

独占资源 ID,仅算力资源类型为 EXCLUSIVE 时有意义。

Response

statusInteger

业务状态码,200 表示请求已受理。

messageString

接口响应信息。例如:"OK"。

dataObject

创建结果。

显示 properties
subscriptionNoString

订阅号。例如:"SUB-20261019-0001"。

resourceInstanceIdString

训练任务实例 ID。例如:"1234567890"。

resultKeyString

开通结果查询 key,用于轮询创建结果。例如:"a1b2c3d4-0000-1111-2222-333344445555"。

curl -X 'POST' \
  'https://api.alayanew.com/api/osm/v1/subscription/sku/training/create' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: [your-auth-header]' \
  -d '{
    "aidcId": 1,
    "skuCode": "SKU-HPT-L40S-8C64G",
    "billingModeId": 1,
    "params": {
      "name": "llama3-8b-sft",
      "createType": "DIRECT",
      "description": "Llama3-8B 指令微调",
      "priority": 3,
      "trainingType": "pre_training",
      "trainingFramework": "pytorch",
      "imageType": "general",
      "image": "registry.example.com/public/pytorch:2.3.0-cuda12.1",
      "workerCount": 1,
      "storageConfigEnable": true,
      "storageMounts": [
        {
          "storageId": "72a2a885-e45e-4c79-aaf3-e1fa05abdb92",
          "mountPath": "/root/nas/datasets"
        }
      ],
      "env": {"CUDA_VISIBLE_DEVICES": "0,1,2,3"},
      "enableAutoRetry": true,
      "maxRetryCount": 3,
      "enableTimeoutCancel": true,
      "timeoutHours": 24,
      "startCommand": "python3 -m torch.distributed.run train.py --data /root/nas/datasets",
      "computeResourceType": "ELASTIC"
    }
  }'
import requests

url = "https://api.alayanew.com/api/osm/v1/subscription/sku/training/create"
headers = {
    "accept": "application/json",
    "Content-Type": "application/json",
    "Authorization": "[your-auth-header]"
}
payload = {
    "aidcId": 1,
    "skuCode": "SKU-HPT-L40S-8C64G",
    "billingModeId": 1,
    "params": {
        "name": "llama3-8b-sft",
        "createType": "DIRECT",
        "description": "Llama3-8B 指令微调",
        "priority": 3,
        "trainingType": "pre_training",
        "trainingFramework": "pytorch",
        "imageType": "general",
        "image": "registry.example.com/public/pytorch:2.3.0-cuda12.1",
        "workerCount": 1,
        "storageConfigEnable": True,
        "storageMounts": [
            {
                "storageId": "72a2a885-e45e-4c79-aaf3-e1fa05abdb92",
                "mountPath": "/root/nas/datasets"
            }
        ],
        "env": {"CUDA_VISIBLE_DEVICES": "0,1,2,3"},
        "enableAutoRetry": True,
        "maxRetryCount": 3,
        "enableTimeoutCancel": True,
        "timeoutHours": 24,
        "startCommand": "python3 -m torch.distributed.run train.py --data /root/nas/datasets",
        "computeResourceType": "ELASTIC"
    }
}

response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
print(response.json())
const payload = {
  aidcId: 1,
  skuCode: 'SKU-HPT-L40S-8C64G',
  billingModeId: 1,
  params: {
    name: 'llama3-8b-sft',
    createType: 'DIRECT',
    description: 'Llama3-8B 指令微调',
    priority: 3,
    trainingType: 'pre_training',
    trainingFramework: 'pytorch',
    imageType: 'general',
    image: 'registry.example.com/public/pytorch:2.3.0-cuda12.1',
    workerCount: 1,
    storageConfigEnable: true,
    storageMounts: [
      {
        storageId: '72a2a885-e45e-4c79-aaf3-e1fa05abdb92',
        mountPath: '/root/nas/datasets'
      }
    ],
    env: { CUDA_VISIBLE_DEVICES: '0,1,2,3' },
    enableAutoRetry: true,
    maxRetryCount: 3,
    enableTimeoutCancel: true,
    timeoutHours: 24,
    startCommand: 'python3 -m torch.distributed.run train.py --data /root/nas/datasets',
    computeResourceType: 'ELASTIC'
  }
};

fetch('https://api.alayanew.com/api/osm/v1/subscription/sku/training/create', {
  method: 'POST',
  headers: {
    'accept': 'application/json',
    'Content-Type': 'application/json',
    'Authorization': '[your-auth-header]'
  },
  body: JSON.stringify(payload)
})
  .then(res => {
    if (!res.ok) {
      throw new Error(`HTTP error! status: ${res.status}`);
    }
    return res.json();
  })
  .then(console.log)
  .catch(console.error);
{
  "status": 200,
  "message": "OK",
  "data": {
    "subscriptionNo": "SUB-20261019-0001",
    "resourceInstanceId": "1234567890",
    "resultKey": "a1b2c3d4-0000-1111-2222-333344445555"
  }
}

最后更新于