已合并
[inductor]sync graph optimization and multi stream ut #44482
zzll创建于 11 天前
[inductor]sync graph optimization and multi stream ut #44482
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 zzll 的贡献)ascend-robot
11 天前 评论:
11 天前 评论:
atomgit-bot
11 天前 评论:
11 天前 评论:
变更摘要
该 PR 主要同步补充 inductor 侧图优化与多流相关的单元测试,新增 test/_inductor/test_ascend_graph_pass.py 和 test/_inductor/test_multi_stream.py。其中图优化测试覆盖 torch_npu._inductor.fx_passes.ascend_custom_passes.ascend_graph_pass 中的多种 fold/erase pass,并通过 torch.compile(..., backend="inductor") 与直接 FX 图变换两种方式对比 eager 结果;多流测试则通过 mock 环境覆盖 CATLASS 与 NPUTriton 代码生成路径在单流/多流下的 origin_node 传递及 workspace 分配/释放行为。
主要改动
- 新增图优化 UT 用例:在
test_ascend_graph_pass.py中定义CastStandardModel、CatSliceCatModel、FoldAddModel、FoldCatModel等模型,并分别调用fold_cast、cat_slice_cat_fold_pass、fold_four_op_pass、fold_cat、fold_reduce、fold_slice、fold_where、pad_slice_fold等 pass,验证图变换前后结果与 eager 计算一致。 - 新增图优化编译对比用例:针对同一批算子组合提供
*_compile_cases测试,使用torch.compile(..., backend="inductor")与标准计算结果比对,覆盖 cast、cat/slice/cat、四则运算、clone/detach/expand、reduce、view/squeeze、where、pad+slice 等场景。 - 新增多流 UT 测试替身:在
test_multi_stream.py中定义FakeGraph、FakeNode、FakeKernel、FakeWrapper、FakeScheduleGraph等 mock 对象,用于隔离测试CATLASSTemplateKernel、CATLASSScheduling、NPUTritonScheduling和NPUIndexTritonKernel的代码生成行为。 - 覆盖单流/多流分支行为:通过
patch("...is_multi_stream", return_value=...)切换单流/多流模式,验证多流时origin_node会透传到 kernel 调用及 workspace 的generate_workspace_allocation/generate_workspace_deallocation,单流时则传None。 - 新增端到端多流编译用例:提供
test_multi_stream_compile_case与test_single_stream_compile_case,在is_multi_stream开关不同取值下对包含 embedding、mm、cat、addmm 的算子图执行torch.compile,并对比 inductor 输出与 eager 结果。


atomgit-bot
11 天前 评论:
11 天前 评论:
11 天前 添加了label:ascend-cla/yes
此处折叠了50条消息 查看更多
dezheng889
7 天前 评论:
7 天前 评论:
/lgtm
/approve


7 天前 添加了label:approvedlgtm
7 天前 关闭了关联的issue
7 天前 合入了pull request
ascend-robot
7 天前 评论:
7 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14109 [ commitID:1ba7a219 ] 已完成


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