pytorch-lightning

Organizes PyTorch training code with Trainer, callbacks, and distributed strategies like DDP, FSDP, and DeepSpeed.

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

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 placement, distributed synchronization, checkpointing, and logging, which introduces bugs and slows experimentation. ## Core Features & Use Cases - LightningModule Structure: Organizes model, training, validation, and test logic into a standardized class while the Trainer handles devices, precision, and loops. - Distributed Training: Scales the same code from a laptop to multi-node clusters using DDP, FSDP, or DeepSpeed with a single strategy parameter. - Callbacks & Tuning: Provides ModelCheckpoint, EarlyStopping, LearningRateMonitor, and integrations with Ray Tune, Optuna, and WandB sweeps. - Use Case: Convert an existing PyTorch training script into a LightningModule, then train on 8 GPUs with BF16 precision and automatic best-model checkpointing without changing model code. ## Quick Start Convert my PyTorch training loop into a PyTorch Lightning module and train it on multiple GPUs with DDP and early stopping.

Frequently Asked Questions about pytorch-lightning

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

FAQPage Schema
How do I convert a PyTorch training loop to PyTorch Lightning?

Move your model into a LightningModule subclass, implement training_step and configure_optimizers, then call Trainer.fit with your DataLoader. The Trainer handles device placement, backward passes, and optimizer steps automatically.

How do I train on multiple GPUs with PyTorch Lightning?

Set accelerator='gpu', devices to the GPU count, and strategy='ddp' in the Trainer. Lightning automatically spawns processes, distributes data, and synchronizes gradients without code changes.

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

Lightning suits teams wanting a standardized structure with built-in callbacks, logging, and checkpointing. Accelerate fits when you want minimal changes to an existing raw PyTorch loop and more manual control.

Does PyTorch Lightning support FSDP and DeepSpeed for large models?

Yes, Lightning provides FSDPStrategy with FULL_SHARD for ZeRO-3-equivalent sharding and DeepSpeedStrategy with stage 3 and CPU offloading. These target models from 7B to 70B+ parameters.

Why is my validation loop not running in PyTorch Lightning?

Validation only runs when you pass a validation DataLoader to trainer.fit as the second argument. Calling trainer.fit(model, train_loader) alone skips validation entirely.

How do I fix out-of-memory errors during Lightning training?

Reduce batch size, set accumulate_grad_batches to simulate larger batches, or use precision='bf16' to halve memory usage. For very large models, switch to FSDP with cpu_offload enabled.