已合并
inductor/fx_passes: dynamic graph optimization e2e #44486
dezheng889创建于 11 天前
inductor/fx_passes: dynamic graph optimization e2e #44486
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 dezheng889 的贡献)11 天前 创建了 pull request,commit 26502df2
atomgit-bot
11 天前 评论:
11 天前 评论:
变更摘要
本 PR 主要面向 NPU Inductor 的动态图优化端到端能力,新增了三类图改写 pass:grouped_matmul_fusion_pass、multi_slice_concat_pass 与 stack_sum_to_add_chain_pass,将多个小 GEMM、多段列切片拼接、以及 stack+sum 等模式折叠为更少的内核调用;同时新增 npu_ext::multi_slice_concat 的 Triton 模板与 lowering 实现,并引入相应配置开关与注册机制。改动还包括 check_op_util.py 中的匹配辅助函数,以及三个 pass 的完整单元测试与编译端到端测试。
主要改动
- 新增三项图优化 pass 及配套测试: 在
ascend_graph_pass.py中提供grouped_matmul_fusion_pass、multi_slice_concat_pass、stack_sum_to_add_chain_pass,分别将独立小矩阵乘合并为npu_grouped_matmul、将固定偏移列切片拼接改写为multi_slice_concat、将 stack+sum 改写为加法链;并新增test_grouped_matmul_pass.py、test_multi_slice_concat_pass.py、test_stack_sum_pass.py覆盖静态/动态 shape、拒绝条件与数值一致性。 - 新增
multi_slice_concat内核 lowering: 在kernel/multi_slice_concat.py中实现_register_npu_inductor_multi_slice_concat,基于NPUTritonTemplate按段计划生成 kernel 源码、按计划缓存模板、去重同 buffer 输入并在失败时回退到逐段拷贝,同时在kernel/__init__.py和torch_npu/_inductor/__init__.py中按enable_multi_slice_concat开关完成导入与注册。 - 新增配置项控制优化行为: 在
config.py中新增_parse_int_env及stack_sum_add_chain_max_inputs、enable_multi_slice_concat、multi_slice_concat_max_segments/max_sources/max_masks、enable_grouped_matmul_fusion、grouped_matmul_min_groups/max_groups_per_call/max_rows等环境变量,用于限制各 pass 的分组规模、源/掩码数量等上限。 - 扩展默认关闭 pass 注册机制: 在
register_custom_pass.py中将multi_slice_concat_pass和grouped_matmul_fusion_pass纳入DEFAULT_SHUT_DOWN_PASSES,使其在未开启enable_multi_slice_concat或enable_grouped_matmul_fusion时不会被注册执行。 - 新增图匹配辅助工具: 在
check_op_util.py中新增is_single_user和normalize_dim,用于判定节点是否仅有一个消费者,以及将可能为负的维度规范到有效范围,供各 pass 在匹配与拒绝条件判断中使用。


ascend-robot
11 天前 评论:
11 天前 评论:
atomgit-bot
11 天前 评论:
11 天前 评论:
11 天前 添加了label:stat/needs-squash
此处折叠了84条消息 查看更多
11 天前 添加了label:lgtm
li_jing_hw
11 天前 评论:
11 天前 评论:
/approve


11 天前 添加了label:approved
11 天前 合入了pull request
ascend-robot
11 天前 评论:
11 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14000 [ commitID:198185ed ] 已完成


【合入来源】
【修改方案】
【资料变更】
【接口变更】
【功能验证】
【CheckList】