Skip to content

Commit 5be438b

Browse files
authored
Merge branch 'main' into spellcheck-addons
2 parents 136ca22 + 5974b5c commit 5be438b

File tree

9 files changed

+32
-21
lines changed

9 files changed

+32
-21
lines changed

beginner_source/basics/buildmodel_tutorial.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@
3232
#############################################
3333
# Get Device for Training
3434
# -----------------------
35-
# We want to be able to train our model on a hardware accelerator like the GPU,
36-
# if it is available. Let's check to see if
37-
# `torch.cuda <https://pytorch.org/docs/stable/notes/cuda.html>`_ is available, else we
38-
# continue to use the CPU.
39-
40-
device = "cuda" if torch.cuda.is_available() else "cpu"
35+
# We want to be able to train our model on a hardware accelerator like the GPU or MPS,
36+
# if available. Let's check to see if `torch.cuda <https://pytorch.org/docs/stable/notes/cuda.html>`_
37+
# or `torch.backends.mps <https://pytorch.org/docs/stable/notes/mps.html>`_ are available, otherwise we use the CPU.
38+
39+
device = (
40+
"cuda"
41+
if torch.cuda.is_available()
42+
else "mps"
43+
if torch.backends.mps.is_available()
44+
else "cpu"
45+
)
4146
print(f"Using {device} device")
4247

4348
##############################################

beginner_source/basics/quickstart_tutorial.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,16 @@
8484
# To define a neural network in PyTorch, we create a class that inherits
8585
# from `nn.Module <https://pytorch.org/docs/stable/generated/torch.nn.Module.html>`_. We define the layers of the network
8686
# in the ``__init__`` function and specify how data will pass through the network in the ``forward`` function. To accelerate
87-
# operations in the neural network, we move it to the GPU if available.
88-
89-
# Get cpu or gpu device for training.
90-
device = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu"
87+
# operations in the neural network, we move it to the GPU or MPS if available.
88+
89+
# Get cpu, gpu or mps device for training.
90+
device = (
91+
"cuda"
92+
if torch.cuda.is_available()
93+
else "mps"
94+
if torch.backends.mps.is_available()
95+
else "cpu"
96+
)
9197
print(f"Using {device} device")
9298

9399
# Define model

beginner_source/basics/saveloadrun_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
# state dictionary, called ``state_dict``. These can be persisted via the ``torch.save``
2727
# method:
2828

29-
model = models.vgg16(pretrained=True)
29+
model = models.vgg16(weights='IMAGENET1K_V1')
3030
torch.save(model.state_dict(), 'model_weights.pth')
3131

3232
##########################
3333
# To load model weights, you need to create an instance of the same model first, and then load the parameters
3434
# using ``load_state_dict()`` method.
3535

36-
model = models.vgg16() # we do not specify pretrained=True, i.e. do not load default weights
36+
model = models.vgg16() # we do not specify weights, i.e. create untrained model
3737
model.load_state_dict(torch.load('model_weights.pth'))
3838
model.eval()
3939

beginner_source/dcgan_faces_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def forward(self, input):
459459
# With :math:`D` and :math:`G` setup, we can specify how they learn
460460
# through the loss functions and optimizers. We will use the Binary Cross
461461
# Entropy loss
462-
# (`BCELoss <https://pytorch.org/docs/stable/nn.html#torch.nn.BCELoss>`__)
462+
# (`BCELoss <https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html#torch.nn.BCELoss>`__)
463463
# function which is defined in PyTorch as:
464464
#
465465
# .. math:: \ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad l_n = - \left[ y_n \cdot \log x_n + (1 - y_n) \cdot \log (1 - x_n) \right]

beginner_source/introyt/captumyt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
# now.
156156
#
157157

158-
model = models.resnet101(pretrained=True)
158+
model = models.resnet101(weights='IMAGENET1K_V1')
159159
model = model.eval()
160160

161161

beginner_source/transfer_learning_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def visualize_model(model, num_images=6):
250250
# Load a pretrained model and reset final fully connected layer.
251251
#
252252

253-
model_ft = models.resnet18(pretrained=True)
253+
model_ft = models.resnet18(weights='IMAGENET1K_V1')
254254
num_ftrs = model_ft.fc.in_features
255255
# Here the size of each output sample is set to 2.
256256
# Alternatively, it can be generalized to ``nn.Linear(num_ftrs, len(class_names))``.
@@ -295,7 +295,7 @@ def visualize_model(model, num_images=6):
295295
# `here <https://pytorch.org/docs/notes/autograd.html#excluding-subgraphs-from-backward>`__.
296296
#
297297

298-
model_conv = torchvision.models.resnet18(pretrained=True)
298+
model_conv = torchvision.models.resnet18(weights='IMAGENET1K_V1')
299299
for param in model_conv.parameters():
300300
param.requires_grad = False
301301

intermediate_source/FSDP_tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ We add the following code snippets to a python script “FSDP_mnist.py”.
249249
250250
if args.save_model:
251251
# use a barrier to make sure training is done on all ranks
252-
dist_barrier()
252+
dist.barrier()
253253
# state_dict for FSDP model is only available on Nightlies for now
254254
states = model.state_dict()
255255
if rank == 0:

intermediate_source/flask_rest_api_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def transform_image(image_bytes):
161161

162162
from torchvision import models
163163

164-
# Make sure to pass `pretrained` as `True` to use the pretrained weights:
165-
model = models.densenet121(pretrained=True)
164+
# Make sure to set `weights` as `'IMAGENET1K_V1'` to use the pretrained weights:
165+
model = models.densenet121(weights='IMAGENET1K_V1')
166166
# Since we are using our model only for inference, switch to `eval` mode:
167167
model.eval()
168168

@@ -269,7 +269,7 @@ def get_prediction(image_bytes):
269269
#
270270
# app = Flask(__name__)
271271
# imagenet_class_index = json.load(open('<PATH/TO/.json/FILE>/imagenet_class_index.json'))
272-
# model = models.densenet121(pretrained=True)
272+
# model = models.densenet121(weights='IMAGENET1K_V1')
273273
# model.eval()
274274
#
275275
#

intermediate_source/tensorboard_profiler_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
# To run on GPU, move model and loss to GPU device.
6969

7070
device = torch.device("cuda:0")
71-
model = torchvision.models.resnet18(pretrained=True).cuda(device)
71+
model = torchvision.models.resnet18(weights='IMAGENET1K_V1').cuda(device)
7272
criterion = torch.nn.CrossEntropyLoss().cuda(device)
7373
optimizer = torch.optim.SGD(model.parameters(), lr=0.001, momentum=0.9)
7474
model.train()

0 commit comments

Comments
 (0)