现象:
forward 中执行 inputs.reshape(-1, K) 后调用 npu_weight_quant_batchmatmul。
reshape 不保证结果连续,当输入为 K 维切片等非连续布局时(例如 QKV 联合投影
拆分出的 hidden_states),aclnn 直接报错:
EZ1001: only support x tensor is contiguous or transpose last two dims。
RuntimeError: npu_weight_quant_batchmatmul:../third_party/op-plugin/op_plugin/ops/opapi/WeightQuantBatchMatmulV2KernelNpuOpApi.cpp:114
NPU function error: call aclnnWeightQuantBatchMatmulV2 failed, error code is 161002
AclNN_Parameter_Error(EZ1001): only support x tensor is contiguous or transpose last two dims.
Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.
Describe the current behavior / 问题描述 (Mandatory / 必填)
模块:
amct_pytorch/classic/deploy_op/weight_npu_quant_module.py 的
NpuWeightQuantizedLinear(GPTQ/AWQ/MinMax/OFMR 等 weight-only 压缩算法的 deploy 算子)
现象:
forward 中执行 inputs.reshape(-1, K) 后调用 npu_weight_quant_batchmatmul。
reshape 不保证结果连续,当输入为 K 维切片等非连续布局时(例如 QKV 联合投影
拆分出的 hidden_states),aclnn 直接报错:
EZ1001: only support x tensor is contiguous or transpose last two dims。
常规的 2D/3D 连续输入 reshape 后恰好是 view,仍满足连续性要求,因此该缺陷
此前未被触发;非连续输入在 LLM 部署场景(投影矩阵切片)中会出现,导致推理失败。
环境:
Ascend 910B4,torch 2.7.1+cpu,torch_npu 2.7.1.post4
已定位根因(reshape 后缺少显式 contiguous()),计划修复并提交 PR 关联本 issue。
Steps to reproduce the issue / 重现步骤 (Optional / 选填)
import torch, torch_npu w = torch.randint(-127, 127, (256, 128), dtype=torch.int8).npu() sc = torch.ones(4, 128, dtype=torch.float16).npu() x = torch.randn(2, 16, 512, dtype=torch.float16).npu()[:, :, :256] torch_npu.npu_weight_quant_batchmatmul( x.reshape(-1, 256), w, sc, antiquant_group_size=64) # -> RuntimeError: EZ1001: only support x tensor is contiguous or transpose last two dims # 对比:reshape 后显式 contiguous() 即正常 torch_npu.npu_weight_quant_batchmatmul( x.reshape(-1, 256).contiguous(), w, sc, antiquant_group_size=64) # OK模块层面:构造 NpuWeightQuantizedLinear(wts_type='int8', group_size=64),
传入 randn(2,16,512).npu()[:, :, :256] 同样报 EZ1001。
Related log / screenshot / 日志 / 截图 (Optional / 选填)
RuntimeError: npu_weight_quant_batchmatmul:../third_party/op-plugin/op_plugin/ops/opapi/WeightQuantBatchMatmulV2KernelNpuOpApi.cpp:114
NPU function error: call aclnnWeightQuantBatchMatmulV2 failed, error code is 161002
AclNN_Parameter_Error(EZ1001): only support x tensor is contiguous or transpose last two dims.