Merged
fix(norm): 修复 Ascend 950 RmsNormQuant 空 Tensor 校验缺失 #10240
fix(norm): 修复 Ascend 950 RmsNormQuant 空 Tensor 校验缺失 #10240
Merged
raoliang_sacAdd on Sep 10
raoliang_sacCollaborators
Sep 10

描述

修改前问题

Ascend 950(RegBase)上的 RmsNormQuant 系列缺少完整且统一的空 Tensor 校验:

  • 公共接口 aclnnRmsNormQuant 已检查空指针,但没有检查 IsEmpty();空 Tensor 可能先进入二维 gamma/beta 预处理,最终被报告为内部 reshape/contiguous 错误,而不是输入 shape 非法。
  • aclnnRmsNormQuantV3 同样只覆盖空指针和基础 shape 关系,未覆盖有效输入、输出的空 Tensor。
  • RmsNormQuantV2/V3 共用的 Ascend 950 tiling 只在较晚阶段检查 x/gamma 的部分零维场景,未统一覆盖其他输入和输出;GEIR 直接调用仍可能得到与实际非法输入不一致的报错。

本 PR 将空 Tensor 统一定义为 Ascend 950 上不支持的有效参数形态,在 ACLNN 和 GEIR tiling 两条入口都提前返回参数/shape 非法;空指针语义和非 RegBase 平台行为保持不变。

逐文件修改说明

  1. norm/rms_norm_quant/op_host/op_api/aclnn_rms_norm_quant.cpp

    • 修改前:CheckParams 已统一检查必选 Tensor 是否为空指针,但未检查空 Tensor,且二维 gamma/beta 的 PreDealData 位于 shape 参数检查之前。
    • 本次修改:新增 CheckTensorNotEmpty/CheckNotEmpty,仅在 IsRegbase() 为 true 时,于 PreDealData 前检查 x、gamma、beta、scale、offset、y 是否为空 Tensor。
    • 修改后:Ascend 950 上任一有效输入/输出为空 Tensor时,API 在预处理前返回 ACLNN_ERR_PARAM_INVALID。原有 CheckParams 仍是唯一的空指针检查入口,不存在重复 CheckNotNull;A2/A3 等非 RegBase 路径不执行新增校验。
  2. norm/rms_norm_quant_v2/op_host/rms_norm_quant_v2_tiling.h

    • 修改前:RegBase tiling 类没有统一的输入输出 shape size 校验接口。
    • 本次修改:声明 CheckInputOutputShapeSize()。
    • 修改后:RmsNormQuantV2/V3 共用 tiling 可以在维度关系和 tiling 参数计算前,通过单一入口校验空 Tensor。
  3. norm/rms_norm_quant_v2/op_host/rms_norm_quant_v2_tiling_regbase_base.cpp

    • 修改前:只在 SetInputParams() 较晚阶段检查 x 的零维和 gamma 元素数为 0;scales1、已提供的 scales2/zero_points1/zero_points2/beta、y1/y2 以及 V3 的有效 rstd 未统一覆盖。
    • 本次修改:实现 CheckInputOutputShapeSize(),在可选输入依赖检查之后、维度与参数计算之前检查所有必选输入、已提供的可选输入和 y1/y2;仅当 V3 的 output_rstd=true 时检查 rstd。删除原来覆盖不完整且时机较晚的 x/gamma 空 shape 检查。
    • 修改后:V2/V3 的 Ascend 950 GEIR 入口在 tiling 计算前统一拒绝空 Tensor,避免后续除零或误导性的内部空指针类错误;output_rstd=false 时未生效的 rstd 空占位保持允许。
  4. norm/rms_norm_quant_v2/tests/ut/op_host/test_aclnn_rms_norm_quant_v2.cpp

    • 修改前:公共 aclnnRmsNormQuant 没有逐参数空 Tensor 用例,也没有非 RegBase 兼容性回归断言。
    • 本次修改:Ascend 950 上逐一将 x、gamma、beta、scale、offset、y 设为空,断言返回 ACLNN_ERR_PARAM_INVALID;同时增加 Ascend 910B(A2)和 Ascend 910_93(A3)空 x 对照用例。
    • 修改后:覆盖 950 的新错误码契约,并明确证明 A2/A3 仍保持修改前的 ACLNN_SUCCESS 历史行为。该文件沿用既有目录命名,验证的是公开接口 aclnnRmsNormQuant 在 950 路由到 V2 L0 后的行为。
  5. norm/rms_norm_quant_v2/tests/ut/op_host/test_rms_norm_quant_v2_empty_tensor_tiling.cpp

    • 修改前:没有直接调用生产 GetShapeAttrsInfo() 的共享 tiling 空 Tensor UT,API 层提前拦截无法覆盖 GEIR 直接调用。
    • 本次修改:新增 TilingContextFaker 真入口 UT,逐一覆盖 7 个输入位置、y1/y2 为空及正常 V2 场景;同时覆盖 V3 的空 rstd 在 output_rstd=true/false 两种状态下的行为。
    • 修改后:V2/V3 共用 RegBase tiling 的输入输出空 shape 分支均有回归保护;有效 rstd 为空时失败,未请求 rstd 时空占位成功。
  6. norm/rms_norm_quant_v3/op_api/aclnn_rms_norm_quant_v3.cpp

    • 修改前:V3 未检查空 Tensor,CheckParams 也未接收 offset/beta,无法覆盖已提供的可选输入。
    • 本次修改:新增空 Tensor 检查,并把 offset/beta 纳入 CheckParams;仅在 RegBase 平台检查 x、gamma、scale、已提供的 offset/beta、y,以及 outputRstd=true 时的 rstd。
    • 修改后:Ascend 950 上有效参数为空 Tensor 时统一返回 ACLNN_ERR_PARAM_INVALID;必选空指针仍返回原有 ACLNN_ERR_PARAM_NULLPTR,outputRstd=false 时 rstd 继续允许为空指针或空 Tensor 占位。
  7. norm/rms_norm_quant_v3/op_api/aclnn_rms_norm_quant_v3.h

    • 修改前:rstd 注释笼统写为“支持空 Tensor”,未体现其有效性取决于 outputRstd。
    • 本次修改:明确 outputRstd=true 时 rstd 不支持空 Tensor;outputRstd=false 时输出无效,允许空指针或空 Tensor 占位。
    • 修改后:接口头文件与代码行为一致。
  8. norm/rms_norm_quant_v3/docs/aclnnRmsNormQuantV3.md

    • 修改前:资料没有说清关闭 outputRstd 时能否用空 Tensor 占位。
    • 本次修改:把 rstd 的非空约束限定为 outputRstd=true,补充关闭输出时支持空指针或空 Tensor 占位。
    • 修改后:用户资料与头文件、API 校验和 tiling 契约一致。
  9. norm/rms_norm_quant_v3/tests/ut/op_api/test_aclnn_rms_norm_quant_v3.cpp

    • 修改前:V3 OpAPI UT 没有逐参数空 Tensor 覆盖,也未验证 rstd 的条件有效性。
    • 本次修改:逐一将 x、gamma、scale、offset、beta、y、rstd 设为空,验证 outputRstd=true 时返回 ACLNN_ERR_PARAM_INVALID;补充 outputRstd=false 且 rstd 为空占位时成功的用例。
    • 修改后:V3 API 的所有有效输入输出空 Tensor 分支,以及 rstd 条件契约均受到 UT 保护。

兼容性结论

  • ACLNN 新增校验显式受 IsRegbase() 保护;RmsNormQuantV2/V3 OpDef 的实现仅注册 Ascend 950。
  • 本 PR 没有修改任何 kernel 或计算逻辑,只调整非法输入的校验阶段和错误码。
  • A2/A3 不进入新增校验,且已用 Ascend 910B、Ascend 910_93 两个平台用例验证历史行为不变。
  • 可选输入未提供(nullptr)仍允许;V3 未请求 rstd 时,其空指针/空 Tensor 占位仍允许。

关联的Issue

关联 Issue #5772:https://gitcode.com/cann/ops-nn/issues/5772

测试

  • 最终提交基于最新 master;提交钩子、clang-format、codespell、OAT:9 个变更文件全部通过。
  • OpHost 定向回归:42/42 PASS(含 V2/V3 tiling、InferShape,以及 A2/A3 行为保持用例)。
  • OpAPI 定向回归:18/18 PASS(含 950 空 Tensor 错误码和 V3 条件 rstd 用例)。
  • OpGraph 阶段:执行成功,本 PR 无 op_graph 变更,无新增相关用例。
  • Kernel UT 门禁:本 PR 无 op_kernel 变更,按规则跳过。
  • 单算子打包:rms_norm_quant、rms_norm_quant_v2、rms_norm_quant_v3 三个 .run 包均构建成功。
  • Ascend 950 三算子联合打包:此前使用 --pkg --ops=rms_norm_quant,rms_norm_quant_v2,rms_norm_quant_v3 --soc=ascend950 -j8 完成 920 个 kernel 对象编译并成功产包;本轮官方 compile_ascend950_pkg.sh 因变更清单不含 kernel 文件按规则跳过。
  • TTK ACLNN 真机回归(Ascend 950、使用本分支刷包):aclnnRmsNormQuant 500/500 PASS;aclnnRmsNormQuantV3 原始汇总 499/500,唯一差异为 INT4 打包值一个 nibble 相差 1 LSB,符合量化算子精度允许范围,固定种子单独重跑 1/1 PASS。
  • TTK 空 Tensor 定向:V1/V3 均在 API 校验阶段返回 161002 (ACLNN_ERR_PARAM_INVALID),未进入 kernel。
  • 全仓 scripts/ci/local_build.sh -j8 已执行;前置 JIT/Host 全仓编译被本机 CANN 9.2.0 与最新 master 的无关接口差异阻断:index/embedding、index/gather_v2 使用 OpImplRegisterV2::SetSupportPcieThrough(),当前包头文件没有该成员。本 PR 的上述定向 CI、单算子打包均通过,未出现 RmsNormQuant 编译或测试失败。

文档更新

更新 aclnnRmsNormQuantV3 用户文档与接口头文件,明确 rstd 的非空约束仅在 outputRstd=true 时生效,关闭输出时允许空占位。

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for raoliang_sac's contribution.)
Rraoliang_sacCollaborators
Sep 10 Created pull request, commit ecfe1507
atomgit-bot
atomgit-bot
Sep 10 Comments:

变更摘要

本 PR 修复 Ascend 950(RegBase)平台上 RmsNormQuant 系列算子空 Tensor 校验缺失的问题:在二维 gamma/beta 预处理、维度关系校验及 tiling 参数计算之前统一校验必选输入、已提供的可选输入与有效输出非空,空 Tensor 统一返回 ACLNN_ERR_PARAM_INVALID,并删除原先较晚、覆盖不完整的检查逻辑;同时更新 V3 rstd 输出的条件约束说明并补充 ACLNN 与 tiling 层 UT。修改仅作用于 Ascend 950/RegBase,A2/A3 等非 RegBase 平台保持原有行为不变。

主要改动

  • ACLNN 公共接口空 Tensor 校验:在 aclnn_rms_norm_quant.cpp 新增 CheckTensorNotEmpty/CheckNotEmpty,aclnnRmsNormQuant 在 RegBase 平台、二维 gamma/beta 预处理前统一校验 x、gamma、beta、scale、offset、y 非空,空 Tensor 返回 ACLNN_ERR_PARAM_INVALID。
  • V3 接口校验扩展与 rstd 条件校验:aclnn_rms_norm_quant_v3.cpp 中 CheckParams 增加 offset、beta 参数并新增 CheckNotEmpty,仅在 RegBase 平台校验 x、gamma、scale、已提供的 offset/beta、y;仅当 outputRstd=true 时校验 rstd,关闭该输出时允许空指针或空 Tensor 占位。
  • RegBase tiling 统一空 shape 校验:rms_norm_quant_v2_tiling_regbase_base.cpp 新增 CheckInputOutputShapeSize(),在维度关系与参数计算前统一校验必选输入、已提供的可选输入及有效输出的 shape size,并删除原先 SetInputParams 中较晚且覆盖不完整的 x/gamma 空 shape 检查;GetShapeAttrsInfo 中在 CheckInputShapeDim/CheckInputShapeValue 之前调用该校验。
  • V2/V3 属性兼容处理与接口文档更新:读取 V3 的 output_rstd 属性前先校验属性数量,兼容只注册 3 个属性的 V2;aclnn_rms_norm_quant_v3.h 更新 rstd 说明:outputRstd 为 true 时不允许空 Tensor,为 false 时该输出无效、允许空指针或空 Tensor 占位。
  • 补充 UT 覆盖:新增 test_rms_norm_quant_v2_empty_tensor_tiling.cpp 验证 tiling 层拒绝空输入/输出 shape、且仅当 output_rstd=true 时校验空 rstd;在 V2/V3 的 ACLNN UT 中新增 950 空 Tensor 返回 ACLNN_ERR_PARAM_INVALID 及 910B 保持旧行为的用例。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Sep 10 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Sep 10 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 10 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)
norm ✅ 钱泽洪, 唐玮玮 (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

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

likedislike
CANN-robot
CANN-robotCollaborators
Sep 10 Comments:

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 10 Set zengjuan,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,gitee-duhuiping,wangrui_,renruhai,su-yueming,zhajianqing123,tang-lei01,chenqi317,wang-xing001,liubo75,tangweiwei2,gitcode-chenjiao,chenxingyu18,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong,wangyongguang,fengying555682,caiwenwen,yanglu-1 as approver
13 event messages are collapsed here。 See more
Rraoliang_sacCollaborators
Sep 10 Modify description of pull request
raoliang_sacCollaborators
Sep 10 Comments:

compile

likedislike
Rraoliang_sacCollaborators
Sep 10 Pre merge succeeded (commit_id: d70bbd8045dad783626f1ac387cfc2787661af15)
CANN-robot
CANN-robotCollaborators
Sep 10 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 10 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 10 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 10 Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
Sep 10 Comments:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!

likedislike
wangyongguangCollaborators
Sep 11 Comments:

/approve

likedislike
chenjiaoCollaborators
Sep 11 Comments:

/approve

likedislike
qianzehongCollaborators
Sep 11 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 11 Added label: approved
tangweiwei2Collaborators
Sep 11 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 11 Added label: lgtm
CANN-robotCANN-robotCollaborators
Sep 11 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 11 Merged pull request