Skip to content

Commit a3b1243

Browse files
authored
Merge branch 'main' into svekars-patch-65
2 parents 7f8fb48 + 6fdd8b1 commit a3b1243

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

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)

0 commit comments

Comments
 (0)