已关闭
[Bug-Report|缺陷反馈]: NpuWeightQuantizedLinear 非连续输入触发 npu_weight_quant_batchmatmul EZ1001 报错 #184
niwang66创建于  19 天前关闭于  7 天前
niwang66
niwang66
19 天前 创建

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。

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.

likedislike
niwang66niwang66
19 天前 修改了issue 的描述
niwang66
niwang66
19 天前 评论:

/assign @niwang66

likedislike
CANN-robotCANN-robot成员
19 天前 将 niwang66 设为负责人
niwang66niwang66
19 天前 关联了pull request:fix: 修复非连续输入触发npu_weight_quant_batchmatmul的EZ1001报错(#184)
Ffujun19成员
11 天前 关联了pull request:fix: NpuWeightQuantizedLinear supports non-contiguous inputs (#184)
fujun19成员
7 天前 评论:

该问题已修复合入,本issue即将关闭,若您还有新的问题,可以提交新的issue反馈

likedislike
Ffujun19成员
7 天前 issue状态由 进行中 改变为 已完成
Ffujun19成员
7 天前 关闭了 issue