Skip to content

Commit

Permalink
Add nightly build installation code snippet to prototype feature tuto…
Browse files Browse the repository at this point in the history
…rials (pytorch#2325)

Summary:
Tutorial notebooks that leverage TorchAudio prototype features don't run as-is on Google Colab due to its runtime's not having nightly builds pre-installed. To make it easier for users to run said notebooks in Colab, this PR adds a code block that installs nightly Pytorch and TorchAudio builds as a comment that users can copy and run locally.

Pull Request resolved: pytorch#2325

Reviewed By: xiaohui-zhang

Differential Revision: D35597753

Pulled By: hwangjeff

fbshipit-source-id: 59914e492ad72e31c0136a48cd88d697e8ea5f6c
  • Loading branch information
hwangjeff authored and facebook-github-bot committed Apr 13, 2022
1 parent b0c8e23 commit fb51cec
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 19 deletions.
20 changes: 20 additions & 0 deletions examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@
import torch
import torchaudio

try:
import torchaudio.prototype.ctc_decoder
except ModuleNotFoundError:
try:
import google.colab

print(
"""
To enable running this notebook in Google Colab, install nightly
torch and torchaudio builds by adding the following code block to the top
of the notebook before running it:
!pip3 uninstall -y torch torchvision torchaudio
!pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
"""
)
except ModuleNotFoundError:
pass
raise


######################################################################
# Acoustic Model and Data
Expand Down
4 changes: 3 additions & 1 deletion examples/tutorials/device_asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.. note::
This tutorial requires prototype Streaming API and ffmpeg>=4.1.
This tutorial requires prototype Streaming API, ffmpeg>=4.1, and SentencePiece.
Prototype features are not part of binary releases, but available in
nightly build. Please refer to https://pytorch.org for installing
Expand All @@ -20,6 +20,8 @@
``conda install -c anaconda ffmpeg`` will install
the required libraries.
You can install SentencePiece by running ``pip install sentencepiece``.
.. note::
This tutorial was tested on MacBook Pro and Dynabook with Windows 10.
Expand Down
36 changes: 26 additions & 10 deletions examples/tutorials/online_asr_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#
# .. note::
#
# This tutorial requires torchaudio with prototype features and
# FFmpeg libraries (>=4.1).
# This tutorial requires torchaudio with prototype features,
# FFmpeg libraries (>=4.1), and SentencePiece.
#
# torchaudio prototype features are available on nightly builds.
# Please refer to https://pytorch.org/get-started/locally/
Expand All @@ -30,13 +30,7 @@
# ``conda install -c anaconda ffmpeg`` will install
# the required libraries.
#
# When running this tutorial in Google Colab, the following
# command should do.
#
# .. code::
#
# !add-apt-repository -y ppa:savoury1/ffmpeg4
# !apt-get -qq install -y ffmpeg
# You can install SentencePiece by running ``pip install sentencepiece``.

######################################################################
# 1. Overview
Expand All @@ -59,10 +53,32 @@
import torch
import torchaudio

try:
from torchaudio.prototype.io import Streamer
except ModuleNotFoundError:
try:
import google.colab

print(
"""
To enable running this notebook in Google Colab, install nightly
torch and torchaudio builds and the requisite third party libraries by
adding the following code block to the top of the notebook before running it:
!pip3 uninstall -y torch torchvision torchaudio
!pip3 install --pre torch torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
!pip3 install sentencepiece
!add-apt-repository -y ppa:savoury1/ffmpeg4
!apt-get -qq install -y ffmpeg
"""
)
except ModuleNotFoundError:
pass
raise

print(torch.__version__)
print(torchaudio.__version__)

from torchaudio.prototype.io import Streamer

######################################################################
# 3. Construct the pipeline
Expand Down
30 changes: 22 additions & 8 deletions examples/tutorials/streaming_api_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
# ``conda install -c anaconda ffmpeg`` will install
# the required libraries.
#
# When running this tutorial in Google Colab, the following
# command should do.
#
# .. code::
#
# !add-apt-repository -y ppa:savoury1/ffmpeg4
# !apt-get -qq install -y ffmpeg

######################################################################
# 1. Overview
Expand Down Expand Up @@ -77,7 +70,28 @@
import matplotlib.pyplot as plt
import torch
import torchaudio
from torchaudio.prototype.io import Streamer

try:
from torchaudio.prototype.io import Streamer
except ModuleNotFoundError:
try:
import google.colab

print(
"""
To enable running this notebook in Google Colab, install nightly
torch and torchaudio builds and the requisite third party libraries by
adding the following code block to the top of the notebook before running it:
!pip3 uninstall -y torch torchvision torchaudio
!pip3 install --pre torch torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
!add-apt-repository -y ppa:savoury1/ffmpeg4
!apt-get -qq install -y ffmpeg
"""
)
except ModuleNotFoundError:
pass
raise

print(torch.__version__)
print(torchaudio.__version__)
Expand Down

0 comments on commit fb51cec

Please sign in to comment.