diff --git a/beginner_source/basics/buildmodel_tutorial.py b/beginner_source/basics/buildmodel_tutorial.py index 987bc7c44a2..1806e80feb5 100644 --- a/beginner_source/basics/buildmodel_tutorial.py +++ b/beginner_source/basics/buildmodel_tutorial.py @@ -32,17 +32,10 @@ ############################################# # Get Device for Training # ----------------------- -# We want to be able to train our model on a hardware accelerator like the GPU or MPS, -# if available. Let's check to see if `torch.cuda `_ -# or `torch.backends.mps `_ are available, otherwise we use the CPU. - -device = ( - "cuda" - if torch.cuda.is_available() - else "mps" - if torch.backends.mps.is_available() - else "cpu" -) +# We want to be able to train our model on an `accelerator `__ +# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU. + +device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu" print(f"Using {device} device") ##############################################