Repository navigation
[Spec][MegaMoE] Let the speculative draft choose its own W4A4 MXFP4 MegaMoE MMA type - #42022
Conversation
--enable-w4a4-mxfp4-megamoe was read process-wide, so a draft model that runs MegaMoE (e.g. the DSpark head of DeepSeek-V4-Pro-0813) always used the same mxf4xmxf4 kernel as the target. Add --[no-]speculative-enable-w4a4-mxfp4-megamoe. When unset it inherits the target flag, so existing deployments are unchanged. draft_model_build_scope applies the draft value while the draft is constructed, and FusedMoE pins the choice on the layer so weight repacking, the symmetric buffer and the forward kernel all use the layer's own MMA type after the scope exits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nvpohanh
left a comment
There was a problem hiding this comment.
[by Claude Code] Two inline style comments. No functional issues found in the traced draft-build, weight-repack, symmetric-buffer, and forward paths.
_mega_moe_mma_type() and _get_mega_moe_symm_buffer() no longer fall back to the process-wide --enable-w4a4-mxfp4-megamoe: a caller that omitted the layer or mma_type would silently get the target's MMA type for a draft layer. Every production caller already passes it. The --speculative-enable-w4a4-mxfp4-megamoe help text and docs row now note that a value different from the target allocates a second MegaMoE symmetric buffer after the KV pool is sized. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/rerun-test test/registered/unit/layers/moe/test_mega_moe_deepgemm_api.py test/registered/unit/server_args/test_server_args.py test/registered/unit/test_server_args_namespaces.py test/registered/e2e/models/test_deepseek_v4_flash_fp4_megamoe_b200.py test/registered/e2e/models/test_kimi_k3_b300.py test/registered/unit/spec/test_draft_construction_isolation.py test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py |
|
Results for 🚀 🚀 🚀 |
|
@Fridge003 @ch-wan could you help to review this? Thanks! |
|
/tag-and-rerun-ci |
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
|
All NV pipelines passed |
kpham-sgl
left a comment
There was a problem hiding this comment.
Three nonblocking suggestions on documentation and test coverage. Ruff lint, Ruff formatting, and isort checks pass for all nine changed Python files.
| boundary_reduction=get_spec().speculative_boundary_reduction | ||
| ), | ||
| _draft_w4a4_mxfp4_megamoe_override(), | ||
| ): |
There was a problem hiding this comment.
Nonblocking documentation nit: could we update draft_model_build_scope()'s docstring to describe the boundary-reduction and W4A4 overrides as well as shared-expert fusion? The scope now controls several construction-time settings; documenting what is restored on exit and what layers retain would make its contract easier to follow.
There was a problem hiding this comment.
[by Claude Code] Done in 35a5d48. The draft_model_build_scope() docstring now lists all three construction-time settings: shared-experts fusion, boundary_reduction, and enable_w4a4_mxfp4_megamoe. It says that all three return to the target's values on exit, including on error. It also says what layers built in the scope keep: boundaries keep the resolved reduction, and FusedMoE layers keep the draft's MegaMoE MMA type.
| "--no-speculative-enable-w4a4-mxfp4-megamoe to keep the draft on " | ||
| "fp8xfp4 (W4A8) while the target runs W4A4. Same as " | ||
| "--enable-w4a4-mxfp4-megamoe if unset. A value different from " | ||
| "--enable-w4a4-mxfp4-megamoe allocates a second MegaMoE symmetric " |
There was a problem hiding this comment.
Nonblocking documentation accuracy nit: differing flag values do not necessarily allocate a second buffer. The draft must actually use MXFP4 MegaMoE; for example, a dense draft does not allocate one because of this flag. Could we qualify this sentence here and in server_arguments.mdx, e.g. "A draft using a different MXFP4 MegaMoE MMA type may allocate an additional symmetric buffer after the KV pool is sized; lower --mem-fraction-static if CUDA-graph capture runs out of memory"?
There was a problem hiding this comment.
[by Claude Code] Done in 35a5d48. The help text and the server_arguments.mdx row now read: "A draft that runs MXFP4 MegaMoE with a different MMA type from the target may allocate an additional MegaMoE symmetric buffer after the KV pool is sized; lower --mem-fraction-static if CUDA-graph capture runs out of memory."
| The draft forward runs outside draft_model_build_scope, so a layer that | ||
| re-read the global flag would pair draft weights with the wrong kernel. | ||
| """ | ||
| for draft_flag, expected_draft in ( |
There was a problem hiding this comment.
Nonblocking test coverage suggestion: could we also cover target W4A8 (enable_w4a4_mxfp4_megamoe=False) with draft W4A4 (speculative_enable_w4a4_mxfp4_megamoe=True)? The current cases exercise the negative override and inheritance with a W4A4 target, while the reverse mixed configuration is also advertised. A nested scope that raises would additionally verify that the target setting is restored on exceptional exit.
There was a problem hiding this comment.
[by Claude Code] Done in 35a5d48. test_draft_layers_keep_their_own_w4a4_choice now covers all four target/draft combinations: W4A4/W4A8, W4A4/inherit, W4A8/W4A4, and W4A8/inherit. It asserts the target flag is restored after each scope. The new test_draft_build_scope_restores_w4a4_on_exception raises inside the scope with a W4A8 target and a W4A4 draft. It checks that the flag returns to False and that a layer built afterward uses fp8xfp4. Both pass locally, along with test_server_args.py, test_server_args_namespaces.py, and test_draft_construction_isolation.py.
…note, and test W4A8 target with W4A4 draft Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
[by Claude Code] All NV pipelines have passed. |
kpham-sgl
left a comment
There was a problem hiding this comment.
Off by default so should be safe to merge
…egaMoE MMA type (sgl-project#42022) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
[by Claude Code]
Motivation
--enable-w4a4-mxfp4-megamoeis read process-wide, so a speculative draft whose MoE layers run through MegaMoE always uses the same MMA type as the target. For example, the DSpark head bundled indeepseek-ai/DeepSeek-V4-Pro-0813has 3 stages x 384 MXFP4 routed experts.DSparkWorkerV2builds and runs it under the target'smegamoeA2A backend, and--speculative-moe-a2a-backendis ignored for DSpark. Users therefore cannot run the target with W4A4 (mxf4xmxf4) while keeping the draft on W4A8 (fp8xfp4), or the reverse.Modifications
--speculative-enable-w4a4-mxfp4-megamoe/--no-speculative-enable-w4a4-mxfp4-megamoe(specnamespace). When unset (defaultNone), the draft inherits--enable-w4a4-mxfp4-megamoe, so existing deployments are unchanged. This mirrors how--speculative-moe-runner-backend/--speculative-moe-a2a-backendinherit from the target.draft_model_build_scope()now also applies the draft's value toexec.moe.enable_w4a4_mxfp4_megamoewhile the draft is constructed. It uses the same scoped config-bag override it already applies toboundary_reduction. Every draft worker (DSpark, DFlash, EAGLE/MTP, multi-layer EAGLE, frozen-KV MTP, standalone) builds its draft inside this scope.FusedMoEpins the choice at construction (_mega_moe_w4a4)._mega_moe_mma_type(experts)reads it from the layer, so weight repacking (build_mega_moe_experts_weights,Mxfp4MoEMethod), the symmetric-buffer key, and the forward kernel all use the layer's own MMA type after the build scope exits._mega_moe_mma_typerequires the layer and_get_mega_moe_symm_bufferrequiresmma_type, so no caller can fall back to the process-wide flag. Kimi K3's MegaMoE forward now passes its layer's MMA type to the buffer lookup as well.server_arguments.mdx, including the memory cost of a draft value that differs from the target.Mixed configurations allocate one additional DeepGEMM MegaMoE symmetric buffer, because the buffer cache is keyed by MMA type (see memory numbers below).
Accuracy Tests
Setup: 8x B300 (SM103),
lmsysorg/sglang:dev-cu13(2026-10-01) with this branch onPYTHONPATH(headb71c8568b2, base5733bcaad3),deepseek-ai/DeepSeek-V4-Pro-0813(HF72e1d32). The recipe is the cookbook section 3.6 DEP8 DSpark + MegaMoE W4A4 command without the HiCache flags, which are unrelated to this change, run on B300 instead of B200:--no-speculative-enable-w4a4-mxfp4-megamoe(target W4A4, draft W4A8)speculative_enable_w4a4_mxfp4_megamoeNoneFalsemxf4xmxf4mxf4xmxf4mxf4xmxf4fp8xfp4mxf4xmxf4)mxf4xmxf4, plusfp8xfp4with the draft's FP8 shared expert fused)max_total_num_tokensThe MMA-type and buffer rows come from a temporary debug print in
build_mega_moe_experts_weights/_get_mega_moe_symm_buffer; that print is not part of this PR. Arm A matches the pre-PR behavior: one buffer, and every MoE layer onmxf4xmxf4.Memory note: the mixed configuration allocates a second DeepGEMM MegaMoE symmetric buffer, about 7.8 GiB per GPU at
SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK=8320for V4-Pro. It is allocated lazily during draft CUDA-graph capture, after the KV pool is sized. KV capacity is therefore unchanged, but post-capture headroom drops by that amount, so lower--mem-fraction-staticif capture runs out of memory.Unit tests
Run in the same container on the B300 node at
b71c8568b2. All pass exceptTestDcpCommBackendDefault::test_a5_npu_supports_dcpintest_server_args.py, which fails the same way on base5733bcaad3and is unrelated (NPU DCP).test/registered/unit/layers/moe/test_mega_moe_deepgemm_api.py: newtest_draft_layers_keep_their_own_w4a4_choicebuilds realFusedMoElayers inside and outsidedraft_model_build_scope. It fails ('mxf4xmxf4' != 'fp8xfp4') when_mega_moe_mma_typereads the process-wide flag instead of the layer's pinned value.test/registered/unit/server_args/test_server_args.py: newtest_speculative_w4a4_mxfp4_megamoe_is_tri_statechecks unset ->None(inherit),--speculative-enable-...->True,--no-speculative-enable-...->False.test_server_args_namespaces.py,test_runtime_context_config_bags.py,test_moe_runner_extensions.py: pass.Benchmarking and Profiling
Not a performance change by itself. The accept-length and throughput rows above show that W4A8 for the DSpark draft does not change accept length or GSM8K accuracy on this workload. The flag lets users trade the draft's W4A4 speedup for W4A8 numerics, or the reverse, without touching the target.
Checklist
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ✅ Run #37454010899
Latest PR Test (Extra): ❌ Run #37454010504
Latest PR Test (AMD ROCm 10): ❌ Run #37454010878