已合并
fix: restore reshape axis padding before autofuse can-fuse #4309
fix: restore reshape axis padding before autofuse can-fuse #4309
已合并
ling-DT创建于 8月8日
ling-DT成员
8月8日

Pull Request

描述

修复 AutoFuse can-fuse/fuse 阶段两类 axis metadata 问题:

  1. no-op reshape 补轴:重新引入 reshape 轴补齐流程,并新增独立的 keep-original-axis-id 补轴接口。新增 no-op reshape axis 使用当前最大 axis id + 1,保留原有 axis id,不 shift reshape_axis_changes,同时刷新 tensor/sched axis 与 axis_group。
  2. reduce 原始轴:按 reduce asc node name 保存、继承、查询和刷新 reduce_original_axis 信息,避免多个 reduce/融合子图继续合并后只保存一份原始轴导致覆盖或刷新错对象。保留原单份字段作为 fallback。

变更类型

请选择本次引入的变更类型:

关联的Issue

如何测试

描述测试此变更的步骤和前提条件:

  1. git commit hooks / pre-commit hooks:Passed(trim trailing whitespace、end of files、clang-format、codespell、OAT 等均通过)
  2. cmake --build /workspace/lingxing/Code/ge_0718/build/ge-compiler --target aihac_autofusion -j8:Passed
  3. 使用 /workspace/lingxing/Ascend0713 执行 TF 用例 tc_af_tf_pv_net_front_narrow_cut_onnx_0001:Pass

核对清单

其他信息

当前 PR 基于 cann/ge develop 最新回退点 bd4bc8257 重新提交修复版 reshape 补轴逻辑,并追加 reduce 原始轴按节点保存/刷新修复;不包含本地 HSTU timeout 调试修改或 Ascend0713 安装目录替换操作。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 ling-DT 的贡献)
Lling-DT成员
8月8日 创建了 pull request,commit 8bd24341
atomgit-bot
atomgit-bot
8月8日 评论:

变更摘要

此 PR 修复了 AutoFuse 在 can-fuse / fuse 阶段因 no-op reshape 补轴导致的 axis metadata 不一致问题。核心改动是新增 adaption_reshape_axis_padding 模块,提供两套补轴接口:PadLeadingUnitAxisByInsertIndexesAndCompleteAttrs(标准补轴,axis id 整体偏移)和 PadLeadingUnitAxisByInsertIndexesAndCompleteAttrsKeepOriginalAxisIds(保留原始 axis id 的补轴,新增 axis 使用当前最大 id + 1)。同时,在 AscBackendSubGraphFusionDecider::CanFuseAscBackendFusionDecider::CanFuseAscBackendFusionDecider::Fuse 中前置调用 CompleteReshapeAxesForBackendCanFuse,确保融合判断和执行前已完成轴补齐与属性刷新。

主要改动

  • 新增 adaption_reshape_axis_padding.h 模块:引入 reshape 轴补齐的核心逻辑,包含标准补轴接口、保留原始 axis id 的补轴接口、AdjustInsertIndexesByAnchorAlignment(锚点对齐调整插入位置)、InheritReshapeAxisChanges(融合时继承 reshape 轴变更信息)以及 FlushReshapeAxisChanges(轴映射后刷新 reshape 轴变更元数据)。

  • asc_backend_fusion_decider.cpp 中前置补轴调用:在 AscBackendSubGraphFusionDecider::CanFuseAscBackendFusionDecider::CanFuse 中将 CompleteReshapeAxesForBackendCanFuse 提前到策略检查之前;在 AscBackendFusionDecider::Fuse 中也增加该调用;UpdateNewNodeAttr 中新增 SetReshapeAxisChangeInfo 以在创建融合节点时继承 reshape 轴变更信息。

  • asc_graph_axis_mapping.cpp 中改进轴映射逻辑:新增 CanMapUnitRepeatAsSubset 辅助函数,允许在 FillUnmappedAxisIndex 中将 size=1 的轴与另一个图中非 size=1 的未映射轴进行配对(子集匹配),扩展了轴映射成功的场景;FlushAscSubGraphAxisInfo 中增加 FlushReshapeAxisChanges 调用以在轴映射完成后刷新 reshape 轴变更。

  • backend_utils.cpp/.h 新增委托方法:新增 CompleteReshapeAxesForBackendCanFuseSetReshapeAxisChangeInfoFlushReshapeAxisChanges 三个静态方法,统一委托到 asc_adapt 命名空间下的对应实现,保持 BackendUtils 作为融合流程的统一入口。

  • 测试覆盖:新增 ReshapeAxisPaddingCase 测试夹具及多个单测用例(CompleteAttrs_RestoreReshapeAxisByBestOverlapCompleteAttrs_RestoreMultipleReshapeAxisChangesByInsertIndexesCompleteAttrs_RestoreReshapeAxisKeepOriginalAxisIds),覆盖标准补轴、多次 reshape 变更补轴以及保留原始 axis id 补轴场景;test_lowering_and_canfuse.cpp 中新增 ReshapePaddingAnchorAlignment 锚点对齐与回退测试。

likedislike
不准确?
atomgit-bot
atomgit-bot
8月8日 评论:

代码审查

我已经完成了最终检查,确认没有遗漏其他严重问题。下面是最终报告。


审查总结

本次审查覆盖了全部 7 个变更文件:

文件 审查结果
asc_backend_fusion_decider.cpp 发现 1 个 P2 问题
asc_graph_axis_mapping.cpp 无问题
backend_utils.cpp 无问题
backend_utils.h 无问题
adaption_reshape_axis_padding.h(新增 1743 行) 无问题
asc_backend_post_processor_unittest.cpp 无问题
test_lowering_and_canfuse.cpp 无问题

问题统计:P0: 0, P1: 0, P2: 1, P3: 0

总体风险评估:此 PR 的核心逻辑正确——在 can-fuse 评估前补齐 reshape 轴信息,确保轴空间一致性。唯一的问题是 AscBackendSubGraphFusionDecider::Fuse 缺少与基类一致的防御性 CompleteReshapeAxesForBackendCanFuse 调用,在正常流程中其正确性隐性依赖 CanFuse 先执行,存在低概率的潜在风险。其余变更(轴映射 fallback 逻辑、属性继承/刷新接口、新增 keep-original-axis-id 补轴接口、单元测试)均无问题。

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

💬 仅评论

likedislike
不准确?
CANN-robotCANN-robot成员
8月8日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
8月8日 评论:

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
repo-cann/ge 张德鹏, xchu42, wangxiaotian995 (3/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

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

likedislike
此处折叠了88条消息 查看更多
wangxiaotian995成员
8月10日 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
8月10日 添加了label:lgtm
张德鹏成员
8月10日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
8月10日 添加了label:approved
CANN-robotCANN-robot成员
8月10日 合入了pull request