[Deepseek-V4] Enable shared-experts fusion on the flashinfer_mxfp4 (trtllm-gen) MoE path (#35505)

Signed-off-by: Shiki Wu <shikiw@nvidia.com>
This commit is contained in:
Junpan Wu
2026-08-25 14:55:25 -07:00
committed by GitHub
parent 6569125e3a
commit 4b4bf3d2a5
3 changed files with 131 additions and 1 deletions
+11 -1
View File
@@ -91,7 +91,10 @@ from sglang.srt.layers.linear import ColumnParallelLinear, RowParallelLinear
from sglang.srt.layers.logits_processor import LogitsProcessor
from sglang.srt.layers.moe import get_moe_a2a_backend, should_use_dp_reduce_scatterv
from sglang.srt.layers.moe.fused_moe_triton import FusedMoE
from sglang.srt.layers.moe.utils import is_shared_experts_fusion_disabled
from sglang.srt.layers.moe.utils import (
is_shared_experts_fusion_disabled,
uses_per_rank_fused_shared_slots,
)
from sglang.srt.layers.quantization.fp8_utils import (
view_aiter_fused_rms_transposed_fp8_scale,
)
@@ -3303,6 +3306,13 @@ class DeepseekV4ForCausalLM(nn.Module):
"routed experts, so they cannot be fused into the quantized "
"routed-expert path."
)
if get_parallel().moe_ep_size > 1 and not uses_per_rank_fused_shared_slots():
return (
"Expert parallelism keeps only a slice of the routed experts on "
"each rank, so the fused shared expert cannot be appended to the "
"routed weight tensor (only DeepEP/MegaMOE per-rank shared slots "
"support fusion under EP)."
)
if not get_exec().moe.enforce_shared_experts_fusion:
return "Config does not support fused shared expert(s)."
if hf_config.n_shared_experts != 1: