Pytorch tensors make Pycharm step-by-step debugging unbearably slow

Hi Mamy,

It happens also with tensors created by PyTorch, whether they are CPU or GPU tensors.

To repro the issue you can try to run step-by-step the code below PyCharm’s debugger:

import torch as np

tensors = []
num_tensors = 16
shape = (1, 3, 512, 512)
for i in range(num_tensors):
    tensors.append(np.zeros(shape))

As one steps through the inner loop debugging will getting slower and slower.
It seems the debugger is trying to collect the tensor data in order to visualize it in the variables pane.
The more data we have the slower it gets…

Memory wise I have 10GB+ available when I run it, so memory doesn’t seem to be an issue.
Instead, single CPU core utilization goes up to over 90%, mostly spent running PyCharm’s code: pycharm/helpers/pydev/pydevd.py

If we replace torch with numpy the problems goes away.

Let me know if you need more data and thanks for helping.