roaffix
(Anton)
August 13, 2018, 12:18pm
1
Hi everyone,
I tried to use such a function to determine cuda availability
def get_torch_device():
if torch.cuda.is_available():
return torch.device("cuda:0")
return torch.device("cpu")
and it returns ‘cuda:0’ on a device without Nvidia GPU at all.
Have anyone faced the same problem? Probably anyone has another solution?
Thanks
That’s strange, as the script works even if I run it on a machine with a masked GPU:
CUDA_VISIBLE_DEVICES="" python your_script.py
> device(type='cpu')
EDIT: Wait a moment. I’ve run the script on the wrong machine.
What is torch.cuda.is_available()
returning on your machine?
roaffix
(Anton)
August 13, 2018, 12:34pm
3
It returns True
. So I manually set device='cpu'
everytime I run code on my laptop without discrete graphics card
What does torch.cuda.device_count()
return?
The script indeed works, i.e. masking the GPU returns ‘cpu’, while the plain call returns ‘cuda:0’ on my machine.
roaffix
(Anton)
August 16, 2018, 1:51pm
5
Hello.
I’m sorry for a delay with a feedback. It seems that it was an issue with my env setup. I installed pytorch for GPU on a laptop without GPU. Updated to version 0.4.1 for CPU and everything works just fine.
pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-linux_x86_64.whl
pip3 install torchvision
Thanks