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
+59 -39

No files matched your search

+37 -33
View File
@@ -11,7 +11,7 @@
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.
*Suggestions are always welcome!*
_Suggestions are always welcome!_
</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)
- **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)
<!-- - **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>
@@ -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:
```
│
├── logs
│ ├── experiments # Folder for logs generated by experiments
│ │ ├── experiment_name # Name of the experiment
│ │ │ ├── 2021-02-15_16-50-49 # Date of execution
│ │ │ │ ├── .hydra # Hydra logs
│ │ │ │ ├── wandb # Weights&Biases logs
│ │ │ │ ├── checkpoints # Training checkpoints
│ │ │ │ └── ... # Any other thing saved during training
│ │ │ ├── runs
│ │ │ │ ├── YYYY-MM-DD # Date of execution
│ │ │ │ │ ├── HH-MM-SS # Time of execution
│ │ │ │ │ │ ├── .hydra # Hydra logs
│ │ │ │ │ │ ├── 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
│ │ ├── 2021-02-15
│ │ │ ├── 16-50-49
│ │ ├── runs
│ │ │ ├── YYYY-MM-DD
│ │ │ │ ├── HH-MM-SS
│ │ │ │ └── ...
│ │ │ └── ...
│ │ ├── ...
│ │ └── ...
│ │ └── multiruns
│ │ ├── YYYY-MM-DD
│ │ │ ├── HH-MM-SS
│ │ │ └── ...
│ │ └─ ...
│ │
│ ├── runs # Folder for logs generated by normal runs
│ │ ├── 2021-02-15
│ │ │ ├── 16-50-49
│ │ │ │ └── ...
│ │ │ ├── ...
│ │ ├── YYYY-MM-DD
│ │ │ ├── HH-MM-SS
│ │ │ └── ...
│ │ ├── ...
│ │ └── ...
│ │
│ └── multiruns # Folder for logs generated by multiruns (sweeps)
│ ├── 2021-02-15_16-50-49
│ │ ├── 0
│ │ │ └── ...
│ │ ├── 1
│ │ ├── 2
│ │ └── ...
│ ├── ...
│ └── multiruns # Folder for logs generated by normal multiruns (sweeps)
│ ├── YYYY-MM-DD
│ | ├── HH-MM-SS
│ | └── ...
│ └── ...
│
```
@@ -921,6 +928,7 @@ python run.py trainer.gpus=4 +trainer.accelerator="ddp"
### Reproducibility
What provides reproducibility:
- 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
- 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
You can load the config of previous run using:
```bash
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!
<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
- 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:
wandb:
name: ${name}_${now:%Y-%m-%d_%H-%M-%S}
name: ${name}/${now:%Y-%m-%d}/${now:%H-%M-%S}
tags: ["best_model", "mnist"]
notes: "Description of this model."
+2 -2
View File
@@ -18,9 +18,9 @@ hydra:
# sets output paths for all file logs to 'logs/debug/'
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:
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}
# 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:
dir: logs/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
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}
+2 -2
View File
@@ -11,7 +11,7 @@ name: ???
hydra:
# sets output paths for all file logs to `logs/experiment/name'
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:
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}
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