From 241937af874d0309c95444bd26e84d0a2c2101db Mon Sep 17 00:00:00 2001 From: McZyWu Date: Wed, 15 Jul 2026 15:26:44 +0800 Subject: [PATCH] [NPU] Determine the topk norm_type through scoring_func (#31107) Co-authored-by: iridiumine <42236072+iridiumine@users.noreply.github.com> Co-authored-by: zhaozx-cn <59479021+zhaozx-cn@users.noreply.github.com> Co-authored-by: sglang-npu-bot --- python/sglang/srt/hardware_backend/npu/moe/topk.py | 2 +- python/sglang/srt/models/glm4_moe_lite.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/python/sglang/srt/hardware_backend/npu/moe/topk.py b/python/sglang/srt/hardware_backend/npu/moe/topk.py index 9aef68476..5c255af57 100644 --- a/python/sglang/srt/hardware_backend/npu/moe/topk.py +++ b/python/sglang/srt/hardware_backend/npu/moe/topk.py @@ -97,7 +97,7 @@ def fused_topk_npu( group_select_mode=(1 if use_grouped_topk else 0), renorm=0, # 1 for sigmoid, 0 for softmax - norm_type=1, + norm_type=(0 if topk_config.scoring_func == "softmax" else 1), routed_scaling_factor=( topk_config.routed_scaling_factor if topk_config.apply_routed_scaling_factor_on_output diff --git a/python/sglang/srt/models/glm4_moe_lite.py b/python/sglang/srt/models/glm4_moe_lite.py index c650585a5..750117f9d 100644 --- a/python/sglang/srt/models/glm4_moe_lite.py +++ b/python/sglang/srt/models/glm4_moe_lite.py @@ -225,6 +225,7 @@ class Glm4MoeLiteSparseMoeBlock(nn.Module): quant_config=quant_config, routed_scaling_factor=self.routed_scaling_factor, prefix=add_prefix("experts", prefix), + **({"scoring_func": "sigmoid"}), ) self.topk = TopK(