已合并
fix: reduce_min/reduce_max/reduce_prod/reduce_log_sum_exp axis empty onnx plugin #3429
RuiWang_创建于 6月18日
fix: reduce_min/reduce_max/reduce_prod/reduce_log_sum_exp axis empty onnx plugin #3429
已合并
RuiWang_创建于 6月18日
RuiWang_成员
6月18日

描述

修复reduce_min/reduce_max/reduce_prod/reduce_log_sum_exp onnx plugin, axes为空时报错

关联的Issue

https://gitcode.com/cann/ops-math/issues/1992

测试

文档更新

类型标签

  • Bug修复
  • 新特性
  • 性能优化
  • 文档更新
  • 其他,请描述:
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 RuiWang_ 的贡献)
RRuiWang_成员
6月18日 创建了 pull request,commit e56c8e78
CANN-robotCANN-robot成员
6月18日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
6月18日 评论:

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


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
math/reduce_log_sum_exp 宋凯, jia0liang (2/2) 宋凯 (1/1)
math/reduce_max 宋凯, jia0liang (2/2) 宋凯 (1/1)
math/reduce_min 宋凯, jia0liang (2/2) 宋凯 (1/1)
math/reduce_prod 宋凯, jia0liang (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

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

likedislike
RRuiWang_成员
6月18日 修改标题为 “fix: reduce_min/reduce_max/reduce_prod/reduce_log_sum_exp axis empty onnx plugin”,原标题为“fix: reduce_min/reduce_max/reduce_prod/reduce_log_sum_exp onnx plugin”
RRuiWang_成员
6月18日 修改了pull request 的描述
RRuiWang_成员
6月18日 修改了pull request 的描述
RuiWang_成员
6月18日 评论:

compile

likedislike
RRuiWang_成员
6月18日 update merge request[project id: 7649531, iid: 3429, commit_id: 71d74d3e7075fd71685dd56d29092ce03ff44f77] virtual merging success
CANN-robotCANN-robot成员
6月18日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6月18日 评论:

流水线任务触发成功
任务链接 [1f314aa3b79047439460415cd13e9238][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_A5 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_A5 ✅ SUCCESS >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_harmony-infer ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
UT_Test_experimental ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-06-18 14:23:21]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
6月18日 评论:

流水线任务触发成功
任务链接 [7eaddc67a0a446a0b38ae6b91c050caa][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_Pr ✅ SUCCESS
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_codestyle ✅ SUCCESS >>>>>
codecheck_precommit ⚠️ WARNING >>>>> >>>>>

[2026-06-18 14:19:45]    CI执行结束

likedislike
atomgit-bot
atomgit-bot
6月18日 评论:

Now let me write the summary.

变更摘要

此 PR 主要修复了 reduce_log_sum_expreduce_maxreduce_minreduce_prod 四个 ONNX 插件的实现。核心变更包括:为各算子补齐 noop_with_empty_axes 属性的存储/传递/设置流程;拆分 ONNX opset 8-12 与 13-18 的注册路径(PartitionedCall vs 算子名),并新增 opset 13+ 对应的 ParseParams*13 / ParseOpToGraph*13 函数;移除冗余的 GetInputTensorDimNum 辅助函数,改为在 opset 13+ 路径中统一通过 GetAttr("axes") 获取空轴张量。reduce_log_sum_exp 改动量最大,单独新增了 ParseParamsReduceLogSumExp13 等完整链条。

主要改动

  • 分离 ONNX opset 8-12 与 13-18 注册路径: 将 reduce_max / reduce_min / reduce_prod / reduce_log_sum_expREGISTER_CUSTOM_OP 拆为两组:"PartitionedCall" 覆盖 opset 8-12,新增 "ReduceMax" / "ReduceMin" / "ReduceProd" / "ReduceLogSumExp" 覆盖 opset 13-18,各自绑定对应版本的 ParseParams / ParseOpToGraph 函数。
  • 补齐 noop_with_empty_axes 处理 (reduce_max/min/prod): 在 opset 8-12 的 ParseParamsReduce* 中存储 noop_with_empty_axes=0,在对应的 ParseOpToGraphReduce* 中读取并调用 set_attr_noop_with_empty_axes;opset 13+ 路径则在 ParseParamsReduce*13 中从 ONNX 节点属性读取真实值并在构建图时设置。
  • 移除 GetInputTensorDimNum,改用空轴张量传递: 删除了三个文件中的 GetInputTensorDimNum 静态函数。opset 13+ 的 ParseParamsReduce*13 统一在 input_size==1 时存储一个空轴张量(dims={0}),由 ParseOpToGraphReduce*13 通过 GetAttr("axes") 获取,不再运行时查询输入维度计算全轴列表。
  • reduce_log_sum_exp 新增 opset 13+ 完整支持: 新增 ParseParamsReduceLogSumExp13、匿名命名空间内的 ReduceLogSumExp13PropGetPropertyParseOpToGraphReduceLogSumExp13,结构对齐其他三个算子,但未处理 noop_with_empty_axes 属性(存在不一致)。
  • reduce_log_sum_exp: noop_with_empty_axes 检查从 else if 改为独立 if: ParseParamsReduceLogSumExp 中对该属性的检查不再受 keepdimselse if 约束,结构更清晰,无功能变化。
likedislike
不准确?
CANN-robotCANN-robot成员
6月18日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6月18日 添加了label:ci-pipeline-passed
atomgit-bot
atomgit-bot
6月18日 评论:

代码审查

All four files have been thoroughly reviewed. The reduce_max, reduce_min, and reduce_prod changes are consistent and correct — they add noop_with_empty_axes handling (matching their GE op definitions), remove the GetInputTensorDimNum/explicit-axis-computation pattern in favor of delegated empty-axes handling, and fix the opset 13 path where empty_axes == 1 would previously error out. The reduce_log_sum_exp changes correctly omit noop_with_empty_axes (its GE op lacks that attribute) while aligning with the same architecture.


审查总结

  • P0: 0
  • P1: 0
  • P2: 0
  • P3: 1(int num = v_axes.size() 窄化转换)

整体风险判断: 低风险。四个文件的改动逻辑一致、边界处理正确。唯一发现是一个低严重度的类型窄化问题,在实际场景中不会触发。

各文件审查结果:

  • math/reduce_log_sum_exp/framework/reduce_log_sum_exp_onnx_plugin.cpp — 1 个 P3 问题
  • math/reduce_max/framework/reduce_max_onnx_plugin.cpp — 无问题
  • math/reduce_min/framework/reduce_min_onnx_plugin.cpp — 无问题
  • math/reduce_prod/framework/reduce_prod_onnx_plugin.cpp — 无问题
类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
不准确?
atomgit-bot
atomgit-bot6月18日进行代码检视1
math/reduce_log_sum_exp/framework/reduce_log_sum_exp_onnx_plugin.cpp
@@ -47,3 +41,3 @@
4741 }
4842 
49- int64_t len = v_axes.size();
43+ int num = v_axes.size();
atomgit-bot
atomgit-bot6月18日评论:

🔵 Low Priority

reduce_log_sum_exp_onnx_plugin.cppParseParamsReduceLogSumExp 中,旧代码使用 int64_t len = v_axes.size();,新代码改为 int num = v_axes.size();(diff 第 43 行)。

std::vector::size() 返回 size_t(64 位无符号类型),赋值给 int(32 位有符号类型)会发生窄化转换。虽然在实际场景中 ONNX 的 reduction axes 数量不会超过几十个,int 完全够用,但从旧代码的 int64_t 改为 int 是类型安全性上的退化。

其他三个文件(reduce_max/min/prod)中对应位置的 int num = axes.size(); 是已有代码,不在此 diff 变更范围内。

失败模式:若 v_axes.size() 超过 INT_MAX(实际不会发生),num 会溢出为负数,导致后续 dims.push_back(num) 写入异常的负数维度值。

建议:将 int num 改回 int64_t num 或直接使用 size_t num,与 v_axes.size() 的返回类型匹配,消除窄化转换风险。

改动建议
43
- int num = v_axes.size();
43
+ size_t num = v_axes.size();
应用建议
likedislike
不准确?
陈佳良成员
6月18日 评论:

/lgtm
/approve

likedislike
RRuiWang_成员
6月18日 解决了最后一个问题
songkai111成员
6月18日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
6月18日 添加了label:lgtmapproved
CANN-robotCANN-robot成员
6月18日 合入了pull request