Guide · Agent skill
How to use the PyTorch Lightning Training agent skill
Updated · written with AI from the project's own documentation and checked against our catalogue data
The PyTorch Lightning Training agent skill (skill name: pytorch-lightning) gives an AI coding agent a working knowledge of how to organise PyTorch training code into Lightning's standard pieces. Once installed, the agent can write or refactor a LightningModule, a LightningDataModule and a Trainer, and point you to detailed reference notes on callbacks, logging and distributed training. This guide is for engineers, researchers and students who have never installed an agent skill before, and it walks through installation, triggering the skill, examples, requirements and safety notes.
Quick start
- 1Install Python and Lightning. Make sure Python 3.10 or newer is available, then install lightning 2.6.6 and a compatible PyTorch with uv pip install "lightning==2.6.6".
- 2Install the skill. Download the ZIP from this page and unzip it into ~/.claude/skills/ or a project's .claude/skills/ folder, or upload it under Settings → Capabilities → Skills in the Claude apps.
- 3Describe your training task. Ask the agent in plain language, for example to convert your training loop into a LightningModule with a Trainer.
- 4Review the generated code. Check the LightningModule, DataModule and Trainer it writes, including data sources, labels and any logger settings.
- 5Run the CPU smoke test. Run the template workflow on CPU with synthetic data to confirm the code executes before using real data.
- 6Add your data and logging. Replace synthetic data with your own split, and add loggers or callbacks only when you have decided on them.
What the skill makes the agent do
Agent skills are folders of instructions and helper files that an agent loads when a request matches them. This one covers the PyTorch Lightning framework (the lightning package). It helps the agent split training code into a LightningModule for the model and its training, validation, test and prediction steps, a LightningDataModule for data loading, and a Trainer that runs the loop, device management, checkpoints and logging.
The skill is guidance and boilerplate for writing and running training code. It is not a trained model. Its templates use synthetic random data and are only smoke tests, so they do not show scientific accuracy.
- Organises a PyTorch project into LightningModule, LightningDataModule and Trainer
- Starts from bundled template files: scripts/template_lightning_module.py, scripts/template_datamodule.py and scripts/quick_trainer_setup.py
- Points to reference notes on callbacks, logging, the Trainer and distributed training (DDP, FSDP, DeepSpeed)
How to install the PyTorch Lightning skill
You can install the skill in one of two ways. Download the ZIP from this page and unzip it into your personal skills folder, ~/.claude/skills/, or into a project's .claude/skills/ folder if you want it to apply only to that project. Alternatively, upload the ZIP in the Claude apps under Settings → Capabilities → Skills.
The folder you unzip should contain SKILL.md, the references/ folder and the scripts/ folder, so the agent can read the notes and copy the templates.
- Option A: unzip into ~/.claude/skills/ for all your projects
- Option B: unzip into a project's .claude/skills/ folder for that project only
- Option C: upload the ZIP in the Claude apps under Settings → Capabilities → Skills
Install the Lightning package it depends on
The skill expects Python 3.10 or newer, the lightning 2.6.6 package and a compatible PyTorch install. The skill's own installation instructions use uv. Lightning exposes the namespace import lightning as L; the separate pytorch-lightning distribution uses import pytorch_lightning as pl. Do not mix the two namespaces in one application.
Optional extras and logger packages are installed separately, only if you use them.
- Requires Python 3.10 or newer
- Requires lightning 2.6.6 and a compatible PyTorch
- Optional: wandb or mlflow, only if you use those loggers
uv pip install "lightning==2.6.6"How to trigger the skill with natural requests
You do not need to name the skill. Describe the task in plain language that matches what the skill covers. The skill is meant to be used when you are building or training a network with PyTorch Lightning, organising code into LightningModules, configuring Trainers for multi-GPU or TPU, building data pipelines with LightningDataModules, or adding callbacks, logging and distributed strategies.
Be specific about your model, data and hardware. The more the agent knows about your setup, the less it has to guess.
- "Convert my PyTorch training loop into a LightningModule with a Trainer."
- "Wrap my image folder loading in a LightningDataModule with train and validation loaders."
- "Set up a Trainer that checkpoints the best model on val/loss and stops early."
- "I have 4 GPUs. Which Lightning strategy should I use for my model, and how do I configure it?"
Examples of a smoke test you can run
The skill's quick workflow copies the three template scripts into a working directory and runs a CPU smoke test. The example below comes from the skill's own instructions. It uses synthetic data, so the result shows that the code runs, not that the model is good. The skill also notes that a fresh model and Trainer should be used when resuming from a checkpoint, and that random labels test mechanics only.
Helpers monitor val/loss by default. Check the bundled scripts before you change the code, because the templates are meant as starting points.
- Run on CPU with accelerator="cpu" and precision="32-true"
- Logs go to logs/ and checkpoints to checkpoints/ in the working directory
import lightning as L
from template_datamodule import TemplateDataModule
from template_lightning_module import TemplateLightningModule
from quick_trainer_setup import production_single_gpu_trainer
L.seed_everything(42, workers=True)
model = TemplateLightningModule(hidden_dim=16)
dm = TemplateDataModule(num_samples=64, batch_size=8, num_workers=0)
trainer = production_single_gpu_trainer(
max_epochs=1, accelerator="cpu", precision="32-true",
log_dir="logs", checkpoint_dir="checkpoints",
)
trainer.fit(model, datamodule=dm)
trainer.test(model, datamodule=dm, ckpt_path="best", weights_only=True)What the skill needs and what it does not do
The skill runs scripts, so the agent can execute Python code on your machine. It does not use the network. CPU examples need no network after installation. GPU, DDP, FSDP and DeepSpeed setups need suitable hardware, and the skill notes that these configurations are illustrative and not validated by executed training.
Online loggers need extra packages and credentials, and they send data to external services. The bundled helpers log to local CSV files. NeptuneLogger was removed in Lightning 2.6.4, so do not rely on it.
- Runs scripts: yes. Uses network: no
- Optional logger packages (wandb, mlflow) and credentials are needed only for online logging
- Multi-GPU, FSDP and DeepSpeed need suitable hardware; check before relying on them
- Cloud logging or artifact uploads should be a deliberate decision, since credentials and network access would expose data
Tips for getting good results
Start with a fast check before a real run. The skill recommends fast_dev_run=True on the Trainer to test with one batch. Set a seed with L.seed_everything(seed, workers=True) so runs are reproducible, and use deterministic=True on the Trainer where you need it.
For distributed training, choose the strategy from measured memory and throughput rather than a fixed size rule. Use DDP when each device can hold the full model, optimizer state and activations. Consider FSDP or DeepSpeed only when memory pressure is measured and those features fit your CUDA stack.
When you log a scalar metric across several GPUs, pass sync_dist=True to self.log, because the default is False. For metrics that do not add up across batches, such as AUROC, use a TorchMetrics object rather than averaging per-GPU values.
- Use self.device instead of calling .cuda() so code stays device agnostic
- Call self.save_hyperparameters() in __init__() to save hyperparameters with checkpoints
- Split your data by the real unit of independence (patient, site, batch) before preprocessing, and keep a test set for the final comparison
What people use it for
- Refactoring an existing PyTorch training script into LightningModule and Trainer structure
- Writing a LightningDataModule that separates download, setup and dataloader code
- Adding ModelCheckpoint and EarlyStopping callbacks monitoring val/loss
- Preparing a prototype to run on several GPUs with a sensible strategy choice
- Teaching students how a standard training loop is organised
Frequently asked questions
How do I install the PyTorch Lightning agent skill?
Download the ZIP from this page and unzip it into ~/.claude/skills/ or a project's .claude/skills/ folder. You can also upload the ZIP in the Claude apps under Settings → Capabilities → Skills.
What are the requirements for the pytorch-lightning skill?
The skill requires Python 3.10 or newer, the lightning 2.6.6 package and a compatible PyTorch install. Optional logger packages such as wandb or mlflow are needed only if you use them.
Is the PyTorch Lightning skill free?
The skill is listed under the MIT licence on this page. Check the licence file in the source repository for the full terms before reuse.
Does the skill train a model for me?
No. It provides guidance and boilerplate for writing and running training code. Its templates use synthetic random data and are only smoke tests, not models with proven scientific accuracy.
Does the skill use the network?
The skill does not use the network. CPU examples need no network after installation, but online loggers need extra packages, credentials and network access if you choose them.
How does PyTorch Lightning compare with plain PyTorch?
Lightning organises PyTorch code into a LightningModule, a DataModule and a Trainer, removing much of the loop, device and checkpoint boilerplate while keeping full PyTorch flexibility. Plain PyTorch gives you full manual control of every step, which can suit small or unusual projects.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Choose this skill if you write or refactor PyTorch training code, want less boilerplate, or are moving a prototype to multiple GPUs and want guidance on strategy. Pick something else if you need a ready-made model with proven accuracy, or if you plan multi-GPU, FSDP or DeepSpeed runs without suitable hardware or a deliberate plan for cloud logging.
Download the skill