[bugfix][megatron] align GPU/NPU GKD precision - #10102
Draft
xinyu-0877 wants to merge 3 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR aligns the numerical precision of Megatron GKD training between NVIDIA GPU
and Ascend NPU backends.
The changes include:
SWIFT_GKD_JSD_FP32=1.differences between GPU and NPU.
accumulate_allreduce_grads_in_fp32option to thecorresponding Megatron DDP fields:
grad_reduce_in_fp32reduce_scatter_with_fp32_accumulationThe default behavior remains unchanged when the FP32 options are disabled.
Motivation
The original GKD JSD loss was computed using the logits' original low precision
(e.g. BF16) without explicit FP32 conversion. Numerical differences in
low-precision operations, such as softmax, KL divergence, tensor-parallel gather,
and reduction, can accumulate differently across GPU and NPU backends.
In addition,
accumulate_allreduce_grads_in_fp32was not correctly forwardedfrom Swift arguments to the Megatron DDP configuration, so gradient accumulation
and reduction were not guaranteed to use FP32 as intended.
This PR explicitly enables FP32 for the GKD JSD loss path and correctly forwards
the FP32 gradient accumulation/reduction configuration, improving numerical
alignment between GPU and NPU Megatron GKD training.
Validation
branch.