Repository navigation
[muse_spark] Support DeepEP expert parallelism - #6037
Conversation
## 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
`MuseSparkMoE.Config` rejects `DeepEPTokenDispatcher`, but nothing in Muse Spark needs that. The shared MoE code already supports DeepEP with an `output_postprocess`:
- In training, DeepEP uses its compact, host-synced path. The routed rows match the received token counts, so there are no rows past the last expert offset, and the HybridEP mask from #6032 is not needed.
- `RoutedExperts.forward` already applies the DeepEP routing scores after the postprocess, because Muse Spark's per-expert RMSNorm is nonlinear and must run first.
DeepEP is the EP backend that `search_r1` uses for both its trainer and its CUDA-graphed generator (expand layout), so this also unblocks Muse Spark RL on Hopper.
## What changed
- `MuseSparkMoE.Config` accepts `DeepEPTokenDispatcher`. `TorchAOTokenDispatcher` stays rejected.
- README: list DeepEP as supported. Note that training needs CUDA graphs disabled, and that DeepEP's combine kernel needs the MoE compressed dimension to be a multiple of 256. The production flavors use 4096. `debugmodel` uses 128, so it cannot run with DeepEP.
## Alternatives considered
- Add a `muse_spark_debugmodel_deepep` recipe and an integration test: `debugmodel` cannot run DeepEP (compressed dimension 128), and changing the debug flavor would change every Muse Spark debug run and golden loss.
- Validate the hidden size in `DeepEPTokenDispatcher.Config`: today a bad size fails at the first forward with DeepEP's static assert ("Invalid hidden"). A config-time check belongs to DeepEP in shared code, so it is left for a separate PR.
## Numerics
Muse Spark debug model with compressed dimension 256 (a local config change, see above), FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps:
| Step | AllToAll | DeepEP |
| --- | --- | --- |
| 1 | 7.75888 | 7.75888 |
| 2 | 6.82995 | 6.83072 |
| 10 | 4.81295 | 4.81803 |
| 20 | 4.40471 | 4.39651 |
Average over 20 steps: 5.18424 vs 5.18254. Step 1 matches. Later steps differ by the combine kernels' summation order, with no consistent sign.
Unit check, the RMSNorm postprocess setup from `test_matches_all_to_all_with_output_postprocess` with DeepEP instead of HybridEP (2x H100): loss, input grad, and router, W13, W2, and norm weight grads match AllToAll within relative error 4.7e-3, below the 1.56e-2 bound. Loss and the expert and norm weight grads are bitwise equal.
## Performance
Not reported. DeepEP's expected benefit is multi-node communication, and I only have single-node H100 runs, which would not show it.
## Testing
- `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k DeepEP` with DeepEP v2 at the CI pin 01dc3aa: 2 passed. These tests already run with an RMSNorm postprocess and check the score order against a reference.
- No new test. The existing DeepEP tests cover the postprocess path, and the unit check above was a one-off run.
- `pytest tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py`: 40 passed, 3 xfailed.
stack-info: PR: #6037, branch: fegin/stack/35
2f50b7a to
491e32c
Compare
|
@claude review this PR |
491e32c to
0dfea8f
Compare
## Summary (human-written) As title. Enabling DeepEP for Muse Spark is trivial, performance is not verified though. ## Why `MuseSparkMoE.Config` rejects `DeepEPTokenDispatcher`, but nothing in Muse Spark needs that. The shared MoE code already supports DeepEP with an `output_postprocess`: - In training, DeepEP uses its compact, host-synced path. The routed rows match the received token counts, so there are no rows past the last expert offset, and the HybridEP mask from #6032 is not needed. - `RoutedExperts.forward` already applies the DeepEP routing scores after the postprocess, because Muse Spark's per-expert RMSNorm is nonlinear and must run first. DeepEP is the EP backend that `search_r1` uses for both its trainer and its CUDA-graphed generator (expand layout), so this also unblocks Muse Spark RL on Hopper. ## What changed - `MuseSparkMoE.Config` accepts `DeepEPTokenDispatcher`. `TorchAOTokenDispatcher` stays rejected. - README: list DeepEP as supported. Note that training needs CUDA graphs disabled, and that DeepEP's combine kernel needs the MoE compressed dimension to be a multiple of 256. The production flavors use 4096. `debugmodel` uses 128, so it cannot run with DeepEP. ## Alternatives considered - Add a `muse_spark_debugmodel_deepep` recipe and an integration test: `debugmodel` cannot run DeepEP (compressed dimension 128), and changing the debug flavor would change every Muse Spark debug run and golden loss. - Validate the hidden size in `DeepEPTokenDispatcher.Config`: today a bad size fails at the first forward with DeepEP's static assert ("Invalid hidden"). A config-time check belongs to DeepEP in shared code, so it is left for a separate PR. ## Numerics Muse Spark debug model with compressed dimension 256 (a local config change, see above), FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps: | Step | AllToAll | DeepEP | | --- | --- | --- | | 1 | 7.75888 | 7.75888 | | 2 | 6.82995 | 6.83072 | | 10 | 4.81295 | 4.81803 | | 20 | 4.40471 | 4.39651 | Average over 20 steps: 5.18424 vs 5.18254. Step 1 matches. Later steps differ by the combine kernels' summation order, with no consistent sign. Unit check, the RMSNorm postprocess setup from `test_matches_all_to_all_with_output_postprocess` with DeepEP instead of HybridEP (2x H100): loss, input grad, and router, W13, W2, and norm weight grads match AllToAll within relative error 4.7e-3, below the 1.56e-2 bound. Loss and the expert and norm weight grads are bitwise equal. ## Performance Not reported. DeepEP's expected benefit is multi-node communication, and I only have single-node H100 runs, which would not show it. ## Testing - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k DeepEP` with DeepEP v2 at the CI pin 01dc3aa: 2 passed. These tests already run with an RMSNorm postprocess and check the score order against a reference. - No new test. The existing DeepEP tests cover the postprocess path, and the unit check above was a one-off run. - `pytest tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py`: 40 passed, 3 xfailed. stack-info: PR: #6037, branch: fegin/stack/35
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The shared RoutedExperts already handles DeepEP with an output postprocess, so Muse Spark only needs to stop rejecting DeepEP.
What this PR does. MuseSparkMoE.Config.__post_init__ now accepts DeepEPTokenDispatcher (TorchAOTokenDispatcher is still rejected). The README now lists DeepEP as supported and explains its limits: no training CUDA graphs, and the compressed dim must be a multiple of 256.
Example.
apply_transforms(muse_spark_config, [TokenDispatcherTransform(
dispatcher=DeepEPTokenDispatcher, num_max_tokens_per_rank=N)])
# before: ValueError("Muse Spark MoE requires LocalTokenDispatcher, AllToAll..., or HybridEP...")
# after: builds. hidden_dim = w13.in_features = compressed_dim (4096 in production).
# RoutedExperts runs w2 without scores -> RMSNorm postprocess -> * scores_R -> combine
# (models/common/moe/moe.py:172-209)Must fix
- PR description: the "Summary (human-written)" section is empty. The one-line note above the template ("Enabling DeepEP for Muse Spark is trivial, performance is not verified though") reads like that summary. Please move it into the section.
torchtitan/models/muse_spark/README.md:138-141: note that CP is not verified with DeepEP, and add a TODO for the config-time hidden-dim check (inline).
Should consider
torchtitan/models/muse_spark/README.md:109: add DeepEP to the CUDA graphs row of the table (inline, with a suggestion).- Description, "unblocks Muse Spark RL on Hopper": the generator uses the expand layout (
cuda_graph_compatible=True), and nothing has run Muse Spark through it. The argument in "Why" that the HybridEP mask isn't needed covers only the training (compact) path. The expand layout has an unused tail pastoffsets_E[-1](distributed/deepep/deepep.py:160-161), and the RMSNorm postprocess runs over it. That looks harmless: the generator runs under no_grad, and Qwen3's w2 tail already reaches combine the same way. Still, either run the generator once or reword the claim to "should unblock".
Details
- Gate: the problem is real, since the old
__post_init__raised for DeepEP. The fix sits in the model folder and changes no shared code. #5708 (DeepEP training on the expand layout) is still open. It keepsdo_cpu_sync=Truefor training, so the received rows stay exactly sized and the "no tail rows in training" argument still holds after it lands. - Training graphs:
validate_model_training_compatibilityalready raises for DeepEP when accelerator graphs are on with EP > 1 (config/validation.py:109-125), so the README note matches what the code enforces. - Score order: with a postprocess,
RoutedExperts.forwardcalls w2 withoutscores_Rand multiplies by the scores after the postprocess (moe.py:172-209), which is correct for the nonlinear per-expert norm. - Buffer sizing:
TokenDispatcherTransformsetshidden_dimfromw13.in_features(config/transform/token_dispatcher.py:66-67), so DeepEP's buffer gets the compressed dim, not the model dim. - No new test: agreed. Debug flavor dim 128 can't run DeepEP, and
test_deepep_activation_checkpoint.pyalready covers the postprocess path.
Not verified: the multi-GPU numerics, the generator expand path for Muse Spark, and DeepEP's multiple-of-256 hidden constraint. A maintainer still needs to review.
| @@ -108,7 +108,6 @@ Both production and debug flavors use MoE in every layer. | |||
| | Model compilation | Regional compilation | | |||
| | CUDA graphs | Text-only with Dist-MoE or HybridEP; multimodal support is a TorchTitan gap; standard all-to-all EP requires graphs to be disabled | | |||
There was a problem hiding this comment.
This table row is what users read to check CUDA graph support, and it still doesn't mention DeepEP. DeepEP training also needs graphs disabled, since it takes the host-synced compact path. validate_model_training_compatibility (torchtitan/config/validation.py:109-125) already rejects it. Suggest adding it to the row:
| | CUDA graphs | Text-only with Dist-MoE or HybridEP; multimodal support is a TorchTitan gap; standard all-to-all EP requires graphs to be disabled | | |
| | CUDA graphs | Text-only with Dist-MoE or HybridEP; multimodal support is a TorchTitan gap; standard all-to-all EP and DeepEP training require graphs to be disabled | |
| DeepEP uses its compact, host-synced path in training, so CUDA graphs must be | ||
| disabled. Its combine kernel requires the MoE compressed dimension to be a | ||
| multiple of 256: the production flavors use 4096, but `debugmodel` uses 128 and | ||
| cannot run with DeepEP. DeepEP is verified with FSDP and with TP+EP. |
There was a problem hiding this comment.
Two small doc gaps, compared with the HybridEP paragraph just above:
- CP isn't covered. The numerics run used FSDP2 + TP2 + EP2 with no CP, so add "CP is not verified with DeepEP." to match line 133-134.
- "
debugmodel... cannot run with DeepEP" is a known-unsupported configuration that is only documented. It fails at the first forward with DeepEP's "Invalid hidden" assert, not at config time. You already leave the config-time check for a follow-up. That's fine because the failure is loud, but please add a TODO here pointing at it so it doesn't get lost. The natural place for the check isDeepEPTokenDispatcher.Config.__post_init__onhidden_dim, whichTokenDispatcherTransformfills fromw13.in_features, i.e. the compressed dim.
(Not verified: the multiple-of-256 requirement itself. I couldn't check it against DeepEP's kernel without a GPU build.)
a637fb2 to
3563999
Compare
## Summary (human-written) As title. Enabling DeepEP for Muse Spark is trivial, performance is not verified though. ## Why `MuseSparkMoE.Config` rejects `DeepEPTokenDispatcher`, but nothing in Muse Spark needs that. The shared MoE code already supports DeepEP with an `output_postprocess`: - In training, DeepEP uses its compact, host-synced path. The routed rows match the received token counts, so there are no rows past the last expert offset, and the HybridEP mask from #6032 is not needed. - `RoutedExperts.forward` already applies the DeepEP routing scores after the postprocess, because Muse Spark's per-expert RMSNorm is nonlinear and must run first. DeepEP is the EP backend that `search_r1` uses for both its trainer and its CUDA-graphed generator (expand layout), so this also unblocks Muse Spark RL on Hopper. ## What changed - `MuseSparkMoE.Config` accepts `DeepEPTokenDispatcher`. `TorchAOTokenDispatcher` stays rejected. - README: list DeepEP as supported. Note that training needs CUDA graphs disabled, and that DeepEP's combine kernel needs the MoE compressed dimension to be a multiple of 256. The production flavors use 4096. `debugmodel` uses 128, so it cannot run with DeepEP. ## Alternatives considered - Add a `muse_spark_debugmodel_deepep` recipe and an integration test: `debugmodel` cannot run DeepEP (compressed dimension 128), and changing the debug flavor would change every Muse Spark debug run and golden loss. - Validate the hidden size in `DeepEPTokenDispatcher.Config`: today a bad size fails at the first forward with DeepEP's static assert ("Invalid hidden"). A config-time check belongs to DeepEP in shared code, so it is left for a separate PR. ## Numerics Muse Spark debug model with compressed dimension 256 (a local config change, see above), FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps: | Step | AllToAll | DeepEP | | --- | --- | --- | | 1 | 7.75888 | 7.75888 | | 2 | 6.82995 | 6.83072 | | 10 | 4.81295 | 4.81803 | | 20 | 4.40471 | 4.39651 | Average over 20 steps: 5.18424 vs 5.18254. Step 1 matches. Later steps differ by the combine kernels' summation order, with no consistent sign. Unit check, the RMSNorm postprocess setup from `test_matches_all_to_all_with_output_postprocess` with DeepEP instead of HybridEP (2x H100): loss, input grad, and router, W13, W2, and norm weight grads match AllToAll within relative error 4.7e-3, below the 1.56e-2 bound. Loss and the expert and norm weight grads are bitwise equal. ## Performance Not reported. DeepEP's expected benefit is multi-node communication, and I only have single-node H100 runs, which would not show it. ## Testing - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k DeepEP` with DeepEP v2 at the CI pin 01dc3aa: 2 passed. These tests already run with an RMSNorm postprocess and check the score order against a reference. - No new test. The existing DeepEP tests cover the postprocess path, and the unit check above was a one-off run. - `pytest tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py`: 40 passed, 3 xfailed. stack-info: PR: #6037, branch: fegin/stack/35
0dfea8f to
bcbcf29
Compare
cd2e60d to
423f559
Compare
## Summary (human-written) As title. Enabling DeepEP for Muse Spark is trivial, performance is not verified though. ## Why `MuseSparkMoE.Config` rejects `DeepEPTokenDispatcher`, but nothing in Muse Spark needs that. The shared MoE code already supports DeepEP with an `output_postprocess`: - In training, DeepEP uses its compact, host-synced path. The routed rows match the received token counts, so there are no rows past the last expert offset, and the HybridEP mask from #6032 is not needed. - `RoutedExperts.forward` already applies the DeepEP routing scores after the postprocess, because Muse Spark's per-expert RMSNorm is nonlinear and must run first. DeepEP is the EP backend that `search_r1` uses for both its trainer and its CUDA-graphed generator (expand layout), so this should also unblock Muse Spark RL on Hopper. I have not run the generator's expand layout with Muse Spark. ## What changed - `MuseSparkMoE.Config` accepts `DeepEPTokenDispatcher`. `TorchAOTokenDispatcher` stays rejected. - README: list DeepEP as supported, and add it to the CUDA graphs row: training needs graphs disabled. Note that CP is not verified with DeepEP, and that DeepEP's combine kernel needs the MoE compressed dimension to be a multiple of 256. Add a TODO for the config-time check. The production flavors use 4096. `debugmodel` uses 128, so it cannot run with DeepEP. ## Alternatives considered - Add a `muse_spark_debugmodel_deepep` recipe and an integration test: `debugmodel` cannot run DeepEP (compressed dimension 128), and changing the debug flavor would change every Muse Spark debug run and golden loss. - Validate the hidden size in `DeepEPTokenDispatcher.Config`: today a bad size fails at the first forward with DeepEP's static assert ("Invalid hidden"). A config-time check belongs to DeepEP in shared code, so it is left for a separate PR. ## Numerics Muse Spark debug model with compressed dimension 256 (a local config change, see above), FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps: | Step | AllToAll | DeepEP | | --- | --- | --- | | 1 | 7.75888 | 7.75888 | | 2 | 6.82995 | 6.83072 | | 10 | 4.81295 | 4.81803 | | 20 | 4.40471 | 4.39651 | Average over 20 steps: 5.18424 vs 5.18254. Step 1 matches. Later steps differ by the combine kernels' summation order, with no consistent sign. One-off unit check, the AllToAll comparison from the HybridEP tests run with DeepEP and an RMSNorm postprocess (2x H100): loss, input grad, and router, W13, W2, and norm weight grads match AllToAll within relative error 4.7e-3, below the 1.56e-2 bound. Loss and the expert and norm weight grads are bitwise equal. ## Performance Not reported. DeepEP's expected benefit is multi-node communication, and I only have single-node H100 runs, which would not show it. ## Testing - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k DeepEP` with DeepEP v2 at the CI pin 01dc3aa: 2 passed. These tests already run with an RMSNorm postprocess and check the score order against a reference. - No new test. The existing DeepEP tests cover the postprocess path, and the unit check above was a one-off run. - `pytest tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py`: 40 passed, 3 xfailed. stack-info: PR: #6037, branch: fegin/stack/35
92dca1b to
f9b3a04
Compare
## Summary (human-written) As title. Enabling DeepEP for Muse Spark is trivial, performance is not verified though. ## Why `MuseSparkMoE.Config` rejects `DeepEPTokenDispatcher`, but nothing in Muse Spark needs that. The shared MoE code already supports DeepEP with an `output_postprocess`: - In training, DeepEP uses its compact, host-synced path. The routed rows match the received token counts, so there are no rows past the last expert offset, and the HybridEP mask from #6032 is not needed. - `RoutedExperts.forward` already applies the DeepEP routing scores after the postprocess, because Muse Spark's per-expert RMSNorm is nonlinear and must run first. DeepEP is the EP backend that `search_r1` uses for both its trainer and its CUDA-graphed generator (expand layout), so this should also unblock Muse Spark RL on Hopper. I have not run the generator's expand layout with Muse Spark. ## What changed - `MuseSparkMoE.Config` accepts `DeepEPTokenDispatcher`. `TorchAOTokenDispatcher` stays rejected. - README: list DeepEP as supported, and add it to the CUDA graphs row: training needs graphs disabled. Note that DeepEP's combine kernel needs the MoE compressed dimension to be a multiple of 256. Add a TODO for the config-time check. The production flavors use 4096. `debugmodel` uses 128, so it cannot run with DeepEP. ## Alternatives considered - Add a `muse_spark_debugmodel_deepep` recipe and an integration test: `debugmodel` cannot run DeepEP (compressed dimension 128), and changing the debug flavor would change every Muse Spark debug run and golden loss. - Validate the hidden size in `DeepEPTokenDispatcher.Config`: today a bad size fails at the first forward with DeepEP's static assert ("Invalid hidden"). A config-time check belongs to DeepEP in shared code, so it is left for a separate PR. ## Numerics Muse Spark debug model with compressed dimension 256 (a local config change, see above), FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps: | Step | AllToAll | DeepEP | | --- | --- | --- | | 1 | 7.75888 | 7.75888 | | 2 | 6.82995 | 6.83072 | | 10 | 4.81295 | 4.81803 | | 20 | 4.40471 | 4.39651 | Average over 20 steps: 5.18424 vs 5.18254. Step 1 matches. Later steps differ by the combine kernels' summation order, with no consistent sign. One-off unit check, the AllToAll comparison from the HybridEP tests run with DeepEP and an RMSNorm postprocess (2x H100): loss, input grad, and router, W13, W2, and norm weight grads match AllToAll within relative error 4.7e-3, below the 1.56e-2 bound. Loss and the expert and norm weight grads are bitwise equal. ## Performance Not reported. DeepEP's expected benefit is multi-node communication, and I only have single-node H100 runs, which would not show it. ## Testing - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k DeepEP` with DeepEP v2 at the CI pin 01dc3aa: 2 passed. These tests already run with an RMSNorm postprocess and check the score order against a reference. - Muse Spark debugmodel with compressed_dim 256, FSDP2 + Ulysses CP2 + EP4 (4x H100), seed 42, deterministic, 20 steps. Loss at steps 1 / 10 / 20: DeepEP 7.74766 / 4.80887 / 4.40117, AllToAll 7.74766 / 4.80533 / 4.39565. - No new test. The existing DeepEP tests cover the postprocess path, and the unit check above was a one-off run. - `pytest tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py`: 40 passed, 3 xfailed. stack-info: PR: #6037, branch: fegin/stack/35
f9b3a04 to
ae898ea
Compare
There was a problem hiding this comment.
oh we don't have to worry about https://github.com/pytorch/torchtitan/pull/6032/changes#r4544302973 for all DeepEP v2 modes? I vaguely remember that they have low-latency mode where a capacity factor needs to be given?
Please make sure it works with this setting, if we swap the model to be Muse Spark which has output_processor
torchtitan/torchtitan_recipes/rl/search_r1.py
Lines 336 to 352 in 1568307
There was a problem hiding this comment.
I see. I need to check other cases. The tests locally didn't get any issue. Will check
There was a problem hiding this comment.
@tianyu-l Double check, the mask is used to avoid 1) stale memory leaking into the backward, 2) forward uses the stale memory. RL case doesn't have 1 and DeepEP doesn't have 2. So we don't need mask for DeepEP.
There was a problem hiding this comment.
when you say
RL case doesn't have 1
RL indeed has backward. Are you saying one of the following?
- the low-latency mode of deepep doesn't support backward, so it cannot be used for trainer (my impression was this one)
- the low-latency mode of deepep can be used for training, but somehow it doesn't leak stale memory into backward (if so, how could it be not leaking?)
Please add comments in code, somewhere
There was a problem hiding this comment.
Sorry for the ambiguous wording, RL doesn't use the DeepEP expand (low-latency) layout because it doesn't support backward -- the kernel will assert. Agent added a comment in moe.py.
## Summary (human-written) As title. Enabling DeepEP for Muse Spark is trivial, performance is not verified though. ## Why `MuseSparkMoE.Config` rejects `DeepEPTokenDispatcher`, but nothing in Muse Spark needs that. The shared MoE code already supports DeepEP with an `output_postprocess`: - In training, DeepEP uses its compact, host-synced path. The routed rows match the received token counts, so there are no rows past the last expert offset, and the HybridEP mask from #6032 is not needed. - `RoutedExperts.forward` already applies the DeepEP routing scores after the postprocess, because Muse Spark's per-expert RMSNorm is nonlinear and must run first. DeepEP is the EP backend that `search_r1` uses for both its trainer and its CUDA-graphed generator (expand layout), so this should also unblock Muse Spark RL on Hopper. I have not run the generator's expand layout with Muse Spark. ## What changed - `MuseSparkMoE.Config` accepts `DeepEPTokenDispatcher`. `TorchAOTokenDispatcher` stays rejected. - README: list DeepEP as supported, and add it to the CUDA graphs row: training needs graphs disabled. Note that DeepEP's combine kernel needs the MoE compressed dimension to be a multiple of 256. Add a TODO for the config-time check. The production flavors use 4096. `debugmodel` uses 128, so it cannot run with DeepEP. ## Alternatives considered - Add a `muse_spark_debugmodel_deepep` recipe and an integration test: `debugmodel` cannot run DeepEP (compressed dimension 128), and changing the debug flavor would change every Muse Spark debug run and golden loss. - Validate the hidden size in `DeepEPTokenDispatcher.Config`: today a bad size fails at the first forward with DeepEP's static assert ("Invalid hidden"). A config-time check belongs to DeepEP in shared code, so it is left for a separate PR. ## Numerics Muse Spark debug model with compressed dimension 256 (a local config change, see above), FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps: | Step | AllToAll | DeepEP | | --- | --- | --- | | 1 | 7.75888 | 7.75888 | | 2 | 6.82995 | 6.83072 | | 10 | 4.81295 | 4.81803 | | 20 | 4.40471 | 4.39651 | Average over 20 steps: 5.18424 vs 5.18254. Step 1 matches. Later steps differ by the combine kernels' summation order, with no consistent sign. One-off unit check, the AllToAll comparison from the HybridEP tests run with DeepEP and an RMSNorm postprocess (2x H100): loss, input grad, and router, W13, W2, and norm weight grads match AllToAll within relative error 4.7e-3, below the 1.56e-2 bound. Loss and the expert and norm weight grads are bitwise equal. ## Performance Not reported. DeepEP's expected benefit is multi-node communication, and I only have single-node H100 runs, which would not show it. ## Testing - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k DeepEP` with DeepEP v2 at the CI pin 01dc3aa: 2 passed. These tests already run with an RMSNorm postprocess and check the score order against a reference. - Muse Spark debugmodel with compressed_dim 256, FSDP2 + Ulysses CP2 + EP4 (4x H100), seed 42, deterministic, 20 steps. Loss at steps 1 / 10 / 20: DeepEP 7.74766 / 4.80887 / 4.40117, AllToAll 7.74766 / 4.80533 / 4.39565. - No new test. The existing DeepEP tests cover the postprocess path, and the unit check above was a one-off run. - `pytest tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py`: 40 passed, 3 xfailed. stack-info: PR: #6037, branch: fegin/stack/35
ae898ea to
23454fc
Compare
## Summary (human-written) As title. Enabling DeepEP for Muse Spark is trivial, performance is not verified though. ## Why `MuseSparkMoE.Config` rejects `DeepEPTokenDispatcher`, but nothing in Muse Spark needs that. The shared MoE code already supports DeepEP with an `output_postprocess`: - In training, DeepEP uses its compact, host-synced path. The routed rows match the received token counts, so there are no rows past the last expert offset, and the HybridEP mask from #6032 is not needed. - `RoutedExperts.forward` already applies the DeepEP routing scores after the postprocess, because Muse Spark's per-expert RMSNorm is nonlinear and must run first. DeepEP is the EP backend that `search_r1` uses for both its trainer and its CUDA-graphed generator (expand layout), so this should also unblock Muse Spark RL on Hopper. I have not run the generator's expand layout with Muse Spark. ## What changed - `MuseSparkMoE.Config` accepts `DeepEPTokenDispatcher`. `TorchAOTokenDispatcher` stays rejected. - `RoutedExperts.forward`: comment at the HybridEP mask gate on why DeepEP needs no mask. Training uses the compact layout, which has no rows past the last offset. The expand layout runs only without grad: `dispatch_tokens` forces the compact layout when grad is enabled, and the DeepEP kernel forbids backward in expand mode. - README: list DeepEP as supported, and add it to the CUDA graphs row: training needs graphs disabled. Note that DeepEP's combine kernel needs the MoE compressed dimension to be a multiple of 256. Add a TODO for the config-time check. The production flavors use 4096. `debugmodel` uses 128, so it cannot run with DeepEP. ## Alternatives considered - Add a `muse_spark_debugmodel_deepep` recipe and an integration test: `debugmodel` cannot run DeepEP (compressed dimension 128), and changing the debug flavor would change every Muse Spark debug run and golden loss. - Validate the hidden size in `DeepEPTokenDispatcher.Config`: today a bad size fails at the first forward with DeepEP's static assert ("Invalid hidden"). A config-time check belongs to DeepEP in shared code, so it is left for a separate PR. ## Numerics Muse Spark debug model with compressed dimension 256 (a local config change, see above), FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps: | Step | AllToAll | DeepEP | | --- | --- | --- | | 1 | 7.75888 | 7.75888 | | 2 | 6.82995 | 6.83072 | | 10 | 4.81295 | 4.81803 | | 20 | 4.40471 | 4.39651 | Average over 20 steps: 5.18424 vs 5.18254. Step 1 matches. Later steps differ by the combine kernels' summation order, with no consistent sign. One-off unit check, the AllToAll comparison from the HybridEP tests run with DeepEP and an RMSNorm postprocess (2x H100): loss, input grad, and router, W13, W2, and norm weight grads match AllToAll within relative error 4.7e-3, below the 1.56e-2 bound. Loss and the expert and norm weight grads are bitwise equal. ## Performance Not reported. DeepEP's expected benefit is multi-node communication, and I only have single-node H100 runs, which would not show it. ## Testing - `pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k DeepEP` with DeepEP v2 at the CI pin 01dc3aa: 2 passed. These tests already run with an RMSNorm postprocess and check the score order against a reference. - Muse Spark debugmodel with compressed_dim 256, FSDP2 + Ulysses CP2 + EP4 (4x H100), seed 42, deterministic, 20 steps. Loss at steps 1 / 10 / 20: DeepEP 7.74766 / 4.80887 / 4.40117, AllToAll 7.74766 / 4.80533 / 4.39565. - No new test. The existing DeepEP tests cover the postprocess path, and the unit check above was a one-off run. - `pytest tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py`: 40 passed, 3 xfailed. stack-info: PR: #6037, branch: fegin/stack/35
23454fc to
333810a
Compare
Stacked PRs:
[muse_spark] Support DeepEP expert parallelism
Summary (human-written)
As title. Enabling DeepEP for Muse Spark is trivial, performance is not
verified though.
Why
MuseSparkMoE.ConfigrejectsDeepEPTokenDispatcher, but nothing in Muse Spark needs that. The shared MoE code already supports DeepEP with anoutput_postprocess:RoutedExperts.forwardalready applies the DeepEP routing scores after the postprocess, because Muse Spark's per-expert RMSNorm is nonlinear and must run first.DeepEP is the EP backend that
search_r1uses for both its trainer and its CUDA-graphed generator (expand layout), so this should also unblock Muse Spark RL on Hopper. I have not run the generator's expand layout with Muse Spark.What changed
MuseSparkMoE.ConfigacceptsDeepEPTokenDispatcher.TorchAOTokenDispatcherstays rejected.RoutedExperts.forward: comment at the HybridEP mask gate on why DeepEP needs no mask. Training uses the compact layout, which has no rows past the last offset. The expand layout runs only without grad:dispatch_tokensforces the compact layout when grad is enabled, and the DeepEP kernel forbids backward in expand mode.debugmodeluses 128, so it cannot run with DeepEP.Alternatives considered
muse_spark_debugmodel_deepeprecipe and an integration test:debugmodelcannot run DeepEP (compressed dimension 128), and changing the debug flavor would change every Muse Spark debug run and golden loss.DeepEPTokenDispatcher.Config: today a bad size fails at the first forward with DeepEP's static assert ("Invalid hidden"). A config-time check belongs to DeepEP in shared code, so it is left for a separate PR.Numerics
Muse Spark debug model with compressed dimension 256 (a local config change, see above), FSDP2 + TP2 (SP) + EP2 on 4x H100, seed 42, deterministic, 20 steps:
Average over 20 steps: 5.18424 vs 5.18254. Step 1 matches. Later steps differ by the combine kernels' summation order, with no consistent sign.
One-off unit check, the AllToAll comparison from the HybridEP tests run with DeepEP and an RMSNorm postprocess (2x H100): loss, input grad, and router, W13, W2, and norm weight grads match AllToAll within relative error 4.7e-3, below the 1.56e-2 bound. Loss and the expert and norm weight grads are bitwise equal.
Performance
Not reported. DeepEP's expected benefit is multi-node communication, and I only have single-node H100 runs, which would not show it.
Testing
pytest tests/unit_tests/gpu/distributed/test_deepep_activation_checkpoint.py -k DeepEPwith DeepEP v2 at the CI pin 01dc3aa: 2 passed. These tests already run with an RMSNorm postprocess and check the score order against a reference.pytest tests/unit_tests/cpu/models/muse_spark tests/unit_tests/cpu/recipes/test_muse_spark.py: 40 passed, 3 xfailed.