From 108182cb8199190a66f14c04ff8f0cc669ea7af2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A1=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=D0=BD?= <58187114+OrangeRedeng@users.noreply.github.com> Date: Thu, 23 Jul 2026 05:31:32 +0300 Subject: [PATCH] [Bugfix] [NPU] Fix w4a8 MoE performance degradation (#32113) --- .../srt/hardware_backend/npu/quantization/moe_methods.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/hardware_backend/npu/quantization/moe_methods.py b/python/sglang/srt/hardware_backend/npu/quantization/moe_methods.py index aa307b19c..f08d1af6c 100644 --- a/python/sglang/srt/hardware_backend/npu/quantization/moe_methods.py +++ b/python/sglang/srt/hardware_backend/npu/quantization/moe_methods.py @@ -428,14 +428,15 @@ class NPUW4A8Int8MoEMethod(_NPUMoEMethodBase): layer, f"{weight_prefix}_scale_bias", torch.nn.Parameter( - bias.data.transpose(1, 2).sum(dim=1).contiguous(), + bias.data.contiguous(), requires_grad=False, ), ) # Process weight weight = getattr(layer, f"{weight_prefix}_weight") - weight.data = npu_format_cast(weight.data.transpose(1, 2)) + weight.data = weight.data.transpose(1, 2).contiguous() + weight.data = npu_format_cast(weight.data) weight.data = self._pack_to_int32(weight.data) # Set dispatcher output dtype @@ -491,7 +492,7 @@ class NPUW4A8Int8MoEMethod(_NPUMoEMethodBase): f"Last dimension of weight must be divisible by 4 for int8→int32 packing, " f"got shape {weight.shape}" ) - return weight.contiguous().view(torch.int32) + return weight.view(torch.int32).contiguous() def apply( self,