Skip to content

Commit 5df8180

Browse files
authored
[train] Update split_dataset_ratio (#4798)
1 parent 1477de3 commit 5df8180

File tree

119 files changed

+251
-65
lines changed

Some content is hidden

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

119 files changed

+251
-65
lines changed

docs/source/BestPractices/NPU支持.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ ASCEND_RT_VISIBLE_DEVICES=0 \
115115
swift sft \
116116
--model Qwen/Qwen2-7B-Instruct \
117117
--dataset AI-ModelScope/blossom-math-v2 \
118+
--split_dataset_ratio 0.01 \
118119
--num_train_epochs 5 \
119120
--train_type lora \
120121
--output_dir output \
@@ -138,6 +139,7 @@ ASCEND_RT_VISIBLE_DEVICES=0,1,2,3 \
138139
swift sft \
139140
--model Qwen/Qwen2-7B-Instruct \
140141
--dataset AI-ModelScope/blossom-math-v2 \
142+
--split_dataset_ratio 0.01 \
141143
--num_train_epochs 5 \
142144
--train_type lora \
143145
--output_dir output \
@@ -157,6 +159,7 @@ ASCEND_RT_VISIBLE_DEVICES=0,1,2,3 \
157159
swift sft \
158160
--model Qwen/Qwen2-7B-Instruct \
159161
--dataset AI-ModelScope/blossom-math-v2 \
162+
--split_dataset_ratio 0.01 \
160163
--num_train_epochs 5 \
161164
--train_type lora \
162165
--output_dir output \
@@ -174,6 +177,7 @@ ASCEND_RT_VISIBLE_DEVICES=0,1,2,3 \
174177
swift sft \
175178
--model Qwen/Qwen2-7B-Instruct \
176179
--dataset AI-ModelScope/blossom-math-v2 \
180+
--split_dataset_ratio 0.01 \
177181
--num_train_epochs 5 \
178182
--train_type lora \
179183
--output_dir output \

docs/source/BestPractices/Qwen3最佳实践.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ swift sft \
222222
--model Qwen/Qwen3-8B \
223223
--train_type full \
224224
--dataset '<your-dataset>' \
225+
--split_dataset_ratio 0.01 \
225226
--torch_dtype bfloat16 \
226227
--per_device_train_batch_size 1 \
227228
--per_device_eval_batch_size 1 \
@@ -280,7 +281,7 @@ pip install vllm==0.8.5.post1
280281

281282
我们使用使 AI-MO/NuminaMath-TIR 作为数据集,并使用accuracy函数计算模型回答的准确率奖励。
282283

283-
在训练过程中,使用 vLLM 加速采样过程。通过设置 `num_infer_workers=8` ,我们为每个设备部署一个 vLLM 引擎以加快采样速度。
284+
在训练过程中,使用 vLLM 加速采样过程。
284285

285286
```bash
286287
# 70G*8
@@ -313,7 +314,6 @@ swift rlhf \
313314
--offload_model true \
314315
--offload_optimizer true \
315316
--deepspeed zero3 \
316-
--num_infer_workers 8 \
317317
--tensor_parallel_size 1 \
318318
--temperature 1.0 \
319319
--top_p 0.85 \
@@ -332,11 +332,13 @@ ms-swift 引入了 Megatron 并行技术以加速大模型的CPT/SFT/DPO。支
332332
```bash
333333
# https://help.aliyun.com/zh/pai/user-guide/general-environment-variables
334334
# 请确保两个节点上的权重保存路径`--save`和packing缓存路径`--packing_cache`相同且共享。
335+
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
335336
NNODES=$WORLD_SIZE \
336337
NODE_RANK=$RANK \
337338
megatron sft \
338339
--load Qwen3-30B-A3B-Base-mcore \
339340
--dataset 'liucong/Chinese-DeepSeek-R1-Distill-data-110k-SFT' \
341+
--split_dataset_ratio 0.01 \
340342
--tensor_model_parallel_size 2 \
341343
--expert_model_parallel_size 8 \
342344
--moe_grouped_gemm true \

docs/source/BestPractices/快速训练VL模型.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ swift sft \
114114
--model_type qwen2_5_vl \
115115
--train_type full \
116116
--dataset xxx \
117+
--split_dataset_ratio 0.01 \
117118
--torch_dtype bfloat16 \
118119
--attn_impl flash_attn \
119120
--freeze_vit true \
@@ -149,6 +150,7 @@ swift sft \
149150
--model_type qwen2_5_vl \
150151
--train_type full \
151152
--dataset xxx \
153+
--split_dataset_ratio 0.01 \
152154
--torch_dtype bfloat16 \
153155
--attn_impl flash_attn \
154156
--freeze_vit false \

docs/source/GetStarted/SWIFT安装.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ pip install ms-swift==2.*
3838
## 镜像
3939

4040
```
41-
# swift3.5.1
42-
modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.27.0-swift3.5.1
43-
modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.27.0-swift3.5.1
44-
modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.27.0-swift3.5.1
41+
# swift3.5.3
42+
modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py310-torch2.6.0-vllm0.8.5.post1-modelscope1.27.1-swift3.5.3
43+
modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py310-torch2.6.0-vllm0.8.5.post1-modelscope1.27.1-swift3.5.3
44+
modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py310-torch2.6.0-vllm0.8.5.post1-modelscope1.27.1-swift3.5.3
4545
4646
# swift3.4.1.post1
4747
modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.26.0-swift3.4.1.post1

docs/source/Instruction/GRPO/GetStarted/GRPO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ $
280280

281281
**6. 为什么没有设置val_dataset,仍然有验证过程,如何取消**
282282

283-
当没有显式传入`val_dataset`时,参数`split_dataset_ratio`负责切分部分`dataset`为验证数据集,默认切分1%数据
283+
当没有显式传入`val_dataset`时,参数`split_dataset_ratio`负责切分部分`dataset`为验证数据集,默认切分1%数据(在"ms-swift>=3.6"中,`split_dataset_ratio`的默认值将从0.01修改为0.)
284284

285285
通过设置`--split_dataset_ratio 0` 来取消验证过程
286286

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ pip install git+https://github.com/NVIDIA/Megatron-LM.git@core_r0.12.0
2626

2727
或者你也可以使用镜像:
2828
```
29-
modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.27.0-swift3.5.1
30-
modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.27.0-swift3.5.1
31-
modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py311-torch2.6.0-vllm0.8.5.post1-modelscope1.27.0-swift3.5.1
29+
modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py310-torch2.6.0-vllm0.8.5.post1-modelscope1.27.1-swift3.5.3
30+
modelscope-registry.cn-beijing.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py310-torch2.6.0-vllm0.8.5.post1-modelscope1.27.1-swift3.5.3
31+
modelscope-registry.us-west-1.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.4.0-py310-torch2.6.0-vllm0.8.5.post1-modelscope1.27.1-swift3.5.3
3232
```
3333

3434
依赖库Megatron-LM中的训练模块将由swift进行git clone并安装。你也可以通过环境变量`MEGATRON_LM_PATH`指向已经下载好的repo路径(断网环境,[core_r0.12.0分支](https://github.com/NVIDIA/Megatron-LM/tree/core_r0.12.0))。
@@ -52,6 +52,7 @@ swift export \
5252
然后,使用以下脚本进行训练,训练所需显存资源为2*80GiB:
5353
- 若使用多机训练,建议共享磁盘,并将`--save`指定为相同的路径。
5454
```shell
55+
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
5556
NPROC_PER_NODE=2 \
5657
CUDA_VISIBLE_DEVICES=0,1 \
5758
megatron sft \
@@ -212,6 +213,8 @@ I am a language model developed by swift, you can call me swift-robot. How can I
212213
- 🔥no_load_optim: 不载入optimizer,默认为False。
213214
- 🔥no_load_rng: 不载入rng,默认为False。
214215
- 🔥finetune: 将模型加载并微调。不加载检查点的优化器和随机种子状态,并将迭代数设置为0。默认为False。
216+
- 注意:断点续训`--load`,若设置`--finetune true`,将不会跳过数据集;若不设置,将跳过之前训练的数据集数量。
217+
- 流式数据集`--streaming`,暂不支持跳过数据集。
215218
- ckpt_format: checkpoint的格式。可选为'torch', 'torch_dist', 'zarr'。默认为'torch_dist'。
216219
- no_initialization: 不对权重进行初始化,默认为True。
217220
- auto_detect_ckpt_format: 自动检测ckpt format为legacy还是distributed格式。默认为True。
@@ -249,7 +252,7 @@ I am a language model developed by swift, you can call me swift-robot. How can I
249252
**评估参数**:
250253
- 🔥eval_iters: 评估的迭代次数,默认为-1,根据验证数据集的数量设置合适的值。
251254
- 注意:若使用流式数据集,该值需要手动设置。
252-
- 🔥eval_interval: 评估的间隔(steps),默认为None,即设置为save_interval。
255+
- 🔥eval_interval: 评估的间隔(steps),即每训练多少steps进行评估,默认为None,即设置为save_interval。
253256

254257
**fp8参数**:
255258
- fp8_format: 用于前向和反向传播中FP8张量的FP8格式方案。可选为'e4m3','hybrid'。默认为None。

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
- 子数据集: 该参数只有当dataset为ID或者文件夹时生效。若注册时指定了subsets,且只有一个子数据集,则默认选择注册时指定的子数据集,否则默认为'default'。你可以使用`/`来选择多个子数据集,例如:`<dataset_id>:subset1/subset2`。你也可以使用'all'来选择所有的子数据集,例如:`<dataset_id>:all`
4747
- 采样数量: 默认使用完整的数据集。若采样数少于数据样本总数,则进行随机选择(不重复采样)。若采样数高于数据样本总数,则只额外随机采样`采样数%数据样本总数`的样本,数据样本重复采样`采样数//数据样本总数`次。注意:流式数据集只进行顺序采样。若设置`--dataset_shuffle false`,则非流式数据集也进行顺序采样。
4848
- 🔥val_dataset: 验证集id或路径的list。默认为`[]`
49-
- 🔥split_dataset_ratio: 不指定val_dataset时如何拆分训练集和验证集,默认为0.01。若不需要切分验证集,设置为0即可。
49+
- 🔥split_dataset_ratio: 不指定val_dataset时从训练集拆分验证集的比例,默认为0.,即不从训练集切分验证集。
50+
- 注意:该参数在"ms-swift<3.6"的默认值为0.01。
5051
- data_seed: 数据集随机种子,默认为42。
5152
- 🔥dataset_num_proc: 数据集预处理的进程数,默认为1。
5253
- 🔥load_from_cache_file: 是否从缓存中加载数据集,默认为True。
@@ -167,6 +168,7 @@
167168
- 🔥save_strategy: 保存模型的策略,可选为'no'、'steps'、'epoch',默认为'steps'。
168169
- 🔥save_steps: 默认为500。
169170
- 🔥eval_strategy: 评估策略。默认为None,跟随`save_strategy`的策略。
171+
- 若不使用`val_dataset``eval_dataset``split_dataset_ratio`为0,则默认为'no'。
170172
- 🔥eval_steps: 默认为None,如果存在评估数据集,则跟随`save_steps`的策略。
171173
- 🔥save_total_limit: 最多保存的checkpoint数,会将过期的checkpoint进行删除。默认为None,保存所有的checkpoint。
172174
- max_steps: 最大训练的steps数。在数据集为流式时需要被设置。默认为-1。
@@ -388,8 +390,8 @@ Vera使用`target_modules`, `target_regex`, `modules_to_save`三个参数.
388390
- optimizer: plugin的自定义optimizer名称,默认为None。可选optimizer参考[这里](https://github.com/modelscope/ms-swift/blob/main/swift/plugin/optimizer.py)
389391
- metric: plugin的自定义metric名称。默认为None,即在predict_with_generate=False的情况下设置为'acc',在predict_with_generate=True的情况下设置为'nlg'。
390392
- eval_use_evalscope: 是否使用evalscope进行训练时评测,需要设置该参数来开启评测,具体使用参考[示例](../Instruction/评测.md#训练中评测)
391-
- eval_datasets: 评测数据集,可设置多个数据集,用空格分割。
392-
- eval_datasets_args: 评测数据集参数,json格式,可设置多个数据集的参数。
393+
- eval_dataset: 评测数据集,可设置多个数据集,用空格分割。
394+
- eval_dataset_args: 评测数据集参数,json格式,可设置多个数据集的参数。
393395
- eval_limit: 评测数据集采样数。
394396
- eval_generation_config: 评测时模型推理配置,json格式,默认为`{'max_tokens': 512}`
395397

docs/source/Instruction/评测.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ swift sft \
131131
--eval_steps "5" \
132132
--per_device_eval_batch_size "5" \
133133
--eval_use_evalscope \
134-
--eval_datasets "gsm8k" \
135-
--eval_datasets_args '{"gsm8k": {"few_shot_num": 0}}' \
134+
--eval_dataset "gsm8k" \
135+
--eval_dataset_args '{"gsm8k": {"few_shot_num": 0}}' \
136136
--eval_limit "10"
137137
```
138138

139139
注意启动命令为`sft`,其中eval相关的参数有:
140140
- eval_strategy: 评估策略。默认为None,跟随`save_strategy`的策略
141141
- eval_steps: 默认为None,如果存在评估数据集,则跟随`save_steps`的策略
142142
- eval_use_evalscope: 是否使用evalscope进行评测,需要设置该参数来开启评测
143-
- eval_datasets: 评测数据集,可设置多个数据集,用空格分割
144-
- eval_datasets_args: 评测数据集参数,json格式,可设置多个数据集的参数
143+
- eval_dataset: 评测数据集,可设置多个数据集,用空格分割
144+
- eval_dataset_args: 评测数据集参数,json格式,可设置多个数据集的参数
145145
- eval_limit: 评测数据集采样数
146146
- eval_generation_config: 评测时模型推理配置,json格式,默认为`{'max_tokens': 512}`
147147

docs/source_en/BestPractices/NPU-support.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ ASCEND_RT_VISIBLE_DEVICES=0 \
115115
swift sft \
116116
--model Qwen/Qwen2-7B-Instruct \
117117
--dataset AI-ModelScope/blossom-math-v2 \
118+
--split_dataset_ratio 0.01 \
118119
--num_train_epochs 5 \
119120
--train_type lora \
120121
--output_dir output \
@@ -136,6 +137,7 @@ ASCEND_RT_VISIBLE_DEVICES=0,1,2,3 \
136137
swift sft \
137138
--model Qwen/Qwen2-7B-Instruct \
138139
--dataset AI-ModelScope/blossom-math-v2 \
140+
--split_dataset_ratio 0.01 \
139141
--num_train_epochs 5 \
140142
--train_type lora \
141143
--output_dir output \
@@ -154,6 +156,7 @@ ASCEND_RT_VISIBLE_DEVICES=0,1,2,3 \
154156
swift sft \
155157
--model Qwen/Qwen2-7B-Instruct \
156158
--dataset AI-ModelScope/blossom-math-v2 \
159+
--split_dataset_ratio 0.01 \
157160
--num_train_epochs 5 \
158161
--train_type lora \
159162
--output_dir output \
@@ -171,6 +174,7 @@ ASCEND_RT_VISIBLE_DEVICES=0,1,2,3 \
171174
swift sft \
172175
--model Qwen/Qwen2-7B-Instruct \
173176
--dataset AI-ModelScope/blossom-math-v2 \
177+
--split_dataset_ratio 0.01 \
174178
--num_train_epochs 5 \
175179
--train_type lora \
176180
--output_dir output \

docs/source_en/BestPractices/Qwen3-Best-Practice.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ swift sft \
225225
--model Qwen/Qwen3-8B \
226226
--train_type full \
227227
--dataset '<your-dataset>' \
228+
--split_dataset_ratio 0.01 \
228229
--torch_dtype bfloat16 \
229230
--per_device_train_batch_size 1 \
230231
--per_device_eval_batch_size 1 \
@@ -284,7 +285,7 @@ Notes on dataset requirements:
284285

285286
We use AI-MO/NuminaMath-TIR as the dataset and compute the accuracy-based reward for model responses.
286287

287-
During training, we utilize vLLM to accelerate the sampling process. By setting `num_infer_workers=8`, we deploy one vLLM engine per device to speed up sampling.
288+
During training, we utilize vLLM to accelerate the sampling process.
288289

289290
```bash
290291
# 70G*8
@@ -317,7 +318,6 @@ swift rlhf \
317318
--offload_model true \
318319
--offload_optimizer true \
319320
--deepspeed zero3 \
320-
--num_infer_workers 8 \
321321
--tensor_parallel_size 1 \
322322
--temperature 1.0 \
323323
--top_p 0.85 \
@@ -336,11 +336,13 @@ We will use Alibaba Cloud DLC to launch training. The training environment consi
336336
```bash
337337
# https://help.aliyun.com/zh/pai/user-guide/general-environment-variables
338338
# Ensure that the weight save path `--save` and packing cache path `--packing_cache` are the same and shared across both nodes.
339+
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
339340
NNODES=$WORLD_SIZE \
340341
NODE_RANK=$RANK \
341342
megatron sft \
342343
--load Qwen3-30B-A3B-Base-mcore \
343344
--dataset 'liucong/Chinese-DeepSeek-R1-Distill-data-110k-SFT' \
345+
--split_dataset_ratio 0.01 \
344346
--tensor_model_parallel_size 2 \
345347
--expert_model_parallel_size 8 \
346348
--moe_grouped_gemm true \

0 commit comments

Comments
 (0)