Closed
[Bug-Report|缺陷反馈]: MaxPoolV3Grad: MaxPoolGradFusionPass 注册在 kAfterInferShape 导致融合替换节点 Shape/Dtype 推导异常 #8372
小王!Add on  14 days agoClosed at  12 days ago
小王!
小王!Collaborators
14 days ago Create

问题现象

MaxPoolGradFusionPass 用于将 MaxPoolGrad 融合替换为 MaxPoolV3Grad。当前 ops-nn 将该 Pass 注册在 CustomPassStage::kAfterInferShape:

REG_FUSION_PASS(MaxPoolGradFusionPass).Stage(CustomPassStage::kAfterInferShape);

该 Pass 的 Replacement() 会创建新的 MaxPoolV3Grad 节点并替换原图。如果 Pass 在 InferShape 之后执行,替换产生的新节点不会再次经过 Shape/Dtype 推导,可能导致融合后节点缺少正确的输出 shape/dtype/format,进而影响后续图构建、融合生效或精度结果。

根因分析

  • 自定义融合 Pass 的执行阶段决定了替换节点是否还能参与后续 InferShape。
  • kAfterInferShape 阶段执行替换时,新节点是在 Shape/Dtype 推导之后创建的,无法保证替换节点获得完整的推导结果。
  • 该 Pass 只替换节点、不重新推导 shape,因此应放在 kBeforeInferShape,让替换后的 MaxPoolV3Grad 正常走 InferShape。

修复方案

将注册阶段改为:

REG_FUSION_PASS(MaxPoolGradFusionPass).Stage(CustomPassStage::kBeforeInferShape);
  • 保持融合匹配、替换和 NaN 处理逻辑不变。
  • 仅调整 Pass 注册阶段,确保替换节点在 InferShape 之前进入图。
  • 影响范围:MaxPoolGrad → MaxPoolV3Grad 融合路径;不涉及其他算子。

验证状态

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

关联 PR

likedislike
yuning_chenyuning_chenCollaborators
14 days ago Assign qq_52056150 as responsible person
CANN-robotCANN-robotCollaborators
12 days ago Close issue
CANN-robotCANN-robotCollaborators
12 days ago changed custom state from 待办的 to 已完成
CANN-robotCANN-robotCollaborators
12 days ago Added label: resolved
chenjiayi_chenjiayi_Collaborators
2 days ago Change title to "[Bug-Report|缺陷反馈]: MaxPoolV3Grad: MaxPoolGradFusionPass 注册在 kAfterInferShape 导致融合替换节点 Shape/Dtype 推导异常", originally titled "MaxPoolV3Grad: MaxPoolGradFusionPass 注册在 kAfterInferShape 导致融合替换节点 Shape/Dtype 推导异常".
chenjiayi_chenjiayi_Collaborators
2 days ago Added label: bug-report
chenjiayi_chenjiayi_Collaborators
2 days ago changed custom category from 任务 to 缺陷