[grug] Fix multi-host MoE ShardingTypeError on shared-expert residual#6297
Open
claude[bot] wants to merge 1 commit into
Open
[grug] Fix multi-host MoE ShardingTypeError on shared-expert residual#6297claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
DenseMLP (shared expert) reshards its output on the flat [T, D] tensor and reshapes after, while MoEMLP (routed) reshapes first and reshards after. Splitting the fused (replica_dcn, data, expert) token axis back into (batch, seq) leaks the expert axis onto the seq dim, so the shared-expert residual add disagrees with the routed path once replica_dcn > 1. On a single host the two layouts coincide, which is why single-node and TPU canary runs pass. Reshard DenseMLP's output after the reshape so it carries the same canonical batch sharding as the routed output before the residual add.
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.
DenseMLP (shared expert) reshards its output on the flat [T, D] tensor via the einsum out_sharding and reshapes after, while MoEMLP (routed) reshapes first and reshards after. Splitting the fused (replica_dcn, data, expert) token axis back into (batch, seq) leaks the expert axis onto the seq dim, so the shared-expert residual add at model.py:467 disagrees with the routed path once replica_dcn > 1. On a single host the two layouts coincide, which is why single-node and TPU canary runs pass.
Reshard DenseMLP's output after the reshape so it carries the same canonical batch sharding as the routed output before the residual add. The reshard is a no-op on a trivial mesh, so single-host behavior is unchanged.
Adds a lowering regression test on a replica_dcn=2 abstract mesh (the canary regime: expert axis size 1, two replicas), which reproduces the exact ShardingTypeError before the fix.
Fixes #6296