Repository navigation
[Module][Full DTensor] Config-based sharding infrastructure with llama3 adoption - #2963
Merged
Merged
Conversation
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
Apr 14, 2026
…ith llama3 adoption Replace imperative parallelize_module() TP plans with declarative ShardingSpec on Module.Config for Llama3. This PR also ensures that DTensor for TP is used for llama3 (no to local). Known TODOs for follow-up: - apply_cp_to_forward: remove once all models use config-based sharding + full DTensor - LocalMapInnerAttention: remove entire class once all models use config-based sharding - parallelize(tp_mesh): pass full world mesh once FSDP/CP also use DTensor - input_layouts: remove once all inputs flow as DTensors - _shard_outputs: extend to support nested outputs (tuples/dicts) for multi-tensor forward ghstack-source-id: 0524554 Pull-Request: #2963
This was referenced Apr 15, 2026
[ghstack-poisoned]
fegin
commented
Apr 16, 2026
fegin
marked this pull request as ready for review
April 17, 2026 16:51
fegin
requested review from
SherlockNoMad,
aditvenk,
tianyu-l,
wconstab,
wwwjn,
xmfan and
yiming0416
as code owners
April 17, 2026 16:51
tianyu-l
reviewed
Apr 24, 2026
[ghstack-poisoned]
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
Apr 24, 2026
…ith llama3 adoption 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. Llama3 is migrated in this PR; remaining models follow in the next PR. Also ensures that TP uses DTensor end-to-end for Llama3 (no to_local() at module boundaries). Known TODOs for follow-up: - apply_cp_to_forward: remove once all models use config-based sharding + full DTensor - LocalMapInnerAttention: remove entire class once all models use config-based sharding - parallelize(tp_mesh): pass full world mesh once FSDP/CP also use DTensor - input_layouts: remove once all inputs flow as DTensors - _shard_outputs: extend to support nested outputs (tuples/dicts) for multi-tensor forward ghstack-source-id: 8c2950f Pull-Request: #2963
fegin
added a commit
that referenced
this pull request
Apr 24, 2026
…ith llama3 adoption 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. Llama3 is migrated in this PR; remaining models follow in the next PR. Also ensures that TP uses DTensor end-to-end for Llama3 (no to_local() at module boundaries). Known TODOs for follow-up: - apply_cp_to_forward: remove once all models use config-based sharding + full DTensor - LocalMapInnerAttention: remove entire class once all models use config-based sharding - parallelize(tp_mesh): pass full world mesh once FSDP/CP also use DTensor - input_layouts: remove once all inputs flow as DTensors - _shard_outputs: extend to support nested outputs (tuples/dicts) for multi-tensor forward ghstack-source-id: 10fb152 Pull-Request: #2963
fegin
added a commit
that referenced
this pull request
Apr 24, 2026
…ith llama3 adoption 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. Llama3 is migrated in this PR; remaining models follow in the next PR. Also ensures that TP uses DTensor end-to-end for Llama3 (no to_local() at module boundaries). Known TODOs for follow-up: - apply_cp_to_forward: remove once all models use config-based sharding + full DTensor - LocalMapInnerAttention: remove entire class once all models use config-based sharding - parallelize(tp_mesh): pass full world mesh once FSDP/CP also use DTensor - input_layouts: remove once all inputs flow as DTensors - _shard_outputs: extend to support nested outputs (tuples/dicts) for multi-tensor forward ghstack-source-id: 5d896ab Pull-Request: #2963
fegin
added a commit
that referenced
this pull request
Apr 27, 2026
…eek V3, GPT-OSS (#2969) Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0) (oldest at bottom): * #2987 * #3113 * #3080 * #2986 * __->__ #2969 * #2963 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.** **Models that are not converted: Flux and qwen3-vl.** 1. Flux doesn't support TP. So it is out of the current scope. We can convert it during the full dtensor PRs. 2. qwen3-vl vision part is hard to convert without full dtensor support. It is doable but let's not do the hacky way and wait until the full dtensor PRs.
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.
saforem2
added a commit
to saforem2/torchtitan
that referenced
this pull request
Apr 28, 2026
50-step moe smoke test using the smallest non-debug flavor (500M) on 2 nodes, AdamW, no checkpoint, fineweb-edu HF stream. Mirrors smoke_2b_50steps for moe to verify the post-pytorch#2963/pytorch#2937 replay end-to-end: imports, model build, sharding-config population on MLA attention + dense FFN, Module.parallelize, apply_moe_ep_tp, per-block compile, FSDP wrap, optimizer step, loss decreasing. scripts/submit_moe_smoke.sh mirrors competition/submit_run.sh but for the moe module path.
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
Replace string-keyed plan dicts passed to
parallelize_module()withShardingSpecattached to eachModule.Config. Sharding is co-located with the rest of a submodule's configuration and applied byModule.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: