SwanLab icon indicating copy to clipboard operation
SwanLab copied to clipboard

[REQUEST] 添加torch.profiler支持

Open Puiching-Memory opened this issue 9 months ago • 6 comments

🤩 Features description [Please make everyone to understand it]

https://github.com/SwanHubX/SwanLab/issues/136 在ISSUE136中曾经调查过torch.profiler的文档,在后续的更新中,它似乎被遗忘了 当我开始尝试分析torch模型的运行性能时,我只能选择tensorboard 然而,我们有机会将其与swanlab集成。

profile类有一个可选参数on_trace_ready,它将在ProfilerAction定义的事件被触发时运行,我们可以为其提供一个Callable函数

def trace_handler():

    def handler_fn(prof) -> None:
        # TODO: get swanlab local log dir here
        prof.export_chrome_trace("trace.json")

    return handler_fn

https://pytorch.org/docs/main/profiler.html

👍 What problem does this feature solve

参考该篇博客展示的效果,我们将可以在swanlab中查看性能报告 https://blog.csdn.net/just_sort/article/details/137784877

👾 What does the proposed API look like

    # profiler
    with torch.profiler.profile(
        activities=[
            torch.profiler.ProfilerActivity.CPU,
            torch.profiler.ProfilerActivity.CUDA,
        ],
        on_trace_ready=swanlab.log.trace_handler(),

    ) as p:

这将在本地的swanlog/run-XX/files/中保存一份临时文件,p.export_chrome_trace("trace.json"),这份文件是Chrome Trace格式的,所以我们可以有许多实现方法,一种想法是:我们提供一个格式转换器,将Chrome Trace格式翻译成目前拥有的swanlab类型,然后上传至云端。另一种想法是:云端提供Chrome Trace格式的可视化,本地不做处理,仅上传文件

🚑 Any additional [like screenshots]

Image

Puiching-Memory avatar Mar 06 '25 15:03 Puiching-Memory

It's a very good idea, let's think about how to integrate torch.profiler with swanlab.

Zeyi-Lin avatar Mar 06 '25 15:03 Zeyi-Lin

The design I want is to support saving/uploading trace.json through special functions and adding tags, and to support one-click jumping to a new tab for rendering the Profiler on SwanLab.

Zeyi-Lin avatar Mar 06 '25 15:03 Zeyi-Lin

hi!这是我最近闲暇之余正在研究的功能,我们没有将他遗忘,主要还是因为我们目前正在忙着 #788 ,anyway,非常感谢您给我提出了可行性方案!

不知您是否有兴趣为我们贡献这个输入到on_trace_ready的大致函数呢?这应该不复杂,我会给您一份详细的文档,只需要这个函数即可,剩下的交给我:)

SAKURA-CAT avatar Mar 06 '25 15:03 SAKURA-CAT

不知您是否有兴趣为我们贡献这个输入到on_trace_ready的大致函数呢?这应该不复杂,我会给您一份详细的文档,只需要这个函数即可,剩下的交给我:)

看到您已经在 https://github.com/SwanHubX/SwanLab/pull/859 中给出了~再次感谢

就目前而言,profile将是我们云端版的独享功能,本地应该不会保存,一个现实原因是我们维护精力有限,本地版本目前只能是一个 it may be work 的状态:(

SAKURA-CAT avatar Mar 06 '25 15:03 SAKURA-CAT

意思应该不是云端版的独享功能,而是尽量支持云端模式?因为本地看板未来可能重构为和云端接口保持一致的状态,免费的私有化版发出后,也会采用类似云端的接口,因此我们尽量以比特流的形式发出。

ShaohonChen avatar Mar 06 '25 16:03 ShaohonChen

意思应该不是云端版的独享功能,而是尽量支持云端模式

嗯嗯,目前暂时云端版尽快推出

SAKURA-CAT avatar Mar 06 '25 16:03 SAKURA-CAT