pytorch-lightning

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

Updated Apr 27, 2026
One-click install
npx skills add https://github.com/DUT-AI/intelligent-testing --skill pytorch-lightning-dut-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytorch-lightning
Source: https://github.com/DUT-AI/intelligent-testing/tree/main/.agents/skills/pytorch-lightning
Command: npx skills add https://github.com/DUT-AI/intelligent-testing --skill pytorch-lightning-dut-ai

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 experimentation. ## Core Features & Use Cases - LightningModule Structure: Organizes model, training, validation, and test logic into a clean class while the Trainer handles GPU/TPU placement, mixed precision, and gradient accumulation. - Distributed Training: Scales from a single GPU to multi-node clusters with DDP, FSDP, or DeepSpeed by changing one strategy parameter. - Callbacks & Tuning: Built-in ModelCheckpoint, EarlyStopping, and LearningRateMonitor callbacks, plus integrations with Ray Tune, Optuna, and WandB sweeps for hyperparameter search. - Use Case: Convert an existing PyTorch training script into a LightningModule, then run it on 8 GPUs with DDP and automatic checkpointing without rewriting the loop. ## Quick Start Convert my PyTorch training loop 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 into a LightningModule subclass, define training_step and configure_optimizers methods, then pass the module and DataLoader to Trainer.fit. The Trainer handles device placement, backward passes, and optimizer steps automatically.

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

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 workflows and Accelerate for incremental adoption.

Does PyTorch Lightning support multi-node distributed training?

Yes, set num_nodes in the Trainer and use DDP, FSDP, or DeepSpeed strategies. Lightning auto-detects SLURM and Kubernetes environments, requiring only MASTER_ADDR, MASTER_PORT, and NODE_RANK variables for manual setups.

Why is my validation loop not running in Lightning?

Validation only runs if 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 roughly in half. For very large models, use FSDP with FULL_SHARD or DeepSpeed ZeRO-3 with CPU offload.

When should I use FSDP instead of DDP in Lightning?

Use DDP for models under roughly 1-7B 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.