Registry / ai-ml / lightning-fabric

lightning-fabric

JSON →
library2.6.5pypypiunverified

Lightning Fabric is a lightweight, high-performance library for training deep learning models at scale with PyTorch. It provides core utilities for distributed training, mixed-precision, and device management, allowing users to write pure PyTorch code while Fabric handles the boilerplate. It is currently at version 2.6.1 and follows the release cadence of the broader Lightning ecosystem, typically with monthly or bi-monthly patch releases.

pip install lightning-fabric torch
INSTALL
IMPORT
SIG · LIGHTNING-FABRIC
L
lightning-fabric
ai-mlpythonv2.6.5
Install
80.9s avg
Import
Disk
4787MB
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
✕ build_error
✓ 97.1s
py 3.11
✕ build_error
✓ 80.2s
py 3.12
✕ build_error
✓ 76s
py 3.13
✕ build_error
✓ 70.2s
py 3.9
✕ build_error
✕ timeout
4787MB installed
● package 4787MB
Code
Verified usage

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

Fabric
from lightning.fabric import Fabric
from pytorch_lightning.fabric import Fabric
Fabric was introduced as part of the unified Lightning ecosystem (Lightning 2.0+). Older imports from `pytorch_lightning` might not contain `Fabric` or refer to deprecated structures.

This quickstart demonstrates how to use Lightning Fabric to set up a simple PyTorch model for training, leveraging Fabric for device management, mixed precision, and distributed training boilerplate. It covers initialization, model/optimizer/dataloader setup, and a basic training loop with a backward pass handled by Fabric.

import os import torch from torch.utils.data import DataLoader, TensorDataset from lightning.fabric import Fabric # 1. Initialize Fabric # Configure accelerators, devices, precision. E.g., Fabric(accelerator='cpu', precision='bf16') # For a basic setup, Fabric() will try to use available GPUs or CPU. fabric = Fabric( accelerator=os.environ.get('ACCELERATOR', 'auto'), devices=os.environ.get('DEVICES', 'auto'), precision=os.environ.get('PRECISION', '32-true') ) # 2. Define your model, optimizer, and data model = torch.nn.Linear(10, 2) optimizer = torch.optim.SGD(model.parameters(), lr=0.01) # Generate dummy data X = torch.randn(100, 10) y = torch.randint(0, 2, (100,)) dataset = TensorDataset(X, y) dataloader = DataLoader(dataset, batch_size=16) # 3. Setup the model, optimizer, and data for distributed training model, optimizer = fabric.setup(model, optimizer) dataloader = fabric.setup_dataloader(dataloader) # 4. Training loop fabric.print(f"Starting training on device: {fabric.device}") for epoch in range(3): for batch_idx, (data, target) in enumerate(dataloader): optimizer.zero_grad() output = model(data) loss = torch.nn.functional.cross_entropy(output, target) fabric.backward(loss) # Perform backward pass using Fabric optimizer.step() if batch_idx % 10 == 0: fabric.print(f"Epoch {epoch}, Batch {batch_idx}, Loss: {loss.item():.4f}") fabric.print("Training complete!") # Example of saving: fabric.save("model.pt", {"model": model.state_dict(), "optimizer": optimizer.state_dict()})
Debug
Known issues
breakingUsers migrating from PyTorch Lightning 1.x to the Lightning 2.x ecosystem (which includes Fabric) will encounter significant API changes. Fabric adopts a more explicit, less opinionated approach to distributed training and device placement compared to the `Trainer` in PL 1.x.
fix
Refer to the official Lightning Fabric 2.x documentation for updated API usage, especially for `Fabric` initialization, `setup`, and manual training loop construction.
affects: >=2.0.0
gotchaLightning Fabric provides low-level distributed training primitives. It does not include a full `Trainer` abstraction like `pytorch_lightning.Trainer`. Users are responsible for writing their own training loops, validation loops, and handling callbacks manually.
fix
Embrace the 'pure PyTorch' philosophy; use Fabric's `setup` methods and `backward` for core distributed operations, but manage the loop structure, metrics, and logging yourself.
affects: All versions
gotchaIncorrect device placement (e.g., calling `.cuda()` or `.to(device)` directly on tensors or modules after Fabric has already set them up) can lead to unexpected behavior or errors, especially in distributed environments.
fix
Always use `fabric.setup()` for your model and optimizer, and `fabric.setup_dataloader()` for your data loaders. Fabric will handle the device placement. Avoid manual `to(device)` calls on objects managed by Fabric.
affects: All versions
Upgrade
Version history
2.6.5latest on PyPI · released May 27, 2026
Audit
Dependencies
torchrequiredDeep learning backend
Agent activity
4 hits · last 30 days
node
4
Resources