From dde7670fead52f16cf08c40260c824206ec0f02b Mon Sep 17 00:00:00 2001 From: "Yu, Guangye" Date: Mon, 25 Nov 2024 13:36:55 +0000 Subject: [PATCH 1/3] refine build model tutorial by accelerator api --- beginner_source/basics/buildmodel_tutorial.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/beginner_source/basics/buildmodel_tutorial.py b/beginner_source/basics/buildmodel_tutorial.py index 987bc7c44a2..4476cfa9240 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 ` +# like 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") ############################################## From 617ff9f6a0ebd816723fa022bc59540d11461e41 Mon Sep 17 00:00:00 2001 From: "Yu, Guangye" <106960996+guangyey@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:36:35 +0800 Subject: [PATCH 2/3] Update beginner_source/basics/buildmodel_tutorial.py Co-authored-by: Svetlana Karslioglu --- beginner_source/basics/buildmodel_tutorial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beginner_source/basics/buildmodel_tutorial.py b/beginner_source/basics/buildmodel_tutorial.py index 4476cfa9240..1ba0cb9e86d 100644 --- a/beginner_source/basics/buildmodel_tutorial.py +++ b/beginner_source/basics/buildmodel_tutorial.py @@ -33,7 +33,7 @@ # Get Device for Training # ----------------------- # We want to be able to train our model on an `accelerator ` -# like CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it, otherwise we use the CPU. +# 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") From e57d5f286d833d75602b0fe6e3c8ec9e0cd263fd Mon Sep 17 00:00:00 2001 From: "Yu, Guangye" <106960996+guangyey@users.noreply.github.com> Date: Tue, 26 Nov 2024 09:37:52 +0800 Subject: [PATCH 3/3] Update beginner_source/basics/buildmodel_tutorial.py Co-authored-by: Svetlana Karslioglu --- beginner_source/basics/buildmodel_tutorial.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beginner_source/basics/buildmodel_tutorial.py b/beginner_source/basics/buildmodel_tutorial.py index 1ba0cb9e86d..1806e80feb5 100644 --- a/beginner_source/basics/buildmodel_tutorial.py +++ b/beginner_source/basics/buildmodel_tutorial.py @@ -32,7 +32,7 @@ ############################################# # Get Device for Training # ----------------------- -# We want to be able to train our model on an `accelerator ` +# 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"