已合并
Add support of Execution Trace Observer object to torch_npu profiler (based on acl_prof). #44622
Add support of Execution Trace Observer object to torch_npu profiler (based on acl_prof). #44622
已合并
ilya_a创建于 12 天前
ilya_a
12 天前

【合入来源】

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

【修改方案】

Re-used existing PyTorch Execution Trace Observer object with torch_npu profiler (based on acl_prof).
Migrated relevant unit tests from original PyTorch test_execution_trace.py

【资料变更】

New parameter is added to npu_profiler - execution_trace_observer.
Execution Trace Observer implementation with torch_npu profiler must work the same way as with PyTorch community profiler.

【接口变更】

New parameter is added to npu_profiler - execution_trace_observer.
execution_trace_observer (ExecutionTraceObserver) : A PyTorch Execution Trace Observer object.
PyTorch Execution Traces <https://arxiv.org/pdf/2305.14516.pdf>__ offer a graph based
representation of AI/ML workloads and enable replay benchmarks, simulators, and emulators.
When this argument is included the observer start() and stop() will be called for the
same time window as npu_profiler.

It is the same Execution Trace Observer as the one used by PyTorch community profiler.

【功能验证】

Build, install, run:
export MAX_JOBS=2
TORCH_DEVICE_BACKEND_AUTOLOAD=0 bash ci/build.sh --python=3.11
pip install --no-deps --force-reinstall dist/torch_npu-*.whl
ASCEND_LAUNCH_BLOCKING=1 pytest -s test_npu_execution_trace.py

Test results

image.png

【CheckList】

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

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 ilya_a 的贡献)
Iilya_a
12 天前 创建了 pull request,commit 0953c715
atomgit-bot
atomgit-bot
12 天前 评论:

变更摘要

本 PR 主要为 torch_npu profiler(基于 acl_prof)增加了对 PyTorch ExecutionTraceObserver 对象的支持:在 profile 类中新增 execution_trace_observer 参数,使 npu_profiler 在启动和停止时同步调用观测器的 start()stop(),从而实现与 PyTorch 社区 profiler 一致的 Execution Trace 采集行为,并新增了相应的单元测试。

主要改动

  • 新增 execution_trace_observer 接口参数:在 torch_npu/profiler/profiler.pyprofile 类构造函数中引入 execution_trace_observer: _ITraceObserver | None = None,用于接收调用方传入的 ExecutionTraceObserver 对象,并将其保存到 self.execution_trace_observer
  • 联动启动与停止 Execution Trace 观测:在 profile.start() 中当 execution_trace_observer 存在时调用其 start(),在 profile.stop() 中调用其 stop(),使观测时间窗口与 npu_profiler 保持一致。
  • 引入 _ITraceObserver 类型:从 torch.profiler.profiler 导入 _ITraceObserver 作为新参数的类型标注。
  • 新增 Execution Trace 单元测试:新增 test/profiler/test_npu_execution_trace.py,覆盖 aten::gathertensor_range 记录,以及通过 set_extra_resource_collection(True)ENABLE_PYTORCH_EXECUTION_TRACE_SAVE_INTEGRAL_TENSOR_DATA 验证 integral tensor 数据落盘(.dat 文件)的功能。
likedislike
atomgit-bot
atomgit-bot
12 天前 评论:

代码审查

审查总结

已审查文件:

  • test/profiler/test_npu_execution_trace.py —— 发现 4 个问题(1 个 P2,3 个 P3)
  • torch_npu/profiler/profiler.py —— 无问题(execution_trace_observer 参数的传递、start()/stop() 中 observer 的启停时序均与 PyTorch 社区 profiler 语义一致;类型注解 _ITraceObserver | None 与本仓库其它文件已使用的 PEP 604 语法一致,无兼容性问题)

问题计数(按优先级):

  • P0:0
  • P1:0
  • P2:1
  • P3:3

整体风险判断:

生产代码改动(torch_npu/profiler/profiler.py)逻辑正确、风险低。主要问题集中在新增测试文件:其中使用 torch.profiler.schedule 而非 torch_npu.profiler.schedule 会因枚举类型不匹配使 NPU profiler 采集静默不启动,导致第二个测试无法真正验证本 PR 的集成点(P2);另有环境变量泄漏、断言空转、死代码三个测试质量问题(P3)。建议至少修复 P2 的 schedule 误用,确保测试真正覆盖 NPU profiler 与 execution_trace_observer 的联动。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
ascend-robotascend-robot成员
12 天前 添加了label:stat/needs-squash
此处折叠了49条消息 查看更多
ascend-robot
ascend-robot成员
9 天前 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
eejiechu

likedislike
ascend-robotascend-robot成员
9 天前 添加了label:lgtm
ascend-robotascend-robot成员
9 天前 合入了pull request
ascend-robot
ascend-robot成员
9 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
ascend-robot
ascend-robot成员
9 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14126 [ commitID:84b625f4 ] 已完成
likedislike