Skip to content

Commit 928306b

Browse files
committed
Merge commit '9dfa63a060ba6de6f53a0a00cf99c3025ea3fe18' into feat/qwen3-emb
* commit '9dfa63a060ba6de6f53a0a00cf99c3025ea3fe18': (35 commits) Fix create checkpoint symlink & grpo omni (modelscope#4468) [grpo] fix base url (modelscope#4463) [train] Fix qwen2.5-vl use_cache (modelscope#4458) [seq_parallel] fix sp compute_acc (modelscope#4456) [dpo] support dpo padding_free/logits_to_keep & dpo compat trl==0.18 (modelscope#4394) [grpo] fix hang in colocate lora settings (modelscope#4451) [grpo] Two-Sided Clipping for GRPO Trainer (modelscope#4450) [grpo] support vllm_server_base_url for vLLMClient (modelscope#4449) [template] fix vlm padding_free/logits_to_keep (modelscope#4444) fix qwen2_5_vl awq (modelscope#4436) [megatron] support megatron num_train_epochs (modelscope#4432) fix emb docs (modelscope#4434) fix model_meta (modelscope#4431) [model] Support MiMo-VL (modelscope#4429) [dataset] add ms_logger_context (modelscope#4428) [dataset] fix self-cognition & load_from_cache_file (modelscope#4426) fix transformers 4.52 device_map ddp (modelscope#4424) Fix cmdline parsing error on Windows system (modelscope#4422) support DeepSeek-R1-0528-Qwen3-8B (modelscope#4417) [pt/sft] support use_logits_to_keep & support DeepSeek-R1-0528 (modelscope#4409) ... # Conflicts: # README.md # README_CN.md
2 parents 812469b + 9dfa63a commit 928306b

File tree

102 files changed

+1650
-877
lines changed

Some content is hidden

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

102 files changed

+1650
-877
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ You can contact us and communicate with us by adding our group:
7474

7575

7676
## 🎉 News
77-
- 🎁 2025.05.26: We support the training of Qwen3-embedding models, please check the script [here](examples/train/embedding/train_emb.sh).
77+
- 🎁 2025.06.05: We support the training of Qwen3-embedding models, please check the script [here](examples/train/embedding/train_emb.sh).
78+
- 🎁 2025.05.29: Support sequence parallel in pt, sft, dpo and grpo, check script [here](https://github.com/modelscope/ms-swift/tree/main/examples/train/long_text).
7879
- 🎁 2025.05.11: GRPO now supports custom processing logic for reward models. See the GenRM example [here](./docs/source_en/Instruction/GRPO.md#customized-reward-models).
7980
- 🎁 2025.04.15: The ms-swift paper has been accepted by AAAI 2025. You can find the paper at [this link](https://ojs.aaai.org/index.php/AAAI/article/view/35383).
8081
- 🎁 2025.03.23: Multi-round GRPO is now supported for training multi-turn dialogue scenarios (e.g., agent tool calling). Please refer to the [training script](examples/train/grpo/internal/vllm_multi_round.sh).
@@ -121,7 +122,7 @@ Running Environment:
121122
| peft | >=0.11,<0.16 | ||
122123
| trl | >=0.13,<0.18 | 0.17 |RLHF|
123124
| deepspeed | >=0.14 | 0.14.5 | Training |
124-
| vllm | >=0.5.1 | 0.7.3/0.8 | Inference/Deployment/Evaluation |
125+
| vllm | >=0.5.1 | 0.8 | Inference/Deployment/Evaluation |
125126
| lmdeploy | >=0.5 | 0.8 | Inference/Deployment/Evaluation |
126127
| evalscope | >=0.11 | | Evaluation |
127128

README_CN.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
- **模型量化**:支持AWQ、GPTQ和BNB的量化导出,导出的模型支持使用vLLM/LmDeploy推理加速,并支持继续训练。
7171

7272
## 🎉 新闻
73-
- 🎁 2025.05.26: 支持Qwen3-embedding模型的训练, 训练脚本参考[这里](examples/train/embedding/train_emb.sh).
73+
- 🎁 2025.06-05: 支持Qwen3-embedding模型的训练, 训练脚本参考[这里](examples/train/embedding/train_emb.sh).
74+
- 🎁 2025.05.29: 支持pt、sft、dpo、grpo的序列并行,具体请查看[脚本](https://github.com/modelscope/ms-swift/tree/main/examples/train/long_text).
7475
- 🎁 2025.05.11: GRPO中的奖励模型支持自定义处理逻辑,GenRM的例子参考[这里](./docs/source/Instruction/GRPO.md#自定义奖励模型)
7576
- 🎁 2025.04.15: ms-swift论文已经被AAAI 2025接收,论文地址在[这里](https://ojs.aaai.org/index.php/AAAI/article/view/35383)
7677
- 🎁 2025.03.23: 支持了多轮GRPO,用于构建多轮对话场景的训练(例如agent tool calling),请查看[训练脚本](examples/train/grpo/internal/vllm_multi_round.sh)
@@ -117,7 +118,7 @@ pip install -e .
117118
| peft | >=0.11,<0.16 | ||
118119
| trl | >=0.13,<0.18 | 0.17 |RLHF|
119120
| deepspeed | >=0.14 | 0.14.5 |训练|
120-
| vllm | >=0.5.1 | 0.7.3/0.8 |推理/部署/评测|
121+
| vllm | >=0.5.1 | 0.8 |推理/部署/评测|
121122
| lmdeploy | >=0.5 | 0.8 |推理/部署/评测|
122123
| evalscope | >=0.11 | |评测|
123124

docs/source/BestPractices/Embedding训练.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,17 @@ SWIFT提供了两个脚手架训练脚本:
9595

9696
- [gte模型](https://github.com/tastelikefeet/swift/blob/main/examples/train/embedding/train_gte.sh)
9797
- [gme模型](https://github.com/tastelikefeet/swift/blob/main/examples/train/embedding/train_gme.sh)
98+
99+
## 推理
100+
101+
SWIFT当前没有支持Embedding的模型推理和部署(时间问题),可以使用原模型的代码进行推理:
102+
103+
https://www.modelscope.cn/models/iic/gte_Qwen2-7B-instruct
104+
105+
https://www.modelscope.cn/models/iic/gme-Qwen2-VL-7B-Instruct
106+
107+
如果使用了其他模型从0训练embedding(例如,原版`qwen2-vl`模型+`--task_type embedding`),也可以使用gme的推理代码,但请注意:
108+
109+
https://www.modelscope.cn/models/iic/gme-Qwen2-VL-7B-Instruct/file/view/master/gme_inference.py?status=1#L111
110+
111+
这里的模板请修改为模型自身的template,以免最后的embedding对不上。需要额外注意的是,gme模型的template和`qwen2-vl``qwen2.5-vl`系列的chatml template并不相同,其推理代码最后的结束字符是`<|endoftext|>`而非`<|im_end|>`.

docs/source/GetStarted/SWIFT安装.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu2
7777
| peft | >=0.11,<0.16 | ||
7878
| trl | >=0.13,<0.18 | 0.17 |RLHF|
7979
| deepspeed | >=0.14 | 0.14.5 |训练|
80-
| vllm | >=0.5.1 | 0.7.3/0.8 |推理/部署/评测|
80+
| vllm | >=0.5.1 | 0.8 |推理/部署/评测|
8181
| lmdeploy | >=0.5 | 0.8 |推理/部署/评测|
8282
| evalscope | >=0.11 | |评测|
8383

docs/source/Instruction/GRPO.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ pip install -U trl
1313
GRPOTrainer在swift3.5.dev进行了代码重构,如果你使用的swift版本<3.5, 请参考[stable文档](https://github.com/modelscope/ms-swift/blob/v3.4.1/docs/source/Instruction/GRPO.md)
1414

1515
**更新日志**
16-
- **2025-05-23** — 支持自定义采样批量大小,参考 generation_batch_size / steps_per_generation 参数
17-
- **2025-05-22** — swift rollout 支持 data_parallel_size 参数
18-
- **2025-05-16** - 增加 ref_model 同步逻辑,参考参数 sync_ref_model
16+
- **2025-05-29** — 支持了padding_free(--padding_free true)和序列并行(--sequence_parallel_size N)。
17+
- **2025-05-23** — 支持自定义采样批量大小,参考 generation_batch_size / steps_per_generation 参数。
18+
- **2025-05-22** — swift rollout 支持 data_parallel_size 参数。
19+
- **2025-05-16** - 增加 ref_model 同步逻辑,参考参数 sync_ref_model。
1920
- **2025-05-13** — 为了代码的可读性和维护性, GRPOTrainer代码重构,Internal mode 支持vLLM>=0.8。
2021
- **2025-05-11** — 支持生成式奖励模型,通过 reward_model_plugin 自定义奖励模型逻辑。有关更多详细信息,请参阅[自定义奖励模型](#自定义奖励模型)部分。
2122
- **2025-04-30** — external vllm server 的启动命令改为 `swift rollout`
@@ -208,6 +209,7 @@ A conversation between User and Assistant. The user asks a question, and the Ass
208209
- use_vllm: 是否使用 vLLM 作为 GRPO 生成的 infer_backend,默认为False。
209210
- vllm_mode: vLLM 集成模式,可选项为 `server``colocate`。server 模式使用 `swift rollout` 拉起的 vLLM 服务器进行采样,colocate 模式在程序内部署 vLLM。
210211
- vllm_mode server 参数
212+
- vllm_server_base_url: vLLM server的Base URL(比如 http://local_host:8000), 默认为None。设置后,忽略host和port设置。
211213
- vllm_server_host:vLLM server host地址,默认为None,使用外部vLLM server时使用.
212214
- vllm_server_port vLLM server 服务端口,默认为8000.
213215
- vllm_server_timeout 连接vLLM server的超时时间,默认为120s.
@@ -219,23 +221,26 @@ A conversation between User and Assistant. The user asks a question, and the Ass
219221
- vllm_limit_mm_per_prompt: vllm透传参数,默认为None.
220222
- vllm_enable_prefix_caching: vllm透传参数,默认为True.
221223
- sleep_level: 训练时释放 vLLM 显存,可选项为[0, 1], 默认为0,不释放.
224+
- move_model_batches: 在模型向vLLM等快速推理框架移动参数时,将layers分为多少个batch. 默认为None, 代表整个模型不进行拆分,否则拆分为move_model_batches+1(非layer参数)+1(多模态部分参数)个。
225+
- offload_optimizer: 是否在vLLM推理时offload optimizer参数,默认为False。
226+
- offload_model: 是否在vLLM推理时offload 模型本身,默认为False。
227+
- gc_collect_after_offload: 是否在offload结束时进行gc(python gc和GPU gc),默认为False。
228+
- completion_length_limit_scope: 在多轮对话中,`max_completion_length` 的限制范围。
229+
`total`限制所有对话轮次的总输出长度不超过`max_completion_length`, `per_round`限制每一轮的输出长度。
230+
默认为`per_round`, 当前仅对 colocate mode 生效。
222231
- num_iterations: 每个批次代更新次数,默认为1。
223232
- epsilon: clip 系数,默认为0.2。
224233
- epsilon_high: upper clip 系数,默认为None,设置后与epsilon共同构成[epsilon, epsilon_high]裁剪范围。
234+
- delta: [INTELLECT-2 tech report](https://huggingface.co/papers/2505.07291)中双侧 GRPO 上界裁剪值。若设置,建议大于 1 + epsilon。默认为None。
225235
- sync_ref_model: 是否定期同步ref_model,默认为False。
226236
- ref_model_mixup_alpha: 控制在更新过程中model和先前ref_model之间的混合。更新公式为 $π_{ref} = α * π_θ + (1 - α) * π_{ref_{prev}}$。默认为0.6。
227237
- ref_model_sync_steps:同步频率,默认为512。
228-
- move_model_batches: 在模型向vLLM等快速推理框架移动参数时,将layers分为多少个batch. 默认为None, 代表整个模型不进行拆分,否则拆分为move_model_batches+1(非layer参数)+1(多模态部分参数)个。
229-
- offload_optimizer: 是否在vLLM推理时offload optimizer参数,默认为False。
230-
- offload_model: 是否在vLLM推理时offload 模型本身,默认为False。
231-
- gc_collect_after_offload: 是否在offload结束时进行gc(python gc和GPU gc),默认为False。
232238
- multi_turn_func: 多轮GRPO参数, 传入对应的plugin名称, 同时在plugin/multi_turn.py中添加好对应的实现。
233-
- completion_length_limit_scope: 在多轮对话中,`max_completion_length` 的限制范围。
234-
`total`限制所有对话轮次的总输出长度不超过`max_completion_length`, `per_round`限制每一轮的输出长度。
235-
默认为`per_round`, 当前仅对 colocate mode 生效。
236239
- dynamic_sample:筛除group内奖励标准差为0的数据,额外采样新数据,默认为False。
237240
- max_resample_times:dynamic_sample设置下限制重采样次数,默认3次。
238241
- overlong_filter:跳过超长截断的样本,不参与loss计算,默认为False。
242+
- padding_free: 去掉所有padding token,并将有效token拼接到一个batch中,仅支持flash_attn.
243+
- sequence_parallel_size: 序列并行段数
239244

240245
奖励函数参数,见[内置奖励函数](#内置奖励函数)
241246

docs/source/Instruction/Megatron-SWIFT训练.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SWIFT引入了Megatron的并行技术来加速大模型的训练,包括数据
1111
pip install pybind11
1212
# transformer_engine
1313
# 若出现安装错误,可以参考该issue解决: https://github.com/modelscope/ms-swift/issues/3793
14+
# ms-swift使用此版本测试: pip install git+https://github.com/NVIDIA/TransformerEngine.git@9c8ba5c8d1a9a8479ab45fbf7951025a393e7c66
1415
pip install git+https://github.com/NVIDIA/TransformerEngine.git@stable
1516

1617
# apex
@@ -158,6 +159,7 @@ I am a language model developed by swift, you can call me swift-robot. How can I
158159
- no_rope_fusion: 默认为False。指定`--no_rope_fusion true`用于禁止rope融合。
159160
- no_gradient_accumulation_fusion: 默认为False。指定`--no_gradient_accumulation_fusion true`用于禁用梯度累加融合。
160161
- 🔥cross_entropy_loss_fusion: 启动交叉熵损失计算融合。默认为False。
162+
- cross_entropy_fusion_impl: 交叉熵损失融合的实现。可选为'native'和'te'。默认为'native'。
161163
- calculate_per_token_loss: 根据全局批次中的非填充token数量来对交叉熵损失进行缩放。默认为True。
162164
- 🔥attention_backend: 使用的注意力后端 (flash、fused、unfused、local、auto)。默认为 auto。
163165
- optimizer: 优化器类型,可选为'adam'、'sgd'。默认为adam。
@@ -208,8 +210,8 @@ I am a language model developed by swift, you can call me swift-robot. How can I
208210
- 🔥use_distributed_optimizer: 使用分布式优化器。默认为True。
209211
- 🔥tensor_model_parallel_size: tp数,默认为1。
210212
- 🔥pipeline_model_parallel_size: pp数,默认为1。
211-
- decoder_first_pipeline_num_layers: decoder第一个流水线阶段所包含的Transformer层数。默认为 None,表示将Transformer层数平均分配到所有流水线阶段。
212-
- decoder_last_pipeline_num_layers: decoder最后一个流水线阶段所包含的Transformer层数。默认为 None,表示将Transformer层数平均分配到所有流水线阶段。
213+
- 🔥decoder_first_pipeline_num_layers: decoder第一个流水线阶段所包含的Transformer层数。默认为 None,表示将Transformer层数平均分配到所有流水线阶段。
214+
- 🔥decoder_last_pipeline_num_layers: decoder最后一个流水线阶段所包含的Transformer层数。默认为 None,表示将Transformer层数平均分配到所有流水线阶段。
213215
- 🔥sequence_parallel: 启动序列并行的优化器。默认为False。
214216
- 🔥context_parallel_size: cp数,默认为1。
215217
- tp_comm_overlap: 启用张量并行通信与GEMM(通用矩阵乘法)内核的重叠(降低通信耗时)。默认为False。
@@ -276,8 +278,11 @@ I am a language model developed by swift, you can call me swift-robot. How can I
276278
- moe_router_topk: 每个token路由到的专家数量。默认为None。自动从config.json读取。
277279
- moe_router_pre_softmax: 为MoE启用预softmax路由,这意味着softmax会在top-k选择之前进行。默认为None。自动从config.json读取。
278280
- 🔥moe_aux_loss_coeff: 辅助损失的缩放系数:建议的初始值为 1e-2。默认为None。自动从config.json读取。
281+
- moe_router_dtype: 用于路由计算和专家输出加权平均的数据类型。可选为'fp32'、'fp64',这增强了数值稳定性,尤其是在专家数量较多时。与`moe_permute_fusion`一起使用时,性能影响可以忽略不计。默认为None,不改变数据类型。
282+
- moe_permute_fusion: 在令牌分发过程中融合令牌重排操作。默认为False。
279283
- 🔥expert_model_parallel_size: 专家并行数,默认为1。
280-
- moe_token_dispatcher_type: 要使用的token分发器类型。可选选项包括 'allgather'、'alltoall' 和 'alltoall_seq'。默认值为 'alltoall'。
284+
- moe_token_dispatcher_type: 要使用的token分发器类型。可选选项包括 'allgather'、'alltoall'、'flex'和'alltoall_seq'。默认值为'alltoall'。
285+
- moe_enable_deepep: 实验性功能,启用DeepSeek/DeepEP以实现 MoE 模型中的高效令牌分发与组合。仅在设置`--moe_token_dispatcher_type flex`使用灵活令牌分发器时生效。
281286
- moe_grouped_gemm: 当每个rank包含多个专家时,通过在多个流中启动多个本地 GEMM 内核,利用 TransformerEngine中的GroupedLinear提高利用率和性能。默认为False。
282287
- moe_router_load_balancing_type: 确定路由器的负载均衡策略。可选项为"aux_loss"、"seq_aux_loss"、"sinkhorn"、"none"。默认值为 "aux_loss"。
283288
- moe_z_loss_coeff: z-loss 的缩放系数。默认为None。
@@ -291,6 +296,8 @@ Megatron训练参数继承自Megatron参数和基本参数。基本参数的内
291296

292297
- add_version: 在`save`上额外增加目录`'<版本号>-<时间戳>'`防止权重覆盖,默认为True。
293298
- 🔥packing: 是否使用序列packing,默认为False。
299+
- 🔥packing_cache: 指定 packing 缓存目录。默认值为`None`,表示缓存将存储在环境变量 `$MODELSCOPE_CACHE`所指定的路径下。在跨节点使用 packing 功能时,需确保所有节点的 packing 缓存路径共享且一致。你可以通过设置`MODELSCOPE_CACHE`环境变量,或在命令行中添加 `--packing_cache <shared_path>`参数来实现这一要求。
294300
- 🔥streaming: 流式读取并处理数据集,默认False。通常在处理大型数据集时,设置为True。更多流式的参数查看命令行参数文档。
295301
- lazy_tokenize: 默认为False。若该参数设置为False,则在训练之前对所有的数据集样本进行tokenize(这可以避免在训练中出现报错);设置为True,则在训练中对数据集进行tokenize(这可以节约内存)。
296302
- max_epochs: 训练到`max_epochs`时强制退出训练,并对权重进行验证和保存。该参数在使用流式数据集时很有用。默认为None。
303+
- 注意:如果你使用非流式数据集,该参数会为你自动计算train_iters,你不需要手动传入`train_iters`

0 commit comments

Comments
 (0)