From 9c6ce542fbdeb0d0734e8506b7f678944ad4ef5b Mon Sep 17 00:00:00 2001 From: hwangjeff Date: Fri, 8 Apr 2022 19:51:20 +0000 Subject: [PATCH 1/3] Add nightly build installation code snippet to prototype feature tutorials --- .../tutorials/asr_inference_with_ctc_decoder_tutorial.py | 7 +++++++ examples/tutorials/online_asr_tutorial.py | 7 +++++++ examples/tutorials/streaming_api_tutorial.py | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py b/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py index 57b93e35d9..98b35af7bd 100644 --- a/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py +++ b/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py @@ -21,6 +21,13 @@ # Please refer to https://pytorch.org/get-started/locally/ # for instructions. # +# To enable running the tutorial 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 +# # The interfaces of prototype features are unstable and subject to # change. Please refer to `the nightly build documentation # `__ for the up-to-date diff --git a/examples/tutorials/online_asr_tutorial.py b/examples/tutorials/online_asr_tutorial.py index 71e0e75aa5..222aba82ab 100644 --- a/examples/tutorials/online_asr_tutorial.py +++ b/examples/tutorials/online_asr_tutorial.py @@ -20,6 +20,13 @@ # Please refer to https://pytorch.org/get-started/locally/ # for instructions. # +# To enable running the tutorial 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 +# # The interfaces of prototype features are unstable and subject to # change. Please refer to `the nightly build documentation # `__ for the up-to-date diff --git a/examples/tutorials/streaming_api_tutorial.py b/examples/tutorials/streaming_api_tutorial.py index 106366afe7..6f1e62e904 100644 --- a/examples/tutorials/streaming_api_tutorial.py +++ b/examples/tutorials/streaming_api_tutorial.py @@ -19,6 +19,13 @@ # Please refer to https://pytorch.org/get-started/locally/ # for instructions. # +# To enable running the tutorial 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 +# # The interfaces of prototype features are unstable and subject to # change. Please refer to `the nightly build documentation # `__ for the up-to-date From 45d529ad2e24c5435ef42a790eb4bf72794d6eaa Mon Sep 17 00:00:00 2001 From: hwangjeff Date: Tue, 12 Apr 2022 21:45:30 +0000 Subject: [PATCH 2/3] move colab-specific steps to try-except import prototype blocks --- ...asr_inference_with_ctc_decoder_tutorial.py | 26 ++++++++---- examples/tutorials/device_asr.py | 4 +- examples/tutorials/online_asr_tutorial.py | 42 +++++++++++-------- examples/tutorials/streaming_api_tutorial.py | 36 +++++++++------- 4 files changed, 68 insertions(+), 40 deletions(-) diff --git a/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py b/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py index 98b35af7bd..8be42d9234 100644 --- a/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py +++ b/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py @@ -21,13 +21,6 @@ # Please refer to https://pytorch.org/get-started/locally/ # for instructions. # -# To enable running the tutorial 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 -# # The interfaces of prototype features are unstable and subject to # change. Please refer to `the nightly build documentation # `__ for the up-to-date @@ -79,6 +72,25 @@ 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 diff --git a/examples/tutorials/device_asr.py b/examples/tutorials/device_asr.py index 46804a5d97..6aeaf7a8a3 100644 --- a/examples/tutorials/device_asr.py +++ b/examples/tutorials/device_asr.py @@ -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 @@ -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. diff --git a/examples/tutorials/online_asr_tutorial.py b/examples/tutorials/online_asr_tutorial.py index 222aba82ab..bed23b6a84 100644 --- a/examples/tutorials/online_asr_tutorial.py +++ b/examples/tutorials/online_asr_tutorial.py @@ -13,20 +13,13 @@ # # .. 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/ # for instructions. # -# To enable running the tutorial 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 -# # The interfaces of prototype features are unstable and subject to # change. Please refer to `the nightly build documentation # `__ for the up-to-date @@ -37,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 @@ -66,10 +53,31 @@ 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 diff --git a/examples/tutorials/streaming_api_tutorial.py b/examples/tutorials/streaming_api_tutorial.py index 6f1e62e904..b3efe7a07e 100644 --- a/examples/tutorials/streaming_api_tutorial.py +++ b/examples/tutorials/streaming_api_tutorial.py @@ -19,13 +19,6 @@ # Please refer to https://pytorch.org/get-started/locally/ # for instructions. # -# To enable running the tutorial 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 -# # The interfaces of prototype features are unstable and subject to # change. Please refer to `the nightly build documentation # `__ for the up-to-date @@ -36,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 @@ -84,7 +70,27 @@ 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__) From cb39bb1974d9848657310f8361846e398e8f271a Mon Sep 17 00:00:00 2001 From: hwangjeff Date: Tue, 12 Apr 2022 22:22:15 +0000 Subject: [PATCH 3/3] lint --- examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py | 1 + examples/tutorials/online_asr_tutorial.py | 1 + examples/tutorials/streaming_api_tutorial.py | 1 + 3 files changed, 3 insertions(+) diff --git a/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py b/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py index 8be42d9234..aa79e9d740 100644 --- a/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py +++ b/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py @@ -77,6 +77,7 @@ except ModuleNotFoundError: try: import google.colab + print( """ To enable running this notebook in Google Colab, install nightly diff --git a/examples/tutorials/online_asr_tutorial.py b/examples/tutorials/online_asr_tutorial.py index bed23b6a84..0c1d279346 100644 --- a/examples/tutorials/online_asr_tutorial.py +++ b/examples/tutorials/online_asr_tutorial.py @@ -58,6 +58,7 @@ except ModuleNotFoundError: try: import google.colab + print( """ To enable running this notebook in Google Colab, install nightly diff --git a/examples/tutorials/streaming_api_tutorial.py b/examples/tutorials/streaming_api_tutorial.py index b3efe7a07e..ec5a85ac3d 100644 --- a/examples/tutorials/streaming_api_tutorial.py +++ b/examples/tutorials/streaming_api_tutorial.py @@ -76,6 +76,7 @@ except ModuleNotFoundError: try: import google.colab + print( """ To enable running this notebook in Google Colab, install nightly