Skip to content

Commit da835dd

Browse files
authored
Merge branch 'master' into cifartut_improve
2 parents 5bbf9d8 + f1fd16f commit da835dd

27 files changed

+163
-150
lines changed

.circleci/scripts/build_for_windows.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ if [[ "${CIRCLE_JOB}" == *worker_* ]]; then
4949
python $DIR/remove_runnable_code.py advanced_source/static_quantization_tutorial.py advanced_source/static_quantization_tutorial.py || true
5050
python $DIR/remove_runnable_code.py beginner_source/hyperparameter_tuning_tutorial.py beginner_source/hyperparameter_tuning_tutorial.py || true
5151
python $DIR/remove_runnable_code.py beginner_source/audio_preprocessing_tutorial.py beginner_source/audio_preprocessing_tutorial.py || true
52+
python $DIR/remove_runnable_code.py beginner_source/dcgan_faces_tutorial.py beginner_source/dcgan_faces_tutorial.py || true
5253
python $DIR/remove_runnable_code.py intermediate_source/tensorboard_profiler_tutorial.py intermediate_source/tensorboard_profiler_tutorial.py || true
5354
# Temp remove for mnist download issue. (Re-enabled for 1.8.1)
5455
# python $DIR/remove_runnable_code.py beginner_source/fgsm_tutorial.py beginner_source/fgsm_tutorial.py || true

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ 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 or /venv/src/pytorch-sphinx-theme (while using virtualenv), run `python setup.py install`.
3232
3333

3434
## About contributing to PyTorch Documentation and Tutorials
3535
* You can find information about contributing to PyTorch documentation in the
3636
PyTorch Repo [README.md](https://github.com/pytorch/pytorch/blob/master/README.md) file.
37-
* Additional information can be found in [PyTorch CONTRIBUTING.md](https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md).
37+
* Additional information can be found in [PyTorch CONTRIBUTING.md](https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md).

_templates/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
</noscript>
7676

7777
<script type="text/javascript">
78-
var collapsedSections = ['PyTorch Recipes', 'Image and Video', 'Audio', 'Text', 'Reinforcement Learning', 'Deploying PyTorch Models in Production', 'Code Transforms with FX', 'Frontend APIs', 'Extending PyTorch', 'Model Optimization', 'Parallel and Distributed Training', 'Mobile'];
78+
var collapsedSections = ['PyTorch Recipes', 'Learning PyTorch', 'Image and Video', 'Audio', 'Text', 'Reinforcement Learning', 'Deploying PyTorch Models in Production', 'Code Transforms with FX', 'Frontend APIs', 'Extending PyTorch', 'Model Optimization', 'Parallel and Distributed Training', 'Mobile'];
7979
</script>
8080

8181
<img height="1" width="1" style="border-style:none;" alt="" src="https://www.googleadservices.com/pagead/conversion/795629140/?label=txkmCPmdtosBENSssfsC&amp;guid=ON&amp;script=0"/>

beginner_source/basics/autogradqs_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#
4848
# In this network, ``w`` and ``b`` are **parameters**, which we need to
4949
# optimize. Thus, we need to be able to compute the gradients of loss
50-
# function with respect to those variables. In orded to do that, we set
50+
# function with respect to those variables. In order to do that, we set
5151
# the ``requires_grad`` property of those tensors.
5252

5353
#######################################################################
@@ -58,7 +58,7 @@
5858
# A function that we apply to tensors to construct computational graph is
5959
# in fact an object of class ``Function``. This object knows how to
6060
# compute the function in the *forward* direction, and also how to compute
61-
# it's derivative during the *backward propagation* step. A reference to
61+
# its derivative during the *backward propagation* step. A reference to
6262
# the backward propagation function is stored in ``grad_fn`` property of a
6363
# tensor. You can find more information of ``Function`` `in the
6464
# documentation <https://pytorch.org/docs/stable/autograd.html#function>`__.

beginner_source/basics/buildmodel_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def forward(self, x):
6767

6868
##############################################
6969
# We create an instance of ``NeuralNetwork``, and move it to the ``device``, and print
70-
# it's structure.
70+
# its structure.
7171

7272
model = NeuralNetwork().to(device)
7373
print(model)
@@ -119,7 +119,7 @@ def forward(self, x):
119119
# nn.Linear
120120
# ^^^^^^^^^^^^^^^^^^^^^^
121121
# The `linear layer <https://pytorch.org/docs/stable/generated/torch.nn.Linear.html>`_
122-
# is a module that applies a linear transformation on the input using it's stored weights and biases.
122+
# is a module that applies a linear transformation on the input using its stored weights and biases.
123123
#
124124
layer1 = nn.Linear(in_features=28*28, out_features=20)
125125
hidden1 = layer1(flat_image)

beginner_source/basics/data_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def __getitem__(self, idx):
225225
# --------------------------
226226
#
227227
# We have loaded that dataset into the ``Dataloader`` and can iterate through the dataset as needed.
228-
# Each iteration below returns a batch of ``train_features`` and ``train_labels``(containing ``batch_size=64`` features and labels respectively).
228+
# Each iteration below returns a batch of ``train_features`` and ``train_labels`` (containing ``batch_size=64`` features and labels respectively).
229229
# Because we specified ``shuffle=True``, after we iterate over all batches the data is shuffled (for finer-grained control over
230230
# the data loading order, take a look at `Samplers <https://pytorch.org/docs/stable/data.html#data-loading-order-and-sampler>`_).
231231

beginner_source/blitz/README.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ Deep Learning with PyTorch: A 60 Minute Blitz
1313
Neural Networks
1414
https://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html#
1515

16-
4. autograd_tutorial.py
17-
Automatic Differentiation
18-
https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html
19-
20-
5. cifar10_tutorial.py
16+
4. cifar10_tutorial.py
2117
Training a Classifier
2218
https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html
2319

20+
5. data_parallel_tutorial.py
21+
Optional: Data Parallelism
22+
https://pytorch.org/tutorials/beginner/blitz/data_parallel_tutorial.html
2423

beginner_source/blitz/neural_networks_tutorial.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ def num_flat_features(self, x):
176176
# -> loss
177177
#
178178
# So, when we call ``loss.backward()``, the whole graph is differentiated
179-
# w.r.t. the loss, and all Tensors in the graph that have ``requires_grad=True``
180-
# will have their ``.grad`` Tensor accumulated with the gradient.
179+
# w.r.t. the neural net parameters, and all Tensors in the graph that have
180+
# ``requires_grad=True`` will have their ``.grad`` Tensor accumulated with the
181+
# gradient.
181182
#
182183
# For illustration, let us follow a few steps backward:
183184

beginner_source/chatbot_tutorial.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ def trimRareWords(voc, pairs, MIN_COUNT):
471471
# with mini-batches.
472472
#
473473
# Using mini-batches also means that we must be mindful of the variation
474-
# of sentence length in our batches. To accomodate sentences of different
474+
# of sentence length in our batches. To accommodate sentences of different
475475
# sizes in the same batch, we will make our batched input tensor of shape
476476
# *(max_length, batch_size)*, where sentences shorter than the
477477
# *max_length* are zero padded after an *EOS_token*.
@@ -615,7 +615,7 @@ def batch2TrainData(voc, pair_batch):
615615
# in normal sequential order, and one that is fed the input sequence in
616616
# reverse order. The outputs of each network are summed at each time step.
617617
# Using a bidirectional GRU will give us the advantage of encoding both
618-
# past and future context.
618+
# past and future contexts.
619619
#
620620
# Bidirectional RNN:
621621
#
@@ -700,7 +700,7 @@ def forward(self, input_seq, input_lengths, hidden=None):
700700
# states to generate the next word in the sequence. It continues
701701
# generating words until it outputs an *EOS_token*, representing the end
702702
# of the sentence. A common problem with a vanilla seq2seq decoder is that
703-
# if we rely soley on the context vector to encode the entire input
703+
# if we rely solely on the context vector to encode the entire input
704704
# sequence’s meaning, it is likely that we will have information loss.
705705
# This is especially the case when dealing with long input sequences,
706706
# greatly limiting the capability of our decoder.
@@ -950,7 +950,7 @@ def maskNLLLoss(inp, target, mask):
950950
# sequence (or batch of sequences). We use the ``GRU`` layer like this in
951951
# the ``encoder``. The reality is that under the hood, there is an
952952
# iterative process looping over each time step calculating hidden states.
953-
# Alternatively, you ran run these modules one time-step at a time. In
953+
# Alternatively, you can run these modules one time-step at a time. In
954954
# this case, we manually loop over the sequences during the training
955955
# process like we must do for the ``decoder`` model. As long as you
956956
# maintain the correct conceptual model of these modules, implementing
@@ -1115,7 +1115,7 @@ def trainIters(model_name, voc, pairs, encoder, decoder, encoder_optimizer, deco
11151115
# softmax value. This decoding method is optimal on a single time-step
11161116
# level.
11171117
#
1118-
# To facilite the greedy decoding operation, we define a
1118+
# To facilitate the greedy decoding operation, we define a
11191119
# ``GreedySearchDecoder`` class. When run, an object of this class takes
11201120
# an input sequence (``input_seq``) of shape *(input_seq length, 1)*, a
11211121
# scalar input length (``input_length``) tensor, and a ``max_length`` to

beginner_source/colab.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ At the top of the page click **Run in Google Colab**.
2020

2121
The file will open in Colab.
2222

23-
If you choose, **Runtime** then **Run All**, you'll get an error as the
23+
If you select **Runtime**, and then **Run All**, you'll get an error as the
2424
file can't be found.
2525

2626
To fix this, we'll copy the required file into our Google Drive account.
@@ -30,7 +30,7 @@ To fix this, we'll copy the required file into our Google Drive account.
3030
**cornell**.
3131
3. Visit the Cornell Movie Dialogs Corpus and download the ZIP file.
3232
4. Unzip the file on your local machine.
33-
5. Copy the file **movie\_lines.txt** to **data/cornell** folder you
33+
5. Copy the files **movie\_lines.txt** and **movie\_conversations.txt** to the **data/cornell** folder that you
3434
created in Google Drive.
3535

3636
Now we'll need to edit the file in\_ \_Colab to point to the file on
@@ -55,12 +55,12 @@ Change the two lines that follow:
5555

5656
We're now pointing to the file we uploaded to Drive.
5757

58-
Now when you click on the **Run cell** button for the code section,
58+
Now when you click the **Run cell** button for the code section,
5959
you'll be prompted to authorize Google Drive and you'll get an
6060
authorization code. Paste the code into the prompt in Colab and you
6161
should be set.
6262

63-
Rerun the notebook from **Runtime** / **Run All** menu command and
63+
Rerun the notebook from the **Runtime** / **Run All** menu command and
6464
you'll see it process. (Note that this tutorial takes a long time to
6565
run.)
6666

beginner_source/dcgan_faces_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
# :math:`D` and :math:`G` play a minimax game in which :math:`D` tries to
7272
# maximize the probability it correctly classifies reals and fakes
7373
# (:math:`logD(x)`), and :math:`G` tries to minimize the probability that
74-
# :math:`D` will predict its outputs are fake (:math:`log(1-D(G(x)))`).
74+
# :math:`D` will predict its outputs are fake (:math:`log(1-D(G(z)))`).
7575
# From the paper, the GAN loss function is
7676
#
7777
# .. math:: \underset{G}{\text{min}} \underset{D}{\text{max}}V(D,G) = \mathbb{E}_{x\sim p_{data}(x)}\big[logD(x)\big] + \mathbb{E}_{z\sim p_{z}(z)}\big[log(1-D(G(z)))\big]

beginner_source/nlp/pytorch_tutorial.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
All of deep learning is computations on tensors, which are
1010
generalizations of a matrix that can be indexed in more than 2
1111
dimensions. We will see exactly what this means in-depth later. First,
12-
lets look what we can do with tensors.
12+
let's look what we can do with tensors.
1313
"""
1414
# Author: Robert Guthrie
1515

@@ -162,7 +162,7 @@
162162
# other operation, etc.)
163163
#
164164
# If ``requires_grad=True``, the Tensor object keeps track of how it was
165-
# created. Lets see it in action.
165+
# created. Let's see it in action.
166166
#
167167

168168
# Tensor factory methods have a ``requires_grad`` flag
@@ -187,7 +187,7 @@
187187
# But how does that help us compute a gradient?
188188
#
189189

190-
# Lets sum up all the entries in z
190+
# Let's sum up all the entries in z
191191
s = z.sum()
192192
print(s)
193193
print(s.grad_fn)
@@ -222,7 +222,7 @@
222222

223223

224224
######################################################################
225-
# Lets have Pytorch compute the gradient, and see that we were right:
225+
# Let's have Pytorch compute the gradient, and see that we were right:
226226
# (note if you run this block multiple times, the gradient will increment.
227227
# That is because Pytorch *accumulates* the gradient into the .grad
228228
# property, since for many models this is very convenient.)

beginner_source/nn_tutorial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
torch.tensor, (x_train, y_train, x_valid, y_valid)
8686
)
8787
n, c = x_train.shape
88-
x_train, x_train.shape, y_train.min(), y_train.max()
8988
print(x_train, y_train)
9089
print(x_train.shape)
9190
print(y_train.min(), y_train.max())

beginner_source/transformer_tutorial.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@
4545
#
4646

4747
import math
48+
4849
import torch
4950
import torch.nn as nn
5051
import torch.nn.functional as F
52+
from torch.nn import TransformerEncoder, TransformerEncoderLayer
5153

5254
class TransformerModel(nn.Module):
5355

5456
def __init__(self, ntoken, ninp, nhead, nhid, nlayers, dropout=0.5):
5557
super(TransformerModel, self).__init__()
56-
from torch.nn import TransformerEncoder, TransformerEncoderLayer
5758
self.model_type = 'Transformer'
5859
self.pos_encoder = PositionalEncoding(ninp, dropout)
5960
encoder_layers = TransformerEncoderLayer(ninp, nhead, nhid, dropout)
@@ -251,12 +252,13 @@ def get_batch(source, i):
251252
# function to scale all the gradient together to prevent exploding.
252253
#
253254

255+
import time
256+
254257
criterion = nn.CrossEntropyLoss()
255258
lr = 5.0 # learning rate
256259
optimizer = torch.optim.SGD(model.parameters(), lr=lr)
257260
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, 1.0, gamma=0.95)
258261

259-
import time
260262
def train():
261263
model.train() # Turn on the train mode
262264
total_loss = 0.

conf.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@
5555
# Add any Sphinx extension module names here, as strings. They can be
5656
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
5757
# ones.
58-
extensions = ['sphinx.ext.mathjax', 'sphinx_copybutton',
59-
'sphinx_gallery.gen_gallery']
58+
extensions = [
59+
'sphinxcontrib.katex',
60+
'sphinx_copybutton',
61+
'sphinx_gallery.gen_gallery',
62+
]
6063

6164

6265
# -- Sphinx-gallery configuration --------------------------------------------
@@ -242,6 +245,18 @@
242245

243246

244247
def setup(app):
248+
# NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value
249+
# and can be moved outside of this function (and the setup(app) function
250+
# can be deleted).
251+
html_css_files = [
252+
'https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css'
253+
]
254+
# In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
255+
# `add_stylesheet` (deprecated in 1.8).
256+
add_css = getattr(app, 'add_css_file', app.add_stylesheet)
257+
for css_file in html_css_files:
258+
add_css(css_file)
259+
245260
# Custom CSS
246261
# app.add_stylesheet('css/pytorch_theme.css')
247262
# app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato')

index.rst

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Welcome to PyTorch Tutorials
132132
:header: Speech Command Recognition
133133
:card_description: Learn how to correctly format an audio dataset and then train/test an audio classifier network on the dataset.
134134
:image: _static/img/thumbnails/cropped/torchaudio-speech.png
135-
:link: intermediate/speech_command_recognition_with_torchaudio.html
135+
:link: intermediate/speech_command_recognition_with_torchaudio_tutorial.html
136136
:tags: Audio
137137

138138
.. Text
@@ -497,14 +497,19 @@ Additional Resources
497497
:header: PyTorch Cheat Sheet
498498
:description: Quick overview to essential PyTorch elements.
499499
:button_link: beginner/ptcheat.html
500-
:button_text: Download
500+
:button_text: Open
501501

502502
.. customcalloutitem::
503503
:header: Tutorials on GitHub
504504
:description: Access PyTorch Tutorials from GitHub.
505505
:button_link: https://github.com/pytorch/tutorials
506506
:button_text: Go To GitHub
507507

508+
.. customcalloutitem::
509+
:header: Run Tutorials on Google Colab
510+
:description: Learn how to copy tutorial data into Google Drive so that you can run tutorials on Google Colab.
511+
:button_link: beginner/colab.html
512+
:button_text: Open
508513

509514
.. End of callout section
510515
@@ -531,9 +536,24 @@ Additional Resources
531536
:maxdepth: 2
532537
:hidden:
533538
:includehidden:
534-
:caption: Learning PyTorch
539+
:caption: Introduction to PyTorch
535540

536541
beginner/basics/intro
542+
beginner/basics/quickstart_tutorial
543+
beginner/basics/tensorqs_tutorial
544+
beginner/basics/data_tutorial
545+
beginner/basics/transforms_tutorial
546+
beginner/basics/buildmodel_tutorial
547+
beginner/basics/autogradqs_tutorial
548+
beginner/basics/optimization_tutorial
549+
beginner/basics/saveloadrun_tutorial
550+
551+
.. toctree::
552+
:maxdepth: 2
553+
:hidden:
554+
:includehidden:
555+
:caption: Learning PyTorch
556+
537557
beginner/deep_learning_60min_blitz
538558
beginner/pytorch_with_examples
539559
beginner/nn_tutorial
@@ -558,8 +578,7 @@ Additional Resources
558578
:caption: Audio
559579

560580
beginner/audio_preprocessing_tutorial
561-
intermediate/speech_command_recognition_with_torchaudio
562-
581+
intermediate/speech_command_recognition_with_torchaudio_tutorial
563582

564583
.. toctree::
565584
:maxdepth: 2

intermediate_source/dist_tuto.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ Setup
2424
The distributed package included in PyTorch (i.e.,
2525
``torch.distributed``) enables researchers and practitioners to easily
2626
parallelize their computations across processes and clusters of
27-
machines. To do so, it leverages messaging passing semantics
27+
machines. To do so, it leverages message passing semantics
2828
allowing each process to communicate data to any of the other processes.
2929
As opposed to the multiprocessing (``torch.multiprocessing``) package,
3030
processes can use different communication backends and are not
3131
restricted to being executed on the same machine.
3232

3333
In order to get started we need the ability to run multiple processes
3434
simultaneously. If you have access to compute cluster you should check
35-
with your local sysadmin or use your favorite coordination tool. (e.g.,
35+
with your local sysadmin or use your favorite coordination tool (e.g.,
3636
`pdsh <https://linux.die.net/man/1/pdsh>`__,
3737
`clustershell <https://cea-hpc.github.io/clustershell/>`__, or
38-
`others <https://slurm.schedmd.com/>`__) For the purpose of this
38+
`others <https://slurm.schedmd.com/>`__). For the purpose of this
3939
tutorial, we will use a single machine and fork multiple processes using
4040
the following template.
4141

0 commit comments

Comments
 (0)