Repository navigation
Conversation
This was referenced Apr 29, 2026
fegin
added a commit
that referenced
this pull request
Apr 29, 2026
…ma4, gpt_oss, deepseek_v3)
Drops the EP gate in ``full_dtensor.validate_config`` and adds the sparse
SPMD mesh wiring needed for routed-expert FSDP under
``--training.full_dtensor``. All four MoE models now support full DTensor
mode where dense subtree sits on the dense SPMD mesh
``(dp_replicate, dp_shard, cp, tp)`` and routed experts on the sparse
SPMD mesh ``(dp_replicate, efsdp, ep, etp)``, both within one
``model.parallelize(parallel_dims)`` invocation.
Verified at 500 steps EP=2 (4xH100, ``--debug.seed=42``):
- qwen3: loss 2.00980, grad_norm 0.5127
- llama4: loss 1.81126, grad_norm 0.1787
- gpt_oss: loss 1.90610, grad_norm 0.2511
- deepseek_v3: loss 2.02116, grad_norm 0.2729
Non-full_dtensor regression bit-identical to PR7 across all four models.
## Sparse mesh helpers in ``full_dtensor.py``
- ``_sparse_spmd_axes(parallel_dims)`` -- canonical sparse SPMD axis
list, intersected with enabled axes. Sibling of ``_dense_spmd_axes``.
- ``get_sparse_dp_mesh_axes(parallel_dims)`` -- ``DataParallelMeshDims``
for routed-expert FSDP: ``shard="efsdp"``, ``replicate="dp_replicate"``
when enabled. Sibling of ``get_dp_mesh_axes``.
- ``resolve_sparse_fsdp_mesh(parallel_dims, full_dtensor)`` -- returns
``(sparse_fsdp_mesh, sparse_dp_mesh_dims)`` under full_dtensor; under
non-full_dtensor returns the legacy ``efsdp`` / ``(dp_replicate,
efsdp)`` mesh and ``None`` for the dims. Returns ``(None, None)``
when EP is disabled. Sibling of ``resolve_fsdp_mesh``.
- ``validate_config`` -- drops the
``if parallel_dims.ep_enabled: raise NotImplementedError`` gate. CP +
SDPA/Varlen rejection retained.
## ``apply_fsdp`` mesh routing under full_dtensor (llama4/parallelize.py)
Adds ``dp_mesh_dims`` and ``edp_mesh_dims`` kwargs. Plumbed through
``fsdp_config`` for the outer ``fully_shard`` call and into
``FSDPMeshInfo(spmd_mesh=, dp_mesh_dims=)`` for per-param routing under
EP > 1. The existing ``_shard_placement_fn`` shape (per-param
``param in expert_params`` check) stays; only the mesh objects swap.
## Per-model ``parallelize_*.py`` enable
For qwen3 / llama4 / gpt_oss / deepseek_v3, replaces
if parallelism.full_dtensor:
raise NotImplementedError("full_dtensor is not supported yet.")
with the llama3 pattern:
if parallelism.full_dtensor:
validate_config(parallel_dims, model)
model.parallelize(parallel_dims)
else:
if parallel_dims.cp_enabled:
apply_cp_to_forward(...)
if parallel_dims.tp_enabled or parallel_dims.ep_enabled:
model.parallelize(parallel_dims)
and resolves both the dense and sparse FSDP meshes via the new helpers
under full_dtensor.
## Module.parallelize partition check (subset, not strict equality)
Under full_dtensor, the partition check that ensures
``distribute_tensor`` reaches every SPMD peer rank is relaxed from
strict equality to subset. ``LocalMap``-only configs (e.g. inner
attention's ``{TP: Shard(2)}``) declare a narrow axis subset of the
dense partition without claiming coverage of the full mesh. State-
shardings helpers always emit all dense axes so they pass either way.
Empty declared (every axis disabled in this run) is treated as a no-op,
not an invalid partition.
## ``set_gqa_inner_attention_local_map``: full dense axis set
Switched ``qkv_placements`` from bare ``{TP: Shard(2)}`` to
``dense_activation_placement(tp=Shard(2))``. Under full_dtensor where
the surrounding mesh is multi-axis (e.g. ``(dp_shard, tp)``),
``local_map``'s redistribute requires placements for every mesh axis;
the bare ``{TP: ...}`` form crashed with "list index out of range" in
``generate_greedy_transform_infos``. Under non-full_dtensor the
(tp,)-only mesh only consumes the ``TP`` placement and the rest are
ignored.
## ``set_moe_sharding_config``: dense submodules unconditional
The MoE wrapper, router gate, and shared experts had their
``sharding_config`` set only when ``tp_enabled``. Under full_dtensor +
EP-only (TP=1), this left those dense params plain (not DTensor),
which fired FSDP2's invariant
"all parameters must be DTensors on the full SPMD mesh." Now set
unconditionally. Under TP=1 the TP-axis placements get filtered at
``resolve_placements`` time and the configs become all-Replicate on
remaining dense axes (no-op for parallelism, but the params are
DTensors as required).
## Out of scope
- qwen3_vl (deferred to PR9, full conversion + full_dtensor).
- vLLM RL inference path.
- Final deletion of ``apply_moe_ep_tp`` from ``llama4/parallelize.py``
(still needed by qwen3_vl until PR9).
ghstack-source-id: c12eb04
Pull-Request: #3161
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):
Drops the EP gate in
full_dtensor.validate_configand adds the sparseSPMD mesh wiring needed for routed-expert FSDP under
--training.full_dtensor. All four MoE models now support full DTensormode where dense subtree sits on the dense SPMD mesh
(dp_replicate, dp_shard, cp, tp)and routed experts on the sparseSPMD mesh
(dp_replicate, efsdp, ep, etp), both within onemodel.parallelize(parallel_dims)invocation.Verified at 500 steps EP=2 (4xH100,
--debug.seed=42):Non-full_dtensor regression bit-identical to PR7 across all four models.
Sparse mesh helpers in
full_dtensor.py_sparse_spmd_axes(parallel_dims)-- canonical sparse SPMD axislist, intersected with enabled axes. Sibling of
_dense_spmd_axes.get_sparse_dp_mesh_axes(parallel_dims)--DataParallelMeshDimsfor routed-expert FSDP:
shard="efsdp",replicate="dp_replicate"when enabled. Sibling of
get_dp_mesh_axes.resolve_sparse_fsdp_mesh(parallel_dims, full_dtensor)-- returns(sparse_fsdp_mesh, sparse_dp_mesh_dims)under full_dtensor; undernon-full_dtensor returns the legacy
efsdp/(dp_replicate, efsdp)mesh andNonefor the dims. Returns(None, None)when EP is disabled. Sibling of
resolve_fsdp_mesh.validate_config-- drops theif parallel_dims.ep_enabled: raise NotImplementedErrorgate. CP +SDPA/Varlen rejection retained.
apply_fsdpmesh routing under full_dtensor (llama4/parallelize.py)Adds
dp_mesh_dimsandedp_mesh_dimskwargs. Plumbed throughfsdp_configfor the outerfully_shardcall and intoFSDPMeshInfo(spmd_mesh=, dp_mesh_dims=)for per-param routing underEP > 1. The existing
_shard_placement_fnshape (per-paramparam in expert_paramscheck) stays; only the mesh objects swap.Per-model
parallelize_*.pyenableFor qwen3 / llama4 / gpt_oss / deepseek_v3, replaces
with the llama3 pattern:
and resolves both the dense and sparse FSDP meshes via the new helpers
under full_dtensor.
Module.parallelize partition check (subset, not strict equality)
Under full_dtensor, the partition check that ensures
distribute_tensorreaches every SPMD peer rank is relaxed fromstrict equality to subset.
LocalMap-only configs (e.g. innerattention's
{TP: Shard(2)}) declare a narrow axis subset of thedense partition without claiming coverage of the full mesh. State-
shardings helpers always emit all dense axes so they pass either way.
Empty declared (every axis disabled in this run) is treated as a no-op,
not an invalid partition.
set_gqa_inner_attention_local_map: full dense axis setSwitched
qkv_placementsfrom bare{TP: Shard(2)}todense_activation_placement(tp=Shard(2)). Under full_dtensor wherethe surrounding mesh is multi-axis (e.g.
(dp_shard, tp)),local_map's redistribute requires placements for every mesh axis;the bare
{TP: ...}form crashed with "list index out of range" ingenerate_greedy_transform_infos. Under non-full_dtensor the(tp,)-only mesh only consumes the
TPplacement and the rest areignored.
set_moe_sharding_config: dense submodules unconditionalThe MoE wrapper, router gate, and shared experts had their
sharding_configset only whentp_enabled. Under full_dtensor +EP-only (TP=1), this left those dense params plain (not DTensor),
which fired FSDP2's invariant
"all parameters must be DTensors on the full SPMD mesh." Now set
unconditionally. Under TP=1 the TP-axis placements get filtered at
resolve_placementstime and the configs become all-Replicate onremaining dense axes (no-op for parallelism, but the params are
DTensors as required).
Out of scope
apply_moe_ep_tpfromllama4/parallelize.py(still needed by qwen3_vl until PR9).