Check PyTorch installation

Published

May 4, 2023

Modified

May 23, 2023

Import pytorch and check if cuda is available.

import torch
torch.cuda.is_available()
True

Pytorch will be able to convert to cuda tensor if (a) GPU is available, (b) the installed version of pytorch was compiled for GPU. In my case, the conda installation failed, pip3 installation instruction provided in the pytorch website worked.

torch.zeros(10).cuda()
tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], device='cuda:0')
Back to top