Skip to content

Commit fb7a0f6

Browse files
authored
Merge branch 'pytorch:main' into issue#1757
2 parents 8800ec5 + 0bee138 commit fb7a0f6

12 files changed

+31
-21
lines changed

Diff for: advanced_source/neural_style_tutorial.py

+3
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ def run_style_transfer(cnn, normalization_mean, normalization_std,
423423
# We want to optimize the input and not the model parameters so we
424424
# update all the requires_grad fields accordingly
425425
input_img.requires_grad_(True)
426+
# We also put the model in evaluation mode, so that specific layers
427+
# such as dropout or batch normalization layers behave correctly.
428+
model.eval()
426429
model.requires_grad_(False)
427430

428431
optimizer = get_input_optimizer(input_img)

Diff for: advanced_source/super_resolution_with_onnxruntime.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
and `ONNX Runtime <https://github.com/microsoft/onnxruntime>`__.
1717
You can get binary builds of ONNX and ONNX Runtime with
1818
``pip install onnx onnxruntime``.
19-
Note that ONNX Runtime is compatible with Python versions 3.5 to 3.7.
20-
21-
``NOTE``: This tutorial needs PyTorch master branch which can be installed by following
22-
the instructions `here <https://github.com/pytorch/pytorch#from-source>`__
19+
ONNX Runtime recommends using the latest stable runtime for PyTorch.
2320
2421
"""
2522

Diff for: beginner_source/README.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Beginner Tutorials
2323

2424
6. transformer_translation.py
2525
Language Translation with Transformers
26-
https://pytorch.org/tutorials/beginner/transformer_tutorial.html
26+
https://pytorch.org/tutorials/beginner/translation_transformer.html

Diff for: beginner_source/deep_learning_60min_blitz.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ Goal of this tutorial:
2020
- Understand PyTorch’s Tensor library and neural networks at a high level.
2121
- Train a small neural network to classify images
2222

23-
To run the tutorials below, make sure you have the `torch`_ and `torchvision`_
24-
packages installed.
23+
To run the tutorials below, make sure you have the `torch`_, `torchvision`_,
24+
and `matplotlib`_ packages installed.
2525

2626
.. _torch: https://github.com/pytorch/pytorch
2727
.. _torchvision: https://github.com/pytorch/vision
28+
.. _matplotlib: https://github.com/matplotlib/matplotlib
2829

2930
.. toctree::
3031
:hidden:

Diff for: beginner_source/introyt/trainingyt.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -290,15 +290,19 @@ def train_one_epoch(epoch_index, tb_writer):
290290
model.train(True)
291291
avg_loss = train_one_epoch(epoch_number, writer)
292292

293-
# We don't need gradients on to do reporting
294-
model.train(False)
295-
293+
296294
running_vloss = 0.0
297-
for i, vdata in enumerate(validation_loader):
298-
vinputs, vlabels = vdata
299-
voutputs = model(vinputs)
300-
vloss = loss_fn(voutputs, vlabels)
301-
running_vloss += vloss
295+
# Set the model to evaluation mode, disabling dropout and using population
296+
# statistics for batch normalization.
297+
model.eval()
298+
299+
# Disable gradient computation and reduce memory consumption.
300+
with torch.no_grad():
301+
for i, vdata in enumerate(validation_loader):
302+
vinputs, vlabels = vdata
303+
voutputs = model(vinputs)
304+
vloss = loss_fn(voutputs, vlabels)
305+
running_vloss += vloss
302306

303307
avg_vloss = running_vloss / (i + 1)
304308
print('LOSS train {} valid {}'.format(avg_loss, avg_vloss))

Diff for: beginner_source/nn_tutorial.py

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@
7575
import numpy as np
7676

7777
pyplot.imshow(x_train[0].reshape((28, 28)), cmap="gray")
78+
# ``pyplot.show()`` only if not on Colab
79+
try:
80+
import google.colab
81+
except ImportError:
82+
pyplot.show()
7883
print(x_train.shape)
7984

8085
###############################################################################

Diff for: beginner_source/transformer_tutorial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# ``nn.TransformerEncoder`` consists of multiple layers of
3838
# `nn.TransformerEncoderLayer <https://pytorch.org/docs/stable/generated/torch.nn.TransformerEncoderLayer.html>`__.
3939
# Along with the input sequence, a square attention mask is required because the
40-
# self-attention layers in ``nn.TransformerEncoder`` are only allowed to attend
40+
# self-attention layers in ``nn.TransformerDecoder`` are only allowed to attend
4141
# the earlier positions in the sequence. For the language modeling task, any
4242
# tokens on the future positions should be masked. To produce a probability
4343
# distribution over output words, the output of the ``nn.TransformerEncoder``

Diff for: intermediate_source/char_rnn_classification_tutorial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
NLP From Scratch: Classifying Names with a Character-Level RNN
44
**************************************************************
5-
**Author**: `Sean Robertson <https://github.com/spro/practical-pytorch>`_
5+
**Author**: `Sean Robertson <https://github.com/spro>`_
66
77
We will be building and training a basic character-level RNN to classify
88
words. This tutorial, along with the following two, show how to do

Diff for: intermediate_source/char_rnn_generation_tutorial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
NLP From Scratch: Generating Names with a Character-Level RNN
44
*************************************************************
5-
**Author**: `Sean Robertson <https://github.com/spro/practical-pytorch>`_
5+
**Author**: `Sean Robertson <https://github.com/spro>`_
66
77
This is our second of three tutorials on "NLP From Scratch".
88
In the `first tutorial </intermediate/char_rnn_classification_tutorial>`

Diff for: intermediate_source/dynamic_quantization_bert_tutorial.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ built-in F1 score calculation helper function.
6868
.. code:: shell
6969
7070
pip install sklearn
71-
pip install transformers
71+
pip install transformers==4.29.2
7272
7373
7474
Because we will be using the beta parts of the PyTorch, it is

Diff for: intermediate_source/seq2seq_translation_tutorial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
NLP From Scratch: Translation with a Sequence to Sequence Network and Attention
44
*******************************************************************************
5-
**Author**: `Sean Robertson <https://github.com/spro/practical-pytorch>`_
5+
**Author**: `Sean Robertson <https://github.com/spro>`_
66
77
This is the third and final tutorial on doing "NLP From Scratch", where we
88
write our own classes and functions to preprocess the data to do our NLP

Diff for: intermediate_source/torchvision_tutorial.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Let’s write a ``torch.utils.data.Dataset`` class for this dataset.
145145
num_objs = len(obj_ids)
146146
boxes = []
147147
for i in range(num_objs):
148-
pos = np.where(masks[i])
148+
pos = np.nonzero(masks[i])
149149
xmin = np.min(pos[1])
150150
xmax = np.max(pos[1])
151151
ymin = np.min(pos[0])

0 commit comments

Comments
 (0)