已合并
fix(add_layer_norm_quant): 修复static量化空Tensor场景 #9903
fix(add_layer_norm_quant): 修复static量化空Tensor场景 #9903
已合并
rk创建于 9月5日
rk成员
9月5日

描述

修复 aclnnAddLayerNormQuant 算子在 static 量化场景下空 Tensor 处理不完整的问题。

static 量化场景下 outScales 输出无实际意义(static 量化使用 input scales,不依赖 output scales)。原代码在 Regbase(Ascend950)架构上的空 Tensor 早返回判断条件为 outScales1Out->IsEmpty():当 x1 为空但 outScales1Out 不为空时,该条件不成立,算子未走早返回,继续执行导致问题。

改动原因

aclnnAddLayerNormQuantGetWorkspaceSize 中 Regbase 架构的空 Tensor 早返回判断条件 outScales1Out->IsEmpty() 不适用于 static 量化场景:static 量化下 outScales 无实际意义,其是否为空不能作为空 Tensor 的判据。当 x1 为空但 outScales1Out 非空时,未走早返回路径,算子执行异常。

改动方法

  1. 引入 IsDynamicQuant(quantMode) 区分 dynamic/static 量化(已有函数)。
  2. 新增 regbaseEmptySkip 判据:dynamic 量化看 outScales1Out->IsEmpty(),static 量化看 x1->IsEmpty(),将 Regbase 空 Tensor 早返回条件由 outScales1Out->IsEmpty() 改为 regbaseEmptySkip,正确覆盖 static 量化下 x1 为空tensor的场景。
  3. 新增 2 个 UT 用例:
    • static_outer_axis_empty:x1={0,64}、gamma={64},验证 outer axis 为空时返回 ACL_SUCCESS 且 workspaceSize==0。
    • static_normalized_axis_empty:x1={2,0}、gamma={0},验证归一化轴为空时返回 ACL_SUCCESS 且 workspaceSize==0。
  4. 整理测试文件头部 license 文本格式。

涉及文件:

  • norm/add_layer_norm_quant/op_host/op_api/aclnn_add_layer_norm_quant.cpp(+3 -2)
  • norm/add_layer_norm_quant/tests/ut/op_host/op_api/test_aclnn_add_layer_norm_quant.cpp(+62 -6)

关联的Issue

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

测试

  • 新增 UT 用例 static_outer_axis_empty(x1={0,64})和 static_normalized_axis_empty(x1={2,0}),验证 static 量化场景下空 Tensor 返回 ACL_SUCCESS 且 workspaceSize==0。
  • 测试环境:SocVersion::ASCEND950。

文档更新

不涉及

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 rk 的贡献)
Rrk成员
9月5日 创建了 pull request,commit 0faf841f
CANN-robotCANN-robot成员
9月5日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
9月5日 评论:

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
norm ✅ 钱泽洪, 陈昊文 (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

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

likedislike
CANN-robotCANN-robot成员
9月5日 将zengjuan,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,wangrui_,renruhai,su-yueming,zhajianqing123,chenqi317,wang-xing001,liubo75,tangweiwei2,chenxingyu18,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong设为评审人
CANN-robotCANN-robot成员
9月5日 将kevin_huang1234,wangrui_,renruhai,su-yueming,zhajianqing123,wang-xing001,chenxingyu18,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong设为审查人
yuning_chen
yuning_chen成员
9月5日 评论:

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

likedislike
rk成员
9月7日 评论:

compile

likedislike
Rrk成员
9月7日 预合并成功(commit_id: da9bbeb7761573484e4cfd9e859279a2aec265e6)
CANN-robot
CANN-robot成员
9月7日 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
9月7日 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
9月7日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
9月7日 添加了label:ci-pipeline-passed
yuning_chen
yuning_chen成员
9月7日 评论:

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

likedislike
Rrk成员
9月8日 修改了pull request 的描述
此处折叠了6条事件消息 查看更多
CANN-robotCANN-robot成员
9月8日 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
9月8日 评论:

Notification

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

likedislike
CANN-robotCANN-robot成员
9月8日 添加了label:cann-cla/yes
yuning_chen
yuning_chen成员
9月8日 评论:

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

likedislike
Rrk成员
9月8日 修改了pull request 的描述
此处折叠了5条事件消息 查看更多
Rrk成员
9月9日 修改了pull request 的描述
rk成员
9月10日 评论:

compile

likedislike
Rrk成员
9月10日 预合并成功(commit_id: 4e687c3190184989b208f1046444d404d162f8c0)
CANN-robot
CANN-robot成员
9月10日 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
9月10日 添加了label:ci-pipeline-running
Rrk成员
9月10日 修改了pull request 的描述
Rrk成员
9月10日 修改了pull request 的描述
CANN-robotCANN-robot成员
9月10日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
9月10日 添加了label:ci-pipeline-passed
yuning_chen
yuning_chen成员
9月10日 评论:

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

likedislike
Chen_HaoWen成员
9月11日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
9月11日 添加了label:approved
qianzehong成员
9月11日 评论:

/approve
/lgtm

likedislike
CANN-robotCANN-robot成员
9月11日 添加了label:lgtm
CANN-robotCANN-robot成员
9月11日 关闭了关联的issue
CANN-robotCANN-robot成员
9月11日 合入了pull request