Merged
modify anti_mx_quant aclnn #14252
modify anti_mx_quant aclnn #14252
Merged
pyongqAdd on 10 days ago
pyongq
pyongqCollaborators
10 days ago

描述

aclnnAntiMxQuant 在辅输入 mxscale 含 0 维时早退,非空输出 y 完全未写(rc=0、ws=0,主输入与输出均非空)
在 CheckShape 中补上 y=x、mxscale 期望形状(按 tiling 公式)校验,mxscale 含 0 维等非法形状现在返回 161002,不再静默跳过计算;新增 9 个 UT 用例,同步更新了中英文文档。

关联的Issue

https://gitcode.com/cann/ops-nn/issues/8232

测试

文档更新

更新了aclnn文档

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for pyongq's contribution.)
pyongqpyongqCollaborators
10 days ago Created pull request, commit f54780d2
atomgit-bot
atomgit-bot
10 days ago Comments:

变更摘要

本 PR 针对 quant/anti_mx_quant/op_api/aclnn_anti_mx_quant.cpp 中的 aclnnAntiMxQuant 接口参数校验逻辑进行了增强,在 CheckShape 中补充输出 y 与输入 x 形状一致性的约束,并按 MX 量化块大小推导并校验 mxscale 的期望形状;同时新增 op_api 层单元测试,覆盖成功与各类参数非法场景。

主要改动

  • 输出形状约束:在 CheckShape 中新增 xShape != yShape 判断,当输出 y 与输入 x 形状不一致时返回 ACLNN_ERR_PARAM_INVALID 并打印两者形状。
  • mxscale 形状校验:新增常量 MX_BLOCK_SIZE(32)与 MXSCALE_TAIL_DIM(2),按 ceil(x.shape[axis]/32) 再折半计算 axis 维长度、末尾追加长度为 2 的维度且秩为 x 秩加 1 的方式构造 expectedMxscaleShape,与实际 mxscale 形状比对,不匹配则报参数非法。
  • 单元测试新增:新增 tests/ut/op_api/test_aclnn_anti_mx_quant.cpp,基于 ASCEND950 平台验证 aclnnAntiMxQuant 在 e4m3→bf16/fp32、空张量等场景下的成功路径及工作空间大小。
  • 非法场景覆盖:测试用例覆盖 mxscale 维度为 0、mxscale 形状不匹配、y 形状不匹配、axis 越界四类失败情形,均断言返回 ACLNN_ERR_PARAM_INVALID。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
10 days ago Comments:

代码审查

审查结论

发现的问题

P2(1 项)

  • quant/anti_mx_quant/tests/ut/op_api/test_aclnn_anti_mx_quant.cpp:51-52 — 新增 mxscale 形状校验缺少能锁定 MX_BLOCK_SIZE=32 的边界用例:两个成功用例的量化轴长度仅 4 和 64,在 blocksize 被误改为 64 时(ceil(4/64)=1、ceil(64/64)=1 后再按 2 打包)期望形状与现在完全相同,全部 6 个用例仍会通过,无法拦截该常量/公式回归;建议补 128(或 65/96)量化轴长度的成功+失败用例。

P3(1 项,可选清理)

  • quant/anti_mx_quant/op_api/aclnn_anti_mx_quant.cpp:122-126 — 新增的严格形状校验使 aclnnAntiMxQuantGetWorkspaceSize 中 if (x->IsEmpty() || mxscale->IsEmpty()) 的第二个条件成为永不单独成立的分支(x 非空时期望形状必非空,空 mxscale 必然在第 122 行被判非法;x 为空时第一个条件已短路)。功能更正确,但两处口径不一致易误导,建议统一。

逐文件复核

文件 结论
quant/anti_mx_quant/op_api/aclnn_anti_mx_quant.cpp 已复核。CheckShape 新增的 y 形状相等校验与新增 mxscale 期望形状公式(ceil(dim/32) 后 (v+1)/2 打包、尾维 2、rank=x rank+1)与 op_host anti_mx_quant_tiling_arch35.cpp 的同类校验公式一致;axis 归一化沿用既有的 axisChange,SetDim 索引已由前面的越界检查保证;op::ToString(Shape).GetString()、AppendDim 等 API 在仓库 op_api 层有先例。除上述 P3 外无功能性问题。
quant/anti_mx_quant/tests/ut/op_api/CMakeLists.txt 已复核,无问题。父级 tests/ut/CMakeLists.txt 通过 glob + add_subdirectory 会自动纳入本目录;UT_TEST_ALL OR OP_API_UT 门控与 add_modules_ut_sources(HOSTNAME ${OP_API_MODULE_NAME} ...) 写法与 quant/quantize、quant/grouped_dynamic_mx_quant 等兄弟目录完全一致;无硬编码绝对路径。
quant/anti_mx_quant/tests/ut/op_api/test_aclnn_anti_mx_quant.cpp 已复核。7 个用例的 shape/axis/dstType 组合逐一核对均与 CheckShape、CheckDtypeValid、CheckAttrValid、空 Tensor 分支的实际行为吻合(x{1,4}→mxscale{1,1,2}、x{2,64}→{2,1,2}、x{0,4}→{0,1,2} 且 workspace=0、{1,1,0}/{1,2,2}/{2,4} 触发 PARAM_INVALID、axis=2 越界);SocVersionManager 用法与兄弟 UT 一致。唯一缺口见上方 P2。

总体风险

本次改动为 ACLNN 入口补上 y 形状相等与 mxscale 期望形状校验,与 op_host tiling 契约一致,未发现正确性、安全或构建问题;风险低。主要不足是新增校验的数值边界(blocksize/打包除数)缺乏能真正区分常量取值的用例。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
10 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
10 days ago Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
*/*/docs/acl*.md ✅ 陈娇, 钱泽洪, 王子韬 (3/2) ✅ 陈娇 (1/1)
*/*/op_api/*.h ✅ 王子韬, 汤磊, 钱泽洪 (3/2) ✅ 汤磊 (1/1)
quant ✅ 钱泽洪, 王子韬 (2/2) ✅ 钱泽洪 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

pyq17870581669, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
65 messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
8 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
8 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
8 days ago Comments:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
yuning_chen
yuning_chenCollaborators
8 days ago Comments:
Chen_HaoWen
Chen_HaoWenCollaborators
8 days ago Comments:

/approve

likedislike