Skip to content

Commit 4fca534

Browse files
authored
Merge branch 'master' into update_profiler_tutorial
2 parents e303fa6 + 1056a2f commit 4fca534

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

beginner_source/basics/optimization_tutorial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def train_loop(dataloader, model, loss_fn, optimizer):
167167

168168
def test_loop(dataloader, model, loss_fn):
169169
size = len(dataloader.dataset)
170+
num_batches = len(dataloader)
170171
test_loss, correct = 0, 0
171172

172173
with torch.no_grad():
@@ -175,7 +176,7 @@ def test_loop(dataloader, model, loss_fn):
175176
test_loss += loss_fn(pred, y).item()
176177
correct += (pred.argmax(1) == y).type(torch.float).sum().item()
177178

178-
test_loss /= size
179+
test_loss /= num_batches
179180
correct /= size
180181
print(f"Test Error: \n Accuracy: {(100*correct):>0.1f}%, Avg loss: {test_loss:>8f} \n")
181182

beginner_source/basics/quickstart_tutorial.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ def train(dataloader, model, loss_fn, optimizer):
158158
##############################################################################
159159
# We also check the model's performance against the test dataset to ensure it is learning.
160160

161-
def test(dataloader, model):
161+
def test(dataloader, model, loss_fn):
162162
size = len(dataloader.dataset)
163+
num_batches = len(dataloader)
163164
model.eval()
164165
test_loss, correct = 0, 0
165166
with torch.no_grad():
@@ -168,7 +169,7 @@ def test(dataloader, model):
168169
pred = model(X)
169170
test_loss += loss_fn(pred, y).item()
170171
correct += (pred.argmax(1) == y).type(torch.float).sum().item()
171-
test_loss /= size
172+
test_loss /= num_batches
172173
correct /= size
173174
print(f"Test Error: \n Accuracy: {(100*correct):>0.1f}%, Avg loss: {test_loss:>8f} \n")
174175

@@ -181,7 +182,7 @@ def test(dataloader, model):
181182
for t in range(epochs):
182183
print(f"Epoch {t+1}\n-------------------------------")
183184
train(train_dataloader, model, loss_fn, optimizer)
184-
test(test_dataloader, model)
185+
test(test_dataloader, model, loss_fn)
185186
print("Done!")
186187

187188
######################################################################

beginner_source/basics/transforms_tutorial.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
To make these transformations, we use ``ToTensor`` and ``Lambda``.
2727
"""
2828

29+
import torch
2930
from torchvision import datasets
3031
from torchvision.transforms import ToTensor, Lambda
3132

intermediate_source/char_rnn_generation_tutorial.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ def unicodeToAscii(s):
9797

9898
# Read a file and split into lines
9999
def readLines(filename):
100-
lines = open(filename, encoding='utf-8').read().strip().split('\n')
101-
return [unicodeToAscii(line) for line in lines]
100+
with open(filename, encoding='utf-8') as some_file:
101+
return [unicodeToAscii(line.strip()) for line in some_file]
102102

103103
# Build the category_lines dictionary, a list of lines per category
104104
category_lines = {}
@@ -347,7 +347,6 @@ def timeSince(since):
347347
#
348348

349349
import matplotlib.pyplot as plt
350-
import matplotlib.ticker as ticker
351350

352351
plt.figure()
353352
plt.plot(all_losses)

intermediate_source/dist_tuto.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ of 6 collectives currently implemented in PyTorch.
233233
``tensor`` and stores the result in ``dst``.
234234
- ``dist.all_reduce(tensor, op, group)``: Same as reduce, but the
235235
result is stored in all processes.
236-
- ``dist.scatter(tensor, src, scatter_list, group)``: Copies the
236+
- ``dist.scatter(tensor, scatter_list, src, group)``: Copies the
237237
:math:`i^{\text{th}}` tensor ``scatter_list[i]`` to the
238238
:math:`i^{\text{th}}` process.
239-
- ``dist.gather(tensor, dst, gather_list, group)``: Copies ``tensor``
239+
- ``dist.gather(tensor, gather_list, dst, group)``: Copies ``tensor``
240240
from all processes in ``dst``.
241241
- ``dist.all_gather(tensor_list, tensor, group)``: Copies ``tensor``
242242
from all processes to ``tensor_list``, on all processes.

recipes_source/recipes/dynamic_quantization.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ def print_size_of_model(model, label=""):
220220
q=print_size_of_model(quantized_lstm,"int8")
221221
print("{0:.2f} times smaller".format(f/q))
222222

223-
# note that this value is wrong in PyTorch 1.4 due to https://github.com/pytorch/pytorch/issues/31468
224-
# this will be fixed in 1.5 with https://github.com/pytorch/pytorch/pull/31540
225-
226223

227224
######################################################################
228225
# 4. Look at Latency

0 commit comments

Comments
 (0)