Skip to content

Commit 0ab21ee

Browse files
authored
Merge branch 'master' into patch-1
2 parents 59209c6 + 68c22a0 commit 0ab21ee

14 files changed

+111
-98
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ beginner
33
intermediate
44
advanced
55
pytorch_basics
6+
recipes
67

78
#data things
89
_data/
@@ -31,6 +32,7 @@ __pycache__/
3132
*.so
3233

3334
# Distribution / packaging
35+
src/
3436
.Python
3537
env/
3638
build/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ docs:
109109

110110
html-noplot:
111111
$(SPHINXBUILD) -D plot_gallery=0 -b html $(SPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)/html"
112-
bash .jenkins/remove_invisible_code_block_batch.sh "$(BUILDDIR)/html"
112+
# bash .jenkins/remove_invisible_code_block_batch.sh "$(BUILDDIR)/html"
113113
@echo
114114
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
115115

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ All the tutorials are now presented as sphinx style documentation at:
1111

1212
We use sphinx-gallery's [notebook styled examples](https://sphinx-gallery.github.io/stable/tutorials/index.html) to create the tutorials. Syntax is very simple. In essence, you write a slightly well formatted python file and it shows up as documentation page.
1313

14-
Here's how to create a new tutorial:
14+
Here's how to create a new tutorial or recipe:
1515
1. Create a notebook styled python file. If you want it executed while inserted into documentation, save the file with suffix `tutorial` so that file name is `your_tutorial.py`.
16-
2. Put it in one of the beginner_source, intermediate_source, advanced_source based on the level.
17-
2. Include it in the right TOC tree at index.rst
18-
3. Create a thumbnail in the index file using a command like `.. galleryitem:: beginner/your_tutorial.py`. (This is a custom directive. See `custom_directives.py` for more info.)
16+
2. Put it in one of the beginner_source, intermediate_source, advanced_source based on the level. If it is a recipe, add to recipes_source.
17+
2. For Tutorials, include it in the TOC tree at index.rst
18+
3. For Tutorials, create a thumbnail in the [index.rst file](https://github.com/pytorch/tutorials/blob/master/index.rst) using a command like `.. customcarditem:: beginner/your_tutorial.html`. For Recipes, create a thumbnail in the [recipes_index.rst](https://github.com/pytorch/tutorials/blob/master/recipes_source/recipes_index.rst)
1919

2020
In case you prefer to write your tutorial in jupyter, you can use [this script](https://gist.github.com/chsasank/7218ca16f8d022e02a9c0deb94a310fe) to convert the notebook to python file. After conversion and addition to the project, please make sure the sections headings etc are in logical order.
2121

@@ -28,4 +28,4 @@ In case you prefer to write your tutorial in jupyter, you can use [this script](
2828
- Then you can build using `make docs`. This will download the data, execute the tutorials and build the documentation to `docs/` directory. This will take about 60-120 min for systems with GPUs. If you do not have a GPU installed on your system, then see next step.
2929
- You can skip the computationally intensive graph generation by running `make html-noplot` to build basic html documentation to `_build/html`. This way, you can quickly preview your tutorial.
3030

31-
> If you get **ModuleNotFoundError: No module named 'pytorch_sphinx_theme' make: *** [html-noplot] Error 2**, from /tutorials/src/pytorch_sphinx_theme run `python setup.py install`.
31+
> If you get **ModuleNotFoundError: No module named 'pytorch_sphinx_theme' make: *** [html-noplot] Error 2**, from /tutorials/src/pytorch-sphinx-theme run `python setup.py install`.

advanced_source/dynamic_quantization_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
(experimental) Dynamic Quantization on an LSTM Word Language Model
2+
(beta) Dynamic Quantization on an LSTM Word Language Model
33
==================================================================
44
55
**Author**: `James Reed <https://github.com/jamesr66a>`_
@@ -13,7 +13,7 @@
1313
to int, which can result in smaller model size and faster inference with only a small
1414
hit to accuracy.
1515
16-
In this tutorial, we'll apply the easiest form of quantization -
16+
In this tutorial, we'll apply the easiest form of quantization -
1717
`dynamic quantization <https://pytorch.org/docs/stable/quantization.html#torch.quantization.quantize_dynamic>`_ -
1818
to an LSTM-based next word-prediction model, closely following the
1919
`word language model <https://github.com/pytorch/examples/tree/master/word_language_model>`_

advanced_source/static_quantization_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
(experimental) Static Quantization with Eager Mode in PyTorch
2+
(beta) Static Quantization with Eager Mode in PyTorch
33
=========================================================
44
55
**Author**: `Raghuraman Krishnamoorthi <https://github.com/raghuramank100>`_

conf.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import glob
3636
import shutil
3737
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective
38+
import distutils.file_util
39+
import re
3840

3941

4042
try:
@@ -63,10 +65,20 @@
6365
'examples_dirs': ['beginner_source', 'intermediate_source',
6466
'advanced_source', 'recipes_source'],
6567
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes'],
66-
'filename_pattern': os.environ.get('GALLERY_PATTERN', r'tutorial.py'),
68+
'filename_pattern': 'tutorial.py',
6769
'backreferences_dir': False
6870
}
6971

72+
if os.getenv('GALLERY_PATTERN'):
73+
# GALLERY_PATTERN is to be used when you want to work on a single
74+
# tutorial. Previously this was fed into filename_pattern, but
75+
# if you do that, you still end up parsing all of the other Python
76+
# files which takes a few seconds. This strategy is better, as
77+
# ignore_pattern also skips parsing.
78+
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
79+
# for a more detailed description of the issue.
80+
sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'
81+
7082
for i in range(len(sphinx_gallery_conf['examples_dirs'])):
7183
gallery_dir = sphinx_gallery_conf['gallery_dirs'][i]
7284
source_dir = sphinx_gallery_conf['examples_dirs'][i]
@@ -78,7 +90,7 @@
7890

7991
# Copy rst files from source dir to gallery dir
8092
for f in glob.glob(os.path.join(source_dir, '*.rst')):
81-
shutil.copy(f, gallery_dir)
93+
distutils.file_util.copy_file(f, gallery_dir, update=True)
8294

8395

8496
# Add any paths that contain templates here, relative to this directory.

index.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Welcome to PyTorch Tutorials
99
.. Add callout items below this line
1010
1111
.. customcalloutitem::
12-
:description: The 60 min blitz is the most common starting point and provides a broad view on how to use PyTorch. It covers the basics all to the way constructing deep neural networks.
12+
:description: The 60 min blitz is the most common starting point and provides a broad view on how to use PyTorch. It covers the basics all the way to constructing deep neural networks.
1313
:header: New to PyTorch?
1414
:button_link: beginner/deep_learning_60min_blitz.html
1515
:button_text: Start 60-min blitz
@@ -203,14 +203,14 @@ Welcome to PyTorch Tutorials
203203
.. Frontend APIs
204204
205205
.. customcarditem::
206-
:header: (experimental) Introduction to Named Tensors in PyTorch
206+
:header: (prototype) Introduction to Named Tensors in PyTorch
207207
:card_description: Learn how to use PyTorch to train a Deep Q Learning (DQN) agent on the CartPole-v0 task from the OpenAI Gym.
208208
:image: _static/img/thumbnails/cropped/experimental-Introduction-to-Named-Tensors-in-PyTorch.png
209209
:link: intermediate/memory_format_tutorial.html
210210
:tags: Frontend-APIs,Named-Tensor,Best-Practice
211211

212212
.. customcarditem::
213-
:header: (experimental) Channels Last Memory Format in PyTorch
213+
:header: (beta) Channels Last Memory Format in PyTorch
214214
:card_description: Get an overview of Channels Last memory format and understand how it is used to order NCHW tensors in memory preserving dimensions.
215215
:image: _static/img/thumbnails/cropped/experimental-Channels-Last-Memory-Format-in-PyTorch.png
216216
:link: intermediate/memory_format_tutorial.html
@@ -261,28 +261,28 @@ Welcome to PyTorch Tutorials
261261
:tags: Model-Optimization,Best-Practice
262262

263263
.. customcarditem::
264-
:header: (experimental) Dynamic Quantization on an LSTM Word Language Model
264+
:header: (beta) Dynamic Quantization on an LSTM Word Language Model
265265
:card_description: Apply dynamic quantization, the easiest form of quantization, to a LSTM-based next word prediction model.
266266
:image: _static/img/thumbnails/cropped/experimental-Dynamic-Quantization-on-an-LSTM-Word-Language-Model.png
267267
:link: advanced/dynamic_quantization_tutorial.html
268268
:tags: Text,Quantization,Model-Optimization
269269

270270
.. customcarditem::
271-
:header: (experimental) Dynamic Quantization on BERT
271+
:header: (beta) Dynamic Quantization on BERT
272272
:card_description: Apply the dynamic quantization on a BERT (Bidirectional Embedding Representations from Transformers) model.
273273
:image: _static/img/thumbnails/cropped/experimental-Dynamic-Quantization-on-BERT.png
274274
:link: intermediate/dynamic_quantization_bert_tutorial.html
275275
:tags: Text,Quantization,Model-Optimization
276276

277277
.. customcarditem::
278-
:header: (experimental) Static Quantization with Eager Mode in PyTorch
278+
:header: (beta) Static Quantization with Eager Mode in PyTorch
279279
:card_description: Learn techniques to impove a model's accuracy = post-training static quantization, per-channel quantization, and quantization-aware training.
280280
:image: _static/img/thumbnails/cropped/experimental-Static-Quantization-with-Eager-Mode-in-PyTorch.png
281281
:link: advanced/static_quantization_tutorial.html
282282
:tags: Image/Video,Quantization,Model-Optimization
283283

284284
.. customcarditem::
285-
:header: (experimental) Quantized Transfer Learning for Computer Vision Tutorial
285+
:header: (beta) Quantized Transfer Learning for Computer Vision Tutorial
286286
:card_description: Learn techniques to impove a model's accuracy - post-training static quantization, per-channel quantization, and quantization-aware training.
287287
:image: _static/img/thumbnails/cropped/experimental-Quantized-Transfer-Learning-for-Computer-Vision-Tutorial.png
288288
:link: advanced/static_quantization_tutorial.html

intermediate_source/dist_tuto.rst

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -394,29 +394,28 @@ using point-to-point collectives.
394394
395395
""" Implementation of a ring-reduce with addition. """
396396
def allreduce(send, recv):
397-
rank = dist.get_rank()
398-
size = dist.get_world_size()
399-
send_buff = th.zeros(send.size())
400-
recv_buff = th.zeros(send.size())
401-
accum = th.zeros(send.size())
402-
accum[:] = send[:]
403-
404-
left = ((rank - 1) + size) % size
405-
right = (rank + 1) % size
406-
407-
for i in range(size - 1):
408-
if i % 2 == 0:
409-
# Send send_buff
410-
send_req = dist.isend(send_buff, right)
411-
dist.recv(recv_buff, left)
412-
accum[:] += recv[:]
413-
else:
414-
# Send recv_buff
415-
send_req = dist.isend(recv_buff, right)
416-
dist.recv(send_buff, left)
417-
accum[:] += send[:]
418-
send_req.wait()
419-
recv[:] = accum[:]
397+
rank = dist.get_rank()
398+
size = dist.get_world_size()
399+
send_buff = send.clone()
400+
recv_buff = send.clone()
401+
accum = send.clone()
402+
403+
left = ((rank - 1) + size) % size
404+
right = (rank + 1) % size
405+
406+
for i in range(size - 1):
407+
if i % 2 == 0:
408+
# Send send_buff
409+
send_req = dist.isend(send_buff, right)
410+
dist.recv(recv_buff, left)
411+
accum[:] += recv_buff[:]
412+
else:
413+
# Send recv_buff
414+
send_req = dist.isend(recv_buff, right)
415+
dist.recv(send_buff, left)
416+
accum[:] += send_buff[:]
417+
send_req.wait()
418+
recv[:] = accum[:]
420419
421420
In the above script, the ``allreduce(send, recv)`` function has a
422421
slightly different signature than the ones in PyTorch. It takes a

intermediate_source/dynamic_quantization_bert_tutorial.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
(experimental) Dynamic Quantization on BERT
1+
(beta) Dynamic Quantization on BERT
22
===========================================
33

44
.. tip::
5-
To get the most of this tutorial, we suggest using this
5+
To get the most of this tutorial, we suggest using this
66
`Colab Version <https://colab.research.google.com/github/pytorch/tutorials/blob/gh-pages/_downloads/dynamic_quantization_bert_tutorial.ipynb>`_. This will allow you to experiment with the information presented below.
7-
7+
88
**Author**: `Jianyu Huang <https://github.com/jianyuh>`_
99

1010
**Reviewed by**: `Raghuraman Krishnamoorthi <https://github.com/raghuramank100>`_
@@ -71,7 +71,7 @@ built-in F1 score calculation helper function.
7171
pip install transformers
7272
7373
74-
Because we will be using the experimental parts of the PyTorch, it is
74+
Because we will be using the beta parts of the PyTorch, it is
7575
recommended to install the latest version of torch and torchvision. You
7676
can find the most recent instructions on local installation `here
7777
<https://pytorch.org/get-started/locally/>`_. For example, to install on

intermediate_source/memory_format_tutorial.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
(experimental) Channels Last Memory Format in PyTorch
3+
(beta) Channels Last Memory Format in PyTorch
44
*******************************************************
55
**Author**: `Vitaly Fedyunin <https://github.com/VitalyFedyunin>`_
66
@@ -11,12 +11,12 @@
1111
1212
For example, classic (contiguous) storage of NCHW tensor (in our case it is two 2x2 images with 3 color channels) look like this:
1313
14-
.. figure:: /_static/img/classic_memory_format.png
14+
.. figure:: /_static/img/classic_memory_format.png
1515
:alt: classic_memory_format
1616
1717
Channels Last memory format orders data differently:
1818
19-
.. figure:: /_static/img/channels_last_memory_format.png
19+
.. figure:: /_static/img/channels_last_memory_format.png
2020
:alt: channels_last_memory_format
2121
2222
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 @@
3434
# Memory Format API
3535
# -----------------------
3636
#
37-
# Here is how to convert tensors between contiguous and channels
37+
# Here is how to convert tensors between contiguous and channels
3838
# last memory formats.
3939

4040
######################################################################
@@ -104,9 +104,9 @@
104104
######################################################################
105105
# Performance Gains
106106
# -------------------------------------------------------------------------------------------
107-
# The most significant performance gains are observed on NVidia's hardware with
107+
# The most significant performance gains are observed on Nvidia's hardware with
108108
# Tensor Cores support. We were able to archive over 22% perf gains while running '
109-
# AMP (Automated Mixed Precision) training scripts supplied by NVidia https://github.com/NVIDIA/apex.
109+
# AMP (Automated Mixed Precision) training scripts supplied by Nvidia https://github.com/NVIDIA/apex.
110110
#
111111
# ``python main_amp.py -a resnet50 --b 200 --workers 16 --opt-level O2 ./data``
112112

@@ -144,7 +144,7 @@
144144

145145
######################################################################
146146
# Passing ``--channels-last true`` allows running a model in Channels Last format with observed 22% perf gain.
147-
#
147+
#
148148
# ``python main_amp.py -a resnet50 --b 200 --workers 16 --opt-level O2 --channels-last true ./data``
149149

150150
# opt_level = O2
@@ -192,7 +192,7 @@
192192
# Converting existing models
193193
# --------------------------
194194
#
195-
# 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.
195+
# 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.
196196
#
197197

198198
# Need to be done once, after model initialization (or load)
@@ -203,12 +203,12 @@
203203
output = model(input)
204204

205205
#######################################################################
206-
# However, not all operators fully converted to support Channels Last (usually returning
207-
# contiguous output instead). That means you need to verify the list of used operators
208-
# against supported operators list https://github.com/pytorch/pytorch/wiki/Operators-with-Channels-Last-support,
206+
# However, not all operators fully converted to support Channels Last (usually returning
207+
# contiguous output instead). That means you need to verify the list of used operators
208+
# against supported operators list https://github.com/pytorch/pytorch/wiki/Operators-with-Channels-Last-support,
209209
# or introduce memory format checks into eager execution mode and run your model.
210-
#
211-
# After running the code below, operators will raise an exception if the output of the
210+
#
211+
# After running the code below, operators will raise an exception if the output of the
212212
# operator doesn't match the memory format of the input.
213213
#
214214
#
@@ -282,7 +282,7 @@ def attribute(m):
282282

283283
######################################################################
284284
# If you found an operator that doesn't support Channels Last tensors
285-
# and you want to contribute, feel free to use following developers
285+
# and you want to contribute, feel free to use following developers
286286
# guide https://github.com/pytorch/pytorch/wiki/Writing-memory-format-aware-operators.
287287
#
288288

intermediate_source/named_tensor_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
(experimental) Introduction to Named Tensors in PyTorch
3+
(prototype) Introduction to Named Tensors in PyTorch
44
*******************************************************
55
**Author**: `Richard Zou <https://github.com/zou3519>`_
66

intermediate_source/quantized_transfer_learning_tutorial.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
(experimental) Quantized Transfer Learning for Computer Vision Tutorial
1+
(beta) Quantized Transfer Learning for Computer Vision Tutorial
22
========================================================================
33

44
.. tip::
5-
To get the most of this tutorial, we suggest using this
6-
`Colab Version <https://colab.research.google.com/github/pytorch/tutorials/blob/gh-pages/_downloads/quantized_transfer_learning_tutorial.ipynb>`_.
7-
This will allow you to experiment with the information presented below.
5+
To get the most of this tutorial, we suggest using this
6+
`Colab Version <https://colab.research.google.com/github/pytorch/tutorials/blob/gh-pages/_downloads/quantized_transfer_learning_tutorial.ipynb>`_.
7+
This will allow you to experiment with the information presented below.
88

99
**Author**: `Zafar Takhirov <https://github.com/z-a-f>`_
1010

@@ -62,7 +62,7 @@ such as installations and data loading/visualizations.
6262
Installing the Nightly Build
6363
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6464

65-
Because you will be using the experimental parts of the PyTorch, it is
65+
Because you will be using the beta parts of the PyTorch, it is
6666
recommended to install the latest version of ``torch`` and
6767
``torchvision``. You can find the most recent instructions on local
6868
installation `here <https://pytorch.org/get-started/locally/>`_.

intermediate_source/rpc_tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Getting Started with Distributed RPC Framework
55

66
This tutorial uses two simple examples to demonstrate how to build distributed
77
training with the `torch.distributed.rpc <https://pytorch.org/docs/master/rpc.html>`__
8-
package which is first introduced as an experimental feature in PyTorch v1.4.
8+
package which is first introduced as a prototype feature in PyTorch v1.4.
99
Source code of the two examples can be found in
1010
`PyTorch examples <https://github.com/pytorch/examples>`__.
1111

0 commit comments

Comments
 (0)