Conversation
…n kernels Wire num_fused_shared_experts through the FlashInfer TRTLLM FP4 MoE path so that nvidia/DeepSeek-R1-0528-NVFP4-v2 shared experts are fused into the same kernel call as routed experts, matching the FP8 fusion already supported in flashinfer-ai/flashinfer#4239. Changes: - flashinfer_trtllm.py: add _FP4_TRTLLM_HAS_FUSED_SHARED and _FP4_TRTLLM_ROUTED_HAS_FUSED_SHARED flags computed at import time via inspect.signature; inject num_fused_shared_experts into both the bypassed (logits) and routed call-kwargs when the installed FlashInfer supports it; guard against EP + fused shared experts with a clear NotImplementedError. - overrides.py: add _fp4_trtllm_supports_fused_shared() helper; lift the blanket auto-disable of shared-expert fusion for flashinfer_trtllm and flashinfer_trtllm_routed runners when quantization==modelopt_fp4 and the installed FlashInfer exposes the param. All other runners unchanged. - test/registered/quant/test_nvfp4_shared_expert_fusion.py: 12 dummy-weight tests covering capability detection, overrides gate logic, EP/capability runtime guards, and kwarg pass-through for both forward paths. EP is explicitly unsupported for this fused path; both the model-level determine_num_fused_shared_experts and the runner-level NotImplementedError guard it. The gate is backward-compatible: on FlashInfer <0.6.16 without the param both flags are False and behavior is identical to before this change. Depends on: flashinfer-ai/flashinfer#4239 Target model: nvidia/DeepSeek-R1-0528-NVFP4-v2 Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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
Wire num_fused_shared_experts through the FlashInfer TRTLLM FP4 MoE forward path so that the shared expert in nvidia/DeepSeek-R1-0528-NVFP4-v2 is fused into the same kernel call as the routed experts, eliminating a separate dense GEMM per MoE layer.
This is the FP4 counterpart of the FP8 shared-expert fusion already present in this codebase, and depends on the FlashInfer-side implementation in flashinfer-ai/flashinfer#4239.
Target model: nvidia/DeepSeek-R1-0528-NVFP4-v2 (https://huggingface.co/nvidia/DeepSeek-R1-0528-NVFP4-v2) — the only publicly available model with NVFP4-quantized MoE experts including a shared expert slot.
Changes
python/sglang/srt/layers/moe/moe_runner/flashinfer_trtllm.py
python/sglang/srt/arg_groups/overrides.py
test/registered/quant/test_nvfp4_shared_expert_fusion.py (new)
Backward compatibility
The gate is fully backward-compatible. On FlashInfer ≤ 0.6.15.post1 (without the param), both flags are False and behavior is identical to before this PR — shared-expert fusion remains auto-disabled for the FP4 path.
EP not supported
Expert parallelism is explicitly unsupported for this fused FP4 path, consistent with the FlashInfer maintainers' guidance. Both determine_num_fused_shared_experts (model level) and the runner-level NotImplementedError guard it independently.
Test plan
Accuracy validation
Server A — fused path:
Server B — baseline (fusion disabled by
--disable-shared-experts-fusion \):CI States
Latest PR Test (Base): ❌ Run #30660223310
Latest PR Test (Extra): ❌ Run #30660222877