Skip to content

Commit 5f2843b

Browse files
committed
Merge branch 'main' into release/3.0
2 parents bad62e1 + 5e15fb1 commit 5f2843b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+478
-335
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ After training is complete, use the following command to perform inference with
146146
CUDA_VISIBLE_DEVICES=0 \
147147
swift infer \
148148
--adapters output/vx-xxx/checkpoint-xxx \
149-
--stream true
149+
--stream true \
150+
--max_new_tokens 2048
150151

151152
# merge-lora and use vLLM for inference acceleration
152153
CUDA_VISIBLE_DEVICES=0 \
@@ -155,7 +156,8 @@ swift infer \
155156
--stream true \
156157
--merge_lora true \
157158
--infer_backend vllm \
158-
--max_model_len 8192
159+
--max_model_len 8192 \
160+
--max_new_tokens 2048
159161
```
160162

161163
### Web-UI
@@ -262,15 +264,17 @@ CUDA_VISIBLE_DEVICES=0 swift rlhf \
262264
CUDA_VISIBLE_DEVICES=0 swift infer \
263265
--model Qwen/Qwen2.5-7B-Instruct \
264266
--stream true \
265-
--infer_backend pt
267+
--infer_backend pt \
268+
--max_new_tokens 2048
266269

267270
# LoRA
268271
CUDA_VISIBLE_DEVICES=0 swift infer \
269272
--model Qwen/Qwen2.5-7B-Instruct \
270273
--adapters swift/test_lora \
271274
--stream true \
272275
--infer_backend pt \
273-
--temperature 0
276+
--temperature 0 \
277+
--max_new_tokens 2048
274278
```
275279

276280
### Deployment

README_CN.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ swift sft \
139139
CUDA_VISIBLE_DEVICES=0 \
140140
swift infer \
141141
--adapters output/vx-xxx/checkpoint-xxx \
142-
--stream true
142+
--stream true \
143+
--max_new_tokens 2048
143144

144145
# merge-lora并使用vLLM进行推理加速
145146
CUDA_VISIBLE_DEVICES=0 \
@@ -148,7 +149,8 @@ swift infer \
148149
--stream true \
149150
--merge_lora true \
150151
--infer_backend vllm \
151-
--max_model_len 8192
152+
--max_model_len 8192 \
153+
--max_new_tokens 2048
152154
```
153155

154156
### Web-UI
@@ -254,15 +256,17 @@ CUDA_VISIBLE_DEVICES=0 swift rlhf \
254256
CUDA_VISIBLE_DEVICES=0 swift infer \
255257
--model Qwen/Qwen2.5-7B-Instruct \
256258
--stream true \
257-
--infer_backend pt
259+
--infer_backend pt \
260+
--max_new_tokens 2048
258261

259262
# LoRA
260263
CUDA_VISIBLE_DEVICES=0 swift infer \
261264
--model Qwen/Qwen2.5-7B-Instruct \
262265
--adapters swift/test_lora \
263266
--stream true \
264267
--infer_backend pt \
265-
--temperature 0
268+
--temperature 0 \
269+
--max_new_tokens 2048
266270
```
267271

268272
### 部署

docs/source/Customization/插件化.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ example在[这里](https://github.com/modelscope/swift/blob/main/swift/plugin/ca
88

99
callback会在trainer构造前注册进trainer中,example中给出了一个简单版本的EarlyStop方案。
1010

11-
## 定制化trainer
12-
13-
example在[这里](https://github.com/modelscope/swift/blob/main/swift/plugin/custom_trainer.py).
14-
15-
用户可以在这里继承现有trainer,并实现自己的训练逻辑,例如定制data_loader、定制compute_loss等。example中给出了一个text-classification任务的trainer。
1611

1712
## 定制化loss
1813

docs/source/Customization/自定义数据集.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ query-response格式:
8181

8282
微调:
8383
```jsonl
84+
{"messages": [{"role": "user", "content": "浙江的省会在哪?"}, {"role": "assistant", "content": "浙江的省会在杭州。"}]}
8485
{"messages": [{"role": "user", "content": "<image><image>两张图片有什么区别"}, {"role": "assistant", "content": "前一张是小猫,后一张是小狗"}], "images": ["/xxx/x.jpg", "xxx/x.png"]}
8586
{"messages": [{"role": "user", "content": "<audio>语音说了什么"}, {"role": "assistant", "content": "今天天气真好呀"}], "audios": ["/xxx/x.mp3"]}
8687
{"messages": [{"role": "system", "content": "你是个有用无害的助手"}, {"role": "user", "content": "<image>图片中是什么,<video>视频中是什么"}, {"role": "assistant", "content": "图片中是一个大象,视频中是一只小狗在草地上奔跑"}], "images": ["/xxx/x.jpg"], "videos": ["/xxx/x.mp4"]}

docs/source/GetStarted/快速开始.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ swift sft \
6363
CUDA_VISIBLE_DEVICES=0 \
6464
swift infer \
6565
--adapters output/vx-xxx/checkpoint-xxx \
66-
--stream true
66+
--stream true \
67+
--max_new_tokens 2048
6768

6869
# merge-lora并使用vLLM进行推理加速
6970
CUDA_VISIBLE_DEVICES=0 \
@@ -72,7 +73,8 @@ swift infer \
7273
--stream true \
7374
--merge_lora true \
7475
--infer_backend vllm \
75-
--max_model_len 8192
76+
--max_model_len 8192 \
77+
--max_new_tokens 2048
7678
```
7779

7880
> [!TIP]

docs/source/Instruction/ReleaseNote3.0.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
- 采用messages格式作为入参接口
1919
4. 支持了plugin机制,用于定制训练过程,目前支持的plugin有:
2020
- callback 定制训练回调方法
21-
- custom_trainer 定制trainer
2221
- loss 定制loss方法
2322
- loss_scale 定制每个token的权重
2423
- metric 定制交叉验证的指标

docs/source/Instruction/命令行参数.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
- custom_register_path: 自定义模型、对话模板和数据集注册的`.py`文件路径
1717

1818
### 模型参数
19-
19+
- task_type: 默认为'causal_lm'. 可选为'causal_lm', 'seq_cls'. 例子可以查看[这里](https://github.com/modelscope/ms-swift/tree/main/examples/train/seq_cls).
2020
- 🔥model: 模型id或模型本地路径。如果是自定义模型请配合`model_type``template`使用,具体可以参考[自定义模型](../Customization/自定义模型.md)
2121
- model_type: 模型类型。相同的模型架构、template、模型加载过程被定义为一个model_type
2222
- model_revision: 模型版本
2323
- 🔥torch_dtype: 模型权重的数据类型,支持`float16`,`bfloat16`,`float32`,默认从config文件中读取
2424
- attn_impl: attention类型,支持`flash_attn`, `sdpa`, `eager`,默认使用sdpa
25+
- num_labels: 分类模型需要指定。代表标签数量,默认为None
2526
- rope_scaling: rope类型,支持`linear``dynamic`,请配合`max_length`共同使用
2627
- device_map: 模型使用的device_map配置,例如:'auto'、'cpu'、json字符串、json文件路径
2728
- local_repo_path: 部分模型在加载时依赖于github repo. 为了避免`git clone`时遇到网络问题, 可以直接使用本地repo. 该参数需要传入本地repo的路径, 默认为`None`
@@ -290,7 +291,6 @@ Vera使用`target_modules`, `target_regex`, `modules_to_save`三个参数.
290291
- resume_only_model: 如果resume_from_checkpoint,仅resume模型权重,默认为False
291292
- check_model: 检查本地模型文件有损坏或修改并给出提示,默认为True。如果是断网环境,请设置为False
292293
- loss_type: loss类型,默认使用模型自带损失函数
293-
- num_labels: 分类模型需要指定。代表标签数量,默认为None
294294

295295
- packing: 是否使用packing,默认为False
296296
- 🔥lazy_tokenize: 是否使用lazy_tokenize,在LLM训练中默认False,MLLM训练中默认True

docs/source_en/Customization/Custom-dataset.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,15 @@ For multimodal datasets, the format is the same as the tasks mentioned above. Th
7474
Pre-training:
7575
```jsonl
7676
{"messages": [{"role": "assistant", "content": "Pre-trained text goes here"}]}
77-
{"messages": [{"role": "assistant", "content": "<image> is a puppy, <image> is a kitten"}], "images": ["/xxx/x.jpg", "/xxx/x.png"]}
78-
{"messages": [{"role": "assistant", "content": "<audio> describes how nice the weather is today"}], "audios": ["/xxx/x.wav"]}
79-
{"messages": [{"role": "assistant", "content": "<image> is an elephant, <video> is a lion running"}], "images": ["/xxx/x.jpg"], "videos": ["/xxx/x.mp4"]}
77+
{"messages": [{"role": "assistant", "content": "<image>is a puppy, <image>is a kitten"}], "images": ["/xxx/x.jpg", "/xxx/x.png"]}
78+
{"messages": [{"role": "assistant", "content": "<audio>describes how nice the weather is today"}], "audios": ["/xxx/x.wav"]}
79+
{"messages": [{"role": "assistant", "content": "<image>is an elephant, <video>is a lion running"}], "images": ["/xxx/x.jpg"], "videos": ["/xxx/x.mp4"]}
8080
```
8181

8282
Supervised Fine-tuning:
8383

8484
```jsonl
85+
{"messages": [{"role": "user", "content": "Where is the capital of Zhejiang?"}, {"role": "assistant", "content": "The capital of Zhejiang is Hangzhou."}]}
8586
{"messages": [{"role": "user", "content": "<image><image>What is the difference between the two images?"}, {"role": "assistant", "content": "The first one is a kitten, and the second one is a puppy."}], "images": ["/xxx/x.jpg", "xxx/x.png"]}
8687
{"messages": [{"role": "user", "content": "<audio>What did the audio say?"}, {"role": "assistant", "content": "The weather is really nice today."}], "audios": ["/xxx/x.mp3"]}
8788
{"messages": [{"role": "system", "content": "You are a helpful and harmless assistant."}, {"role": "user", "content": "<image>What is in the image, <video>What is in the video?"}, {"role": "assistant", "content": "The image shows an elephant, and the video shows a puppy running on the grass."}], "images": ["/xxx/x.jpg"], "videos": ["/xxx/x.mp4"]}
@@ -93,7 +94,7 @@ The data format for RLHF can refer to the format used for pure text large models
9394
For grounding (object detection) tasks, SWIFT supports two methods:
9495
1. Maintain consistency with the above multimodal dataset format, adding special characters in the dataset, for example:
9596
```jsonl
96-
{"messages": [{"role": "system", "content": "You are a useful and harmless assistant"}, {"role": "user", "content": "<image> Find a <ref> elephant </ref>"}, {"role": "assistant", "content": "<box>(200,450),(500,800)</box>"}], "images": ["/xxx/x.jpg"]}
97+
{"messages": [{"role": "system", "content": "You are a useful and harmless assistant"}, {"role": "user", "content": "<image>Find a <ref> elephant </ref>"}, {"role": "assistant", "content": "<box>(200,450),(500,800)</box>"}], "images": ["/xxx/x.jpg"]}
9798
```
9899
With this type of data, please note:
99100
- Grounding tasks often require special characters. You need to determine which model to use, read the model paper to identify special characters for grounding tasks, and combine the data accordingly.
@@ -104,9 +105,9 @@ With this type of data, please note:
104105

105106
```jsonl
106107
# Object detection
107-
{"messages": [{"role": "system", "content": "You are a useful and harmless assistant"}, {"role": "user", "content": "<image> Identify <bbox>"}, {"role": "assistant", "content": "<ref-object>"}], "images": ["/coco2014/train2014/COCO_train2014_000000001507.jpg"], "objects": "[{\"caption\": \"guy in red\", \"bbox\": [138, 136, 235, 359], \"bbox_type\": \"real\", \"image\": 0}]"}
108+
{"messages": [{"role": "system", "content": "You are a useful and harmless assistant"}, {"role": "user", "content": "<image>Identify <bbox>"}, {"role": "assistant", "content": "<ref-object>"}], "images": ["/coco2014/train2014/COCO_train2014_000000001507.jpg"], "objects": "[{\"caption\": \"guy in red\", \"bbox\": [138, 136, 235, 359], \"bbox_type\": \"real\", \"image\": 0}]"}
108109
# Grounding to multiple bboxes
109-
{"messages": [{"role": "system", "content": "You are a useful and harmless assistant"}, {"role": "user", "content": "<image> Find <ref-object>"}, {"role": "assistant", "content": "<bbox>"}], "images": ["/coco2014/train2014/COCO_train2014_000000001507.jpg"], "objects": "[{\"caption\": \"guy in red\", \"bbox\": [[138, 136, 235, 359], [1,2,3,4]], \"bbox_type\": \"real\", \"image\": 0}]"}
110+
{"messages": [{"role": "system", "content": "You are a useful and harmless assistant"}, {"role": "user", "content": "<image>Find <ref-object>"}, {"role": "assistant", "content": "<bbox>"}], "images": ["/coco2014/train2014/COCO_train2014_000000001507.jpg"], "objects": "[{\"caption\": \"guy in red\", \"bbox\": [[138, 136, 235, 359], [1,2,3,4]], \"bbox_type\": \"real\", \"image\": 0}]"}
110111
```
111112

112113
This format adds the objects field, which includes:

docs/source_en/Customization/Pluginization.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ Examples can be found [here](https://github.com/modelscope/swift/blob/main/swift
88

99
Callbacks are registered into the trainer before constructing the trainer. The example provides a simple version of the EarlyStop scheme.
1010

11-
## Customized Trainer
12-
13-
Examples can be found [here](https://github.com/modelscope/swift/blob/main/swift/plugin/custom_trainer.py).
14-
15-
Users can inherit existing trainers and implement their own training logic here, such as customizing data loaders, customizing compute_loss, etc. The example demonstrates a trainer for a text-classification task.
16-
1711
## Customized Loss
1812

1913
Examples can be found [here](https://github.com/modelscope/swift/blob/main/swift/plugin/loss.py).

docs/source_en/GetStarted/Quick-start.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ After training is complete, use the following command to perform inference with
6363
CUDA_VISIBLE_DEVICES=0 \
6464
swift infer \
6565
--adapters output/vx-xxx/checkpoint-xxx \
66-
--stream true
66+
--stream true \
67+
--max_new_tokens 2048
6768

6869
# merge-lora and use vLLM for inference acceleration
6970
CUDA_VISIBLE_DEVICES=0 \
@@ -72,7 +73,8 @@ swift infer \
7273
--stream true \
7374
--merge_lora true \
7475
--infer_backend vllm \
75-
--max_model_len 8192
76+
--max_model_len 8192 \
77+
--max_new_tokens 2048
7678
```
7779

7880
> [!TIP]

0 commit comments

Comments
 (0)