Merged
fix(example): preserve ND outputs for INTrainingReduceV2 on Ascend950 #14400
fix(example): preserve ND outputs for INTrainingReduceV2 on Ascend950 #14400
Merged
zsq_888Add on 9 days ago
zsq_888
zsq_888Collaborators
9 days ago

描述

修复 Ascend950 下 INTrainingReduceV2 图模式 example 执行失败的问题。

原 example 未明确设置输出描述及格式推导,GE 格式传播后,输出被设置为 NCHW,与 Ascend950 要求输出为 ND 的约束不一致,导致图编译失败。

本次修改:

  • 显式设置 sum、square_sum 两个输出为 ND 格式、FP32 类型,并设置对应的归约输出 shape。
  • 在 example 中注册输出格式推导,确保 GE 格式传播后两个输出仍保持 ND。

本次仅修改 example,不涉及 kernel 和 tiling。

关联的Issue

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

测试

在 Ascend950DT CANN 主线环境下验证:

  • 默认 build.sh 图模式 example 编译、执行成功。

文档更新

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for zsq_888's contribution.)
zsq_888zsq_888Collaborators
9 days ago Created pull request, commit 86a1fa8c
atomgit-bot
atomgit-bot
9 days ago Comments:

变更摘要

本 PR 针对 norm/in_training_reduce_v2/examples/arch35/test_geir_in_training_reduce_v2.cpp 示例,修复 INTrainingReduceV2 在 Ascend950 上输出格式被格式传播阶段改写的问题:通过新增格式推导注册函数并显式设置两个输出的 ND 描述符,确保示例的 sum 与 square_sum 输出始终保持 ND 格式,不随输入的通道布局(如 NHWC/NDHWC)变化。

主要改动

  • 新增输出格式推导函数 InferExampleOutputFormats: 遍历算子前两个输出的 TensorDesc,同时设置 Format 与 OriginFormat 为 FORMAT_ND,并通过 UpdateOutputDesc 写回,失败时返回 ge::GRAPH_FAILED,使声明的 ND 输出在 GE 格式传播阶段得以保留。
  • 注册格式推导回调: 在 RunExample 中构造 ge::InferFormatFuncRegister,将 InferExampleOutputFormats 绑定到算子类型 INTrainingReduceV2。
  • 显式设置输出描述符: 依据输入是否为通道在后(FORMAT_NHWC/FORMAT_NDHWC)确定通道轴,构造仅保留第 0 维与通道维的 outputShape,以 FORMAT_ND、DT_FLOAT 生成 outputDesc 并设置 OriginFormat。
  • 更新两个输出并处理失败: 调用 update_output_desc_sum 与 update_output_desc_square_sum 应用该描述符,任一失败时打印 Set output descriptors failed 并返回 FAILED。

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

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

代码审查

检视总结

改动文件: norm/in_training_reduce_v2/examples/arch35/test_geir_in_training_reduce_v2.cpp(+28/-0,已逐条检视新增的 InferExampleOutputFormats、RunExample 中的输出描述符设置与格式推导注册逻辑,并对照了未修改的 CheckOutputs / ParseOptions / GenFloatData)

发现数量:

  • P0:0
  • P1:0
  • P2:1(输出描述符 dtype 硬编码 DT_FLOAT,与 fp16 输入路径的语义存在冲突风险)
  • P3:2(输出形状推导逻辑与 CheckOutputs 重复,存在双份实现分叉风险;InferExampleOutputFormats 输出个数写死 2 且失败无诊断信息)

整体风险判断: 本次改动是示例/用例侧增强(为两个输出显式声明 ND 描述符并注册格式推导回调),不触及算子 kernel、tiling 或对外接口契约,回归面很小。主要风险集中在“声明描述符”与“校验期望”两处各自硬编码(dtype 与形状)可能产生不一致,其中 dtype 一项只在 fp16 入参下可能触发,已按中等置信度上报;其余为可维护性与可诊断性建议。建议合入前确认该算子对 fp16 输入的输出 dtype 是否恒为 fp32,并据此统一描述符与 CheckOutputs 的约定。

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

💬 仅评论


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

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
9 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
9 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
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

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

likedislike
CANN-robotCANN-robotCollaborators
9 days ago Set zengjuan,u010470851,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,wangrui_,renruhai,su-yueming,zhajianqing123,yourealize,chenqi317,wang-xing001,liubo75,tangweiwei2,chenxingyu18,liujie12345678,east_yang,pingchuantang,Chen_HaoWen,qianzehong as approver
CANN-robotCANN-robotCollaborators
9 days ago Set u010470851,kevin_huang1234,wangrui_,renruhai,su-yueming,zhajianqing123,yourealize,wang-xing001,chenxingyu18,liujie12345678,east_yang,pingchuantang,Chen_HaoWen,qianzehong as approver
zsq_888
zsq_888Collaborators
9 days ago Comments:

/compile

likedislike
zsq_888zsq_888Collaborators
9 days ago Pre merge succeeded (commit_id: e1a5f34f469a5429655db2411bdec240e0a35cce)
CANN-robot
CANN-robotCollaborators
9 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
9 days ago Added label: ci-pipeline-running
atomgit-bot
atomgit-bot9 days agoStart code review1
norm/in_training_reduce_v2/examples/arch35/test_geir_in_training_reduce_v2.cpp
@@ -185,0 +201,4 @@
201+ outputShape[0] = options.shape[0];
202+ outputShape[channelAxis] = options.shape[channelAxis];
203+ TensorDesc outputDesc(ge::Shape(outputShape), FORMAT_ND, DT_FLOAT);
204+ outputDesc.SetOriginFormat(FORMAT_ND);
atomgit-bot
atomgit-bot9 days agoComments:

🟡 Medium Priority

变更行 203 用 TensorDesc(ge::Shape(outputShape), FORMAT_ND, DT_FLOAT) 把 sum/square_sum 两个输出的 dtype 硬编码为 DT_FLOAT,而同一函数第 187-188 行创建输入描述符时按 options.dtype 走,且 main/ParseOptions(56-62 行)明确支持 fp16 参数、GenFloatData 也真的按 DT_FLOAT16 填数据。

改动前后行为差异:改动前输出 dtype 由 GE 的 infer-dtype 阶段推导;改动后被显式覆盖为 DT_FLOAT,与输入 dtype 解耦。

触发条件:以 ./test_geir_in_training_reduce_v2 fp16 运行。失败模式(取决于算子 fp16 情况下输出 dtype 的真实语义):

  1. 若算子对 fp16 输入的输出为 DT_FLOAT16,则描述符声明 float32,GE 按 float32 分配输出缓冲,CheckOutputs 第 148 行 dtype 校验与第 150 行 expected.size() * sizeof(float) 长度校验都会“通过”,但 156-158 行按 float32 解释 float16 的原始字节,必然与 expected 不等,用例稳定报 FAIL(错值被当成真实测试失败,掩盖真实原因);
  2. 或在 AddGraph/InferDataType 阶段因手工 desc 与算子推导的 dtype 冲突而编译失败,只留下 "AddGraph failed" 这类无信息日志。

建议:输出 TensorDesc 的 dtype 改为按约定推导(例如 const DataType outDtype = DT_FLOAT; 并注释“该算子输出恒为 fp32,与输入 dtype 无关”),或直接使用 GE 推导的 dtype;同时与 CheckOutputs 的 dtype 校验保持同一来源,避免两处硬编码各写一份。

likedislike
Incorrect?
zsq_888zsq_888Collaborators
9 days ago Modify description of pull request
14 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
9 days ago Removed label: ci-pipeline-passedstat/needs-squash
CANN-robot
CANN-robotCollaborators
9 days ago Comments:

Notification

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

likedislike
CANN-robotCANN-robotCollaborators
9 days ago Added label: cann-cla/yes
yuning_chen
yuning_chenCollaborators
9 days ago Comments:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!
@yourealize @liujie12345678 @wangrui_ @chenxingyu18 @su-yueming @qianzehong @Chen_HaoWen @renruhai @pingchuantang

likedislike
zsq_888
zsq_888Collaborators
9 days ago Comments:

/compile

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

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
9 days ago Added label: approved
sgqt12
sgqt12Collaborators
9 days ago Comments:

/lgtm

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

Pull Request 已合并或已关闭。

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

likedislike