已合并
fix(add_layer_norm): 修复InferShape未将norm多尾轴置1的bug #8804
rk创建于 8月17日
fix(add_layer_norm): 修复InferShape未将norm多尾轴置1的bug #8804
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 rk 的贡献)atomgit-bot
8月17日 评论:
8月17日 评论:
变更摘要
本 PR 主要修复 AddLayerNorm 算子在 InferShape4AddLayerNorm 中推断 mean 和 rstd 输出形状时的 bug:当 gamma 为多尾轴(多维度)时,原实现仅将最后一个归一化维置为 1,导致输出形状错误。修复后改为循环遍历所有被归一化的尾部维度并将其逐一置为 1,同时新增了对应的单元测试用例。
主要改动
- 修复多尾轴形状推断逻辑: 在
norm/add_layer_norm/op_host/add_layer_norm_infershape.cpp的InferShape4AddLayerNorm中,将原先仅执行一次shape.SetDim(shape.GetDimNum() - gamma_shape->GetDimNum(), 1)的写法改为循环遍历从shape.GetDimNum() - gamma_shape->GetDimNum()到末尾的所有维度并分别SetDim(i, 1),确保mean_shape与rstd_shape的归一化尾部维度全部置为1。 - 新增多维度 gamma 单元测试: 在
norm/add_layer_norm/tests/ut/op_host/test_AddLayerNorm_infershape.cpp中新增AddLayerNorm_infershape_multi_dim_gamma测试,构造x1/x2形状为{4, 1, 8, 16}、gamma/beta形状为{8, 16}的输入,验证mean与rstd输出形状为{4, 1, 1, 1},y与x输出形状保持{4, 1, 8, 16}。


不准确?
atomgit-bot
8月17日 评论:
8月17日 评论:
8月17日 添加了label:cann-cla/yes
CANN-robot
8月17日 评论:
8月17日 评论:
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.
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) | ✅ 钱泽洪 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


CANN-robot
8月17日 评论:
8月17日 评论:
8月17日 将zengjuan,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,wangrui_,renruhai,su-yueming,zhajianqing123,chenqi317,wang-xing001,liubo75,tangweiwei2,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong设为评审人
8月17日 将zengjuan,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,wangrui_,renruhai,su-yueming,zhajianqing123,chenqi317,wang-xing001,liubo75,tangweiwei2,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong设为评审人
8月17日 将kevin_huang1234,wangrui_,renruhai,su-yueming,zhajianqing123,wang-xing001,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong设为审查人
8月17日 将kevin_huang1234,wangrui_,renruhai,su-yueming,zhajianqing123,wang-xing001,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong设为审查人
8月17日 添加了label:ci-pipeline-running
CANN-robot
8月17日 评论:
8月17日 评论:
流水线任务触发成功
任务链接 [be7e771a20274c6c9b03cd8fb78f619e][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_report_lcov | ✅ SUCCESS | >>>>> |
[2026-08-17 19:22:19] CI执行结束


CANN-robot
8月17日 评论:
8月17日 评论:
流水线任务触发成功
任务链接 [d9ee68e6c8b449a180a4d9556f7ffb4b][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> |
[2026-08-17 19:13:53] CI执行结束


8月17日 添加了label:api-check-pass
8月17日 删除了label:ci-pipeline-running
8月17日 添加了label:ci-pipeline-passed
tangweiwei2
8月18日 评论:
8月18日 评论:
/lgtm


qianzehong
8月20日 评论:
8月20日 评论:
/lgtm
/approve


8月20日 添加了label:lgtmapproved
8月20日 关闭了关联的issue
8月20日 合入了pull request
描述
AddLayerNorm算子的InferShape4AddLayerNorm在推导mean/rstd形状时,仅对 x1 尾部第 1 根 norm 轴调用SetDim(..., 1),漏置其余 norm 轴。当gamma为多根尾轴(例如x1=[A,B,C,D]、gamma=[C,D])时,mean/rstd被错误推导为[A,B,1,D],正确应为[A,B,1,1],进而触发 tiling 侧CheckX1GammaMean校验失败(要求尾部gammaDimNum维全为 1)。修复:将单次
SetDim改为循环,把 x1 尾部gammaDimNum维全部置 1。gamma为 1 维时循环只执行 1 次,行为与原实现完全一致,零回归。InplaceAddLayerNorm复用同一 InferShape 函数,一并修复。改动原因
改动方法
norm/add_layer_norm/op_host/add_layer_norm_infershape.cpp:auto shape(*x1_shape); for (size_t i = shape.GetDimNum() - gamma_shape->GetDimNum(); i < shape.GetDimNum(); i++) { shape.SetDim(i, 1); } *mean_shape = shape; *rstd_shape = shape;关联的Issue
#https://gitcode.com/cann/ops-nn/issues/4856
测试
AddLayerNorm_infershape_multi_dim_gamma:x1=[4,1,8,16]、gamma=[8,16],校验mean/rstd=[4,1,1,1]。文档更新
无。
类型标签
AI/Agent生成声明