Pull Request已成功合入, 合并人@CANN-robot
(感谢 ling-DT 的贡献)变更摘要
此 PR 修复了 AutoFuse 在 can-fuse / fuse 阶段因 no-op reshape 补轴导致的 axis metadata 不一致问题。核心改动是新增 adaption_reshape_axis_padding 模块,提供两套补轴接口:PadLeadingUnitAxisByInsertIndexesAndCompleteAttrs(标准补轴,axis id 整体偏移)和 PadLeadingUnitAxisByInsertIndexesAndCompleteAttrsKeepOriginalAxisIds(保留原始 axis id 的补轴,新增 axis 使用当前最大 id + 1)。同时,在 AscBackendSubGraphFusionDecider::CanFuse、AscBackendFusionDecider::CanFuse 和 AscBackendFusionDecider::Fuse 中前置调用 CompleteReshapeAxesForBackendCanFuse,确保融合判断和执行前已完成轴补齐与属性刷新。
主要改动
-
新增
adaption_reshape_axis_padding.h模块:引入 reshape 轴补齐的核心逻辑,包含标准补轴接口、保留原始 axis id 的补轴接口、AdjustInsertIndexesByAnchorAlignment(锚点对齐调整插入位置)、InheritReshapeAxisChanges(融合时继承 reshape 轴变更信息)以及FlushReshapeAxisChanges(轴映射后刷新 reshape 轴变更元数据)。 -
asc_backend_fusion_decider.cpp中前置补轴调用:在AscBackendSubGraphFusionDecider::CanFuse和AscBackendFusionDecider::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新增委托方法:新增CompleteReshapeAxesForBackendCanFuse、SetReshapeAxisChangeInfo和FlushReshapeAxisChanges三个静态方法,统一委托到asc_adapt命名空间下的对应实现,保持BackendUtils作为融合流程的统一入口。 -
测试覆盖:新增
ReshapeAxisPaddingCase测试夹具及多个单测用例(CompleteAttrs_RestoreReshapeAxisByBestOverlap、CompleteAttrs_RestoreMultipleReshapeAxisChangesByInsertIndexes、CompleteAttrs_RestoreReshapeAxisKeepOriginalAxisIds),覆盖标准补轴、多次 reshape 变更补轴以及保留原始 axis id 补轴场景;test_lowering_and_canfuse.cpp中新增ReshapePaddingAnchorAlignment锚点对齐与回退测试。


代码审查
我已经完成了最终检查,确认没有遗漏其他严重问题。下面是最终报告。
审查总结
本次审查覆盖了全部 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 |
💬 仅评论


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


/lgtm


Pull Request
描述
修复 AutoFuse can-fuse/fuse 阶段两类 axis metadata 问题:
变更类型
请选择本次引入的变更类型:
关联的Issue
无
如何测试
描述测试此变更的步骤和前提条件:
核对清单
其他信息
当前 PR 基于 cann/ge develop 最新回退点 bd4bc8257 重新提交修复版 reshape 补轴逻辑,并追加 reduce 原始轴按节点保存/刷新修复;不包含本地 HSTU timeout 调试修改或 Ascend0713 安装目录替换操作。