已合并
feat:支持融合结果上报的 Python 化 #4070
lfz2812创建于 7月20日
feat:支持融合结果上报的 Python 化 #4070
已合并
Pull Request已成功合入, 合并人@CANN-robot
(感谢 lfz2812 的贡献)此处折叠了161条消息 查看更多
7月23日 添加了label:lgtm
zhanj
7月23日 评论:
7月23日 评论:
/approve


7月23日 添加了label:approved
7月23日 合入了pull request
Pull Request
描述
在 PR3996 完成
can_fusePython 化的基础上,本 PR 继续补齐 GE 融合结果上报能力,使 Python 融合 Pass 能够完成融合可行性检查、改图和融合结果上报的完整流程。
本次修改包括:
新增
report_fusePython native 绑定:Node可迭代对象。Node转换为 C++GNode集合。GraphFuseInspectorUtils::ReportFuse上报融合结果。PassContext,并向 Python 抛出RuntimeError。ge.passes中公开report_fuse,并补充类型声明。为
SubgraphRewriter.replace增加带context的调用方式:SubgraphRewriter.replace(boundary, replacement)行为保持不变。SubgraphRewriter.replace(boundary, replacement, context=context)。context后,由底层自动完成融合可行性检查、子图替换和融合结果上报。PassContext,并向 Python 抛出RuntimeError。支持两种 Python 融合 Pass 改图流程:
can_fuse、自定义 Graph 改图接口和report_fuse。context调用SubgraphRewriter.replace,由底层统一完成检查、替换和上报。优化 Python 与 native 层的职责划分:
GNode转换统一在 native 层完成,避免 Python 与 native 重复处理。can_fuse保留 Python 包装,用FuseCheckResult封装检查结果。report_fuse无需适配返回值,直接重导出 native 实现。更新 Python 融合 Pass 样例:
move_relu_before_concat_pass使用带context的SubgraphRewriter.replace。modify_conv_data_format_pass演示can_fuse、直接改图、report_fuse和旧节点删除的调用顺序。补充接口和设计文档:
report_fuseAPI 文档。SubgraphRewriter.replaceAPI 文档,说明传入和不传入context时的行为差异。补充和更新测试:
report_fuse非法PassContext入参。report_fuse。context的融合结果上报流程。can_fuse正常、异常和边界场景覆盖。调用示例:
from ge.passes import can_fuse, report_fuse # 传统直接改图方式 result = can_fuse(nodes_before) if not result.ok: context.set_error_message(result.reason) return False # 用户直接调用Graph接口完成自定义改图。 report_fuse(nodes_before, nodes_after, context) from ge.passes import SubgraphRewriter # 基于子图替换的方式 SubgraphRewriter.replace( boundary, replacement, context=context, )变更类型
关联的Issue
关联 Issue:#299
如何测试
bash tests/run_test.sh --ut=python
执行 ut_fusion_pass_executor_utest,验证 Python Pass 通过 pybind 调用 report_fuse,并检查
PythonFusionBasePass_PybindBridge_RunSuccess 用例。
检查相关 Python 融合 Pass 样例和中英文文档。
核对清单
其他信息