From 76f9213a411018547f4fd6a75f36feaa4d6bed58 Mon Sep 17 00:00:00 2001 From: Xiaoyu Zhang <1182563586@qq.com> Date: Sat, 19 Sep 2026 21:41:51 +0800 Subject: [PATCH] [Fix] Keep mHC context out of non-V4 compiled MoE forwards (#40353) --- python/sglang/srt/models/deepseek_v2.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/python/sglang/srt/models/deepseek_v2.py b/python/sglang/srt/models/deepseek_v2.py index 3ca0915da..7c37b22e3 100644 --- a/python/sglang/srt/models/deepseek_v2.py +++ b/python/sglang/srt/models/deepseek_v2.py @@ -608,6 +608,7 @@ class DeepseekV2MoE(nn.Module): self.alt_stream = alt_stream self.routed_quant_stream = routed_quant_stream self.is_nextn = is_nextn + self.is_deepseek_v4 = is_deepseek_v4 self._fuse_finalize_all_reduce = ( is_deepseek_v4 and getattr(config, "hc_pre_from_prev_sublayer", False) @@ -1185,8 +1186,10 @@ class DeepseekV2MoE(nn.Module): ) if not all_reduce_done: - if self.tp_size > 1 and not should_skip_post_experts_all_reduce( - is_tp_path=True + if ( + self.is_deepseek_v4 + and self.tp_size > 1 + and not should_skip_post_experts_all_reduce(is_tp_path=True) ): from sglang.srt.layers.moe.mhc_post_fusion import ( current_mhc_post_fusion, @@ -1341,8 +1344,10 @@ class DeepseekV2MoE(nn.Module): self.routed_scaling_factor, ) - if self.tp_size > 1 and not should_skip_post_experts_all_reduce( - is_tp_path=True, + if ( + self.is_deepseek_v4 + and self.tp_size > 1 + and not should_skip_post_experts_all_reduce(is_tp_path=True) ): from sglang.srt.layers.moe.mhc_post_fusion import current_mhc_post_fusion