Skip to content

Commit

Permalink
Added support for lightning and hydra
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-dufour committed Jan 19, 2024
1 parent 21f2e44 commit 5d3f20a
Show file tree
Hide file tree
Showing 38 changed files with 1,137 additions and 182 deletions.
167 changes: 167 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,169 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


.vscode/
checkpoints/
wandb/
outputs/
datasets/*
/logs/
/checkpoints/
7 changes: 7 additions & 0 deletions src/configs/computer/1-gpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
devices: 1
progress_bar_refresh_rate: 2
num_workers: 8
accelerator: gpu
precision: bf16-mixed
strategy: auto
num_nodes: 1
7 changes: 7 additions & 0 deletions src/configs/computer/2-gpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
devices: 2
progress_bar_refresh_rate: 2
num_workers: 8
accelerator: gpu
precision: bf16-mixed
strategy: ddp
num_nodes: 1
7 changes: 7 additions & 0 deletions src/configs/computer/4-gpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
devices: 4
progress_bar_refresh_rate: 2
num_workers: 8
accelerator: gpu
precision: bf16-mixed
strategy: ddp
num_nodes: 1
11 changes: 11 additions & 0 deletions src/configs/data/additional_train_transforms/randaugment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
instance:
- _target_: torchvision.transforms.v2.RandomApply
transforms:
- _target_: torchvision.transforms.v2.RandAugment
magnitude: ${data.additional_train_transforms.randaugment_magnitude}
p: ${data.additional_train_transforms.randaugment_p}



randaugment_magnitude: 6
randaugment_p: 0.1
24 changes: 24 additions & 0 deletions src/configs/data/imagenet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defaults:
- additional_train_transforms: randaugment
- _self_

full_batch_size: 128
size: 256
num_classes: 1000
name: Imagenet-1K

dataset_builder:
_partial_: true
_target_: utils.data.build_imagenet
data_dir: ${data_dir}/imagenet
num_classes: ${data.num_classes}
size: ${data.size}
additional_transforms: ${data.additional_train_transforms.instance}

datamodule:
_target_: utils.datamodule.ImageDataModule
dataset_builder: ${data.dataset_builder}
full_batch_size: ${data.full_batch_size}
num_workers: ${computer.num_workers}
num_nodes: ${computer.num_nodes}
num_devices: ${computer.devices}
Empty file.
6 changes: 6 additions & 0 deletions src/configs/logger/wandb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_target_: pytorch_lightning.loggers.WandbLogger
save_dir: ${root_dir}/wandb
name: ${experiment_name}
project: Homm
log_model: False
offline: False
24 changes: 24 additions & 0 deletions src/configs/model/homm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defaults:
- train_batch_preprocess: mixup_and_cutmix
- network: homm
- loss: CE
- optimizer: adamw
- lr_scheduler: warmup_cosine_decay
- train_metric: accuracy
- val_metric: accuracy
- test_metric: accuracy

name: HoMM
instance:
_target_: model.classification.ClassificationModule
model: ${model.network}
loss: ${model.loss}
optimizer_cfg: ${model.optimizer}
lr_scheduler_builder: ${model.lr_scheduler}
train_batch_preprocess: ${model.train_batch_preprocess}
train_metrics: ${model.train_metric}
val_metrics: ${model.val_metric}
test_metrics: ${model.test_metric}


lsuv_normalize: False
2 changes: 2 additions & 0 deletions src/configs/model/loss/CE.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_target_: model.losses.CE.CrossEntropyLossModule
sum_label_dim: True
4 changes: 4 additions & 0 deletions src/configs/model/lr_scheduler/warmup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_partial_: true
_target_: utils.lr_scheduler.WarmupLR
warmup_steps: 10000

5 changes: 5 additions & 0 deletions src/configs/model/lr_scheduler/warmup_cosine_decay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
_partial_: true
_target_: utils.lr_scheduler.WarmupCosineDecayLR
warmup_steps: 10000
total_steps: ${trainer.max_steps}

12 changes: 12 additions & 0 deletions src/configs/model/network/homm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_target_: model.network.vision.HoMVision
nb_classes: ${data.num_classes}
dim: 256
im_size: 256
kernel_size: 32
nb_layers: 4
order: 2
order_expand: 4
ffw_expand: 4
dropout: 0.0
pooling: cls
in_conv: true
Empty file.
8 changes: 8 additions & 0 deletions src/configs/model/optimizer/adam.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
optim:
_partial_: true
_target_: torch.optim.Adam
lr: 1e-3
betas: [0.9, 0.999]
weight_decay: 0.01

exclude_ln_and_biases_from_weight_decay: False
8 changes: 8 additions & 0 deletions src/configs/model/optimizer/adamw.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
optim:
_partial_: true
_target_: torch.optim.AdamW
lr: 1e-3
betas: [0.9, 0.999]
weight_decay: 0.01

exclude_ln_and_biases_from_weight_decay: False
7 changes: 7 additions & 0 deletions src/configs/model/optimizer/sgd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
optim:
_partial_: true
_target_: torch.optim.SGD
lr: 1e-3
weight_decay: 0.01

exclude_ln_and_biases_from_weight_decay: False
2 changes: 2 additions & 0 deletions src/configs/model/test_metric/accuracy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_target_: utils.metrics.ClassificationMetrics
num_classes: ${data.num_classes}
4 changes: 4 additions & 0 deletions src/configs/model/train_batch_preprocess/cutmix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_target_: utils.mixup.CutMix
apply_transform_prob: 1.0
alpha: 1.0
num_classes: 1000
4 changes: 4 additions & 0 deletions src/configs/model/train_batch_preprocess/mixup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_target_: utils.mixup.MixUp
apply_transform_prob: 1.0
alpha: 0.1
num_classes: 1000
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_target_: utils.mixup.CutMixUp
apply_transform_prob: 1.0
mixup_prob: 0.5
alpha_mixup: 0.1
alpha_cutmix: 1.0
num_classes: 1000
2 changes: 2 additions & 0 deletions src/configs/model/train_metric/accuracy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_target_: utils.metrics.ClassificationMetrics
num_classes: ${data.num_classes}
2 changes: 2 additions & 0 deletions src/configs/model/val_metric/accuracy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_target_: utils.metrics.ClassificationMetrics
num_classes: ${data.num_classes}
42 changes: 42 additions & 0 deletions src/configs/train.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
defaults:
- model: homm
- computer: 1-gpu
- data: imagenet
- logger: wandb
- _self_

trainer:
_target_: pytorch_lightning.Trainer
max_steps: 300000
deterministic: True
devices: ${computer.devices}
accelerator: ${computer.accelerator}
strategy: ${computer.strategy}
log_every_n_steps: 1
num_nodes: ${computer.num_nodes}
precision: ${computer.precision}
gradient_clip_val: 1.0

checkpoints:
_target_: pytorch_lightning.callbacks.ModelCheckpoint
dirpath: ${checkpoint_dir}/${experiment_name}
save_last: True
monitor: val/loss
mode: min

progress_bar:
_target_: pytorch_lightning.callbacks.TQDMProgressBar
refresh_rate: ${computer.progress_bar_refresh_rate}

seed: 3407
data_dir: ${root_dir}/datasets
root_dir: ${hydra:runtime.cwd}
checkpoint_dir: ${root_dir}/checkpoints
experiment_name_suffix: base
experiment_name: ${data.name}_${model.name}_${experiment_name_suffix}

hydra:
run:
dir: outputs/${hydra.job.name}/${now:%Y-%m-%d_%H-%M-%S}/${experiment_name}
job:
chdir: true
Loading

0 comments on commit 5d3f20a

Please sign in to comment.