How to run pytorch 2.0 on google colab?

I tried the following command to install PyTorch 2.0 from PyTorch 2.0 | PyTorch

pip3 install numpy --pre torch[dynamo] --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/cu117

But I couldn’t manage to run the new version on the google colab.
I checked the version after installation but it still showed the older version.

Let me know if you have figured it out!
Thank you !!!

1 Like

It works for me in a new Colab notebook as seen here:

import torch
print(torch.__version__)
# 1.13.0+cu116

!pip3 install numpy --pre torch[dynamo] --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/cu117
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/, https://download.pytorch.org/whl/nightly/cu117
Collecting numpy
  Downloading numpy-1.24.0rc2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
     |████████████████████████████████| 17.3 MB 362 kB/s 
Collecting torch[dynamo]
  Downloading https://download.pytorch.org/whl/nightly/cu117/torch-1.14.0.dev20221207%2Bcu117-cp38-cp38-linux_x86_64.whl (1814.9 MB)
...

# Click on RESTART RUNTIME

import torch
print(torch.__version__)
# 1.14.0.dev20221207+cu117
1 Like

Installed PyTorch2.0 on my MacBook pro (Intel, macOS Big Sur)

 pip3 install numpy --pre torch torchvision torchaudio --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/cpu

And still getting version 1.13.0

❯ conda list | grep -i torch
# packages in environment at /Users/.../opt/anaconda3/envs/pytorch2.0:
torch                     1.13.0                   pypi_0    pypi
torchaudio                0.13.0                   pypi_0    pypi
torchvision               0.14.0                   pypi_0    pypi

also via torch.__version__

and getting error in compiling model

---> 10 model = torch.compile(model)

AttributeError: module 'torch' has no attribute 'compile'

It looks like proper version of PyTorch in not installed.

Thanks in Advance,
Kushal

Got it! seems no whl file exists for python 3.10 at https://download.pytorch.org/whl/nightly/torchrec_nightly_cpu/

Working now…

❯ conda list | grep -i torch
# packages in environment at /Users/.../opt/anaconda3/envs/pytorch2.0:
torch                     2.0.0.dev20221213          pypi_0    pypi
torchaudio                0.14.0.dev20221213          pypi_0    pypi
torchvision               0.15.0.dev20221213          pypi_0    pypi

and model = torch.compile(model) is also working.

!pip3 install numpy --pre torch[dynamo] torchvision torchaudio --force-reinstall --index-url https://download.pytorch.org/whl/nightly/cu116

import torch
print(torch.version)

1.13.0.dev20220816+cu116

But I am getting error when trying to use
torch._dynamo.optimize(my_fn)(foo)(torch.randn([2,2]), torch.randn([2,2]))

AttributeError: module ‘torch’ has no attribute ‘_dynamo’

!pip3 install numpy --pre torch[dynamo] torchvision torchaudio --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/cu117

It worked now with cu117. Thanks

import torch
print(torch.version)

2.1.0.dev20230329+cu117

Kinda works but still has dependency issues… hopefully, it doesn’t generate errors…

ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchtext 0.14.1 requires torch==1.13.1, but you have torch 2.1.0.dev20230329+cu117 which is incompatible.
numba 0.56.4 requires numpy<1.24,>=1.18, but you have numpy 1.24.2 which is incompatible.
fastai 2.7.11 requires torch<1.14,>=1.7, but you have torch 2.1.0.dev20230329+cu117 which is incompatible.
Successfully installed MarkupSafe-2.1.2 certifi-2022.12.7 charset-normalizer-3.1.0 filelock-3.10.7 idna-3.4 jinja2-3.1.2 mpmath-1.3.0 networkx-3.0 numpy-1.24.2 pillow-9.4.0 pytorch-triton-2.1.0+46672772b4 requests-2.28.2 sympy-1.12rc1 torch-2.1.0.dev20230329+cu117 torchaudio-2.1.0.dev20230329+cu117 torchvision-0.16.0.dev20230329+cu117 typing-extensions-4.5.0 urllib3-1.26.15

FYI: pytorch 2.0 is now the default version on google colab

1 Like

Thank you @marksaroufim