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来分析网络性能失败 #512

Closed Deeperfinder closed 1 year ago

Deeperfinder commented 1 year ago

同一套代码在Google colab中上上个星期还能运行tensorboard,这个星期就运行不了了。 在本地的ubuntu 上也报错,下面是tensorboard的错误信息:

No dashboards are active for the current data set.
Probable causes:

You haven’t written any data to your event files.
TensorBoard can’t find your event files.
If you’re new to using TensorBoard, and want to find out how to add data and set up your event files, 
check out the [README](https://github.com/tensorflow/tensorboard/blob/master/README.md) 
and perhaps the [TensorBoard tutorial](https://www.tensorflow.org/get_started/summaries_and_tensorboard).
If you think TensorBoard is configured properly, 
please see [the section of the README devoted to missing data problems](https://github.com/tensorflow/tensorboard/blob/master/README.md#my-tensorboard-isnt-showing-any-data-whats-wrong) 
and consider filing an issue on GitHub.

Last reload: Oct 31, 2023, 8:15:54 AM
Log directory: /content/drive/MyDrive/Colab_Notebooks/working/performance

tensorboard 版本为2.14.1,tensorflow都有安装,运行官方的tensorboard教程是可以运行的。

下面是代码

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() 

google colab 中的命令也是一样的,当前在working目录下

%reload_ext tensorboard
%tensorboard --logdir performance --port=8660

并且当我使用完整路径的时候,tensorboard也生成不了profiler

%reload_ext tensorboard
%tensorboard --logdir=/content/drive/MyDrive/Colab_Notebooks/working/performance --port=8662
Deeperfinder commented 1 year ago

pip install torch_tb_profiler on no ! sorry ~