Running Tutorials in Google Colab¶
When you run a tutorial in Google Colab, there might be additional requirements and dependencies that you need to meet in order for the tutorial to work properly. This section contains notes on how to configure various settings in order to successfully run PyTorch tutorials in Google Colab.
PyTorch Version in Google Colab¶
When you are running a tutorial that requires a version of PyTorch that has
just been released, that version might not be yet available in Google Colab.
To check that you have the required
torch and compatible domain libraries
If the installed version of PyTorch is lower than required, uninstall it and reinstall again by running the following commands:
!pip3 uninstall --yes torch torchaudio torchvision torchtext torchdata !pip3 install torch torchaudio torchvision torchtext torchdata
Using Tutorial Data from Google Drive in Colab¶
We’ve added a new feature to tutorials that allows users to open the notebook associated with a tutorial in Google Colab. You may need to copy data to your Google drive account to get the more complex tutorials to work.
In this example, we’ll demonstrate how to change the notebook in Colab to work with the Chatbot Tutorial. To do this, you’ll first need to be logged into Google Drive. (For a full description of how to access data in Colab, you can view their example notebook here.)
To get started open the Chatbot Tutorial in your browser.
At the top of the page click Run in Google Colab.
The file will open in Colab.
If you select Runtime, and then Run All, you’ll get an error as the file can’t be found.
To fix this, we’ll copy the required file into our Google Drive account.
Log into Google Drive.
In Google Drive, make a folder named
data, with a subfolder named
Visit the Cornell Movie Dialogs Corpus and download the movie-corpus ZIP file.
Unzip the file on your local machine.
Copy the file
data/cornellfolder that you created in Google Drive.
Now we’ll need to edit the file in_ _Colab to point to the file on Google Drive.
In Colab, add the following to top of the code section over the line
from google.colab import drive drive.mount('/content/gdrive')
Change the two lines that follow:
Change the line that begins with
corpus = os.path.join("/content/gdrive/My Drive/data", corpus_name)
We’re now pointing to the file we uploaded to Drive.
Now when you click the Run cell button for the code section, you’ll be prompted to authorize Google Drive and you’ll get an authorization code. Paste the code into the prompt in Colab and you should be set.
Rerun the notebook from the Runtime / Run All menu command and you’ll see it process. (Note that this tutorial takes a long time to run.)
Hopefully this example will give you a good starting point for running some of the more complex tutorials in Colab. As we evolve our use of Colab on the PyTorch tutorials site, we’ll look at ways to make this easier for users.