Closed
[Bug-Report|缺陷反馈]: aclnnRotateQuant 的 N/K 越界返回 561103 而非资料声明的 161002 #7415
liuhanwen8Add on  26 days agoClosed at  18 days ago
liuhanwen8
liuhanwen8
26 days ago Create

环境

  • 硬件:Atlas A2 训练服务器(910B2,64GB HBM),驱动 npu-smi 26.1.1
  • 软件:CANN 9.2.0(toolkit 与 ops 包同为 9.2.0)
  • 接口:aclnnRotateQuant,资料 docs/aclnnRotateQuant.md(A2 分支),仓 ops-nn 711a4f5d

现象

资料「约束说明」写明 A2 上 N 范围 [128, 16000]、K 范围 [16, 1024],错误码表只列
161001(空指针)与 161002(数据类型/维度/shape/参数取值不符)。实测越界的 N、K
返回 561103(内部错误码):

(M, N, K) 违反的约束 资料声明 实测
4, 64, 64 N < 128 161002 561103
4, 16384, 64 N > 16000 161002 561103
4, 128, 8 K < 16 161002 561103
2, 2048, 2048 K > 1024 161002 561103

源码锚点:op_api/aclnn_rotate_quant.cpp 的 CheckIntRotationShape() 只校验 N % 8 == 0、
K != 0、N % K == 0 与方阵,没有 N/K 范围校验;范围校验在
op_host/arch22/rotate_quant_tiling.cpp 的 N_MIN/N_MAX/K_MIN/K_MAX,tiling 失败经 aclnn
转成 561103。同族约束 N % 8 != 0(N=132)、N % K != 0 都能正确返回 161002,
说明校验被拆成两段、报错码随之分裂。

期望

四条越界用例都返回 161002;或资料补充声明「N/K 越界由 tiling 拒绝并返回 561103」。

复现步骤

  1. 保存下方 C++ 脚本为 repro.cpp。
  2. 编译:g++ -std=c++17 -O2 repro.cpp -I$ASCEND_HOME_PATH/include -L$ASCEND_HOME_PATH/lib64 -lascendcl -lnnopbase -lopapi -o repro
  3. 选空闲卡:export ASCEND_RT_VISIBLE_DEVICES=<空闲卡号>
  4. 运行 ./repro,对比五行返回码。

复现脚本

#include <cstdio>
#include <cstdint>
#include <cstring>
#include <vector>
#include "acl/acl.h"
#include "aclnnop/aclnn_rotate_quant.h"
static aclTensor* mkT(const std::vector<int64_t>& v, aclDataType dt, void* d) {
    std::vector<int64_t> s(v.size(), 1);
    for (int i = (int)v.size() - 2; i >= 0; i--) s[i] = v[i + 1] * s[i + 1];
    return aclCreateTensor(v.data(), v.size(), dt, s.data(), 0, ACL_FORMAT_ND, v.data(), v.size(), d);
}
static int call(int64_t M, int64_t N, int64_t K) {
    std::vector<int64_t> xv{M, N}, rv{K, K}, yv{M, N}, sv{M};
    size_t xb = (size_t)M * N * 2, rb = (size_t)K * K * 2, yb = (size_t)M * N;
    if (!xb) xb = 2; if (!rb) rb = 2; if (!yb) yb = 1;
    void *xd = nullptr, *rd = nullptr, *yd = nullptr, *sd = nullptr;
    aclrtMalloc(&xd, xb, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&rd, rb, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&yd, yb, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMalloc(&sd, (size_t)M * 4, ACL_MEM_MALLOC_HUGE_FIRST);
    aclrtMemset(xd, xb, 0, xb); aclrtMemset(rd, rb, 0, rb);
    aclrtMemset(yd, yb, 0, yb); aclrtMemset(sd, (size_t)M * 4, 0, (size_t)M * 4);
    aclTensor* xT = mkT(xv, ACL_BF16, xd);
    aclTensor* rT = mkT(rv, ACL_BF16, rd);
    aclTensor* yT = mkT(yv, ACL_INT8, yd);
    aclTensor* sT = mkT(sv, ACL_FLOAT, sd);
    uint64_t ws = 0; aclOpExecutor* ex = nullptr; char rm[] = "rint";
    aclnnStatus p1 = aclnnRotateQuantGetWorkspaceSize(xT, rT, nullptr, -1, rm, 0, 0.0, false, yT, sT, &ws, &ex);
    aclDestroyTensor(xT); aclDestroyTensor(rT); aclDestroyTensor(yT); aclDestroyTensor(sT);
    aclrtFree(xd); aclrtFree(rd); aclrtFree(yd); aclrtFree(sd);
    return (int)p1;
}
int main() {
    aclInit(nullptr); aclrtSetDevice(0);
    printf("baseline      M=4 N=256   K=64   -> p1=%d\n", call(4, 256, 64));
    printf("N<128         M=4 N=64    K=64   -> p1=%d  (doc:161002)\n", call(4, 64, 64));
    printf("N>16000       M=4 N=16384 K=64   -> p1=%d  (doc:161002)\n", call(4, 16384, 64));
    printf("K<16          M=4 N=128   K=8    -> p1=%d  (doc:161002)\n", call(4, 128, 8));
    printf("K>1024        M=2 N=2048  K=2048 -> p1=%d  (doc:161002)\n", call(2, 2048, 2048));
    int bad = (call(4, 64, 64) == 561103) || (call(4, 16384, 64) == 561103);
    printf("对照组 CTRL return code = 0\n");
    printf("缺陷组 DEFECT return code = %d\n", bad ? 1 : 0);
    aclrtResetDevice(0); aclFinalize();
    return 0;
}

实测输出:

baseline      M=4 N=256   K=64   -> p1=0
N<128         M=4 N=64    K=64   -> p1=561103  (doc:161002)
N>16000       M=4 N=16384 K=64   -> p1=561103  (doc:161002)
K<16          M=4 N=128   K=8    -> p1=561103  (doc:161002)
K>1024        M=2 N=2048  K=2048 -> p1=561103  (doc:161002)
对照组 CTRL return code = 0
缺陷组 DEFECT return code = 1

影响

561103 是内部错误码,调用方无法据此判断是传参越界还是算子内部异常,通常按「算子故障」上报;
同类越界(N%8、N%K)已返回 161002,口径不一致会让上层参数校验用例产生误判。

建议

把 N_MIN/N_MAX/K_MIN/K_MAX 上移到 CheckIntRotationShape()(与 N % 8、K != 0 放在一起)
返回 161002,tiling 侧保留同样兜底。

同族参考:#7400(前置维不一致报 561103)、#7298(aclnnEinsum 形状不符 561103)、
#7293(同族 matmul 两种错误码并存)。

likedislike
liuhanwen8liuhanwen8
26 days ago Added label: bug-report
yuning_chen
yuning_chenCollaborators
26 days ago Comments:

初步分析

感谢反馈。

现象理解:
aclnnRotateQuant N/K 越界实测返回 561103,资料错误码表仅 161001/161002;同接口部分 shape 约束已在首段报 161002。

当前判断:初步判断,待复现确认。
偏校验分层导致错误码分裂。范围检查在 tiling,对齐/整除检查在 aclnn。

涉及范围:
rotate_quant op_api 与 arch22 tiling 的 N/K 范围校验。

下一步:
建议将 N/K 范围校验前移到首段并返回 161002,或资料显式声明 tiling 场景返回 561103。

likedislike
yuning_chenyuning_chenCollaborators
25 days ago Assign yushan-kite as responsible person
yuning_chen
yuning_chenCollaborators
25 days ago Comments:

您好,问题已收到,当前 @yushan-kite 正在处理中。

likedislike
zhangzhuoran3
zhangzhuoran3Collaborators
24 days ago Comments:
likedislike
CANN-robotCANN-robotCollaborators
24 days ago Assign zhangzhuoran3 as responsible person
zhangzhuoran3zhangzhuoran3Collaborators
24 days ago Removed responsible person yushan-kite
zhangzhuoran3zhangzhuoran3Collaborators
18 days ago Associated pull request
CANN-robotCANN-robotCollaborators
18 days ago Close issue
CANN-robotCANN-robotCollaborators
18 days ago Added label: resolved