Skip to content

Commit 09ef4a3

Browse files
authored
Merge branch 'main' into issues-3859
2 parents 483da6b + 36f3ca7 commit 09ef4a3

7 files changed

Lines changed: 18 additions & 14 deletions

File tree

.ci/docker/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pydantic>=2.10
2525
fastapi
2626
matplotlib
2727
librosa
28-
torch==2.11
28+
torch==2.12
2929
torchvision
3030
torchdata
3131
networkx

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.

beginner_source/blitz/tensor_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@
105105
#
106106

107107
# We move our tensor to the GPU if available
108-
if torch.cuda.is_available():
109-
tensor = tensor.to('cuda')
110-
print(f"Device tensor is stored on: {tensor.device}")
108+
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else 'cpu'
109+
tensor = tensor.to(device)
110+
print(f"Device tensor is stored on: {tensor.device}")
111111

112112

113113
######################################################################

beginner_source/ddp_series_multigpu.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ Running the distributed training job
202202
Here's what the code looks like:
203203

204204
.. code-block:: python
205+
205206
def main(rank, world_size, total_epochs, save_every):
206207
ddp_setup(rank, world_size)
207208
dataset, model, optimizer = load_train_objs()
@@ -218,7 +219,6 @@ Here's what the code looks like:
218219
mp.spawn(main, args=(world_size, total_epochs, save_every,), nprocs=world_size)
219220
220221
221-
222222
Further Reading
223223
---------------
224224

beginner_source/introyt/modelsyt_tutorial.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ class is a subclass of ``torch.Tensor``, with the special behavior that
4848
class TinyModel(torch.nn.Module):
4949

5050
def __init__(self):
51-
super(TinyModel, self).__init__()
51+
super().__init__()
5252

5353
self.linear1 = torch.nn.Linear(100, 200)
5454
self.activation = torch.nn.ReLU()
5555
self.linear2 = torch.nn.Linear(200, 10)
56-
self.softmax = torch.nn.Softmax()
56+
self.softmax = torch.nn.Softmax(dim=1)
5757

5858
def forward(self, x):
5959
x = self.linear1(x)
@@ -150,7 +150,7 @@ def forward(self, x):
150150
class LeNet(torch.nn.Module):
151151

152152
def __init__(self):
153-
super(LeNet, self).__init__()
153+
super().__init__()
154154
# 1 input image channel (black & white), 6 output channels, 5x5 square convolution
155155
# kernel
156156
self.conv1 = torch.nn.Conv2d(1, 6, 5)
@@ -249,7 +249,7 @@ def num_flat_features(self, x):
249249
class LSTMTagger(torch.nn.Module):
250250

251251
def __init__(self, embedding_dim, hidden_dim, vocab_size, tagset_size):
252-
super(LSTMTagger, self).__init__()
252+
super().__init__()
253253
self.hidden_dim = hidden_dim
254254

255255
self.word_embeddings = torch.nn.Embedding(vocab_size, embedding_dim)

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::

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Welcome to PyTorch Tutorials
33

44
**What's new in PyTorch tutorials?**
55

6+
* `Data Loading Optimization in PyTorch <https://docs.pytorch.org/tutorials/intermediate/intermediate_data_loading_tutorial.html>`__
67
* `Distributed Training with Ray Train <https://docs.pytorch.org/tutorials/beginner/distributed_training_with_ray_tutorial.html>`__
78
* `Serve PyTorch models at scale with Ray Serve <https://docs.pytorch.org/tutorials/beginner/serving_tutorial.html>`__
89
* `Hyperparameter tuning using Ray Tune <https://docs.pytorch.org/tutorials/beginner/hyperparameter_tuning_tutorial.html>`__

0 commit comments

Comments
 (0)