Fix mixed-dtype gradient norms and clipping - #7279
Draft
aroshanghias-nvd wants to merge 1 commit into
Draft
Conversation
Signed-off-by: Ali Roshan Ghias <aroshanghias@nvidia.com>
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?
Group gradients by dtype before fused L2-norm and clipping-scale calls, so mixed BF16/FP32 lists produce the intended norm and in-place scaling.
The fused backend tested here interprets a list using its first tensor's dtype. For example,
[BF16[128], FP32[128]]filled with1/64returns0.2165063471instead of0.25. Reversing the order can read beyond the logical BF16 view. Scaling has an independent defect: even with coefficient0.5supplied directly, mixed lists leave some elements unscaled or modify padding beyond the gradient view. The reproductions use padded backing allocations.The change:
The existing single-device gradient-list contract is retained. No kernel implementation or optimizer-state layout changes are required.
Validation
2.11.0+cu130and the Transformer Engine backend: all 48 norm boundary cases per rank matched first-dtype byte interpretation, with 15 incorrect logical norms. Both scaling APIs failed on both mixed orders. Bucketed controls preserved padding and matched the logical reference.tools/autoformat.sh: Black, isort, pylint, and Ruff passed. Mypy could not resolve Torch/TE/Apex/pytest imports in the isolated local lint environment.python3 tools/check_kernel_determinism_coverage.py --base-ref origin/main: passed.This establishes the component defect and correction; it does not claim a measured full-training quality impact or that the fused API promises heterogeneous-list support.
Issue tracking
Linked issue: none; standalone bug fix.
Contribution process
Pre-checks
tools/autoformat.shon my PRNo training recipe or public API changes; no functional-test goldens or user documentation updates are included.