Experimenting MoE new sharding - #3996
Open
acisseJZhong wants to merge 13 commits into
Open
Conversation
acisseJZhong
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
July 27, 2026 19:11
acisseJZhong
marked this pull request as draft
July 27, 2026 19:12
acisseJZhong
marked this pull request as ready for review
July 31, 2026 08:12
tianyu-l
approved these changes
Aug 1, 2026
tianyu-l
left a comment
Contributor
There was a problem hiding this comment.
it'd be good to check the numerics doesn't change (for inference) when input sequence length is not always even
| # --------------------------------------------------------------------- | ||
| return out_BLD | ||
|
|
||
| def parallelize(self, parallel_dims) -> None: |
Contributor
There was a problem hiding this comment.
add a TODO to deprecate this when DTensor backend is deprecated -- for spmd_types, we can directly access this info from global context
This was referenced Aug 1, 2026
Open
This was referenced Aug 5, 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.
Stack from ghstack (oldest at bottom):
Summary
This updates the MoE EP/SP sharding contract so token dispatchers return the local sequence shard directly instead of constructing a full global-length sparse contribution.
The main change is that routed expert outputs are represented as the MoE local output layout:
Shared experts are updated to produce the same layout as routed experts before the routed + shared add. The outer MoE boundary remains responsible for redistributing the final MoE output to
sp_layout.Changes
sp_size-expanded buffer.local_seq_len_after_paddingfrom the dispatcher combine interface since local-shard combine no longer needs per-rank-to-global SP index mapping.num_local_tokens_after_paddingfor logical sequence padding, so AllToAll can size the local padded output without materializing pad rows.MoE.forward()syncs before the routed output is read.w1/w3expose input all-gather andw2exposes Partial-to-output-layout reduction.Test plan
loss parity on FSDP4, TP=2, SP on, EP=2, ETP=1: AssertionError: 7.949278831481934 != 7.9492878913879395 : Loss mismatch at step 1: baseline=7.949278831481934, test=7.9492878913879395
loss parity on FSDP4, TP=2, SP off, EP=2, ETP=1: [LOSS_COMPARE] Average difference: 0.000000
loss parity on FSDP4, TP=2, SP on, EP=1, ETP=2: AssertionError: 6.0643310546875 != 6.064278602600098 : Loss mismatch at step 2: baseline=6.0643310546875, test=6.064278602600098
loss parity on FSDP4, TP=2, SP off, EP=1, ETP=2: [LOSS_COMPARE] Average difference: 0.000000
passed spmd type checking:
Also used a temporary script based on
TestBitwiseParityMoEEPto run mainand the current commit with identical checkpoint weights and uneven
prompts, then compared all prefill/decode logprobs and generated
token IDs bit-for-bit.