Repository navigation
[dist_moe] Add DeepSeek V3 recipes and integration coverage - #4542
Merged
Merged
Conversation
This was referenced Sep 9, 2026
This was referenced Sep 10, 2026
sanketpurandare
added a commit
that referenced
this pull request
Sep 10, 2026
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: cc45371 Pull-Request: #4543
sanketpurandare
added a commit
that referenced
this pull request
Sep 10, 2026
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: cc45371 Pull-Request: #4543
sanketpurandare
marked this pull request as ready for review
September 10, 2026 20:03
sanketpurandare
requested review from
IvanKobzarev,
SherlockNoMad,
aditvenk,
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
September 10, 2026 20:03
sanketpurandare
added a commit
that referenced
this pull request
Sep 11, 2026
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: ec33322 Pull-Request: #4543
sanketpurandare
added a commit
that referenced
this pull request
Sep 11, 2026
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: a2aec19 Pull-Request: #4543
sanketpurandare
added a commit
that referenced
this pull request
Sep 11, 2026
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: a2aec19 Pull-Request: #4543
sanketpurandare
added a commit
that referenced
this pull request
Sep 11, 2026
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: d0a1e01 Pull-Request: #4543
sanketpurandare
added a commit
that referenced
this pull request
Sep 11, 2026
Summary: Add the single TorchTitan-owned guide for the standalone Dist-MoE backend. It documents conversion, checkpoint compatibility, the shared MXFP8/FSDP lifecycle, memory and VMM ownership, pipeline slot planning, configuration, and cleanup. Kernel and allocator internals remain in the package documentation. It distinguishes the direct ordinary-eager entry from the registered ordered-effect entry used under dispatch and tracing. This change defines no independent runtime contract and does not duplicate kernel derivations. Examples must continue to match the registered config schema and the released package API. Dependencies and risks: - Documentation follows #4539-#4542/#4559 and the released annex API. - Broken links or stale examples are release-blocking documentation drift. Test Plan: - `pre-commit run --files README.md docs/dist_moe.md` - Markdown link check and executable validation of copied configuration examples. ghstack-source-id: 8b8aaed Pull-Request: #4543
sanketpurandare
added a commit
that referenced
this pull request
Sep 26, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0) (oldest at bottom): * #4543 * #4542 * #4541 * __->__ #4623 * #4559 * #4652 * #4591 * #4592 Summary: Let `RoutedExperts.Config` own an optional `output_postprocess` `Module.Config` that transforms each expert output after W2 and before dispatcher combine. The name is unambiguous within `RoutedExperts`, while the module-based contract supports learned route-wise operations such as MS post-expert RMSNorm and keeps their parameters in the module state, checkpoint, optimizer, and FSDP ownership tree. The default remains `None`, so existing models retain the same execution path. Communication-owning expert backends can translate supported modules to their native fused descriptors and reject unsupported modules during conversion. Test Plan: - `python -m pytest -q tests/unit_tests/cpu/test_moe.py` - `pre-commit run --files torchtitan/models/common/moe.py tests/unit_tests/cpu/test_moe.py`
tianyu-l
reviewed
Oct 1, 2026
sanketpurandare
commented
Oct 1, 2026
sanketpurandare
commented
Oct 1, 2026
sanketpurandare
commented
Oct 1, 2026
sanketpurandare
commented
Oct 1, 2026
sanketpurandare
commented
Oct 1, 2026
sanketpurandare
commented
Oct 1, 2026
sanketpurandare
commented
Oct 1, 2026
tianyu-l
approved these changes
Oct 2, 2026
| ), | ||
| IntegrationTestDefinition( | ||
| configs=[ | ||
| recipes.graph_trainer_deepseek_v3_debugmodel_dist_moe_bf16_fsdp2_ep2 |
Contributor
There was a problem hiding this comment.
please don't put graph trainer CI into this file
tianyu-l
reviewed
Oct 2, 2026
| CUDA_HOME=/usr/local/cuda TORCH_SHOW_CPP_STACKTRACES=1 \ | ||
| python -m torchtitan.experiments.graph_trainer.tests.integration_tests \ | ||
| "$RUNNER_TEMP/artifacts-to-be-uploaded/graph_trainer_b200" \ | ||
| --test_suite graph_trainer_b200 \ |
Contributor
There was a problem hiding this comment.
run this in its separate capacity https://github.com/pytorch/torchtitan/blob/main/.github/workflows/integration_test_8gpu_graph_trainer_h100.yaml -- please don't piggyback on core trainer test
sanketpurandare
added a commit
that referenced
this pull request
Oct 2, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0) (oldest at bottom): * #4543 * #4542 * #4541 * __->__ #4934 Summary: SimpleFSDP intentionally materializes a parameter on each property access, so tracing may produce duplicate annotated all-gather and post-gather preparation chains for one parameter. GraphTrainer already canonicalizes those chains before partitioning and FSDP extraction. Prefer an unshard endpoint that still has consumers when choosing the canonical chain. Dead-code elimination removes an unused preparation tail but retains its effectful collective; choosing that dead raw endpoint can otherwise replace a live prepared MXFP8 value with a BF16 gathered tensor. Remove dead duplicate chains without substituting their unused endpoints. This keeps SimpleFSDP functional and compiler-safe. It adds no module hooks, Python cache state, MXFP8 execution-mode branches, or changes to eager FSDP behavior. Test Plan: - The six focused FSDP unshard-deduplication and overlap tests pass on the current base. - The final changed-surface suite passes with 315 tests and 1 skip.
SherlockNoMad
added a commit
that referenced
this pull request
Oct 2, 2026
Rebased directly onto `main`; no longer depends on the `graph_builder.py` split (#5000), so all changes are in `graph_builder.py`. ## Why `_annotate_graph_pp_graph` wrote `graph_pp_stage_index`, `graph_pp_callable`, `graph_pp_action`, and `graph_pp_slot` into `node.meta` of every GraphPP and SPMD gradient-accumulation graph. It was added in #3089 ("GraphPP node metadata is annotated for TLParse and debugging"), but nothing ever consumed it: - **No reader anywhere.** `git log --all -S` for each key finds only the writers and a unit test asserting them; no reader existed at any point. Upstream PyTorch has no references either. - **TLParse never showed them.** TLParse graph dumps use `gm.print_readable()`, which only prints extra `node.meta` keys listed in `additional_meta` (`torch/fx/graph.py`). `trace_graph_pp_graph` passes none, and `debug_utils` only lists `autograd_backward` / `seq_nr`. ## What - Remove `_annotate_graph_pp_graph` and `_annotate_graph_pp_modules`. - Drop the `annotate_graph` parameter from `stage_builder._build_graph_pp_overlap_graphs`. - Rename `_annotate_and_compile_scheduled_fwd_bwd_graphs` -> `_compile_scheduled_fwd_bwd_graphs`. Compiled graph names (visible in TLParse) are unchanged. - Remove `test_graph_pp_node_metadata_is_annotated`, the only consumer of the keys. Net: -84 / +3. No behavior change. ## Tests - Before rebasing onto `main` (same change applied to the unsplit `graph_builder.py`): `test_graph_pp_runner.py`, `test_graph_pp_passes.py`, `test_trace_module.py` -> 161 passed, 3 skipped (one GPU-contention flake in `test_peak_memory_identical_fsdp` passed on rerun). - After rebasing onto `main`: pre-commit and pyflakes clean. Unit tests not re-run locally (current `main` needs a newer PyTorch than the local build for `WAIT_REDUCE_GRAD`); relying on CI. - Merges cleanly with Sanket's Dist-MoE stack (#4541, #4542, #4543), none of which use the removed annotation API.
sanketpurandare
added a commit
that referenced
this pull request
Oct 3, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0) (oldest at bottom): * #4543 * #4542 * __->__ #4541 I reviewed this integration against the standalone Dist-MoE API, TorchTitan's current model-transform and FSDP contracts, eager pipeline execution, GraphPP tracing, and the recorded local distributed validation. > The following technical description was prepared with Codex assistance and reviewed before posting. > > ## Summary > > Integrate the standalone [`dist-moe`](https://github.com/meta-pytorch/dist_moe) > package as an optional routed-expert backend for BF16 and asynchronous MXFP8 > training on NVIDIA SM100-or-newer GPUs. > > TorchTitan owns routing, structured W13/W2 parameters, optimizer and > checkpoint state, FSDP, model transforms, pipeline policy, and the training > lifecycle. Dist-MoE owns dispatch through combine, grouped expert kernels, > communication buffers, saved activations, device scratch, optional VMM > overflow scratch, and its device-side save/recompute policy. PyTorch > pipelining owns stage/microbatch metadata and schedule-derived liveness. > > ## Optional dependency boundary > > Ordinary TorchTitan and GraphTrainer imports do not import or install > Dist-MoE. `TrainingEngine.Config.dist_moe` is a > `Configurable.Config | None`; `None` is the only disabled state, so there is > no duplicate enable flag. A selected recipe performs a guarded import and > supplies `DistMoeRuntime.Config`. Base requirements intentionally do not > install this Blackwell-only package. > > The built object is retained as an exactly typed optional runtime through a > `TYPE_CHECKING`-only import. Dist-MoE operator handles used by GraphPP are > loaded lazily only when a Dist-MoE graph is traced. > > ## Routed-expert transform > > One `DistMoeTransform(expert_precision="bf16" | "mxfp8")` replaces each stock > `RoutedExperts.Config` directly. The source uses stock `GroupedLinear` W13/W2, > SwiGLU, and all-to-all dispatcher configs. The replacement retains: > > - `w13.weight`: `[E, 2, F, D]` > - `w2.weight`: `[E, D, F]` > > Dist-MoE owns dispatch, activation, expert compute, and combine, so the > transform conflicts with LoRA and `TokenDispatcherTransform`. Dense MXFP8 > `Linear` conversion remains an independent recipe choice. > > Optional expert output postprocessing remains a normal TorchTitan module with > optimizer, checkpoint, FSDP, autograd, and tracing ownership. The adapter > binds its live parameter into the Annex descriptor executed after W2 and > before score-weighted combine. > > ## Runtime lifecycle and memory > > Runtime construction is the first forward/backward-initialization phase, > after model materialization and before tracing or CUDA-graph capture. The > standard or graph engine supplies final model parts, topology, the liveness > schedule, and a narrow context-registration capability. `DistMoeRuntime` > owns expert discovery, EP group resolution, token capacity, slot coloring, > Annex context creation, eager/GraphPP registration, handles, partial-failure > unwind, module attachment, and idempotent close. > > TrainingEngine does not own Dist-MoE hook handles or inspect Annex memory. > Runtime configuration separates device scratch, per-live-slot saved > activations, optional host-backed VMM scratch, and PP slot granularity. > > ## Eager PP and GraphPP > > Eager PP uses PyTorch's registered stage-forward context and a deterministic > `(stage, microbatch) -> activation slot` mapping. GraphPP uses the same > resolver but supplies an immutable `activation_slot_id_1` graph input. The > graph builder lazily imports exact registered operators, resolves the slot > operand from each schema, and performs no string target matching. > > ## FSDP and WGrad > > BF16 experts use ordinary FSDP ownership. MXFP8 experts reuse TorchTitan's > prepared-weight post-all-gather lifecycle for 32x32 qdata and FPROP/DGRAD > scales. Prepared storage follows the normal reshard boundary. > > The integration currently emits WGrad in the BF16 unsharded compute-parameter > dtype. FSDP independently casts to `mixed_precision_reduce` before > reduce-scatter. A TODO records future Annex `parameter.grad_dtype` support. > #4541 defaults to functional WGrad; #4542 enables eager in-place accumulation > and keeps GraphTrainer functional. > > Eager/common adapter tests and GraphTrainer adapter tests live in separate > owner-specific files. Recipe and B200 coverage belongs to the stacked recipe > integration PR. > > ## Scope > > This PR integrates training. Annex supports inference execution, but > TorchTitan does not yet provide an inference runtime owner. The PR does not > copy kernels, expose allocator internals, add optimizer/checkpoint branches, > or enable VMM tests on a personal development host. > > ## Verification > > - 25 focused eager/common and GraphTrainer-owned adapter/GraphPP CPU tests > pass at the #4541 commit boundary. > - The final stacked affected CPU suite passes 136 tests. > - Focused GraphPP runner slot-input and runtime registration tests pass. > - The stack is semantically rebased onto current TorchTitan main and retains > #4927's GraphTrainer gradient-accumulation state and execution modes. > - Common modules import with `dist_moe` blocked; selecting a Dist-MoE recipe > raises the focused optional-package diagnostic. > - Formatting, Flake8, pydoclint, codespell, AST, merge-conflict, and link > checks pass. > - Pyrefly reports no error in the new integration files. Its configured > project check reproduces only the current-main `_set_lru_cache` and PyAV > nullability findings outside this stack. >
sanketpurandare
changed the base branch from
gh/sanketpurandare/18/base
to
main
October 3, 2026 13:24
sanketpurandare
changed the base branch from
main
to
gh/sanketpurandare/18/base
October 3, 2026 13:25
sanketpurandare
changed the base branch from
gh/sanketpurandare/18/base
to
main
October 3, 2026 15:58
sanketpurandare
changed the base branch from
main
to
gh/sanketpurandare/18/base
October 3, 2026 15:59
Summary: Add guarded BF16 and MXFP8 Dist-MoE recipes in the ownership layout introduced by recipe reorganization #4913. Verified 671B eager recipes live under model recipes; debug and 16B variants are test-owned. Verified 671B GraphTrainer wrappers and test-owned debug/16B wrappers follow the same split. The production recipes use sequence length 4096, PP4/VPP4, EP64, MBS1, GBS15360, varlen attention, fused MLA and SwiGLU, no activation checkpointing, unchunked loss, FP32 persistent parameters, BF16 compute and reduction, and fused AdamW with BF16 moments. BF16 uses DP128 with 120 PP microbatches; MXFP8 uses DP64 with 240. GraphTrainer recipe tests and B200 factories live only under GraphTrainer-owned paths. The eager B200 suite retains BF16/MXFP8 SPMD, VMM, and production-like MXFP8 PP BF16 coverage. The GraphTrainer suite retains focused BF16 SPMD and MXFP8 GraphPP coverage; redundant GraphTrainer MXFP8 SPMD and eager PP FP32 reduction cells are omitted. Both B200 workflows install the latest Dist-MoE nightly directly from its public Git repository. The labeler selects ciflow/b200 for Dist-MoE paths and B200 workflow/config changes. Dist-MoE PP numerics inherit SAC and use eight PP microbatches. Eager slot policies run with full CUDA graphs and remain bitwise. GraphPP explicitly disables CUDA graphs and uses the established BF16 distributed tolerance until issue #5043 restores its singleton-FSDP WGrad rounding boundary. Issue #5044 tracks GraphTrainer fusion of Dist-MoE accumulating backward operators. Test Plan: - 55 focused eager/common and GraphTrainer-owned Dist-MoE CPU tests pass. - Real EP2 stock fused-SwiGLU and Annex BF16 forward/backward parity passes at rtol=atol=1e-4. - Four-GPU eager microbatch and stage-microbatch slot policies match loss and gradient norm bitwise for four SAC/CUDA-graph steps with eight PP microbatches. - Four-GPU GraphPP loss and gradient norm match eager for four SAC-enabled steps at rtol=atol=2e-2 with eight PP microbatches. - Changed-file formatting, lint, docstring, spelling, and link hooks pass. Pyrefly reports only two existing findings outside this stack. ghstack-source-id: f38c9bf Pull Request resolved: #4542
sanketpurandare
changed the base branch from
gh/sanketpurandare/18/base
to
main
October 3, 2026 16:04
sanketpurandare
force-pushed
the
gh/sanketpurandare/18/head
branch
from
October 3, 2026 16:04
76d553d to
cc726c3
Compare
sanketpurandare
added a commit
that referenced
this pull request
Oct 3, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.18.0) (oldest at bottom): * __->__ #4543 * #4542 Summary: Add a user-facing Dist-MoE integration guide under torchtitan/models/common/dist_moe/README.md and link it from the top-level feature list. The guide documents the optional package boundary, nightly Git installation, BF16/MXFP8 transforms, parameter/checkpoint ownership, runtime lifecycle, scratch and activation-slot planning, VMM, eager PP and GraphPP slot selection, FSDP prepared-weight handling, WGrad ownership, output postprocessing, recipe locations, and current limitations. Test Plan: - Markdown formatting and codespell pass. - Link checking passes for README.md and the Dist-MoE guide. - BF16, MXFP8, and VMM examples use the final API and import paths.
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:
Add guarded BF16 and MXFP8 Dist-MoE recipes in the ownership layout introduced
by recipe reorganization #4913. Verified 671B eager recipes live under model
recipes; debug and 16B variants are test-owned. Verified 671B GraphTrainer
wrappers and test-owned debug/16B wrappers follow the same split.
The production recipes use sequence length 4096, PP4/VPP4, EP64, MBS1,
GBS15360, varlen attention, fused MLA and SwiGLU, no activation checkpointing,
unchunked loss, FP32 persistent parameters, BF16 compute and reduction, and
fused AdamW with BF16 moments. BF16 uses DP128 with 120 PP microbatches; MXFP8
uses DP64 with 240.
GraphTrainer recipe tests and B200 factories live only under GraphTrainer-owned
paths. The eager B200 suite retains BF16/MXFP8 SPMD, VMM, and production-like
MXFP8 PP BF16 coverage. The GraphTrainer suite retains focused BF16 SPMD and
MXFP8 GraphPP coverage; redundant GraphTrainer MXFP8 SPMD and eager PP FP32
reduction cells are omitted.
Both B200 workflows install the latest Dist-MoE nightly directly from its
public Git repository. The labeler selects ciflow/b200 for Dist-MoE paths and
B200 workflow/config changes.
Dist-MoE PP numerics inherit SAC and use eight PP microbatches. Eager slot
policies run with full CUDA graphs and remain bitwise. GraphPP explicitly
disables CUDA graphs and uses the established BF16 distributed tolerance until
issue #5043 restores its singleton-FSDP WGrad rounding boundary. Issue #5044
tracks GraphTrainer fusion of Dist-MoE accumulating backward operators.
Test Plan:
rtol=atol=1e-4.
gradient norm bitwise for four SAC/CUDA-graph steps with eight PP microbatches.
steps at rtol=atol=2e-2 with eight PP microbatches.
Pyrefly reports only two existing findings outside this stack.