Unify log dir structure (#211)

* Unifiy log dir paths
* Add a little helper script `logs/latest` which can be used to quickly change into the latest log dir of a specific kind
* Update README
This commit is contained in:
Nils Werner authored and GitHub committed 2021-12-03 03:42:33 +01:00
1 parent 6cbf168156
commit ab02996fd4
6 files changed
+62 -42

No files matched your search

+40 -36
View File
@@ -11,7 +11,7 @@
A clean and scalable template to kickstart your deep learning project 🚀⚡🔥<br> A clean and scalable template to kickstart your deep learning project 🚀⚡🔥<br>
Click on [<kbd>Use this template</kbd>](https://github.com/ashleve/lightning-hydra-template/generate) to initialize new repository. Click on [<kbd>Use this template</kbd>](https://github.com/ashleve/lightning-hydra-template/generate) to initialize new repository.
*Suggestions are always welcome!* _Suggestions are always welcome!_
</div> </div>
@@ -52,8 +52,6 @@ It makes your code neatly organized and provides lots of useful features, like a
- **Hyperparameter Search**: made easier with Hydra built-in plugins like [Optuna Sweeper](https://hydra.cc/docs/next/plugins/optuna_sweeper) | [#Hyperparameter Search](#hyperparameter-search) - **Hyperparameter Search**: made easier with Hydra built-in plugins like [Optuna Sweeper](https://hydra.cc/docs/next/plugins/optuna_sweeper) | [#Hyperparameter Search](#hyperparameter-search)
- **Tests**: unit tests and shell/command based tests for speeding up the development | [#Tests](#tests) - **Tests**: unit tests and shell/command based tests for speeding up the development | [#Tests](#tests)
- **Best Practices**: a couple of recommended tools, practices and standards for efficient workflow and reproducibility | [#Best Practices](#best-practices) - **Best Practices**: a couple of recommended tools, practices and standards for efficient workflow and reproducibility | [#Best Practices](#best-practices)
<!-- - **Tricks**: a couple of sometimes useful tricks | [#Useful Tricks](#useful-tricks) -->
<!-- - **Extra Features**: optional utilities to make your life easier | [#Extra Features](#extra-features) -->
<br> <br>
@@ -657,43 +655,52 @@ hydra:
This means your working directory is different for every run, which might not be compatible with some libraries and workflows. By default, logs have the following structure: This means your working directory is different for every run, which might not be compatible with some libraries and workflows. By default, logs have the following structure:
``` ```
│
├── logs ├── logs
│ ├── experiments # Folder for logs generated by experiments │ ├── experiments # Folder for logs generated by experiments
│ │ ├── experiment_name # Name of the experiment │ │ ├── experiment_name # Name of the experiment
│ │ │ ├── 2021-02-15_16-50-49 # Date of execution │ │ │ ├── runs
│ │ │ │ ├── .hydra # Hydra logs │ │ │ │ ├── YYYY-MM-DD # Date of execution
│ │ │ │ ├── wandb # Weights&Biases logs │ │ │ │ │ ├── HH-MM-SS # Time of execution
│ │ │ │ ├── checkpoints # Training checkpoints │ │ │ │ │ │ ├── .hydra # Hydra logs
│ │ │ │ └── ... # Any other thing saved during training │ │ │ │ │ │ ├── wandb # Weights&Biases logs
│ │ │ └── ... │ │ │ │ │ │ ├── checkpoints # Training checkpoints
│ │ ├── ... │ │ │ │ │ │ └── ... # Any other thing saved during training
│ │ │ │ │ └── ...
│ │ │ │ └── ...
│ │ │ │
│ │ │ └── multiruns
│ │ │ ├── YYYY-MM-DD
│ │ │ │ ├── HH-MM-SS
│ │ │ │ │ ├── 1 # Multirun job number
│ │ │ │ │ │ └── ...
│ │ │ │ │ ├── 2
│ │ │ │ │ └── ...
│ │ │ │ └── ...
│ │ │ └── ...
│ │ └── ... │ │ └── ...
│ │ │ │
│ ├── debugs # Folder for logs generated during debugging │ ├── debugs # Folder for logs generated during debugging
│ │ ├── 2021-02-15 │ │ ├── runs
│ │ │ ├── 16-50-49 │ │ │ ├── YYYY-MM-DD
│ │ │ │ ├── HH-MM-SS
│ │ │ │ └── ...
│ │ │ └── ... │ │ │ └── ...
│ │ ├── ... │ │ └── multiruns
│ │ └── ... │ │ ├── YYYY-MM-DD
│ │ │ ├── HH-MM-SS
│ │ │ └── ...
│ │ └─ ...
│ │ │ │
│ ├── runs # Folder for logs generated by normal runs │ ├── runs # Folder for logs generated by normal runs
│ │ ├── 2021-02-15 │ │ ├── YYYY-MM-DD
│ │ │ ├── 16-50-49 │ │ │ ├── HH-MM-SS
│ │ │ │ └── ...
│ │ │ ├── ...
│ │ │ └── ... │ │ │ └── ...
│ │ ├── ...
│ │ └── ... │ │ └── ...
│ │ │ │
│ └── multiruns # Folder for logs generated by multiruns (sweeps) │ └── multiruns # Folder for logs generated by normal multiruns (sweeps)
│ ├── 2021-02-15_16-50-49 │ ├── YYYY-MM-DD
│ │ ├── 0 │ | ├── HH-MM-SS
│ │ │ └── ... │ | └── ...
│ │ ├── 1
│ │ ├── 2
│ │ └── ...
│ ├── ...
│ └── ... │ └── ...
│ │
``` ```
@@ -921,6 +928,7 @@ python run.py trainer.gpus=4 +trainer.accelerator="ddp"
### Reproducibility ### Reproducibility
What provides reproducibility: What provides reproducibility:
- Hydra manages your configs - Hydra manages your configs
- Hydra manages your logging paths and makes every executed run store its hyperparameters and config overrides in a separate file in logs - Hydra manages your logging paths and makes every executed run store its hyperparameters and config overrides in a separate file in logs
- Single seed for random number generators in pytorch, numpy and python.random - Single seed for random number generators in pytorch, numpy and python.random
@@ -931,19 +939,15 @@ What provides reproducibility:
- Example callbacks for wandb show how you can save and upload a snapshot of codebase every time the run is executed, as well as upload ckpts and track model gradients - Example callbacks for wandb show how you can save and upload a snapshot of codebase every time the run is executed, as well as upload ckpts and track model gradients
You can load the config of previous run using: You can load the config of previous run using:
```bash ```bash
python run.py --config-path /logs/runs/.../.hydra/ --config-name config.yaml python run.py --config-path /logs/runs/.../.hydra/ --config-name config.yaml
``` ```
The `config.yaml` from `.hydra` folder contains all overriden parameters and sections. This approach however is not officially supported by Hydra and doesn't override the `hydra/` part of the config, meaning logging paths will revert to default! The `config.yaml` from `.hydra` folder contains all overriden parameters and sections. This approach however is not officially supported by Hydra and doesn't override the `hydra/` part of the config, meaning logging paths will revert to default!
<br> <br>
<!--
### Extra Features
- Loading environment variables from `.env` file
- Forcing debug-friendly configuration when using `trainer.fast_dev_run=True` (disables GPU and multiprocessing)
-->
### Limitations ### Limitations
- Currently, template doesn't support k-fold cross validation, but it's possible to achieve it with Lightning Loop interface. See the [official example](https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pl_examples/loop_examples/kfold.py). Implementing it requires rewriting the training pipeline. - Currently, template doesn't support k-fold cross validation, but it's possible to achieve it with Lightning Loop interface. See the [official example](https://github.com/PyTorchLightning/pytorch-lightning/blob/master/pl_examples/loop_examples/kfold.py). Implementing it requires rewriting the training pipeline.
+1 -1
View File
@@ -71,6 +71,6 @@ callbacks:
logger: logger:
wandb: wandb:
name: ${name}_${now:%Y-%m-%d_%H-%M-%S} name: ${name}/${now:%Y-%m-%d}/${now:%H-%M-%S}
tags: ["best_model", "mnist"] tags: ["best_model", "mnist"]
notes: "Description of this model." notes: "Description of this model."
+2 -2
View File
@@ -18,9 +18,9 @@ hydra:
# sets output paths for all file logs to 'logs/debug/' # sets output paths for all file logs to 'logs/debug/'
run: run:
dir: logs/debug/${now:%Y-%m-%d}/${now:%H-%M-%S} dir: logs/debug/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
sweep: sweep:
dir: logs/debug/multirun_${now:%Y-%m-%d_%H-%M-%S} dir: logs/debug/multiruns/${now:%Y-%m-%d}/${now:%H-%M-%S}
subdir: ${hydra.job.num} subdir: ${hydra.job.num}
# disable rich config printing, since it will be already printed by hydra when `verbose: True` # disable rich config printing, since it will be already printed by hydra when `verbose: True`
+1 -1
View File
@@ -9,5 +9,5 @@ hydra:
run: run:
dir: logs/runs/${now:%Y-%m-%d}/${now:%H-%M-%S} dir: logs/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
sweep: sweep:
dir: logs/multiruns/${now:%Y-%m-%d_%H-%M-%S} dir: logs/multiruns/${now:%Y-%m-%d}/${now:%H-%M-%S}
subdir: ${hydra.job.num} subdir: ${hydra.job.num}
+2 -2
View File
@@ -11,7 +11,7 @@ name: ???
hydra: hydra:
# sets output paths for all file logs to `logs/experiment/name' # sets output paths for all file logs to `logs/experiment/name'
run: run:
dir: logs/experiments/${name}/${now:%Y-%m-%d_%H-%M-%S} dir: logs/experiments/${name}/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
sweep: sweep:
dir: logs/experiments/${name}/multirun_${now:%Y-%m-%d_%H-%M-%S} dir: logs/experiments/${name}/multiruns/${now:%Y-%m-%d}/${now:%H-%M-%S}
subdir: ${hydra.job.num} subdir: ${hydra.job.num}
Executable
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# This script allows to quickly change into the latest log dir of a specific kind.
# Should be executed from project root folder.
#
# Go to latest log dir from 'runs' folder:
# cd $(logs/latest logs/runs)
#
# Go to latest log dir from 'experiments' folder:
# cd $(logs/latest logs/experiments)
set -e
set -o pipefail
find "$1" -maxdepth 2 -type d | sort -r | head -n 1