fix(megatron): sync fused shared-outer LoRA main grads - #2723
Open
zhoutong-hai wants to merge 1 commit into
Open
fix(megatron): sync fused shared-outer LoRA main grads#2723zhoutong-hai wants to merge 1 commit into
zhoutong-hai wants to merge 1 commit into
Conversation
zhoutong-hai
requested review from
Shi-Dong,
Zhichenzzz,
fzyzcjy,
maocheng23,
yueming-yuan and
yushengsu-thu
as code owners
August 23, 2026 18:04
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.
Summary
SharedOuterGroupedExpertAdapterduring LoRA model constructionmain_gradover the tensor+data group for the current pipeline stageProblem
Megatron Bridge registers a Parameter hook to synchronize the shared outer factor of routed-expert LoRA adapters. With fused weight-gradient accumulation, however, the real optimizer gradient is written directly into
param.main_grad; only a dummy tensor reaches the Parameter hook. The optimizer therefore consumes rank-local shared-factor gradients.The failure is delayed by LoRA initialization: LoRA-B starts at zero, so shared expert-fc1 LoRA-A first receives a useful gradient only after LoRA-B changes. In a GLM-5.2 TP8/PP4/EP8 run, the first update looked healthy, while the second update split every replicated expert-fc1 LoRA-A tensor into eight TP hashes before publication.
Disabling fusion on the adapter module alone did not repair the optimizer-facing buffer. Moving the SUM collective to final gradient processing did: eight consecutive full-scope updates produced replica-equal fc1/fc2 gradient evidence on all four pipeline stages, nonzero bitwise-equal early/middle/terminal native deltas, and maximum train/rollout absolute difference 0.0474493, KL 0.0162019, and TIS clip fraction 0.0125902. The full scope included routed-expert down-projection LoRA.
Implementation
Miles already finalizes explicitly tagged LoRA gradients before optimizer preparation. This change extends that mechanism with an intra-pipeline-stage domain matching the Bridge shared-factor ownership contract. Adapter class and factor dimensionality identify the target; model-specific parameter suffixes are not used. Stable per-chunk/module keys order collectives consistently across replicas.
For each present fc1/fc2 family, only one fixed-size SHA-256 digest is gathered after reduction. An inventory digest is gathered first so incompatible layouts fail before the gradient collective sequence.
Validation
.gradand the real nonzero gradient in.main_gradmain(cc92260df)Non-goal
Long sparse-DSA prefill scoring exposed a separate SGLang indexer top-k determinism issue. It is intentionally excluded from this gradient-synchronization PR.