Repository navigation
fix: preserve FP32 target gradients in Megatron TE cross entropy - #1117
Merged
Merged
Conversation
bradhilton
force-pushed
the
tarkin/te-ce-fp32-target-grad
branch
3 times, most recently
from
October 10, 2026 18:58
05b87f0 to
a29149c
Compare
bradhilton
marked this pull request as ready for review
October 10, 2026 19:26
bradhilton
force-pushed
the
tarkin/te-ce-fp32-target-grad
branch
from
October 10, 2026 19:38
a29149c to
c52869c
Compare
FurtherAI
approved these changes
Oct 12, 2026
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.
Fixes #1108.
Problem: ART's Megatron backend uses Transformer Engine's fused cross-entropy (
cross_entropy_fusion_impl = "te"). TE's Triton kernel storesbf16(p)for every vocabulary entry, then reloads the target entry and subtracts 1 in BF16. The target gradient is therefore exactly 0 whenever p ≥ 0.998, the same dead zone #1105 fixed in TrainerRank. In a GPU sweep through Megatron's loss with ART's settings, 294 of 512 rows had a zero target gradient. A real ART SFT step with near-certain targets had 163 of 216.Behavior after this change:
art.megatron.te_cross_entropypatches TE's kernel source at import, alongside ART's existing bridge patches.Validation:
nativeor unfused) would need 4–6× the memory (14 GB versus 2.4 GB at 8,192 rows) and be 3–5× slower.Limitations:
_unsafe_update_src, plus clearing the kernel's compiled cache.