Random_device could not be read

Traceback (most recent call last):
** File “test.py”, line 55, in **
** from torchvision.transforms import transforms as T**
** File “/home/manager/env/lib/python3.8/site-packages/torchvision/init.py”, line 4, in **
** from .extension import _HAS_OPS**
** File “/home/manager/env/lib/python3.8/site-packages/torchvision/extension.py”, line 101, in **
** _check_cuda_version()**
** File “/home/manager/env/lib/python3.8/site-packages/torchvision/extension.py”, line 80, in _check_cuda_version**
** _version = torch.ops.torchvision._cuda_version()**
RuntimeError: random_device could not be read

Not sure whats wrong, whenever I try to run my model in a script on cuda device I get this error.
If I import “from torchvision.transforms import transforms as T” in a console it runs fine.

I have tried installing latest to historic versions of pytorch but no luck.

My system has ubuntu 20.04 installed. I am also using tensorflow along with pytorch in the script. I have started facing this issue after upgrading to 20.04 from 16.04.

This would point to a broken installation in the other environment you are using (I don’t know how you are executing the script in the failing case).

I just want to write that I see a very similar problem. I reported it also here:

What TensorFlow version did you use? I noticed that I get the hang in PyTorch when I use TensorFlow 2.12, but not when I use TensorFlow 2.10. But different CUDA versions/setups might also have influenced this observation.

For me importing torchvision package (or other packages using it) before importing tensorflow solved the problem. Wonder why is this happening…

Some versions of TensorFlow with PyTorch cause this problem. You can try downgrading or upgrading your TensorFlow. For me, it worked by downgrading the TensorFlow

| univanxx Ivan
August 10 |

  • | - |

For me importing torchvision package (or other packages using it) before importing tensorflow solved the problem. Wonder why is this happening…

I had the same issue recently. I commented the cause in this thread: PyTorch hangs at import when used together with TensorFlow · Issue #102360 · pytorch/pytorch · GitHub

Hope that would be helpful.

1 Like