Closed
[Bug-Report|缺陷反馈]: aclnnAntiMxQuant 在辅输入 mxscale 含 0 维时早退,非空输出 y 完全未写(rc=0、ws=0,主输入与输出均非空) #8232
liuhanwen8Add on 16 days agoClosed at 8 days ago
16 days ago Modify description of issue
15 days ago Assign sxb154714 as responsible person
yuning_chen
15 days ago Comments:
15 days ago Comments:
yuning_chen
15 days ago Comments:
15 days ago Comments:
您好,该问题已收到,当前问题 @sxb154714 正在处理中


10 days ago Assign liujie12345678 as responsible person, remove original responsible person: sxb154714
10 days ago Assign liujie12345678 as responsible person, remove original responsible person: sxb154714
10 days ago Assign sxb154714 as responsible person, remove original responsible person: liujie12345678
10 days ago Assign sxb154714 as responsible person, remove original responsible person: liujie12345678
chenjiayi_
9 days ago Comments:
9 days ago Comments:
补充当前 master 的核对结果(2026-11-12):
quant/anti_mx_quant/op_api/aclnn_anti_mx_quant.cpp:68-105的CheckShape覆盖 x/y 维数与 mxscale 维数校验(:86-94),mxscale 各维 size 的逐维比对可作为补充。:150-154在 x 或 mxscaleIsEmpty()时置workspaceSize=0并返回ACLNN_SUCCESS;该分支先于:166-170的 Contiguous 与 l0op 调用,y元素数大于 0 时的写入在后续路径。
建议:在 CheckShape 增加 mxscale 各维 size 与 x 对应维的比对,mxscale 含 0 维时返回 161002;或把该空态纳入正常执行路径并写出 y。补 x 与 y 元素数大于 0、mxscale 第三维为 0 的 UT。


9 days ago Associated pull request
9 days ago Assign chenjiayi_ as responsible person
8 days ago Close issue
8 days ago changed custom state from 进行中 to 已完成
8 days ago Added label: resolved
chenjiayi_
2 days ago Comments:
2 days ago Comments:
补充说明本问题的后续处理:
已修复并随关联 PR 合入。
处理结果:
- !14252:modify anti_mx_quant aclnn
验证:
- 关联 PR(2026-11-13)已合入,变更可从 PR 记录追溯。
- 本次以 PR 记录与 issue 讨论核对为主,未重新执行复现或真机验证。
说明:合入分支与版本以 PR 记录为准;如仍有问题,请重新提 issue 并附版本、shape 与日志。
如果还有后续需要,请重新提 issue。


11 hours ago Removed responsible person chenjiayi_
现象
aclnnAntiMxQuant在辅输入 mxscale 含 0 维时早退,导致非空的输出 y 完全未被写。注意:主输入 x 与输出 y 都是非空的,唯一变化是 mxscale 的第三维从 2 变成 0 —— 这与既往「主输入为空」的空态缺陷不是同一触发面。0x3FC0(已写)0x7E01原样)0x7E01两路一致:sweep-example(device5)与 verifier(device6、自写探针、三阶段 hex)实测相同:基线 ws=512、written 4/4、hex
3f00×4;变异 ws=0、written 0/4、hex7e01×4原样。根因(9.3.0-beta.1,行号实测):
quant/anti_mx_quant/op_api/aclnn_anti_mx_quant.cpp的CheckShape(:68起)只取mxscaleDimNum = mxscaleShape.GetDimNum()(:86)做维数比较(要求 mxscale 维数 = x 维数 + 1),不校验各维 size;因此mxscale=[1,1,0]这种「维数对、但含 0 维」的非法形状被放行;随后:150的if (x->IsEmpty() || mxscale->IsEmpty()) { ... }把 mxscale 含 0 维当作「空」走早退,第二段不再启动(ws=0),y 保持未写。期望
两种正确行为之一:①mxscale 含 0 维时按形状非法拒绝(返回 161002),因为 mxscale 的每一维必须与 x 对应维匹配;②若视为合法空态,则必须写出 y(例如按语义填 0/1),不能返回 SUCCESS 却一个字节都不写。当前是「rc=0 + ws=0 + 非空输出完全未写」的最坏组合。
与同仓既有单的区别(防合并):ops-nn#8108 是
RmsNormDynamicMxQuant的「外层空输入(主输入尾轴以外为 0)绕过 ACLNN 参数校验」;#8109 是AddRmsNormDynamicMxQuant、#8119 是QuantBatchMatmulInplace*。本条触发面不同:主输入 x 与输出 y 都非空,唯一变化是辅输入 mxscale 的第三维 2→0 ⇒ 属「辅输入含 0 维导致非空输出未写」,请勿与上述合并。环境
libopapi.so构建 2026-10-289.3.0-beta.1@99a37ee3e2c3fb57048cd1628ed7042bba70c697(2026-11-04)0x7E01,aclnnAntiMxQuant(...)之后执行aclrtSynchronizeStream(nullptr)再aclrtMemcpy读回(避免读旧缓冲的假阳性)复现步骤
source /usr/local/Ascend/ascend-toolkit/latest/set_env.sh; export ASCEND_RT_VISIBLE_DEVICES=<空闲卡号>probe.cppg++ -std=c++17 -O2 -o probe probe.cpp -I$OFF/include -I$OFF/include/aclnnop -I$OFF/include/aclnnop/level2 -L$OFF/lib64 -lopapi -lnnopbase -lascendcl./probe:期望两行 —— 基线rc1=0 rc2=0 ws=512 金丝雀=0/4;变异rc1=0 rc2=0 ws=0 金丝雀=4/4复现脚本
实测输出(A5 / CANN 9.3.0.B020,aclnn 两段式直调,axis=-1、dstType=27):
// aclnnAntiMxQuant:辅输入 mxscale 含 0 维(主输入 x 与输出 y 均非空)时早退,y 完全未写 #include <cstdio> #include <cstdint> #include <cstring> #include <vector> #include "acl/acl.h" #include "aclnnop/aclnn_anti_mx_quant.h" static const uint16_t CAN16 = 0x7E01u; // BF16 NaN 金丝雀 static void* Dev(int64_t bytes, uint8_t fill8, uint16_t fill16, bool isBf16) { void* p = nullptr; aclrtMalloc(&p, bytes, ACL_MEM_MALLOC_HUGE_FIRST); std::vector<uint8_t> v(static_cast<size_t>(bytes), fill8); if (isBf16) { std::vector<uint16_t> w(static_cast<size_t>(bytes / 2), fill16); aclrtMemcpy(p, bytes, w.data(), bytes, ACL_MEMCPY_HOST_TO_DEVICE); } else aclrtMemcpy(p, bytes, v.data(), bytes, ACL_MEMCPY_HOST_TO_DEVICE); return p; } static aclTensor* T(std::vector<int64_t> d, aclDataType dt, void* p) { std::vector<int64_t> s(d.size(), 1); for (int i = static_cast<int>(d.size()) - 2; i >= 0; --i) s[i] = s[i + 1] * d[i + 1]; return aclCreateTensor(d.data(), d.size(), dt, s.data(), 0, ACL_FORMAT_ND, d.data(), d.size(), p); } int main() { aclInit(nullptr); aclrtSetDevice(0); for (int bad = 0; bad < 2; ++bad) { std::vector<int64_t> xD = {1, 4}; std::vector<int64_t> sD = bad ? std::vector<int64_t>{1, 1, 0} : std::vector<int64_t>{1, 1, 2}; aclTensor* x = T(xD, ACL_FLOAT8_E4M3FN, Dev(4, 0x3C, 0, false)); // F8E4M3 4 字节 aclTensor* mx = T(sD, ACL_FLOAT8_E8M0, Dev(bad ? 1 : 2, 0x7F, 0, false)); // F8E8M0 void* dy = Dev(8, 0, CAN16, true); // BF16 输出填金丝雀 aclTensor* y = T(xD, ACL_BF16, dy); uint64_t ws = 0; aclOpExecutor* ex = nullptr; int rc1 = int(aclnnAntiMxQuantGetWorkspaceSize(x, mx, -1, 27, y, &ws, &ex)); int rc2 = -1; int canary = -1; uint16_t w0 = 0; if (rc1 == 0) { void* w = ws ? Dev(int64_t(ws), 0, 0, false) : nullptr; rc2 = int(aclnnAntiMxQuant(w, ws, ex, 0)); aclrtSynchronizeStream(nullptr); // <<< 关键:D2H 前同步 if (w) aclrtFree(w); std::vector<uint16_t> v(4, 0); aclrtMemcpy(v.data(), 8, dy, 8, ACL_MEMCPY_DEVICE_TO_HOST); canary = 0; for (uint16_t t : v) if (t == CAN16) ++canary; w0 = v[0]; } printf("[%s] rc1=%d rc2=%d ws=%llu 金丝雀=%d/4 y0=0x%04X\n", bad ? "变异 mxscale=[1,1,0]" : "基线 mxscale=[1,1,2]", rc1, rc2, (unsigned long long)ws, canary, w0); aclDestroyTensor(x); aclDestroyTensor(mx); aclDestroyTensor(y); } aclrtResetDevice(0); aclFinalize(); return 0; }影响
量化算子的辅输入被上游置成含 0 维(如空 batch 的 scale 缓冲)时,接口返回成功、workspace 为 0,输出 y 保持调用方缓冲区的旧值(实测金丝雀)。调用方拿到未初始化的 BF16 数据当量化结果,后续反量化/推理会直接产生错误张量且无任何报错;
ws=512 → 0说明计算根本没有启动。建议
①
CheckShape增加 mxscale 各维 size 与 x 对应维的一致性校验(不只比维数),命中返回 161002;②:150的早退判据不要把「mxscale 含 0 维」与「合法空态」混同——若确实要支持,必须在早退分支内显式写出 y;③ 补 UT:mxscale=[1,1,0]、x/y 非空 ⇒ 期望 161002。