Repository navigation
[Module][Full DTensor] Config-based sharding for Qwen3, Llama4, DeepSeek V3, GPT-OSS - #2969
Merged
Merged
Conversation
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
Apr 14, 2026
…4, DeepSeek V3, GPT-OSS Convert dense-layer TP and attention for all remaining models to config-based ShardingSpec, leaving MoE part unchanged, still using apply_moe_ep_tp(). After this PR, every model's attention uses Module.parallelize(). We will remove LocalInnerAttention in the next PR. ghstack-source-id: f3d2786 Pull-Request: #2969
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
Apr 14, 2026
…4, DeepSeek V3, GPT-OSS Convert dense-layer TP and attention for all remaining models to config-based ShardingSpec, leaving MoE part unchanged, still using apply_moe_ep_tp(). After this PR, every model's attention uses Module.parallelize(). We will remove LocalInnerAttention in the next PR. ghstack-source-id: 1343a6e Pull-Request: #2969
This was referenced Apr 15, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
fegin
marked this pull request as ready for review
April 17, 2026 16:51
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
tianyu-l
approved these changes
Apr 23, 2026
tianyu-l
left a comment
Contributor
There was a problem hiding this comment.
didn't check actual plan
| - apply training techniques in the following order | ||
| - TP (and EP if the model has MoE architecture) | ||
| - `model.parallelize(mesh)` — auto-recursive declarative sharding driven by `sharding_spec` (TP, SP, attention `local_map`). Replaces per-model `parallelize_module` plan dicts. | ||
| - (MoE models) `apply_moe_ep_tp` for expert-parallel + TP on MoE experts (not yet config-based). |
Contributor
There was a problem hiding this comment.
Right now the support of EP + ETP should be poor in perf, any no one is doing that really. So I think we should
- move the ETP > 1, EP=1 code to sharding.py
- deprecate the
ExpertTensorParallelclass. - rename
apply_moe_ep_tptoapply_ep, which itself should be killed after @acisseJZhong 's refactoring. The local_map application aroundGroupedExpertsshould also happen in set sharding.
Can be done in separate PR.
Contributor
Author
There was a problem hiding this comment.
Sparse related change will come later. I only focus on the dense part. Mesh selection needs to be addressed first before I play with the sparse part.
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
Apr 27, 2026
…a3 adoption (#2963) Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0) (oldest at bottom): * #2987 * #3113 * #3080 * #2986 * #2969 * __->__ #2963 **Summary** Replace string-keyed plan dicts passed to `parallelize_module()` with `ShardingSpec` attached to each `Module.Config`. Sharding is co-located with the rest of a submodule's configuration and applied by `Module.parallelize(mesh)` via auto-recursion. **NOTE that we have to do some compromise designs due to the backward compatibility issues, these should be removed either full DTensor is applied or at some time in the future** **Known TODOs for follow-up:** - apply_cp_to_forward: This is a workaround to keep the current CP work. Remove once all models use config-based sharding + full DTensor - input_layouts: Another workaround. We can remove it once all inputs flow as DTensors - LocalMapInnerAttention: remove entire class once all models use config-based sharding (#2986) - parallelize(tp_mesh): pass full SPMD mesh once FSDP/CP also uses DTensor (#2987) - _shard_outputs: extend to support nested outputs (tuples/dicts) for multi-tensor forward
saforem2
added a commit
to saforem2/torchtitan
that referenced
this pull request
Apr 28, 2026
…ytorch#2963/pytorch#2969) Mirror upstream's llama3 sharding refactor for agpt. Replaces the manual parallelize_module(...) + apply_tp(...) pipeline with the new config-based sharding API: each sub-config gets a ShardingConfig attached during update_from_config, and Module.parallelize(mesh) reads those declarations at TP-application time. New files: - agpt/sharding.py: set_agpt_sharding_config — wrapper around upstream's set_decoder_sharding_config + set_gqa_attention_sharding + set_dense_ffn_sharding helpers, plus QK-Norm sharding (which upstream's GQA helper doesn't know about because llama3 has no QK-Norm). - agpt/model.py: AgptModel(Llama3Model) — overrides Config.update_from_config to call set_agpt_sharding_config after the base llama3 setter runs. Modified: - agpt/__init__.py: switch all configs from Llama3Model.Config to AgptModel.Config so the ezpz update_from_config hook fires. - agpt/parallelize.py: rewritten as a thin orchestrator. TP is now just model.parallelize(tp_mesh); apply_tp + parallelize_module + manual ColwiseParallel/RowwiseParallel/SequenceParallel/PrepareModuleInput plumbing all gone. Float8 tensorwise TP path also gone — the new sharding API doesn't have an equivalent yet, and we weren't using it in production. Will revisit when float8 lands in the new API upstream. Preserved agpt-specific behavior: - disable_fsdp_gradient_division still calls set_force_sum_reduction_for_comms(True) on non-NCCL backends (CCL/XPU). - Post-apply_compile reset of capture_scalar_outputs=False to keep the separately-compiled CrossEntropyLoss working on dense models. - apply_fsdp keeps the [norm, lm_head] joint grouping with reshard_after_forward gated on the policy. Verified: - agpt_configs['debugmodel'] / 2B / 2B_qknorm import + build_meta + run update_from_config + Module.parallelize(1D tp mesh) cleanly. lm_head becomes a DTensor as expected; QK-Norm RMSNorm gets a sharding_config.
saforem2
added a commit
to saforem2/torchtitan
that referenced
this pull request
Apr 28, 2026
…torch#2963/pytorch#2969) Mirror upstream's deepseek_v3 sharding refactor for moe. The non-MoE TP path (attention/norms/dense FFN) is now driven by sharding_config declarations consumed by Module.parallelize(tp_mesh). MoE blocks are still parallelized at parallelize-time by apply_moe_ep_tp — that mirrors upstream deepseek_v3, where set_deepseek_v3_sharding_config also leaves the MoE block alone. New file: - moe/sharding.py: set_moe_sharding_config — wrapper around upstream's set_decoder_sharding_config + set_dense_ffn_sharding helpers, plus the MLA-specific attention sharding. Binds against experiments.ezpz.moe.model.Attention (our MLA Attention is a separate class from upstream's, even though structurally identical). Modified: - moe/model.py: extends moeModel.Config.update_from_config to call set_moe_sharding_config after the existing rope/MoE sync logic. - moe/parallelize.py: rewritten as a thin orchestrator. Drops 230+ lines of manual ColwiseParallel/RowwiseParallel/SequenceParallel/ PrepareModuleInput plans (`apply_non_moe_tp`) that are now declared via sharding_config. Keeps the agpt-style XPU `disable_fsdp_gradient_division`, the per-block `block.compile(backend=...)` workaround (XPU can't fullgraph compile MoE routing), the inlined `apply_fsdp` (avoids ShardPlacementResult import that doesn't exist in Aurora's PyTorch) with the Shard(0) fallback for non-divisible expert hidden dims, and the `summarize_model` log line. Verified locally on 1-rank gloo: imports clean, Module.parallelize(1D mesh) populates DTensor on every sub-module (including lm_head, MLA wkv_a/wkv_b, both q_lora_rank=0 and >0 paths). meta build of moe debugmodel succeeds with the expected 1 dense + 5 MoE layer structure.
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):
Convert dense-layer TP and attention for all remaining models to config-based
ShardingSpec, leaving MoE part unchanged, still usingapply_moe_ep_tp(). After this PR, every model's attention usesModule.parallelize().We will remove LocalInnerAttention in the next PR.
Models that are not converted: Flux and qwen3-vl.