diff --git a/docs/source/Megatron-SWIFT/Command-line-parameters.md b/docs/source/Megatron-SWIFT/Command-line-parameters.md index 7faac51c46..f2e10a25ad 100644 --- a/docs/source/Megatron-SWIFT/Command-line-parameters.md +++ b/docs/source/Megatron-SWIFT/Command-line-parameters.md @@ -26,7 +26,8 @@ - apply_rope_fusion: 默认为False。用于开启rope融合。该参数为megatron-core参数透传。注意:并不是所有情况都支持rope融合,例如:MLA、mrope等不支持。 - gradient_accumulation_fusion: 默认为True。用于开启梯度累加融合。 - 🔥cross_entropy_loss_fusion: 启动交叉熵损失计算融合。默认为True。 -- cross_entropy_fusion_impl: 交叉熵损失融合的实现。可选为'native'和'te'。默认为None,如果是cuda设置为'te',npu设置为'native'。 +- cross_entropy_fusion_impl: 交叉熵损失融合的实现。可选为'native'和'te'。默认为'native'。 + - **"ms-swift>=4.3.1"默认值从"te"修改为"native"**,原因查看[这个PR](https://github.com/NVIDIA/Megatron-LM/pull/5115),这可能会导致更多的显存占用。 - calculate_per_token_loss: 根据全局批次中的非填充token数量来对交叉熵损失进行缩放。默认为None,`task_type`为'causal_lm'且为预训练/微调时,默认为True,否则默认为False。 - 🔥attention_backend: 使用的注意力后端 (flash、fused、unfused、local、auto、flash_2、flash_3、flash_4)。默认为 flash。 - 如果安装'flash_attention_4/3',`--attention_backend flash`则优先使用fa4/fa3。如果要显式设置,你可以设置`--attention_backend flash_2/3/4`。训练脚本参考[这里](https://github.com/modelscope/ms-swift/tree/main/examples/train/flash_attention_3)。多模态模型的vit部分要使用flash_attention_4/3,请设置`--attn_impl flash_attention_4/3`。 diff --git a/docs/source_en/Megatron-SWIFT/Command-line-parameters.md b/docs/source_en/Megatron-SWIFT/Command-line-parameters.md index 79f4bd081a..ae156a17d7 100644 --- a/docs/source_en/Megatron-SWIFT/Command-line-parameters.md +++ b/docs/source_en/Megatron-SWIFT/Command-line-parameters.md @@ -28,7 +28,8 @@ - apply_rope_fusion: Defaults to False. Used to enable RoPE fusion. This parameter is passed through from megatron-core. Note: RoPE fusion is not supported in all cases, for example: MLA, mrope, etc. are not supported. - gradient_accumulation_fusion: Defaults to True. Used to enable gradient accumulation fusion. - 🔥cross_entropy_loss_fusion: Enables cross-entropy loss computation fusion. Defaults to True. -- cross_entropy_fusion_impl: Implementation for cross-entropy loss fusion. Options are 'native' and 'te'. Defaults to None. Automatically set to 'te' for CUDA and 'native' for NPU. +- cross_entropy_fusion_impl: The implementation of cross-entropy loss fusion. Options are `'native'` and `'te'`. Defaults to `'native'`. + - **The default value in `ms-swift>=4.3.1` has been changed from `'te'` to `'native'`**, for the reason see [this PR](https://github.com/NVIDIA/Megatron-LM/pull/5115). This may result in higher GPU memory usage. - calculate_per_token_loss: Scales the cross-entropy loss according to the number of non-padding tokens in the global batch. Defaults to None. When `task_type` is 'causal_lm' and during pretraining/fine-tuning, it defaults to True; otherwise, it defaults to False. - 🔥attention_backend: The attention backend to use (flash, fused, unfused, local, auto, flash_2, flash_3, flash_4). Defaults to `flash`. - If `flash_attention_4/3` is installed, `--attention_backend flash` will prioritize fa4/fa3. To explicitly specify a version, you can set `--attention_backend flash_2/3/4`. For training script examples, refer to [here](https://github.com/modelscope/ms-swift/tree/main/examples/train/flash_attention_3). To use flash_attention_4/3 for the ViT part of multimodal models, please set `--attn_impl flash_attention_4/3`. diff --git a/examples/megatron/fp8/benchmark.sh b/examples/megatron/fp8/benchmark.sh index 309d34645b..8b80145098 100644 --- a/examples/megatron/fp8/benchmark.sh +++ b/examples/megatron/fp8/benchmark.sh @@ -20,7 +20,7 @@ megatron sft \ --num_train_epochs 1 \ --finetune true \ --cross_entropy_loss_fusion true \ - --cross_entropy_fusion_impl te \ + --cross_entropy_fusion_impl native \ --lr 1e-5 \ --lr_warmup_fraction 0.05 \ --min_lr 1e-6 \ diff --git a/swift/megatron/arguments/megatron_args.py b/swift/megatron/arguments/megatron_args.py index 8ab31e9c3c..c8a88f902b 100644 --- a/swift/megatron/arguments/megatron_args.py +++ b/swift/megatron/arguments/megatron_args.py @@ -440,7 +440,7 @@ class MegatronArguments(RLHFMegatronArgumentsMixin, MegatronTunerMixin): apply_rope_fusion: bool = False gradient_accumulation_fusion: bool = True cross_entropy_loss_fusion: bool = True - cross_entropy_fusion_impl: Optional[Literal['native', 'te']] = None + cross_entropy_fusion_impl: Literal['native', 'te'] = 'native' calculate_per_token_loss: Optional[bool] = None attention_backend: str = 'flash' # flash, fused, unfused, local, auto optimizer: Literal['adam', 'sgd', 'muon', 'dist_muon'] = 'adam' @@ -720,15 +720,6 @@ def __post_init__(self): self._init_vpp_size() if self.vit_gradient_checkpointing is None: self.vit_gradient_checkpointing = not self.freeze_vit - if self.cross_entropy_fusion_impl is None: - if is_torch_npu_available(): - self.cross_entropy_fusion_impl = 'native' - else: - import transformer_engine - if version.parse(transformer_engine.__version__) >= version.parse('2.8.0'): - self.cross_entropy_fusion_impl = 'te' - else: - self.cross_entropy_fusion_impl = 'native' if isinstance(self.report_to, str): self.report_to = [self.report_to] self.model_info, self.model_meta = get_model_info_meta(