Skip to content

Commit f20a78f

Browse files
phlippeBordapre-commit-ci[bot]awaelchli
authored
UvA DL Tutorials: Updating PL API to >1.8 (#222)
Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Adrian Wälchli <[email protected]> Co-authored-by: Jirka <[email protected]>
1 parent fbed9e5 commit f20a78f

File tree

22 files changed

+80
-58
lines changed

22 files changed

+80
-58
lines changed

course_UvA-DL/01-introduction-to-pytorch/.meta.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: "Tutorial 1: Introduction to PyTorch"
22
author: Phillip Lippe
33
created: 2021-08-27
4-
updated: 2021-11-29
4+
updated: 2023-01-04
55
license: CC BY-SA
66
description: |
77
This tutorial will give a short introduction to PyTorch basics, and get you setup for writing your own neural networks.

course_UvA-DL/01-introduction-to-pytorch/Introduction_to_PyTorch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@
455455

456456
# Additionally, some operations on a GPU are implemented stochastic for efficiency
457457
# We want to ensure that all operations are deterministic on GPU (if used) for reproducibility
458-
torch.backends.cudnn.determinstic = True
458+
torch.backends.cudnn.deterministic = True
459459
torch.backends.cudnn.benchmark = False
460460

461461
# %% [markdown]

course_UvA-DL/02-activation-functions/.meta.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: "Tutorial 2: Activation Functions"
22
author: Phillip Lippe
33
created: 2021-08-27
4-
updated: 2021-08-27
4+
updated: 2023-01-04
55
license: CC BY-SA
66
description: |
77
In this tutorial, we will take a closer look at (popular) activation functions and investigate their effect on optimization properties in neural networks.

course_UvA-DL/02-activation-functions/Activation_Functions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def set_seed(seed):
6464

6565
# Additionally, some operations on a GPU are implemented stochastic for efficiency
6666
# We want to ensure that all operations are deterministic on GPU (if used) for reproducibility
67-
torch.backends.cudnn.determinstic = True
67+
torch.backends.cudnn.deterministic = True
6868
torch.backends.cudnn.benchmark = False
6969

7070
# Fetching the device that will be used throughout this notebook

course_UvA-DL/03-initialization-and-optimization/.meta.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: "Tutorial 3: Initialization and Optimization"
22
author: Phillip Lippe
33
created: 2021-08-27
4-
updated: 2021-11-29
4+
updated: 2023-01-04
55
license: CC BY-SA
66
tags:
77
- Image

course_UvA-DL/03-initialization-and-optimization/Initialization_and_Optimization.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
pl.seed_everything(42)
4848

4949
# Ensure that all operations are deterministic on GPU (if used) for reproducibility
50-
torch.backends.cudnn.determinstic = True
50+
torch.backends.cudnn.deterministic = True
5151
torch.backends.cudnn.benchmark = False
5252

5353
# Fetching the device that will be used throughout this notebook
@@ -937,8 +937,8 @@ def pathological_curve_loss(w1, w2):
937937
def plot_curve(
938938
curve_fn, x_range=(-5, 5), y_range=(-5, 5), plot_3d=False, cmap=cm.viridis, title="Pathological curvature"
939939
):
940-
fig = plt.figure()
941-
ax = fig.gca(projection="3d") if plot_3d else fig.gca()
940+
_ = plt.figure()
941+
ax = plt.axes(projection="3d") if plot_3d else plt.axes()
942942

943943
x = torch.arange(x_range[0], x_range[1], (x_range[1] - x_range[0]) / 100.0)
944944
y = torch.arange(y_range[0], y_range[1], (y_range[1] - y_range[0]) / 100.0)

course_UvA-DL/04-inception-resnet-densenet/.meta.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: "Tutorial 4: Inception, ResNet and DenseNet"
22
author: Phillip Lippe
33
created: 2021-08-27
4-
updated: 2021-11-29
4+
updated: 2023-01-04
55
license: CC BY-SA
66
tags:
77
- Image
@@ -18,5 +18,6 @@ requirements:
1818
- matplotlib
1919
- seaborn
2020
- tabulate
21+
- pytorch-lightning>=1.8
2122
accelerator:
2223
- GPU

course_UvA-DL/04-inception-resnet-densenet/Inception_ResNet_DenseNet.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
pl.seed_everything(42)
5050

5151
# Ensure that all operations are deterministic on GPU (if used) for reproducibility
52-
torch.backends.cudnn.determinstic = True
52+
torch.backends.cudnn.deterministic = True
5353
torch.backends.cudnn.benchmark = False
5454

5555
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
@@ -348,7 +348,8 @@ def train_model(model_name, save_name=None, **kwargs):
348348
trainer = pl.Trainer(
349349
default_root_dir=os.path.join(CHECKPOINT_PATH, save_name), # Where to save models
350350
# We run on a single GPU (if possible)
351-
gpus=1 if str(device) == "cuda:0" else 0,
351+
accelerator="gpu" if str(device).startswith("cuda") else "cpu",
352+
devices=1,
352353
# How many epochs to train for if no patience is set
353354
max_epochs=180,
354355
callbacks=[
@@ -357,7 +358,7 @@ def train_model(model_name, save_name=None, **kwargs):
357358
), # Save the best checkpoint based on the maximum val_acc recorded. Saves only weights and not optimizer
358359
LearningRateMonitor("epoch"),
359360
], # Log learning rate every epoch
360-
progress_bar_refresh_rate=1,
361+
enable_progress_bar=True,
361362
) # In case your notebook crashes due to the progress bar, consider increasing the refresh rate
362363
trainer.logger._log_graph = True # If True, we plot the computation graph in tensorboard
363364
trainer.logger._default_hp_metric = None # Optional logging argument that we don't need

course_UvA-DL/05-transformers-and-MH-attention/.meta.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: "Tutorial 5: Transformers and Multi-Head Attention"
22
author: Phillip Lippe
33
created: 2021-06-30
4-
updated: 2021-11-29
4+
updated: 2023-01-04
55
license: CC BY-SA
66
build: 0
77
tags:
@@ -19,5 +19,6 @@ requirements:
1919
- torchvision
2020
- matplotlib
2121
- seaborn
22+
- pytorch-lightning>=1.8
2223
accelerator:
2324
- GPU

course_UvA-DL/05-transformers-and-MH-attention/Transformers_MHAttention.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
pl.seed_everything(42)
6262

6363
# Ensure that all operations are deterministic on GPU (if used) for reproducibility
64-
torch.backends.cudnn.determinstic = True
64+
torch.backends.cudnn.deterministic = True
6565
torch.backends.cudnn.benchmark = False
6666

6767
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
@@ -979,10 +979,11 @@ def train_reverse(**kwargs):
979979
trainer = pl.Trainer(
980980
default_root_dir=root_dir,
981981
callbacks=[ModelCheckpoint(save_weights_only=True, mode="max", monitor="val_acc")],
982-
gpus=1 if str(device).startswith("cuda") else 0,
982+
accelerator="gpu" if str(device).startswith("cuda") else "cpu",
983+
devices=1,
983984
max_epochs=10,
984985
gradient_clip_val=5,
985-
progress_bar_refresh_rate=1,
986+
enable_progress_bar=True,
986987
)
987988
trainer.logger._default_hp_metric = None # Optional logging argument that we don't need
988989

@@ -1439,10 +1440,11 @@ def train_anomaly(**kwargs):
14391440
trainer = pl.Trainer(
14401441
default_root_dir=root_dir,
14411442
callbacks=[ModelCheckpoint(save_weights_only=True, mode="max", monitor="val_acc")],
1442-
gpus=1 if str(device).startswith("cuda") else 0,
1443+
accelerator="gpu" if str(device).startswith("cuda") else "cpu",
1444+
devices=1,
14431445
max_epochs=100,
14441446
gradient_clip_val=2,
1445-
progress_bar_refresh_rate=1,
1447+
enable_progress_bar=True,
14461448
)
14471449
trainer.logger._default_hp_metric = None # Optional logging argument that we don't need
14481450

course_UvA-DL/06-graph-neural-networks/.meta.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: "Tutorial 6: Basics of Graph Neural Networks"
22
author: Phillip Lippe
33
created: 2021-06-07
4-
updated: 2021-12-04
4+
updated: 2023-01-04
55
license: CC BY-SA
66
build: 0
77
tags:
@@ -19,10 +19,11 @@ description: |
1919
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
2020
requirements:
2121
- torch-scatter
22-
- torch-sparse<0.6.13
22+
- torch-sparse
2323
- torch-cluster
2424
- torch-spline-conv
25-
- torch-geometric==2.0.2
25+
- torch-geometric
26+
- pytorch-lightning>=1.8
2627
pip__find-link:
2728
# - https://pytorch-geometric.com/whl/torch-1.8.0+cu101.html
2829
- https://pytorch-geometric.com/whl/torch-%(TORCH_MAJOR_DOT_MINOR)s.0+%(DEVICE)s.html

course_UvA-DL/06-graph-neural-networks/GNN_overview.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
pl.seed_everything(42)
4040

4141
# Ensure that all operations are deterministic on GPU (if used) for reproducibility
42-
torch.backends.cudnn.determinstic = True
42+
torch.backends.cudnn.deterministic = True
4343
torch.backends.cudnn.benchmark = False
4444

4545
# %% [markdown]
@@ -634,7 +634,7 @@ def test_step(self, batch, batch_idx):
634634
# Additionally to the Lightning module, we define a training function below.
635635
# As we have a single graph, we use a batch size of 1 for the data loader and share the same data loader for the train,
636636
# validation, and test set (the mask is picked inside the Lightning module).
637-
# Besides, we set the argument `progress_bar_refresh_rate` to zero as it usually shows the progress per epoch,
637+
# Besides, we set the argument `enable_progress_bar` to False as it usually shows the progress per epoch,
638638
# but an epoch only consists of a single step.
639639
# If you have downloaded the pre-trained models in the beginning of the tutorial, we load those instead of training from scratch.
640640
# Finally, we test the model and return the results.
@@ -651,9 +651,10 @@ def train_node_classifier(model_name, dataset, **model_kwargs):
651651
trainer = pl.Trainer(
652652
default_root_dir=root_dir,
653653
callbacks=[ModelCheckpoint(save_weights_only=True, mode="max", monitor="val_acc")],
654-
gpus=AVAIL_GPUS,
654+
accelerator="gpu" if AVAIL_GPUS > 0 else "cpu",
655+
devices=max(1, AVAIL_GPUS),
655656
max_epochs=200,
656-
progress_bar_refresh_rate=0,
657+
enable_progress_bar=False,
657658
) # 0 because epoch size is 1
658659
trainer.logger._default_hp_metric = None # Optional logging argument that we don't need
659660

@@ -932,9 +933,10 @@ def train_graph_classifier(model_name, **model_kwargs):
932933
trainer = pl.Trainer(
933934
default_root_dir=root_dir,
934935
callbacks=[ModelCheckpoint(save_weights_only=True, mode="max", monitor="val_acc")],
935-
gpus=AVAIL_GPUS,
936+
accelerator="gpu" if AVAIL_GPUS > 0 else "cpu",
937+
devices=max(1, AVAIL_GPUS),
936938
max_epochs=500,
937-
progress_bar_refresh_rate=0,
939+
enable_progress_bar=False,
938940
)
939941
trainer.logger._default_hp_metric = None
940942

course_UvA-DL/07-deep-energy-based-generative-models/.meta.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: "Tutorial 7: Deep Energy-Based Generative Models"
22
author: Phillip Lippe
33
created: 2021-07-12
4-
updated: 2021-07-12
4+
updated: 2023-01-04
55
license: CC BY-SA
66
build: 0
77
tags:
@@ -22,6 +22,7 @@ requirements:
2222
- torchvision
2323
- matplotlib
2424
- tensorboard
25+
- pytorch-lightning>=1.8
2526
accelerator:
2627
- CPU
2728
- GPU

course_UvA-DL/07-deep-energy-based-generative-models/Deep_Energy_Models.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
pl.seed_everything(42)
4545

4646
# Ensure that all operations are deterministic on GPU (if used) for reproducibility
47-
torch.backends.cudnn.determinstic = True
47+
torch.backends.cudnn.deterministic = True
4848
torch.backends.cudnn.benchmark = False
4949

5050
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
@@ -640,7 +640,8 @@ def train_model(**kwargs):
640640
# Create a PyTorch Lightning trainer with the generation callback
641641
trainer = pl.Trainer(
642642
default_root_dir=os.path.join(CHECKPOINT_PATH, "MNIST"),
643-
gpus=1 if str(device).startswith("cuda") else 0,
643+
accelerator="gpu" if str(device).startswith("cuda") else "cpu",
644+
devices=1,
644645
max_epochs=60,
645646
gradient_clip_val=0.1,
646647
callbacks=[
@@ -650,7 +651,7 @@ def train_model(**kwargs):
650651
OutlierCallback(),
651652
LearningRateMonitor("epoch"),
652653
],
653-
progress_bar_refresh_rate=1,
654+
enable_progress_bar=True,
654655
)
655656
# Check whether pretrained model exists. If yes, load it and skip training
656657
pretrained_filename = os.path.join(CHECKPOINT_PATH, "MNIST.ckpt")

course_UvA-DL/08-deep-autoencoders/.meta.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: "Tutorial 8: Deep Autoencoders"
22
author: Phillip Lippe
33
created: 2021-07-12
4-
updated: 2021-07-12
4+
updated: 2023-01-04
55
license: CC BY-SA
66
build: 0
77
tags:
@@ -22,6 +22,7 @@ requirements:
2222
- torchvision
2323
- matplotlib
2424
- seaborn
25+
- pytorch-lightning>=1.8
2526
accelerator:
2627
- CPU
2728
- GPU

course_UvA-DL/08-deep-autoencoders/Deep_Autoencoders.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
pl.seed_everything(42)
4242

4343
# Ensure that all operations are deterministic on GPU (if used) for reproducibility
44-
torch.backends.cudnn.determinstic = True
44+
torch.backends.cudnn.deterministic = True
4545
torch.backends.cudnn.benchmark = False
4646

4747
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
@@ -385,7 +385,8 @@ def train_cifar(latent_dim):
385385
# Create a PyTorch Lightning trainer with the generation callback
386386
trainer = pl.Trainer(
387387
default_root_dir=os.path.join(CHECKPOINT_PATH, "cifar10_%i" % latent_dim),
388-
gpus=1 if str(device).startswith("cuda") else 0,
388+
accelerator="gpu" if str(device).startswith("cuda") else "cpu",
389+
devices=1,
389390
max_epochs=500,
390391
callbacks=[
391392
ModelCheckpoint(save_weights_only=True),

course_UvA-DL/09-normalizing-flows/.meta.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: "Tutorial 9: Normalizing Flows for Image Modeling"
22
author: Phillip Lippe
33
created: 2021-06-07
4-
updated: 2021-06-16
4+
updated: 2023-01-04
55
license: CC BY-SA
66
build: 0
77
tags:
@@ -25,6 +25,7 @@ requirements:
2525
- matplotlib
2626
- seaborn
2727
- tabulate
28+
- pytorch-lightning>=1.8
2829
accelerator:
2930
- CPU
3031
- GPU

0 commit comments

Comments
 (0)