Google Colab Notebook with PyTorch v1.0 Nightly (Lesson 9)

Avinash
1 min readNov 24, 2018

--

UPDATE 8th Dec, 2018: Since now PyTorch stable is available, I have updated and released a new notebook with stable version. I am keeping this blog post as it is for historical reasons. You can you get the updated version from here — https://medium.com/@ml_kid/google-colab-notebook-with-pytorch-v1-0-stable-lesson-9-46433881da05

In Lesson 9 of Udacity’s Deep Learning with Python, we explore the latest features of PyTorch. We use beta/nightly version of PyTorch, which is not available on stable release channel. So, to get the appropriate version working on Google Colab, I made this handy notebook, which installs correct PyTorch version based on the GPU architecture of Google Colab.

Here are the brief steps:

  1. Download the modified Notebook from this link
  2. Visit Google Colab
  3. You will be prompted with a modal, select Upload
  4. If modal doesn’t appear and instead if it opens a new Notebook, then from menu File > Upload Notebook
  5. Upload the modified notebook
  6. That’s it!

If you are curious to know what I did, then I wrote this following script which downloads PyTorch v1 nightly:

from os.path import exists
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*\.\([0-9]*\)\.\([0-9]*\)$/cu\1\2/'
accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'
!pip install torchvision_nightly
!pip install torch_nightly -f https://download.pytorch.org/whl/nightly/{accelerator}/torch_nightly.html

Hope this helps! If you have got any issues with running this notebook, then feel free to message me on Slack for any help. My slack username is avinash

All the best for the last lesson!

--

--