Repository navigation
[graph_trainer] Don't pick dead unshard chain as canonical in FSDP dedup - #4966
Closed
SherlockNoMad wants to merge 1 commit into
Closed
SherlockNoMad wants to merge 1 commit into
SherlockNoMad wants to merge 1 commit into
Conversation
#4867 moved SimpleFSDP stacked expert weights (w13, [E, 2, F, D]) to Shard(2), so their unshard chain is all_gather -> wait -> split -> cat(dim 2) -> view instead of just all_gather -> wait. GroupedLinear.forward reads self.weight twice, once only for its shape. That chain's output is unused, so DCE truncates it to the impure all_gather/wait. deduplicate_fsdp_unshard_chains_pass could then pick the truncated chain as canonical and redirect the live chain's users to the raw wait output, which has the wrong layout for Shard(dim > 0). The expert matmul silently consumed a scrambled weight and the qwen3 MoE eager-vs-graph_trainer loss compare in the H100 GraphTrainer CI diverged. With Shard(0) the raw wait happened to be the correct unsharded weight, which is why this was latent. Fix: only chains whose output has users are eligible as canonical; dead chains are removed along with their redundant all-gather. Test plan: - New unit test test_dead_unshard_chain_is_not_canonical (fails without fix) - test_passes.py, test_graph_pp_passes.py, test_bitwise_deterministic.py pass - 20-step qwen3 MoE loss_compare (eager vs graph_trainer): all losses equal
SherlockNoMad
requested review from
IvanKobzarev,
aditvenk,
sanketpurandare and
tianyu-l
as code owners
September 30, 2026 15:45
aditvenk
approved these changes
Sep 30, 2026
This was referenced Sep 30, 2026
Contributor
Author
|
abort, in favor of #4949 |
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 the qwen3 MoE loss-compare failure in the GraphTrainer 8 GPU H100 Integration Tests on main.
Why
#4867 moved SimpleFSDP stacked expert weights (
w13, shape[E, 2, F, D]) fromShard(0)toShard(2). Their traced unshard chain is nowall_gather -> wait -> split -> cat(dim 2) -> view, not justall_gather -> wait.GroupedLinear.forwardreadsself.weighttwice, and one of those reads is only for its shape. That chain's output is unused, so DCE cuts it back to the impureall_gather/wait.deduplicate_fsdp_unshard_chains_passcould then pick the cut-down chain as canonical. It redirected the live chain's users to the rawwaitoutput, which has the wrong layout forShard(dim > 0). The expert matmul silently used a scrambled weight, and the losses diverged from eager.Under
Shard(0)the rawwaitoutput happened to be the correct unsharded weight, which kept the bug hidden until #4867.What
Test plan
test_dead_unshard_chain_is_not_canonical(fails without the fix, passes with it)test_passes.py: 231 passed, 1 skippedtest_graph_pp_passes.py: 46 passedtest_bitwise_deterministic.py: 15 passed, 10 skippedscripts/loss_compare.py(eager vs graph_trainer, same config as CI): all losses equalFollow-ups (not in this PR)
shard_dim=0it is passed for routed experts, so its expert placement no longer matches core FSDP. This may be unintended in [ci][graph_trainer] Shard stacked linears on matrix rows #4867.GroupedLinear.forwardcould readself.weightonce, which would avoid the redundant unshard chain entirely.