PyTorch Profiler not working with CUDA

To run profiler you have do some operations, you have to input some tensor into your model.

Change your code as following.

import torch
import torchvision.models as models

model = models.densenet121(pretrained=True)
x = torch.randn((1, 3, 224, 224), requires_grad=True)

with torch.autograd.profiler.profile(use_cuda=True) as prof:
    model(x)
print(prof) 

This is the sample of the output I got.