Lightning open source
Open-source libraries for training and serving AI models at scale. Powering generative AI since 2015.
# pip install lightningimport lightning as Lmodel = LitAutoEncoder() # any LightningModuletrainer = L.Trainer(accelerator="gpu", devices=8, strategy="fsdp")trainer.fit(model, train_loader)Python frameworks to trainand deploy models, Lightning fast
Six open-source libraries for the whole model lifecycle, from data loading and training to evaluation and serving.
Pretrain and finetune AI models of any size on one or many GPUs. Includes Lightning Fabric for expert-level control.
Read the docs →20+ high-performance LLMs with recipes to pretrain, finetune and deploy at scale.
Read the docs →Build custom inference servers for any model in pure Python, with batching, streaming and multi-GPU built in.
Read the docs →Machine learning metrics for distributed, scalable PyTorch applications.
Read the docs →A source-to-source compiler that makes PyTorch training and inference faster. Understandable, inspectable, extensible.
Read the docs →Speed up model training by fixing data loading. Stream optimized datasets straight from cloud storage.
Read the docs →
import lightning as Limport torch, torch.nn as nn, torch.nn.functional as Fclass LitAutoEncoder(L.LightningModule): def __init__(self): super().__init__() self.encoder = nn.Sequential(nn.Linear(28 * 28, 64), nn.ReLU(), nn.Linear(64, 3)) self.decoder = nn.Sequential(nn.Linear(3, 64), nn.ReLU(), nn.Linear(64, 28 * 28)) def training_step(self, batch, batch_idx): x, _ = batch x = x.view(x.size(0), -1) loss = F.mse_loss(self.decoder(self.encoder(x)), x) self.log("train_loss", loss) return loss def configure_optimizers(self): return torch.optim.Adam(self.parameters(), lr=1e-3)trainer = L.Trainer(accelerator="gpu", devices=8)trainer.fit(LitAutoEncoder(), train_loader)from litgpt import LLMllm = LLM.load("microsoft/qwen3")text = llm.generate("Fix the spelling: Every fall, the family goes to the mountains.")print(text)# Corrected Sentence: Every fall, the family goes to the mountains.import litserve as lsclass InferenceEngine(ls.LitAPI): def setup(self, device): self.model = lambda x: x ** 2 def predict(self, request): return {"output": self.model(request["input"])}if __name__ == "__main__": server = ls.LitServer(InferenceEngine(max_batch_size=1), accelerator="auto") server.run(port=8000)import torchimport torchmetricsmetric = torchmetrics.classification.Accuracy(task="multiclass", num_classes=5)for _ in range(10): preds = torch.randn(10, 5).softmax(dim=-1) target = torch.randint(5, (10,)) acc = metric(preds, target) # accuracy on this batchacc = metric.compute() # accuracy across all batchesimport torchimport torch.nn as nnimport thundermodel = nn.Sequential(nn.Linear(2048, 4096), nn.ReLU(), nn.Linear(4096, 64))thunder_model = thunder.compile(model)x = torch.randn(64, 2048)y = thunder_model(x)torch.testing.assert_close(y, model(x))import litdata as lddataset = ld.StreamingDataset( "s3://my-bucket/fast_data", shuffle=True, drop_last=True,)dataloader = ld.StreamingDataLoader(dataset, batch_size=64)for sample in dataloader: img, cls = sample["image"], sample["class"]Powering generativeAI since 2015
- 2015PyTorch Lightning is born
- 2019World's first Trainer
- 20192048 GPU model
- 2019GPU → TPU with no code changes
- 2020Lightning accelerators
- 2021TorchMetrics
- 2022Fabric, to scale foundation models
- 2023LitGPT, open LLM recipes
- 2024Thunder, LitData and LitServe
Design philosophy
The principles behind every Lightning library.
Foundation-model first
Lightning libraries are designed to enable the flexibility and control needed to scale billion to trillion parameter models.
Minimal APIs
We design minimal abstractions that require almost no learning curve. We don't want you to learn a new framework.
Ultimate control and flexibility
Let Lightning handle all the details when you want to focus on science, and keep full control when you want to handle the engineering.
Interoperable by design
Lightning APIs enable team-wide collaboration by enforcing best practices and standardizing codebases.