Skip to content

[muse_spark] Add an MXFP8 variant of the 64-GPU Dist-MoE recipe - #6136

Closed
fegin wants to merge 1 commit into
fegin/stack/42from
fegin/stack/43
Closed

fegin wants to merge 1 commit into
fegin/stack/42from
fegin/stack/43

Conversation

@fegin

@fegin fegin commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Stacked PRs:


[muse_spark] Add an MXFP8 variant of the 64-GPU Dist-MoE recipe

Summary (human-written)

This PR adds an MXFP8 variant of the 64-GPU Dist-MoE Muse Spark recipe.
The routed experts and the attention and pooler/unpooler linears use MXFP8,
and the Dist-MoE experts use fast-math SwiGLU, as the DeepSeek-V3 MXFP8
recipe does. It needs dist_moe with the MXFP8 padded-route postprocess fix
(meta-pytorch/dist_moe@b76e0e0).

Why

The 816B scale recipes are BF16 only. The comment gave two reasons: inner attention and the LM head stay BF16, and TorchTitan has no asynchronous MXFP8 TP path, so MXFP8 with TP exposes TP communication. The 64-GPU recipe uses TP1, so the TP reason does not apply. Dist-MoE and the Muse debug recipe already support MXFP8.

Example.

before: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 only
after:  muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64: same DP8/CP8/EP64 layout
        routed experts -> MXFP8DistMoeRoutedExperts, BlockScaledConfig(fast_math=True)
        attention.*, feed_forward.pooler/unpooler -> MXFP8Linear
        inner attention and lm_head stay BF16
        checkpoint folder muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64

What changed

  • _muse_spark_816b_dist_moe_bf16_spmd is renamed to _muse_spark_816b_dist_moe_spmd and takes expert_precision. With "mxfp8", the routed experts use MXFP8 Dist-MoE, and an MXFP8LinearTransform quantizes the attention and compressed-MoE (pooler/unpooler) projections, as in muse_spark_debugmodel_dist_moe_mxfp8.
  • _with_dist_moe passes BlockScaledConfig(fast_math=True) for MXFP8, as the DeepSeek-V3 MXFP8 Dist-MoE recipe does. The staged pipeline's fused clamped-SwiGLU (in the W2 combine and in backward) then uses an approximate exp and reciprocal in the sigmoid. This also applies to the MXFP8 debug recipe.
  • A comment on the 64-GPU recipe's TP1 records why MXFP8 recipes avoid TP.
  • The MXFP8 linear policy moves from the test recipes into torchtitan_recipes/models/muse_spark.py, so both recipes share it (mechanical).
  • The checkpoint folder name includes the expert precision.
  • New recipes: muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64 and muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_fake.
  • The README recipe table lists the MXFP8 recipe.

Performance

64 real GB300 GPUs, 100 steps from random init on c4_test, tps over steps 71-90, step-1 peak allocated / reserved (max over ranks). Base = parent commit (BF16), same harness.

  • BF16 -> MXFP8: 2,245.5 -> 2,525.3 tps (+12.5%), 252.41 / 260.40 -> 259.05 / 266.44 GiB. NVML peak 266.01 -> 272.66 GiB.
  • Logical 64-GPU FakePG run (rank 0): 3,746.1 -> 4,165.3 tps (+11.2%), 252.41 / 260.40 -> 259.03 / 266.44 GiB.
  • Of this, fast_math=True alone is about +3% (A/B of the flag: +2.9% real, +2.5% FakePG, memory unchanged).

The +6.6 GiB comes from Dist-MoE buffers allocated once at init, not from training memory. The MXFP8 backward scratch is 53.65 GiB vs 48.00 GiB for BF16, because the block-scaled size formula adds its buffers without overlapping them by lifetime. The activation slots are 63.04 vs 62.00 GiB, from the scale bytes and the 128-row expert padding. Saved activations and unshard buffers are the same within 0.1 GiB at the peak.

Numerics

  • BF16 vs MXFP8, 100 real steps: loss at steps 1 / 50 / 100 is 12.2323 / 3.8930 / 2.9158 vs 12.2316 / 3.8928 / 2.9195. No long loss comparison was run.
  • fast_math=True vs exact SwiGLU (A/B of the flag), 100 real steps: the loss difference has mean +0.00000 over all steps and max abs 0.0073 (0.24%, step 80), with no consistent sign.

Testing

  • test_dist_moe_64_mxfp8_recipe_quantizes_experts_and_projections builds the MXFP8 fake recipe and checks the expert and projection config types and the fast-math flag. It catches FQN patterns that stop matching and the policy being dropped. It needs dist_moe, so it runs in the B200 lane, which installs dist_moe; this commit adds it to that lane's pytest list.
  • pytest tests/unit_tests/cpu/recipes tests/unit_tests/cpu/models/muse_spark (with dist_moe installed): 77 passed, 13 skipped (Fused MLA needs CUDA), 3 xfailed.

Known issues / follow-ups

  • Needs dist_moe at or after meta-pytorch/dist_moe@b76e0e0 ("Fix MXFP8 callback postprocess with padded routes"). Before it, the padded-row zeroing that Muse uses raises in the MXFP8 expert postprocess. CI installs dist_moe from main, which includes the fix.
  • The lm_head stays BF16. MuseSparkLMHead has an fp32 output, an output multiplier, and a tanh soft cap, and MXFP8LinearTransform only converts plain Linear configs.
  • The Dist-MoE MXFP8 scratch could share memory by buffer lifetime, as the BF16 formula does, which would return about 5.6 GiB. That change belongs in Dist-MoE.

fegin added a commit that referenced this pull request Nov 16, 2026
## Summary (human-written)
This PR adds an MXFP8 variant of the 64-GPU Dist-MoE Muse Spark recipe.
The routed experts and the attention and pooler/unpooler linears use MXFP8,
and the Dist-MoE experts use fast-math SwiGLU, as the DeepSeek-V3 MXFP8
recipe does. It needs dist_moe with the MXFP8 padded-route postprocess fix
(meta-pytorch/dist_moe@b76e0e0).

## Why
The 816B scale recipes are BF16 only. The comment gave two reasons: inner attention and the LM head stay BF16, and TorchTitan has no asynchronous MXFP8 TP path, so MXFP8 with TP exposes TP communication. The 64-GPU recipe uses TP1, so the TP reason does not apply. Dist-MoE and the Muse debug recipe already support MXFP8.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 only
after:  muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64: same DP8/CP8/EP64 layout
        routed experts -> MXFP8DistMoeRoutedExperts, BlockScaledConfig(fast_math=True)
        attention.*, feed_forward.pooler/unpooler -> MXFP8Linear
        inner attention and lm_head stay BF16
        checkpoint folder muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64
```

## What changed
- `_muse_spark_816b_dist_moe_bf16_spmd` is renamed to `_muse_spark_816b_dist_moe_spmd` and takes `expert_precision`. With `"mxfp8"`, the routed experts use MXFP8 Dist-MoE, and an `MXFP8LinearConverter` quantizes the attention and compressed-MoE (pooler/unpooler) projections, as in `muse_spark_debugmodel_dist_moe_mxfp8`.
- `_with_dist_moe` passes `BlockScaledConfig(fast_math=True)` for MXFP8, as the DeepSeek-V3 MXFP8 Dist-MoE recipe does. The staged pipeline's fused clamped-SwiGLU (in the W2 combine and in backward) then uses an approximate exp and reciprocal in the sigmoid. This also applies to the MXFP8 debug recipe.
- A comment on the 64-GPU recipe's TP1 records why MXFP8 recipes avoid TP.
- The MXFP8 linear policy moves from the test recipes into `torchtitan_recipes/models/muse_spark.py`, so both recipes share it (mechanical).
- `muse_spark_816b_a42b` passes `converters` to `build_model_config`.
- The checkpoint folder name includes the expert precision.
- New recipes: `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64` and `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_fake`.
- The README recipe table lists the MXFP8 recipe.

## Performance
64 real GB300 GPUs, 100 steps from random init on c4_test, tps over steps 71-90, step-1 peak allocated / reserved (max over ranks). Base = parent commit (BF16), same harness.
- BF16 -> MXFP8: 2,245.5 -> 2,525.3 tps (+12.5%), 252.41 / 260.40 -> 259.05 / 266.44 GiB. NVML peak 266.01 -> 272.66 GiB.
- Logical 64-GPU FakePG run (rank 0): 3,746.1 -> 4,165.3 tps (+11.2%), 252.41 / 260.40 -> 259.03 / 266.44 GiB.
- Of this, `fast_math=True` alone is about +3% (A/B of the flag: +2.9% real, +2.5% FakePG, memory unchanged).

The +6.6 GiB comes from Dist-MoE buffers allocated once at init, not from training memory. The MXFP8 backward scratch is 53.65 GiB vs 48.00 GiB for BF16, because the block-scaled size formula adds its buffers without overlapping them by lifetime. The activation slots are 63.04 vs 62.00 GiB, from the scale bytes and the 128-row expert padding. Saved activations and unshard buffers are the same within 0.1 GiB at the peak.

## Numerics
- BF16 vs MXFP8, 100 real steps: loss at steps 1 / 50 / 100 is 12.2323 / 3.8930 / 2.9158 vs 12.2316 / 3.8928 / 2.9195. No long loss comparison was run.
- `fast_math=True` vs exact SwiGLU (A/B of the flag), 100 real steps: the loss difference has mean +0.00000 over all steps and max abs 0.0073 (0.24%, step 80), with no consistent sign.

## Testing
- `test_dist_moe_64_mxfp8_recipe_quantizes_experts_and_projections` builds the MXFP8 fake recipe and checks the expert and projection config types and the fast-math flag. It catches FQN patterns that stop matching and the policy being dropped. It needs dist_moe, so it runs in the B200 lane, which installs dist_moe; this commit adds it to that lane's pytest list.
- `pytest tests/unit_tests/cpu/recipes tests/unit_tests/cpu/models/muse_spark` (with dist_moe installed): 77 passed, 13 skipped (Fused MLA needs CUDA), 3 xfailed.

## Known issues / follow-ups
- Needs dist_moe at or after meta-pytorch/dist_moe@b76e0e0 ("Fix MXFP8 callback postprocess with padded routes"). Before it, the padded-row zeroing that Muse uses raises in the MXFP8 expert postprocess. CI installs dist_moe from main, which includes the fix.
- The lm_head stays BF16. `MuseSparkLMHead` has an fp32 output, an output multiplier, and a tanh soft cap, and `MXFP8LinearConverter` only converts plain `Linear` configs.
- The Dist-MoE MXFP8 scratch could share memory by buffer lifetime, as the BF16 formula does, which would return about 5.6 GiB. That change belongs in Dist-MoE.

stack-info: PR: #6136, branch: fegin/stack/43
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 16, 2026
fegin added a commit that referenced this pull request Nov 17, 2026
…r graph capture (#6131)

Stacked PRs:
 * #6136
 * #6135
 * #6134
 * #6133
 * #6132
 * #5882
 * #5881
 * __->__#6131


--- --- ---

### [cudagraph] Remove the unsynchronized empty_cache() before
accelerator graph capture


## Summary (human-written)
There is a race condition if users do not call a sync after step() and
call empty_cache() before the next step().

For the current TorchTitan main, we do call sync in the end of each
iteration to gather the log. However, if we change the logging to async,
this race condition will be exposed.

The race condition happens like this:
```text
step 2 (eager): FSDP2 allocates the sharded grads on its reduce-scatter stream
                AdamW reading those grads is queued on the default stream
step 3:         zero_grad(set_to_none=True) frees the grads on the host
                -> the blocks return to the reduce-scatter stream's free pool
                empty_cache() unmaps free blocks of expandable segments, after
                syncing only the reduce-scatter stream
                -> the queued AdamW reads unmapped memory: illegal memory access
```

This PR fixes the issue by removing the wrapper's empty_cache(). The
graph
capture context (torch.cuda.graph / torch.accelerator.Graph) already
calls
synchronize() and then empty_cache() when it starts, so the extra call
is
not needed and the race is gone.

## Why
`AcceleratorGraphWrapper` calls `torch.accelerator.empty_cache()` right
before it captures a graph, without a sync. If the host runs ahead of
the device, this can unmap memory that a queued kernel still reads:

```text
step 2 (eager): FSDP2 allocates the sharded grads on its reduce-scatter stream
                AdamW reading those grads is queued on the default stream
step 3:         zero_grad(set_to_none=True) frees the grads on the host
                -> the blocks return to the reduce-scatter stream's free pool
                empty_cache() unmaps free blocks of expandable segments, after
                syncing only the reduce-scatter stream
                -> the queued AdamW reads unmapped memory: illegal memory access
```

On main, a blocking host-to-device copy of the token counts in
`Trainer.train_step` waits for the previous optimizer step before
`zero_grad`, so the host never gets this far ahead. "[trainer] Log
training metrics without waiting for the device", later in this stack,
removes that copy and exposes the crash: llama3 debug model, FSDP2 on 2
GPUs, `expandable_segments:True` (set by `run_train.sh`), crashes in
step 2-3 with varlen, flex, and CP2.

The call is not needed. The capture context that runs right after it,
`torch.cuda.graph` or `torch.accelerator.Graph`, already calls
`synchronize()` and then `empty_cache()` in `__enter__`.

## What changed
- Remove the wrapper's `empty_cache()` and its `before_empty_cache` /
`after_empty_cache` memory logs. The capture context releases the same
cache, after a device sync.
- `ACCELERATOR_GRAPH.md` says the capture context empties the cache.
- `test_preparation_runs_only_before_first_capture` (renamed) expects no
`empty_cache()` call from the wrapper.

The underlying gap is in PyTorch. FSDP2 orders the reuse of gradient
blocks with stream events, which covers normal allocations but not
`empty_cache()`. The expandable-segment unmap waits only for the stream
that allocated the block, while a plain `cudaFree` syncs the device. A
single-GPU repro without torchtitan crashes with expandable segments,
and passes with a `record_stream` before the free or a sync before
`empty_cache()`. The optimizer's first-step `empty_cache()` already
syncs first (#5019). The other call runs at startup.

## Testing
- With the host running ahead ("[trainer] Log training metrics without
waiting for the device"), llama3 debug model on 2 GPUs, `log_freq=10`,
20 steps: with the wrapper's unsynchronized call, varlen, flex, and CP2
each crash 3 of 3 runs; with it removed all pass 3 of 3. A GPU coredump
puts the fault in the fused AdamW kernel, on gradients in segments owned
by FSDP2's reduce-scatter stream.
- On another 4-GPU host the debug model does not get far enough ahead to
crash. With an ~80 ms GPU sleep added before each AdamW step, the
wrapper's unsynchronized call crashes 8 of 9 runs (varlen, flex, CP2)
and this change passes 9 of 9.
- Losses and grad_norm match a `CUDA_LAUNCH_BLOCKING=1` run of the same
config (varlen with `debug.deterministic=True`).

This change was written with an AI assistant (Claude).
@fegin
fegin changed the base branch from fegin/stack/42 to main November 18, 2026 08:46
fegin added a commit that referenced this pull request Nov 18, 2026
## Summary (human-written)
This PR adds an MXFP8 variant of the 64-GPU Dist-MoE Muse Spark recipe.
The routed experts and the attention and pooler/unpooler linears use MXFP8,
and the Dist-MoE experts use fast-math SwiGLU, as the DeepSeek-V3 MXFP8
recipe does. It needs dist_moe with the MXFP8 padded-route postprocess fix
(meta-pytorch/dist_moe@b76e0e0).

## Why
The 816B scale recipes are BF16 only. The comment gave two reasons: inner attention and the LM head stay BF16, and TorchTitan has no asynchronous MXFP8 TP path, so MXFP8 with TP exposes TP communication. The 64-GPU recipe uses TP1, so the TP reason does not apply. Dist-MoE and the Muse debug recipe already support MXFP8.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 only
after:  muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64: same DP8/CP8/EP64 layout
        routed experts -> MXFP8DistMoeRoutedExperts, BlockScaledConfig(fast_math=True)
        attention.*, feed_forward.pooler/unpooler -> MXFP8Linear
        inner attention and lm_head stay BF16
        checkpoint folder muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64
```

## What changed
- `_muse_spark_816b_dist_moe_bf16_spmd` is renamed to `_muse_spark_816b_dist_moe_spmd` and takes `expert_precision`. With `"mxfp8"`, the routed experts use MXFP8 Dist-MoE, and an `MXFP8LinearConverter` quantizes the attention and compressed-MoE (pooler/unpooler) projections, as in `muse_spark_debugmodel_dist_moe_mxfp8`.
- `_with_dist_moe` passes `BlockScaledConfig(fast_math=True)` for MXFP8, as the DeepSeek-V3 MXFP8 Dist-MoE recipe does. The staged pipeline's fused clamped-SwiGLU (in the W2 combine and in backward) then uses an approximate exp and reciprocal in the sigmoid. This also applies to the MXFP8 debug recipe.
- A comment on the 64-GPU recipe's TP1 records why MXFP8 recipes avoid TP.
- The MXFP8 linear policy moves from the test recipes into `torchtitan_recipes/models/muse_spark.py`, so both recipes share it (mechanical).
- `muse_spark_816b_a42b` passes `converters` to `build_model_config`.
- The checkpoint folder name includes the expert precision.
- New recipes: `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64` and `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_fake`.
- The README recipe table lists the MXFP8 recipe.

## Performance
64 real GB300 GPUs, 100 steps from random init on c4_test, tps over steps 71-90, step-1 peak allocated / reserved (max over ranks). Base = parent commit (BF16), same harness.
- BF16 -> MXFP8: 2,245.5 -> 2,525.3 tps (+12.5%), 252.41 / 260.40 -> 259.05 / 266.44 GiB. NVML peak 266.01 -> 272.66 GiB.
- Logical 64-GPU FakePG run (rank 0): 3,746.1 -> 4,165.3 tps (+11.2%), 252.41 / 260.40 -> 259.03 / 266.44 GiB.
- Of this, `fast_math=True` alone is about +3% (A/B of the flag: +2.9% real, +2.5% FakePG, memory unchanged).

The +6.6 GiB comes from Dist-MoE buffers allocated once at init, not from training memory. The MXFP8 backward scratch is 53.65 GiB vs 48.00 GiB for BF16, because the block-scaled size formula adds its buffers without overlapping them by lifetime. The activation slots are 63.04 vs 62.00 GiB, from the scale bytes and the 128-row expert padding. Saved activations and unshard buffers are the same within 0.1 GiB at the peak.

## Numerics
- BF16 vs MXFP8, 100 real steps: loss at steps 1 / 50 / 100 is 12.2323 / 3.8930 / 2.9158 vs 12.2316 / 3.8928 / 2.9195. No long loss comparison was run.
- `fast_math=True` vs exact SwiGLU (A/B of the flag), 100 real steps: the loss difference has mean +0.00000 over all steps and max abs 0.0073 (0.24%, step 80), with no consistent sign.

## Testing
- `test_dist_moe_64_mxfp8_recipe_quantizes_experts_and_projections` builds the MXFP8 fake recipe and checks the expert and projection config types and the fast-math flag. It catches FQN patterns that stop matching and the policy being dropped. It needs dist_moe, so it runs in the B200 lane, which installs dist_moe; this commit adds it to that lane's pytest list.
- `pytest tests/unit_tests/cpu/recipes tests/unit_tests/cpu/models/muse_spark` (with dist_moe installed): 77 passed, 13 skipped (Fused MLA needs CUDA), 3 xfailed.

## Known issues / follow-ups
- Needs dist_moe at or after meta-pytorch/dist_moe@b76e0e0 ("Fix MXFP8 callback postprocess with padded routes"). Before it, the padded-row zeroing that Muse uses raises in the MXFP8 expert postprocess. CI installs dist_moe from main, which includes the fix.
- The lm_head stays BF16. `MuseSparkLMHead` has an fp32 output, an output multiplier, and a tanh soft cap, and `MXFP8LinearConverter` only converts plain `Linear` configs.
- The Dist-MoE MXFP8 scratch could share memory by buffer lifetime, as the BF16 formula does, which would return about 5.6 GiB. That change belongs in Dist-MoE.

stack-info: PR: #6136, branch: fegin/stack/43
fegin added a commit that referenced this pull request Nov 18, 2026
## Summary (human-written)
This PR adds an MXFP8 variant of the 64-GPU Dist-MoE Muse Spark recipe.
The routed experts and the attention and pooler/unpooler linears use MXFP8,
and the Dist-MoE experts use fast-math SwiGLU, as the DeepSeek-V3 MXFP8
recipe does. It needs dist_moe with the MXFP8 padded-route postprocess fix
(meta-pytorch/dist_moe@b76e0e0).

## Why
The 816B scale recipes are BF16 only. The comment gave two reasons: inner attention and the LM head stay BF16, and TorchTitan has no asynchronous MXFP8 TP path, so MXFP8 with TP exposes TP communication. The 64-GPU recipe uses TP1, so the TP reason does not apply. Dist-MoE and the Muse debug recipe already support MXFP8.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 only
after:  muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64: same DP8/CP8/EP64 layout
        routed experts -> MXFP8DistMoeRoutedExperts, BlockScaledConfig(fast_math=True)
        attention.*, feed_forward.pooler/unpooler -> MXFP8Linear
        inner attention and lm_head stay BF16
        checkpoint folder muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64
```

## What changed
- `_muse_spark_816b_dist_moe_bf16_spmd` is renamed to `_muse_spark_816b_dist_moe_spmd` and takes `expert_precision`. With `"mxfp8"`, the routed experts use MXFP8 Dist-MoE, and an `MXFP8LinearConverter` quantizes the attention and compressed-MoE (pooler/unpooler) projections, as in `muse_spark_debugmodel_dist_moe_mxfp8`.
- `_with_dist_moe` passes `BlockScaledConfig(fast_math=True)` for MXFP8, as the DeepSeek-V3 MXFP8 Dist-MoE recipe does. The staged pipeline's fused clamped-SwiGLU (in the W2 combine and in backward) then uses an approximate exp and reciprocal in the sigmoid. This also applies to the MXFP8 debug recipe.
- A comment on the 64-GPU recipe's TP1 records why MXFP8 recipes avoid TP.
- The MXFP8 linear policy moves from the test recipes into `torchtitan_recipes/models/muse_spark.py`, so both recipes share it (mechanical).
- `muse_spark_816b_a42b` passes `converters` to `build_model_config`.
- The checkpoint folder name includes the expert precision.
- New recipes: `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64` and `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_fake`.
- The README recipe table lists the MXFP8 recipe.

## Performance
64 real GB300 GPUs, 100 steps from random init on c4_test, tps over steps 71-90, step-1 peak allocated / reserved (max over ranks). Base = parent commit (BF16), same harness.
- BF16 -> MXFP8: 2,245.5 -> 2,525.3 tps (+12.5%), 252.41 / 260.40 -> 259.05 / 266.44 GiB. NVML peak 266.01 -> 272.66 GiB.
- Logical 64-GPU FakePG run (rank 0): 3,746.1 -> 4,165.3 tps (+11.2%), 252.41 / 260.40 -> 259.03 / 266.44 GiB.
- Of this, `fast_math=True` alone is about +3% (A/B of the flag: +2.9% real, +2.5% FakePG, memory unchanged).

The +6.6 GiB comes from Dist-MoE buffers allocated once at init, not from training memory. The MXFP8 backward scratch is 53.65 GiB vs 48.00 GiB for BF16, because the block-scaled size formula adds its buffers without overlapping them by lifetime. The activation slots are 63.04 vs 62.00 GiB, from the scale bytes and the 128-row expert padding. Saved activations and unshard buffers are the same within 0.1 GiB at the peak.

## Numerics
- BF16 vs MXFP8, 100 real steps: loss at steps 1 / 50 / 100 is 12.2323 / 3.8930 / 2.9158 vs 12.2316 / 3.8928 / 2.9195. No long loss comparison was run.
- `fast_math=True` vs exact SwiGLU (A/B of the flag), 100 real steps: the loss difference has mean +0.00000 over all steps and max abs 0.0073 (0.24%, step 80), with no consistent sign.

## Testing
- `test_dist_moe_64_mxfp8_recipe_quantizes_experts_and_projections` builds the MXFP8 fake recipe and checks the expert and projection config types and the fast-math flag. It catches FQN patterns that stop matching and the policy being dropped. It needs dist_moe, so it runs in the B200 lane, which installs dist_moe; this commit adds it to that lane's pytest list.
- `pytest tests/unit_tests/cpu/recipes tests/unit_tests/cpu/models/muse_spark` (with dist_moe installed): 77 passed, 13 skipped (Fused MLA needs CUDA), 3 xfailed.

## Known issues / follow-ups
- Needs dist_moe at or after meta-pytorch/dist_moe@b76e0e0 ("Fix MXFP8 callback postprocess with padded routes"). Before it, the padded-row zeroing that Muse uses raises in the MXFP8 expert postprocess. CI installs dist_moe from main, which includes the fix.
- The lm_head stays BF16. `MuseSparkLMHead` has an fp32 output, an output multiplier, and a tanh soft cap, and `MXFP8LinearConverter` only converts plain `Linear` configs.
- The Dist-MoE MXFP8 scratch could share memory by buffer lifetime, as the BF16 formula does, which would return about 5.6 GiB. That change belongs in Dist-MoE.

stack-info: PR: #6136, branch: fegin/stack/43
@fegin
fegin changed the base branch from main to fegin/stack/42 November 18, 2026 08:47
@fegin
fegin changed the base branch from fegin/stack/42 to main November 19, 2026 21:12
@fegin
fegin changed the base branch from main to fegin/stack/42 November 19, 2026 21:13
@fegin
fegin changed the base branch from fegin/stack/42 to main November 19, 2026 22:16
@fegin
fegin changed the base branch from main to fegin/stack/42 November 19, 2026 22:17
@fegin
fegin changed the base branch from fegin/stack/42 to main November 20, 2026 00:20
@fegin
fegin changed the base branch from main to fegin/stack/42 November 20, 2026 00:20
@fegin
fegin changed the base branch from fegin/stack/42 to main November 20, 2026 18:01
@fegin
fegin changed the base branch from main to fegin/stack/42 November 20, 2026 18:02
## Summary (human-written)
This PR adds an MXFP8 variant of the 64-GPU Dist-MoE Muse Spark recipe.
The routed experts and the attention and pooler/unpooler linears use MXFP8,
and the Dist-MoE experts use fast-math SwiGLU, as the DeepSeek-V3 MXFP8
recipe does. It needs dist_moe with the MXFP8 padded-route postprocess fix
(meta-pytorch/dist_moe@b76e0e0).

## Why
The 816B scale recipes are BF16 only. The comment gave two reasons: inner attention and the LM head stay BF16, and TorchTitan has no asynchronous MXFP8 TP path, so MXFP8 with TP exposes TP communication. The 64-GPU recipe uses TP1, so the TP reason does not apply. Dist-MoE and the Muse debug recipe already support MXFP8.

**Example.**

```text
before: muse_spark_816b_a42b_dist_moe_bf16_spmd_64 only
after:  muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64: same DP8/CP8/EP64 layout
        routed experts -> MXFP8DistMoeRoutedExperts, BlockScaledConfig(fast_math=True)
        attention.*, feed_forward.pooler/unpooler -> MXFP8Linear
        inner attention and lm_head stay BF16
        checkpoint folder muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64
```

## What changed
- `_muse_spark_816b_dist_moe_bf16_spmd` is renamed to `_muse_spark_816b_dist_moe_spmd` and takes `expert_precision`. With `"mxfp8"`, the routed experts use MXFP8 Dist-MoE, and an `MXFP8LinearTransform` quantizes the attention and compressed-MoE (pooler/unpooler) projections, as in `muse_spark_debugmodel_dist_moe_mxfp8`.
- `_with_dist_moe` passes `BlockScaledConfig(fast_math=True)` for MXFP8, as the DeepSeek-V3 MXFP8 Dist-MoE recipe does. The staged pipeline's fused clamped-SwiGLU (in the W2 combine and in backward) then uses an approximate exp and reciprocal in the sigmoid. This also applies to the MXFP8 debug recipe.
- A comment on the 64-GPU recipe's TP1 records why MXFP8 recipes avoid TP.
- The MXFP8 linear policy moves from the test recipes into `torchtitan_recipes/models/muse_spark.py`, so both recipes share it (mechanical).
- The checkpoint folder name includes the expert precision.
- New recipes: `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64` and `muse_spark_816b_a42b_dist_moe_mxfp8_spmd_64_fake`.
- The README recipe table lists the MXFP8 recipe.

## Performance
64 real GB300 GPUs, 100 steps from random init on c4_test, tps over steps 71-90, step-1 peak allocated / reserved (max over ranks). Base = parent commit (BF16), same harness.
- BF16 -> MXFP8: 2,245.5 -> 2,525.3 tps (+12.5%), 252.41 / 260.40 -> 259.05 / 266.44 GiB. NVML peak 266.01 -> 272.66 GiB.
- Logical 64-GPU FakePG run (rank 0): 3,746.1 -> 4,165.3 tps (+11.2%), 252.41 / 260.40 -> 259.03 / 266.44 GiB.
- Of this, `fast_math=True` alone is about +3% (A/B of the flag: +2.9% real, +2.5% FakePG, memory unchanged).

The +6.6 GiB comes from Dist-MoE buffers allocated once at init, not from training memory. The MXFP8 backward scratch is 53.65 GiB vs 48.00 GiB for BF16, because the block-scaled size formula adds its buffers without overlapping them by lifetime. The activation slots are 63.04 vs 62.00 GiB, from the scale bytes and the 128-row expert padding. Saved activations and unshard buffers are the same within 0.1 GiB at the peak.

## Numerics
- BF16 vs MXFP8, 100 real steps: loss at steps 1 / 50 / 100 is 12.2323 / 3.8930 / 2.9158 vs 12.2316 / 3.8928 / 2.9195. No long loss comparison was run.
- `fast_math=True` vs exact SwiGLU (A/B of the flag), 100 real steps: the loss difference has mean +0.00000 over all steps and max abs 0.0073 (0.24%, step 80), with no consistent sign.

## Testing
- `test_dist_moe_64_mxfp8_recipe_quantizes_experts_and_projections` builds the MXFP8 fake recipe and checks the expert and projection config types and the fast-math flag. It catches FQN patterns that stop matching and the policy being dropped. It needs dist_moe, so it runs in the B200 lane, which installs dist_moe; this commit adds it to that lane's pytest list.
- `pytest tests/unit_tests/cpu/recipes tests/unit_tests/cpu/models/muse_spark` (with dist_moe installed): 77 passed, 13 skipped (Fused MLA needs CUDA), 3 xfailed.

## Known issues / follow-ups
- Needs dist_moe at or after meta-pytorch/dist_moe@b76e0e0 ("Fix MXFP8 callback postprocess with padded routes"). Before it, the padded-row zeroing that Muse uses raises in the MXFP8 expert postprocess. CI installs dist_moe from main, which includes the fix.
- The lm_head stays BF16. `MuseSparkLMHead` has an fp32 output, an output multiplier, and a tanh soft cap, and `MXFP8LinearTransform` only converts plain `Linear` configs.
- The Dist-MoE MXFP8 scratch could share memory by buffer lifetime, as the BF16 formula does, which would return about 5.6 GiB. That change belongs in Dist-MoE.

stack-info: PR: #6136, branch: fegin/stack/43
@fegin
fegin changed the base branch from fegin/stack/42 to main November 23, 2026 08:13
@fegin
fegin changed the base branch from main to fegin/stack/42 November 23, 2026 08:14
@fegin fegin closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant