Skip to content

[kimi_k3] Run Dist-MoE through Kimi K3's pipeline stages - #6049

Merged
shuhuayu merged 1 commit into
mainfrom
shuhuayu/k3-dm-stack-11-pp
Nov 25, 2026
Merged

shuhuayu merged 1 commit into
mainfrom
shuhuayu/k3-dm-stack-11-pp

Conversation

@shuhuayu

@shuhuayu shuhuayu commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

  1. Let dist-moe get activation slots from the customized pp in k3.
  2. build pp metadata from config in build time, avoid timeout during dynamic pp metadata inference in full scale kimi k3 runs.

Part of the Kimi K3 training stack, stacked on #5684 (SiTU-GLU Dist-MoE).

Why

Kimi K3 rebuilds every PP stage as AttnResPipelineStage (to carry AttnRes block stacks). With Dist-MoE under PP, that rebuild breaks two things on main:

  1. No activation slot is selected. Dist-MoE picks its per-(stage, microbatch) activation slot through the stage's registered forward contexts. AttnResPipelineStage.forward_one_chunk overrides the base method and calls the model directly, so the contexts are never entered.
  2. Every real-PG run does dynamic metadata inference. Core declares static stage metadata only on the fake backend, and its single-hidden boundary does not fit K3's (hidden, delta) carriers anyway. So PyTorch infers metadata by running one serial forward and backward through every stage before step 1, on uninitialized inputs:
    • at full K3 scale (256 GB200, PP8) this hit the 600 s NCCL timeout;
    • with learned routing, the uninitialized inputs collapsed onto a few experts and tripped Dist-MoE's capacity guard before training (512 GB200 run).

Example (K3 with CP16, 64K tokens per microbatch):

main:  stage rebuild -> no static metadata -> dynamic inference:
       serial fwd+bwd over all stages, uninitialized inputs routed through Dist-MoE
this:  stage i receives hidden_TD [4096, D] + delta_TND [4096, n_i, D]
       (65536 / CP16 = 4096 tokens; n_i = blocks sent into stage i)
       -> no inference pass; forward contexts select the Dist-MoE slot

What changed

  • kimi_k3/pipeline_parallel/__init__.py:
    • _build_attn_res_stage_metadata declares every stage's inputs, outputs and their gradients on the meta device. It reuses core's decoder boundaries: token IDs into the first stage, and logits (or hidden, under chunked loss) out of the last. Each boundary between stages is (hidden_TD, delta_TND), with N from the block layout.
    • The block stack takes its token count from core's hidden_TD, so it is CP-local and sequence-sharded under SP. K3 declares this metadata on every backend.
    • With sequence parallelism, the first stage must contain a decoder layer; otherwise the first boundary would carry TP-replicated embeddings, so this raises ValueError.
    • The stage swap now happens after the layout is known, so the metadata can be passed to the rebuilt stages.
  • kimi_k3/pipeline_parallel/stage.py:
    • AttnResPipelineStage overrides the public register_forward_context. It keeps the factory itself and enters it in its own forward_one_chunk with the stage and microbatch index; PyTorch enters registered contexts only in the base forward_one_chunk, which this class replaces. No private PyTorch API is used.
    • The stage now requires input_args and output_args, so it can never fall back to dynamic inference, which would run outside its block routing and forward context.
    • Deleted the code only dynamic inference reached: _compute_outputs and _compute_input_grads (PyTorch calls them only from metadata inference), and the frozen-delta branch in _retrieve_recv_grads (declared metadata always gives the delta a gradient channel; PyTorch's stage_backward skips outputs that don't require grad).
  • distributed/pipeline_parallel.py (mechanical): build_decoder_stage_io and DecoderStageIO become public, so K3 reuses core's boundary shapes instead of duplicating them.
  • tests/integration_tests/b200.py: [dist_moe] 11/n Support Kimi K3 SiTU-GLU experts #5684's MXFP8 Dist-MoE entry adds PP2 (Interleaved1F1B, 4 microbatches) and becomes FSDP2 + EP2 + CP2 + PP2 on 8 GPUs. With CP2, the PP carriers are CP-local, which checks the static metadata's token count end to end.

Alternatives considered

  • Make core declare static metadata on every backend: that changes PP setup for every model. K3 needs its own carrier shapes regardless.
  • Keep dynamic inference and only bypass Dist-MoE while it runs: it still pays the serial setup pass that timed out at K3 scale.

Numerics

No arithmetic change; the stage only gets metadata it used to infer. test_kimi_k3_pp_block_grads now runs the pipeline with declared metadata, as pipeline_kimi_k3 builds it, with and without the AttnRes cache. Every block gradient and loss matches the single-device reference bitwise, the same check the inferred-metadata runs passed before.

Testing

Check Hardware Result
tests/unit_tests/cpu/models/kimi_k3/, distributed/test_pipeline_parallel.py, models/common/test_dist_moe.py CPU (1 GPU visible) pass
Kimi K3 BF16 Dist-MoE, PP2 Interleaved1F1B, 4 microbatches (local smoke, no FSDP/EP/CP) 2x GB300 completes 4 steps
Integration kimi_k3_dist_moe_fsdp_ep_cp_pp (MXFP8, FSDP2 + EP2 + CP2 + PP2) 8 GPUs not run locally (only 3 free GPUs); relies on CI. Its CP2 part passes in a 2-GPU proxy (see #5684)

New and extended tests and what they catch:

  • test_kimi_k3_pp_block_grads and test_forward_only_eval_between_steps (switched to declared metadata): training and eval match the single-device reference; they fail if any boundary shape or gradient flag is wrong.
  • test_forward_enters_registered_pipeline_context: the stage enters the forward context with the right stage and microbatch index, and stops once its handle is removed.
  • TestStageSwap (extended): the rebuilt stage receives the declared metadata, so dynamic inference is off.

Pre-commit passes on the changed files.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 12, 2026
@shuhuayu
shuhuayu added this pull request to stack #6051 November 12, 2026 03:45
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch from d31f74f to 0dfd3c2 Compare November 17, 2026 08:36
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch from 0dfd3c2 to 19aab00 Compare November 17, 2026 09:31
@shuhuayu shuhuayu added the ciflow/b200 Trigger B200 CI label Nov 17, 2026
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch from 19aab00 to aeb6e3b Compare November 17, 2026 09:35
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch from aeb6e3b to 2e33d6e Compare November 17, 2026 09:50
@shuhuayu

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @shuhuayu's task in 5m 43s —— View job


Approve -- please address the items before merging (delete the now-unreachable dynamic-inference path; a maintainer still needs to review). See the review.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging -- The PR fixes both stated failures inside the K3 folder: K3 now declares static (hidden, delta) metadata, and the AttnRes stage enters the Dist-MoE forward context itself. The remaining item is deleting the dynamic-inference path that this PR makes unreachable. A maintainer still needs to review, since torchtitan/distributed/pipeline_parallel.py makes two of its symbols public.

What this PR does. pipeline_kimi_k3 now builds complete per-stage metadata before it swaps core's stages for AttnResPipelineStage:

  • The first stage takes token IDs as input, and the last stage outputs logits (or hidden states under chunked loss).
  • Every boundary between stages carries hidden_TD plus delta_TND, where N is the number of blocks layout.delta_to_send(i) sends.
  • The token count comes from core's build_decoder_stage_io, so it is CP-local, and also TP-local under sequence parallelism.

With complete metadata, PyTorch skips the serial inference pass. AttnResPipelineStage also stores the Dist-MoE forward-context factory and enters it around the model call in its own forward_one_chunk.

Example.

K3, CP2, 128 tokens per microbatch, PP2 x 2 stages per rank (Interleaved1F1B), Dist-MoE
before: rebuilt stages carry no metadata -> one serial fwd+bwd runs over all
        stages on uninitialized inputs before step 1 (timed out at K3 scale);
        forward_one_chunk never enters Dist-MoE's context -> no activation slot
after:  stage 1 input_args = (hidden_TD[64, D], delta_TND[64, n_0, D]),
        where n_0 = len(layout.delta_to_send(0)); no inference pass;
        model call runs inside ctx(PipelineStageInfo(stage_index=1, microbatch_index=mb))
SP with no decoder layer on stage 0 -> ValueError (the boundary would carry
        TP-replicated embeddings, which the static shape does not describe)

Must fix

  1. tests/unit_tests/cpu/models/kimi_k3/test_kimi_k3_pp_block_grads.py:249 -- Production can no longer reach dynamic inference. Make declared metadata the only mode: delete AttnResPipelineStage._compute_outputs (stage.py:350) and the frozen-delta branch (stage.py:257-264), require the metadata in __init__, and switch the tests to declared metadata instead of adding it as a third and fourth run. Details are in the inline comment.

Should consider

  • torchtitan/models/kimi_k3/pipeline_parallel/stage.py:106 -- Add a TODO with an upstream issue link for the copied register_forward_context, and fix the "same contract" docstring if upstream allows several contexts. Details are in the inline comment.

Questions

  • Any large model running PP on a real process group pays the same serial inference pass that timed out here; it is not specific to K3. Do the maintainers want core to declare static decoder metadata on real process groups too (as a follow-up, not in this PR)?
Details
  • Necessity: Both problems exist on the base branch. Dist-MoE's runtime.py:407 registers its context through stage.register_forward_context, but the base class only enters that context inside the forward_one_chunk that K3 replaces. Real process groups previously always inferred metadata, because core builds stage_io only for the fake backend (pipeline_parallel.py:111).
  • Metadata shapes: I checked them against KimiK3Model.forward and KimiK3TransformerBlock.forward. Non-last stages return (h_TD, block_residual_TND), both in the activation dtype. Mixed precision always applies here, because resolve_fsdp_mesh keeps FSDP even at size 1, so param_dtype is the right dtype. The ValueError for SP when stage 0 has no layer matches the model: h_TD is TP-replicated after embedding. The b200 entry kimi_k3_debugmodel_fsdp2_tp2_ep2_pp2_vpp4 (TP2 + SP) now runs on declared metadata. Its stage 0 still holds 2 layers (17 layers in total, 8 stages), so it does not hit the new error.
  • Mechanical changes: making build_decoder_stage_io/DecoderStageIO public and updating the two callers in test_pipeline_parallel.py.
  • Integration test: extending the existing CP Dist-MoE entry with PP2 (4 -> 8 GPUs) follows rules/tests.md.

Not verified:

  • GPU runs.
  • Whether PyTorch calls _compute_outputs anywhere other than dynamic inference.
  • Whether upstream register_forward_context accepts more than one context.

Comment on lines +249 to +262
cached, cached_sent = self._run_pipeline(split, dtype, cache=True)
naive, naive_sent = self._run_pipeline(split, dtype, cache=False)
# Declared metadata, as pipeline_kimi_k3 builds it, instead of
# inferring it by running the stages.
declared = [
self._run_pipeline(
split, dtype, cache=cache, static_metadata=True
)[0]
for cache in (True, False)
]
self.assertLess(cached_sent, naive_sent)
for step in range(STEPS):
ref_grads, ref_losses = reference[step]
for grads, losses in (cached[step], naive[step]):
runs = (cached, naive, *declared)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR, production never runs dynamic inference. pipeline_kimi_k3 is the only builder of AttnResPipelineStage, and it always passes complete metadata through _swap_in_attn_res_stages. So the inferred-metadata runs here (cached, naive), and all of test_forward_only_eval_between_steps, now test a path that only tests use. They are also the only reason two pieces of production code still exist:

  • AttnResPipelineStage._compute_outputs (stage.py:350-375), which is dynamic inference's forward. It also never enters the Dist-MoE forward context, as the new register_forward_context docstring admits.
  • The frozen-delta branch in _retrieve_recv_grads (stage.py:257-264). It checks outputs_meta[1].requires_grad, which is always True with declared metadata.

This also doubles the work per subtest, from 2 pipeline runs to 4.

Smallest fix: make declared metadata the only mode.

  1. Build stage_metadata unconditionally in _run_pipeline and drop static_metadata, keeping just the cached and naive runs.
  2. Delete _compute_outputs and the frozen-delta branch.
  3. Raise in AttnResPipelineStage.__init__ when input_args/output_args are missing, so nobody can build a stage that would silently run inference without the Dist-MoE context. test_forward_enters_registered_pipeline_context would then pass **_linear_stage_metadata(1)[0].

That is roughly 40 lines removed. If upstream calls _compute_outputs from anything other than dynamic inference (I could not check the installed PyTorch), keep it and say so in a comment.

Comment on lines +106 to +123
def register_forward_context(
self,
context_factory: Callable[[PipelineStageInfo], AbstractContextManager[None]],
) -> RemovableHandle:
"""Wrap each forward of this stage in ``context_factory(info)``.

Same contract as ``PipelineStage.register_forward_context``. PyTorch enters
the context in the ``forward_one_chunk`` this class replaces, so the stage
keeps and enters it itself. Dynamic metadata inference does not enter it;
``pipeline_kimi_k3`` always declares static metadata.
"""
if self._forward_context_factories:
raise RuntimeError(
f"stage {self.stage_index}: a forward context is already registered"
)
handle = RemovableHandle(self._forward_context_factories)
self._forward_context_factories[handle.id] = context_factory
return handle

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copies PipelineStage.register_forward_context only because K3 replaces forward_one_chunk, and that is where PyTorch enters the registered contexts. CLAUDE.md principle 3 asks for a TODO with an upstream issue link here. Two possible upstream fixes: enter the forward context around a public hook that subclasses can keep (for example, the call to forward_maybe_with_nosync), or expose the registered factories. Either one lets this copy be deleted.

Also, the docstring says "Same contract as PipelineStage.register_forward_context", but this version raises on a second registration. If upstream allows several contexts on one stage, that claim is wrong. Either match upstream, or say in the docstring that only one is allowed.

@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch from 2e33d6e to 22d0bdd Compare November 17, 2026 22:30
@shuhuayu
shuhuayu marked this pull request as ready for review November 17, 2026 22:31
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 17, 2026
shuhuayu added a commit that referenced this pull request Nov 20, 2026
Non-final stages send all four residual streams; the final stage owns the
stream mixer, final norm and LM head. Every stage receives original token
IDs and document positions, and the first local model part prepares PLE
routing through a weak reference when an interleaved schedule puts the
table on a later local part.

- Static stage metadata. pipeline_llm takes an optional stage_io, and
  build_decoder_stage_io / DecoderStageIO become public. Flash-Next's
  pipeline() starts from core's decoder boundaries and declares the hidden
  boundary as [T, num_streams * D], so PyTorch skips its metadata-inference
  forward. That forward ran every stage on uninitialized hidden states,
  whose routing could collapse onto a few experts and overflow Dist-MoE's
  scratch. With declared boundaries, PP works with Dist-MoE and on fake
  process groups. A split the static metadata cannot describe raises.
- The rename duplicates #6049's; whichever lands second drops it.
- Remaining bans, at build time: zero-bubble and CSV schedules (under full
  remat the split weight-gradient pass reads the shared MoE routing remat
  region as an unrecomputed placeholder; TODO), multimodal flavors (TODO),
  and a stage split that separates the mixer, norm and LM head.
- The DistMuon policy now works under PP. OptimizersContainer built one
  optimizer per (model part, config) and raised when a pattern matched
  nothing in a part, but the policy's PLE Adam pattern matches only the
  part holding layers.1 and its DistMuon pattern misses a
  tok_embeddings-only part. The container now skips empty (part, config)
  pairs and raises only when a pattern matches nothing on every PP rank:
  one all-reduce over the PP group at build time, and the old local check
  without PP. A fake-PP process holds one stage and skips the check. DistMuon itself already ignores compute layouts for other
  stages and skips empty buckets.

Tests: B200 FSDP2+TP2+SP+EP4+PP2 (all-to-all, AdamW; DistMuon has no TP
support) and FSDP2+EP2+PP2 with the DistMuon policy, Dist-MoE and
accelerator graphs, both Interleaved1F1B with full remat and PLE on a
later local part. A CPU test covers the container's skip-and-raise rule
over two model parts, with and without a PP group.

Numerics (GB300, seed 42, deterministic, shared seed checkpoint):
- FSDP2+TP2+EP4+PP2 against the same config without PP (4 accumulation
  microbatches instead of 4 PP microbatches, same data): step 1 identical
  (loss 7.73923, grad_norm 5.0487); later steps differ only by gradient
  summation order (step 10 loss 5.44578 vs 5.44624).
- Debug Dist-MoE PP tracks all-to-all PP on the same mesh: step-1 loss
  7.73953 vs 7.73918.
- The TP2+SP PP config passes. The 125B recipe at FSDP8+EP8+PP2 gets past
  stage setup, then runs out of memory at step 2 on the PLE-holding stage,
  as the memory model predicts.
shuhuayu added a commit that referenced this pull request Nov 20, 2026
Non-final stages send all four residual streams; the final stage owns the
stream mixer, final norm and LM head. Every stage receives original token
IDs and document positions, and the first local model part prepares PLE
routing through a weak reference when an interleaved schedule puts the
table on a later local part.

- Static stage metadata. pipeline_llm takes an optional stage_io, and
  build_decoder_stage_io / DecoderStageIO become public. Flash-Next's
  pipeline() starts from core's decoder boundaries and declares the hidden
  boundary as [T, num_streams * D], so PyTorch skips its metadata-inference
  forward. That forward ran every stage on uninitialized hidden states,
  whose routing could collapse onto a few experts and overflow Dist-MoE's
  scratch. With declared boundaries, PP works with Dist-MoE and on fake
  process groups. A split the static metadata cannot describe raises.
- The rename duplicates #6049's; whichever lands second drops it.
- Remaining bans, at build time: zero-bubble and CSV schedules (under full
  remat the split weight-gradient pass reads the shared MoE routing remat
  region as an unrecomputed placeholder; TODO), multimodal flavors (TODO),
  and a stage split that separates the mixer, norm and LM head.
- The DistMuon policy now works under PP. OptimizersContainer built one
  optimizer per (model part, config) and raised when a pattern matched
  nothing in a part, but the policy's PLE Adam pattern matches only the
  part holding layers.1 and its DistMuon pattern misses a
  tok_embeddings-only part. The container now skips empty (part, config)
  pairs and raises only when a pattern matches nothing on every PP rank:
  one all-reduce over the PP group at build time, and the old local check
  without PP. A fake-PP process holds one stage and skips the check. DistMuon itself already ignores compute layouts for other
  stages and skips empty buckets.

Tests: B200 FSDP2+TP2+SP+EP4+PP2 (all-to-all, AdamW; DistMuon has no TP
support) and FSDP2+EP2+PP2 with the DistMuon policy, Dist-MoE and
accelerator graphs, both Interleaved1F1B with full remat and PLE on a
later local part. A CPU test covers the container's skip-and-raise rule
over two model parts, with and without a PP group.

Numerics (GB300, seed 42, deterministic, shared seed checkpoint):
- FSDP2+TP2+EP4+PP2 against the same config without PP (4 accumulation
  microbatches instead of 4 PP microbatches, same data): step 1 identical
  (loss 7.73923, grad_norm 5.0487); later steps differ only by gradient
  summation order (step 10 loss 5.44578 vs 5.44624).
- Debug Dist-MoE PP tracks all-to-all PP on the same mesh: step-1 loss
  7.73953 vs 7.73918.
- The TP2+SP PP config passes. The 125B recipe at FSDP8+EP8+PP2 gets past
  stage setup, then runs out of memory at step 2 on the PLE-holding stage,
  as the memory model predicts.
shuhuayu added a commit that referenced this pull request Nov 20, 2026
Non-final stages send all four residual streams; the final stage owns the
stream mixer, final norm and LM head. Every stage receives original token
IDs and document positions, and the first local model part prepares PLE
routing through a weak reference when an interleaved schedule puts the
table on a later local part.

- Static stage metadata. pipeline_llm takes an optional stage_io, and
  build_decoder_stage_io / DecoderStageIO become public. Flash-Next's
  pipeline_flash_next (pipeline_parallel.py) starts from core's decoder
  boundaries and declares the hidden
  boundary as [T, num_streams * D], so PyTorch skips its metadata-inference
  forward. That forward ran every stage on uninitialized hidden states,
  whose routing could collapse onto a few experts and overflow Dist-MoE's
  scratch. With declared boundaries, PP works with Dist-MoE, and stages
  build on fake process groups. A split the static metadata cannot describe raises.
- The rename duplicates #6049's; whichever lands second drops it.
- Remaining bans, at build time: zero-bubble and CSV schedules (under full
  remat the split weight-gradient pass reads the shared MoE routing remat
  region as an unrecomputed placeholder; TODO), multimodal flavors (TODO),
  and a stage split that separates the mixer, norm and LM head.
- The DistMuon policy now works under PP. OptimizersContainer built one
  optimizer per (model part, config) and raised when a pattern matched
  nothing in a part, but the policy's PLE Adam pattern matches only the
  part holding layers.1 and its DistMuon pattern misses a
  tok_embeddings-only part. The container now skips empty (part, config)
  pairs and raises only when a pattern matches nothing on every PP rank:
  one all-reduce over the PP group at build time, and the old local check
  without PP. A fake-PP process holds one stage and skips the check. DistMuon itself already ignores compute layouts for other
  stages and skips empty buckets.

Tests: B200 FSDP2+TP2+SP+EP4+PP2 (all-to-all, AdamW; DistMuon has no TP
support, so the text debug recipe takes an optimizer argument) and
FSDP2+EP2+PP2 with the DistMuon policy, Dist-MoE and accelerator graphs,
both Interleaved1F1B with full remat and PLE on a later local part. A
CPU test covers the container's skip-and-raise rule over two model
parts, with and without a PP group.

Numerics (GB300, seed 42, deterministic, shared seed checkpoint):
- FSDP2+TP2+EP4+PP2 against the same config without PP (4 accumulation
  microbatches instead of 4 PP microbatches, same data): step 1 identical
  (loss 7.73923, grad_norm 5.0487); later steps differ only by gradient
  summation order (step 10 loss 5.44578 vs 5.44624).
- Debug Dist-MoE PP tracks all-to-all PP on the same mesh: step-1 loss
  7.73953 vs 7.73918.
- The TP2+SP PP config passes. The 125B recipe at FSDP8+EP8+PP2 gets past
  stage setup, then runs out of memory at step 2 on the PLE-holding stage,
  as the memory model predicts.
shuhuayu added a commit that referenced this pull request Nov 21, 2026
Non-final stages send all four residual streams; the final stage owns the
stream mixer, final norm and LM head. Every stage receives original token
IDs and document positions, and the first local model part prepares PLE
routing through a weak reference when an interleaved schedule puts the
table on a later local part.

- Static stage metadata. pipeline_llm takes an optional stage_io, and
  build_decoder_stage_io / DecoderStageIO become public. Flash-Next's
  pipeline_flash_next (pipeline_parallel.py) starts from core's decoder
  boundaries and declares the hidden
  boundary as [T, num_streams * D], so PyTorch skips its metadata-inference
  forward. That forward ran every stage on uninitialized hidden states,
  whose routing could collapse onto a few experts and overflow Dist-MoE's
  scratch. With declared boundaries, PP works with Dist-MoE, and stages
  build on fake process groups. A split the static metadata cannot describe raises.
- The rename duplicates #6049's; whichever lands second drops it.
- Remaining bans, at build time: zero-bubble and CSV schedules (under full
  remat the split weight-gradient pass reads the shared MoE routing remat
  region as an unrecomputed placeholder; TODO), multimodal flavors (TODO),
  and a stage split that separates the mixer, norm and LM head.
- The DistMuon policy now works under PP. OptimizersContainer built one
  optimizer per (model part, config) and raised when a pattern matched
  nothing in a part, but the policy's PLE Adam pattern matches only the
  part holding layers.1 and its DistMuon pattern misses a
  tok_embeddings-only part. The container now skips empty (part, config)
  pairs and raises only when a pattern matches nothing on every PP rank:
  one all-reduce over the PP group at build time, and the old local check
  without PP. A fake-PP process holds one stage and skips the check. DistMuon itself already ignores compute layouts for other
  stages and skips empty buckets.

Tests: B200 FSDP2+TP2+SP+EP4+PP2 (all-to-all, AdamW; DistMuon has no TP
support, so the text debug recipe takes an optimizer argument) and
FSDP2+EP2+PP2 with the DistMuon policy, Dist-MoE and accelerator graphs,
both Interleaved1F1B with full remat and PLE on a later local part. A
CPU test covers the container's skip-and-raise rule over two model
parts, with and without a PP group.

Numerics (GB300, seed 42, deterministic, shared seed checkpoint):
- FSDP2+TP2+EP4+PP2 against the same config without PP (4 accumulation
  microbatches instead of 4 PP microbatches, same data): step 1 identical
  (loss 7.73923, grad_norm 5.0487); later steps differ only by gradient
  summation order (step 10 loss 5.44578 vs 5.44624).
- Debug Dist-MoE PP tracks all-to-all PP on the same mesh: step-1 loss
  7.73953 vs 7.73918.
- The TP2+SP PP config passes. The 125B recipe at FSDP8+EP8+PP2 gets past
  stage setup, then runs out of memory at step 2 on the PLE-holding stage,
  as the memory model predicts.
shuhuayu added a commit that referenced this pull request Nov 21, 2026
Non-final stages send all four residual streams; the final stage owns the
stream mixer, final norm and LM head. Every stage receives original token
IDs and document positions, and the first local model part prepares PLE
routing through a weak reference when an interleaved schedule puts the
table on a later local part.

- Static stage metadata. pipeline_llm takes an optional stage_io, and
  build_decoder_stage_io / DecoderStageIO become public. Flash-Next's
  pipeline_flash_next (pipeline_parallel.py) starts from core's decoder
  boundaries and declares the hidden
  boundary as [T, num_streams * D], so PyTorch skips its metadata-inference
  forward. That forward ran every stage on uninitialized hidden states,
  whose routing could collapse onto a few experts and overflow Dist-MoE's
  scratch. With declared boundaries, PP works with Dist-MoE, and stages
  build on fake process groups. A split the static metadata cannot describe raises.
- The rename duplicates #6049's; whichever lands second drops it.
- Remaining bans, at build time: zero-bubble and CSV schedules (under full
  remat the split weight-gradient pass reads the shared MoE routing remat
  region as an unrecomputed placeholder; TODO), multimodal flavors (TODO),
  and a stage split that separates the mixer, norm and LM head.
- The DistMuon policy now works under PP. OptimizersContainer built one
  optimizer per (model part, config) and raised when a pattern matched
  nothing in a part, but the policy's PLE Adam pattern matches only the
  part holding layers.1 and its DistMuon pattern misses a
  tok_embeddings-only part. The container now skips empty (part, config)
  pairs and raises only when a pattern matches nothing on every PP rank:
  one all-reduce over the PP group at build time, and the old local check
  without PP. A fake-PP process holds one stage and skips the check. DistMuon itself already ignores compute layouts for other
  stages and skips empty buckets.

Tests: B200 FSDP2+TP2+SP+EP4+PP2 (all-to-all, AdamW; DistMuon has no TP
support, so the text debug recipe takes an optimizer argument) and
FSDP2+EP2+PP2 with the DistMuon policy, Dist-MoE and accelerator graphs,
both Interleaved1F1B with full remat and PLE on a later local part. A
CPU test covers the container's skip-and-raise rule over two model
parts, with and without a PP group.

Numerics (GB300, seed 42, deterministic, shared seed checkpoint):
- FSDP2+TP2+EP4+PP2 against the same config without PP (4 accumulation
  microbatches instead of 4 PP microbatches, same data): step 1 identical
  (loss 7.73923, grad_norm 5.0487); later steps differ only by gradient
  summation order (step 10 loss 5.44578 vs 5.44624).
- Debug Dist-MoE PP tracks all-to-all PP on the same mesh: step-1 loss
  7.73953 vs 7.73918.
- The TP2+SP PP config passes. The 125B recipe at FSDP8+EP8+PP2 gets past
  stage setup, then runs out of memory at step 2 on the PLE-holding stage,
  as the memory model predicts.
shuhuayu added a commit that referenced this pull request Nov 21, 2026
Non-final stages send all four residual streams; the final stage owns the
stream mixer, final norm and LM head. Every stage receives original token
IDs and document positions, and the first local model part prepares PLE
routing through a weak reference when an interleaved schedule puts the
table on a later local part.

- Static stage metadata. pipeline_llm takes an optional stage_io, and
  build_decoder_stage_io / DecoderStageIO become public. Flash-Next's
  pipeline_flash_next (pipeline_parallel.py) starts from core's decoder
  boundaries and declares the hidden
  boundary as [T, num_streams * D], so PyTorch skips its metadata-inference
  forward. That forward ran every stage on uninitialized hidden states,
  whose routing could collapse onto a few experts and overflow Dist-MoE's
  scratch. With declared boundaries, PP works with Dist-MoE, and stages
  build on fake process groups. A split the static metadata cannot describe raises.
- The rename duplicates #6049's; whichever lands second drops it.
- Remaining bans, at build time: zero-bubble and CSV schedules (under full
  remat the split weight-gradient pass reads the shared MoE routing remat
  region as an unrecomputed placeholder; TODO), multimodal flavors (TODO),
  and a stage split that separates the mixer, norm and LM head.
- The DistMuon policy now works under PP. OptimizersContainer built one
  optimizer per (model part, config) and raised when a pattern matched
  nothing in a part, but the policy's PLE Adam pattern matches only the
  part holding layers.1 and its DistMuon pattern misses a
  tok_embeddings-only part. The container now skips empty (part, config)
  pairs and raises only when a pattern matches nothing on every PP rank:
  one all-reduce over the PP group at build time, and the old local check
  without PP. A fake-PP process holds one stage and skips the check. DistMuon itself already ignores compute layouts for other
  stages and skips empty buckets.

Tests: B200 FSDP2+TP2+SP+EP4+PP2 (all-to-all, AdamW; DistMuon has no TP
support, so the text debug recipe takes an optimizer argument) and
FSDP2+EP2+PP2 with the DistMuon policy, Dist-MoE and accelerator graphs,
both Interleaved1F1B with full remat and PLE on a later local part. A
CPU test covers the container's skip-and-raise rule over two model
parts, with and without a PP group.

Numerics (GB300, seed 42, deterministic, shared seed checkpoint):
- FSDP2+TP2+EP4+PP2 against the same config without PP (4 accumulation
  microbatches instead of 4 PP microbatches, same data): step 1 identical
  (loss 7.73923, grad_norm 5.0487); later steps differ only by gradient
  summation order (step 10 loss 5.44578 vs 5.44624).
- Debug Dist-MoE PP tracks all-to-all PP on the same mesh: step-1 loss
  7.73953 vs 7.73918.
- The TP2+SP PP config passes. The 125B recipe at FSDP8+EP8+PP2 gets past
  stage setup, then runs out of memory at step 2 on the PLE-holding stage,
  as the memory model predicts.
shuhuayu added a commit that referenced this pull request Nov 21, 2026
Non-final stages send all four residual streams; the final stage owns the
stream mixer, final norm and LM head. Every stage receives original token
IDs and document positions, and the first local model part prepares PLE
routing through a weak reference when an interleaved schedule puts the
table on a later local part.

- Static stage metadata. pipeline_llm takes an optional stage_io, and
  build_decoder_stage_io / DecoderStageIO become public. Flash-Next's
  pipeline_flash_next (pipeline_parallel.py) starts from core's decoder
  boundaries and declares the hidden
  boundary as [T, num_streams * D], so PyTorch skips its metadata-inference
  forward. That forward ran every stage on uninitialized hidden states,
  whose routing could collapse onto a few experts and overflow Dist-MoE's
  scratch. With declared boundaries, PP works with Dist-MoE, and stages
  build on fake process groups. A split the static metadata cannot describe raises.
- The rename duplicates #6049's; whichever lands second drops it.
- Remaining bans, at build time: zero-bubble and CSV schedules (under full
  remat the split weight-gradient pass reads the shared MoE routing remat
  region as an unrecomputed placeholder; TODO), multimodal flavors (TODO),
  and a stage split that separates the mixer, norm and LM head.
- The DistMuon policy now works under PP. OptimizersContainer built one
  optimizer per (model part, config) and raised when a pattern matched
  nothing in a part, but the policy's PLE Adam pattern matches only the
  part holding layers.1 and its DistMuon pattern misses a
  tok_embeddings-only part. The container now skips empty (part, config)
  pairs and raises only when a pattern matches nothing on every PP rank:
  one all-reduce over the PP group at build time, and the old local check
  without PP. A fake-PP process holds one stage and skips the check. DistMuon itself already ignores compute layouts for other
  stages and skips empty buckets.

Tests: B200 FSDP2+TP2+SP+EP4+PP2 (all-to-all, AdamW; DistMuon has no TP
support, so the text debug recipe takes an optimizer argument) and
FSDP2+EP2+PP2 with the DistMuon policy, Dist-MoE and accelerator graphs,
both Interleaved1F1B with full remat and PLE on a later local part. A
CPU test covers the container's skip-and-raise rule over two model
parts, with and without a PP group.

Numerics (GB300, seed 42, deterministic, shared seed checkpoint):
- FSDP2+TP2+EP4+PP2 against the same config without PP (4 accumulation
  microbatches instead of 4 PP microbatches, same data): step 1 identical
  (loss 7.73923, grad_norm 5.0487); later steps differ only by gradient
  summation order (step 10 loss 5.44578 vs 5.44624).
- Debug Dist-MoE PP tracks all-to-all PP on the same mesh: step-1 loss
  7.73953 vs 7.73918.
- The TP2+SP PP config passes. The 125B recipe at FSDP8+EP8+PP2 gets past
  stage setup, then runs out of memory at step 2 on the PLE-holding stage,
  as the memory model predicts.
shuhuayu added a commit that referenced this pull request Nov 21, 2026
Non-final stages send all four residual streams; the final stage owns the
stream mixer, final norm and LM head. Every stage receives original token
IDs and document positions, and the first local model part prepares PLE
routing through a weak reference when an interleaved schedule puts the
table on a later local part.

- Static stage metadata. pipeline_llm takes an optional stage_io, and
  build_decoder_stage_io / DecoderStageIO become public. Flash-Next's
  pipeline_flash_next (pipeline_parallel.py) starts from core's decoder
  boundaries and declares the hidden
  boundary as [T, num_streams * D], so PyTorch skips its metadata-inference
  forward. That forward ran every stage on uninitialized hidden states,
  whose routing could collapse onto a few experts and overflow Dist-MoE's
  scratch. With declared boundaries, PP works with Dist-MoE, and stages
  build on fake process groups. A split the static metadata cannot describe raises.
- The rename duplicates #6049's; whichever lands second drops it.
- Remaining bans, at build time: zero-bubble and CSV schedules (under full
  remat the split weight-gradient pass reads the shared MoE routing remat
  region as an unrecomputed placeholder; TODO), multimodal flavors (TODO),
  and a stage split that separates the mixer, norm and LM head.
- The DistMuon policy now works under PP. OptimizersContainer built one
  optimizer per (model part, config) and raised when a pattern matched
  nothing in a part, but the policy's PLE Adam pattern matches only the
  part holding layers.1 and its DistMuon pattern misses a
  tok_embeddings-only part. The container now skips empty (part, config)
  pairs and raises only when a pattern matches nothing on every PP rank:
  one all-reduce over the PP group at build time, and the old local check
  without PP. A fake-PP process holds one stage and skips the check. DistMuon itself already ignores compute layouts for other
  stages and skips empty buckets.

Tests: B200 FSDP2+TP2+SP+EP4+PP2 (all-to-all, AdamW; DistMuon has no TP
support, so the text debug recipe takes an optimizer argument) and
FSDP2+EP2+PP2 with the DistMuon policy, Dist-MoE and accelerator graphs,
both Interleaved1F1B with full remat and PLE on a later local part. A
CPU test covers the container's skip-and-raise rule over two model
parts, with and without a PP group.

Numerics (GB300, seed 42, deterministic, shared seed checkpoint):
- FSDP2+TP2+EP4+PP2 against the same config without PP (4 accumulation
  microbatches instead of 4 PP microbatches, same data): step 1 identical
  (loss 7.73923, grad_norm 5.0487); later steps differ only by gradient
  summation order (step 10 loss 5.44578 vs 5.44624).
- Debug Dist-MoE PP tracks all-to-all PP on the same mesh: step-1 loss
  7.73953 vs 7.73918.
- The TP2+SP PP config passes. The 125B recipe at FSDP8+EP8+PP2 gets past
  stage setup, then runs out of memory at step 2 on the PLE-holding stage,
  as the memory model predicts.
shuhuayu added a commit that referenced this pull request Nov 21, 2026
Non-final stages send all four residual streams; the final stage owns the
stream mixer, final norm and LM head. Every stage receives original token
IDs and document positions, and the first local model part prepares PLE
routing through a weak reference when an interleaved schedule puts the
table on a later local part.

- Static stage metadata. pipeline_llm takes an optional stage_io, and
  build_decoder_stage_io / DecoderStageIO become public. Flash-Next's
  pipeline_flash_next (pipeline_parallel.py) starts from core's decoder
  boundaries and declares the hidden
  boundary as [T, num_streams * D], so PyTorch skips its metadata-inference
  forward. That forward ran every stage on uninitialized hidden states,
  whose routing could collapse onto a few experts and overflow Dist-MoE's
  scratch. With declared boundaries, PP works with Dist-MoE, and stages
  build on fake process groups. A split the static metadata cannot describe raises.
- The rename duplicates #6049's; whichever lands second drops it.
- Remaining bans, at build time: zero-bubble and CSV schedules (under full
  remat the split weight-gradient pass reads the shared MoE routing remat
  region as an unrecomputed placeholder; TODO), multimodal flavors (TODO),
  and a stage split that separates the mixer, norm and LM head.
- The DistMuon policy now works under PP. OptimizersContainer built one
  optimizer per (model part, config) and raised when a pattern matched
  nothing in a part, but the policy's PLE Adam pattern matches only the
  part holding layers.1 and its DistMuon pattern misses a
  tok_embeddings-only part. The container now skips empty (part, config)
  pairs and raises only when a pattern matches nothing on every PP rank:
  one all-reduce over the PP group at build time, and the old local check
  without PP. A fake-PP process holds one stage and skips the check. DistMuon itself already ignores compute layouts for other
  stages and skips empty buckets.

Tests: B200 FSDP2+TP2+SP+EP4+PP2 (all-to-all, AdamW; DistMuon has no TP
support, so the text debug recipe takes an optimizer argument) and
FSDP2+EP2+PP2 with the DistMuon policy, Dist-MoE and accelerator graphs,
both Interleaved1F1B with full remat and PLE on a later local part. A
CPU test covers the container's skip-and-raise rule over two model
parts, with and without a PP group.

Numerics (GB300, seed 42, deterministic, shared seed checkpoint):
- FSDP2+TP2+EP4+PP2 against the same config without PP (4 accumulation
  microbatches instead of 4 PP microbatches, same data): step 1 identical
  (loss 7.73923, grad_norm 5.0487); later steps differ only by gradient
  summation order (step 10 loss 5.44578 vs 5.44624).
- Debug Dist-MoE PP tracks all-to-all PP on the same mesh: step-1 loss
  7.73953 vs 7.73918.
- The TP2+SP PP config passes. The 125B recipe at FSDP8+EP8+PP2 gets past
  stage setup, then runs out of memory at step 2 on the PLE-holding stage,
  as the memory model predicts.
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch from d871371 to dfa481c Compare November 21, 2026 09:48
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch 2 times, most recently from fb99f53 to c6a7865 Compare November 23, 2026 22:43
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch from c6a7865 to 26d8ee6 Compare November 24, 2026 06:52
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch 2 times, most recently from 7dc1c14 to 833279e Compare November 24, 2026 20:57
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch from 833279e to f13cdda Compare November 25, 2026 01:09
@shuhuayu

Copy link
Copy Markdown
Contributor Author

all tests passed since pytorch/pytorch#205562 is now in pytorch nightly, now merge.

Base automatically changed from shuhuayu/k3-dm-stack-11 to main November 25, 2026 08:04
shuhuayu added a commit that referenced this pull request Nov 25, 2026
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
     this approach, and what you checked yourself. -->

Part **11/n** of the Kimi K3 training stack: bottom of a two-PR stack:
this PR -> #6049 (Kimi K3 PP stages).

## Why

Kimi K3's routed experts use bounded SiTU-GLU (`SiTUGLU.Config(beta,
linear_beta)`). `DistMoeTransform` only translates SwiGLU and clamped
SwiGLU, so Kimi K3 cannot use Dist-MoE at all:

```python
config = kimi_k3_debugmodel(...)
apply_transforms(config, [DistMoeTransform()])
# main: TypeError: Dist-MoE supports SwiGLU.Config or ClampedSwiGLU.Config; got SiTUGLU.Config
```

The native Dist-MoE kernels already implement SiTU-GLU
(`activation="situ_glu"`, `situ_glu_gate_beta`, `situ_glu_up_beta`);
only the TorchTitan translation is missing.

## What changed

- `config/transform/dist_moe.py`: translate `SiTUGLU.Config` to
`activation="situ_glu"` with `beta -> situ_glu_gate_beta` and
`linear_beta -> situ_glu_up_beta`. `linear_beta=None` (unbounded up
projection) raises, since the native kernel requires both bounds.
- `dist_moe/routed_experts.py`: add `"situ_glu"` and its two bounds to
`DistMoeRoutedExperts.Config`; validate that each activation sets
exactly its own parameters.
- `dist_moe/runtime.py`: pass the bounds to the native context config.
- `torchtitan_recipes/tests/models/kimi_k3.py`:
`kimi_k3_debugmodel_dist_moe_mxfp8` debug recipe (varlen attention),
used by the integration test below.
- `torchtitan_recipes/dist_moe.py` (mechanical move): `require_dist_moe`
and `dist_moe_runtime_config` move out of
`torchtitan_recipes/models/deepseek_v3.py`, where they were private, so
the Kimi recipes don't import another module's `_private` helpers.
Callers in the DeepSeek V3 recipes and `tests/rl/alphabet_sort.py` are
updated; the bodies are unchanged.
- `tests/integration_tests/b200.py`: Kimi K3 MXFP8 Dist-MoE with FSDP2 +
EP2 + CP2 (4 GPUs, real PG). CP maps KDA to `ContextParallelInnerKDA`
and MLA to `UlyssesMLAAttention`, which keeps the recipe on varlen
attention and needs no load balancer. The vision encoder is not
context-parallel: each CP rank encodes the full image input, as in every
VLM decoder. Type checking stays off, as for the DeepSeek Dist-MoE
entries: the MXFP8 Dist-MoE kernel's autograd function is not registered
with spmd_types (it fails with type checking on). BF16 SiTU-GLU is
covered by the GPU numerics test against the stock experts.
- `tests/integration_tests/b200.py` (reorder only): K3 configs and
entries are grouped together, which moves the two llama3 functions below
them with unchanged bodies.
- `dist_moe/README.md`: document SiTU-GLU support and the Kimi recipe
location.

## User-facing changes

| Before | After |
| --- | --- |
| `DistMoeTransform` rejects `SiTUGLU.Config` | Translated to native
`situ_glu`, BF16 and MXFP8 |
| No Kimi K3 Dist-MoE recipe | `kimi_k3_debugmodel_dist_moe_mxfp8` |

## Numerics

No change to existing activations. New SiTU-GLU path vs stock experts
(`test_bf16_matches_stock_situglu`, real EP2 on 2 GPUs): output and the
four gradient families (input, scores, W13, W2) match at the existing
BF16 tolerance. The test uses bounds (0.25, 0.1) that saturate tanh at
its input scale; with Kimi's (4.0, 25.0), tanh is nearly linear there
and SiTU-GLU would be indistinguishable from SwiGLU. Giving only the
native side (4.0, 25.0) makes 96% of output elements mismatch.

## Testing

Run with an env that has the `dist_moe` package (without it the Dist-MoE
tests are skipped).

| Check | Hardware | Result |
| --- | --- | --- |
| `tests/unit_tests/cpu/models/common/test_dist_moe.py` | CPU (1 GPU
visible, for the MXFP8 capability check) | pass |
| `tests/unit_tests/gpu/models/common/test_dist_moe.py` | 2x GB300 | 4
passed, including the new SiTU-GLU case |
| Integration `kimi_k3_dist_moe_fsdp_ep_cp` (MXFP8, FSDP2 + EP2 + CP2) |
4 GPUs | not run locally (only 3 free GPUs); relies on CI |
| MXFP8 recipe with CP2 + EP2 sharing the CP axis (2-GPU proxy of the CI
entry) | 2x GB300 | completes 4 steps |
| MXFP8 recipe with FSDP2 + EP2 (the previous CI entry) | 2x GB300 |
completes 4 steps |

New tests and what they catch:
- `test_transform_preserves_situglu_configuration`: both expert
precisions carry the model's bounds into the native config. It uses
bounds other than the annex defaults (4.0, 25.0), so a bound dropped
anywhere on the way fails.
- `test_transform_rejects_unbounded_situglu_up_projection`: an unbounded
SiTU-GLU fails at transform time instead of silently changing math.
- `test_bf16_matches_stock_situglu` (GPU): native SiTU-GLU, with bounds
that saturate tanh, matches the stock implementation; it fails if the
kernel ignores either bound.

Pre-commit passes on the changed files.
@shuhuayu
shuhuayu force-pushed the shuhuayu/k3-dm-stack-11-pp branch from f13cdda to 1654ea9 Compare November 25, 2026 08:04
@shuhuayu
shuhuayu merged commit 8919259 into main Nov 25, 2026
27 of 29 checks passed
shuhuayu added a commit that referenced this pull request Nov 26, 2026
## Summary (human-written)

Part **14/n** of the Kimi K3 training stack. Independent PR on `main`:
the
pieces it composes are all on `main` now (SiTU-GLU Dist-MoE #5684, Kimi
K3
Dist-MoE pipeline stages #6049, per-block remat #6104).

## Why

TorchTitan has Kimi K3 debug recipes only. There is no recipe that runs
the
full 93-layer model with Dist-MoE, DistMuon and pipeline parallelism
together,
so the configuration used for full-scale throughput runs lives outside
the
repo.

## What changed

`torchtitan_recipes/models/kimi_k3.py` adds one text-only 4K MXFP8
recipe:

| Recipe | Hardware | PP / VPP / EP / FSDP | Microbatches / update |
Tokens / update |
| --- | --- | --- | ---: | ---: |
| `kimi_k3_dist_moe_mxfp8_gb200_512` | 512 GB200 | 8 / 1 / 64 / 64 | 64
| 16,777,216 |

- FP32 parameters, gradients and optimizer state with BF16 compute
views; only
routed-expert GEMMs use MXFP8 (Dist-MoE). Interleaved1F1B with one
explicit
  chunk per rank (seven 12-layer chunks and a final 9-layer chunk),
  CUDA-graph forward/backward, DistMuon, FSDP
  parameters kept unsharded across forward/backward.
- Expert routing uses core's `RoundRobinTokenChoiceTopKRouter`, so this
is a
**throughput recipe, not learned-router training**; gate scores and
their
  gradients stay learned. KDA uses core's default kernel selection.
- `torchtitan/models/kimi_k3/README.md`: a short "Full-Scale Recipe"
section
  with measured throughput for forced and learned routing.
- The K3 DistMuon optimizer builder moves from the K3 debug recipe to
`torchtitan_recipes.models.kimi_k3.dist_muon_optimizer` and is
simplified
(one layout helper, one table per layer type, one pass over layers); the
K3
and K3.1 debug recipes and the GPU test import it from there. The
full-scale
  recipe keeps its own private copy of the expert compute layout helper
  instead of importing it from the K2.7 debug recipe.
- CI: the B200 job, which installs Dist-MoE, also runs the recipe-build
test
(`test_full_recipe_selects_dist_moe_before_graph_validation`); it skips
  wherever Dist-MoE is not installed.

## Numerics

No change to existing recipes. The simplified optimizer builder produces
identical optimizer configs (Muon pattern, learning rates, ordered
buckets and
ordered per-FQN compute layouts) for the K3 debug, K3 debug MXFP8, K3.1
debug
and full-scale recipes, and for the debug model at EP=1 and EP=2.

## Testing

| Check | Result |
| --- | --- |
| `tests/unit_tests/cpu/recipes/test_kimi_dist_moe.py` (Dist-MoE
selection before graph validation) | pass |
| `tests/unit_tests/cpu/models/kimi_k3/` | pass |
| `tests/unit_tests/gpu/models/kimi_k3/test_kimi_k3.py -k dist_muon` (1
GPU) | pass |
| Kimi K2.5 / K3 / K3.1 debug recipes and the 512-GPU recipe build |
pass |

The README's forced-routing row (1,009.5 tokens/s/GPU, 651.44 model
TFLOP/s/GPU,
158.41 GiB maximum reserved, twelve updates on 512 GB200) was measured
with
this recipe. The learned-routing row (971 tokens/s/GPU, 626.52 model
TFLOP/s/GPU) used Kimi K3's default router with Dist-MoE scratch
capacity 2.0.
anijain2305 added a commit to anijain2305/torchtitan that referenced this pull request Nov 30, 2026
…rops the local PP forward-context fix in favor of it)

# Conflicts:
#	torchtitan/models/kimi_k3/pipeline_parallel/stage.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants