An open API service indexing awesome lists of open source software.

https://github.com/willyfh/lightning-hydra-boilerplate

A project boilerplate for deep learning experiments using PyTorch Lightning and Hydra, designed for rapid prototyping, clean configuration management, and scalable research workflows.
https://github.com/willyfh/lightning-hydra-boilerplate

artificial-intelligence boilerplate deep-learning hydra lightning machine-learning pytorch pytorch-lightning research-tool

Last synced: about 1 month ago
JSON representation

A project boilerplate for deep learning experiments using PyTorch Lightning and Hydra, designed for rapid prototyping, clean configuration management, and scalable research workflows.

Awesome Lists containing this project

README

        


⚔ Lightning-Hydra-Boilerplate

[![python](https://img.shields.io/badge/python-3.12-blue)]() [![Run Tests](https://github.com/willyfh/lightning-hydra-boilerplate/actions/workflows/pytest.yaml/badge.svg)](https://github.com/willyfh/lightning-hydra-boilerplate/actions/workflows/pytest.yaml)

A project boilerplate for deep learning experiments using PyTorch Lightning and Hydra, designed for rapid prototyping, clean configuration management, and scalable research workflows.

āš ļø _This project is in its early stages and still under active development. Expect breaking changes and incomplete features._

## šŸ“ Project Structure

```plaintext
lightning-hydra-boilerplate/
│── configs/ # YAML configurations for Hydra
│ ā”œā”€ā”€ data/
│ │ ā”œā”€ā”€ example_data.yaml
│ ā”œā”€ā”€ model/
│ │ ā”œā”€ā”€ example_model.yaml
│ ā”œā”€ā”€ trainer/
│ │ ā”œā”€ā”€ default.yaml
│ ā”œā”€ā”€ train.yaml
│ ā”œā”€ā”€ eval.yaml
│ ā”œā”€ā”€ predict.yaml
│
│── src/ # Core codebase
│ ā”œā”€ā”€ data/
│ │ ā”œā”€ā”€ example_data/
│ │ │ ā”œā”€ā”€ lightning_datamodule.py
│ │ │ ā”œā”€ā”€ torch_dataset.py
│ ā”œā”€ā”€ model/
│ │ ā”œā”€ā”€ example_model/
│ │ │ ā”œā”€ā”€ lightning_module.py
│ │ │ ā”œā”€ā”€ torch_model.py
│ ā”œā”€ā”€ utils/
│ ā”œā”€ā”€ train.py # Training entrypoint
│ ā”œā”€ā”€ eval.py # Evaluation entrypoint
│ ā”œā”€ā”€ predict.py # Inference entrypoint (for making predictions)
│
│── tests/ # Unit tests
│
│── .gitignore
│── LICENSE
│── poetry.lock
│── pyproject.toml
│── README.md
```

## šŸš€ Getting Started

### **1ļøāƒ£ Install Dependencies**

This project uses **Poetry** for dependency management.

```bash
pip install poetry # If you haven't installed Poetry yet
poetry install
```

### **2ļøāƒ£ Train a Model**

Run the training script with the default configurations:

```bash
poetry run python src/train.py
```

This will:

- Train the model on the training set
- Validate during training using the validation set
- Test the final model on the test set (unless `skip_test=true` is set)

### **3ļøāƒ£ Evaluate a Model**

If you need to run evaluation independently on a specific checkpoint and dataset split (val or test), use the evaluation script:

```bash
poetry run python src/eval.py data_split=test ckpt_path=/path/to/checkpoint.ckpt
```

### **4ļøāƒ£ Predict Outputs**

To generate predictions from a trained model (e.g., for submission or analysis), run the predict.py script with the path to your checkpoint:

```bash
poetry run python src/predict.py ckpt_path=/path/to/checkpoint.ckpt
```

This will:

- Run inference on the prediction set (defaults to `test` set)
- Save the results to a file (e.g., predictions.csv or predictions.json depending on `save_format`) under the Hydra run directory

### **5ļøāƒ£ Experiment Configuration**

All experiment settings are managed with Hydra.

You can modify the configs under configs/ or override them via CLI. For example:

```bash
poetry run python src/train.py trainer.max_epochs=10
```

More info: https://hydra.cc/docs/intro/

### **6ļøāƒ£ Outputs**

All run outputs are saved under the `outputs/` directory:

```plaintext
outputs/
ā”œā”€ā”€ train/ ← training logs, checkpoints, config snapshots
ā”œā”€ā”€ eval/ ← evaluation logs and results
ā”œā”€ā”€ predict/ ← prediction files (e.g. .csv, .json)
```

Each run is timestamped for easy tracking and reproducibility.

## āœ… Completed Tasks

- [x] Initial project setup with PyTorch Lightning and Hydra
- [x] Basic training workflow with example model and data
- [x] TensorBoard logging support
- [x] Poetry setup
- [x] Configurable Callbacks (EarlyStopping, ModelCheckpoint, etc.)
- [x] Run test after training
- [x] Setup pre-commit setup
- [x] Setup tests
- [x] Setup dependabot
- [x] Add logger
- [x] Organize `logs/`, `checkpoints/` (Lightning), and `outputs/` (Hydra) properly
- [x] Evaluation script (`eval.py`)
- [x] Inference script (`predict.py`)

## šŸ“ TODO List

āš ļø _Feel free to fork the repo, create a PR, or open an issue if you spot anything or have ideas. I’d love to hear your feedback and make this more useful for everyone!_

- [ ] Hyperparameter tuning with Optuna
- [ ] Check Multi-GPU
- [ ] Add more Lightning Trainer features (resume, callbacks, etc.)
- [ ] MLflow and/or Wandb
- [ ] Docker support for easy deployment
- [ ] Make metrics configurable
- [ ] Add task-specific examples and configs (e.g., object detection, text classification, etc.)
- [ ] Add experiment configs for reusable training/eval setups (e.g., `configs/experiments/exp1.yaml`)

## šŸ“œ License

This project is licensed under the MIT License.