文档

API详情

更新时间:

概述

本文将详细介绍模型定制的API,使用这些API,您可以:

  • 使用您的数据并指定一个基础模型来创建模型定制任务。

  • 列举或查看您创建的定制任务及其状态。

  • 查看定制任务的过程日志。

  • 删除或取消一个定制任务。

说明

创建模型定制任务时,根据基础模型的不同,所需要的训练数据、超参数等会有所不同,具体可参考支持定制的模型列表。

HTTP调用接口

前提条件

已开通服务并获得API-KEY,具体操作请参见开通DashScope并创建API-KEY

以下示例展示通过curl命令来调用定制模型的API。

说明

需要使用您的API-KEY替换示例中的<YOUR-DASHSCOPE-API-KEY>才能正常运行。

文件管理

您可以使用DashScope提供的文件服务来管理您的训练文件,详细的api请参考模型定制文件管理服务

管理定制

创建定制任务

POST https://dashscope.aliyuncs.com/api/v1/fine-tunes
Accept: application/json
  • 请求参数

    字段

    类型

    传参方式

    必选

    描述

    job_name

    String

    Body

    自定义任务名称,缺失该参数时,会使用自动生成的任务id替代

    training_file_ids

    Array

    Body

    训练集文件列表。

    validation_file_ids

    Array

    Body

    验证集文件列表。

    model

    String

    Body

    用于定制的基础模型名,或其他定制任务产出的finetuned_output。

    hypter_parameters

    Map

    Body

    用于定制模型的超参数,缺失该参数时系统会使用默认值进行定制。

    training_type

    String

    Body

    训练方法,可选值如下:

    • sft:全参训练。

    • efficient_sft:高效训练,一般为LoRa方式。

  • 请求示例

    curl --location 'https://dashscope.aliyuncs.com/api/v1/fine-tunes' \
    --header 'Authorization: Bearer <YOUR-DASHSCOPE-API-KEY>' \
    --header 'Content-Type: application/json' \
    --data '{
        "model":"qwen-turbo",
        "training_file_ids":[
            "98e0ec51-8edc-4948-bdba-11429756716f"
        ],
        "hyper_parameters":{
            "n_epochs":1,
            "batch_size":16,
            "learning_rate":"1.6e-5"
        }
    }'
  • 返回数据

    字段

    类型

    描述

    output.job_id

    String

    本次创建请求产生的定制任务的任务ID。

    output.job_name

    String

    本次创建请求产生的定制任务的任务名称。

    output.model

    String

    本次训练所使用的起始模型

    output.base_model

    String

    本次训练所使用的起始模型的基模型

    output.training_file_ids

    Array

    本次训练您传入的训练文件

    output.validation_file_ids

    Array

    本次训练您传入的验证文件

    output.hyper_parameters

    Map

    本次训练您设置的超参数,如果您未设置超参数,此处会返回系统默认值

    output.training_type

    String

    本次训练您选择的训练方法

    output.create_time

    String

    训练任务创建时间

    output.status

    String

    本次创建请求产生的定制任务的状态。

    request_id

    String

    本次请求的系统唯一码。

  • 返回示例

    {
        "request_id": "6332fb02-3111-43f0-bf79-f9e8c5ffa7f9",
        "output": {
            "job_id": "ft-202305251344-80b0",
            "job_name": "ft-202305251344-80b0",
            "status": "PENDING",
            "model": "qwen-turbo",
            "base_model": "qwen-turbo",
            "training_file_ids": [
              	"98e0ec51-8edc-4948-bdba-11429756716f"
            ],
            "hyper_parameters": {
              	"n_epochs":1,
            		"batch_size":16,
            		"learning_rate":"1.6e-5"
            },
            "training_type": "sft",
            "create_time": "2024-01-01 00:00:00"
        }
    }

查询定制任务

GET https://dashscope.aliyuncs.com/api/v1/fine-tunes/{job_id}
Accept: application/json
  • 请求参数

    字段

    类型

    传参方式

    必选

    描述

    job_id

    String

    Url Path

    要查询的定制任务的ID。

  • 请求示例

    curl --location --request GET 'https://dashscope.aliyuncs.com/api/v1/fine-tunes/ft-202305251344-80b0' \
    --header 'Authorization: Bearer <YOUR-DASHSCOPE-API-KEY>' \
    --header 'Content-Type: application/json'
  • 返回数据

    字段

    类型

    描述

    output.job_id

    String

    定制任务的任务ID。

    output.status

    String

    定制任务的状态。

    output.model

    String

    定制任务的基础模型。

    output.finetuned_output

    String

    定制任务产出的模型,只有在定制任务成功后才显示该字段。

    output.training_file_ids

    Array

    定制任务使用的训练文件。

    output.hyper_parameters

    Map

    创建定制任务时传入的超参数。

    output.code

    String

    错误码,当任务失败时展示该字段。

    request_id

    String

    本次请求的系统唯一码。

  • 返回示例

    {
        "request_id": "1aa3d2df-8d58-4de8-9592-3216c346ea6b",
        "output": {
            "job_id": "ft-202305251119-8a43",
            "status": "SUCCEEDED",
            "finetuned_output": "qwen-turbo-ft-202305251119-8a43",
            "model": "qwen-turbo",
            "training_file_ids": [
                "98e0ec51-8edc-4948-bdba-11429756716f"
            ],
            "hyper_parameters": {
                "n_epochs": 1,
                "batch_size": 16,
                "learning_rate": "1e-5",
                "prompt_loss": "0.9"
            }
        }
    }

列举定制任务

GET https://dashscope.aliyuncs.com/api/v1/fine-tunes
Accept: application/json
  • 请求参数

    字段

    类型

    传参方式

    必选

    描述

    page_no

    Number

    Query

    页码,默认为1。

    page_size

    Number

    Query

    分页大小,默认为10,最大值为100,最小值为1。

  • 请求示例

    curl --location 'https://dashscope.aliyuncs.com/api/v1/fine-tunes' \
    --header 'Authorization: Bearer <YOUR-DASHSCOPE-API-KEY>' \
    --header 'Content-Type: application/json'
  • 返回数据

    字段

    类型

    描述

    output.total

    Number

    总记录条数。

    output.jobs.$.job_id

    String

    定制任务的任务ID。

    output.jobs.$.status

    String

    定制任务的状态。

    output.jobs.$.model

    String

    定制任务的基础模型。

    output.jobs.$.finetuned_output

    String

    定制任务产出的模型,只有在定制任务成功后才显示该字段。

    output.jobs.$.training_file_ids

    Array

    定制任务使用的训练文件。

    output.jobs.$.hyper_parameters

    Map

    创建定制任务时传入的超参数。

    request_id

    String

    本次请求的系统唯一码。

  • 返回示例

    {
        "request_id":"1aa3d2df-8d58-4de8-9592-3216c346ea6b",
        "output":{
            "jobs":[
                {
                    "job_id":"ft-202305251119-8a43",
                    "status":"SUCCEEDED",
                    "finetuned_output":"qwen-turbo-ft-202305251119-8a43",
                    "model":"qwen-turbo",
                    "training_file_ids":[
                        "98e0ec51-8edc-4948-bdba-11429756716f"
                    ],
                    "hyper_parameters":{
                        "n_epochs":1,
                        "batch_size":16,
                        "learning_rate":"1e-5",
                        "prompt_loss":"0.9"
                    }
                }
            ]
        }
    }

删除定制任务

DELETE https://dashscope.aliyuncs.com/api/v1/fine-tunes/{job_id}
Accept: application/json
  • 请求参数

    字段

    类型

    传参方式

    必选

    描述

    job_id

    String

    Url Path

    要删除的定制任务的ID。

  • 请求示例

    curl --location --request DELETE 'https://dashscope.aliyuncs.com/api/v1/fine-tunes/ft-202305251344-80b0' \
    --header 'Authorization: Bearer <YOUR-DASHSCOPE-API-KEY>' \
    --header 'Content-Type: application/json'
  • 返回数据

    字段

    类型

    描述

    output.status

    String

    本次删除结果。

    request_id

    String

    本次请求的系统唯一码。

  • 返回示例

    {
        "request_id":"1aa3d2df-8d58-4de8-9592-3216c346ea6b",
        "output":{
             "status":"success"
        }
    }

取消定制任务

POST https://dashscope.aliyuncs.com/api/v1/fine-tunes/{job_id}/cancel
Accept: application/json
  • 请求参数

    字段

    类型

    传参方式

    必选

    描述

    job_id

    String

    Url Path

    要取消的定制任务的ID。

  • 请求示例

    curl --location --request POST 'https://dashscope.aliyuncs.com/api/v1/fine-tunes/ft-202305251344-80b0/cancel' \
    --header 'Authorization: Bearer <YOUR-DASHSCOPE-API-KEY>' \
    --header 'Content-Type: application/json'
  • 返回数据

    字段

    类型

    描述

    output.status

    String

    本次取消的结果。

    request_id

    String

    本次请求的系统唯一码。

  • 返回示例

    {
        "request_id":"1aa3d2df-8d58-4de8-9592-3216c346ea6b",
        "output":{
             "status":"success"
        }
    }

获取定制任务的输出

GET https://dashscope.aliyuncs.com/api/v1/fine-tunes/{job_id}/logs
Accept: application/json
  • 请求参数

    字段

    类型

    传参方式

    必选

    描述

    job_id

    String

    Url Path

    要取消的定制任务的ID。

    offset

    Number

    Query

    忽略前offset行输出,从第offset+1行开始读取。不能超过当前已有输出的总行数,超过则不会有输出信息返回。默认值为0。

    line

    Number

    Query

    从offset+1行(包含)起,读取line行输出信息,如果本次请求的输出不足line行,则以实际输出为准。默认值为100,上限为1000。

  • 请求示例

    curl --location 'https://dashscope.aliyuncs.com/api/v1/fine-tunes/ft-202305251344-80b0/logs?offset=0&line=100' \
    --header 'Authorization: Bearer <YOUR-DASHSCOPE-API-KEY>' \
    --header 'Content-Type: application/json'
  • 返回数据

    字段

    类型

    描述

    output.total

    Number

    当前已有的输出信息条数。

    output.logs

    Array

    输出信息数组。

    request_id

    String

    本次请求的系统唯一码。

  • 返回示例

    {
        "request_id":"BE213CDD-8A5C-59EE-9A67-055EAB0CB59B",
        "output":{
            "total":1744,
            "logs":[
                "2023-06-06 18:56:03,416 - INFO - data process succeeded, start to fine-tune",
                "2023-06-07 10:49:25,680 - dashscope - INFO -  epoch(eval) [10][1]	memory: 54058, evaluation/accuracy: 0.6000, evaluation/loss: 3.7001",
                "2023-06-06 18:58:25,083 - INFO - ##FT_COMPLETE##"
            ]
        }
    }

请求错误码说明

请求异常时返回

字段

类型

描述

示例值

code

String

错误码。

NotFound

request_id

String

本次请求的系统唯一码。

6332fb02-3111-43f0-bf79-f9e8c5ffa7f9

message

String

错误信息。

Not Found!

请求异常示例

{
  "code": "NotFound",
  "request_id": "BE213CDD-8A5C-59EE-9A67-055EAB0CB59B",
  "message": "Not Found!"
}

错误码列表

http状态码

错误码

错误信息举例

含义

处理方式

400

InvalidParameter

Missing training files

参数错误,缺少参数或者参数格式问题等。

根据错误信息,修正您的参数。

400

UnsupportedOperation

The fine-tune job can not be deleted because it is succeeded,failed or canceled

当资源处于特定状态时,无法对其进行操作。

待要操作的资源到达可操作状态时再进行操作。

404

NotFound

Not found!

要查询/操作的资源不存在。

检查要查询/操作的资源ID是否错误。

409

Conflict

Model instance xxxxx already exists, please specify a suffix

已存在deployed_model名为xxxxx的部署实例,需要指定后缀进行区分。

为部署指定唯一的后缀。

429

Throttling

Too many fine-tune job in running, please retry later

资源的创建触发平台限制。

稍后再试。

500

InternalError

Internal server error!

内部错误。

记录request_id,通过工单联系阿里云工程师进行排查。

  • 本页导读 (0)
文档反馈