Skip to content

Commit c00977d

Browse files
committed
Add XPU support to torchvision_tutorial.py
1 parent af73618 commit c00977d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

intermediate_source/torchvision_tutorial.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,14 @@ def get_transform(train):
406406

407407

408408
######################################################################
409-
# Let’s now write the main function which performs the training and the
410-
# validation:
409+
# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`_
410+
# such as CUDA, MPS, MTIA, or XPU. Let’s now write the main function which performs the training and the validation:
411411

412412

413413
from engine import train_one_epoch, evaluate
414414

415-
# train on the GPU or on the CPU, if a GPU is not available
416-
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
415+
# train on the accelerator or on the CPU, if an accelerator is not available
416+
device = torch.accelerator.current_accelerator() if torch.accelerator.is_available() else torch.device('cpu')
417417

418418
# our dataset has two classes only - background and person
419419
num_classes = 2

0 commit comments

Comments
 (0)