[npu] [bugfix] Add contiguous operation during quantized weight loading. (#26309)

This commit is contained in:
gjsheu
2026-05-27 19:55:58 +08:00
committed by GitHub
parent 83d5f4604c
commit d9d719b270
@@ -496,12 +496,16 @@ class _NPUFusedMoEMethodBase(FusedMoEMethodBase):
class NPUW4A4Int4DynamicMoEMethod(_NPUFusedMoEMethodBase):
def process_weights_after_loading(self, layer: torch.nn.Module) -> None:
layer.w13_weight.data = npu_format_cast(layer.w13_weight.data.transpose(1, 2))
layer.w13_weight.data = npu_format_cast(
layer.w13_weight.data.transpose(1, 2).contiguous()
)
layer.w13_weight.data = self._pack_to_int32(
layer.w13_weight.data.to(torch.int32)
)
layer.w2_weight.data = npu_format_cast(layer.w2_weight.data.transpose(1, 2))
layer.w2_weight.data = npu_format_cast(
layer.w2_weight.data.transpose(1, 2).contiguous()
)
scale_np = layer.w13_weight_scale.data.cpu().numpy()
scale_np.dtype = np.uint32
@@ -618,8 +622,12 @@ class NPUW8A8Int8DynamicMoEMethod(_NPUFusedMoEMethodBase):
def process_weights_after_loading(self, layer: torch.nn.Module) -> None:
if self._maybe_apply_fuseep_weights(layer):
return
layer.w13_weight.data = npu_format_cast(layer.w13_weight.data.transpose(1, 2))
layer.w2_weight.data = npu_format_cast(layer.w2_weight.data.transpose(1, 2))
layer.w13_weight.data = npu_format_cast(
layer.w13_weight.data.transpose(1, 2).contiguous()
)
layer.w2_weight.data = npu_format_cast(
layer.w2_weight.data.transpose(1, 2).contiguous()
)
layer.w13_weight_scale = torch.nn.Parameter(
layer.w13_weight_scale.data.squeeze(-1), requires_grad=False
)