How to test if installed torch is supported with CUDA

Do you have an NVIDIA GPU? Have you installed cuda on this NVIDIA GPU? If not, then pytorch will not find cuda. It is not mandatory, you can use your cpu instead. Every time you see in the code something like tensor = tensor.cuda(), simply remove that line and the tensor will reside on the CPU. The problem is that it will be incredibly slow to the point of being unusable.

You can also explicitly check by doing
torch.cuda.is_available()
If it returns False, it means that CUDA is not available on your machine

8 Likes