PyTorch Lightning is a lightweight PyTorch wrapper designed to simplify the training and evaluation of deep learning models. It abstracts away common boilerplate code, allowing researchers and engineers to focus on model architecture and experimental logic. The library is actively maintained, currently at version 2.6.1, and follows a release cadence where minor versions may introduce backwards-incompatible changes with deprecations, and major versions may do so without.
pip install pytorch-lightningVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a minimal autoencoder training loop using `lightning`. It covers defining a `LightningModule`, setting up data loaders, and training with the `Trainer`. The code shows how Lightning automatically handles the training loop, backward passes, and optimizer steps, reducing boilerplate. A simple inference step is included to show how to use the trained model.
Update your `pip install` command to `pip install lightning`, change all `import pytorch_lightning` statements to `import lightning as L`, and migrate `Trainer` arguments to the new unified accelerator API. Consult the official migration guide for a detailed overview.
Use alternative methods for TorchScript export or refer to the latest Lightning documentation for recommended export patterns.
Remove explicit `.cuda()` or `.to(device)` calls for your model and tensors that are part of the training loop. Lightning will place them on the correct device. If initializing new tensors, use `new_tensor = torch.Tensor(...).to(existing_tensor)` to ensure correct device placement.
Do not manually instantiate `torch.utils.data.DistributedSampler` for your data loaders when using `lightning.Trainer` with a distributed strategy. Simply pass your standard `DataLoader` to `trainer.fit()`, and Lightning will handle the distributed sampling.
Install build dependencies in your Dockerfile (e.g., `RUN apk add --no-cache build-base` for Alpine) before `pip install`ing these libraries, or use a more comprehensive Python base image (e.g., `python:3.13` instead of `python:3.13-alpine`).