1 parent
3002778f68
commit
f4e0c3a75f
11 files changed
+34
-34
No files matched your search
@@ -1,9 +1,11 @@
|
||||
## Lightning + Hydra template for Deep Learning projects
|
||||
This is my starting template and pipeline for most deep learning projects.<br>
|
||||
Built with <b>PyTorch Lightning</b> and <b>Hydra</b>.<br>
|
||||
Also contains special <b>Weights&Biases</b> integration, but can be used with any other logger.<br>
|
||||
## PyTorch Lightning + Hydra template 🚀⚡🔥
|
||||
A clean and simple template and pipeline to kickstart your deep learning project!<br>
|
||||
|
||||
It's supposed to be enchancement/expansion on original [deep-learninig-project-template](https://github.com/PyTorchLightning/deep-learning-project-template) repository.<br>
|
||||
<b>[PyTorch Lightning](https://github.com/PyTorchLightning/pytorch-lightning)</b> provides great abstractions for well structured ML code and advanced features like checkpointing and gradient accumulation.<br>
|
||||
<b>[Hydra](https://github.com/facebookresearch/hydra)</b> provides convenient way to manage experiment configurations (see examples below).<br>
|
||||
Also available extra <b>[Weights&Biases](https://www.wandb.com/)</b> utilites, but template can be used with any other logger.<br>
|
||||
|
||||
It's supposed to be extended version of [deep-learninig-project-template](https://github.com/PyTorchLightning/deep-learning-project-template) repository.<br>
|
||||
I'm trying to make this as generic as possible - you should be able to easily modify behavior in [train.py](project/train.py) file in case you need some unconventional configuration wiring.<br>
|
||||
|
||||
The goal is to:
|
||||
@@ -20,21 +22,21 @@ Click on <b>`Use this template`</b> button above to initialize new repository.<b
|
||||
|
||||
## Features
|
||||
- Predefined folder structure
|
||||
- Modularity: all abstractions are splitted into different submodules
|
||||
- Automates training with PyTorch Lightning
|
||||
- You only need to create model and datamodule and specify them in configuration files
|
||||
- You only need to create model and datamodule and specify them in config and you can already run training
|
||||
- All advantages of Hydra
|
||||
- Main config file contains default training configuration ([config.yaml](project/configs/config.yaml))
|
||||
- Storing many experiment configurations in a convenient way ([project/configs/experiment](project/configs/experiment))
|
||||
- Composing configuration files out of other configuration files
|
||||
- Scheduling execution of many experiments from command line
|
||||
- Overriding any config parameter from command line
|
||||
- Scheduling execution of many experiments from command line
|
||||
- Sweeping over hyperparameters from command line
|
||||
- Command line tab completion
|
||||
- Logging history of all executed runs/experiments
|
||||
- ~~Automatically validate config structure with config schemas~~ (TODO)
|
||||
- Weights&Biases integration
|
||||
- optional Weights&Biases utilities for experiment tracking
|
||||
- Available callbacks that store all code files and model checkpoints as artifacts in Weights&Biases cloud ([wandb_callbacks.py](project/src/callbacks/wandb_callbacks.py))
|
||||
- Example wandb callbacks for generating confusion matrices and f1/precision/recall heatmaps ([wandb_callbacks.py](project/src/callbacks/wandb_callbacks.py))
|
||||
- Automatically watches the model
|
||||
- ~~Hyperparameter search with Weights&Biases sweeps ([execute_sweep.py](project/template_utils/execute_sweep.py))~~ (TODO)
|
||||
- Example of inference with trained model ([inference_example.py](project/src/utils/inference_example.py))
|
||||
- Built in requirements ([requirements.txt](requirements.txt))
|
||||
@@ -351,7 +353,7 @@ To create a sweep over some hyperparameters run:
|
||||
python train.py --multirun datamodule.batch_size=32,64,128 model.lr=0.001,0.0005
|
||||
```
|
||||
|
||||
## Import
|
||||
## Installing project as a package
|
||||
Optionally you can install project as a package with [setup.py](setup.py):
|
||||
```yaml
|
||||
pip install -e .
|
||||
@@ -362,13 +364,3 @@ from project.src.datasets.img_test_dataset import TestDataset
|
||||
from project.src.models.mnist_model import LitModelMNIST
|
||||
from project.src.datamodules.mnist_datamodule import MNISTDataModule
|
||||
```
|
||||
|
||||
## Citation
|
||||
```
|
||||
@article{YourName,
|
||||
title={Your Title},
|
||||
author={Your team},
|
||||
journal={Location},
|
||||
year={Year}
|
||||
}
|
||||
```
|
||||
@@ -50,7 +50,7 @@ logger: # you can add here additional lo
|
||||
tags: ["best_model", "uwu"]
|
||||
notes: "Description of this model."
|
||||
group: "mnist"
|
||||
comet:
|
||||
neptune:
|
||||
tags: ["best_model"]
|
||||
csv_logger:
|
||||
save_dir: "."
|
||||
@@ -2,6 +2,6 @@
|
||||
defaults:
|
||||
- csv_logger.yaml
|
||||
- wandb.yaml
|
||||
- comet.yaml
|
||||
- neptune.yaml
|
||||
- tensorboard.yaml
|
||||
# - comet.yaml
|
||||
# - tensorboard.yaml
|
||||
@@ -1,5 +1,5 @@
|
||||
# Comet logger config
|
||||
comet:
|
||||
_target_: pytorch_lightning.logger.CometLogger
|
||||
_target_: pytorch_lightning.loggers.comet.CometLogger
|
||||
api_key: ???
|
||||
project_name: "project_template_test"
|
||||
@@ -1,5 +1,5 @@
|
||||
# Csv logger config
|
||||
csv_logger:
|
||||
_target_: pytorch_lightning.loggers.CSVLogger
|
||||
_target_: pytorch_lightning.loggers.csv_logs.CSVLogger
|
||||
save_dir: "."
|
||||
name: "csv_logger/"
|
||||
@@ -1,3 +1,6 @@
|
||||
# Neptune logger config
|
||||
neptune:
|
||||
_target_: pytorch_lightning.logger.NeptuneLogger
|
||||
_target_: pytorch_lightning.loggers.neptune.NeptuneLogger
|
||||
project_name: "hobogalaxy/lightning-hydra-template-test"
|
||||
api_key: ${env:NEPTUNE_API_TOKEN} # api key is laoded from environment variable
|
||||
# experiment_name: "some_experiment"
|
||||
@@ -1,3 +1,3 @@
|
||||
# Tensorboard logger config
|
||||
tensorboard:
|
||||
_target_: pytorch_lightning.logger.TensorboardLogger
|
||||
_target_: pytorch_lightning.loggers.tensorboard.TensorboardLogger
|
||||
@@ -2,7 +2,7 @@
|
||||
wandb:
|
||||
_target_: pytorch_lightning.loggers.wandb.WandbLogger
|
||||
project: "env_tests"
|
||||
entity: "" # set to name of your wandb team or just remove it
|
||||
# entity: "" # set to name of your wandb team or just remove it
|
||||
offline: False # set True to store all logs only locally
|
||||
job_type: "train"
|
||||
save_dir: "."
|
||||
@@ -1,4 +1,5 @@
|
||||
# trainer args for debugging model
|
||||
_target_: pytorch_lightning.Trainer
|
||||
gpus: 0 # set -1 to train on all GPUs abailable, set 0 to train on CPU only
|
||||
# auto_select_gpus: True
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pytorch lightning imports
|
||||
import wandb
|
||||
from pytorch_lightning.loggers.wandb import WandbLogger
|
||||
from pytorch_lightning.loggers.neptune import NeptuneLogger
|
||||
import pytorch_lightning as pl
|
||||
|
||||
# hydra imports
|
||||
@@ -9,6 +9,8 @@ from omegaconf import DictConfig, OmegaConf
|
||||
# normal imports
|
||||
from typing import List
|
||||
import logging
|
||||
import neptune
|
||||
import wandb
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -42,9 +44,9 @@ def make_wandb_watch_model(loggers: List[pl.loggers.LightningLoggerBase], model:
|
||||
for logger in loggers:
|
||||
if isinstance(logger, WandbLogger):
|
||||
if hasattr(model, 'architecture'):
|
||||
logger.watch(model.architecture, log=None)
|
||||
logger.watch(model.architecture)
|
||||
else:
|
||||
logger.watch(model, log=None)
|
||||
logger.watch(model)
|
||||
|
||||
|
||||
def send_hparams_to_loggers(loggers: List[pl.loggers.LightningLoggerBase], hparams: dict):
|
||||
@@ -91,3 +93,4 @@ def extras(config, model, datamodule, callbacks, loggers, trainer):
|
||||
|
||||
def finish():
|
||||
wandb.finish()
|
||||
neptune.stop()
|
||||
+3
-2
@@ -1,10 +1,11 @@
|
||||
torch>=1.7.1
|
||||
torchvision>=0.8.2
|
||||
torchaudio>=0.7.2
|
||||
pytorch-lightning>=1.1.4
|
||||
pytorch-lightning>=1.1.6
|
||||
# hydra-core>=1.0.5
|
||||
hydra-core>=1.1.0.dev2
|
||||
wandb>=0.10.14
|
||||
wandb>=0.10.15
|
||||
neptune-client>=0.5.0
|
||||
scikit-learn>=0.24.0
|
||||
pandas>=1.2.0
|
||||
hydra_colorlog>=1.0.0
|
||||
Reference in new issue
Block a user