Skip to content

Activation offload: reload after FSDP2's parameter copy-in - #6137

Merged
anijain2305 merged 1 commit into
activation-offloadfrom
activation-offload-fsdp-order
Nov 19, 2026
Merged

anijain2305 merged 1 commit into
activation-offloadfrom
activation-offload-fsdp-order

Conversation

@anijain2305

@anijain2305 anijain2305 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Depends on pytorch/pytorch#205180 (FSDPModule.get_all_gather_copy_in_stream).
Stacked on #6022.

Why

With FSDP2 CPU parameter offload, block i's backward boundary queues two
host-to-device copies for block i - 1: FSDP2's pre-backward queues its
parameter shards on all_gather_copy_in_stream, then the reload trigger
queues its activations on the reload stream. Both become ready when block
i's copy-out finishes and share the link's bandwidth in no defined order.
The parameters still need the all-gather after their copy; the activations
need nothing more. So when the copies do not fit in block i's backward,
sharing is the worst order: both finish after (P + A) / BW, and only then
does the all-gather start. Parameters first lets the all-gather overlap the
activation copy, saving up to min(all-gather, A / BW).

Before -> after, at the block i boundary (FSDP2 default streams):

Shard H2D (block i-1) Activation H2D (group i-1) All-gather (block i-1) starts
before starts after copy-out (i), shares bandwidth starts after copy-out (i), shares bandwidth after both copies
after starts after copy-out (i), alone starts after the shard H2D and pack after the shard H2D, overlapping the reload

FSDP2 default streams at a backward block boundary

What changed

  • ActivationOffloader._reload also waits on
    model_part.get_all_gather_copy_in_stream() when the model part is an
    FSDP2 module. The hook order makes this precise: FSDP2's pre-backward (a
    tensor hook on out_i) has queued block i - 1's copy-in just before the
    reload trigger (a pre-hook on out_i.grad_fn) runs. The stream is read at
    reload time, after FSDP2's lazy initialization in the first forward.

  • Under fsdp_unshard_in_current_stream or a single rank, FSDP2 runs the
    copy-in on the compute stream, which the reload already waits on, and the
    copy-in stream is idle, so the new wait changes nothing there:

    FSDP2 unshard_in_current_stream at a backward block boundary

  • Without CPU offload the copy-in is only a GPU-to-GPU pack kernel, so the
    reload starts after that short kernel too.

  • ACTIVATION_OFFLOAD.md: the FSDP2 section describes the ordering, with both
    diagrams (assets/images/activation_offload_fsdp_streams*.png); the TODO is
    gone.

Alternatives considered

  • Issue reloads on FSDP2's copy-in stream (an earlier version of Activation offloading on torch_remat saved-tensor hooks #6020):
    same-stream FIFO would make FSDP2's next copy-in queue behind a long reload.
  • An event recorded right after the shard H2D: tighter (skips the pack), but
    needs FSDP2 to record it inside copy-in.

Numerics

Ordering only; loss and gradients are unchanged. The FSDP2 CPU-offload test
checks gradients bitwise against no activation offload.

Testing

tests/unit_tests/gpu/distributed/test_activation_offload.py and
test_activation_checkpoint.py (36 tests, GB300), run against PyTorch main's
FSDP2 with pytorch/pytorch#205180 applied:

  • The FSDP2 CPU-offload test (2 ranks) records the reload stream's waits:
    every reload waits on FSDP2's copy-in stream as well as the compute stream
    (fails without the change).

Not run: an end-to-end recipe with FSDP2 CPU offload measuring the overlap.
Until pytorch/pytorch#205180 reaches a nightly, CI's Pyrefly and this test
fail on the missing method.

@anijain2305
anijain2305 added this pull request to stack #6105 November 16, 2026 22:28
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 16, 2026
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch from 59a94d2 to 5de7473 Compare November 17, 2026 18:35
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch 3 times, most recently from 4a528d6 to 7a01d85 Compare November 17, 2026 20:17
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch from 7a01d85 to aaf543f Compare November 18, 2026 21:27
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch from aaf543f to fc820e7 Compare November 18, 2026 21:38
@anijain2305
anijain2305 removed this pull request from stack #6105 November 18, 2026 21:38
@anijain2305
anijain2305 changed the base branch from activation-offload-pp to activation-offload November 18, 2026 21:41
@anijain2305
anijain2305 added this pull request to stack #6191 November 18, 2026 21:41
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch from fc820e7 to f68d48a Compare November 19, 2026 00:12
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch from f68d48a to f5f4355 Compare November 19, 2026 00:49
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch 2 times, most recently from 29d8fdf to 99cebf1 Compare November 19, 2026 01:22
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch from 99cebf1 to d8dd3aa Compare November 19, 2026 06:21
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch from d8dd3aa to 4d2e426 Compare November 19, 2026 06:40
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 19, 2026
@anijain2305
anijain2305 force-pushed the activation-offload-fsdp-order branch from 4455a01 to 962505e Compare November 19, 2026 21:37
@tianyu-l

Copy link
Copy Markdown
Contributor

@claude review

@claude

claude Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 3m 15s —— View job


Approve -- please address the items before merging (two wording fixes in the PR description and a docstring, plus doc-contract suggestions). 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 change is an 8-line stream wait that follows the FSDP2 hook order correctly and removes the TODO now that the upstream API exists; the remaining items are wording fixes.

What this PR does. Before queuing a reload, ActivationOffloader._reload now also waits on FSDP2's all-gather copy-in stream. FSDP2's pre-backward for block i (a tensor hook on out_i) queues block i - 1's parameter H2D on that stream. The reload trigger (a node pre-hook on out_i.grad_fn) always runs after it. So the activation H2D for group i - 1 goes after the shard H2D instead of competing with it for link bandwidth. The stream is read through the new public FSDPModule.get_all_gather_copy_in_stream(). pytorch/pytorch#205180 landed through ghstack (shows as closed; mergebot reported merge success).

Example. Block i's backward boundary, FSDP2 CPU offload, default streams:

before: copy-out(i) -> [shard H2D(i-1) || act H2D(i-1)] share BW -> both done at (P+A)/BW -> all-gather(i-1)
after:  copy-out(i) -> shard H2D(i-1) -> pack -> act H2D(i-1)
                                              \-> all-gather(i-1)   (overlaps the act H2D)

Without CPU offload, the reload only moves behind the copy-in kernel (pack plus param_dtype cast). Under fsdp_unshard_in_current_stream, the compute-stream wait already covers everything the new wait orders after.

Must fix

  1. PR description -- it says "The stream is read at reload time, after FSDP2's lazy initialization in the first forward". The code caches it in _model_part_pre_forward (activation_offload.py:448) and reads the cached value in _reload. Update the description to match.
  2. torchtitan/distributed/activation_offload.py:714 -- the edited docstring line isn't rewrapped (~120 columns). Inline suggestion attached.

Should consider

  • torchtitan/distributed/ACTIVATION_OFFLOAD.md:287-289 -- "or a single rank" and "the copy-in stream is idle" overstate the contract (inline). The same goes for the comment at activation_offload.py:768.
  • Perf evidence -- the gain is only argued from a diagram. One profiler trace from an FSDP2 CPU-offload run, showing the all-gather for block i - 1 starting before the activation H2D finishes, would confirm the overlap. It's cheap to add once the API reaches a nightly.
Details
  • Hook order: FSDP2's _register_pre_backward_hook uses Tensor.register_hook (step 1). The trigger is grad_fn.register_prehook (step 3). So FSDP2's prefetch of block i - 1 on all_gather_copy_in_stream (the PRE_BACKWARD implicit-prefetch path) is always queued before the reload's wait_stream, whatever the registration order. This also holds for torchtitan's explicit set_modules_to_backward_prefetch([prev_block]) in distributed/fsdp.py:615, which prefetches a single block.
  • Lazy init timing: fully_shard prepends its root pre-forward, so it runs before _model_part_pre_forward, and the stream exists when it is read. All FSDP states under one root share the root's comm context, so the root's stream is the one block i - 1 uses.
  • PP: each model part is its own FSDP root with its own comm context and its own offloader, so each reload waits on the stream of the right root. The upstream review's share_comm_ctx staleness concern (a later root's lazy init replaces the shared stream) doesn't apply: torchtitan doesn't call share_comm_ctx. Even if it did, the stream is re-read at every model-part forward, so only the first step could wait on a stale stream, which costs performance but not correctness.
  • Test: the extended FSDP2 CPU-offload test asserts that exactly half of the reload stream's waits are on the copy-in stream. That guards the ordering invariant, which would otherwise regress silently. It reuses the existing 2-rank test rather than adding a new one.

Not verified: the GPU test run and the overlap gain (no GPU here).

Comment on lines +714 to 715
stream, see _reload), queues behind it. Queued first, the reload could hold that copy, and block ``i``'s backward,
in the copy engine (H100, pytorch/torchtitan#467). A module backward

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 docstring edit didn't get rewrapped. Line 714 is about 120 columns, while the rest of the docstring wraps near 76. B950 allows up to 132, so CI won't flag it. Rewrapped:

Suggested change
stream, see _reload), queues behind it. Queued first, the reload could hold that copy, and block ``i``'s backward,
in the copy engine (H100, pytorch/torchtitan#467). A module backward
stream, see _reload), queues behind it. Queued first, the reload
could hold that copy, and block ``i``'s backward, in the copy engine
(H100, pytorch/torchtitan#467). A module backward

Comment on lines +286 to +289
Under `set_unshard_in_current_stream` (TorchTitan's
`fsdp_unshard_in_current_stream`) or a single rank, FSDP2 runs the copy-in
on the compute stream, so the compute-stream wait already orders the reload
after the parameters, and the copy-in stream is idle:

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.

Two parts of this contract are worded more strongly than the code supports. The automated review on pytorch/pytorch#205180 raised the same two points against the upstream docstring.

  • "or a single rank": FSDP2 skips foreach_all_gather per param group whenever the parameters aren't sharded: a shard group of size 1, which includes HSDP with shard size 1, or a replicate() module at any world size. The rank count isn't the condition.
  • "the copy-in stream is idle": in this mode the copy-in stream still waits on the compute stream at root pre-forward, and on every copy-out event. So the wait isn't free in principle. It adds no ordering only because the reload already waits on the compute stream, which is a superset.

Suggested wording: "...fsdp_unshard_in_current_stream) or when parameters are not sharded, FSDP2 runs the copy-in on the compute stream. The reload's compute-stream wait already orders it after the parameters, and the extra wait on the copy-in stream adds nothing." The same applies to "An idle-stream wait" in the comment at activation_offload.py:768 and to the PR description.

@anijain2305
anijain2305 merged commit 2377d43 into main Nov 19, 2026
21 of 25 checks passed
fegin added a commit that referenced this pull request Nov 20, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (pinned_host_moment_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020).

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Nov 20, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (pinned_host_moment_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020).

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Nov 23, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020).

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Nov 23, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020).

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Nov 23, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020).

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
tianyu-l added a commit that referenced this pull request Nov 26, 2026
…er override; agent self-review; rl/transport (#6407)

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
     this approach, and what you checked yourself. -->

## Why

Since #5667, `@claude review` has reviewed 459 PRs. Of the 380 PRs it
approved,
30 then got a formal "request changes" from a maintainer, and about 20
more got
substantive inline asks. In nearly all of them the bot either saw the
problem
and approved anyway, or never asked the questions maintainers ask most
("does
the repo already do this?", "who should own this?"). The opposite
failure, the
bot blocking something a maintainer was fine with, is rare: in the PRs
we
sampled, 2 of its 81 must-fix items were wrong and about a third were
minor
(the empty human-written summary was the biggest source).

**Example** (#6112, controller sizes the rollout worker pool):

```
before: bot approved 10 times; tianyu-l then blocked: "the controller reads
        rollouter.rollouts_per_worker to compute a count it hands back to the
        Rollouter -- violates encapsulation"
after:  same commit, new skill -> Request changes, must-fix #1:
        "controller.py:589 -- wrong owner for the worker count ..."
```

There was also no way for a code owner to overrule the bot except
dismissing
its review in the GitHub UI, and a later `@claude review again` would
block
again.

## What changed

**Review skill** (`.claude/skills/pr-review/`, `review-checklist.md`):
- Verdict rules: Approve only when every remaining item is an edit the
bot
could write itself. Anything the author still owes (a design change, an
unexplained golden change, evidence the PR rests on) is Request changes;
anything only a maintainer can decide is Needs discussion. A hedge like
"a
  maintainer should decide" can't come with Approve.
- Always must-fix: a violated written rule, a silent wrong result, a
second
  definition of an existing concept, a gate finding.
- Design gate: new questions for the existing counterpart, in-repo
ownership,
and the design behind a bug; "ban only what doesn't work on main"; read
the
numbers behind a claim. The overlapping-PR search is mandatory and
reported.
- Re-review covers every commit since the last full review, including
code
taken from the bot's own suggestions. A scoped question gets a
`COMMENT`, not
  a whole-PR verdict.
- The bot fact-checks its own proposed fixes, and cites a source for
claims
  about external tools or marks them unverified (never must-fix).
- An empty "Summary (human-written)" is a one-line "Before merge" note
that
  never affects the verdict.
- Checklist: config ownership direction, general shared wrappers, dead
code the
PR creates, model variants as flavors, a mechanical pass over every new
or
  changed function.

**Code owner override** (`SKILL.md`, `claude-code.yml`,
`CONTRIBUTING.md`): a
code owner comments `@claude override` (optionally `@claude override
2,3:
<reason>`); the bot approves if nothing else is open and doesn't
re-raise the
overridden items. A code owner's GitHub approval or "LGTM" is not an
override,
so a teammate can approve without the bot dropping its findings.
Dismissing the
bot's review still unblocks the PR, but isn't an override: the bot can't
tell
who dismissed it.

**Agent self-review** (`CLAUDE.md`, `pr-description`): an agent
preparing a PR
runs `pr-review` in branch mode first and records unaddressed items in
an
optional "Self-review" section. PRs written without an agent are
unaffected; a
missing section is never a finding.

Where each new rule comes from (maintainer asks the bot missed):

| Change | PRs |
| --- | --- |
| No Approve with open design/evidence items or a "maintainer should
decide" hedge | #6007, #5837, #5997, #5712, #5511, #5996 |
| Author waiver can't clear a must-fix | #6201, #6202, #6203 |
| Existing counterpart; one source of truth | #5228, #6169, #5881,
#5823, #5824, #6059, #5812 |
| Responsibility owner; config ownership direction | #6112, #6332,
#5802, #5803, #6325 |
| Fix the design behind the bug; a TODO doesn't justify a workaround |
#5572, #5689, #5657 |
| Fact-check the bot's own suggested fixes | #5740, #5802, #5511, #4819,
#5543 |
| Re-review covers all new commits; scoped asks don't approve | #5824,
#5842 |
| Mandatory overlap search | #5885, #6248 |
| Ban only what doesn't work on main | #5543 |
| Summary placeholder no longer a must-fix | #6119, #6174, #6112, #5868
|

**Rules**: `design.md` gets the one-general-wrapper rule (moved from
`models.md`, whose glob skipped `torchtitan/rl`), thin adapters, and the
consumer owning its values; `config.md` gets ownership direction and "a
Config
doesn't read runtime state"; `direction.md` calls all-to-all the MoE
reference
implementation, so a new vendor-specific dispatch path (e.g. #6242)
needs a
reason the existing backends can't serve.

**Area reviewers**: `.ci/` -> huydhn, wwwjn; `torchtitan/rl/transport/`
-> d4l3k.

**Mechanical, skim**: `torchtitan/rl/transport/` holds data movement
between RL
actors.
- `rl/model_state_dict_transport.py` ->
`rl/transport/model_state_dict.py`
- `rl/MODEL_STATE_DICT_TRANSPORT.md` ->
`rl/transport/MODEL_STATE_DICT_TRANSPORT.md`
- `rl/trainer/rdma_microbatch.py` -> `rl/transport/rdma_microbatch.py`
- tests:
`tests/rl/unit_tests/cpu/test_{model_state_dict_transport,rdma_microbatch}.py`
->
`tests/rl/unit_tests/cpu/transport/test_{model_state_dict,rdma_microbatch}.py`
- imports, READMEs and `scripts/install_rl_env.sh` updated; no code
changes.

## User-facing changes

| Before | After |
| --- | --- |
| Overrule the bot: dismiss its review in the UI, and it blocks again on
the next run | `@claude override [items]: <reason>`; the bot approves
and doesn't re-raise them |
| Empty human-written summary: bot must-fix | One "Before merge" line,
no effect on the verdict |
| `from torchtitan.rl.model_state_dict_transport import ...` | `from
torchtitan.rl.transport.model_state_dict import ...` |
| `from torchtitan.rl.trainer.rdma_microbatch import ...` | `from
torchtitan.rl.transport.rdma_microbatch import ...` |

## Testing

Backtest: the new skill run locally (nothing posted) on each PR at the
commit
and thread state the bot originally saw.

| PR | Bot then | New skill | What the maintainer asked |
| --- | --- | --- | --- |
| #6112 | Approve | Request changes | worker-count ownership (caught) |
| #5837 | Approve | Request changes | apply to `dp_shard` too (caught) |
| #5572 | Approve | Request changes | delete the injection design
(caught) |
| #6201 | Approve after author waived pins | Request changes, waiver
ignored | pins broke GPU tests after merge (caught) |
| #6007 | Approve | Request changes | fold K3.1 into K3 (caught) |
| #5543 | Request changes: "ban it" | Request changes: keep main's path
| don't break gpt-oss + DeepEP (fixed) |
| #6144, #5905 (controls) | Approve | Approve | -- |
| #6137 (control) | Approve | Needs discussion | -- (merge gate on an
upstream API) |

Code owner override, simulated on #6201: override by a code owner lifts
the
named item; `@claude override` from the author changes nothing; a code
owner's
"LGTM" approval followed by "review again" keeps Request changes.

Transport move: 83 RL CPU unit tests pass locally
(`transport/test_model_state_dict.py`, `test_trainer.py`,
`test_engine_loop.py`). `transport/test_rdma_microbatch.py`,
`test_generator.py` and
`test_batcher_actor.py` fail to collect in my env on `origin/main` too
(stale
attention-gym / Monarch), so CI is the check for those.

## Known issues / follow-ups
- Open PRs that edit the moved files rebase cleanly (git follows the
renames),
but new imports of the old module paths will break: #6309 (adds a delta
transport that should live in `rl/transport/`), #6237, #6176, #6177,
#5862,
  and drafts #6127, #6393, #6163, #5764.
- The Actions bot can't read dependency source (e.g. SGLang); follow-up
for the
  workflow.

## Self-review
pr-review (branch mode) at ad905a5: Needs discussion. Fixed: branch
mode diffs
against `origin/main` and skips description findings before a
description
exists; the "Config doesn't read runtime state" rule no longer
contradicts
hardware validation; dismissal dropped as an override form (the bot
can't tell
who dismissed); `test_rdma_microbatch.py` added to the transport area.
Not
addressed:
- One concern per PR -- the five changes ship together at the
maintainer's
  request.
- Open PRs touching the moved files -- listed above; the maintainer will
  coordinate.
fegin added a commit that referenced this pull request Nov 30, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020). These runs used `max_num_documents=64`. #5882 raises it to 128, which removes the padding (10.7% of the tokens on C4) and lowers the reported tps, because tps counts padding tokens.

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Nov 30, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020). These runs used `max_num_documents=64`. #5882 raises it to 128, which removes the padding (10.7% of the tokens on C4) and lowers the reported tps, because tps counts padding tokens.

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Dec 1, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020). These runs used `max_num_documents=64`. #5882 raises it to 128, which removes the padding (10.7% of the tokens on C4) and lowers the reported tps, because tps counts padding tokens.

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Dec 1, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020). These runs used `max_num_documents=64`. #5882 raises it to 128, which removes the padding (10.7% of the tokens on C4) and lowers the reported tps, because tps counts padding tokens.

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Dec 1, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020). These runs used `max_num_documents=64`. #5882 raises it to 128, which removes the padding (10.7% of the tokens on C4) and lowers the reported tps, because tps counts padding tokens.

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Dec 2, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020). These runs used `max_num_documents=64`. #5882 raises it to 128, which removes the padding (10.7% of the tokens on C4) and lowers the reported tps, because tps counts padding tokens.

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
fegin added a commit that referenced this pull request Dec 2, 2026
…ctivation offload

## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
     this approach, and what you checked yourself. -->

## Why
Our fastest Muse Spark 816B runs on 64 GPUs cannot be reproduced from the repo. They start from the 64-GPU recipe and change it in an out-of-tree launcher: layout, forced routing, Dist-MoE budgets, remat and offload policy, Adam moment placement, the optimizer CUDA graph, and FSDP symmetric memory. The launch environment and the dependency versions are not written down anywhere either.

The 64-GPU recipe also all-gathers the K/V of the full 32K sequence in every layer. The sliding-window varlen layers (46 of 62 layers, 2048-token window) read only the blocks inside their window, so most of that K/V is never used.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64, then the launcher sets
        DP32/CP2, forced routing, scratch 2, slot factor 0, remat p3,
        offload attention + MoE projections, moments on GPU, optimizer graph,
        FSDP symmetric memory, c4_test, 100 steps
after:  --module torchtitan_recipes.models.muse_spark \
        --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```

## What changed
- The Muse K/V-gather CP transform maps `SlidingWindowVarlenInnerAttention` to `SelectiveGatherKVSlidingWindowVarlenInnerAttention`. Global layers keep `AllGatherKVVarlenInnerAttention`. This applies to every 64-GPU recipe.
- The Muse save region becomes `attention.inner_attention*`, so the selective-gather assembly region nested in attention is saved with it. torch_remat rejects a recomputed region inside a saved one. The 256- and 512-GPU and UltraData recipes have no region nested in attention, so the wildcard does not change them.
- `_muse_spark_816b_dist_moe_spmd_64` takes `context_parallel_degree`; FSDP gets the other 64 / CP ranks. The existing 64-GPU recipes pass 8, as before.
- New `muse_spark_816b_a42b_dist_moe_{bf16,mxfp8}_spmd_64_benchmark` recipes and their `_fake` variants. They are benchmark only: forced balanced routing does not train a usable model.

| Setting | BF16 | MXFP8 |
| --- | --- | --- |
| layout | DP32, CP2, EP64, 2 microbatches per step | same |
| routing | forced balanced (round robin) | same |
| Dist-MoE | scratch_capacity_factor 2, activation_slot_capacity_factor 0 | same |
| remat save regions | Dist-MoE defaults + `attention.*` | + pooler, unpooler, router |
| activation offload | block input + `attention.*`, not in the last block | + pooler, unpooler, router |
| Adam moments | GPU (moment_cpu_offload_fraction 0.0) | same |
| CUDA graphs | per microbatch group + optimizer graph | same |
| FSDP symmetric memory | scope all (off in `_fake`) | same |
| data | c4_test, random init, 100 steps (10 in `_fake`) | same |

- The benchmark docstring lists the launch environment (`NCCL_NVLS_ENABLE=1`, `PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1`, one NVLink domain per CP group, skipping `destroy_process_group`) and the dependency versions.

## Dependencies
- PyTorch nightly from 2026-11-20 or later. Activation offload on main calls `FSDPModule.get_all_gather_copy_in_stream` (pytorch/pytorch#205180).
- Depends on meta-pytorch/attention-gym#651 (selective gather); the attention-gym pin bump lands separately.

## How to reproduce
Stage the Muse Spark Open tokenizer files at `./assets/hf/Muse-Spark-Open-816B-A42B`, then on each of 16 hosts (4 GPUs each, all in one NVLink domain):
```bash
NCCL_NVLS_ENABLE=1 PYTORCH_ALLOC_CONF=pinned_max_round_threshold_mb:1 \
  torchrun --nnodes 16 --nproc-per-node 4 --node-rank <i> \
  --master-addr <host 0> --master-port 29500 -m torchtitan.train \
  --module torchtitan_recipes.models.muse_spark \
  --config muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark
```
Use `..._bf16_spmd_64_benchmark` for BF16. Measure tps as the mean of steps 71-90.

## Numerics
No model or kernel change. Forced routing makes the loss meaningless for training quality; it is only a run-to-run check.

The benchmark recipes build the same effective config as the launcher-built reference runs, field by field, except: `offload_last_block=False` in the reference runs, which #6020 removed (the recipes keep the last block on GPU with a `BlockRematOverride`, the same per-block offload plan), the new `per_sample_pad_multiple=1` dataloader default from main, main's RoPE `scaling='none'` -> `scaling=None` refactor, the launcher's profiler settings, and the tokenizer path.

100-step runs on 64 GPUs vs the reference runs of the same precision:

| Recipe | Mean / max abs loss diff | Loss at step 100 (new / reference) |
| --- | --- | --- |
| BF16 | 0.0017 / 0.0057 | 6.92717 / 6.92149 |
| MXFP8, run 1 | 0.0034 / 0.0086 | 6.94351 / 6.95157 |
| MXFP8, run 2 | 0.00025 / 0.0012 | 6.95231 / 6.95157 |

The two MXFP8 runs of this recipe differ from each other by 0.0035, so the run 1 gap is run-to-run noise. Step 1 matches the references exactly, and step-1 and step-2 peak memory match to 0.01 GiB.

## Performance
64 GB300 GPUs (16 nodes x 4), 100 steps. tps and TFLOPs are per GPU as logged by torchtitan, mean of steps 71-90. These runs used the launcher-built reference config, which matches these recipes field by field (see Numerics), on an earlier revision of this stack and of activation offload (#6020). These runs used `max_num_documents=64`. #5882 raises it to 128, which removes the padding (10.7% of the tokens on C4) and lowers the reported tps, because tps counts padding tokens.

| Recipe | tps | TFLOPs |
| --- | ---: | ---: |
| `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_benchmark` | 5,166 | 1,691 |
| `muse_spark_816b_a42b_dist_moe_bf16_spmd_64_benchmark` | 3,869 | 1,267 |

Forced balanced routing makes these benchmark numbers, not real-training numbers.

## Testing
- `pytest tests/unit_tests/cpu/recipes`: the new recipes build; the MLA override tests also pass when run alone.
- Config build of all four benchmark recipes, diffed field by field as above.
- FakePG, logical 64 GPUs, rank 0, 10 steps, both `_fake` recipes: MXFP8 step-2 peak 239.52 allocated / 252.68 reserved GiB, the same as an earlier FakePG run of this config. Activation offload moves 124.73 GiB (MXFP8) and 100.90 GiB (BF16) per forward, the same as the reference real runs.
- 64 GPUs, 100 steps, both precisions (MXFP8 twice): all ranks exit 0; numerics above.

## Known issues / follow-ups
- The numbers predate #6137 (activation reloads wait on FSDP2's copy-in stream). Its effect on these recipes is not measured.
- torchtitan does not check that a CP group sits in one NVLink domain.
- With FSDP symmetric memory and EP, `destroy_process_group` can hang after training. The recipe cannot skip it; the launcher must.
- `pytorch/pytorch#204942` is required: without it step 1 runs out of memory. This was measured with DP8/CP8, not rechecked with DP32/CP2.

stack-info: PR: #6252, branch: fegin/stack/45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests 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.

3 participants