Skip to content

Commit d00f58b

Browse files
committed
Automated tutorials push
1 parent 111e7f9 commit d00f58b

File tree

188 files changed

+10301
-11163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+10301
-11163
lines changed

_downloads/76d764ad694d0795e494a1edbfb068a6/buildmodel_tutorial.ipynb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@
6464
"Get Device for Training\n",
6565
"=======================\n",
6666
"\n",
67-
"We want to be able to train our model on a hardware accelerator like the\n",
68-
"GPU or MPS, if available. Let\\'s check to see if\n",
69-
"[torch.cuda](https://pytorch.org/docs/stable/notes/cuda.html) or\n",
70-
"[torch.backends.mps](https://pytorch.org/docs/stable/notes/mps.html) are\n",
71-
"available, otherwise we use the CPU.\n"
67+
"We want to be able to train our model on an\n",
68+
"[accelerator](https://pytorch.org/docs/stable/torch.html#accelerators)\n",
69+
"such as CUDA, MPS, MTIA, or XPU. If the current accelerator is\n",
70+
"available, we will use it. Otherwise, we use the CPU.\n"
7271
]
7372
},
7473
{
@@ -79,13 +78,7 @@
7978
},
8079
"outputs": [],
8180
"source": [
82-
"device = (\n",
83-
" \"cuda\"\n",
84-
" if torch.cuda.is_available()\n",
85-
" else \"mps\"\n",
86-
" if torch.backends.mps.is_available()\n",
87-
" else \"cpu\"\n",
88-
")\n",
81+
"device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else \"cpu\"\n",
8982
"print(f\"Using {device} device\")"
9083
]
9184
},

_downloads/ac800c8c4c9c372154788058b1e89246/buildmodel_tutorial.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,10 @@
3232
#############################################
3333
# Get Device for Training
3434
# -----------------------
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-
)
35+
# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`__
36+
# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.
37+
38+
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu"
4639
print(f"Using {device} device")
4740

4841
##############################################
-124 Bytes
Loading
-127 Bytes
Loading
276 Bytes
Loading
-4.5 KB
Loading
-419 Bytes
Loading
1.22 KB
Loading
15 Bytes
Loading
2.68 KB
Loading

0 commit comments

Comments
 (0)