pytorch-lightning

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

1|Updated Mar 12, 2026
One-click install
npx skills add https://github.com/kaminocorp/hermes-alpha-hunter --skill pytorch-lightning-kaminocorp
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pytorch-lightning
Source: https://github.com/kaminocorp/hermes-alpha-hunter/tree/main/skills/mlops/training/pytorch-lightning
Command: npx skills add https://github.com/kaminocorp/hermes-alpha-hunter --skill pytorch-lightning-kaminocorp

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 synchronization, checkpointing, and logging, which introduces bugs and slows down experimentation. ## Core Features & Use Cases - Boilerplate-Free Training Loops: Encapsulate model logic in a LightningModule and let the Trainer handle GPU placement, mixed precision, gradient accumulation, and logging automatically. - One-Line Distributed Training: Scale from a single GPU to multi-node clusters using DDP, FSDP, or DeepSpeed by changing a single strategy parameter. - Modular Callbacks System: Add ModelCheckpoint, EarlyStopping, LearningRateMonitor, or custom callbacks without touching model code. - Use Case: Convert an existing PyTorch training script into a LightningModule, then launch 8-GPU DDP training with automatic best-model checkpointing and early stopping in under 20 lines of code. ## Quick Start Convert my PyTorch training loop into a PyTorch Lightning module and train it on multiple GPUs with checkpointing enabled.

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 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 placement and backward calls.

How do I train on multiple GPUs with PyTorch Lightning?▼

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

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

Lightning provides a 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, suiting projects that need 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 with stage 3 and CPU offloading. These strategies support models from 7B to 70B+ parameters across multiple GPUs.

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) without val_loader 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.