Working on Colab
Parts of this post were drafted using an AI tool and then reviewed and edited by the course instructor.
As part of the course, you will be working on coding assignments in the form of Jupyter notebooks. To run these, you need a development environment including machine learning libraries, in particular PyTorch. Instead of setting up this environment on your computer, you can use Google Colab.
In this post, we will walk you through how to open a notebook from the course repo in Colab and start experimenting. As our example, we will use the Introduction to PyTorch notebook that introduces the basics of the PyTorch library. This notebook (like all others) is available in the course repo.
What is Google Colab?
Google Colab (short for “Colaboratory”) is a web service that lets you run and edit Jupyter notebooks in the cloud. All you need is a Google account.
Colab comes pre-installed with many machine learning libraries, including PyTorch. You can also connect to a GPU runtime, which makes Colab ideal for deep learning experiments. While the computational resources that you can access at the free tier are limited, they will be sufficient to run the notebooks in this course.
Getting the notebook file
To use a notebook in Colab, you first need to download the file to your computer:
- Go to the Introduction to PyTorch notebook.
- Click the Download button.
- Save the file to your computer.
Uploading to Google Colab
Now that you have the notebook file locally, follow these steps:
- Go to Google Colab.
- Sign in with your Google account.
- At the Colab start page, select the Upload tab.
- Click Choose file and upload the notebook file.
The notebook will open in a new Colab tab, ready to run.
(Optional) Enabling GPU acceleration
Some PyTorch operations run much faster on a GPU. To use one in Colab:
- In the top menu, click Runtime → Change runtime type.
- Under Hardware accelerator, select GPU.
- Save your settings.
You will now be running on a GPU-backed environment.
Saving your work
Any changes you make will disappear once your Colab session ends, unless you save them. You have two options:
- Save a copy to your Google Drive: Click File → Save a copy in Drive.
- Download your modified notebook: Click File → Download → Download .ipynb.
Troubleshooting tips
- If a cell fails because a package is missing, install it with
!pip install packagename
. - If you get disconnected from Colab after inactivity, just reconnect and re-run the cells.
- Remember that free GPU sessions have time limits (typically up to 12 hours).