Merged
[Fix] 长尾算子加固:ForeachDivList 契约对齐社区 issue(out shape size≥x1) #13515
[Fix] 长尾算子加固:ForeachDivList 契约对齐社区 issue(out shape size≥x1) #13515
Merged
wenqi_wuAdd on 19 days ago
wenqi_wu
wenqi_wu
19 days ago

描述

针对社区对 aclnnForeachDivList 提出的 3 个问题单(wangyueting/changwei_jiaoyiming #35/#36/#37)完成闭环:

  • #37 out 约束方向(本 PR 代码修复):按文档原始口径"out 的 shape size 大于等于 x1 的 shape size"恢复契约——op_api CheckShape 的 out 校验由逐元素完全相等放宽为 out 元素数 ≥ x1(并补 out rank≤8,EZ0015 注册错误码上报);arch35 tiling 由"元素数相等"改为 ">="(对齐公共 ForeachCommonTiling 与 foreach_abs / ForeachAddcdivScalar(PR#13111) 同族口径);文档 out 行恢复"shape size大于等于"。
  • #35 列表长度失配报错打印错误对(核验为上游已解决,本 PR 附真机验证):当前实现报错已打印三方 size("x1=…, x2=…, out=…")且 EZ0038 上报真实失配参数名;真机探针确认 out 长度失配双向返回 161002、无崩溃。
  • #36 错误码表 561002 vs 161002(核验为已解决,本 PR 附真机验证):文档错误码表 8 类 host 侧参数校验均为 161002/ACLNN_ERR_PARAM_INVALID(561002 为 tiling 内部错误码,host 参数校验按 ACLNN 语义归 161002);真机探针断言 x2 shape 失配 / dtype 不支持等场景均返回 161002。

测试补强:

  • 新增 op_api UT 8 例(本算子此前无 op_api UT):基线、out 更大、同 numel 异 shape、out 更小、列表失配双向、x2 shape 失配、不支持的 dtype——同时守护 #35/#36 的错误码口径;
  • 新增 tests/ut/op_host/op_api/ 构建挂载(父级 CMakeLists 补 add_subdirectory 循环与 OP_API_UT 注册);
  • arch35 tiling UT 新增 out 更大正例与 out 更小负例。

关联的Issue

测试

  • UT:bash build.sh -u --ops=foreach_div_list -j64 全绿(arch22 tiling 2/2 + op_api 8/8(新增) + kernel 3/3);--soc=ascend950 全绿(arch35 tiling 5/5,含新增 2 例 + op_api 8/8)
  • 构建:--pkg --soc=ascend950 出包并隔离安装
  • 真机:Ascend950PR 上 9 用例 ACLNN 探针 9/9 PASS——out=(2,4)/(3,2)/(6,) 执行成功且逐元素数值正确(y=x1/x2);out 更小 / out 列表双向失配 / x2 shape 失配 / dtype 不支持均返回 161002、无崩溃
  • 门禁:pre-commit 全 hook 通过(clang-format/codespell/OAT 等,7 文件)

文档更新

  • docs/aclnnForeachDivList.md:out 行恢复"shape size大于等于入参x1的shape size";错误码表 shape 行补注(含 out shape size 小于 x1)

类型标签

AI/Agent生成声明

  • AI辅助编写
likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for wenqi_wu's contribution.)
wenqi_wuwenqi_wu
19 days ago Created pull request, commit b94a9b97
wenqi_wuwenqi_wu
19 days ago Associated issue: [Bug-Report|缺陷反馈]: transpose_batch_mat_mul编译安装后用torch_npu调用出现精度问题,[Bug-Report|缺陷反馈]: DynamicRNN matmul对象定义有误,[Bug-Report|缺陷反馈]: dynamic_quant_update_scatter_v2 存在编译告警,aclnnForeachDivList列表长度失配报错信息打印错误对:out 失配时显示 x1/x2 的 size,aclnnForeachDivList错误码表与实现不符:文档 561002(tiling)vs 实现 161002(host),8 条错位,aclnnForeachDivList out "shape size 大于等于 x1" 与实现相反(要求完全相等)
atomgit-bot
atomgit-bot
19 days ago Comments:

变更摘要

本 PR 针对社区对 aclnnForeachDivList 提出的问题单完成闭环,核心是将其 out 约束恢复为文档原始契约:out 的 shape size 应大于等于入参 x1 的 shape size,而不再要求逐元素完全相等。对应地在 op_api 参数校验与 arch35 tiling 两条路径上同步放宽校验方向,并补充 op_api UT 与 arch35 tiling UT 用例守护新口径,同时在报错信息与错误码上报上做对齐。此外按 PR 描述还包含 tests/ut/op_host/op_api/ 的构建挂载与 docs/aclnnForeachDivList.md 的文档更新。

主要改动

  • op_api 放宽 out shape 校验: aclnn_foreach_div_list.cpp 中 CheckShape 将原来的 OP_CHECK_SHAPE_NOT_EQUAL 逐元素完全相等校验替换为按元素数比较,仅当 outSize < x1Size 时判定失败,允许 out 元素数大于 x1 或同元素数异 shape。
  • out 维度上限与错误码上报: 同一函数中新增对 (*out)[i] 的 OP_CHECK_MAX_DIM 维度检查(最多 8 维),失配时通过 OP_LOGE_WITHOUT_REPORT 与 REPORT_PREDEFINED_ERR_MSG("EZ0015") 携带 param_name/op_name/incorrect_size/reason 上报参数错误。
  • arch35 tiling 校验方向对齐: foreach_div_list_tiling.cpp 的 CheckTensorListInfo 将 out 与 x1 的 shape size 比较由 != 改为 <,错误日志改为输出实际的 out 与 x1 元素数,与公共 ForeachCommonTiling 同族算子口径保持一致。
  • arch35 tiling UT 补充正负例: test_foreach_div_list_tiling.cpp 新增 RunTilingOutShapeCase 辅助函数,并新增 out 元素数更大(GRAPH_SUCCESS)与更小(GRAPH_FAILED)两个用例。
  • 新增 op_api UT 文件: test_aclnn_foreach_div_list.cpp 新增 8 个用例,覆盖基线、out 更大、同 numel 异 shape、out 更小、out 列表双向失配、x2 shape 失配与不支持 dtype,统一断言 ACLNN_ERR_PARAM_INVALID,兼作 #35/#36 的错误码口径守护。

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

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

代码审查

✅ 未发现问题


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

likedislike
Incorrect?
wenqi_wuwenqi_wu
19 days ago Modify description of pull request
CANN-robotCANN-robotCollaborators
19 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
19 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
*/*/README.md ✅ 王星, 汤平川, 陈娇 (3/2) ✅ 陈娇 (1/1)
*/*/docs/acl*.md ✅ 陈娇, 王星, 汤平川 (3/2) ✅ 陈娇 (1/1)
foreach ✅ 王星, 汤平川 (2/2) ✅ 王星, 汤平川 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
19 days ago Set zengjuan,u010470851,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,gitee-duhuiping,wangrui_,renruhai,su-yueming,zhajianqing123,yourealize,chenqi317,wang-xing001,liubo75,tangweiwei2,gitcode-chenjiao,chenxingyu18,liujie12345678,east_yang,pingchuantang,Chen_HaoWen,qianzehong,fengying555682,caiwenwen,yanglu-1 as approver
CANN-robotCANN-robotCollaborators
19 days ago Set u010470851,kevin_huang1234,gitee-duhuiping,wangrui_,renruhai,su-yueming,zhajianqing123,yourealize,wang-xing001,gitcode-chenjiao,chenxingyu18,liujie12345678,east_yang,pingchuantang,Chen_HaoWen,qianzehong,fengying555682,caiwenwen,yanglu-1 as approver
wenqi_wu
wenqi_wu
19 days ago Comments:

compile

likedislike
wenqi_wuwenqi_wu
19 days ago Pre merge succeeded (commit_id: d9334b34924ddabf0daed0426cd002663bb4b130)
CANN-robot
CANN-robotCollaborators
19 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
19 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
19 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
19 days ago Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
19 days ago Comments:
yuning_chen
yuning_chenCollaborators18 days agoStart code review1
foreach/foreach_div_list/op_host/op_api/aclnn_foreach_div_list.cpp
@@ -150,1 +151,3 @@
150- OP_CHECK_SHAPE_NOT_EQUAL((*x1)[i], (*out)[i], return false);
151+ const int64_t x1Size = (*x1)[i]->GetViewShape().GetShapeSize();
152+ const int64_t outSize = (*out)[i]->GetViewShape().GetShapeSize();
153+ if (outSize < x1Size) {
yuning_chen
yuning_chen18 days agoComments:

out 的校验从 shape 一致放宽成只比 shape size 之后,shape 本身就不再受约束了。

  • 现在代码看来原来的 OP_CHECK_SHAPE_NOT_EQUAL 被整体替换成只比较 outSize 与 x1Size 的大小关系,tiling 侧的 CheckTensorListInfo 同样只比较 GetShapeSize()。
  • 可能存在有 out 的 shape 与 x1 不一致却能通过校验的问题,例如 x1 是 [2, 3] 而 out 传成 [6] 或 [3, 2],算子按元素数写满 out,返回给用户的张量 shape 与文档里"shape 与入参 x1 一致"的约定不符。
  • 建议可以在放宽 size 约束的同时补一条 shape 相等的校验,只把 storage shape size 放宽为大于等于,这样与 README 的描述保持一致。
likedislike
wang-xing001
wang-xing001Collaborators
18 days ago Comments:

/lgtm
/approve

likedislike
chenjiao
chenjiaoCollaborators
18 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
18 days ago Added label: approved
wenqi_wuwenqi_wu
18 days ago Pre merge succeeded (commit_id: 9afa127a2299c88b8b469ed859279a799fa0fdf5)
wenqi_wuwenqi_wu
18 days ago Force-pushed 1 commits:618e26a2-[Fix] foreach_div_list: 按社区 issue 恢复 out shape size>=x1 契约并补齐 op_api UT
wenqi_wuwenqi_wu
18 days ago Pre merge succeeded (commit_id: bbf176d3880ac1ed797500f57d691234189a36cc)
CANN-robotCANN-robotCollaborators
18 days ago Removed label: cann-cla/yes
CANN-robotCANN-robotCollaborators
18 days ago Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
18 days ago Comments:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robotCollaborators
18 days ago Added label: cann-cla/yes
CANN-robotCANN-robotCollaborators
18 days ago Removed label: approved
CANN-robot
CANN-robotCollaborators
18 days ago Comments:

Notice

New code changes of the pull request are detected and remove these labels approved. 😳

likedislike
wenqi_wu
wenqi_wu
18 days ago Comments:

感谢指出 README 与 aclnn 文档的矛盾——确认属实:本 PR 原只更新了 docs/aclnnForeachDivList.md 的 out 行,漏改了 README.md 的 y 行,已在 commit 618e26a24 补齐(README y 行同步为"shape size大于等于入参x1的shape size"),两份文档现已一致。

关于"补 shape 相等校验、仅放宽 storage shape size"的建议,说明保留"元素数大于等于"口径的两点依据,请评审权衡:

  1. 社区问题单 #37 的原始诉求即此口径:其 PROBE-001(out=(2,4) vs x1=(2,3),numel 8≥6)、PROBE-002((3,2) 同 numel 异 shape)、PROBE-003((6,) 同 numel 降维)三例均明确要求按文档"shape size 大于等于"放行;若收紧为 shape 相等,三例将重新被 161002 拒绝,等于推翻问题单诉求。
  2. 族内一致性与公共实现口径:同族 ForeachAddcdivScalar 已合入的 PR#13111 为同款行为(op_api 与 arch35 tiling 均为元素数 ≥,其对应社区问题单 #7 与本单同源、同文档模板措辞);且 arch22/910B 路径走公共 ForeachCommonTiling,其输出校验本就是"仅 src 元素数 > dst 才拒、允许异 shape"(foreach_tiling_class.h),本 PR 恰是使 arch35 与公共口径对齐。补一条说明:ForeachAddcdivScalar 的 README 存在同样的历史行文(PR#13111 亦只改了 aclnn 文档),将另提纯文档 PR 对齐,保持族内两份文档一致。

行为正确性方面:真机(Ascend950PR)探针已验证 out=(2,4)/(3,2)/(6,) 执行成功且逐元素数值正确、out 尾部不被越界改写(x1 元素数写入语义),op_api UT 8 例与 arch35 tiling UT 5 例看护该口径(commit 618e26a24)。

如您仍认为契约应收紧为"out shape 与 x1 一致",建议作为族级契约决策统一裁决(届时 ForeachAddcdivScalar/ForeachDivList 的 op_api+tiling 及已发布文档需一并调整),我可以在本 PR 或后续 PR 按裁决方向实施,请示下。

likedislike
wenqi_wu
wenqi_wu
18 days ago Comments:

compile

likedislike
wenqi_wuwenqi_wu
18 days ago Pre merge succeeded (commit_id: 2a15717a007208863421ef678fdcd6753d26d681)
CANN-robot
CANN-robotCollaborators
18 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
18 days ago Added label: ci-pipeline-running
田野田野Collaborators
18 days ago Resolved final issue
CANN-robotCANN-robotCollaborators
18 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
18 days ago Added label: ci-pipeline-passed
TangPC
TangPCCollaborators
18 days ago Comments:

/lgtm
/approve

likedislike
wang-xing001
wang-xing001Collaborators
18 days ago Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
18 days ago Added label: lgtm
yuning_chen
yuning_chenCollaborators
18 days ago Comments:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!
@wang-xing001 @pingchuantang @caiwenwen @yanglu-1 @gitcode-chenjiao @gitee-duhuiping @fengying555682

likedislike
chenjiao
chenjiaoCollaborators
17 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
17 days ago Added label: approved
CANN-robotCANN-robotCollaborators
17 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
17 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
17 days ago Comments:

Pull Request 已合并或已关闭。

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

likedislike
wenqi_wu
wenqi_wu
17 days ago Comments:

已确认并处理:参数说明表为 raw HTML

块,CommonMark 规范下 HTML 块内的 md 反引号 code span 不会被渲染、按字面输出——已提交 follow-up PR #13692 清理本 PR 与 PR#13111 触碰行中的反引号(div_list README y 行 / 两算子 aclnn 文档 out 行),并顺带补齐 addcdiv README 的 y 行口径(shape size 大于等于)。仓内其余历史行文不扩大处理,如需统一建议另行立项。

likedislike