DeepseekV2MoE: defer shared experts when routed kernel is non-mutating (#25279)

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cheng Wan
2026-05-14 22:20:55 -07:00
committed by GitHub
co-authored by Claude Opus 4.7
parent 897587b03a
commit ad4994dc1d
+11 -3
View File
@@ -826,10 +826,9 @@ class DeepseekV2MoE(nn.Module):
if server_args.enable_eplb
else None
)
defer_shared = not self.experts.moe_runner_config.inplace
if hidden_states.shape[0] > 0:
if (
not self._fuse_shared_experts_inside_sbo
): # TODO: check if it supports mtp
if not defer_shared and not self._fuse_shared_experts_inside_sbo:
shared_output = self._forward_shared_experts(
hidden_states, gemm_output_zero_allocator
)
@@ -894,6 +893,15 @@ class DeepseekV2MoE(nn.Module):
# fused in biased_grouped_topk so we can skip here
final_hidden_states *= self.routed_scaling_factor
if (
defer_shared
and hidden_states.shape[0] > 0
and not self._fuse_shared_experts_inside_sbo
):
shared_output = self._forward_shared_experts(
hidden_states, gemm_output_zero_allocator
)
final_hidden_states = maybe_fuse_routed_scale_and_shared_add(
self.experts,
final_hidden_states,