pytorch-lightning

Organizes PyTorch training code into LightningModules with built-in distributed training and callbacks.

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

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 - Structured Training Loops: Organize model code into LightningModule with training_step, validation_step, and configure_optimizers while the Trainer handles epochs, devices, and logging. - Distributed Training: Switch between single GPU, multi-GPU DDP, FSDP, and DeepSpeed ZeRO with a single strategy parameter, including multi-node and SLURM cluster support. - Callbacks and Tuning: Use ModelCheckpoint, EarlyStopping, and LearningRateMonitor callbacks, plus integrations with Ray Tune, Optuna, and WandB sweeps for hyperparameter search. - Use Case: Convert an existing PyTorch image classifier into a LightningModule, then scale it from one GPU to eight GPUs with DDP and automatic checkpointing by changing only the Trainer configuration. ## Quick Start Convert my PyTorch training script into a PyTorch Lightning module and train it on two GPUs with validation 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 PyTorch code to PyTorch Lightning?▼

Move your model into a LightningModule subclass, put the forward and loss logic 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 loop code.

How to do distributed training with PyTorch Lightning DDP?▼

Set accelerator to gpu, devices to the GPU count, and strategy to ddp in the Trainer, then run your script normally. Lightning handles process spawning, data distribution, and gradient synchronization automatically, with multi-node support via num_nodes.

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 PyTorch loop and more manual control over the training process.

Does PyTorch Lightning support FSDP and DeepSpeed for large models?▼

Yes, Lightning provides FSDPStrategy with FULL_SHARD for models in the 7-70B range and DeepSpeedStrategy with ZeRO-3 and CPU offload for 70B+ models. Both are enabled by passing the strategy object to the Trainer.

Why is my PyTorch Lightning training running out of memory?▼

Out-of-memory errors usually come from batch size or precision settings. Reduce batch size, set accumulate_grad_batches to simulate larger batches, or switch precision to bf16 or fp16 to cut memory usage roughly in half.

How do I tune hyperparameters with PyTorch Lightning?▼

Use the built-in Tuner for automatic learning rate and batch size finding, or integrate Ray Tune, Optuna, or WandB sweeps. Each framework provides callbacks that report validation metrics and support early pruning of poor trials.