Repository navigation
deprecate minimal_async_ep - #4627
Merged
Merged
Conversation
tianyu-l
requested review from
IvanKobzarev,
SherlockNoMad,
aditvenk,
fegin,
sanketpurandare,
wconstab and
wwwjn
as code owners
September 12, 2026 05:21
aditvenk
approved these changes
Sep 12, 2026
anijain2305
approved these changes
Sep 12, 2026
tianyu-l
force-pushed
the
ep_backend
branch
2 times, most recently
from
September 12, 2026 07:18
bbf25e2 to
18c63d3
Compare
wwwjn
approved these changes
Sep 12, 2026
|
Warning: Unknown label
Please add the new label to .github/pytorch-probot.yml |
tianyu-l
force-pushed
the
ep_backend
branch
from
September 12, 2026 21:11
6fccd06 to
2662644
Compare
tianyu-l
force-pushed
the
ep_backend
branch
from
September 12, 2026 22:11
2662644 to
9264f27
Compare
chelsea0x3b
pushed a commit
to LambdaLabsML/torchtitan
that referenced
this pull request
Oct 5, 2026
…it in the GB300 recipe (#25) MinimalAsyncEP was deprecated in pytorch#4627 as unmaintained, leaving only the standard all-to-all for MoE dispatch on this cluster. It was worth +4.9% over standard before the leaf compiles and ~+15% after them (137.28 vs 119.33 TFLOP/s on 32x GB300), and nothing available replaces it: DeepEP measured 7.4% above standard and needs a source build, HybridEP 2.9% below MinimalAsyncEP. Restored from fc0e816^ with its wiring, adapted to main's current logging layout (library modules make their own named logger now). The GB300 recipe uses it and disables CUDA graphs (now on by default upstream, and incompatible with any dispatcher that has a host sync). Split out of 62e9bbf (restore MinimalAsyncEP and make flex autotune configurable per layer) on dsv4_te_mhc. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
chelsea0x3b
pushed a commit
to LambdaLabsML/torchtitan
that referenced
this pull request
Oct 5, 2026
* restore MinimalAsyncEP (deprecated upstream in pytorch#4627) and use it in the GB300 recipe (#25) MinimalAsyncEP was deprecated in pytorch#4627 as unmaintained, leaving only the standard all-to-all for MoE dispatch on this cluster. It was worth +4.9% over standard before the leaf compiles and ~+15% after them (137.28 vs 119.33 TFLOP/s on 32x GB300), and nothing available replaces it: DeepEP measured 7.4% above standard and needs a source build, HybridEP 2.9% below MinimalAsyncEP. Restored from fc0e816^ with its wiring, adapted to main's current logging layout (library modules make their own named logger now). The GB300 recipe uses it and disables CUDA graphs (now on by default upstream, and incompatible with any dispatcher that has a host sync). Split out of 62e9bbf (restore MinimalAsyncEP and make flex autotune configurable per layer) on dsv4_te_mhc. Co-authored-by: Claude Opus 5 (1M context) <[email protected]> * gb300 launcher (renderers side dir, memory sampler) Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> (cherry picked from commit 1737fcf) * launcher: EXTRA_PYTHONPATH appends side dependency dirs Side-installed dependency dirs (e.g. the cuDNN DSA frontend in /mnt/dgxc/pydeps-cudnn) go on PYTHONPATH without touching the shared venv. Cherry-picked-from: c537579 (paths: gb300/dsv4_64xgb300.slurm) * launcher: CPATH for header-less nodes (python3.12 headers + multiarch pyconfig.h dir) Nodes yqb01-qa01-mgx-[00001-00008] have no python3.12-dev, so Triton cannot build its CUDA driver shim there ("Python.h: No such file", job 686). gcc honours CPATH; the headers are copied from a node that has them, and the multiarch pyconfig.h dir is added alongside. Cherry-picked-from: f13f059 (paths: gb300/dsv4_64xgb300.slurm) and fcc371a --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
fegin
added a commit
that referenced
this pull request
Nov 11, 2026
## Summary (human-written) Muse Spark currently only supports AllToAll and Dist-MoE backends. The former is slow and the latter cannot be used on Hopper. This PR enables HybridEP. The main design decision is how to run `output_postprocess`, which Muse Spark uses to perform RMSNorm after the experts and before combine. With non-blocking HybridEP, the rows past the last expert offset are never written, so `output_postprocess` needs `torch.where` masks around it to keep those rows out of the forward and the gradients. The masks are slow in eager mode, so we use local_compile to fuse them into the RMSNorm kernels. See the performance section. TL;DR: with local_compile and CUDA graphs, we see about 60% higher TPS than AllToAll (note that the AllToAll performance is also improved after #placeholder). ## Why On Hopper, Dist-MoE is not available, so Muse Spark's only EP path is the AllToAll dispatcher. AllToAll syncs the CPU in every MoE layer, so it cannot use CUDA graphs. `MuseSparkMoE.Config` rejects HybridEP, which has no CPU sync in non-blocking mode and supports CUDA graphs. The check was added when the per-expert norm could only run after combine. `output_postprocess` (#4623) now runs it before combine, and HybridEP applies scores after it, so the operation order is right. Allowing HybridEP alone is not enough. Non-blocking HybridEP (`non_blocking_capacity_factor` set) sizes the routed rows to its capacity, not to the received token count. Rows past `offsets_E[-1]` are never written: in forward, the grouped GEMMs only write rows inside the expert offsets, and in backward, HybridEP's combine backward only writes grads for received tokens. So those rows hold stale memory in both directions. `output_postprocess` runs on every row, so its parameter grads sum over those rows. The result is a wrong grad, or NaN when the stale memory is not finite. Muse Spark is the only model that sets `output_postprocess`, so no other model hits this. **Example.** ```python config = muse_spark_debugmodel(seq_len) config = apply_transforms(config, [TokenDispatcherTransform( dispatcher=HybridEPTokenDispatcher, num_max_tokens_per_rank=tokens_per_microbatch // (cp * tp), kwargs={"non_blocking_capacity_factor": 1.0}, )]) # main: ValueError("Muse Spark MoE requires LocalTokenDispatcher or AllToAllTokenDispatcher, ...") # only the check removed: "Loss or gradient norm is not finite" at step 1 # this change: trains ``` The stale rows, at EP2, 64 tokens per rank, top-2, capacity factor 1.0, RMSNorm postprocess: ``` routed rows: 256, valid rows (offsets_E[-1]): 128 rows 128..255: stale inputs (abs max ~30) and nonzero incoming grads (abs max ~14) norm weight grad vs AllToAll: relative error 1.2 and 1.5 (all other grads bitwise equal) ``` ## What changed - Shared MoE (`models/common/moe/moe.py`, please review this first): with non-blocking HybridEP and an `output_postprocess`, `RoutedExperts.forward` calls `_masked_output_postprocess`. It masks rows past `offsets_E[-1]` with `torch.where` before the postprocess (finite forward) and after it (zero grad for those rows). `torch.where` instead of a multiply, so NaN rows are dropped too. The mask is built on the GPU from `offsets_E`, so there is no CPU sync and CUDA graph capture still works. The function is a `local_compile` region (`moe_masked_output_postprocess`), so Inductor fuses both masks into the postprocess kernels. Without the region it runs eagerly with the same math. In training, other dispatchers and blocking HybridEP never produce rows past the last offset, so they skip it. HybridEP `pad_multiple` padding rows are inside the offsets, and HybridEP writes zeros to them in both directions, so they need no mask. Dist-MoE does not use this forward. - Muse Spark enables the `moe_masked_output_postprocess` region in its default `local_compile.regions`. - `MuseSparkMoE.Config` accepts `HybridEPTokenDispatcher`. DeepEP stays rejected because it is untested with Muse Spark. - Add the `muse_spark_debugmodel_hybridep` test recipe with CUDA graphs on, like `deepseek_v3_debugmodel_hybridep`. Capacity factor 1.0 reserves the worst case, so no tokens are dropped. - Integration: add a Muse Spark FSDP2 + TP2 (SP) + EP2 run to the H100 HybridEP test, renamed from `deepseek_v3_fsdp+hybridep` to `fsdp+hybridep` because it covers both models. Mechanical: update the test name in `run_8xgpu_integration_tests.sh`, `validate_release_gpu.sh`, and `test_integration_test_definitions.py`. The last also checks every config of the test, not only the first. - README: list HybridEP as supported (verified with FSDP, TP+EP, and CUDA graphs; CP is not verified), say that on Hopper it is the EP path with CUDA graph support, give its memory cost (about 2x at capacity factor 1.0) and measured speedup, note its BF16 score rounding, and drop MinimalAsyncEP, which was deleted in #4627. ## Alternatives considered - Clean the rows inside HybridEP: only covers backward. The forward stale rows come from w2's grouped GEMM output. Masking in `RoutedExperts` handles both directions in one place. - Mask whenever `output_postprocess` is set: adds the mask cost to Muse Spark with AllToAll, which has no capacity rows. - A dispatcher property such as "may produce rows past the last offset": an interface with one implementer. The check follows the existing `DeepEPDispatchMetadata` branch in the same forward instead. - Reject non-blocking HybridEP with `output_postprocess`: blocking mode syncs the CPU in every MoE layer and cannot use CUDA graphs, which removes most of the reason to use HybridEP on Hopper. ## Numerics No change for other models or for Muse Spark with AllToAll: the mask only runs for non-blocking HybridEP with `output_postprocess`. Compiling the mask region does not change numerics: unfused masks vs the compiled region, `muse_spark_debugmodel_hybridep` on 4x H100, 20 steps, `scripts/loss_compare.py`: loss is bitwise identical at every step, and grad_norm matches. Muse Spark debug model, FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps, `scripts/loss_compare.py`, AllToAll (`muse_spark_debugmodel`) vs HybridEP (`muse_spark_debugmodel_hybridep`): | Step | AllToAll | HybridEP | Diff | | --- | --- | --- | --- | | 1 | 7.782996 | 7.783380 | +0.000383 | | 2 | 6.977194 | 6.979984 | +0.002790 | | 10 | 4.832992 | 4.837770 | +0.004778 | | 20 | 4.407280 | 4.412218 | +0.004938 | Average over 20 steps: 5.233406 vs 5.231284. The differences have no consistent sign. HybridEP rounds the routing scores to BF16 before the combine multiply, while AllToAll multiplies in FP32, and the two combine kernels sum in a different order. The README notes the BF16 rounding. ## Performance Scaled-up Muse Spark (dim 2048, 8 layers, 64 experts, top-8, compressed dim 1024, seq 4096) with the fused SwiGLU override, FSDP8 + EP8 on 8x H100, mean TPS over steps 11-30. All runs include the fused SwiGLU recompile fix earlier in this stack; without it, AllToAll runs at 2,138 TPS. | Config | TPS | Memory | | --- | --- | --- | | AllToAll | 18,624 | 7.7 GiB | | HybridEP eager, masks unfused | 18,618 | 16.7 GiB | | HybridEP eager, masks compiled | 21,439 (+15%) | 16.7 GiB | | HybridEP CUDA graphs, masks unfused | 24,777 | 16.8 GiB | | HybridEP CUDA graphs, masks compiled | 30,287 (+63%) | 16.8 GiB | - Most of the gain comes from CUDA graphs, which AllToAll cannot use. - Unfused, the masks run over all capacity rows (8x the valid rows at EP8 and top-8), and remat runs them again. Compiling them into the postprocess region removes that cost: +15% eager, +22% with graphs. - The extra memory comes from capacity factor 1.0. A lower factor saves memory but can drop tokens. ## Testing - `test_matches_all_to_all_with_output_postprocess` (new, 2x H100): HybridEP (blocking and non-blocking) vs AllToAll with an RMSNorm postprocess. Compares loss, input grad, and router, W13, W2, and norm weight grads within 2 BF16 eps (normwise). Without the mask it fails with errors of 12.5 and 8.8 vs bounds below 0.87. This is the regression it catches. - The HybridEP activation-checkpointing tests also run with an RMSNorm postprocess, as the DeepEP tests do, so remat replay stays exact around the mask. They run the mask function eagerly; the loss comparison above covers the compiled region. - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k HybridEP`: 4 passed. - Manual check: the parity test also passes with `pad_multiple=32`, with and without the postprocess. So the per-expert padding rows inside the offsets do not affect gradients. - `python -m tests.integration_tests.run_tests --test_suite h100 --execution_mode real_pg --ngpu 4 --test_name=fsdp+hybridep` (4x H100, HybridEP at the CI pin f725d29), CUDA graphs on: both configs pass and record a CUDA graph. The Muse Spark config (FSDP2 + TP2 + SP + EP2) keeps local compile on, so CI runs the compiled mask region. SPMD type checking would turn it off; Muse Spark TP+SP+EP type checking is covered by `muse_spark_mm_fsdp+tp+cp+ep+sp`. Muse Spark loss goes from about 7.7 to about 4.9-5.2 in 10 steps across three runs. - `pytest tests/unit_tests/cpu/test_integration_test_definitions.py tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py tests/unit_tests/cpu/config`: 263 passed, 3 xfailed. - `pytest tests/unit_tests/cpu -k "moe or expert or dispatcher or local_compile"`: 147 passed, 1 skipped. ## Known issues / follow-ups - CP + EP with HybridEP is not tested. - Multimodal training with CUDA graphs is not supported for Muse Spark with any dispatcher. - The score multiply in HybridEP's combine also runs over all capacity rows. Moving it into a compiled region would change HybridEP's combine, which DeepSeek-V3 also uses, so it is left for a follow-up. stack-info: PR: #6032, branch: fegin/stack/34
fegin
added a commit
that referenced
this pull request
Nov 11, 2026
## Summary (human-written) Muse Spark currently only supports AllToAll and Dist-MoE backends. The former is slow and the latter cannot be used on Hopper. This PR enables HybridEP. The main design decision is how to run `output_postprocess`, which Muse Spark uses to perform RMSNorm after the experts and before combine. With non-blocking HybridEP, the rows past the last expert offset are never written, so `output_postprocess` needs `torch.where` masks around it to keep those rows out of the forward and the gradients. The masks are slow in eager mode, so we use local_compile to fuse them into the RMSNorm kernels. See the performance section. TL;DR: with local_compile and CUDA graphs, we see about 60% higher TPS than AllToAll (note that the AllToAll performance is also improved after #6030). ## Why On Hopper, Dist-MoE is not available, so Muse Spark's only EP path is the AllToAll dispatcher. AllToAll syncs the CPU in every MoE layer, so it cannot use CUDA graphs. `MuseSparkMoE.Config` rejects HybridEP, which has no CPU sync in non-blocking mode and supports CUDA graphs. The check was added when the per-expert norm could only run after combine. `output_postprocess` (#4623) now runs it before combine, and HybridEP applies scores after it, so the operation order is right. Allowing HybridEP alone is not enough. Non-blocking HybridEP (`non_blocking_capacity_factor` set) sizes the routed rows to its capacity, not to the received token count. Rows past `offsets_E[-1]` are never written: in forward, the grouped GEMMs only write rows inside the expert offsets, and in backward, HybridEP's combine backward only writes grads for received tokens. So those rows hold stale memory in both directions. `output_postprocess` runs on every row, so its parameter grads sum over those rows. The result is a wrong grad, or NaN when the stale memory is not finite. Muse Spark is the only model that sets `output_postprocess`, so no other model hits this. **Example.** ```python config = muse_spark_debugmodel(seq_len) config = apply_transforms(config, [TokenDispatcherTransform( dispatcher=HybridEPTokenDispatcher, num_max_tokens_per_rank=tokens_per_microbatch // (cp * tp), kwargs={"non_blocking_capacity_factor": 1.0}, )]) # main: ValueError("Muse Spark MoE requires LocalTokenDispatcher or AllToAllTokenDispatcher, ...") # only the check removed: "Loss or gradient norm is not finite" at step 1 # this change: trains ``` The stale rows, at EP2, 64 tokens per rank, top-2, capacity factor 1.0, RMSNorm postprocess: ``` routed rows: 256, valid rows (offsets_E[-1]): 128 rows 128..255: stale inputs (abs max ~30) and nonzero incoming grads (abs max ~14) norm weight grad vs AllToAll: relative error 1.2 and 1.5 (all other grads bitwise equal) ``` ## What changed - Shared MoE (`models/common/moe/moe.py`, please review this first): with non-blocking HybridEP and an `output_postprocess`, `RoutedExperts.forward` calls `_masked_output_postprocess`. It masks rows past `offsets_E[-1]` with `torch.where` before the postprocess (finite forward) and after it (zero grad for those rows). `torch.where` instead of a multiply, so NaN rows are dropped too. The mask is built on the GPU from `offsets_E`, so there is no CPU sync and CUDA graph capture still works. The function is a `local_compile` region (`moe_masked_output_postprocess`), so Inductor fuses both masks into the postprocess kernels. Without the region it runs eagerly with the same math. In training, other dispatchers and blocking HybridEP never produce rows past the last offset, so they skip it. HybridEP `pad_multiple` padding rows are inside the offsets, and HybridEP writes zeros to them in both directions, so they need no mask. Dist-MoE does not use this forward. - Muse Spark enables the `moe_masked_output_postprocess` region in its default `local_compile.regions`. - `MuseSparkMoE.Config` accepts `HybridEPTokenDispatcher`. DeepEP stays rejected because it is untested with Muse Spark. - Add the `muse_spark_debugmodel_hybridep` test recipe with CUDA graphs on, like `deepseek_v3_debugmodel_hybridep`. Capacity factor 1.0 reserves the worst case, so no tokens are dropped. - Integration: add a Muse Spark FSDP2 + TP2 (SP) + EP2 run to the H100 HybridEP test, renamed from `deepseek_v3_fsdp+hybridep` to `fsdp+hybridep` because it covers both models. Mechanical: update the test name in `run_8xgpu_integration_tests.sh`, `validate_release_gpu.sh`, and `test_integration_test_definitions.py`. The last also checks every config of the test, not only the first. - README: list HybridEP as supported (verified with FSDP, TP+EP, and CUDA graphs; CP is not verified), say that on Hopper it is the EP path with CUDA graph support, give its memory cost (about 2x at capacity factor 1.0) and measured speedup, note its BF16 score rounding, and drop MinimalAsyncEP, which was deleted in #4627. ## Alternatives considered - Clean the rows inside HybridEP: only covers backward. The forward stale rows come from w2's grouped GEMM output. Masking in `RoutedExperts` handles both directions in one place. - Mask whenever `output_postprocess` is set: adds the mask cost to Muse Spark with AllToAll, which has no capacity rows. - A dispatcher property such as "may produce rows past the last offset": an interface with one implementer. The check follows the existing `DeepEPDispatchMetadata` branch in the same forward instead. - Reject non-blocking HybridEP with `output_postprocess`: blocking mode syncs the CPU in every MoE layer and cannot use CUDA graphs, which removes most of the reason to use HybridEP on Hopper. ## Numerics No change for other models or for Muse Spark with AllToAll: the mask only runs for non-blocking HybridEP with `output_postprocess`. Compiling the mask region does not change numerics: unfused masks vs the compiled region, `muse_spark_debugmodel_hybridep` on 4x H100, 20 steps, `scripts/loss_compare.py`: loss is bitwise identical at every step, and grad_norm matches. Muse Spark debug model, FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps, `scripts/loss_compare.py`, AllToAll (`muse_spark_debugmodel`) vs HybridEP (`muse_spark_debugmodel_hybridep`): | Step | AllToAll | HybridEP | Diff | | --- | --- | --- | --- | | 1 | 7.782996 | 7.783380 | +0.000383 | | 2 | 6.977194 | 6.979984 | +0.002790 | | 10 | 4.832992 | 4.837770 | +0.004778 | | 20 | 4.407280 | 4.412218 | +0.004938 | Average over 20 steps: 5.233406 vs 5.231284. The differences have no consistent sign. HybridEP rounds the routing scores to BF16 before the combine multiply, while AllToAll multiplies in FP32, and the two combine kernels sum in a different order. The README notes the BF16 rounding. ## Performance Scaled-up Muse Spark (dim 2048, 8 layers, 64 experts, top-8, compressed dim 1024, seq 4096) with the fused SwiGLU override, FSDP8 + EP8 on 8x H100, mean TPS over steps 11-30. All runs include the fused SwiGLU recompile fix earlier in this stack; without it, AllToAll runs at 2,138 TPS. | Config | TPS | Memory | | --- | --- | --- | | AllToAll | 18,624 | 7.7 GiB | | HybridEP eager, masks unfused | 18,618 | 16.7 GiB | | HybridEP eager, masks compiled | 21,439 (+15%) | 16.7 GiB | | HybridEP CUDA graphs, masks unfused | 24,777 | 16.8 GiB | | HybridEP CUDA graphs, masks compiled | 30,287 (+63%) | 16.8 GiB | - Most of the gain comes from CUDA graphs, which AllToAll cannot use. - Unfused, the masks run over all capacity rows (8x the valid rows at EP8 and top-8), and remat runs them again. Compiling them into the postprocess region removes that cost: +15% eager, +22% with graphs. - The extra memory comes from capacity factor 1.0. A lower factor saves memory but can drop tokens. ## Testing - `test_matches_all_to_all_with_output_postprocess` (new, 2x H100): HybridEP (blocking and non-blocking) vs AllToAll with an RMSNorm postprocess. Compares loss, input grad, and router, W13, W2, and norm weight grads within 2 BF16 eps (normwise). Without the mask it fails with errors of 12.5 and 8.8 vs bounds below 0.87. This is the regression it catches. - The HybridEP activation-checkpointing tests also run with an RMSNorm postprocess, as the DeepEP tests do, so remat replay stays exact around the mask. They run the mask function eagerly; the loss comparison above covers the compiled region. - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k HybridEP`: 4 passed. - Manual check: the parity test also passes with `pad_multiple=32`, with and without the postprocess. So the per-expert padding rows inside the offsets do not affect gradients. - `python -m tests.integration_tests.run_tests --test_suite h100 --execution_mode real_pg --ngpu 4 --test_name=fsdp+hybridep` (4x H100, HybridEP at the CI pin f725d29), CUDA graphs on: both configs pass and record a CUDA graph. The Muse Spark config (FSDP2 + TP2 + SP + EP2) keeps local compile on, so CI runs the compiled mask region. SPMD type checking would turn it off; Muse Spark TP+SP+EP type checking is covered by `muse_spark_mm_fsdp+tp+cp+ep+sp`. Muse Spark loss goes from about 7.7 to about 4.9-5.2 in 10 steps across three runs. - `pytest tests/unit_tests/cpu/test_integration_test_definitions.py tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py tests/unit_tests/cpu/config`: 263 passed, 3 xfailed. - `pytest tests/unit_tests/cpu -k "moe or expert or dispatcher or local_compile"`: 147 passed, 1 skipped. ## Known issues / follow-ups - CP + EP with HybridEP is not tested. - Multimodal training with CUDA graphs is not supported for Muse Spark with any dispatcher. - The score multiply in HybridEP's combine also runs over all capacity rows. Moving it into a compiled region would change HybridEP's combine, which DeepSeek-V3 also uses, so it is left for a follow-up. stack-info: PR: #6032, branch: fegin/stack/34
fegin
added a commit
that referenced
this pull request
Nov 11, 2026
## Summary (human-written) Muse Spark currently only supports AllToAll and Dist-MoE backends. The former is slow and the latter cannot be used on Hopper. This PR enables HybridEP. The main design decision is how to run `output_postprocess`, which Muse Spark uses to perform RMSNorm after the experts and before combine. With non-blocking HybridEP, the rows past the last expert offset are never written, so `output_postprocess` needs `torch.where` masks around it to keep those rows out of the forward and the gradients. The masks are slow in eager mode, so we use local_compile to fuse them into the RMSNorm kernels. See the performance section. TL;DR: with local_compile and CUDA graphs, we see about 60% higher TPS than AllToAll (note that the AllToAll performance is also improved after #6030). ## Why On Hopper, Dist-MoE is not available, so Muse Spark's only EP path is the AllToAll dispatcher. AllToAll syncs the CPU in every MoE layer, so it cannot use CUDA graphs. `MuseSparkMoE.Config` rejects HybridEP, which has no CPU sync in non-blocking mode and supports CUDA graphs. The check was added when the per-expert norm could only run after combine. `output_postprocess` (#4623) now runs it before combine, and HybridEP applies scores after it, so the operation order is right. Allowing HybridEP alone is not enough. Non-blocking HybridEP (`non_blocking_capacity_factor` set) sizes the routed rows to its capacity, not to the received token count. Rows past `offsets_E[-1]` are never written: in forward, the grouped GEMMs only write rows inside the expert offsets, and in backward, HybridEP's combine backward only writes grads for received tokens. So those rows hold stale memory in both directions. `output_postprocess` runs on every row, so its parameter grads sum over those rows. The result is a wrong grad, or NaN when the stale memory is not finite. Muse Spark is the only model that sets `output_postprocess`, so no other model hits this. **Example.** ```python config = muse_spark_debugmodel(seq_len) config = apply_transforms(config, [TokenDispatcherTransform( dispatcher=HybridEPTokenDispatcher, num_max_tokens_per_rank=tokens_per_microbatch // (cp * tp), kwargs={"non_blocking_capacity_factor": 1.0}, )]) # main: ValueError("Muse Spark MoE requires LocalTokenDispatcher or AllToAllTokenDispatcher, ...") # only the check removed: "Loss or gradient norm is not finite" at step 1 # this change: trains ``` The stale rows, at EP2, 64 tokens per rank, top-2, capacity factor 1.0, RMSNorm postprocess: ``` routed rows: 256, valid rows (offsets_E[-1]): 128 rows 128..255: stale inputs (abs max ~30) and nonzero incoming grads (abs max ~14) norm weight grad vs AllToAll: relative error 1.2 and 1.5 (all other grads bitwise equal) ``` ## What changed - Shared MoE (`models/common/moe/moe.py`, please review this first): with non-blocking HybridEP and an `output_postprocess`, `RoutedExperts.forward` calls `_masked_output_postprocess`. It masks rows past `offsets_E[-1]` with `torch.where` before the postprocess (finite forward) and after it (zero grad for those rows). `torch.where` instead of a multiply, so NaN rows are dropped too. The mask is built on the GPU from `offsets_E`, so there is no CPU sync and CUDA graph capture still works. The function is a `local_compile` region (`moe_masked_output_postprocess`), so Inductor fuses both masks into the postprocess kernels. Without the region it runs eagerly with the same math. In training, other dispatchers and blocking HybridEP never produce rows past the last offset, so they skip it. HybridEP `pad_multiple` padding rows are inside the offsets, and HybridEP writes zeros to them in both directions, so they need no mask. Dist-MoE does not use this forward. - Muse Spark enables the `moe_masked_output_postprocess` region in its default `local_compile.regions`. - `MuseSparkMoE.Config` accepts `HybridEPTokenDispatcher`. DeepEP stays rejected because it is untested with Muse Spark. - Add the `muse_spark_debugmodel_hybridep` test recipe with CUDA graphs on, like `deepseek_v3_debugmodel_hybridep`. Capacity factor 1.0 reserves the worst case, so no tokens are dropped. - Integration: add a Muse Spark FSDP2 + TP2 (SP) + EP2 run to the H100 HybridEP test, renamed from `deepseek_v3_fsdp+hybridep` to `fsdp+hybridep` because it covers both models. Mechanical: update the test name in `run_8xgpu_integration_tests.sh`, `validate_release_gpu.sh`, and `test_integration_test_definitions.py`. The last also checks every config of the test, not only the first. - README: list HybridEP as supported (verified with FSDP, TP+EP, and CUDA graphs; CP is not verified), say that on Hopper it is the EP path with CUDA graph support, give its memory cost (about 2x at capacity factor 1.0) and measured speedup, note its BF16 score rounding, and drop MinimalAsyncEP, which was deleted in #4627. ## Alternatives considered - Clean the rows inside HybridEP: only covers backward. The forward stale rows come from w2's grouped GEMM output. Masking in `RoutedExperts` handles both directions in one place. - Mask whenever `output_postprocess` is set: adds the mask cost to Muse Spark with AllToAll, which has no capacity rows. - A dispatcher property such as "may produce rows past the last offset": an interface with one implementer. The check follows the existing `DeepEPDispatchMetadata` branch in the same forward instead. - Reject non-blocking HybridEP with `output_postprocess`: blocking mode syncs the CPU in every MoE layer and cannot use CUDA graphs, which removes most of the reason to use HybridEP on Hopper. ## Numerics No change for other models or for Muse Spark with AllToAll: the mask only runs for non-blocking HybridEP with `output_postprocess`. Compiling the mask region does not change numerics: unfused masks vs the compiled region, `muse_spark_debugmodel_hybridep` on 4x H100, 20 steps, `scripts/loss_compare.py`: loss is bitwise identical at every step, and grad_norm matches. Muse Spark debug model, FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps, `scripts/loss_compare.py`, AllToAll (`muse_spark_debugmodel`) vs HybridEP (`muse_spark_debugmodel_hybridep`): | Step | AllToAll | HybridEP | Diff | | --- | --- | --- | --- | | 1 | 7.782996 | 7.783380 | +0.000383 | | 2 | 6.977194 | 6.979984 | +0.002790 | | 10 | 4.832992 | 4.837770 | +0.004778 | | 20 | 4.407280 | 4.412218 | +0.004938 | Average over 20 steps: 5.233406 vs 5.231284. The differences have no consistent sign. HybridEP rounds the routing scores to BF16 before the combine multiply, while AllToAll multiplies in FP32, and the two combine kernels sum in a different order. The README notes the BF16 rounding. ## Performance Scaled-up Muse Spark (dim 2048, 8 layers, 64 experts, top-8, compressed dim 1024, seq 4096) with the fused SwiGLU override, FSDP8 + EP8 on 8x H100, mean TPS over steps 11-30. All runs include the fused SwiGLU recompile fix earlier in this stack; without it, AllToAll runs at 2,138 TPS. | Config | TPS | Memory | | --- | --- | --- | | AllToAll | 18,624 | 7.7 GiB | | HybridEP eager, masks unfused | 18,618 | 16.7 GiB | | HybridEP eager, masks compiled | 21,439 (+15%) | 16.7 GiB | | HybridEP CUDA graphs, masks unfused | 24,777 | 16.8 GiB | | HybridEP CUDA graphs, masks compiled | 30,287 (+63%) | 16.8 GiB | - Most of the gain comes from CUDA graphs, which AllToAll cannot use. - Unfused, the masks run over all capacity rows (8x the valid rows at EP8 and top-8), and remat runs them again. Compiling them into the postprocess region removes that cost: +15% eager, +22% with graphs. - The extra memory comes from capacity factor 1.0. A lower factor saves memory but can drop tokens. ## Testing - `test_matches_all_to_all_with_output_postprocess` (new, 2x H100): HybridEP (blocking and non-blocking) vs AllToAll with an RMSNorm postprocess. Compares loss, input grad, and router, W13, W2, and norm weight grads within 2 BF16 eps (normwise). Without the mask it fails with errors of 12.5 and 8.8 vs bounds below 0.87. This is the regression it catches. - The HybridEP activation-checkpointing tests also run with an RMSNorm postprocess, as the DeepEP tests do, so remat replay stays exact around the mask. They run the mask function eagerly; the loss comparison above covers the compiled region. - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k HybridEP`: 4 passed. - Manual check: the parity test also passes with `pad_multiple=32`, with and without the postprocess. So the per-expert padding rows inside the offsets do not affect gradients. - `python -m tests.integration_tests.run_tests --test_suite h100 --execution_mode real_pg --ngpu 4 --test_name=fsdp+hybridep` (4x H100, HybridEP at the CI pin f725d29), CUDA graphs on: both configs pass and record a CUDA graph. The Muse Spark config (FSDP2 + TP2 + SP + EP2) keeps local compile on, so CI runs the compiled mask region. SPMD type checking would turn it off; Muse Spark TP+SP+EP type checking is covered by `muse_spark_mm_fsdp+tp+cp+ep+sp`. Muse Spark loss goes from about 7.7 to about 4.9-5.2 in 10 steps across three runs. - `pytest tests/unit_tests/cpu/test_integration_test_definitions.py tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py tests/unit_tests/cpu/config`: 263 passed, 3 xfailed. - `pytest tests/unit_tests/cpu -k "moe or expert or dispatcher or local_compile"`: 147 passed, 1 skipped. ## Known issues / follow-ups - CP + EP with HybridEP is not tested. - Multimodal training with CUDA graphs is not supported for Muse Spark with any dispatcher. - The score multiply in HybridEP's combine also runs over all capacity rows. Moving it into a compiled region would change HybridEP's combine, which DeepSeek-V3 also uses, so it is left for a follow-up. stack-info: PR: #6032, branch: fegin/stack/34
fegin
added a commit
that referenced
this pull request
Nov 12, 2026
## Summary (human-written) Muse Spark currently only supports AllToAll and Dist-MoE backends. The former is slow and the latter cannot be used on Hopper. This PR enables HybridEP. The main design decision is how to run `output_postprocess`, which Muse Spark uses to perform RMSNorm after the experts and before combine. With non-blocking HybridEP, the rows past the last expert offset are never written, so `output_postprocess` needs `torch.where` masks around it to keep those rows out of the forward and the gradients. The masks are slow in eager mode, so we use local_compile to fuse them into the RMSNorm kernels. See the performance section. TL;DR: with local_compile and CUDA graphs, we see about 60% higher TPS than AllToAll (note that the AllToAll performance is also improved after #6030). ## Why On Hopper, Dist-MoE is not available, so Muse Spark's only EP path is the AllToAll dispatcher. AllToAll syncs the CPU in every MoE layer, so it cannot use CUDA graphs. `MuseSparkMoE.Config` rejects HybridEP, which has no CPU sync in non-blocking mode and supports CUDA graphs. The check was added when the per-expert norm could only run after combine. `output_postprocess` (#4623) now runs it before combine, and HybridEP applies scores after it, so the operation order is right. Allowing HybridEP alone is not enough. Non-blocking HybridEP (`non_blocking_capacity_factor` set) sizes the routed rows to its capacity, not to the received token count. Rows past `offsets_E[-1]` are never written: in forward, the grouped GEMMs only write rows inside the expert offsets, and in backward, HybridEP's combine backward only writes grads for received tokens. So those rows hold stale memory in both directions. `output_postprocess` runs on every row, so its parameter grads sum over those rows. The result is a wrong grad, or NaN when the stale memory is not finite. Muse Spark is the only model that sets `output_postprocess`, so no other model hits this. **Example.** ```python config = muse_spark_debugmodel(seq_len) config = apply_transforms(config, [TokenDispatcherTransform( dispatcher=HybridEPTokenDispatcher, num_max_tokens_per_rank=tokens_per_microbatch // (cp * tp), kwargs={"non_blocking_capacity_factor": 1.0}, )]) # main: ValueError("Muse Spark MoE requires LocalTokenDispatcher or AllToAllTokenDispatcher, ...") # only the check removed: "Loss or gradient norm is not finite" at step 1 # this change: trains ``` The stale rows, at EP2, 64 tokens per rank, top-2, capacity factor 1.0, RMSNorm postprocess: ``` routed rows: 256, valid rows (offsets_E[-1]): 128 rows 128..255: stale inputs (abs max ~30) and nonzero incoming grads (abs max ~14) norm weight grad vs AllToAll: relative error 1.2 and 1.5 (all other grads bitwise equal) ``` ## What changed - Shared MoE (`models/common/moe/moe.py`, please review this first): with non-blocking HybridEP and an `output_postprocess`, `RoutedExperts.forward` calls `_masked_output_postprocess`. It masks rows past `offsets_E[-1]` with `torch.where` before the postprocess (finite forward) and after it (zero grad for those rows). `torch.where` instead of a multiply, so NaN rows are dropped too. The mask is built on the GPU from `offsets_E`, so there is no CPU sync and CUDA graph capture still works. The function is a `local_compile` region (`moe_masked_output_postprocess`), so Inductor fuses both masks into the postprocess kernels. Without the region it runs eagerly with the same math. In training, other dispatchers and blocking HybridEP never produce rows past the last offset, so they skip it. HybridEP `pad_multiple` padding rows are inside the offsets, and HybridEP writes zeros to them in both directions, so they need no mask. Dist-MoE does not use this forward. - Muse Spark enables the `moe_masked_output_postprocess` region in its default `local_compile.regions`. - `MuseSparkMoE.Config` accepts `HybridEPTokenDispatcher`. DeepEP stays rejected because it is untested with Muse Spark. - Add the `muse_spark_debugmodel_hybridep` test recipe with CUDA graphs on, like `deepseek_v3_debugmodel_hybridep`. Capacity factor 1.0 reserves the worst case, so no tokens are dropped. - Integration: add a Muse Spark FSDP2 + TP2 (SP) + EP2 run to the H100 HybridEP test, renamed from `deepseek_v3_fsdp+hybridep` to `fsdp+hybridep` because it covers both models. Mechanical: update the test name in `run_8xgpu_integration_tests.sh`, `validate_release_gpu.sh`, and `test_integration_test_definitions.py`. The last also checks every config of the test, not only the first. - README: list HybridEP as supported (verified with FSDP, TP+EP, and CUDA graphs; CP is not verified), say that on Hopper it is the EP path with CUDA graph support, give its memory cost (about 2x at capacity factor 1.0) and measured speedup, note its BF16 score rounding, and drop MinimalAsyncEP, which was deleted in #4627. ## Alternatives considered - Clean the rows inside HybridEP: only covers backward. The forward stale rows come from w2's grouped GEMM output. Masking in `RoutedExperts` handles both directions in one place. - Mask whenever `output_postprocess` is set: adds the mask cost to Muse Spark with AllToAll, which has no capacity rows. - A dispatcher property such as "may produce rows past the last offset": an interface with one implementer. The check follows the existing `DeepEPDispatchMetadata` branch in the same forward instead. - Reject non-blocking HybridEP with `output_postprocess`: blocking mode syncs the CPU in every MoE layer and cannot use CUDA graphs, which removes most of the reason to use HybridEP on Hopper. ## Numerics No change for other models or for Muse Spark with AllToAll: the mask only runs for non-blocking HybridEP with `output_postprocess`. Compiling the mask region does not change numerics: unfused masks vs the compiled region, `muse_spark_debugmodel_hybridep` on 4x H100, 20 steps, `scripts/loss_compare.py`: loss is bitwise identical at every step, and grad_norm matches. Muse Spark debug model, FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps, `scripts/loss_compare.py`, AllToAll (`muse_spark_debugmodel`) vs HybridEP (`muse_spark_debugmodel_hybridep`): | Step | AllToAll | HybridEP | Diff | | --- | --- | --- | --- | | 1 | 7.782996 | 7.783380 | +0.000383 | | 2 | 6.977194 | 6.979984 | +0.002790 | | 10 | 4.832992 | 4.837770 | +0.004778 | | 20 | 4.407280 | 4.412218 | +0.004938 | Average over 20 steps: 5.233406 vs 5.231284. The differences have no consistent sign. HybridEP rounds the routing scores to BF16 before the combine multiply, while AllToAll multiplies in FP32, and the two combine kernels sum in a different order. The README notes the BF16 rounding. ## Performance Scaled-up Muse Spark (dim 2048, 8 layers, 64 experts, top-8, compressed dim 1024, seq 4096) with the fused SwiGLU override, FSDP8 + EP8 on 8x H100, mean TPS over steps 11-30. All runs include the fused SwiGLU recompile fix earlier in this stack; without it, AllToAll runs at 2,138 TPS. | Config | TPS | Memory | | --- | --- | --- | | AllToAll | 18,624 | 7.7 GiB | | HybridEP eager, masks unfused | 18,618 | 16.7 GiB | | HybridEP eager, masks compiled | 21,439 (+15%) | 16.7 GiB | | HybridEP CUDA graphs, masks unfused | 24,777 | 16.8 GiB | | HybridEP CUDA graphs, masks compiled | 30,287 (+63%) | 16.8 GiB | - Most of the gain comes from CUDA graphs, which AllToAll cannot use. - Unfused, the masks run over all capacity rows (8x the valid rows at EP8 and top-8), and remat runs them again. Compiling them into the postprocess region removes that cost: +15% eager, +22% with graphs. - The extra memory comes from capacity factor 1.0. A lower factor saves memory but can drop tokens. ## Testing - The HybridEP activation-checkpointing tests also run with an RMSNorm postprocess, as the DeepEP tests do, so remat replay stays exact around the mask. The shared test helper also compares each HybridEP run (blocking and non-blocking) with an AllToAll reference: loss, input grad, and router, W13, W2, and norm weight grads within 2 BF16 eps (normwise). It builds this reference the same way it builds the post-W2 scoring reference for DeepEP. Without the mask, the comparison fails (NaN vs a bound of 0.87). This is the regression it catches. The tests run the mask function eagerly; the loss comparison above covers the compiled region. - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k HybridEP`: 3 passed. With DeepEP v2: `-k DeepEP`, 2 passed. - Manual check: the AllToAll comparison also passes with `pad_multiple=32`, with and without the postprocess. So the per-expert padding rows inside the offsets do not affect gradients. - `python -m tests.integration_tests.run_tests --test_suite h100 --execution_mode real_pg --ngpu 4 --test_name=fsdp+hybridep` (4x H100, HybridEP at the CI pin f725d29), CUDA graphs on: both configs pass and record a CUDA graph. The Muse Spark config (FSDP2 + TP2 + SP + EP2) keeps local compile on, so CI runs the compiled mask region. SPMD type checking would turn it off; Muse Spark TP+SP+EP type checking is covered by `muse_spark_mm_fsdp+tp+cp+ep+sp`. Muse Spark loss goes from about 7.7 to about 4.9-5.2 in 10 steps across three runs. - `pytest tests/unit_tests/cpu/test_integration_test_definitions.py tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py tests/unit_tests/cpu/config`: 263 passed, 3 xfailed. - `pytest tests/unit_tests/cpu -k "moe or expert or dispatcher or local_compile"`: 147 passed, 1 skipped. ## Known issues / follow-ups - CP + EP with HybridEP is not tested. - Multimodal training with CUDA graphs is not supported for Muse Spark with any dispatcher. - The score multiply in HybridEP's combine also runs over all capacity rows. Moving it into a compiled region would change HybridEP's combine, which DeepSeek-V3 also uses, so it is left for a follow-up. stack-info: PR: #6032, branch: fegin/stack/34
fegin
added a commit
that referenced
this pull request
Nov 12, 2026
## Summary (human-written) Muse Spark currently only supports AllToAll and Dist-MoE backends. The former is slow and the latter cannot be used on Hopper. This PR enables HybridEP. The main design decision is how to run `output_postprocess`, which Muse Spark uses to perform RMSNorm after the experts and before combine. With non-blocking HybridEP, the rows past the last expert offset are never written, so `output_postprocess` needs `torch.where` masks around it to keep those rows out of the forward and the gradients. The masks are slow in eager mode, so we use local_compile to fuse them into the RMSNorm kernels. See the performance section. TL;DR: with local_compile and CUDA graphs, we see about 60% higher TPS than AllToAll (note that the AllToAll performance is also improved after #6030). ## Why On Hopper, Dist-MoE is not available, so Muse Spark's only EP path is the AllToAll dispatcher. AllToAll syncs the CPU in every MoE layer, so it cannot use CUDA graphs. `MuseSparkMoE.Config` rejects HybridEP, which has no CPU sync in non-blocking mode and supports CUDA graphs. The check was added when the per-expert norm could only run after combine. `output_postprocess` (#4623) now runs it before combine, and HybridEP applies scores after it, so the operation order is right. Allowing HybridEP alone is not enough. Non-blocking HybridEP (`non_blocking_capacity_factor` set) sizes the routed rows to its capacity, not to the received token count. Rows past `offsets_E[-1]` are never written: in forward, the grouped GEMMs only write rows inside the expert offsets, and in backward, HybridEP's combine backward only writes grads for received tokens. So those rows hold stale memory in both directions. `output_postprocess` runs on every row, so its parameter grads sum over those rows. The result is a wrong grad, or NaN when the stale memory is not finite. Muse Spark is the only model that sets `output_postprocess`, so no other model hits this. **Example.** ```python config = muse_spark_debugmodel(seq_len) config = apply_transforms(config, [TokenDispatcherTransform( dispatcher=HybridEPTokenDispatcher, num_max_tokens_per_rank=tokens_per_microbatch // (cp * tp), kwargs={"non_blocking_capacity_factor": 1.0}, )]) # main: ValueError("Muse Spark MoE requires LocalTokenDispatcher or AllToAllTokenDispatcher, ...") # only the check removed: "Loss or gradient norm is not finite" at step 1 # this change: trains ``` The stale rows, at EP2, 64 tokens per rank, top-2, capacity factor 1.0, RMSNorm postprocess: ``` routed rows: 256, valid rows (offsets_E[-1]): 128 rows 128..255: stale inputs (abs max ~30) and nonzero incoming grads (abs max ~14) norm weight grad vs AllToAll: relative error 1.2 and 1.5 (all other grads bitwise equal) ``` ## What changed - Shared MoE (`models/common/moe/moe.py`, please review this first): with non-blocking HybridEP and an `output_postprocess`, `RoutedExperts.forward` calls `_masked_output_postprocess`. It masks rows past `offsets_E[-1]` with `torch.where` before the postprocess (finite forward) and after it (zero grad for those rows). `torch.where` instead of a multiply, so NaN rows are dropped too. The mask is built on the GPU from `offsets_E`, so there is no CPU sync and CUDA graph capture still works. The function is a `local_compile` region (`moe_masked_output_postprocess`), so Inductor fuses both masks into the postprocess kernels. Without the region it runs eagerly with the same math. In training, other dispatchers and blocking HybridEP never produce rows past the last offset, so they skip it. HybridEP `pad_multiple` padding rows are inside the offsets, and HybridEP writes zeros to them in both directions, so they need no mask. Dist-MoE does not use this forward. - Muse Spark enables the `moe_masked_output_postprocess` region in its default `local_compile.regions`. - `MuseSparkMoE.Config` accepts `HybridEPTokenDispatcher`. DeepEP stays rejected because it is untested with Muse Spark. - Add the `muse_spark_debugmodel_hybridep` test recipe with CUDA graphs on, like `deepseek_v3_debugmodel_hybridep`. Capacity factor 1.0 reserves the worst case, so no tokens are dropped. - Integration: add a Muse Spark FSDP2 + TP2 (SP) + EP2 run to the H100 HybridEP test, renamed from `deepseek_v3_fsdp+hybridep` to `fsdp+hybridep` because it covers both models. Mechanical: update the test name in `run_8xgpu_integration_tests.sh`, `validate_release_gpu.sh`, and `test_integration_test_definitions.py`. The last also checks every config of the test, not only the first. - README: list HybridEP as supported (verified with FSDP, TP+EP, Ulysses CP+EP, and CUDA graphs), say that on Hopper it is the EP path with CUDA graph support, give its memory cost (about 2x at capacity factor 1.0) and measured speedup, note its BF16 score rounding, and drop MinimalAsyncEP, which was deleted in #4627. ## Alternatives considered - Clean the rows inside HybridEP: only covers backward. The forward stale rows come from w2's grouped GEMM output. Masking in `RoutedExperts` handles both directions in one place. - Mask whenever `output_postprocess` is set: adds the mask cost to Muse Spark with AllToAll, which has no capacity rows. - A dispatcher property such as "may produce rows past the last offset": an interface with one implementer. The check follows the existing `DeepEPDispatchMetadata` branch in the same forward instead. - Reject non-blocking HybridEP with `output_postprocess`: blocking mode syncs the CPU in every MoE layer and cannot use CUDA graphs, which removes most of the reason to use HybridEP on Hopper. ## Numerics No change for other models or for Muse Spark with AllToAll: the mask only runs for non-blocking HybridEP with `output_postprocess`. Compiling the mask region does not change numerics: unfused masks vs the compiled region, `muse_spark_debugmodel_hybridep` on 4x H100, 20 steps, `scripts/loss_compare.py`: loss is bitwise identical at every step, and grad_norm matches. Muse Spark debug model, FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps, `scripts/loss_compare.py`, AllToAll (`muse_spark_debugmodel`) vs HybridEP (`muse_spark_debugmodel_hybridep`): | Step | AllToAll | HybridEP | Diff | | --- | --- | --- | --- | | 1 | 7.782996 | 7.783380 | +0.000383 | | 2 | 6.977194 | 6.979984 | +0.002790 | | 10 | 4.832992 | 4.837770 | +0.004778 | | 20 | 4.407280 | 4.412218 | +0.004938 | Average over 20 steps: 5.233406 vs 5.231284. The differences have no consistent sign. HybridEP rounds the routing scores to BF16 before the combine multiply, while AllToAll multiplies in FP32, and the two combine kernels sum in a different order. The README notes the BF16 rounding. ## Performance Scaled-up Muse Spark (dim 2048, 8 layers, 64 experts, top-8, compressed dim 1024, seq 4096) with the fused SwiGLU override, FSDP8 + EP8 on 8x H100, mean TPS over steps 11-30. All runs include the fused SwiGLU recompile fix earlier in this stack; without it, AllToAll runs at 2,138 TPS. | Config | TPS | Memory | | --- | --- | --- | | AllToAll | 18,624 | 7.7 GiB | | HybridEP eager, masks unfused | 18,618 | 16.7 GiB | | HybridEP eager, masks compiled | 21,439 (+15%) | 16.7 GiB | | HybridEP CUDA graphs, masks unfused | 24,777 | 16.8 GiB | | HybridEP CUDA graphs, masks compiled | 30,287 (+63%) | 16.8 GiB | - Most of the gain comes from CUDA graphs, which AllToAll cannot use. - Unfused, the masks run over all capacity rows (8x the valid rows at EP8 and top-8), and remat runs them again. Compiling them into the postprocess region removes that cost: +15% eager, +22% with graphs. - The extra memory comes from capacity factor 1.0. A lower factor saves memory but can drop tokens. ## Testing - The HybridEP activation-checkpointing tests also run with an RMSNorm postprocess, as the DeepEP tests do, so remat replay stays exact around the mask. The shared test helper also compares each HybridEP run (blocking and non-blocking) with an AllToAll reference: loss, input grad, and router, W13, W2, and norm weight grads within 2 BF16 eps (normwise). It builds this reference the same way it builds the post-W2 scoring reference for DeepEP. Without the mask, the comparison fails (NaN vs a bound of 0.87). This is the regression it catches. The tests run the mask function eagerly; the loss comparison above covers the compiled region. - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k HybridEP`: 3 passed. With DeepEP v2: `-k DeepEP`, 2 passed. - Manual check: the AllToAll comparison also passes with `pad_multiple=32`, with and without the postprocess. So the per-expert padding rows inside the offsets do not affect gradients. - `python -m tests.integration_tests.run_tests --test_suite h100 --execution_mode real_pg --ngpu 4 --test_name=fsdp+hybridep` (4x H100, HybridEP at the CI pin f725d29), CUDA graphs on: both configs pass and record a CUDA graph. The Muse Spark config (FSDP2 + TP2 + SP + EP2) keeps local compile on, so CI runs the compiled mask region. SPMD type checking would turn it off; Muse Spark TP+SP+EP type checking is covered by `muse_spark_mm_fsdp+tp+cp+ep+sp`. Muse Spark loss goes from about 7.7 to about 4.9-5.2 in 10 steps across three runs. - Muse Spark debugmodel, FSDP2 + Ulysses CP2 + EP4 (4x H100), seed 42, deterministic, 20 steps. Loss at steps 1 / 10 / 20: HybridEP (capacity 1.0) 7.77302 / 4.83989 / 4.40672, AllToAll 7.77313 / 4.84151 / 4.41106. HybridEP with CUDA graphs prints the same loss as without them. - `pytest tests/unit_tests/cpu/test_integration_test_definitions.py tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py tests/unit_tests/cpu/config`: 263 passed, 3 xfailed. - `pytest tests/unit_tests/cpu -k "moe or expert or dispatcher or local_compile"`: 147 passed, 1 skipped. ## Known issues / follow-ups - Multimodal training with CUDA graphs is not supported for Muse Spark with any dispatcher. - The score multiply in HybridEP's combine also runs over all capacity rows. Moving it into a compiled region would change HybridEP's combine, which DeepSeek-V3 also uses, so it is left for a follow-up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
as it is not maintained, e.g. #4588
HybridEP backend will be deprecated once DistMoE is available.