Merged
fix(MaxPoolV3Grad): 融合 pass 注册阶段改为 kBeforeInferShape #13743
fix(MaxPoolV3Grad): 融合 pass 注册阶段改为 kBeforeInferShape #13743
Merged
小王!Add on 16 days ago
小王!
小王!Collaborators
16 days ago

描述

将 MaxPoolGradFusionPass 的注册阶段由 CustomPassStage::kAfterInferShape 调整为 CustomPassStage::kBeforeInferShape,其余逻辑不变。

该 Pass 的 Replacement() 会创建新的 MaxPoolV3Grad 节点并替换原图;若注册在 kAfterInferShape,替换产生的新节点不会再次经过 Shape/Dtype 推导,可能导致融合后节点缺少正确的输出 shape/dtype/format,影响后续图构建、融合生效或精度结果。改为 kBeforeInferShape 后,替换节点可在图编译流程中正常走 InferShape。

修改点:

  • pooling/max_pool_v3_grad/op_graph/fusion_pass/max_pool_grad_fusion_pass.cpp
    • REG_FUSION_PASS(MaxPoolGradFusionPass).Stage(CustomPassStage::kAfterInferShape);
    • 改为 CustomPassStage::kBeforeInferShape

影响范围:MaxPoolGrad → MaxPoolV3Grad 融合路径;不涉及融合匹配、替换和 NaN 处理逻辑。

关联的Issue

#8372
https://gitcode.com/cann/ops-nn/issues/8372

测试

  • 仅注册阶段变更,未改动 MeetRequirements() / Replacement() 逻辑。
  • 待黄区验证:MaxPoolGrad → MaxPoolV3Grad 图融合是否生效、融合后 shape/dtype/format 是否正确、原始精度用例是否 PASS。
  • 蓝区无 Ascend950 NPU,尚未做真实 GE 图融合和精度回归。

文档更新

不涉及

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 小王!'s contribution.)
小王!小王!Collaborators
16 days ago Created pull request, commit b0475746
atomgit-bot
atomgit-bot
16 days ago Comments:

变更摘要

本 PR 调整了 MaxPoolGradFusionPass 融合 pass 的注册阶段,将其由 CustomPassStage::kAfterInferShape 改为 CustomPassStage::kBeforeInferShape,使该融合 pass 在 InferShape 之前执行;融合匹配与替换逻辑本身未做任何改动,属于注册阶段的单点修复。

主要改动

  • 融合 pass 注册阶段前移: 在 max_pool_grad_fusion_pass.cpp 中将 REG_FUSION_PASS(MaxPoolGradFusionPass) 的 Stage 参数由 CustomPassStage::kAfterInferShape 改为 CustomPassStage::kBeforeInferShape,使 MaxPoolGradFusionPass 在 InferShape 阶段之前被调度执行。
  • 融合逻辑保持不变: 本次仅修改注册宏的 stage 参数,MaxPoolGradFusionPass 的匹配(Match)与替换(Replacement)流程及 MaxPoolV3Grad 算子图结构均未变更。

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

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

代码审查

审查结论

已检视文件

  • pooling/max_pool_v3_grad/op_graph/fusion_pass/max_pool_grad_fusion_pass.cpp:发现 1 处问题(P2)

问题清单

  • P2 × 1:注册阶段硬编码为 kBeforeInferShape,未沿用同族 pass(max_pool_fusion_pass.cpp、max_pool_grad_with_argmax_v3_fusion_pass.cpp、max_pool_with_argmax_v3_fusion_pass.cpp)的「编译期宏守卫 + 运行期 GE 版本自适应(9.0+ 用 kCompatibleInherited)」模式,在该 pass 唯一生效的新平台上与前向 MaxPoolFusionPass 阶段分裂,破坏文件自身声明的「前向/后向融合属性与实现保持一致」契约,存在前后向融合不在同一阶段执行、本修复在目标平台失效的风险。

总体风险评估:本次改动仅一行、逻辑面很小,但方向性可能不完整——不是把 kAfterInferShape 换成 kBeforeInferShape 就与同族对齐;若不同步引入版本自适应与 #if 守卫,该 pass 在 GE 9.0+ 平台上仍与配对的 MaxPoolFusionPass 处于不同阶段。建议按同族模式补齐后再合入,风险等级中等,需在目标平台(Ascend950/Ascend350/Ascend960DT)上验证前向+后向成对融合结果。

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

💬 仅评论


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

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
16 days ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
16 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
pooling ✅ 上官秦南, 陈琦 (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_52056150, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
16 days ago Set zengjuan,u010470851,Nice_try,chaotang233,kevin_huang1234,crystalhu,yangyang016,fanqirui,su-yueming,yourealize,chenqi317,wang-xing001,liubo75,tangweiwei2,chenxingyu18,pingchuantang,qianzehong,liuchuangdev as approver
CANN-robotCANN-robotCollaborators
16 days ago Set u010470851,Nice_try,kevin_huang1234,su-yueming,yourealize,wang-xing001,chenxingyu18,pingchuantang,qianzehong,liuchuangdev as approver
atomgit-bot
atomgit-bot16 days agoStart code review2
pooling/max_pool_v3_grad/op_graph/fusion_pass/max_pool_grad_fusion_pass.cpp
@@ -259,3 +259,3 @@
259259}
260260 
261-REG_FUSION_PASS(MaxPoolGradFusionPass).Stage(CustomPassStage::kAfterInferShape);
261+REG_FUSION_PASS(MaxPoolGradFusionPass).Stage(CustomPassStage::kBeforeInferShape);
atomgit-bot
atomgit-bot16 days agoComments:

🟡 Medium Priority

改动行:REG_FUSION_PASS(MaxPoolGradFusionPass).Stage(CustomPassStage::kBeforeInferShape); 把注册阶段从 kAfterInferShape 硬编码改成 kBeforeInferShape。

对照同一仓库、同一算子族、且必须与本 pass 保持一致的三份 pass(本文件头注释第 22–26 行、docs/MaxPoolGradFusionPass_en.md 均明确要求 MaxPoolGradFusionPass 的属性转换与 MaxPoolFusionPass 保持一致):

这三份 pass 都采用“编译期 #if GE_COMPILER_VERSION_NUM >= GE_COMPILER_VERSION_900 守卫 + 运行期 aclGetVersionNum("ge_compiler", &version) 判断”的方式选择阶段:运行期 GE >= 9.0 时返回 CustomPassStage::kCompatibleInherited,只有 GE < 9.0 才回退到 CustomPassStage::kBeforeInferShape(并注释说明 “D1 scenario: uses kCompatibleInherited stage (9.0.0+)”);同时它们的 MeetRequirements 里也先做 version < GE_COMPILER_VERSION_900 → return false 的版本门禁。它们的 regbase 平台判定集合(Ascend950/Ascend350/Ascend960DT/MC62)与本文件第 64 行 IsSupportedPlatform 的集合(Ascend950/Ascend350/Ascend960DT)基本一致。

受影响契约/失败模式:本 pass 只在 Ascend950/Ascend350/Ascend960DT 这类新平台生效,而这些平台正是 GE 运行期版本 >= 9.0 的场景;在该场景下前向的 MaxPoolFusionPass 会以 kCompatibleInherited 注册,本文件却以 kBeforeInferShape 注册。同一张图上前向融合与反向融合被放进不同的 pass 阶段执行,破坏“融合后向前向/后向节点属性与实现保持一致”的既有契约:

  1. 前向 MaxPool 在后一阶段才被改写为 MaxPoolV3,后向 MaxPoolGrad 在更早阶段被改写为 MaxPoolV3Grad,两者配对/属性一致性依赖的时序不再对齐,存在“前向已融合而反向未融合”或反向在前向改写前完成匹配、最终生成前向 MaxPool + 后向 MaxPoolV3Grad 的不一致组合的风险(后向引用的 orig_output 语义与已改写的前向输出不再对应);
  2. 若 9.0+ 管线中 kBeforeInferShape 已属于旧阶段语义(同族代码正是在 9.0+ 才切到 kCompatibleInherited),则该 pass 在 9.0+ 上可能不按预期时机执行,本 PR 想要的“提前到 inferShape 之前”修复在目标平台上失效。

另外该注册行没有 #if GE_COMPILER_VERSION_NUM >= GE_COMPILER_VERSION_900 守卫,而同族三份 pass 是把整条 REG_FUSION_PASS 包在该守卫内的,编译期行为也与同族不一致。

建议:按 max_pool_fusion_pass.cpp:222-235 的模式改造:新增 #define GE_COMPILER_VERSION_900 90000000、GetMaxPoolGradFusionPassStage()(aclGetVersionNum >= 900 → kCompatibleInherited,否则 kBeforeInferShape),并用 #if GE_COMPILER_VERSION_NUM >= GE_COMPILER_VERSION_900 ... #endif 包住 REG_FUSION_PASS;同时确认 MeetRequirements 的 GE 版本门禁与前向 pass 一致,保证前向/后向融合处于同一阶段。

likedislike
Incorrect?
小王!
小王!Collaborators
14 days ago Comments:

A3上无同名pass,故新增 #define GE_COMPILER_VERSION_900 90000000进去兼容性阶段会导致图融合失败

likedislike
小王!
小王!Collaborators
14 days ago Comments:

compile

likedislike
小王!小王!Collaborators
14 days ago Pre merge succeeded (commit_id: af74daa6b66209b5036a45ebb37776fe3b13d019)
CANN-robot
CANN-robotCollaborators
14 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
14 days ago Added label: ci-pipeline-running
小王!小王!Collaborators
14 days ago Modify description of pull request
CANN-robotCANN-robotCollaborators
14 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
14 days ago Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
14 days ago Comments:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!
@yourealize @fanqirui @chenxingyu18 @u010470851 @liuchuangdev @su-yueming @Nice_try

likedislike
chenqi317
chenqi317Collaborators
14 days ago Comments:

/lgtm

likedislike
sgqt12
sgqt12Collaborators
12 days ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
12 days ago Added label: lgtmapproved
CANN-robot
CANN-robotCollaborators
12 days ago Comments:

The MR can not be merged, because of CodeReview discussion not resolved

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

likedislike
小王!小王!Collaborators
12 days ago Resolved final issue
CANN-robotCANN-robotCollaborators
12 days ago Closed associated issue
CANN-robotCANN-robotCollaborators
12 days ago Merged pull request
CANN-robot
CANN-robotCollaborators
12 days ago Comments:

Pull Request 已合并或已关闭。

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

likedislike