From c0f47a06fc8e8b7c9eec0e38018e6fb176fe1cb1 Mon Sep 17 00:00:00 2001 From: McZyWu Date: Mon, 27 Jul 2026 15:12:38 +0800 Subject: [PATCH] [NPU] Determine the topk norm_type through scoring_func (#31393) --- python/sglang/srt/hardware_backend/npu/moe/topk.py | 2 +- python/sglang/srt/models/glm4_moe_lite.py | 3 +++ 2 files changed, 4 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 d59498038..ffe772b04 100644 --- a/python/sglang/srt/hardware_backend/npu/moe/topk.py +++ b/python/sglang/srt/hardware_backend/npu/moe/topk.py @@ -98,7 +98,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..68f9dea7c 100644 --- a/python/sglang/srt/models/glm4_moe_lite.py +++ b/python/sglang/srt/models/glm4_moe_lite.py @@ -85,12 +85,14 @@ from sglang.srt.utils import ( LazyValue, add_prefix, is_non_idle_and_non_empty, + is_npu, log_info_on_rank0, make_layers, ) from sglang.srt.utils.hf_transformers_utils import get_rope_config logger = logging.getLogger(__name__) +_is_npu = is_npu() class Glm4MoeLiteMLP(nn.Module): @@ -242,6 +244,7 @@ class Glm4MoeLiteSparseMoeBlock(nn.Module): # Some Fp4 MoE backends require the output format to be bypassed but the MTP layers are unquantized # and requires the output format to be standard. We use quant_config to determine the output format. output_format=TopKOutputFormat.STANDARD if quant_config is None else None, + **({"scoring_func": "sigmoid"} if _is_npu else {}), ) self.shared_experts_is_int8 = False