From 7714b182f223bdcd1b376c6ade369d9c48dfb7ac Mon Sep 17 00:00:00 2001 From: Xiaoyu Zhang <1182563586@qq.com> Date: Fri, 18 Sep 2026 22:53:13 +0800 Subject: [PATCH] [Bugfix] Fix top-1 MoE routing with non-unit scaling (#40187) --- .../srt/layers/moe/moe_runner/triton_utils/fused_moe.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/layers/moe/moe_runner/triton_utils/fused_moe.py b/python/sglang/srt/layers/moe/moe_runner/triton_utils/fused_moe.py index ce665e936..07a7bb6b9 100644 --- a/python/sglang/srt/layers/moe/moe_runner/triton_utils/fused_moe.py +++ b/python/sglang/srt/layers/moe/moe_runner/triton_utils/fused_moe.py @@ -813,8 +813,11 @@ def _fused_moe_kernel_sequence( ) # LoRA hooks force the second kernel to write to intermediate_cache3 so - # hooks.after_down can inspect/modify it before reduction. - _use_intermediate = not no_combine and (topk != 1 or hooks) + # hooks.after_down can inspect/modify it before reduction. Non-unit routed + # scaling also needs the intermediate because the reduction applies it. + _use_intermediate = not no_combine and ( + topk != 1 or hooks or routed_scaling_factor not in (None, 1.0) + ) out_slice = None if use_fused_moe_sum_all_reduce: