Lightning is a deep learning framework built on PyTorch, simplifying the training, deployment, and scaling of AI models. It abstracts away boilerplate code, allowing researchers and engineers to focus on model logic. The current stable version is 2.6.1, and it maintains a rapid release cadence with minor versions typically released every 1-2 months, alongside frequent patch updates.
pip install lightningVerified import paths — ran on the pinned version, not inferred.
This quickstart defines a simple linear model using `LightningModule`, prepares dummy data with `DataLoader`, and trains it using the `Trainer`. It showcases the minimal setup for defining a model, training step, optimizer, and running a training loop.
Update all import statements, e.g., `from pytorch_lightning import Trainer` should become `from lightning.pytorch import Trainer`.
Change `return [optimizer]` to `return optimizer` when only one optimizer is configured.
Trust Lightning's device management. If you need to initialize tensors on the correct device, use `self.device` inside your `LightningModule` or access `trainer.device` if available.
Refer to the official PyTorch documentation or Lightning's export guide for the recommended way to convert models to TorchScript or other deployment formats.
Update your CLI commands to use `lightning run model` followed by your script and arguments. For example, `python train.py --config config.yaml` might become `lightning run model train.py --config config.yaml`.
Use a Python version officially supported by PyTorch (e.g., 3.8-3.12 for current PyTorch releases) or await official PyTorch wheels for Python 3.13. Building PyTorch from source on Alpine Linux can be complex and is often not recommended for general use.
Update your import statements from `import pytorch_lightning as pl` to `import lightning.pytorch as pl` or `import lightning as L`. Ensure you have installed the `lightning` package (`pip install lightning`).
Ensure the `lightning` package is installed: `pip install lightning`. If you are using an older codebase, you might need `pip install pytorch_lightning`. Verify your Python environment and package paths.
Change your import statement from `from pytorch_lightning import LightningModule` to `from lightning.pytorch import LightningModule`. Similarly, update other imports like `Trainer`.
Ensure your model class explicitly inherits from `lightning.pytorch.LightningModule` (e.g., `class MyModel(L.LightningModule): ...`) and that you are passing an instantiated object of this class to `trainer.fit()`.
Common solutions include: reducing the learning rate, gradient clipping (`gradient_clip_val` in `Trainer`), using a more stable optimizer, checking your loss function implementation for potential numerical issues, ensuring data preprocessing is robust, or debugging with `Trainer(detect_anomaly=True)` to pinpoint the exact operation causing the NaNs.