From a9bd604fa3b514313904987aaafcfb8a3045e352 Mon Sep 17 00:00:00 2001 From: Jessica Lin Date: Thu, 18 Jun 2020 10:14:39 -0700 Subject: [PATCH 1/2] Update feature classification labels --- .../dynamic_quantization_tutorial.py | 4 +- .../static_quantization_tutorial.py | 2 +- index.rst | 12 ++-- .../dynamic_quantization_bert_tutorial.rst | 8 +-- intermediate_source/memory_format_tutorial.py | 26 ++++---- intermediate_source/named_tensor_tutorial.py | 2 +- .../quantized_transfer_learning_tutorial.rst | 10 +-- intermediate_source/rpc_tutorial.rst | 2 +- .../recipes/dynamic_quantization.py | 64 +++++++++---------- 9 files changed, 65 insertions(+), 65 deletions(-) diff --git a/advanced_source/dynamic_quantization_tutorial.py b/advanced_source/dynamic_quantization_tutorial.py index 990fd688651..cabdd90d224 100644 --- a/advanced_source/dynamic_quantization_tutorial.py +++ b/advanced_source/dynamic_quantization_tutorial.py @@ -1,5 +1,5 @@ """ -(experimental) Dynamic Quantization on an LSTM Word Language Model +(beta) Dynamic Quantization on an LSTM Word Language Model ================================================================== **Author**: `James Reed `_ @@ -13,7 +13,7 @@ to int, which can result in smaller model size and faster inference with only a small hit to accuracy. -In this tutorial, we'll apply the easiest form of quantization - +In this tutorial, we'll apply the easiest form of quantization - `dynamic quantization `_ - to an LSTM-based next word-prediction model, closely following the `word language model `_ diff --git a/advanced_source/static_quantization_tutorial.py b/advanced_source/static_quantization_tutorial.py index 60f9112a8c1..72ea3cc703e 100644 --- a/advanced_source/static_quantization_tutorial.py +++ b/advanced_source/static_quantization_tutorial.py @@ -1,5 +1,5 @@ """ -(experimental) Static Quantization with Eager Mode in PyTorch +(beta) Static Quantization with Eager Mode in PyTorch ========================================================= **Author**: `Raghuraman Krishnamoorthi `_ diff --git a/index.rst b/index.rst index 81113c919ed..9a8762e8026 100644 --- a/index.rst +++ b/index.rst @@ -203,14 +203,14 @@ Welcome to PyTorch Tutorials .. Frontend APIs .. customcarditem:: - :header: (experimental) Introduction to Named Tensors in PyTorch + :header: (prototype) Introduction to Named Tensors in PyTorch :card_description: Learn how to use PyTorch to train a Deep Q Learning (DQN) agent on the CartPole-v0 task from the OpenAI Gym. :image: _static/img/thumbnails/cropped/experimental-Introduction-to-Named-Tensors-in-PyTorch.png :link: intermediate/memory_format_tutorial.html :tags: Frontend-APIs,Named-Tensor,Best-Practice .. customcarditem:: - :header: (experimental) Channels Last Memory Format in PyTorch + :header: (beta) Channels Last Memory Format in PyTorch :card_description: Get an overview of Channels Last memory format and understand how it is used to order NCHW tensors in memory preserving dimensions. :image: _static/img/thumbnails/cropped/experimental-Channels-Last-Memory-Format-in-PyTorch.png :link: intermediate/memory_format_tutorial.html @@ -261,28 +261,28 @@ Welcome to PyTorch Tutorials :tags: Model-Optimization,Best-Practice .. customcarditem:: - :header: (experimental) Dynamic Quantization on an LSTM Word Language Model + :header: (beta) Dynamic Quantization on an LSTM Word Language Model :card_description: Apply dynamic quantization, the easiest form of quantization, to a LSTM-based next word prediction model. :image: _static/img/thumbnails/cropped/experimental-Dynamic-Quantization-on-an-LSTM-Word-Language-Model.png :link: advanced/dynamic_quantization_tutorial.html :tags: Text,Quantization,Model-Optimization .. customcarditem:: - :header: (experimental) Dynamic Quantization on BERT + :header: (beta) Dynamic Quantization on BERT :card_description: Apply the dynamic quantization on a BERT (Bidirectional Embedding Representations from Transformers) model. :image: _static/img/thumbnails/cropped/experimental-Dynamic-Quantization-on-BERT.png :link: intermediate/dynamic_quantization_bert_tutorial.html :tags: Text,Quantization,Model-Optimization .. customcarditem:: - :header: (experimental) Static Quantization with Eager Mode in PyTorch + :header: (beta) Static Quantization with Eager Mode in PyTorch :card_description: Learn techniques to impove a model's accuracy = post-training static quantization, per-channel quantization, and quantization-aware training. :image: _static/img/thumbnails/cropped/experimental-Static-Quantization-with-Eager-Mode-in-PyTorch.png :link: advanced/static_quantization_tutorial.html :tags: Image/Video,Quantization,Model-Optimization .. customcarditem:: - :header: (experimental) Quantized Transfer Learning for Computer Vision Tutorial + :header: (beta) Quantized Transfer Learning for Computer Vision Tutorial :card_description: Learn techniques to impove a model's accuracy - post-training static quantization, per-channel quantization, and quantization-aware training. :image: _static/img/thumbnails/cropped/experimental-Quantized-Transfer-Learning-for-Computer-Vision-Tutorial.png :link: advanced/static_quantization_tutorial.html diff --git a/intermediate_source/dynamic_quantization_bert_tutorial.rst b/intermediate_source/dynamic_quantization_bert_tutorial.rst index c3c800bbf89..6642f6768c8 100644 --- a/intermediate_source/dynamic_quantization_bert_tutorial.rst +++ b/intermediate_source/dynamic_quantization_bert_tutorial.rst @@ -1,10 +1,10 @@ -(experimental) Dynamic Quantization on BERT +(beta) Dynamic Quantization on BERT =========================================== .. tip:: - To get the most of this tutorial, we suggest using this + To get the most of this tutorial, we suggest using this `Colab Version `_. This will allow you to experiment with the information presented below. - + **Author**: `Jianyu Huang `_ **Reviewed by**: `Raghuraman Krishnamoorthi `_ @@ -71,7 +71,7 @@ built-in F1 score calculation helper function. pip install transformers -Because we will be using the experimental parts of the PyTorch, it is +Because we will be using the beta parts of the PyTorch, it is recommended to install the latest version of torch and torchvision. You can find the most recent instructions on local installation `here `_. For example, to install on diff --git a/intermediate_source/memory_format_tutorial.py b/intermediate_source/memory_format_tutorial.py index 2c3109de1e1..e988457d93b 100644 --- a/intermediate_source/memory_format_tutorial.py +++ b/intermediate_source/memory_format_tutorial.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -(experimental) Channels Last Memory Format in PyTorch +(beta) Channels Last Memory Format in PyTorch ******************************************************* **Author**: `Vitaly Fedyunin `_ @@ -11,12 +11,12 @@ For example, classic (contiguous) storage of NCHW tensor (in our case it is two 2x2 images with 3 color channels) look like this: -.. figure:: /_static/img/classic_memory_format.png +.. figure:: /_static/img/classic_memory_format.png :alt: classic_memory_format Channels Last memory format orders data differently: -.. figure:: /_static/img/channels_last_memory_format.png +.. figure:: /_static/img/channels_last_memory_format.png :alt: channels_last_memory_format Pytorch supports memory formats (and provides back compatibility with existing models including eager, JIT, and TorchScript) by utilizing existing strides structure. @@ -34,7 +34,7 @@ # Memory Format API # ----------------------- # -# Here is how to convert tensors between contiguous and channels +# Here is how to convert tensors between contiguous and channels # last memory formats. ###################################################################### @@ -104,7 +104,7 @@ ###################################################################### # Performance Gains # ------------------------------------------------------------------------------------------- -# The most significant performance gains are observed on NVidia's hardware with +# The most significant performance gains are observed on NVidia's hardware with # Tensor Cores support. We were able to archive over 22% perf gains while running ' # AMP (Automated Mixed Precision) training scripts supplied by NVidia https://github.com/NVIDIA/apex. # @@ -144,7 +144,7 @@ ###################################################################### # Passing ``--channels-last true`` allows running a model in Channels Last format with observed 22% perf gain. -# +# # ``python main_amp.py -a resnet50 --b 200 --workers 16 --opt-level O2 --channels-last true ./data`` # opt_level = O2 @@ -192,7 +192,7 @@ # Converting existing models # -------------------------- # -# Channels Last support not limited by existing models, as any model can be converted to Channels Last and propagate format through the graph as soon as input formatted correctly. +# Channels Last support not limited by existing models, as any model can be converted to Channels Last and propagate format through the graph as soon as input formatted correctly. # # Need to be done once, after model initialization (or load) @@ -203,12 +203,12 @@ output = model(input) ####################################################################### -# However, not all operators fully converted to support Channels Last (usually returning -# contiguous output instead). That means you need to verify the list of used operators -# against supported operators list https://github.com/pytorch/pytorch/wiki/Operators-with-Channels-Last-support, +# However, not all operators fully converted to support Channels Last (usually returning +# contiguous output instead). That means you need to verify the list of used operators +# against supported operators list https://github.com/pytorch/pytorch/wiki/Operators-with-Channels-Last-support, # or introduce memory format checks into eager execution mode and run your model. -# -# After running the code below, operators will raise an exception if the output of the +# +# After running the code below, operators will raise an exception if the output of the # operator doesn't match the memory format of the input. # # @@ -282,7 +282,7 @@ def attribute(m): ###################################################################### # If you found an operator that doesn't support Channels Last tensors -# and you want to contribute, feel free to use following developers +# and you want to contribute, feel free to use following developers # guide https://github.com/pytorch/pytorch/wiki/Writing-memory-format-aware-operators. # diff --git a/intermediate_source/named_tensor_tutorial.py b/intermediate_source/named_tensor_tutorial.py index 09946a50809..34941604083 100644 --- a/intermediate_source/named_tensor_tutorial.py +++ b/intermediate_source/named_tensor_tutorial.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- """ -(experimental) Introduction to Named Tensors in PyTorch +(prototype) Introduction to Named Tensors in PyTorch ******************************************************* **Author**: `Richard Zou `_ diff --git a/intermediate_source/quantized_transfer_learning_tutorial.rst b/intermediate_source/quantized_transfer_learning_tutorial.rst index 5d734922aed..a4be9eafe9a 100644 --- a/intermediate_source/quantized_transfer_learning_tutorial.rst +++ b/intermediate_source/quantized_transfer_learning_tutorial.rst @@ -1,10 +1,10 @@ -(experimental) Quantized Transfer Learning for Computer Vision Tutorial +(beta) Quantized Transfer Learning for Computer Vision Tutorial ======================================================================== .. tip:: - To get the most of this tutorial, we suggest using this - `Colab Version `_. - This will allow you to experiment with the information presented below. + To get the most of this tutorial, we suggest using this + `Colab Version `_. + This will allow you to experiment with the information presented below. **Author**: `Zafar Takhirov `_ @@ -62,7 +62,7 @@ such as installations and data loading/visualizations. Installing the Nightly Build ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Because you will be using the experimental parts of the PyTorch, it is +Because you will be using the beta parts of the PyTorch, it is recommended to install the latest version of ``torch`` and ``torchvision``. You can find the most recent instructions on local installation `here `_. diff --git a/intermediate_source/rpc_tutorial.rst b/intermediate_source/rpc_tutorial.rst index 6d149e80837..16d47f9379a 100644 --- a/intermediate_source/rpc_tutorial.rst +++ b/intermediate_source/rpc_tutorial.rst @@ -5,7 +5,7 @@ Getting Started with Distributed RPC Framework This tutorial uses two simple examples to demonstrate how to build distributed training with the `torch.distributed.rpc `__ -package which is first introduced as an experimental feature in PyTorch v1.4. +package which is first introduced as a prototype feature in PyTorch v1.4. Source code of the two examples can be found in `PyTorch examples `__. diff --git a/recipes_source/recipes/dynamic_quantization.py b/recipes_source/recipes/dynamic_quantization.py index 78dc1f5408a..945ea5f70fd 100644 --- a/recipes_source/recipes/dynamic_quantization.py +++ b/recipes_source/recipes/dynamic_quantization.py @@ -127,13 +127,13 @@ # define a very, very simple LSTM for demonstration purposes # in this case, we are wrapping nn.LSTM, one layer, no pre or post processing -# inspired by +# inspired by # https://pytorch.org/tutorials/beginner/nlp/sequence_models_tutorial.html, by Robert Guthrie # and https://pytorch.org/tutorials/advanced/dynamic_quantization_tutorial.html class lstm_for_demonstration(nn.Module): """Elementary Long Short Term Memory style model which simply wraps nn.LSTM - Not to be used for anything other than demonstration. - """ + Not to be used for anything other than demonstration. + """ def __init__(self,in_dim,out_dim,depth): super(lstm_for_demonstration,self).__init__() self.lstm = nn.LSTM(in_dim,out_dim,depth) @@ -142,7 +142,7 @@ def forward(self,inputs,hidden): out,hidden = self.lstm(inputs,hidden) return out, hidden - + torch.manual_seed(29592) # set the seed for reproducibility #shape parameters @@ -154,32 +154,32 @@ def forward(self,inputs,hidden): # random data for input inputs = torch.randn(sequence_length,batch_size,model_dimension) # hidden is actually is a tuple of the initial hidden state and the initial cell state -hidden = (torch.randn(lstm_depth,batch_size,model_dimension), torch.randn(lstm_depth,batch_size,model_dimension)) +hidden = (torch.randn(lstm_depth,batch_size,model_dimension), torch.randn(lstm_depth,batch_size,model_dimension)) ###################################################################### # 2: Do the Quantization # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# +# # Now we get to the fun part. First we create an instance of the model # called float\_lstm then we are going to quantize it. We're going to use # the -# +# # :: -# +# # torch.quantization.quantize_dynamic() -# +# # function here (`see # documentation `__) # which takes the model, then a list of the submodules which we want to # have quantized if they appear, then the datatype we are targeting. This # function returns a quantized version of the original model as a new # module. -# +# # That's all it takes. -# +# - # here is our floating point instance + # here is our floating point instance float_lstm = lstm_for_demonstration(model_dimension, model_dimension,lstm_depth) # this is the call that does the work @@ -206,7 +206,7 @@ def forward(self,inputs,hidden): # (for example you can set model dimension to something like 80) this will # converge towards 4x smaller as the stored model size dominated more and # more by the parameter values. -# +# def print_size_of_model(model, label=""): torch.save(model.state_dict(), "temp.p") @@ -221,7 +221,7 @@ def print_size_of_model(model, label=""): print("{0:.2f} times smaller".format(f/q)) # note that this value is wrong in PyTorch 1.4 due to https://github.com/pytorch/pytorch/issues/31468 -# this will be fixed in 1.5 with https://github.com/pytorch/pytorch/pull/31540 +# this will be fixed in 1.5 with https://github.com/pytorch/pytorch/pull/31540 ###################################################################### @@ -229,15 +229,15 @@ def print_size_of_model(model, label=""): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # The second benefit is that the quantized model will typically run # faster. This is due to a combinations of effects including at least: -# +# # 1. Less time spent moving parameter data in # 2. Faster INT8 operations -# +# # As you will see the quantized version of this super-simple network runs # faster. This will generally be true of more complex networks but as they # say "your milage may vary" depending on a number of factors including # the structure of the model and the hardware you are running on. -# +# # compare the performance print("Floating point FP32") @@ -255,10 +255,10 @@ def print_size_of_model(model, label=""): # trained one. However, I think it is worth quickly showing that the # quantized network does produce output tensors that are "in the same # ballpark" as the original one. -# +# # For a more detailed analysis please see the more advanced tutorials # referenced at the end of this recipe. -# +# # run the float model out1, hidden1 = float_lstm(inputs, hidden) @@ -270,7 +270,7 @@ def print_size_of_model(model, label=""): mag2 = torch.mean(abs(out2)).item() print('mean absolute value of output tensor values in the INT8 model is {0:.5f}'.format(mag2)) -# compare them +# compare them mag3 = torch.mean(abs(out1-out2)).item() print('mean absolute value of the difference between the output tensors is {0:.5f} or {1:.2f} percent'.format(mag3,mag3/mag1*100)) @@ -281,26 +281,26 @@ def print_size_of_model(model, label=""): # We've explained what dynamic quantization is, what benefits it brings, # and you have used the ``torch.quantization.quantize_dynamic()`` function # to quickly quantize a simple LSTM model. -# +# # This was a fast and high level treatment of this material; for more -# detail please continue learning with `(experimental) Dynamic Quantization on an LSTM Word Language Model Tutorial `_. -# -# +# detail please continue learning with `(beta) Dynamic Quantization on an LSTM Word Language Model Tutorial `_. +# +# # Additional Resources # ========= # Documentation # ~~~~~~~~~~~~~~ -# +# # `Quantization API Documentaion `_ -# +# # Tutorials # ~~~~~~~~~~~~~~ -# -# `(experimental) Dynamic Quantization on BERT `_ -# -# `(experimental) Dynamic Quantization on an LSTM Word Language Model `_ -# +# +# `(beta) Dynamic Quantization on BERT `_ +# +# `(beta) Dynamic Quantization on an LSTM Word Language Model `_ +# # Blogs # ~~~~~~~~~~~~~~ # ` Introduction to Quantization on PyTorch `_ -# +# From 45d02c7138ab9041cbe90255850d701da8b0ebc1 Mon Sep 17 00:00:00 2001 From: Jessica Lin Date: Mon, 22 Jun 2020 19:52:28 -0700 Subject: [PATCH 2/2] Update NVidia -> Nvidia --- intermediate_source/memory_format_tutorial.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/intermediate_source/memory_format_tutorial.py b/intermediate_source/memory_format_tutorial.py index e988457d93b..244e23ac204 100644 --- a/intermediate_source/memory_format_tutorial.py +++ b/intermediate_source/memory_format_tutorial.py @@ -104,9 +104,9 @@ ###################################################################### # Performance Gains # ------------------------------------------------------------------------------------------- -# The most significant performance gains are observed on NVidia's hardware with +# The most significant performance gains are observed on Nvidia's hardware with # Tensor Cores support. We were able to archive over 22% perf gains while running ' -# AMP (Automated Mixed Precision) training scripts supplied by NVidia https://github.com/NVIDIA/apex. +# AMP (Automated Mixed Precision) training scripts supplied by Nvidia https://github.com/NVIDIA/apex. # # ``python main_amp.py -a resnet50 --b 200 --workers 16 --opt-level O2 ./data``