Skip to content

insane-group/pytorch-lightning-template

arXiv Mkdocs Open In Colab CI pre-commit LICENSE

Project Name

Accompanying code for the paper Paper Title.

Add a brief description of your project here. You can use Markdown syntax for formatting, such as bold, italics, and links.

Make sure you:

  • Replace the Project Name with the name of your project
  • Add a brief description of your project
  • Remove the πŸ€” Why ? section
  • Rename the project appropriately
  • Change the project details (e.g. name, description, URLs) in the following files:
    • pyproject.toml
    • mkdocs.yml
    • README.md
  • Update CITATION.cff (and the πŸ“‘ Citation section below)
  • Update the arXiv badge in the README.md with the correct arXiv ID (when available)
  • Update the logo in the README.md

πŸ€” Why ?

When working on a new project, we frequently encountered challenges such as:

  1. Reproducibility: How can we ensure that our results are reproducible across different environments?
  2. Boilerplate Code: We often find ourselves writing the same boilerplate code over and over again.

To address these challenges, we have created a template for PyTorch projects that streamlines the setup process and helps you focus on your research.

Main Technologies

  • PyTorch Lightning: A lightweight wrapper for PyTorch that streamlines high-performance AI research. It serves as a structured framework for organizing PyTorch code.
  • Hydra: A powerful configuration framework for managing complex applications. It enables dynamic composition of hierarchical configurations, allowing overrides via config files and the command line.

πŸš€ Getting Started

Click Use this template to create a new repository.

Once your repository is set up using the template, clone it and start working with the following commands (We use the Rye Python package manager):

# Install Rye (https://rye.astral.sh/guide/installation/)
curl -sSf https://rye.astral.sh/get | bash

# Clone the repository & cd into it
git clone https://github.com/insane-group/<YOUR-PROJECT-NAME>
cd <YOUR-PROJECT-NAME>

# Rename the project and make sure you change the project details (e.g. name, description, URLs) in the following files:
# 1. pyproject.toml
# 2. mkdocs.yml
# 3. README.md
mv src/project src/<YOUR-PROJECT-NAME>

# Install dependencies using Rye
rye sync

# Activate the virtual environment
source .venv/bin/activate

# Install the pre-commit hooks
poe hooks

# Run the training/evaluation script
# Override any config parameter from command line
python src/project/train.py trainer.max_epochs=20 model.optimizer.lr=1e-4
# train on CPU
python src/project/train.py trainer=cpu
# train on 1 GPU
python src/project/train.py trainer=gpu
# test checkpoint on test dataset
python src/project/test.py checkpoint="/path/to/ckpt/name.ckpt"

Feel free to share any relevant details to help others get started, for example, content similar to the Setup and Quickstart sections in Google’s Prompt-to-Prompt.

Performing tasks using poethepoet

We are using poethepoet, to perform various development oriented tasks. Formatting, type-checking, as well as a few other operations, can be performed by running

poe <task>

where <task> is one of the tasks listed by running:

poe --help
Poe the Poet - A task runner that works well with poetry.
version 0.28.0

Result: No task specified.

Usage:
  poe [global options] task [task arguments]

Global options:
  -h, --help            Show this help page and exit
  --version             Print the version and exit
  -v, --verbose         Increase command output (repeatable)
  -q, --quiet           Decrease command output (repeatable)
  -d, --dry-run         Print the task contents but don't actually run it
  -C PATH, --directory PATH
                        Specify where to find the pyproject.toml
  -e EXECUTOR, --executor EXECUTOR
                        Override the default task executor
  --ansi                Force enable ANSI output
  --no-ansi             Force disable ANSI output

Configured tasks:
  clean                 Clean up any auxiliary files
  format                Format your codebase
  hooks                 Run all pre-commit hooks
  test                  Run the test suite
  type-check            Run static type checking on your codebase
  lint                  Lint your code for errors
  docs                  Build and serve the documentation

Consider installing poe as global dependency to make your life easier using rye install poethepoet πŸ˜›.

πŸ“‚ Project Structure

The project follows a standard structure for a Python project.

β”œβ”€β”€ CITATION.cff                                 <- Citation file for referencing the project
β”œβ”€β”€ configs                                      <- Hydra configuration files
β”‚   β”œβ”€β”€ callbacks                                  <- Configs for training callbacks
β”‚   β”œβ”€β”€ data                                       <- Configs for loading the dataset
β”‚   β”œβ”€β”€ hydra                                      <- Hydra-specific settings
β”‚   β”œβ”€β”€ loggers                                    <- Configs for logging
β”‚   β”œβ”€β”€ model                                      <- Model-specific config
β”‚   β”œβ”€β”€ test.yaml                                  <- Test configuration file
β”‚   β”œβ”€β”€ trainer                                    <- Configs for the training loop
β”‚   └── train.yaml                                 <- Training configuration file
β”œβ”€β”€ data                                         <- Dataset storage directory
β”œβ”€β”€ docs                                         <- Project documentation
β”‚   β”œβ”€β”€ code                                       <- Source code documentation
β”‚   β”œβ”€β”€ CODE_OF_CONDUCT.md                         <- Guidelines for community behavior
β”‚   β”œβ”€β”€ CONTRIBUTING.md                            <- Instructions for contributing to the project
β”‚   β”œβ”€β”€ images                                     <- Images used in documentation
β”‚   β”œβ”€β”€ LICENSE.md                                 <- License information
β”‚   β”œβ”€β”€ index.md                                   <- Main documentation page
β”‚   └── welcome.md                                 <- Welcome page for the project
β”œβ”€β”€ .editorconfig                                <- Editor configuration for consistent formatting
β”œβ”€β”€ .github                                      <- GitHub-specific configurations
β”‚   └── workflows                                  <- CI/CD workflow definitions for GitHub Actions
β”œβ”€β”€ .gitignore                                   <- Files and directories to ignore in Git
β”œβ”€β”€ logs                                         <- Logs generated during training/testing
β”œβ”€β”€ models                                       <- Trained models and related files
β”œβ”€β”€ notebooks                                    <- Jupyter notebooks for experiments and analysis
β”‚   └── template.ipynb                             <- Notebook template for new experiments
β”œβ”€β”€ .pre-commit-config.yaml                      <- Pre-commit hook configurations
β”œβ”€β”€ src                                          <- Source code directory
β”‚   └── project                                    <- Main project codebase
β”œβ”€β”€ tests                                        <- Unit tests for the project
β”‚   β”œβ”€β”€ __init__.py                                <- Init file for test module
β”‚   └── test_model.py                              <- Tests for model functionality
β”œβ”€β”€ LICENSE                                      <- License information for the project
β”œβ”€β”€ README.md                                    <- Main project README file
β”œβ”€β”€ mkdocs.yml                                   <- Configuration for MkDocs documentation site
β”œβ”€β”€ pyproject.toml                               <- Python project configuration file
β”œβ”€β”€ .python-version                              <- Python version specification
β”œβ”€β”€ requirements-dev.lock                        <- Locked dependencies for development
β”œβ”€β”€ requirements.lock                            <- Locked dependencies for production
└── .vscode                                      <- VS Code workspace settings
    β”œβ”€β”€ extensions.json                            <- Recommended extensions for VS Code
    β”œβ”€β”€ launch.json                                <- Debugging configurations
    └── settings.json                              <- VS Code-specific settings

πŸ“– Exploring the Documentation

The documentation is generated from Python docstrings using MkDocs and mkdocstrings for the source code, while the rest is written in standard Markdown. To view it, run poe docs in the terminal or visit https://insane-group.github.io/pytorch-lightning-template/.

πŸ“‘ Citation

Please use the following citation if you use this project in your work:

@software{Sioros_scikit-learn-template,
  author = {Sioros, Vassilis},
  license = {Apache-2.0},
  title = {{scikit-learn-template}},
  url = {https://github.com/insane-group/scikit-learn-template}
}

πŸͺ™ Credits

This template was created by INSANE Group and is based on the following projects:

About

Generic template to bootstrap your PyTorch project

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks