快速开始
模型定制快速开始指南
前言
本文档以通义千问模型的定制为例,帮助您快速了解灵积模型服务平台提供的模型定制功能。
重要
通义千问模型定制API调用需“申请体验”并通过后才可使用,否则API调用将返回错误状态码。
快速开始
前提条件
重要
已开通服务并获得api-key:开通DashScope并创建API-KEY。
千问模型定制示例
以下示例帮助您快速体验通义千问的模型定制功能。
说明
需要使用您的api-key替换示例中的 <your-dashscope-api-key> ,代码才能正常运行。
您可以安装 DashScope Python SDK,安装后可以使用下述提供的Shell示例以命令行方式体验。
下载示例文件
您可以点击此处下载我们准备好的训练文件,用以下面的示例运行,同时也作为您后续准备自己的数据文件时的参考。
将文件上传至dashscope的文件管理中
export DASHSCOPE_API_KEY=<your-dashscope-api-key>
dashscope files.upload -f qwen-fine-tune-sample.jsonl -p fine_tune -d 'training dataset'
curl --location --request POST
'https://dashscope.aliyuncs.com/api/v1/files' \
--header 'Authorization: Bearer <your_api_key>' \
--form 'files=@"./qwen-fine-tune-sample.jsonl"' \
--form 'descriptions="a sample fine-tune data file for qwen"'
创建模型定制任务
从上一步的response中data.uploaded_files.$.file_id。放置在本步骤training_file_ids中
dashscope fine_tunes.call -m qwen-turbo -t <替换为上一步获取的file_id> -v validation_file_id_1
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":[ "<替换为上一步获取的file_id>" ],
"hyper_parameters":
{ "n_epochs":1, "batch_size":4, "learning_rate":"2e-5" }}'
查看模型定制任务的状态
在上一步的response中,您可以获取到job_id字段,为本次模型定制任务的id,您可以使用该id来查询此模型定制任务的状态。
dashscope fine_tunes.get -j <替换为您的定制任务id>
curl --location 'https://dashscope.aliyuncs.com/api/v1/fine-tunes/<替换为您的定制任务id>' \
--header 'Authorization: Bearer <your-dashscope-api-key>' \
--header 'Content-Type: application/json'
查看模型定制的过程日志
待您查询到模型定制任务的状态为"SUCCEEDED"时,表示该模型定制任务顺利完成。您可以通过下述方式查看模型定制任务的日志,用以观察训练的效果。
dashscope fine_tunes.stream -j <替换为您的定制任务id>
curl --location 'https://dashscope.aliyuncs.com/api/v1/fine-tunes/<替换为您的定制任务id>/logs?offset=0&line=100' \
--header 'Authorization: Bearer <your-dashscope-api-key>' \
--header 'Content-Type: application/json'
将定制模型部署为一个可供调用的服务
从上述定制任务的response中获取finetuned_output,作为创建模型服务的model_name参数
dashscope deployments.call -m <替换为上一步获取的finetuned_output>
curl --location 'https://dashscope.aliyuncs.com/api/v1/deployments' \
--header 'Authorization: Bearer <your-dashscope-api-key>' \
--header 'Content-Type: application/json' \
--data '{ "model_name": "<替换为上一步获取的finetuned_output>", "suffix": "sample", "capacity":1 }'
查询模型部署的状态
模型的部署需要一定的时间,通过如下方式检查部署的状态,当部署状态为RUNNING时,表示该部署当前可供调用
dashscope deployments.get -d <模型部署时获取的deployed_model>
curl --location 'https://dashscope.aliyuncs.com/api/v1/deployments/<模型部署时获取的deployed_model>' \
--header 'Authorization: Bearer <your-dashscope-api-key>' \
--header 'Content-Type: application/json'
调用定制模型
当模型部署状态为RUNNING时,您可以进行模型的调用
dashscope generation.call -m <模型部署时获取的deployed_model> -p '用土豆,鸡块,做一个土豆炖鸡块'
curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation' \
--header 'Authorization: Bearer <your-dashscope-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "<模型部署时获取的deployed_model>",
"input":{
"prompt":"用土豆,鸡块,做一个土豆炖鸡块"
},
"parameters": {
}
}'
了解更多
有关模型定制的详细API,您可前往API详情页面进一步了解。要了解支持定制的模型及数据准备等信息,您可以前往支持定制的模型列表查看。