已合并
fix(inductor): keep autotune from nesting a profiler session #44117
fix(inductor): keep autotune from nesting a profiler session #44117
已合并
dezheng889创建于 16 天前
dezheng889成员
16 天前

【合入来源】

如有社区issue,请关联issue链接
请勿携带内部流程信息(需求链接、问题单、内部issue等)

【修改方案】

请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列
如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

【资料变更】

请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

【接口变更】

请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

【功能验证】

说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤
新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 dezheng889 的贡献)
Ddezheng889成员
16 天前 创建了 pull request,commit ce03affc
atomgit-bot
atomgit-bot
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 过滤正确性。
likedislike
atomgit-bot
atomgit-bot
16 天前 评论:

代码审查

✅ 未发现问题

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

/sync master

likedislike
ascend-robot
ascend-robot成员
5 天前 评论:

In response to this:

/sync master

@crazyDannyBoy

同步操作执行结果:

Branch Status Pull Request
master 同步失败:请手动创建 PR 进行同步,我们会继续完善分支之间同步操作,尽量避免同步失败的情况
likedislike