Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit 3b4e9a0

Browse files
authored
docker: add missing git-lfs & readability (#284)
1 parent fb7e973 commit 3b4e9a0

8 files changed

Lines changed: 52 additions & 59 deletions

File tree

.actions/assistant.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@
9595

9696
def load_requirements(path_req: str = PATH_REQ_DEFAULT) -> list:
9797
"""Load the requirements from a file."""
98-
with open(path_req) as fp:
99-
req = fp.readlines()
98+
with open(path_req) as fopen:
99+
req = fopen.readlines()
100100
req = [r[: r.index("#")] if "#" in r else r for r in req]
101101
req = [r.strip() for r in req]
102102
req = [r for r in req if r]
@@ -252,7 +252,7 @@ def _parse_requirements(folder: str) -> Tuple[str, str]:
252252
for k, v in meta.items()
253253
if k.startswith(AssistantCLI._META_PIP_KEY)
254254
}
255-
pip_args = ["--extra-index-url https://download.pytorch.org/whl/" + _RUNTIME_VERSIONS.get("DEVICE")]
255+
pip_args = ['--find-links="https://download.pytorch.org/whl/"' + _RUNTIME_VERSIONS.get("DEVICE")]
256256
for pip_key in meta_pip_args:
257257
if not isinstance(meta_pip_args[pip_key], (list, tuple, set)):
258258
meta_pip_args[pip_key] = [meta_pip_args[pip_key]]
@@ -335,8 +335,8 @@ def bash_render(folder: str, output_file: str = PATH_SCRIPT_RENDER) -> Optional[
335335
cmd.append(f"git add {pub_ipynb}")
336336
if not output_file:
337337
return os.linesep.join(cmd)
338-
with open(output_file, "w") as fp:
339-
fp.write(os.linesep.join(cmd))
338+
with open(output_file, "w") as fopen:
339+
fopen.write(os.linesep.join(cmd))
340340

341341
@staticmethod
342342
def bash_test(folder: str, output_file: str = PATH_SCRIPT_TEST) -> Optional[str]:
@@ -386,8 +386,8 @@ def bash_test(folder: str, output_file: str = PATH_SCRIPT_TEST) -> Optional[str]
386386
cmd += ["deactivate", f"rm -rf {os.path.join(folder, 'venv')}"]
387387
if not output_file:
388388
return os.linesep.join(cmd)
389-
with open(output_file, "w") as fp:
390-
fp.write(os.linesep.join(cmd))
389+
with open(output_file, "w") as fopen:
390+
fopen.write(os.linesep.join(cmd))
391391

392392
@staticmethod
393393
def convert_ipynb(folder: str) -> None:
@@ -397,8 +397,8 @@ def convert_ipynb(folder: str) -> None:
397397
folder: folder with python script
398398
"""
399399
fpath, _, _ = AssistantCLI._valid_folder(folder, ext=".py")
400-
with open(fpath) as fp:
401-
py_script = fp.readlines()
400+
with open(fpath) as fopen:
401+
py_script = fopen.readlines()
402402

403403
meta = AssistantCLI._load_meta(folder, strict=True)
404404
meta.update(
@@ -414,8 +414,8 @@ def convert_ipynb(folder: str) -> None:
414414

415415
py_script = AssistantCLI._replace_images(py_script, folder)
416416

417-
with open(fpath, "w") as fp:
418-
fp.writelines(py_script)
417+
with open(fpath, "w") as fopen:
418+
fopen.writelines(py_script)
419419

420420
os.system(f'python -m jupytext --set-formats "ipynb,py:percent" {fpath}')
421421

@@ -442,8 +442,8 @@ def _replace_images(lines: list, local_dir: str) -> list:
442442
else:
443443
url_path = "/".join([URL_PL_DOWNLOAD, local_dir, p_img])
444444
p_local_img = os.path.join(local_dir, p_img)
445-
with open(p_local_img, "rb") as fp:
446-
im = fp.read()
445+
with open(p_local_img, "rb") as fopen:
446+
im = fopen.read()
447447
im_base64 = base64.b64encode(im).decode("utf-8")
448448
_, ext = os.path.splitext(p_img)
449449
md = md.replace(f'src="{p_img}"', f'src="{url_path}"')
@@ -489,8 +489,8 @@ def group_folders(
489489
$ python assistant.py group-folders ../target-diff.txt \
490490
--fpath_actual_dirs "['../dirs-main.txt', '../dirs-publication.txt']"
491491
"""
492-
with open(fpath_gitdiff) as fp:
493-
changed = [ln.strip() for ln in fp.readlines()]
492+
with open(fpath_gitdiff) as fopen:
493+
changed = [ln.strip() for ln in fopen.readlines()]
494494
dirs = [os.path.dirname(ln) for ln in changed]
495495
# not empty paths
496496
dirs = [ln for ln in dirs if ln]
@@ -520,22 +520,23 @@ def group_folders(
520520
raise FileNotFoundError(f"{msg} nor sub-folder: \n {os.linesep.join(dirs_invalid)}")
521521

522522
dirs_change = [d for d in dirs_exist if AssistantCLI._find_meta(d)]
523-
with open(fpath_change_folders, "w") as fp:
524-
fp.write(os.linesep.join(sorted(dirs_change)))
523+
with open(fpath_change_folders, "w") as fopen:
524+
fopen.write(os.linesep.join(sorted(dirs_change)))
525525

526526
dirs_drop = [d for d in dirs if not os.path.isdir(d)]
527-
with open(fpath_drop_folders, "w") as fp:
528-
fp.write(os.linesep.join(sorted(dirs_drop)))
527+
with open(fpath_drop_folders, "w") as fopen:
528+
fopen.write(os.linesep.join(sorted(dirs_drop)))
529529

530530
@staticmethod
531-
def generate_matrix(fpath_change_folders: str) -> str:
531+
def generate_matrix(fpath_change_folders: str, json_indent: Optional[int] = None) -> str:
532532
"""Generate Azure matrix with leaf for each changed notebook.
533533
534534
Args:
535535
fpath_change_folders: output of previous ``group_folders``
536+
json_indent: makes the json more readable, recommendation is 4
536537
"""
537-
with open(fpath_change_folders) as fp:
538-
folders = [ln.strip() for ln in fp.readlines()]
538+
with open(fpath_change_folders) as fopen:
539+
folders = [ln.strip() for ln in fopen.readlines()]
539540
# set default so the matrix has at least one runner
540541
if not folders:
541542
return ""
@@ -548,7 +549,7 @@ def generate_matrix(fpath_change_folders: str) -> str:
548549
# TODO: allow defining some custom images with with python or PT
549550
"docker-image": AssistantCLI._AZURE_DOCKER,
550551
}
551-
return json.dumps(mtx)
552+
return json.dumps(mtx, indent=json_indent)
552553

553554
@staticmethod
554555
def _get_card_item_cell(path_ipynb: str, path_meta: str, path_thumb: Optional[str]) -> Dict[str, Any]:
@@ -652,7 +653,12 @@ def copy_notebooks(
652653

653654
@staticmethod
654655
def _copy_notebook(
655-
path_ipynb: str, path_root: str, docs_root: str, path_docs_ipynb: str, path_docs_images: str
656+
path_ipynb: str,
657+
path_root: str,
658+
docs_root: str,
659+
path_docs_ipynb: str,
660+
path_docs_images: str,
661+
json_indent: Optional[int] = None,
656662
) -> str:
657663
"""Copy particular notebook."""
658664
ipynb = path_ipynb.split(os.path.sep)
@@ -678,7 +684,7 @@ def _copy_notebook(
678684
ipynb["cells"].append(AssistantCLI._get_card_item_cell(path_ipynb, path_meta, path_thumb))
679685

680686
with open(new_ipynb, "w") as fopen:
681-
json.dump(ipynb, fopen, indent=4)
687+
json.dump(ipynb, fopen, indent=json_indent)
682688
return path_ipynb_in_dir
683689

684690
@staticmethod
@@ -691,8 +697,8 @@ def update_env_details(folder: str, base_path: str = DIR_NOTEBOOKS) -> str:
691697
"""
692698
meta = AssistantCLI._load_meta(folder)
693699
# default is COU runtime
694-
with open(PATH_REQ_DEFAULT) as fp:
695-
req = fp.readlines()
700+
with open(PATH_REQ_DEFAULT) as fopen:
701+
req = fopen.readlines()
696702
req += meta.get("requirements", [])
697703
req = [r.strip() for r in req]
698704

.azure/ipynb-publish.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ jobs:
4242
4343
- bash: |
4444
notebooks=$(python .actions/assistant.py generate-matrix changed-folders.txt)
45-
printf "Changed notebooks: $notebooks\n"
4645
echo "##vso[task.setVariable variable=dirs;isOutput=true]$notebooks"
4746
name: mtrx
4847
displayName: "Changed matrix"
48+
- bash: echo '$(mtrx.dirs)' | python -m json.tool
49+
displayName: "Show matrix"
4950

5051
- bash: |
5152
# second half with || [...] is needed for reading the last line
@@ -79,10 +80,10 @@ jobs:
7980
# - For 60 minutes on Microsoft-hosted agents with a private project or private repository
8081
timeoutInMinutes: "180"
8182

82-
pool: "$(agent-pool)"
83+
pool: $(agent-pool)
8384
# this need to have installed docker in the base machine/image...
8485
container:
85-
image: "$(docker-image)"
86+
image: $(docker-image)
8687
options: "--gpus=all --shm-size=32g -v /usr/bin/docker:/tmp/docker:ro"
8788

8889
variables:
@@ -131,12 +132,14 @@ jobs:
131132
- bash: |
132133
set -e
133134
pip --version
135+
# todo: export requirements for notebooks to file and execute
136+
# todo: adjust torch ecosystem versions
134137
pip install -r requirements.txt -r _requirements/data.txt
135-
pip list
136138
displayName: "Install dependencies"
137139
138140
- bash: |
139141
set -e
142+
pip list
140143
python -c "import torch ; mgpu = torch.cuda.device_count() ; assert mgpu > 0, f'GPU: {mgpu}'"
141144
python -m papermill --version
142145
displayName: "Sanity check"

.azure/ipynb-tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ jobs:
2929
3030
- bash: |
3131
notebooks=$(python .actions/assistant.py generate-matrix changed-folders.txt)
32-
printf "Changed notebooks: $notebooks\n"
3332
echo "##vso[task.setVariable variable=dirs;isOutput=true]$notebooks"
3433
name: mtrx
3534
displayName: "Changed matrix"
35+
- bash: echo '$(mtrx.dirs)' | python -m json.tool
36+
displayName: "Show matrix"
3637

3738
- job: nbval
3839
dependsOn: check_diff
@@ -43,10 +44,10 @@ jobs:
4344
# how much time to give 'run always even if cancelled tasks' before stopping them
4445
cancelTimeoutInMinutes: "2"
4546

46-
pool: "$(agent-pool)"
47+
pool: $(agent-pool)
4748
# this need to have installed docker in the base image...
4849
container:
49-
image: "$(docker-image)"
50+
image: $(docker-image)
5051
options: "--gpus=all --shm-size=32g -v /usr/bin/docker:/tmp/docker:ro"
5152

5253
variables:

.github/workflows/ci_docs.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ on: # Trigger the workflow on push or pull request
44
# push:
55
# branches: [main]
66
pull_request: {}
7-
schedule:
8-
# At the end of every day
9-
- cron: "0 0 * * *"
7+
#workflow_dispatch: {}
108

119
concurrency:
1210
group: ${{ github.workflow }}-${{ github.head_ref }}

.github/workflows/docker-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ concurrency:
1717
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
1818

1919
env:
20-
PUSH_DOCKERHUB: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }}
20+
PUSH_DOCKERHUB: ${{ github.ref == 'refs/heads/main' || github.event_name != 'pull_request' }}
2121

2222
jobs:
2323
build-cuda:

.gitignore

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ share/python-wheels/
2525
*.egg-info/
2626
.installed.cfg
2727
*.egg
28-
MANIFEST
2928

3029
# PyInstaller
3130
# Usually these files are written by a python script from a template
@@ -55,16 +54,6 @@ coverage.xml
5554
*.mo
5655
*.pot
5756

58-
# Django stuff:
59-
*.log
60-
local_settings.py
61-
db.sqlite3
62-
db.sqlite3-journal
63-
64-
# Flask stuff:
65-
instance/
66-
.webassets-cache
67-
6857
# Scrapy stuff:
6958
.scrapy
7059

@@ -84,13 +73,8 @@ ipython_config.py
8473
# pyenv
8574
.python-version
8675

87-
# pipenv
88-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91-
# install all needed dependencies.
92-
#Pipfile.lock
93-
76+
# PyCharm
77+
.idea/
9478
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
9579
__pypackages__/
9680

@@ -128,10 +112,10 @@ dmypy.json
128112
# Pyre type checker
129113
.pyre/
130114

131-
.idea/
132-
133115
# data artifacts
134116
logs/
135117
lightning_logs/
136118
cifar-10-batches-py
137119
*.tar.gz
120+
121+
.ruff_cache/

_dockers/ubuntu-cuda/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ RUN \
4343
openmpi-bin \
4444
cmake \
4545
git \
46+
git-lfs \
4647
wget \
4748
curl \
4849
unzip \

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
# if the hyperparameters are not well tuned.
228228
# We will rely on training tricks proposed in the paper
229229
# [Implicit Generation and Generalization in Energy-Based Models](https://arxiv.org/abs/1903.08689)
230-
# by Yilun Du and Igor Mordatch ([blog](https://openai.com/blog/energy-based-models/)).
230+
# by Yilun Du and Igor Mordatch ([blog](https://openai.com/research/energy-based-models)).
231231
# The important part of this notebook is however to see how the theory above can actually be used in a model.
232232
#
233233
# ### Dataset

0 commit comments

Comments
 (0)