Skip to content


pip install lighter


  • Configuration-based


    Define, reproduce, and share experiments through config files.

  • Task-agnostic


    Classification, segmentation, or self-supervised learning? Lighter can handle it.

  • Minimal


    Lighter handles the boilerplate, letting you run experiments with little to no code.

  • Customizable


    Add custom code seamlessly, whether it's models, datasets, or any other component.

Lighter vs. PyTorch Lightning

See how training a model on CIFAR-10 differs between Lighter and PyTorch Lightning.

Terminal
lighter fit config.yaml
config.yaml
trainer:
    _target_: pytorch_lightning.Trainer
    max_epochs: 2

system:
    _target_: lighter.System

    model:
        _target_: torchvision.models.resnet18
        num_classes: 10

    criterion:
        _target_: torch.nn.CrossEntropyLoss

    optimizer:
        _target_: torch.optim.Adam
        params: "$@system#model.parameters()"
        lr: 0.001

    dataloaders:
        train:
            _target_: torch.utils.data.DataLoader
            batch_size: 32
            shuffle: True
            dataset:
                _target_: torchvision.datasets.CIFAR10
                download: True
                root: .datasets
                train: True
                transform:
                    _target_: torchvision.transforms.Compose
                    transforms:
                        - _target_: torchvision.transforms.ToTensor
                        - _target_: torchvision.transforms.Normalize
                          mean: [0.5, 0.5, 0.5]
                          std: [0.5, 0.5, 0.5]
Terminal
python cifar10.py
cifar10.py
from pytorch_lightning import Trainer, LightningModule
from torch.nn import CrossEntropyLoss
from torch.optim import Adam
from torch.utils.data import DataLoader
from torchvision.models import resnet18
from torchvision.datasets import CIFAR10
from torchvision.transforms import ToTensor, Normalize, Compose


class Model(LightningModule):
    def __init__(self):
        super().__init__()
        self.model = resnet18(num_classes=10)
        self.criterion = CrossEntropyLoss()

    def forward(self, x):
        return self.model(x)

    def training_step(self, batch, batch_idx):
        x, y = batch
        y_hat = self(x)
        loss = self.criterion(y_hat, y)
        return loss

    def configure_optimizers(self):
        return Adam(self.model.parameters(), lr=0.001)


transform = Compose([
    ToTensor(),
    Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
])

train_dataset = CIFAR10(
    root=".datasets",
    train=True,
    download=True,
    transform=transform
)

train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)

model = Model()
trainer = Trainer(max_epochs=2)
trainer.fit(model, train_loader)

Next Steps

  • Tutorials


    Run your first experiments with step-by-step tutorials Start Learning

  • How-To Guides


    Learn about Lighter's advanced features with practical guides Learn More

  • Design


    Understand Lighter's design principles and architecture Read More

  • Reference


    Explore Lighter's classes, functions, and interfaces View API

Cite

@software{lighter,
    author       = {Ibrahim Hadzic and
                    Suraj Pai and
                    Keno Bressem and
                    Hugo Aerts},
    title        = {Lighter},
    publisher    = {Zenodo},
    doi          = {10.5281/zenodo.8007711},
    url          = {https://doi.org/10.5281/zenodo.8007711}
}