pytorch-lightning

Organize PyTorch training code with LightningModule, Trainer, callbacks, and distributed strategies.

14|5|Updated Apr 9, 2026
One-click install
npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill pytorch-lightning-mlt-oss
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-lightning
Source: https://github.com/MLT-OSS/hermes-agent-go/tree/main/optional-skills/mlops/pytorch-lightning
Command: npx skills add https://github.com/MLT-OSS/hermes-agent-go --skill pytorch-lightning-mlt-oss

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 - Structured Training Loops: Encapsulate model, loss, and optimizer logic in a LightningModule while the Trainer handles epochs, devices, and precision automatically. - Distributed Training: Scale from a single GPU to multi-node clusters with DDP, FSDP, or DeepSpeed by changing one strategy parameter. - Callbacks and Tuning: Use ModelCheckpoint, EarlyStopping, and LearningRateMonitor, plus integrations with Ray Tune, Optuna, and WandB sweeps. - Use Case: Convert an existing PyTorch MNIST classifier into a LightningModule, then train it on 8 GPUs with BF16 precision and automatic best-model checkpointing without changing model code. ## Quick Start Convert my PyTorch training script into a PyTorch Lightning module and train it on multiple 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 a PyTorch training loop to PyTorch Lightning?

Move your model definition into a LightningModule subclass, put the loss computation 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 backward-pass code.

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 handles process spawning, data distribution with DistributedSampler, and gradient synchronization without code changes.

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

Lightning provides a fully structured framework with built-in callbacks, checkpointing, and logging, ideal for standardized team workflows. Accelerate makes minimal changes to existing PyTorch loops and offers more flexibility for custom training logic.

Does PyTorch Lightning support FSDP and DeepSpeed for large models?

Yes, Lightning includes FSDPStrategy with FULL_SHARD for ZeRO-3 equivalent sharding and DeepSpeedStrategy supporting ZeRO stages 2 and 3 with CPU offloading. These strategies 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 or via val_dataloaders. Calling trainer.fit(model, train_loader) alone skips validation entirely.

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

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