# PyTorch Profiler not working with CUDA

**URL:** <https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061>\
**Category:** Uncategorized\
**Created:** [September 15, 2021, 1:41pm UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061 "2021-09-15T13:41:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![marewi](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@marewi](https://discuss.pytorch.org/u/marewi)\
**Post date:** [September 15, 2021, 1:41pm UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061/1 "2021-09-15T13:41:37Z")

</div>

Hi,  
For me, Torch.Profiler is not working with CUDA activity only. With CPU it is working for me.

**Code** :

```auto
with torch.profiler.profile(
        activities=[torch.profiler.ProfilerActivity.CUDA],
        schedule=torch.profiler.schedule(wait=1, warmup=1, active=3, repeat=2),        
        on_trace_ready=torch.profiler.tensorboard_trace_handler('./log/model'),
        profile_memory=False,
        record_shapes=True,
        with_stack=True,
        use_cuda=True
    ) as prof:

        for mini_batch_data in dataloader:
              ...

```

**Error Msg** : “AssertionError: No activities specified for Kineto profiler”

Is someone able to give me an hint?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [September 15, 2021, 9:59pm UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061/2 "2021-09-15T21:59:49Z")

</div>

I cannot reproduce the issue using this simple code snippet:

```python
import torch
from torch.profiler import profile, record_function, ProfilerActivity

with profile(
        activities=[torch.profiler.ProfilerActivity.CUDA],
        schedule=torch.profiler.schedule(wait=1, warmup=1, active=3, repeat=2),        
        on_trace_ready=torch.profiler.tensorboard_trace_handler('./log/model'),
        profile_memory=False,
        record_shapes=True,
        with_stack=True,
    ) as prof:
        for _ in range(10):
            y = torch.randn(1).cuda() + torch.randn(1).cuda()
            prof.step()
            

print(prof.key_averages())

```

so could you post a minimal, executable code snippet which would reproduce the issue, please?

---

<div class="post-metadata">

**Author:** ![marewi](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@marewi](https://discuss.pytorch.org/u/marewi)\
**Post date:** [September 16, 2021, 8:11am UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061/3 "2021-09-16T08:11:37Z")

</div>

> [@ptrblck](#):
>
> ```auto
> import torch
> from torch.profiler import profile, record_function, ProfilerActivity
> 
> with profile(
> activities=[torch.profiler.ProfilerActivity.CUDA],
> schedule=torch.profiler.schedule(wait=1, warmup=1, active=3, repeat=2),        
> on_trace_ready=torch.profiler.tensorboard_trace_handler('./log/model'),
> profile_memory=False,
> record_shapes=True,
> with_stack=True,
> ) as prof:
> for _ in range(10):
> y = torch.randn(1).cuda() + torch.randn(1).cuda()
> prof.step()
>             
> 
> print(prof.key_averages())
> 
> ```

Hi ptrblck,  
actually I can reproduce the same issue with your code snippet. Here the full error stack:

```auto
C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\autograd\profiler.py:440: UserWarning: CUPTI tracing is not available, falling back to legacy CUDA profiling
  warn("CUPTI tracing is not available, falling back to legacy CUDA profiling")
Traceback (most recent call last):
  File "test_profiler.py", line 14, in <module>
    prof.step()
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\profiler\profiler.py", line 282, in step
    self._start_warmup()
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\profiler\profiler.py", line 413, in _start_warmup
    self.profiler = prof.profile(
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\autograd\profiler.py", line 447, in __init__
    assert len(self.kineto_activities) > 0, \
AssertionError: No activities specified for Kineto profiler

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_profiler.py", line 14, in <module>
    prof.step()
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\profiler\profiler.py", line 253, in __exit__
    self._exit_actions()
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\profiler\profiler.py", line 404, in _exit_actions
    self._start_trace()
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\profiler\profiler.py", line 425, in _start_trace
    assert self.profiler is not None
AssertionError

```

FYI:

- Python 3.8.0
- GPU: NVIDIA Tesla V100-PCIE-16GB
- torch==1.9.0+cu111
- torch-tb-profiler==0.2.0

---

<div class="post-metadata">

**Author:** ![marewi](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@marewi](https://discuss.pytorch.org/u/marewi)\
**Post date:** [September 20, 2021, 4:20pm UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061/4 "2021-09-20T16:20:15Z")

</div>

Any tips/ideas?  
Or are any additional information needed?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [September 20, 2021, 7:54pm UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061/5 "2021-09-20T19:54:31Z")

</div>

No, unfortunately I don’t have any debugging advice and would recommend to create an issue in GitHub, so that others could try to reproduce it as well.

---

<div class="post-metadata">

**Author:** ![marewi](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@marewi](https://discuss.pytorch.org/u/marewi)\
**Post date:** [September 21, 2021, 7:42am UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061/6 "2021-09-21T07:42:05Z")

</div>

> [@marewi](#):
>
> NVIDIA Tesla V100-PCIE-16GB

Problem was issued here: [PyTorch Profiler is not working with CUDA · Issue #65393 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/issues/65393)

---

<div class="post-metadata">

**Author:** ![Emil895](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/e/f05b48/32.png) [@Emil895](https://discuss.pytorch.org/u/Emil895)\
**Post date:** [September 21, 2021, 1:23pm UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061/7 "2021-09-21T13:23:36Z")

</div>

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

Change your code as following[.](https://www.liteblue.app/)

```auto
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[.](https://www.liteblue.app/)

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [September 21, 2021, 7:34pm UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061/8 "2021-09-21T19:34:09Z")

</div>

MY code snippet is already performing operations on the device via:

```python
y = torch.randn(1).cuda() + torch.randn(1).cuda()

```

and while it works for me, it seems that @marewi is still hitting the issue.  
Are you seeing the same error using my code snippet?

---

<div class="post-metadata">

**Author:** ![jaketalyor32325](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jaketalyor32325/32/48856_2.png) [@jaketalyor32325](https://discuss.pytorch.org/u/jaketalyor32325)\
**Post date:** [April 21, 2022, 8:21am UTC](https://discuss.pytorch.org/t/pytorch-profiler-not-working-with-cuda/132061/9 "2022-04-21T08:21:42Z")

</div>

Are you using Windows? I found this open issue.

# [PyTorch Profiler Kineto is not available - windows OS](https://github.com/pytorch/kineto/issues/280#) #280
