Pull Request has been successfully merged by CANN-robot.
(Thank you for zsq_888's contribution.)变更摘要
本 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:


代码审查
检视总结
改动文件: 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:


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


/compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


🟡 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 的真实语义):
- 若算子对 fp16 输入的输出为 DT_FLOAT16,则描述符声明 float32,GE 按 float32 分配输出缓冲,CheckOutputs 第 148 行 dtype 校验与第 150 行
expected.size() * sizeof(float)长度校验都会“通过”,但 156-158 行按 float32 解释 float16 的原始字节,必然与 expected 不等,用例稳定报 FAIL(错值被当成真实测试失败,掩盖真实原因); - 或在 AddGraph/InferDataType 阶段因手工 desc 与算子推导的 dtype 冲突而编译失败,只留下 "AddGraph failed" 这类无信息日志。
建议:输出 TensorDesc 的 dtype 改为按约定推导(例如 const DataType outDtype = DT_FLOAT; 并注释“该算子输出恒为 fp32,与输入 dtype 无关”),或直接使用 GE 推导的 dtype;同时与 CheckOutputs 的 dtype 校验保持同一来源,避免两处硬编码各写一份。


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


/compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


/lgtm
/approve


/lgtm


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
修复 Ascend950 下 INTrainingReduceV2 图模式 example 执行失败的问题。
原 example 未明确设置输出描述及格式推导,GE 格式传播后,输出被设置为 NCHW,与 Ascend950 要求输出为 ND 的约束不一致,导致图编译失败。
本次修改:
本次仅修改 example,不涉及 kernel 和 tiling。
关联的Issue
关联 Issue #8775:https://gitcode.com/cann/ops-nn/issues/8775
测试
在 Ascend950DT CANN 主线环境下验证:
文档更新
类型标签
AI/Agent生成声明