已合并
fix(inductor): keep autotune from nesting a profiler session #44117
dezheng889创建于 16 天前
fix(inductor): keep autotune from nesting a profiler session #44117
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 dezheng889 的贡献)16 天前 创建了 pull request,commit ce03affc
atomgit-bot
16 天前 评论:
16 天前 评论:
变更摘要
此 PR 修复了两个与 torch_npu Inductor 后端相关的 bug:一是自动调优(autotune)在调用者已开启 profiler 时会嵌套启动新的 profiler 会话,导致外部会话的 trace 数据被提前终结;二是 filter_masks 在处理动态形状 cat 时,错误地将 size symbol 当作循环轴处理,导致 guard mask 被丢弃、读取越界。修复方案包括新增 profiler 状态探测函数 npu_profiler_session_active() 以在关键路径上跳过嵌套 profiler 启动,以及在 NPUIndexTritonKernel.filter_masks 中过滤掉 size symbol。
主要改动
- 新增
npu_profiler_session_active()探测函数:在torch_npu/_inductor/runtime/triton_heuristics.py中新增该函数,通过访问ProfPathCreator().is_prof_inited判断当前进程是否已有活跃的 profiler 会话,并在探测失败时静默返回False,确保不会中断 kernel 启动路径。 - 批量 benchmark 跳过外部 profiler 会话:在
NPUCachingAutotuner._benchmark_kernel_funcs_batch中,当npu_profiler_session_active()返回True时跳过mspti_batch_benchmark调用并返回None,让调用者回退到逐配置的 event timer 方式。 - 带宽 benchmark 回退到 event timer:在
NPUCachingAutotuner._bench_with_launch_args中,当 profiler 会话活跃时跳过do_bench_using_profiling_npu,改用benchmarker.benchmark_gpu的 event timer 进行计时,避免嵌套 profiler 会话破坏外部 trace。 filter_masks过滤 size symbol:在NPUIndexTritonKernel.filter_masks中,从current_subblock_axis中排除以s/ps/i开头的 size symbol,防止其因无法通过issubset测试而错误地丢弃动态cat切片上的 guard mask。- 新增完整测试覆盖:新增
test/_inductor/test_autotune_profiler_session.py(5 个用例)和test/_inductor/test_dynamic_cat_mask.py(5 个用例),分别验证 profiler 嵌套防护的各类回退路径和动态 cat 的 mask 过滤正确性。


ascend-robot
16 天前 评论:
16 天前 评论:
atomgit-bot
16 天前 评论:
16 天前 评论:
16 天前 添加了label:stat/needs-squash
此处折叠了55条消息 查看更多
13 天前 关闭了关联的issue
13 天前 合入了pull request
ascend-robot
13 天前 评论:
13 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#13865 [ commitID:3b0dd199 ] 运行失败


dezheng889
5 天前 评论:
5 天前 评论:
/sync master


ascend-robot
5 天前 评论:
5 天前 评论:
In response to this:
/sync master
同步操作执行结果:
| Branch | Status | Pull Request |
|---|---|---|
| master | 同步失败:请手动创建 PR 进行同步,我们会继续完善分支之间同步操作,尽量避免同步失败的情况 |


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