pytorch-lightning

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

Updated May 29, 2026
One-click install
npx skills add https://github.com/m4an5you6/aspera-agent --skill pytorch-lightning-m4an5you6
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: pytorch-lightning
Source: https://github.com/m4an5you6/aspera-agent/tree/main/optional-skills/mlops/pytorch-lightning
Command: npx skills add https://github.com/m4an5you6/aspera-agent --skill pytorch-lightning-m4an5you6

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 - Trainer Abstraction: Encapsulates GPU/TPU switching, mixed precision, gradient accumulation, and checkpointing behind a single Trainer class. - Distributed Training: Scales from one GPU to multi-node clusters with DDP, FSDP, or DeepSpeed by changing a single strategy parameter. - Callbacks System: Adds ModelCheckpoint, EarlyStopping, LearningRateMonitor, and custom hooks without modifying model code. - Use Case: Convert an existing PyTorch training script into a LightningModule, then run it on 8 GPUs with BF16 precision and automatic best-model checkpointing without rewriting the loop. ## 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 a PyTorch training loop to PyTorch Lightning?▼

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

PyTorch Lightning vs Hugging Face Accelerate for distributed training?▼

Lightning provides a structured framework with built-in callbacks, logging, and checkpointing, while Accelerate makes minimal changes to existing loops with more flexibility. Choose Lightning for standardized team codebases and Accelerate for incremental adoption.

Does PyTorch Lightning support multi-node GPU training?▼

Yes, set num_nodes in the Trainer and configure MASTER_ADDR, MASTER_PORT, and NODE_RANK environment variables on each machine. Lightning also auto-detects SLURM cluster environments for job scheduling.

Why is my validation loop not running in Lightning?▼

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.

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

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

When should I use FSDP instead of DDP in Lightning?▼

Use DDP for models under roughly 7 billion parameters where each GPU can hold a full copy. Switch to FSDP with FULL_SHARD for 7-70B parameter models, and DeepSpeed ZeRO-3 with CPU offload beyond that.