Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/Megatron-SWIFT/Command-line-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**训练参数**:
- 🔥micro_batch_size: 每个device的批次大小,默认为1。
- 🔥global_batch_size: 总批次大小,等价于`micro_batch_size*数据并行大小*梯度累加步数`。默认为16。
- 其中,`数据并行大小 (DP) = 总GPU数 / (TP × PP × CP)`。
- 🔥recompute_granularity: 重新计算激活的粒度,可选项为'full', 'selective'。其中full代表重新计算整个transformer layer,selective代表只计算transformer layer中的核心注意力部分。通常'selective'是推荐的。默认为'selective'。
- 当你设置为'selective'时,你可以通过指定`--recompute_modules`来选择对哪些部分进行重新计算。
- 🔥recompute_method: 该参数需将recompute_granularity设置为'full'才生效,可选项为'uniform', 'block'。默认为None。
Expand Down
1 change: 1 addition & 0 deletions docs/source/Megatron-SWIFT/Mcore-Bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ swift infer \
## 导出与转换精度测试

Mcore-Bridge除了支持在训练中进行safetensors的转换和保存,也支持了`megatron export`命令用于单独的权重导出。`megatron export`支持在权重转换时,对转换精度进行测试,这在接入新模型时验证接入准确性很有帮助。通常,Megatron-SWIFT已经接入的模型不会出现精度不对齐的情况,你可以放心设置`--test_convert_precision false`
- 提示:多模态模型请关注`mean_diff (with loss)`字段,`mean_diff`因包含图像tokens且该部分不计算损失,有较大的diff。

全参数权重:
```shell
Expand Down
2 changes: 2 additions & 0 deletions docs/source_en/Megatron-SWIFT/Command-line-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- 🔥micro_batch_size: Batch size per device, default is 1.
- 🔥global_batch_size: Total batch size, equivalent to `micro_batch_size * data parallel size * gradient accumulation steps`. Default is 16.
- Here, `Data Parallelism size (DP) = Total number of GPUs / (TP × PP × CP)`.
- 🔥recompute_granularity: Granularity of activation recomputation, options are 'full', 'selective'. 'full' means recomputing the entire transformer layer, while 'selective' means only recomputing the core attention part of the transformer layer. 'selective' is generally recommended. Default is 'selective'.
- When you set it to 'selective', you can specify `--recompute_modules` to choose which parts to recompute.
- 🔥recompute_method: This parameter takes effect only when recompute_granularity is set to 'full', options are 'uniform', 'block'. Default is None.
Expand Down Expand Up @@ -315,6 +316,7 @@ Megatron training parameters are inherited from Megatron parameters and basic pa
- 🔥packing: Whether to use sequence packing to improve computational efficiency (achieving better load balancing across nodes and processes, and higher GPU utilization), at the cost of additional preprocessing time, while also stabilizing GPU memory usage. Defaults to `False`. Currently supported for CPT, SFT, DPO, KTO and RM.
- Note: **Sequences within the same batch remain mutually invisible**, except for Qwen3-Next.
- Note: **Packing reduces the number of samples in the dataset; please adjust the gradient accumulation steps and learning rate accordingly**.
- packing_length: the length to use for packing. Defaults to None, in which case it is set to max_length.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The description for packing_length is a bit brief. For better clarity, consider expanding it to explain what the 'length' refers to in the context of packing. Also, it might be helpful to add the 🔥 emoji to highlight it as an important parameter, similar to packing.

Suggested change
- packing_length: the length to use for packing. Defaults to None, in which case it is set to max_length.
- 🔥packing_length: Specifies the target sequence length for packing. When packing is enabled, multiple short sequences are concatenated into a single sequence of this length to improve efficiency. Defaults to `None`, in which case it is set to `max_length`.

- streaming: Stream data loading and processing, default is False.
- Note: Since the length of a streaming dataset cannot be determined, the `--train_iters` parameter must be set. Also set the `max_epochs` parameter to ensure training exits after the specified number of epochs, and to validate and save the model weights accordingly.
- Note: Streaming datasets can skip preprocessing wait time by overlapping preprocessing with training. Preprocessing for streaming datasets is performed only on rank 0 and then synchronized to other processes via data distribution. **This is generally less efficient than the data sharding approach used in non-streaming datasets.** When the training world_size is large, preprocessing and data distribution can become a training bottleneck.
Expand Down
1 change: 1 addition & 0 deletions docs/source_en/Megatron-SWIFT/Mcore-Bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ swift infer \
## Export and Conversion Precision Testing

In addition to supporting safetensors conversion and saving during training, Mcore-Bridge also supports the `megatron export` command for standalone weight export. `megatron export` supports conversion precision testing during weight conversion, which is very helpful for verifying accuracy when integrating new models. Typically, models already integrated into Megatron-SWIFT will not have precision misalignment issues, so you can confidently set `--test_convert_precision false`.
- Note: For multimodal models, please focus on the `mean_diff (with loss)` field. The `mean_diff` may show a large difference because it includes image tokens, and loss is not calculated for that portion.

Full parameter weights:

Expand Down
1 change: 1 addition & 0 deletions swift/llm/train/sft.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def _post_process_datasets(self, datasets: List) -> List:
template,
dataset,
num_proc=args.dataset_num_proc,
packing_length=args.packing_length,
strict=args.strict,
load_from_cache_file=args.load_from_cache_file)
elif args.streaming:
Expand Down
2 changes: 1 addition & 1 deletion swift/megatron/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_convert_precision(hf_model, mg_model, template, torch_dtype=torch.float
print(f'token_mean_diff: {token_mean_diff}')
print(f'mean_diff: {mean_diff}, max_diff: {max_diff}')
print(f'mean_diff (with loss): {mean_diff_with_loss}, max_diff (with loss): {max_diff_with_loss} '
'(Please check that mean_diff is less than 0.1).')
'(Please check that mean_diff (with loss) is less than 0.1).')
hf_tokens = hf_logits.argmax(-1)
mg_tokens = mg_logits.argmax(-1)
print(f'hf_tokens: {hf_tokens[0].tolist()}\nmg_tokens: {mg_tokens[0].tolist()}')
Expand Down
Loading