I’m using the following, from the docs:
with torch.cuda.profiler.profile():
    model(input_var) # Warmup CUDA memory allocator and profiler
    with torch.autograd.profiler.emit_nvtx():
        output = model(input_var)