已合并
对齐Pytorch Profiler部分接口 #34217
xfeng创建于 4月23日
对齐Pytorch Profiler部分接口 #34217
已合并
xfeng创建于 4月23日
xfeng
xfeng成员
4月23日

【合入来源】

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

【修改方案】

对齐pytorch profiler的部分接口:
一个是增加一个skip_first_wait
image.png
一个是custom_trace_id_callback,然后增加两个对应的set和get的接口set_custom_trace_id_callbackget_trace_id

image.png
image.png

【资料变更】

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

涉及,需要和资料沟通

【接口变更】

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

涉及,前面已经说明

【功能验证】

场景1
设置schedule = torch_npu.profiler.schedule(wait=2, warmup=1, active=1, repeat=2, skip_first=0, skip_first_wait=1)
之前:采集第3和第7个step
image.png
现在:采集第1和第5个step
image.png

场景2
测试get_trace_id接口:

……
    with torch_npu.profiler.profile(
        activities=[
            torch_npu.profiler.ProfilerActivity.NPU,
            torch_npu.profiler.ProfilerActivity.CPU,
        ],
        with_stack=True,
        schedule = torch_npu.profiler.schedule(wait=2, warmup=1, active=2, repeat=2, skip_first=1, skip_first_wait=1),
        on_trace_ready=torch_npu.profiler.tensorboard_trace_handler("./result_profiling"),
        experimental_config=experimental_config) as prof:

        for i in range(12):
            add(x0, x1)
            prof.step()
            print(f"step {i}: {prof.get_trace_id()}")
……

image.png
默认是一个uuid,是直接从pytorch里面拷贝过来的,现在会在profiler_metadata.json里面落盘,db里面也有
image.png
image.png
image.png

场景3
异常的skip_first_wait参数不生效,reset为0
正常:image.png
异常:必须设置为整数,否则有警告信息,reset为0
image.png
image.png

场景4:
设置custom_trace_id_callback,这个trace_id,我们是想和每一份ascend_pt数据或者repeat参数绑定的,

class RepeatTraceIdGenerator:
    def __init__(self):
        self.repeat_count = 0  # 从 0 开始

    def __call__(self) -> str:
        # 每一轮 profile 启动,计数 +1
        current_id = str(self.repeat_count)
        self.repeat_count += 1
        return current_id

trace_id_gen = RepeatTraceIdGenerator()
……
    with torch_npu.profiler.profile(
        activities=[
            torch_npu.profiler.ProfilerActivity.NPU,
            torch_npu.profiler.ProfilerActivity.CPU,
        ],
        with_stack=True,
        schedule = torch_npu.profiler.schedule(wait=2, warmup=1, active=2, repeat=2, skip_first=1, skip_first_wait=1),
        on_trace_ready=torch_npu.profiler.tensorboard_trace_handler("./result_profiling"),
        experimental_config=experimental_config,
        custom_trace_id_callback=trace_id_gen) as prof:

        for i in range(12):
            add(x0, x1)
            prof.step()
            print(f"step {i}: {prof.get_trace_id()}")

image.png

如果call_back类型不对,会有警告信息,然后使用默认的uuid
image.png

【CheckList】

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

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 xfeng 的贡献)
xfengxfeng成员
4月23日 创建了 pull request,commit 31a5b551
ascend-robot
ascend-robot成员
4月23日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
test li_jing_hw, 陈豪 (2/2) li_jing_hw, 陈豪 (2/1)
torch_npu/profiler 陈豪, li_jing_hw (2/2) 陈豪, li_jing_hw (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

zyb_230, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robotascend-robot成员
4月23日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
4月23日 评论:

当前仓库存在以下 保护分支

Protected Branch Version Release
master
v2.8.0
v2.7.1
v2.9.0
v2.11.0
v2.10.0

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
此处折叠了323条消息 查看更多
ascend-robotascend-robot成员
5月6日 添加了label:lgtm
openLiBingCI成员
5月6日 评论:

本PR中共发现代码检查告警抑制1处,请Committer检视合理性

本评论自动扫描PR中使用的开源代码检查工具(ruff、clang-tidy、CodeQL等)的屏蔽注释。
这些屏蔽注释会阻止开源代码检查工具对特定代码区域的检测,可能导致潜在问题被忽略。

点击下载完整报告

文件路径 行号 屏蔽类型 代码片段 工具名称
torch_npu/profiler/profiler.py 1 行级屏蔽 1: # ruff: noqa: UP045, UP007
3: import os.path
4: from collections.abc import Callable, Iterable
6: from typing import Any, Optional, Union
12: _enable_profiler_in_child_thread,
14: NpuProfilerConfig,
ruff
likedislike
ascend-robot
ascend-robot成员
5月6日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: 陈豪, li_jing_hw.
Reviewers who wrote a comment of /lgtm are: li_jing_hw, 陈豪.

likedislike
ascend-robotascend-robot成员
5月6日 合入了pull request
ascend-robot
ascend-robot成员
5月6日 评论:

In response to this:

/sync v2.9.0 v2.10.0 v2.11.0 master

@zyb_230

同步操作执行结果:

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