Pull Request已成功合入, 合并人@CANN-robot
(感谢 RuiWang_ 的贡献)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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


Now let me write the summary.
变更摘要
此 PR 主要修复了 reduce_log_sum_exp、reduce_max、reduce_min、reduce_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_exp的REGISTER_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、匿名命名空间内的ReduceLogSumExp13Prop与GetProperty、ParseOpToGraphReduceLogSumExp13,结构对齐其他三个算子,但未处理noop_with_empty_axes属性(存在不一致)。reduce_log_sum_exp:noop_with_empty_axes检查从else if改为独立if:ParseParamsReduceLogSumExp中对该属性的检查不再受keepdims的else if约束,结构更清晰,无功能变化。


代码审查
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 |
💬 仅评论


🔵 Low Priority
在 reduce_log_sum_exp_onnx_plugin.cpp 的 ParseParamsReduceLogSumExp 中,旧代码使用 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
| - i |
|
43 | + size_t num = v_axes.size(); |


/lgtm
/approve


描述
修复reduce_min/reduce_max/reduce_prod/reduce_log_sum_exp onnx plugin, axes为空时报错
关联的Issue
https://gitcode.com/cann/ops-math/issues/1992
测试
文档更新
类型标签