Skip to content

Commit b422272

Browse files
authored
Merge branch 'main' into fix/3855-deprecated-inplace-ops
2 parents 1efcd62 + 03706c5 commit b422272

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

beginner_source/blitz/neural_networks_tutorial.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
class Net(nn.Module):
4646

4747
def __init__(self):
48-
super(Net, self).__init__()
48+
super().__init__()
4949
# 1 input image channel, 6 output channels, 5x5 square convolution
5050
# kernel
5151
self.conv1 = nn.Conv2d(1, 6, 5)
5252
self.conv2 = nn.Conv2d(6, 16, 5)
5353
# an affine operation: y = Wx + b
54-
self.fc1 = nn.Linear(16 * 5 * 5, 120) # 5*5 from image dimension
54+
self.fc1 = nn.Linear(16 * 5 * 5, 120) # 5*5 from image dimension
5555
self.fc2 = nn.Linear(120, 84)
5656
self.fc3 = nn.Linear(84, 10)
5757

@@ -205,7 +205,9 @@ def forward(self, input):
205205
#
206206
#
207207
# Now we shall call ``loss.backward()``, and have a look at conv1's bias
208-
# gradients before and after the backward.
208+
# gradients before and after the backward. Since we have not introduced an
209+
# optimizer yet, we clear the gradients directly on the model. Once using an
210+
# optimizer, prefer ``optimizer.zero_grad()`` as shown below.
209211

210212

211213
net.zero_grad() # zeroes the gradient buffers of all parameters
@@ -246,7 +248,8 @@ def forward(self, input):
246248
#
247249
# learning_rate = 0.01
248250
# for f in net.parameters():
249-
# f.data.sub_(f.grad.data * learning_rate)
251+
# with torch.no_grad():
252+
# f -= f.grad * learning_rate
250253
#
251254
# However, as you use neural networks, you want to use various different
252255
# update rules such as SGD, Nesterov-SGD, Adam, RMSProp, etc.

compilers_index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ control, as well as third-party backend solutions.
166166
:header: Building a Convolution/Batch Norm fuser in FX
167167
:card_description: Build a simple FX pass that fuses batch norm into convolution to improve performance during inference.
168168
:image: _static/img/thumbnails/cropped/Deploying-PyTorch-in-Python-via-a-REST-API-with-Flask.png
169-
:link: intermediate/torch_compile_conv_bn_fuser
169+
:link: intermediate/torch_compile_conv_bn_fuser.html
170170
:tags: FX
171171

172172
.. customcarditem::

0 commit comments

Comments
 (0)