How can I enable pytorch GPU support in Google Colab?
How can I enable pytorch to work on GPU?

I've installed pytorch successfully in google colab notebook:

Tensorflow reports GPU to be in place:



But torch.device function fails somehow:



How can I fix this?

I hit the same issue.

Try installing Torch like this:

# http://pytorch.org/
from os import path
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())

accelerator = 'cu80' #'cu80' if path.exists('/opt/bin/nvidia-smi') else 'cpu'
print('Platform:', platform, 'Accelerator:', accelerator)

!pip install --upgrade --force-reinstall -q http://download.pytorch.org/whl/{accelerator}/torch-0.4.0-{platform}-linux_x86_64.whl torchvision

import torch
print('Torch', torch.__version__, 'CUDA', torch.version.cuda)
print('Device:', torch.device('cuda:0'))


The output should be:


  Platform: cp36-cp36m Accelerator: cu80 Torch 0.4.0 CUDA 8.0.61
  Device: cuda:0


Some snippets floating around use torch-0.3.0.post4-{platform}-linux_x86_64.whl, which will lead to the same error, because device is a Torch 4 feature.  If you have already installed the wrong version, you may need to do !pip uninstall torch.

Also be sure to enable GPU under Edit > Notebook settings > Hardware accelerator.
