Repository navigation
[spmd] normalize partial to replicate on size-1 mesh axes in resolve_placements - #3762
Merged
Merged
Conversation
shuhuayu
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
June 24, 2026 05:38
tianyu-l
approved these changes
Jun 24, 2026
tianyu-l
left a comment
Contributor
There was a problem hiding this comment.
sounds reasonable, thanks!!
saforem2
added a commit
to saforem2/torchtitan
that referenced
this pull request
Jun 25, 2026
Clean merge, no conflicts, no code replays. Fused-QKV-by-default (pytorch#3714) flows via common/ but ezpz/agpt keeps fuse_qkv=False (zero checkpoint risk to 2B/80B chains); LoRA/protocol convert() change (pytorch#3456) benign for ezpz (moe quant builds OK); varlen+PP assert (pytorch#3777) and SPMD Partial size-1 fix (pytorch#3762) are no-op/free-win. Config-build smoke passed for agpt_2b/2b_real/80b + moe_10b_2b/sdpa.
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.
resolve_placementsalready collapsesShard(d) -> Replicate()on a size-1 mesh axis.Partialhas the exact same property but wasn't covered, which makes full-DTensor MoE crash on any config with a size-1 data-parallel axis. To reproduce,Got
root cause
Under
full_dtensor, the batch is sharded across the data-parallel axis. Withdp_shard == 1that axis has a single rank, so there's nothing to split and the whole batch lives on that one rank, i.e.Replicateon the dp axis. Intorchtitan/models/common/moe.py,When dp_shard=1,
routing_map_BLE = zeros_like(scores_BLE).scatter_(...)inherits that placement, so it'sReplicateon the dp axis too. The MoE per-expert token counts (num_local_tokens_per_expert_E = routing_map.sum(dim=(0,1))) are declaredPartial(sum)on the data-parallel axis via_tokens_per_expert_placement, correct, because each dp rank processes different tokens and contributes a partial count. Withdp_shard == 1the DP axis has a single rank, so the batch is not split and the runtime value comes outReplicateon that axis as shown above.resolve_placementsonly normalizesShard -> Replicateon size-1 axes, notPartial, so the contract's expected keepsPartial(sum)while the actual value isReplicate. _redistribute_inputsthen rejects the (numerically identical) mismatch.Fix
Extend the existing size-1 normalization in
resolve_placementsto coverPartialas well asShard.Numerical test confirmed loss/gd_norm parity on dp_shard=2 after the fix.