modelscope-funasr怎么微调performer-zh模型?
要微调ModelScope-FunASR中的performer-zh
模型,您可以按照以下步骤操作。这些步骤基于阿里云百炼平台提供的模型微调功能。
微调模型需要准备符合格式要求的训练数据集。以下是具体要求:
system
、user
、assistant
等角色的消息。准备好数据后,将其保存为本地文件(如train_data.jsonl
)。
将本地训练数据上传至百炼平台,获取文件ID(file_id
)。以下是两种上传方式:
dashscope files.upload -f '<替换为训练数据集的本地文件路径>' -p fine_tune -d 'training dataset'
curl --location --request POST 'https://dashscope.aliyuncs.com/api/v1/files' \
--header 'Authorization: Bearer ${DASHSCOPE_API_KEY}' \
--form 'files=@"<替换为训练数据集的本地文件路径>"' \
--form 'descriptions="a sample fine-tune data file for performer-zh"'
上传成功后,您会获得一个file_id
,用于后续创建微调任务。
使用上传的训练数据创建微调任务,指定performer-zh
模型进行微调。
dashscope fine_tunes.call -m performer-zh -t '<替换为训练数据集的file_id>' \
--mode sft -b 16 -e 1 -l 1.6e-5 \
--hyper_parameters split=0.9 warmup_ratio=0.0 eval_steps=1
curl --location 'https://dashscope.aliyuncs.com/api/v1/fine-tunes' \
--header 'Authorization: Bearer ${DASHSCOPE_API_KEY}' \
--header 'Content-Type: application/json' \
--data '{
"model":"performer-zh",
"training_file_ids":["<替换为训练数据集的file_id>"],
"hyper_parameters":{
"n_epochs":1,
"batch_size":16,
"learning_rate":"1.6e-5",
"split":0.9,
"warmup_ratio":0.0,
"eval_steps":1
},
"training_type":"sft"
}'
注意:请根据实际需求调整超参数(如batch_size
、learning_rate
等)。
创建微调任务后,可以通过以下命令查看任务状态,确保任务成功完成。
dashscope fine_tunes.get -j <替换为您的微调任务 id>
curl --location 'https://dashscope.aliyuncs.com/api/v1/fine-tunes/<替换为您的微调任务 id>' \
--header 'Authorization: Bearer ${DASHSCOPE_API_KEY}' \
--header 'Content-Type: application/json'
任务状态说明: - PENDING
:任务待开始。 - RUNNING
:任务正在进行中。 - SUCCEEDED
:任务成功完成。 - FAILED
:任务失败。
如果任务失败,可以通过以下命令查看日志以排查问题。
如果微调任务未成功完成,可以通过以下命令查看详细日志。
dashscope fine_tunes.stream -j <替换为您的微调任务 id>
curl --location 'https://dashscope.aliyuncs.com/api/v1/fine-tunes/<替换为您的微调任务 id>/logs?offset=0&line=1000' \
--header 'Authorization: Bearer ${DASHSCOPE_API_KEY}' \
--header 'Content-Type: application/json'
当微调任务成功完成后,返回结果中会包含微调后的模型 ID。例如:
{
"finetuned_output": "performer-zh-ft-202410121111-a590"
}
记录下该模型 ID(如performer-zh-ft-202410121111-a590
),用于后续部署和调用。
将微调后的模型部署为在线服务,以便调用。
dashscope deployments.call -c 2 -m <替换为微调任务成功后的模型 ID>
curl --location 'https://dashscope.aliyuncs.com/api/v1/deployments' \
--header 'Authorization: Bearer ${DASHSCOPE_API_KEY}' \
--header 'Content-Type: application/json' \
--data '{
"model_name": "<替换为微调任务成功后的模型 ID>",
"capacity":2
}'
注意:capacity
参数表示实例数量,可根据实际需求调整。
部署完成后,可以通过以下方式调用微调后的模型。
dashscope generation.call -m <替换为部署任务成功后的模型实例 ID> -p '测试输入'
curl --location 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation' \
--header 'Authorization: Bearer ${DASHSCOPE_API_KEY}' \
--header 'Content-Type: application/json' \
--data '{
"model": "<替换为部署任务成功后的模型实例 ID>",
"input":{
"messages":[
{
"role": "user",
"content": "测试输入"
}
]
},
"parameters": {
"result_format": "message"
}
}'
DASHSCOPE_API_KEY
环境变量。通过以上步骤,您可以顺利完成performer-zh
模型的微调、部署和调用。