Skip to content

Commit 766ffb3

Browse files
refactor requirements into own file with parent inheritance (#336)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 3f96b5f commit 766ffb3

File tree

71 files changed

+159
-212
lines changed

Some content is hidden

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

71 files changed

+159
-212
lines changed

.actions/assistant.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
_PATH_HERE = os.path.dirname(__file__)
2020
_PATH_ROOT = os.path.dirname(_PATH_HERE)
21-
PATH_REQ_DEFAULT = os.path.join(_PATH_ROOT, "_requirements", "default.txt")
2221
PATH_SCRIPT_RENDER = os.path.join(_PATH_HERE, "_ipynb-render.sh")
2322
PATH_SCRIPT_TEST = os.path.join(_PATH_HERE, "_ipynb-test.sh")
2423
# https://askubuntu.com/questions/909918/how-to-show-unzip-progress
@@ -93,8 +92,18 @@
9392
"""
9493

9594

96-
def load_requirements(path_req: str = PATH_REQ_DEFAULT) -> list:
97-
"""Load the requirements from a file."""
95+
def load_requirements(folder: str, fname: str = "requirements.txt") -> List[str]:
96+
"""Load the requirements from a file.
97+
98+
Args:
99+
folder: path to the folder with requirements
100+
fname: filename
101+
102+
"""
103+
path_req = os.path.join(folder, fname)
104+
if not os.path.isfile(path_req):
105+
warnings.warn(f"Missing expected requirement file '{path_req}'")
106+
return []
98107
with open(path_req) as fopen:
99108
req = fopen.readlines()
100109
req = [r[: r.index("#")] if "#" in r else r for r in req]
@@ -184,7 +193,7 @@ class AssistantCLI:
184193
_EXT_ARCHIVE_TAR = (".tar", ".gz")
185194
_EXT_ARCHIVE = _EXT_ARCHIVE_ZIP + _EXT_ARCHIVE_TAR
186195
_AZURE_POOL = "lit-rtx-3090"
187-
_AZURE_DOCKER = "pytorchlightning/tutorials:latest"
196+
_AZURE_DOCKER = "pytorchlightning/tutorials:cuda"
188197

189198
@staticmethod
190199
def _find_meta(folder: str) -> str:
@@ -276,22 +285,22 @@ def _parse_requirements(folder: str) -> Tuple[str, str]:
276285
277286
"""
278287
meta = AssistantCLI._load_meta(folder)
279-
reqs = meta.get("requirements", [])
288+
requires = set(load_requirements(folder) + load_requirements(os.path.dirname(folder)))
280289

281290
meta_pip_args = {
282291
k.replace(AssistantCLI._META_PIP_KEY, ""): v
283292
for k, v in meta.items()
284293
if k.startswith(AssistantCLI._META_PIP_KEY)
285294
}
286-
pip_args = ['--find-links="https://download.pytorch.org/whl/"' + _RUNTIME_VERSIONS.get("DEVICE")]
295+
pip_args = ['--extra-index-url="https://download.pytorch.org/whl/"' + _RUNTIME_VERSIONS.get("DEVICE")]
287296
for pip_key in meta_pip_args:
288297
if not isinstance(meta_pip_args[pip_key], (list, tuple, set)):
289298
meta_pip_args[pip_key] = [meta_pip_args[pip_key]]
290299
for arg in meta_pip_args[pip_key]:
291300
arg = arg % _RUNTIME_VERSIONS
292301
pip_args.append(f"--{pip_key} {arg}")
293302

294-
return " ".join([f'"{req}"' for req in reqs]), " ".join(pip_args)
303+
return " ".join([f'"{req}"' for req in requires]), " ".join(pip_args)
295304

296305
@staticmethod
297306
def _bash_download_data(folder: str) -> List[str]:
@@ -465,7 +474,8 @@ def convert_ipynb(folder: str) -> None:
465474
meta["description"] = meta["description"].replace(os.linesep, f"{os.linesep}# ")
466475

467476
header = TEMPLATE_HEADER % meta
468-
requires = set(load_requirements() + meta["requirements"])
477+
# load local and parent requirements
478+
requires = set(load_requirements(folder) + load_requirements(os.path.dirname(folder)))
469479
setup = TEMPLATE_SETUP % dict(requirements=" ".join([f'"{req}"' for req in requires]))
470480
py_script = [header + setup] + py_script + [TEMPLATE_FOOTER]
471481

@@ -769,23 +779,20 @@ def update_env_details(folder: str, base_path: str = DIR_NOTEBOOKS) -> str:
769779
770780
"""
771781
meta = AssistantCLI._load_meta(folder)
772-
# default is COU runtime
773-
with open(PATH_REQ_DEFAULT) as fopen:
774-
req = fopen.readlines()
775-
req += meta.get("requirements", [])
776-
req = [r.strip() for r in req]
782+
# load local and parent requirements
783+
requires = set(load_requirements(folder) + load_requirements(os.path.dirname(folder)))
777784

778-
require = {_parse_package_name(r) for r in req if r}
785+
requires = {_parse_package_name(r) for r in requires if r}
779786
# duplicate package name/key for cases with -/_ separator
780787
env = {
781788
**{_parse_package_name(p).replace("-", "_"): p for p in freeze.freeze()},
782789
**{_parse_package_name(p).replace("_", "-"): p for p in freeze.freeze()},
783790
}
784791
# for debugging reasons print the env and requested packages
785792
try:
786-
meta["environment"] = [env[r] for r in require]
793+
meta["environment"] = [env[r] for r in requires]
787794
except KeyError:
788-
raise KeyError(f"Missing matching requirements: {require}\n within environment: {env}")
795+
raise KeyError(f"Missing matching requirements: {requires}\n within environment: {env}")
789796
meta["published"] = datetime.now().isoformat()
790797

791798
fmeta = os.path.join(base_path, folder) + ".yaml"

.azure/ipynb-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ jobs:
149149
timeoutInMinutes: "15"
150150
151151
- bash: |
152-
set -e
152+
set -ex
153153
pip list
154154
python -c "import torch ; mgpu = torch.cuda.device_count() ; assert mgpu > 0, f'GPU: {mgpu}'"
155155
python -m papermill --version

.azure/ipynb-validate.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ jobs:
8686
displayName: "Install dependencies"
8787
8888
- bash: |
89+
set -ex
90+
pip list
8991
python -c "import torch ; mgpu = torch.cuda.device_count() ; assert mgpu > 0, f'GPU: {mgpu}'"
9092
displayName: "Sanity check"
9193

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ______________________________________________________________________
3333

3434
We are always looking for help to implement new features or fixing bugs.
3535

36-
A lot of good work has already been done in project mechanics (\_requirements/base.txt, setup.py, pep8, badges, ci, etc...) so we're in a good state there thanks to all sooner contributors!
36+
A lot of good work has already been done in project mechanics (setup.py, pep8, badges, ci, etc...) so we're in a good state there thanks to all sooner contributors!
3737

3838
### Bug Fixes:
3939

.github/workflows/ci_internal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
run: |
3737
pip install -q -r .actions/requires.txt -r _requirements/test.txt
3838
# this is needed to be able to run package version parsing test
39-
pip install -q -r _requirements/default.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
39+
pip install -q -r _requirements/devel.txt --find-links https://download.pytorch.org/whl/cpu/torch_stable.html
4040
pip list
4141
4242
- name: Prepare dummy inputs

_dockers/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ You can build it on your own, note it takes lots of time, be prepared.
88
git clone https://github.com/Lightning-AI/torchmetrics.git
99

1010
# build with the default arguments
11-
docker image build -t tutorials:latest -f dockers/ubuntu-cuda/Dockerfile .
11+
docker image build -t tutorials:cuda -f dockers/ubuntu-cuda/Dockerfile .
1212

1313
# build with specific arguments
1414
docker image build -t tutorials:ubuntu-cuda11.7.1-py3.9-torch1.13 \
@@ -23,14 +23,14 @@ To run your docker use
2323

2424
```bash
2525
docker image list
26-
docker run --rm -it tutorials:latest bash
26+
docker run --rm -it tutorials:cuda bash
2727
```
2828

2929
and if you do not need it anymore, just clean it:
3030

3131
```bash
3232
docker image list
33-
docker image rm tutorials:latest
33+
docker image rm tutorials:cuda
3434
```
3535

3636
## Run docker image with GPUs

_requirements/default.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

_requirements/devel.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
virtualenv>=20.10
2-
jupytext>=1.10, <1.15 # converting
3-
pytest>=7.0, <9.0
2+
3+
# pytest>=7.0, <9.0
44
# testing with own fork with extended cell timeout
55
# https://github.com/Borda/nbval/archive/refs/heads/timeout-limit.zip
6-
papermill>=2.3.4, <2.5.0 # render
6+
ipython[notebook]>=8.0.0, <8.17.0
7+
urllib3 # for ipython
8+
jupytext>=1.10, <1.15 # converting
9+
papermill>=2.3.4, <2.5.0 # rendering
10+
11+
matplotlib
12+
# all is based on PyTorch
13+
torch
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
title: "Tutorial 1: Introduction to PyTorch"
22
author: Phillip Lippe
33
created: 2021-08-27
4-
updated: 2023-03-14
54
license: CC BY-SA
6-
build: 1
75
description: |
86
This tutorial will give a short introduction to PyTorch basics, and get you setup for writing your own neural networks.
97
This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.
108
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
11-
requirements:
12-
- matplotlib
13-
- lightning>=2.0.0
149
accelerator:
1510
- CPU
1611
- GPU
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
matplotlib
2+
lightning>=2.0.0
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
title: "Tutorial 2: Activation Functions"
22
author: Phillip Lippe
33
created: 2021-08-27
4-
updated: 2023-03-14
54
license: CC BY-SA
65
description: |
76
In this tutorial, we will take a closer look at (popular) activation functions and investigate their effect on optimization properties in neural networks.
@@ -10,11 +9,6 @@ description: |
109
The goal of this tutorial is to show the importance of choosing a good activation function (and how to do so), and what problems might occur if we don't.
1110
This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.
1211
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
13-
requirements:
14-
- torchvision
15-
- matplotlib
16-
- seaborn
17-
- lightning>=2.0.0
1812
accelerator:
1913
- CPU
2014
- GPU
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
torchvision
2+
matplotlib
3+
seaborn
4+
lightning>=2.0.0
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
title: "Tutorial 3: Initialization and Optimization"
22
author: Phillip Lippe
33
created: 2021-08-27
4-
updated: 2023-03-14
54
license: CC BY-SA
65
tags:
76
- Image
@@ -14,11 +13,6 @@ description: |
1413
This is why we will take a closer look at the following concepts: initialization and optimization.
1514
This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.
1615
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
17-
requirements:
18-
- torchvision
19-
- matplotlib
20-
- seaborn
21-
- lightning>=2.0.0
2216
accelerator:
2317
- CPU
2418
- GPU
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
torchvision
2+
matplotlib
3+
seaborn
4+
lightning>=2.0.0
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
title: "Tutorial 4: Inception, ResNet and DenseNet"
22
author: Phillip Lippe
33
created: 2021-08-27
4-
updated: 2023-03-14
54
license: CC BY-SA
65
tags:
76
- Image
@@ -13,12 +12,5 @@ description: |
1312
Thus, it is important to understand these architectures in detail and learn how to implement them.
1413
This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.
1514
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
16-
requirements:
17-
- torchvision
18-
- matplotlib
19-
- seaborn
20-
- tabulate
21-
- lightning>=2.0.0
22-
- tensorboard
2315
accelerator:
2416
- GPU
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
torchvision
2+
matplotlib
3+
seaborn
4+
tabulate
5+
lightning>=2.0.0
6+
tensorboard
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
title: "Tutorial 5: Transformers and Multi-Head Attention"
22
author: Phillip Lippe
33
created: 2021-06-30
4-
updated: 2023-03-14
54
license: CC BY-SA
6-
build: 0
75
tags:
86
- Text
97
description: |
@@ -15,10 +13,5 @@ description: |
1513
it is important to understand how it works, and have implemented it yourself, which we will do in this notebook.
1614
This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.
1715
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
18-
requirements:
19-
- torchvision
20-
- matplotlib
21-
- seaborn
22-
- lightning>=2.0.0
2316
accelerator:
2417
- GPU
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
torchvision
2+
matplotlib
3+
seaborn
4+
lightning>=2.0.0

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
title: "Tutorial 6: Basics of Graph Neural Networks"
22
author: Phillip Lippe
33
created: 2021-06-07
4-
updated: 2023-03-14
54
license: CC BY-SA
6-
build: 0
75
tags:
86
- Graph
97
description: |
@@ -17,13 +15,6 @@ description: |
1715
Finally, we will apply a GNN on semi-supervised node classification and molecule categorization.
1816
This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.
1917
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
20-
requirements:
21-
- torch-scatter
22-
- torch-sparse
23-
- torch-cluster
24-
- torch-spline-conv
25-
- "torch-geometric>=2.0.0,<2.5.0"
26-
- "lightning>=2.0.0"
2718
pip__find-link:
2819
# - https://pytorch-geometric.com/whl/torch-1.8.0+cu101.html
2920
- https://pytorch-geometric.com/whl/torch-%(TORCH_MAJOR_DOT_MINOR)s.0+%(DEVICE)s.html
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
torch-scatter
2+
torch-sparse
3+
torch-cluster
4+
torch-spline-conv
5+
torch-geometric>=2.0.0,<2.5.0
6+
lightning>=2.0.0
Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
title: "Tutorial 7: Deep Energy-Based Generative Models"
22
author: Phillip Lippe
33
created: 2021-07-12
4-
updated: 2023-03-14
54
license: CC BY-SA
6-
build: 1
75
tags:
86
- Image
97
description: |
@@ -18,11 +16,6 @@ description: |
1816
we will show the idea of energy-based models with a lot of examples.
1917
This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.
2018
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
21-
requirements:
22-
- torchvision
23-
- matplotlib
24-
- tensorboard
25-
- pytorch-lightning>=2.0.0
2619
accelerator:
2720
- CPU
2821
- GPU
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
torchvision
2+
matplotlib
3+
tensorboard
4+
pytorch-lightning>=2.0.0
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
title: "Tutorial 8: Deep Autoencoders"
22
author: Phillip Lippe
33
created: 2021-07-12
4-
updated: 2023-03-14
54
license: CC BY-SA
6-
build: 0
75
tags:
86
- Image
97
description: |
@@ -18,12 +16,6 @@ description: |
1816
and need to output an image of full size (e.g. in VAE, GANs, or super-resolution applications).
1917
This notebook is part of a lecture series on Deep Learning at the University of Amsterdam.
2018
The full list of tutorials can be found at https://uvadlc-notebooks.rtfd.io.
21-
requirements:
22-
- torchvision
23-
- matplotlib
24-
- seaborn
25-
- lightning>=2.0.0
26-
- tensorboard
2719
accelerator:
2820
- CPU
2921
- GPU

0 commit comments

Comments
 (0)