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.
- Host: GitHub
- URL: https://github.com/willyfh/lightning-hydra-boilerplate
- Owner: willyfh
- License: mit
- Created: 2025-04-04T15:31:40.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2025-04-06T15:49:55.000Z (about 1 month ago)
- Last Synced: 2025-04-09T22:53:53.160Z (about 1 month ago)
- Topics: artificial-intelligence, boilerplate, deep-learning, hydra, lightning, machine-learning, pytorch, pytorch-lightning, research-tool
- Language: Python
- Homepage:
- Size: 72.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ā” Lightning-Hydra-Boilerplate
[]() [](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.