General improvements (#88)

* remove unnecessary linters from pre-commit-config

* hook fix

* small improvements

* fix readme

* implement easier access to debug mode

* fix tests

* Update README.md

* Update README.md
This commit is contained in:
Łukasz Zalewski authored and GitHub committed 2021-03-08 15:53:30 +01:00
1 parent 5385a2ec98
commit 3d301977b3
14 files changed
+176 -113

No files matched your search

+56 -27
View File
@@ -22,8 +22,8 @@ You should be able to easily modify behavior in [train.py](train.py) in case you
If you use this template please add <br>
[![](https://shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat&logo=github&labelColor=001A22)](https://github.com/hobogalaxy/lightning-hydra-template) <br>
to you `README.md`.
[![](https://shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat&logo=github&labelColor=303030)](https://github.com/hobogalaxy/lightning-hydra-template) <br>
to your `README.md`.
<br>
@@ -33,7 +33,7 @@ to you `README.md`.
- [Main Ideas](#main-ideas)
- [Some Notes](#some-notes)
- [Project Structure](#project-structure)
- [Quick Setup](#quick-setup)
- [Quickstart](#quickstart)
- [Your Superpowers](#your-superpowers)
- [Features](#features)
- [Main Project Configuration](#main-project-configuration)
@@ -139,14 +139,13 @@ The directory structure of new project looks like this:
<br>
## Quick Setup
Install dependencies:
## Quickstart
```yaml
# clone project
git clone https://github.com/hobogalaxy/lightning-hydra-template
cd lightning-hydra-template
# optionally create conda environment
# [OPTIONAL] create conda environment
conda env create -f conda_env_gpu.yaml -n testenv
conda activate testenv
@@ -154,14 +153,16 @@ conda activate testenv
pip install -r requirements.txt
```
When running `python train.py` you should see this:
When running `python train.py` you should see something like this:
<div align="center">
![](https://github.com/hobogalaxy/lightning-hydra-template/blob/resources/teminal.png)
</div>
### Your Superpowers
(click to expand)
<details>
<summary>Override any config parameter from command line</summary>
@@ -171,6 +172,7 @@ python train.py trainer.max_epochs=20 model.lr=0.0005
</details>
<details>
<summary>Train on GPU</summary>
@@ -180,6 +182,7 @@ python train.py trainer.gpus=1
</details>
<details>
<summary>Train model with any logger available in PyTorch Lightning, like <a href="https://wandb.ai/">Weights&Biases</a></summary>
@@ -197,6 +200,7 @@ python train.py logger=wandb
</details>
<details>
<summary>Train model with chosen experiment config</summary>
@@ -207,6 +211,7 @@ python train.py +experiment=exp_example_simple
</details>
<details>
<summary>Execute all experiments from folder</summary>
@@ -217,6 +222,7 @@ python train.py -m '+experiment=glob(*)'
</details>
<details>
<summary>Attach some callbacks to run</summary>
@@ -227,6 +233,31 @@ python train.py callbacks=default_callbacks
</details>
<details>
<summary>Easily debug</summary>
```yaml
# run 1 train, val and test loop, using only 1 batch
python train.py debug=True
```
</details>
<details>
<summary>Resume training from checkpoint</summary>
```yaml
# checkpoint can be either path or URL
# path should be absolute!
python train.py trainer.resume_from_checkpoint="/home/user/X/lightning-hydra-template/logs/runs/2021-02-28/16-50-49/checkpoints/last.ckpt"
# currently loading ckpt in Lightning doesn't resume logger experiment, this should change when v1.3 is released...
```
</details>
<details>
<summary>Create a sweep over some hyperparameters </summary>
@@ -238,32 +269,18 @@ python train.py -m datamodule.batch_size=32,64,128 model.lr=0.001,0.0005
</details>
<details>
<summary>Create a sweep over some hyperparameters with Optuna</summary>
```yaml
# this will run hyperparameter search defined in `configs/config_optuna.yaml`
# this will run hyperparameter search defined in `configs/config_optuna.yaml`
# over chosen experiment config
python train.py -m --config-name config_optuna.yaml +experiment=exp_example_simple
```
</details>
<details>
<summary>Resume training from checkpoint</summary>
(TODO)
<!--
```yaml
# checkpoint can be either path or URL
# path should be either absolute or prefixed with `${work_dir}/`
# use quotes '' around argument or otherwise $ symbol breaks it
python train.py '+trainer.resume_from_checkpoint=${work_dir}/logs/runs/2021-02-28/16-50-49/checkpoints/last.ckpt'
```
-->
</details>
<br>
@@ -316,6 +333,11 @@ work_dir: ${hydra:runtime.cwd}
data_dir: ${work_dir}/data/
# use `python train.py debug=true` for easy debugging!
# (equivalent to running `python train.py trainer.fast_dev_run=True`)
debug: False
# pretty print config at the start of the run using Rich library
print_config: True
@@ -328,20 +350,27 @@ disable_warnings: False
disable_lightning_logs: False
# output paths for hydra logs
# hydra configuration
hydra:
# output paths for hydra logs
run:
dir: logs/runs/${now:%Y-%m-%d}/${now:%H-%M-%S}
sweep:
dir: logs/multiruns/${now:%Y-%m-%d_%H-%M-%S}
subdir: ${hydra.job.num}
# set your environment variables here
job:
env_set:
ENV_VAR_X: something
```
<br>
## Experiment Configuration
Location: [configs/experiment](configs/experiment)<br>
You can store many experiment configurations in this folder.<br>
You should store all your experiment configurations in this folder.<br>
### Simple Example
```yaml
# to execute this experiment run:
@@ -535,7 +564,7 @@ choosing metric names with '/' for wandb -->
<a href="https://pytorch.org/get-started/locally/"><img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-orange?logo=pytorch"></a>
<a href="https://pytorchlightning.ai/"><img alt="Lightning" src="https://img.shields.io/badge/-Lightning-blueviolet"></a>
<a href="https://hydra.cc/"><img alt="Config: Hydra" src="https://img.shields.io/badge/Config-Hydra-blue"></a>
[![](https://shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat&logo=github&labelColor=001A22)](https://github.com/hobogalaxy/lightning-hydra-template)
[![](https://shields.io/badge/-Lightning--Hydra--Template-017F2F?style=flat&logo=github&labelColor=303030)](https://github.com/hobogalaxy/lightning-hydra-template)
</div>