Registry / ai-ml / lightning

lightning

JSON →
library2.6.5pypypi✓ verified 25d ago

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 lightning
INSTALL
IMPORT
SIG · LIGHTNING
L
lightning
ai-mlpythonv2.6.5
Install
73.5s avg
Import
13150ms
Disk
4838MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.6.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ dependency_conflict
✓ 83.4s
py 3.11
✕ dependency_conflict
✓ 76.8s
py 3.12
✕ dependency_conflict
✓ 69.5s
py 3.13
✕ no_wheel
✓ 64.3s
py 3.9
✕ dependency_conflict
✕ timeout
4838MB installed
● package 4838MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LightningModule
from lightning.pytorch import LightningModule
from pytorch_lightning import LightningModule
The package name for PyTorch-specific components changed from 'pytorch_lightning' to 'lightning.pytorch' in v2.0.
Trainer
from lightning.pytorch import Trainer
from pytorch_lightning import Trainer
The package name for PyTorch-specific components changed from 'pytorch_lightning' to 'lightning.pytorch' in v2.0.
ModelCheckpoint
from lightning.pytorch.callbacks import ModelCheckpoint
LightningDataModule
from lightning.pytorch.utilities.data import LightningDataModule

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.

import torch from torch.utils.data import DataLoader, TensorDataset from lightning.pytorch import LightningModule, Trainer class SimpleModel(LightningModule): def __init__(self): super().__init__() self.linear = torch.nn.Linear(10, 1) def training_step(self, batch, batch_idx): x, y = batch y_hat = self.linear(x) loss = torch.nn.functional.mse_loss(y_hat, y) self.log('train_loss', loss) return loss def configure_optimizers(self): optimizer = torch.optim.Adam(self.parameters(), lr=0.02) return optimizer # 1. Prepare dummy data x_data = torch.randn(100, 10) y_data = torch.randn(100, 1) dataset = TensorDataset(x_data, y_data) dataloader = DataLoader(dataset, batch_size=32) # 2. Instantiate model and trainer model = SimpleModel() trainer = Trainer(max_epochs=5, enable_progress_bar=False, enable_checkpointing=False) # 3. Train the model trainer.fit(model, dataloader) print("Training complete for a simple Lightning model.")
lightning --version
Debug
Known issues
breakingThe primary package name for PyTorch-specific components was renamed from `pytorch_lightning` to `lightning.pytorch` in v2.0. Direct imports from the old name will fail.
fix
Update all import statements, e.g., `from pytorch_lightning import Trainer` should become `from lightning.pytorch import Trainer`.
affects: >=2.0.0
breakingThe return signature for `LightningModule.configure_optimizers()` changed. For a single optimizer, it should now return just the optimizer instance directly, not a list containing a single optimizer.
fix
Change `return [optimizer]` to `return optimizer` when only one optimizer is configured.
affects: >=2.0.0
gotchaLightning automatically handles device placement for models, data, and optimizers. Manually calling `.to(device)` on models or tensors within `training_step` or similar methods is usually unnecessary and can lead to bugs or redundant operations.
fix
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.
affects: all
deprecatedThe `to_torchscript` method on `LightningModule` has been deprecated.
fix
Refer to the official PyTorch documentation or Lightning's export guide for the recommended way to convert models to TorchScript or other deployment formats.
affects: >=2.6.1
gotchaThe `LightningCLI` command-line interface changed its execution pattern. Instead of `python your_script.py fit`, it now uses `lightning run model your_script.py`.
fix
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`.
affects: >=2.0.0
breakingInstallation of `lightning` fails on Python 3.13 because its `torch` dependency does not have pre-built wheels available for this Python version, especially on Alpine Linux. The error 'no matching distributions available for your environment: torch' indicates this.
fix
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.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytorch_lightning'
The `pytorch_lightning` package has been renamed to `lightning` since version 2.0.0. Code written for older versions will try to import from the old package name.
fix
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`).
ModuleNotFoundError: No module named 'lightning'
This error occurs if the `lightning` package is not installed or if there's an environment issue, or if you're trying to use `lightning` but only `pytorch_lightning` is installed. It can also occur in specific environments like Docker images where the module might be installed under a different name or path.
fix
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.
AttributeError: module 'pytorch_lightning' has no attribute 'LightningModule'
This `AttributeError` typically arises when code expects `LightningModule` to be directly accessible under the `pytorch_lightning` namespace, which changed after the package was renamed to `lightning` (version 2.0.0 onwards). The correct import path for `LightningModule` shifted.
fix
Change your import statement from `from pytorch_lightning import LightningModule` to `from lightning.pytorch import LightningModule`. Similarly, update other imports like `Trainer`.
TypeError: `Trainer.fit()` requires a `LightningModule`, got: ...
This error means that the object passed to the `Trainer.fit()` method is not an instance of `lightning.pytorch.LightningModule` (or `pytorch_lightning.LightningModule` for older versions). This often happens if your model class does not correctly inherit from `LightningModule` or if you've mistakenly passed a different type of object.
fix
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()`.
Lightning will terminate the training loop with an error message if NaN or infinite values are detected.
This is a runtime warning/error indicating that your model's loss or parameters have become numerically unstable (Not a Number or infinity). This can be caused by various factors, such as high learning rates, unstable loss functions, issues with mixed-precision training (FP16), or bad data.
fix
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.
Upgrade
Version history
2.6.5latest on PyPI · released May 27, 2026
Audit
Dependencies
torchrequiredCore dependency for deep learning models. While not strictly required by 'pip install lightning', it is implicitly required for any practical use of the framework and should be installed separately (e.g., 'pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121').
Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
1
Resources
lightning — pip install lightning · libregistry