Skip to content

Commit 7b9d39f

Browse files
committed
Automated tutorials push
1 parent b65376e commit 7b9d39f

File tree

208 files changed

+16312
-13354
lines changed

Some content is hidden

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

208 files changed

+16312
-13354
lines changed

_downloads/0184bded18578d24a48fdfad2c701b09/polynomial_autograd.ipynb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@
4242
"import torch\n",
4343
"import math\n",
4444
"\n",
45+
"# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`__\n",
46+
"# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.\n",
47+
"\n",
4548
"dtype = torch.float\n",
46-
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
49+
"device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else \"cpu\"\n",
50+
"print(f\"Using {device} device\")\n",
4751
"torch.set_default_device(device)\n",
4852
"\n",
4953
"# Create Tensors to hold input and outputs.\n",

_downloads/377bf4a7b1761e5f081e057385870d8e/fgsm_tutorial.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,9 @@
125125
# `pytorch/examples/mnist <https://github.com/pytorch/examples/tree/master/mnist>`__.
126126
# For simplicity, download the pretrained model `here <https://drive.google.com/file/d/1HJV2nUHJqclXQ8flKvcWmjZ-OU5DGatl/view?usp=drive_link>`__.
127127
#
128-
# - ``use_cuda`` - boolean flag to use CUDA if desired and available.
129-
# Note, a GPU with CUDA is not critical for this tutorial as a CPU will
130-
# not take much time.
131-
#
132128

133129
epsilons = [0, .05, .1, .15, .2, .25, .3]
134130
pretrained_model = "data/lenet_mnist_model.pth"
135-
use_cuda=True
136131
# Set random seed for reproducibility
137132
torch.manual_seed(42)
138133

@@ -184,9 +179,10 @@ def forward(self, x):
184179
])),
185180
batch_size=1, shuffle=True)
186181

187-
# Define what device we are using
188-
print("CUDA Available: ",torch.cuda.is_available())
189-
device = torch.device("cuda" if use_cuda and torch.cuda.is_available() else "cpu")
182+
# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`__
183+
# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.
184+
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu"
185+
print(f"Using {device} device")
190186

191187
# Initialize the network
192188
model = Net().to(device)

_downloads/56c122e1c18e5e07666673e900acaed5/fgsm_tutorial.ipynb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@
149149
" trained with\n",
150150
" [pytorch/examples/mnist](https://github.com/pytorch/examples/tree/master/mnist).\n",
151151
" For simplicity, download the pretrained model\n",
152-
" [here](https://drive.google.com/file/d/1HJV2nUHJqclXQ8flKvcWmjZ-OU5DGatl/view?usp=drive_link).\n",
153-
"- `use_cuda` - boolean flag to use CUDA if desired and available.\n",
154-
" Note, a GPU with CUDA is not critical for this tutorial as a CPU\n",
155-
" will not take much time.\n"
152+
" [here](https://drive.google.com/file/d/1HJV2nUHJqclXQ8flKvcWmjZ-OU5DGatl/view?usp=drive_link).\n"
156153
]
157154
},
158155
{
@@ -165,7 +162,6 @@
165162
"source": [
166163
"epsilons = [0, .05, .1, .15, .2, .25, .3]\n",
167164
"pretrained_model = \"data/lenet_mnist_model.pth\"\n",
168-
"use_cuda=True\n",
169165
"# Set random seed for reproducibility\n",
170166
"torch.manual_seed(42)"
171167
]
@@ -228,9 +224,10 @@
228224
" ])),\n",
229225
" batch_size=1, shuffle=True)\n",
230226
"\n",
231-
"# Define what device we are using\n",
232-
"print(\"CUDA Available: \",torch.cuda.is_available())\n",
233-
"device = torch.device(\"cuda\" if use_cuda and torch.cuda.is_available() else \"cpu\")\n",
227+
"# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`__\n",
228+
"# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.\n",
229+
"device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else \"cpu\"\n",
230+
"print(f\"Using {device} device\")\n",
234231
"\n",
235232
"# Initialize the network\n",
236233
"model = Net().to(device)\n",

_downloads/74249e7f9f1f398f57ccd094a4f3021b/transfer_learning_tutorial.ipynb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@
133133
"dataset_sizes = {x: len(image_datasets[x]) for x in ['train', 'val']}\n",
134134
"class_names = image_datasets['train'].classes\n",
135135
"\n",
136-
"device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")"
136+
"# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`__\n",
137+
"# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.\n",
138+
"\n",
139+
"device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else \"cpu\"\n",
140+
"print(f\"Using {device} device\")"
137141
]
138142
},
139143
{

_downloads/a74022a3afc7f1a190f572b6b9e883e4/polynomial_autograd.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
import torch
1818
import math
1919

20+
# We want to be able to train our model on an `accelerator <https://pytorch.org/docs/stable/torch.html#accelerators>`__
21+
# such as CUDA, MPS, MTIA, or XPU. If the current accelerator is available, we will use it. Otherwise, we use the CPU.
22+
2023
dtype = torch.float
21-
device = "cuda" if torch.cuda.is_available() else "cpu"
24+
device = torch.accelerator.current_accelerator().type if torch.accelerator.is_available() else "cpu"
25+
print(f"Using {device} device")
2226
torch.set_default_device(device)
2327

2428
# Create Tensors to hold input and outputs.

0 commit comments

Comments
 (0)