Repository navigation
mega_moe: route pre-dispatch through DeepGEMM + FP4 acts opt-in - #24449
Closed
pranjalssh wants to merge 2 commits into
Closed
pranjalssh wants to merge 2 commits into
pranjalssh wants to merge 2 commits into
Conversation
Rebased onto dsv4-rebase. Mega-MoE forward lives in
`python/sglang/srt/layers/moe/mega_moe.py` on this branch, so the patch
that previously sat in `models/deepseek_v2.py` moves here.
Two changes:
1. Add two opt-in env flags forwarded to DeepGEMM via `DG_USE_*` at first
symm-buffer alloc:
- `SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_FP4_ACTS` — pack the symm-buffer x
slot as E2M1 nibbles instead of FP8 E4M3 (halves x-slot footprint;
SF slot unchanged).
- `SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_MXF4_KIND` — switch DeepGEMM's
L1+L2 mainloops to `kind::mxf4` (2-CTA cluster, dense FP4 smem).
Requires the FP4-acts flag (DeepGEMM asserts host-side).
Forwarding happens once via `setdefault` so explicit external `DG_USE_*`
exports still win.
2. Gate the pre-dispatch implementation on the flag:
- `use_fp4_acts=True` → call `deep_gemm.mega_moe_pre_dispatch` (handles
the E2M1 packing variant).
- default → call the existing
`sglang.jit_kernel.deepseek_v4.mega_moe_pre_dispatch` (FP8 only).
Companion DeepGEMM PR: sgl-project/DeepGEMM#27 — adds the FP4 acts +
MXF4 kind support and the fused `mega_moe_pre_dispatch` kernel that this
PR calls into.
Validated end-to-end on 8x B300 with DeepSeek-V4-Pro:
- Sentinel test (FP4 acts vs FP8 acts agreement): rel-RMSE <= 0.5 across
layers.
- 8K-input bench (concurrency 2048): tokens match the FP8 baseline.
- GSM8K accuracy parity within run-to-run variance.
pranjalssh
requested review from
BBuf,
Edwardf0t1,
Fridge003,
HaiShaw,
Ying1123,
ch-wan,
ispobock and
merrymercy
as code owners
May 5, 2026 21:51
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Forwards `DG_USE_FP8_COMBINE=1` to DeepGEMM so the L2 epilogue ships FP8 E4M3 + per-(token, N=128) UE8M0 SF over NVLink instead of BF16. Halves NVLink bytes/token on the second a2a. Independent of `DG_USE_FP4_ACTS` / `DG_USE_MXF4_KIND` (those control the dispatch a2a + mainloops). Combinable: enable all three for the maximum bandwidth savings. Companion DeepGEMM PR: sgl-project/DeepGEMM#27 (commit ports the FP8 combine path into `sm100_fp8_fp4_mega_moe.cuh`). Validated on 8x B300, DeepSeek-V4-Pro, b=8192 input, 1024 output: b=512: 91.9 s (FP8 acts) -> 78.4 s (FP4+MXF4+FP8combine) — +17.3% b=2048: 259.4 s -> 238.2 s — +8.9% b=4096: 489.5 s -> 444.2 s — +10.2% Sentinel + GSM8K parity preserved. How to enable (combined with the existing FP4 stack): export SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_FP4_ACTS=1 export SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_MXF4_KIND=1 export SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_FP8_COMBINE=1
5 tasks done
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.
Summary
DG_USE_*env vars at first symm-buffer alloc:SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_FP4_ACTS— pack the symm-buffer x slot as E2M1 nibbles instead of FP8 E4M3 (halves x-slot footprint; SF slot unchanged).SGLANG_OPT_DEEPGEMM_MEGA_MOE_USE_MXF4_KIND— switch DeepGEMM's L1+L2 mainloops tokind::mxf4(2-CTA cluster, dense FP4 smem). Requires the FP4-acts flag (DeepGEMM asserts host-side).python/sglang/srt/layers/moe/mega_moe.py:use_fp4_acts=True→ calldeep_gemm.mega_moe_pre_dispatch(handles the E2M1 packing variant).sglang.jit_kernel.deepseek_v4.mega_moe_pre_dispatch.Companion PR
sgl-project/DeepGEMM#27 — adds the FP4 acts + MXF4 kind support and the fused
mega_moe_pre_dispatchkernel that this PR calls into. Both must land together.How to enable (e.g. for InferenceX CI)
Set both env flags before launching sglang:
These are off by default. They are read once at first mega-MoE symm-buffer allocation and forwarded into
DG_USE_FP4_ACTS=1/DG_USE_MXF4_KIND=1viaos.environ.setdefault, so explicit externalDG_USE_*exports still win.The full launch invocation we use on B300x8 with DeepSeek-V4-Pro:
Validation
End-to-end on 8x B300 with DeepSeek-V4-Pro:
Test plan
tests/test_mega_moe_pre_dispatch.py) — bytewise equality vsper_token_cast_to_fp{8,4}host helpersNotes on the move from deepseek_v2.py
This PR replaces #24444 (closed) which was based on
deepseek_v4. Ondsv4-rebasethe mega-MoE forward path was extracted out ofmodels/deepseek_v2.pyintolayers/moe/mega_moe.py, so the patch lives there now.🤖 Generated with Claude Code