命令行工具详情

介绍如何使用DashScope python命令行工具进行模型定制

前言

为了方便您使用模型定制功能,我们提供了python命令行工具,本文档介绍模型定制python命令行的详细使用方式

使用命令行进行模型定制及部署

前提条件

说明

以下示例展示了通过DashScope Python SDK以命令行方式进行模型定制的示例,其中需要使用您的api-key替换示例中的 your-dashscope-api-key ,代码才能正常运行。

设置DashScope api-key

export DASHSCOPE_API_KEY=your-dashscope-api-key

数据准备

上传fine-tune数据

保存数据准备中的文件,然后执行文件上传命令行。

dashscope files.upload -f fine_tune_train_example.jsonl  -p fine_tune -d 'training dataset'

文件上传成功会输出文件id,您需要拿文件id来定制模型。

Upload success, file id: fb3e5112-12af-43bd-bf61-79c7620df314

数据列表

通过命令

dashscope files.list

结果为已经上传的文件列表

file_id: fb3e5112-12af-43bd-bf61-79c7620df314, name: fine_tune_example.jsonl, description: training datasets, time: 2023-06-06 10:01:14

数据查询

dashscope files.get -i your_uploaded_file_id

结果

file_id: fb3e5112-12af-43bd-bf61-79c7620df314, name: fine_tune_example.jsonl, description: training datasets

数据删除

dashscope files.delete -i the_file_id_to_delete

定制模型

创建定制任务

获取命令帮助信息

dashscope fine_tunes.call --help

帮助信息示例

说明

随着SDK的升级,此处帮助信息可能会有所变化,此处仅做示例,请以实际为准

options:
  -h, --help            show this help message and exit
  -t TRAINING_FILE_IDS [TRAINING_FILE_IDS ...], --training_file_ids TRAINING_FILE_IDS [TRAINING_FILE_IDS ...]
                        Training file ids which upload by File command.
  -v VALIDATION_FILE_IDS [VALIDATION_FILE_IDS ...], --validation_file_ids VALIDATION_FILE_IDS [VALIDATION_FILE_IDS ...]
                        Validation file ids which upload by File command.
  -m MODEL, --model MODEL
                        The based model to start fine-tune.
  -e N_EPOCHS, --n_epochs N_EPOCHS
                        How many epochs to fine-tune.
  -b BATCH_SIZE, --batch_size BATCH_SIZE
                        How big is batch_size.
  -l LEARNING_RATE, --learning_rate LEARNING_RATE
                        The fine-tune learning rate.
  -p PROMPT_LOSS, --prompt_loss PROMPT_LOSS
                        The fine-tune prompt loss.

创建定制任务

dashscope fine_tunes.call -m qwen-v1 -t training_file_id_1 training_file_id2 -v validation_file_id_1

执行后,命令会一直等待定制任务执行,并实时输出定制任务的输出信息,定制任务通常需要运行较长时间,如果任务断开,你仍然可以通过命令(dashscope fine_tunes.stream -j your-fine-tune-job-id)继续获取输出。

The fine-tune task is: PENDING
The fine-tune task is: PENDING
Fine-tuning is RUNNING, start get output stream.
connect success, now start to follow ft-202306061011-ceea
2023-06-06 10:12:27,071 - INFO - data process succeeded, start to fine-tune

获取定制输出

dashscope fine_tunes.stream -j your-fine-tune-job-id

获取定制任务信息

dashscope fine_tunes.get -j your-fine-tune-job-id

输出(成功)

Fine-tune task success, fine-tuned model : the_fine_tuned_model_name

取消定制任务

只有PENDING和RUNNING状态的任务才可以取消

dashscope fine_tunes.cancel -j your-fine-tune-job-id

获取定制任务列表

dashscope fine_tunes.list

输出模型列表

删除定制任务

dashscope fine_tunes.delete -j your-fine-tune-job-id

定制任务的模型也会被删除

部署定制模型

部署定制模型

命令帮助信息

 dashscope deployments.call -h

帮助信息示例

说明

随着SDK的升级,此处帮助信息可能会有所变化,此处仅做示例,请以实际为准

usage: dashscope deployments.call [-h] -m MODEL [-s SUFFIX]

options:
  -h, --help            show this help message and exit
  -m MODEL, --model MODEL
                        The model ID
  -s SUFFIX, --suffix SUFFIX
                        The suffix of the deployment, lower cased characters 8 chars max.
  -c CAPACITY, --capacity CAPACITY
                        The target capacity

部署模型

dashscope deployments.call -m the-fine-tuned-model-name

命令会等待部署完成,模型部署通常需要20分钟左右,您可以根据命令输出获取部署状态。

获取部署模型信息

输出示例

Create model: qwen-v1-ft-202306061011-ceea deployment
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment qwen-v1-ft-202306061011-ceea is PENDING
Deployment: qwen-v1-ft-202306061011-ceea status: RUNNING

获取部署模型列表

dashscope deployments.list

输出为部署的模型列表

获取部署模型信息

dashscope deployments.get -d the-deployed-model-name

删除部署模型

dashscope deployments.delete -d the-deployed-model-name

调用模型

千问系列定制模型可以通过命令行调用

dashscope generation.call -m the-deployed-model-name -p '用土豆,鸡块,做一个土豆炖鸡块'

输出

{"text": "材料:\n土豆1个,鸡块500克,青椒1个,红椒1个,葱,姜,蒜适量,料酒,生抽,老抽,糖,盐适量\n\n做法:\n\n1. 鸡块洗净,入冷水锅中,焯水去除浮沫,捞出沥干水分。\n2. 土豆去皮切块,青椒、红椒切块,葱切段,姜切片,蒜备用。\n3. 锅内少许油烧热,放入葱、姜、蒜炒香,再放入鸡块煸炒。\n4. 加料酒、生抽、老抽炒匀上色。\n5. 加入适量的水,没过鸡块,同时加入土豆块、青椒块、红椒块,调入糖、盐,中火炖20分钟左右。\n6. 炖至鸡肉熟烂,土豆、青椒、红椒熟软,调入鸡精,收浓汤汁即可。", "finish_reason": "stop"}
{"input_tokens": 22, "output_tokens": 241}