OpenPPL / ppq

PPL Quantization Tool (PPQ) is a powerful offline neural network quantization tool.
Apache License 2.0
1.56k stars 236 forks source link

[视频资料:网络性能分析] profiler无法看到GPU信息 #507

Closed Deeperfinder closed 1 year ago

Deeperfinder commented 1 year ago

Hi,当按照视频中的资料一步步实现的时候,发现在tensorboard里面只有others 和 CPU的信息,没有其他信息,下面是代码: Resnet18模型文件是从torchvision中生成的model = torchvision.models.resnet18(pretrained=True)

import torch.profiler
from tqdm import tqdm
from ppq import *
from ppq.api import *

sample_input = [torch.rand(1,3,224,224) for i in range(32)]
ir = quantize_onnx_model(
    onnx_import_file="models/resnet18_cpu_torchvision.onnx",
    calib_dataloader=sample_input,
    calib_steps=16,
    platform = TargetPlatform.PPL_CUDA_INT8,
    do_quantize=False,
    input_shape=None,
    collate_fn=lambda x:x.to('cuda'),
    inputs=torch.rand(1,3,224,224).to('cuda')
)
executor = TorchExecutor(ir)

with torch.profiler.profile(
    schedule=torch.profiler.schedule(wait=2, warmup=2, active=6, repeat=1),
    on_trace_ready=torch.profiler.tensorboard_trace_handler(
        dir_name="working/performance/"),
    activities=[
        torch.profiler.ProfilerActivity.CUDA,
        torch.profiler.ProfilerActivity.CPU
    ],
    with_stack=True,
) as profiler:
    with torch.no_grad():
        for batch_idx in tqdm(range(16),
            desc = "Profiling ..."):
            executor.forward(sample_input[0].to('cuda'))
            profiler.step()

导出的profile json文件信息

{
  "schemaVersion": 1,
  "traceEvents": [
  {
    "ph": "X", "cat": "cpu_op", 
    "name": "aten::empty", "pid": 9544, "tid": 2156,
    "ts": 1697510561808234, "dur": 5,
    "args": {
       "External id": 2,
       "Trace name": "PyTorch Profiler", "Trace iteration": 0,
       "Call stack": "D:/Anaconda/envs/pytorch110/lib/site-packages/torch/autograd/profiler.py(432): __init__;D:/Anaconda/envs/pytorch110/lib/site-packages/torch/profiler/profiler.py(329): step;D:/量化测试/main.py(33): <module>;"
    }
  },

是哪里参数没有设置对吗?

Deeperfinder commented 1 year ago

同样的代码,同样的onnx,在Google colab(T4)中运行就能够看到GPU的信息。 amazing!

ZhangZhiPku commented 1 year ago

不能用windows跑这个

Deeperfinder commented 1 year ago

不能用windows跑这个

好的,感谢大佬~

gitctrlx commented 8 months ago

不能用windows跑这个

作者您好,请问可以在NVIDIA Jetson平台跑这个代码吗?我在jetson xavier nx上运行代码生成了json文件,但是当我在vscode中使用TensoBoard打开后它无法正常显示,并且json文件中没有traceEvents这个字段。