Closed
[Bug-Report|缺陷反馈]: aclnnRmsNormQuant y=INT4 输出在 Atlas A2 不可用(形状同 x 报 561103,形状取 x/8 报 161002) #7403
liuhanwen8Add on 26 days agoClosed at 17 days ago
26 days ago Added label: bug-report
yuning_chen
26 days ago Comments:
26 days ago Comments:
初步分析
感谢反馈,我们已开始核对这个问题。
现象理解:文档反馈;aclnnRmsNormQuant y=INT4 输出在 Atlas A2 不可用(形状同 x 报 561103,形状取 x/8 报 161002)。
当前判断:从描述看,这是资料/注释与实现口径不一致类文档反馈「aclnnRmsNormQuant y=INT4 输出在 Atlas A2 不可用(形状同 x 报 561103,形状取 x/8 报 161002)」。需要对照接口文档、头文件注释与实现/实测结果核对哪一侧需修正。以上为初步判断,待复现确认,不能当成已确认根因。
涉及范围:aclnnRmsNormQuant、aclnnop、aclnn_rms_norm_quant
下一步:我们会先核对文档声明与实现/测试结果是否一致,再决定改资料还是改代码。


25 days ago Assign liujie12345678 as responsible person
yuning_chen
25 days ago Comments:
25 days ago Comments:
您好,问题已收到。当前 @liujie12345678 正在处理中。


25 days ago Assign liuyun_nj as responsible person
25 days ago Removed responsible person liujie12345678
17 days ago changed custom state from 进行中 to 已完成
17 days ago Close issue
chenjiayi_
11 days ago Comments:
11 days ago Comments:
补充说明本问题的处理结果:
结论:A2/A3 不再接受「直接声明 y 为 INT4 输出」,INT4 量化结果统一以 INT32 打包张量承载(y 末维为 x 末维的 1/8);原 y=INT4 形态现在第一段返回 161002 并给出原因,文档已同步。
修复内容(文件/函数):
norm/rms_norm_quant/op_host/op_api/aclnn_rms_norm_quant.cppCheckShapeDim():非 INT32 分支新增outDtype != DT_INT4校验,命中时报OP_LOGE_FOR_INVALID_DTYPE_WITH_REASON(提示 A2/A3 上 INT4 输出需以 INT32 声明、末维为 x 的 1/8)并返回ACLNN_ERR_PARAM_INVALID;同时在该分支补上 x/y 全维一致性校验。Int42Int32PackedTensor的触发条件限定为「y 声明为 INT32 且实际按 INT4 打包」(op_api/aclnn_rms_norm_quant.cpp:438),避免对 DT_INT4 声明的 y 走 ViewCopy 时因 DT_INT32 与 DT_INT4 不一致报 561103。norm/rms_norm_quant/docs/aclnnRmsNormQuant.md:184(A2/A3 段):出参 y 由「INT8、INT4」改为「INT8、INT32(INT4 量化结果通过 INT32 承载,此时 y 的最后一维为 x 最后一维的 1/8,不支持直接以 INT4 数据类型声明输出)」。
验证:
- 修复后 y 直接声明 INT4 时第一段返回 161002,错误信息直接指向「以 INT32 声明、末维 1/8」;
- y=INT32、x=[3,40]、y=[3,5] 的打包形态两段返回 0(与 issue 中记录的实测一致),是 A2 上 INT4 量化的可用通路。
该 issue 已随修复合入关闭。


现象
资料 A2 dtype 表声明出参 y 支持 INT4,算子 def 也对
ascend910b注册了DT_INT4输出。实测 y=INT4 且 shape==x([3,16])第一段返回 561103;改成 y=INT4 且末维 = x末维/8([3,2])则返回 161002。两条路都不通。期望
资料
norm/rms_norm_quant/docs/aclnnRmsNormQuant.md「各产品型号支持数据类型说明」A2/A3 表:y 数据类型为 INT8、INT4;「参数说明」y 使用说明:数据类型不为 INT32 时 shape 需要与 x 一致。因此 y=INT4 且 shape==x 应两段返回 0。环境
711a4f5dda0d(norm/rms_norm_quant),2026-10-26复现步骤
repro.cpp;g++ -O2 -std=c++17 repro.cpp -o repro -I$ASCEND_HOME_PATH/include \ -L$ASCEND_HOME_PATH/lib64 -lascendcl -lnnopbase -lopapi./repro ctrl 0、./repro yint4 0;GetWorkspaceSize与第二段RmsNormQuant)。复现脚本
#include <cstdio> #include <cstdlib> #include <string> #include <vector> #include "acl/acl.h" #include "aclnnop/aclnn_rms_norm_quant.h" static void* MkDev(size_t bytes) { void* p = nullptr; aclrtMalloc(&p, bytes, ACL_MEM_MALLOC_HUGE_FIRST); return p; } static aclTensor* MkTen(const std::vector<int64_t>& sh, aclDataType dt, void* dev, size_t esz) { int64_t n = 1; for (auto v : sh) n *= v; std::vector<int64_t> st(sh.size(), 1); for (int i = (int)sh.size() - 2; i >= 0; --i) st[i] = sh[i + 1] * st[i + 1]; return aclCreateTensor(sh.data(), sh.size(), dt, st.data(), 0, ACL_FORMAT_ND, sh.data(), sh.size(), dev); } int main(int argc, char** argv) { std::string sc = argc > 1 ? argv[1] : "ctrl"; std::vector<int64_t> xs{3,5}, gs{1,5}, bs{1,5}, ss{1}, os{1}, ys{3,5}; aclDataType ydt = ACL_INT8; if (sc == "gamma2d") gs = {3,5}; else if (sc == "scale2d") { ss = {1,1}; os = {1,1}; } else if (sc == "scalelen3") { ss = {3}; os = {3}; } else if (sc == "empty") { xs = {0,5}; ys = {0,5}; } else if (sc == "yint4") { xs = {3,16}; gs = {1,16}; bs = {1,16}; ys = {3,16}; ydt = ACL_INT4; } else if (sc == "yint32") { xs = {3,40}; gs = {1,40}; bs = {1,40}; ys = {3,5}; ydt = ACL_INT32; } else if (sc == "xyrank3") { xs = {1,3,5}; ys = {3,5}; } if (aclInit(nullptr) != ACL_SUCCESS) return 1; if (aclrtSetDevice(atoi(argc > 2 ? argv[2] : "0")) != ACL_SUCCESS) return 1; aclrtStream stm = nullptr; aclrtCreateStream(&stm); auto num = [](const std::vector<int64_t>& s) { int64_t n = 1; for (auto v : s) n *= v; return (int)(n > 0 ? n : 1); }; int nx = num(xs), ng = num(gs), nb = num(bs), ns = num(ss), no = num(os), ny = num(ys); std::vector<uint16_t> xh(nx), gh(ng), bh(nb), sh(ns); for (auto& v : xh) v = aclFloatToFloat16(-1.5f); for (auto& v : gh) v = aclFloatToFloat16(1.0f); for (auto& v : bh) v = aclFloatToFloat16(0.25f); for (int i = 0; i < ns; ++i) sh[i] = aclFloatToFloat16(sc == "scalelen3" ? std::vector<float>{0.01f,0.02f,0.05f}[i] : 0.01f); std::vector<int8_t> oh(no, 2), yh(ny * (ydt == ACL_INT4 ? 1 : 4), 0); void *dx = MkDev(nx*2), *dg = MkDev(ng*2), *db = MkDev(nb*2), *ds = MkDev(ns*2), *dof = MkDev(no), *dy = MkDev(yh.size()); aclrtMemcpy(dx, nx*2, xh.data(), nx*2, ACL_MEMCPY_HOST_TO_DEVICE); aclrtMemcpy(dg, ng*2, gh.data(), ng*2, ACL_MEMCPY_HOST_TO_DEVICE); aclrtMemcpy(db, nb*2, bh.data(), nb*2, ACL_MEMCPY_HOST_TO_DEVICE); aclrtMemcpy(ds, ns*2, sh.data(), ns*2, ACL_MEMCPY_HOST_TO_DEVICE); aclrtMemcpy(dof, no, oh.data(), no, ACL_MEMCPY_HOST_TO_DEVICE); aclTensor* x = MkTen(xs, ACL_FLOAT16, dx, 2); aclTensor* g = MkTen(gs, ACL_FLOAT16, dg, 2); aclTensor* b = MkTen(bs, ACL_FLOAT16, db, 2); aclTensor* s = MkTen(ss, ACL_FLOAT16, ds, 2); aclTensor* o = MkTen(os, ACL_INT8, dof, 1); aclTensor* y = MkTen(ys, ydt, dy, 1); uint64_t ws = 0; aclOpExecutor* ex = nullptr; auto r1 = aclnnRmsNormQuantGetWorkspaceSize(x, g, b, s, o, 1e-6, y, &ws, &ex); printf("[%s] GetWorkspaceSize = %d\n", sc.c_str(), (int)r1); if (r1 == 0) { void* p = ws > 0 ? MkDev((size_t)ws) : nullptr; auto r2 = aclnnRmsNormQuant(p, ws, ex, stm); printf("[%s] RmsNormQuant = %d\n", sc.c_str(), (int)r2); if (r2 == 0) { aclrtSynchronizeStream(stm); std::vector<int8_t> out(ny, 0); aclrtMemcpy(out.data(), ny, dy, ny, ACL_MEMCPY_DEVICE_TO_HOST); printf(" y[0..7]="); for (int i = 0; i < ny && i < 8; ++i) printf("%d ", out[i]); printf("\n"); } if (p) aclrtFree(p); } aclFinalize(); return 0; }实测输出:
影响
A2 上按资料选 INT4 输出必然失败,且失败点在 ViewCopy 内部(561103),调用方无法从返回码看出是 dtype 组合问题;INT4 量化是该接口的主要使用形态之一。当前唯一可用的是 y=INT32 且末维取 x末维/8(该形态资料 A2 表未列)。
建议
plog 显示根因:
RunRmsNormQuantKernel里 kernel 返回 DT_INT32 打包结果,随后对 dtype=DT_INT4 的 y 做ViewCopy,contiguous.cpp:638报「Input tensor's dtype[DT_INT32] should be same with output's dtype[DT_INT4]」。建议非 regbase 路径按 y 实际 dtype 选择 ViewCopy 目标(或先 Cast 再 ViewCopy),或在文档与 def 层明确 A2 只支持 INT32 打包输出,避免声明支持却不可用。