Skip to content

Fix colab note #2258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion beginner_source/colab.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
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
installed, run ``!pip list``.

If the installed version of PyTorch is lower than required,
uninstall it and reinstall again by running the following commands:

.. code-block:: python

!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
Expand Down
16 changes: 0 additions & 16 deletions beginner_source/new-release-colab.rst

This file was deleted.

6 changes: 3 additions & 3 deletions beginner_source/t5_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
# 3. Read in the CNNDM, IMDB, and Multi30k datasets and pre-process their texts in preparation for the model
# 4. Perform text summarization, sentiment classification, and translation
#
# .. note::
# This tutorial requires PyTorch 2.0.0 or later.
#

#######################################################################
# Data Transformation
# -------------------
Expand All @@ -34,8 +35,7 @@
#
# T5 uses a SentencePiece model for text tokenization. Below, we use a pre-trained SentencePiece model to build
# the text pre-processing pipeline using torchtext's T5Transform. Note that the transform supports both
# batched and non-batched text input (for example, one can either pass a single sentence or a list of sentences), however
# the T5 model expects the input to be batched.
# batched and non-batched text input (for example, one can either pass a single sentence or a list of sentences), however the T5 model expects the input to be batched.
#

from torchtext.models import T5Transform
Expand Down
5 changes: 4 additions & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes', 'prototype'],
'filename_pattern': re.compile(SPHINX_SHOULD_RUN),
'promote_jupyter_magic': True,
'backreferences_dir': None
'backreferences_dir': None,
'first_notebook_cell': ("# For tips on running notebooks in Google Colab, see\n"
"# https://pytorch.org/tutorials/beginner/colab\n"
"%matplotlib inline")
}

if os.getenv('GALLERY_PATTERN'):
Expand Down
3 changes: 2 additions & 1 deletion intermediate_source/ensembling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

Let's demonstrate how to do this using an ensemble of simple MLPs.

.. include:: ../beginner_source/new-release-colab.rst
.. note::

This tutorial requires PyTorch 2.0.0 or later.
"""

import torch
Expand Down
4 changes: 3 additions & 1 deletion intermediate_source/jacobians_hessians.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
provides ways of computing various higher-order autodiff quantities
efficiently.

.. include:: ../beginner_source/new-release-colab.rst
.. note::

This tutorial requires PyTorch 2.0.0 or later.

Computing the Jacobian
----------------------
Expand Down
4 changes: 3 additions & 1 deletion intermediate_source/neural_tangent_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
demonstrates how to easily compute this quantity using ``torch.func``,
composable function transforms for PyTorch.

.. include:: ../beginner_source/new-release-colab.rst
.. note::

This tutorial requires PyTorch 2.0.0 or later.

Setup
-----
Expand Down
4 changes: 3 additions & 1 deletion intermediate_source/per_sample_grads.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
sample in a batch of data. It is a useful quantity in differential privacy,
meta-learning, and optimization research.

.. include:: ../beginner_source/new-release-colab.rst
.. note::

This tutorial requires PyTorch 2.0.0 or later.

"""

Expand Down
6 changes: 4 additions & 2 deletions intermediate_source/scaled_dot_product_attention_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
# * `Memory-Efficient Attention <https://github.com/facebookresearch/xformers>`__
# * A PyTorch implementation defined in C++
#
# .. literalinclude:: ../beginner_source/new-release-colab.rst
# :language: rst
# .. note::
#
# This tutorial requires PyTorch 2.0.0 or later.
#

import torch
import torch.nn as nn
Expand Down
2 changes: 0 additions & 2 deletions intermediate_source/torch_compile_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#
# Note: a modern NVIDIA GPU (Volta or Ampere) is recommended for this tutorial.
#
# .. include:: ../beginner_source/new-release-colab.rst
#

######################################################################
# Basic Usage
Expand Down
3 changes: 3 additions & 0 deletions recipes_source/recipes/changing_default_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
Typically, to do this you might have used if-statements and ``cuda()`` calls
to do this:

.. note::
This recipe requires PyTorch 2.0.0 or later.

"""
import torch

Expand Down