14

PyTorch v1.0.0 stable was released on 8 December 2018 after being announced 7 months earlier.

I want get a version optimised for the hardware that my IPython kernel is running on.

How do I get this version on Google Colab?

Tom Hale
  • 40,825
  • 36
  • 187
  • 242

6 Answers6

21

try the following code snippet (it works equally for the runtime with or without gpu)

!pip install -q torch==1.0.0 torchvision

to check the version

import torch
print(torch.__version__)

here you have the version 1.0.0

UPDATE

!pip install torch

Works fine now, as the most stable version is 1.0.0

Arunava
  • 353
  • 1
  • 4
  • 13
ashunigion
  • 1,769
  • 1
  • 11
  • 15
  • 1
    Will this take into account the version of CUDA running on the system for optimisation? – Tom Hale Dec 17 '18 at 07:58
  • I think it does, it tried `torch.backends.cudnn.version()` and the output was `7401` and `torch.backends.cudnn.enabled == True` the output was `true`. I used the colab GPU runtime. – ashunigion Dec 17 '18 at 10:28
  • 1
    Great! I also get `7410` even though [my solution](https://stackoverflow.com/a/53775509/5353461) is based on Google's colab code snippet and has `cu90` in the generated download URL. – Tom Hale Dec 19 '18 at 05:10
5

With version 1.0.0, PyTorch changed the download URL format from:

https://download.pytorch.org/whl/cu92/torch-1.0.0-cp36-cp36m-linux_x86_64.whl

to

https://download.pytorch.org/whl/cu90/torch-1.0.0-cp36-cp36m-linux_x86_64.whl

(The change is in the CUDA version part, where cu92 changes to cu90.)

To programmatically generate that URL, I used the following code:

from os.path import exists
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag

platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*\.\([0-9]*\)\.\([0-9]*\)$/cu\10/'    
accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'

torch_url=f"http://download.pytorch.org/whl/{accelerator}/torch-{version}-{platform}-linux_x86_64.whl"
version='1.0.0'

!pip install -U {torch_url} torchvision

You can then change the version variable as desired as newer versions are released.

Tom Hale
  • 40,825
  • 36
  • 187
  • 242
3

You can now just

import torch

No need for additional installation.

Linh Le Vu
  • 436
  • 4
  • 7
2

For version 1.1.0, this works

!pip install -q torch==1.1.0 torchvision
Oladimeji Mudele
  • 63
  • 1
  • 1
  • 5
2

It worked for me you can try

!pip install torch
!pip install torchvision
!pip install mxnet-cu101
Maheep
  • 767
  • 10
  • 6
  • 1
    Actually, when I was installing pytorch using the 1st two commands it was showing error when I was importing but when I installed mxnet-cu101 it worked. – Maheep Jul 19 '20 at 15:27
1

Here is a code to install pytorch. You can change it to whatever version you want.

!pip3 install http://download.pytorch.org/whl/cu92/torch-1.0.0-cp36-cp36m-linux_x86_64.whl