Agent skill
pytorch-lightning
High-level training framework for PyTorch that abstracts boilerplate while maintaining flexibility. Includes the Trainer, LightningModule, and support for multi-GPU scaling and reproducibility. (lightning, pytorch-lightning, lightningmodule, trainer, callback, ddp, fast_dev_run, seed_everything)
Install this agent skill to your Project
npx add-skill https://github.com/cuba6112/skillfactory/tree/main/skills/pytorch-lightning
SKILL.md
Overview
PyTorch Lightning is a lightweight wrapper for PyTorch that decouples the research code from the engineering code. It automates 40+ engineering details like epoch loops, optimization, and hardware acceleration, while allowing researchers to retain full control over the model logic.
When to Use
Use Lightning when you want to scale models to multi-GPU or multi-node environments without changing training code, or when you want to eliminate boilerplate for logging, checkpointing, and reproducibility.
Decision Tree
- Are you testing code logic on a small subset?
- YES: Use
Trainer(fast_dev_run=True).
- YES: Use
- Do you need to scale to multiple GPUs?
- YES: Set
accelerator='gpu'anddevices=Nin the Trainer.
- YES: Set
- Do you have logic that is non-essential to the model (e.g., special logging)?
- YES: Implement it as a
Callback.
- YES: Implement it as a
Workflows
-
Transitioning from Raw PyTorch to Lightning
- Define a class inheriting from
L.LightningModule. - Move model architecture into
__init__and logic intotraining_step. - Implement
configure_optimizersto return the optimizer and optional scheduler. - Instantiate an
L.Trainerand pass the model and DataLoader totrainer.fit().
- Define a class inheriting from
-
Multi-GPU Training Scaling
- Initialize the Trainer with
accelerator='gpu'anddevices=N. - Set
strategy='ddp'or'deepspeed_stage_2'for multi-node/large-scale runs. - Optionally enable 16-bit precision using
precision='16-mixed'. - Run the script without code changes to standard logic.
- Initialize the Trainer with
-
Ensuring Training Reproducibility
- Call
seed_everything(seed, workers=True)at the start of the script. - Initialize the Trainer with
deterministic=True. - Avoid data-dependent logic in transforms that isn't handled by the derived seeds.
- Call
Non-Obvious Insights
- Overhead Analysis: The 'barebones' mode in the Trainer is specifically for overhead analysis and disables almost all logging and checkpointing for speed.
- Callback State Management: Custom callbacks must implement a
state_keyproperty if multiple instances of the same callback type are used in a single Trainer. - Superior Debugging: The
fast_dev_runflag is superior to limiting batches manually because it avoids all side effects like checkpointing or logging that might clutter the workspace during debugging.
Evidence
- "The Lightning Trainer automates 40+ tricks including: Epoch and batch iteration, optimizer.step(), loss.backward(), optimizer.zero_grad() calls." (https://lightning.ai/docs/pytorch/stable/starter/introduction.html)
- "By setting workers=True in seed_everything(), Lightning derives unique seeds across all dataloader workers." (https://lightning.ai/docs/pytorch/stable/common/trainer.html)
Scripts
scripts/pytorch-lightning_tool.py: Template for a LightningModule and Trainer setup.scripts/pytorch-lightning_tool.js: Script to trigger Lightning training with CLI arguments.
Dependencies
- lightning
- torch
References
- PyTorch Lightning Reference
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
prompt-engineering
Comprehensive prompt engineering techniques for Claude models. Use this skill when crafting, optimizing, or debugging prompts for Claude API, Claude Code, or any Claude-powered application. Covers system prompts, role prompting, multishot examples, chain of thought, XML structuring, long context handling, extended thinking, prompt chaining, Claude 4.x-specific best practices, and agentic orchestration including subagents, agent loops, skills, MCP integration, and multi-agent workflows.
adk-rag-agent
Build RAG (Retrieval-Augmented Generation) agents with Google ADK and Vertex AI RAG Engine. Use when implementing document Q&A, knowledge base search, or citation-backed responses. Covers VertexAiRagRetrieval tool, corpus setup, and citation formatting.
headless-cli-agents
Build agentic systems using Claude CLI in headless mode or the Claude Agent SDK. Use when building automation pipelines, CI/CD integrations, multi-agent orchestration, or programmatic Claude interactions. Covers CLI flags (-p, --output-format), session management (--resume, --continue), Python SDK (claude-agent-sdk), custom tools, and agent loop patterns.
notion-knowledge-capture
Capture conversations and decisions into structured Notion pages; use when turning chats/notes into wiki entries, how-tos, decisions, or FAQs with proper linking.
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
gh-fix-ci
Inspect GitHub PR checks with gh, pull failing GitHub Actions logs, summarize failure context, then create a fix plan and implement after user approval. Use when a user asks to debug or fix failing PR CI/CD checks on GitHub Actions and wants a plan + code changes; for external checks (e.g., Buildkite), only report the details URL and mark them out of scope.
Didn't find tool you were looking for?