Support 3D+ MoE local_map mesh variants#514
Open
AlbedoWang wants to merge 1 commit into
Open
Conversation
7425913 to
32466d4
Compare
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
This PR extends the DeepSeekV3 MoE
local_mapimplementation so MoE can be represented on 3D+ AutoParallel meshes.The change makes the MoE communication and compute boundary explicit at the
local_mapHOP. AutoParallel continues to reason about the outer graph through HOP input/output placements, while the MoE body owns the variant-specific dispatch, expert computation, and collectives.Supported MoE role axes:
ep_axis_name: expert parallel axis for expert ownership and token dispatch/combine.token_axis_names: token batch sharding axes, defaulting to all mesh axes except ETP.expert_tensor_parallel_axis_name: optional ETP axis for expert hidden-dim tensor parallelism.expert_fsdp_axis_name: optional expert-weight sharding axis exposed at the HOP boundary.expert_fsdp_shard_dim: optional explicit EFSDP shard dimension.This lets the DSv3 example express MoE layouts such as:
dp, epep, etpefsdp, epdp_replicate, ep, etpdp_replicate, efsdp, epdp_replicate, efsdp, ep, etpMotivation
TorchTitan supports multiple sparse MoE mesh variants by assigning logical roles to mesh dimensions, for example DP replicate, EFSDP, EP, and ETP. AutoParallel needs the same kind of expressiveness, but its integration point is different.
In AutoParallel,
local_mapis the boundary that exposes MoE communication and computation to tracing as a HOP. DTensor placement reasoning happens at the HOP boundary, not by inferring arbitrary placement transitions inside the local body.Because of that, this PR makes each MoE variant explicit through:
Axis names themselves are only handles for selecting mesh dimensions. The semantics come from which role argument uses that axis.
Changes
3D+ MoE local_map placement construction
Adds a role-based placement helper for DSv3 MoE.
The helper builds token and expert-weight placements from the selected MoE roles:
Shard(0);Shard(0);This allows the same DSv3 MoE implementation to represent 2D, 3D, 4D, and higher-dimensional mesh variants without changing AutoParallel main graph logic.
Variant-specific MoE body collectives
Extends the local MoE body so the implementation matches the selected boundary placements:
This is necessary because AutoParallel does not rely on DTensor inference inside the
local_mapbody.DeepSeekV3 user-facing role arguments
Extends the DSv3 model/MoE constructor path with role arguments for EP, token axes, ETP, and EFSDP.
Users express the intended layout by constructing a named
DeviceMeshand passing the matching role arguments toDeepSeekV3Model. They do not manually writelocal_mapregions for the DSv3 example.local_map HOP compatibility
Updates placement option handling so the current
local_map_hoptarget name is recognized in addition to older local_map target names.3D expand propagation regression
Adds an AutoParallel propagation rule for
aten.expand.default. This fixes the 3D DSv3 attention failure where DTensor's expand rule raisesKeyError: 2when a candidate strategy shards the singleton head dimension that expand turns into the full head dimension.Invalid expand mappings are skipped; valid placements continue through normal redistribute-cost generation.
Documentation
Updates
docs/local_map_and_moe.mdwith user-facing guidance for:Validation
Codebase version:
Results:
Earlier, I also validated that an EFSDP-enabled DSv3 AutoParallel trace contains the expected expert-weight all-gathers inside the
local_mapbody:3D full-graph DSv3 AutoParallel smoke was also investigated. Before the expand rule, it failed at dense attention
aten.expand.defaultwithKeyError: 2. After this fix, that correctness failure is removed, but the local full 3D build did not complete within the diagnostic window because the later full-graph 3D strategy/cost search is still very large. This PR does not claim that full 3D DSv3 AutoParallel optimization completes locally end-to-end.Notes
This PR does not make AutoParallel synthesize arbitrary MoE implementations. It makes the DSv3 MoE example expose the correct 3D+
local_mapboundary and body for supported EP, ETP, EFSDP, and token-sharding role combinations.