How to run pytorch 2.0 on google colab?

bhimrazy: <p>I tried the following command to install PyTorch 2.0 from <a href="https://pytorch.org/get-started/pytorch-2.0" class="inline-onebox" rel="noopener nofollow ugc">PyTorch 2.0 | PyTorch</a></p>
<pre data-code-wrap="shell"><code class="lang-nohighlight">pip3 install numpy --pre torch[dynamo] --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/cu117
</code></pre>
<p>But I couldn’t manage to run the new version on the google colab.<br>
I checked the version after installation but it still showed the older version.</p>
<p>Let me know if you have figured it out!<br>
Thank you !!!</p>

ptrblck: <p>It works for me in a new Colab notebook as seen here:</p>
<pre><code class="lang-python">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
</code></pre>

kushal.verma: <p>Installed PyTorch2.0 on my MacBook pro (Intel, macOS Big Sur)</p>
<pre><code class="lang-auto"> pip3 install numpy --pre torch torchvision torchaudio --force-reinstall --extra-index-url https://download.pytorch.org/whl/nightly/cpu
</code></pre>
<p>And still getting version 1.13.0</p>
<pre><code class="lang-auto">❯ 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
</code></pre>
<p>also via <code>torch.__version__</code></p>
<p>and getting error in compiling model</p>
<pre><code class="lang-auto">---&gt; 10 model = torch.compile(model)

AttributeError: module 'torch' has no attribute 'compile'
</code></pre>
<p>It looks like proper version of PyTorch in not installed.</p>
<p>Thanks in Advance,<br>
Kushal</p>

kushal.verma: <p>Got it! seems no whl file exists for python 3.10 at <a href="https://download.pytorch.org/whl/nightly/torchrec_nightly_cpu/" rel="noopener nofollow ugc">https://download.pytorch.org/whl/nightly/torchrec_nightly_cpu/</a></p>
<p>Working now…</p>
<pre><code class="lang-auto">❯ 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
</code></pre>
<p>and <code>model = torch.compile(model)</code> is also working.</p>

Puneesh_Khanna: <p>!pip3 install numpy --pre torch[dynamo] torchvision torchaudio --force-reinstall --index-url <a href="https://download.pytorch.org/whl/nightly/cu116" rel="noopener nofollow ugc">https://download.pytorch.org/whl/nightly/cu116</a></p>
<p>import torch<br>
print(torch.<strong>version</strong>)</p>
<blockquote>
<blockquote>
<p>1.13.0.dev20220816+cu116</p>
</blockquote>
</blockquote>
<p>But I am getting error when trying to use<br>
torch._dynamo.optimize(my_fn)(foo)(torch.randn([2,2]), torch.randn([2,2]))</p>
<p>AttributeError: module ‘torch’ has no attribute ‘_dynamo’</p>

Puneesh_Khanna: <p>!pip3 install numpy --pre torch[dynamo] torchvision torchaudio --force-reinstall --extra-index-url <a href="https://download.pytorch.org/whl/nightly/cu117" rel="noopener nofollow ugc">https://download.pytorch.org/whl/nightly/cu117</a></p>
<p>It worked now with cu117. Thanks</p>

kingdavid72: <p>import torch<br>
print(torch.<strong>version</strong>)</p>
<p>2.1.0.dev20230329+cu117</p>
<p>Kinda works but still has dependency issues… hopefully, it doesn’t generate errors…</p>
<p>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.<br>
torchtext 0.14.1 requires torch==1.13.1, but you have torch 2.1.0.dev20230329+cu117 which is incompatible.<br>
numba 0.56.4 requires numpy&lt;1.24,&gt;=1.18, but you have numpy 1.24.2 which is incompatible.<br>
fastai 2.7.11 requires torch&lt;1.14,&gt;=1.7, but you have torch 2.1.0.dev20230329+cu117 which is incompatible.<br>
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</p>

marksaroufim: <p>FYI: pytorch 2.0 is now the default version on google colab<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/d/ddfa4b051996222ed2d8f33268dff8dda8607aa0.png" data-download-href="https://discuss.pytorch.org/uploads/default/ddfa4b051996222ed2d8f33268dff8dda8607aa0" title="Screenshot 2023-04-12 at 1.36.33 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/d/ddfa4b051996222ed2d8f33268dff8dda8607aa0_2_561x500.png" alt="Screenshot 2023-04-12 at 1.36.33 PM" data-base62-sha1="vFHLP3Usyhm0OgIJCOeGLBXHos0" width="561" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/d/ddfa4b051996222ed2d8f33268dff8dda8607aa0_2_561x500.png, https://discuss.pytorch.org/uploads/default/optimized/3X/d/d/ddfa4b051996222ed2d8f33268dff8dda8607aa0_2_841x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/d/d/ddfa4b051996222ed2d8f33268dff8dda8607aa0.png 2x" data-dominant-color="F4F4F4"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot 2023-04-12 at 1.36.33 PM</span><span class="informations">1016×904 56.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

bhimrazy: <p>Thank you <a class="mention" href="/u/marksaroufim">@marksaroufim</a></p>