pytorch-lightning
Agent skill fromOrchestra-Research/AI-Research-SKILLs
High-level PyTorch framework with Trainer class, automatic distributed training (DDP/FSDP/DeepSpeed), callbacks system, and minimal boilerplate. Scales from laptop to supercomputer with same code. Use when you want clean training loops with built-in best practices.
How to install pytorch-lightning
install pytorch-lightning
# install the AI-Research-SKILLs pack with the skills CLI
npx skills add Orchestra-Research/AI-Research-SKILLs# or add only this skill to Claude Code: copy the folder
08-distributed-training/pytorch-lightning/
# into
~/.claude/skills/pytorch-lightning/ (all projects)
.claude/skills/pytorch-lightning/ (one project)
1# PyTorch Lightning - High-Level Training Framework23## Quick start45PyTorch Lightning organizes PyTorch code to eliminate boilerplate while maintaining flexibility.67**Installation**:8```bash9pip install lightning10```1112**Convert PyTorch to Lightning** (3 steps):1314```python15import lightning as L16import torch17from torch import nn18from torch.utils.data import DataLoader, Dataset1920# Step 1: Define LightningModule (organize your PyTorch code)21class LitModel(L.LightningModule):22 def __init__(self, hidden_size=128):23 super().__init__()24 self.model = nn.Sequential(25 nn.Linear(28 * 28, hidden_size),26 nn.ReLU(),27 nn.Linear(hidden_size, 10)28 )2930 def training_step(self, batch, batch_idx):31 x, y = batch32 y_hat = self.model(x)33 loss = nn.functional.cross_entropy(y_hat, y)34 self.log('train_loss', loss) # Auto-logged to TensorBoard35 return loss3637 def configure_optimizers(self):38 return torch.optim.Adam(self.parameters(), lr=1e-3)3940# Step 2: Create data41train_loader = DataLoader(train_dataset, batch_size=32)4243# Step 3: Train with Trainer (handles everything else!)44trainer = L.Trainer(max_epochs=10, accelerator='gpu', devices=2)45model = LitModel()46trainer.fit(model, train_loader)47```4849**That's it!** Trainer handles:50- GPU/TPU/CPU switching51- Distributed training (DDP, FSDP, DeepSpeed)52- Mixed precision (FP16, BF16)53- Gradient accumulation54- Checkpointing55- Logging56- Progress bars57…
Excerpt shown under the repository's MIT license.
