pytorch-lightning

Organizes PyTorch training code with automatic distributed training, callbacks, and checkpointing.

Updated Jun 7, 2026
One-click install
npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill pytorch-lightning-chensihakniroth
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pytorch-lightning
Source: https://github.com/Chensihakniroth/ANAKOT-AGENT/tree/main/optional-skills/mlops/pytorch-lightning
Command: npx skills add https://github.com/Chensihakniroth/ANAKOT-AGENT --skill pytorch-lightning-chensihakniroth

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires lightning, torch, transformers, and includes references (resource) components.

What problem does it solve? Writing raw PyTorch training loops requires repetitive boilerplate for device management, distributed training, checkpointing, and logging, which introduces bugs and slows down experimentation. ## Core Features & Use Cases - Structured Training Loops: Organize model code into a LightningModule with training_step, validation_step, and configure_optimizers while the Trainer handles the rest. - Automatic Distributed Training: Scale from a single GPU to multi-node clusters with DDP, FSDP, or DeepSpeed by changing one Trainer parameter. - Built-In Callbacks: Use ModelCheckpoint, EarlyStopping, and LearningRateMonitor to save best models, stop unproductive runs, and track learning rates automatically. - Use Case: Convert an existing PyTorch training script into a LightningModule, then train on 8 GPUs with mixed precision and automatic checkpointing without rewriting device or synchronization logic. ## Quick Start Convert my PyTorch training loop into a PyTorch Lightning module and train it on two GPUs with early stopping and checkpointing.

Frequently Asked Questions about pytorch-lightning

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert PyTorch code to PyTorch Lightning?▼

Move your model definition into a LightningModule subclass, put the forward and loss logic in training_step, and return the optimizer from configure_optimizers. Then create a Trainer and call trainer.fit with your DataLoader, removing all manual device and loop code.

How to train on multiple GPUs with PyTorch Lightning?▼

Set accelerator='gpu', devices to the GPU count, and strategy='ddp' in the Trainer. Lightning automatically handles process spawning, data distribution, and gradient synchronization with no code changes to your LightningModule.

PyTorch Lightning vs Hugging Face Accelerate: which should I use?▼

Lightning provides a structured framework with built-in callbacks, logging, and checkpointing for organized training code. Accelerate makes minimal changes to existing PyTorch loops and offers more flexibility, suiting projects that want to keep custom loop logic.

Does PyTorch Lightning support FSDP and DeepSpeed for large models?▼

Yes, Lightning includes FSDPStrategy with FULL_SHARD for models in the 7-70B range and DeepSpeedStrategy with ZeRO-3 and CPU offload for models above 70B parameters. Both are enabled by passing the strategy object to the Trainer.

Why is my PyTorch Lightning validation not running?▼

Validation only runs when you pass a validation DataLoader to trainer.fit as the second argument. Calling trainer.fit(model, train_loader) without val_loader skips validation entirely, so monitored callbacks like EarlyStopping will not trigger.

How do I fix out of memory errors in PyTorch Lightning training?▼

Reduce batch size, enable gradient accumulation with accumulate_grad_batches, or switch to mixed precision with precision='bf16' or 'fp16' to cut memory usage roughly in half. For very large models, use FSDP with cpu_offload enabled.