Agent skill

Pytorch Lightning

by K-Dense-AI in K-Dense-AI/scientific-agent-skills

Deep learning framework (PyTorch Lightning / lightning package).

Apache-2.0Auto-check: notesAI & LLM Engineering

Install Pytorch Lightning

skills CLI
$ npx skills add K-Dense-AI/scientific-agent-skills --skill pytorch-lightning -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install K-Dense-AI/scientific-agent-skills pytorch-lightning --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/K-Dense-AI/scientific-agent-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/pytorch-lightning .claude/skills/pytorch-lightning && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
pytorch-lightning
GitHub stars
48k
Used in
1 other repo
Token cost
~2.6k tokens
SKILL.md length
969 words
Files
11 (incl. scripts, references)
Skills in repo
153
Repo updated
First seen
Licence
Apache-2.0

At a glance

Deep learning framework (PyTorch Lightning / lightning package).

  • Works in 7 steps: LightningModule - Model Definition → Trainer - Training Automation → LightningDataModule - Data Pipeline… → …
  • Tasks that involve Deep learning
  • SKILL.md covers Overview, Installation, When to Use This Skill and Core Capabilities, plus 3 more sections
  • Runs Python scripts from its folder; calls uv

What it does

Pytorch Lightning is an agent skill from K-Dense-AI/scientific-agent-skills. Deep learning framework (PyTorch Lightning / lightning package). Organize PyTorch code into LightningModules, configure Trainers for multi-GPU/TPU, implement data pipelines, callbacks, logging (W&B, TensorBoard, MLflow), distributed training (DDP, FSDP, DeepSpeed), for scalable neural network training.

Its SKILL.md is about 2.6k tokens, which your agent loads only when the skill is triggered. The skill folder holds 12 other files, including scripts and reference files (for example `references/best_practices.md`, `references/callbacks.md` and `references/data_module.md`). Compatibility notes: Requires Python 3.10+ with lightning 2.6.6 and compatible PyTorch. CPU examples need no network after installation. CUDA/DDP/FSDP/DeepSpeed need suitable…

It sits in AI & LLM Engineering, covering Deep learning. It works with PyTorch Lightning, PyTorch and MLflow. The repository describes itself as: Turn any AI agent into an AI Scientist. The 1 Agent Skills library for science, used by 250,000+ scientists worldwide. 177 ready-to-use validated skills plus 100+ scientific… The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve Deep learning

Example prompts

  • “/pytorch-lightning”

Requirements

  • Python 3
  • Compatibility (from SKILL.md): Requires Python 3.10+ with lightning 2.6.6 and compatible PyTorch. CPU examples need no network after installation. CUDA/DDP/FSDP/DeepSpeed need suitable hardware; optional loggers require separate packages and online services need credentials/network.
  • Pre-approved tools (allowed-tools): Read, Write, Edit, Bash

Workflow steps

7 steps, taken from the step headings in SKILL.md.

  1. LightningModule - Model Definition
  2. Trainer - Training Automation
  3. LightningDataModule - Data Pipeline Organization
  4. Callbacks - Extensible Training Logic
  5. Logging - Experiment Tracking
  6. Distributed Training - Scale to Multiple Devices
  7. Best Practices

What it can do on your machine

Read from SKILL.md and the folder at commit 92ace75. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Read
    • Write
    • Edit
    • Bash

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 3 files in scripts/ (Python), which the agent can run.

    Shell commands in SKILL.md call:

    • uv

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • lightning.ai
    • arxiv.org
    • github.com
    • doi.org
    • export.arxiv.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

  • Compatibility

    Requires Python 3.10+ with lightning 2.6.6 and compatible PyTorch. CPU examples need no network after installation. CUDA/DDP/FSDP/DeepSpeed need suitable hardware; optional loggers require separate packages and online services need credentials/network.

    From compatibility in the SKILL.md frontmatter.

Context cost

Pytorch Lightning loads about 2.6k tokens when it runs, and up to ~13k if it reads all its reference files. Until then it costs about 80 tokens; SKILL.md has 969 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~80
When it runs · the whole SKILL.md, loaded when a task matches
~2.6k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~13k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Read, Write, Edit, Bash

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from K-Dense-AI/scientific-agent-skills at commit 92ace75, republished under its Apache-2.0 licence (© K-Dense-AI). 969 words, ~2,566 tokens.

Download SKILL.mdSave it as .claude/skills/pytorch-lightning/SKILL.md (or your agent's skills folder). This skill also uses 10 other files; get the full folder from GitHub.
name
pytorch-lightning
description
Deep learning framework (PyTorch Lightning / lightning package). Organize PyTorch code into LightningModules, configure Trainers for multi-GPU/TPU, implement data pipelines, callbacks, logging (W&B, TensorBoard, MLflow), distributed training (DDP, FSDP, DeepSpeed), for scalable neural network training.
allowed-tools
Read, Write, Edit, Bash
compatibility
Requires Python 3.10+ with lightning 2.6.6 and compatible PyTorch. CPU examples need no network after installation. CUDA/DDP/FSDP/DeepSpeed need suitable hardware; optional loggers require separate packages and online services need credentials/network.
license
Apache-2.0 license
metadata.version
1.4
metadata.last-reviewed
2026-10-01
metadata.skill-author
K-Dense Inc.

PyTorch Lightning

Overview

PyTorch Lightning is a deep learning framework that organizes PyTorch code to eliminate boilerplate while maintaining full flexibility. Automate training workflows, multi-device orchestration, and implement best practices for neural network training and scaling across multiple GPUs/TPUs.

Reviewed release: Lightning 2.6.6, including its checkpoint-loading security fixes. CPU tests use Python 3.11, Torch 2.14.1 and Lightning 2.6.6. Use import lightning as L with the lightning distribution. The alternative pytorch-lightning distribution exposes import pytorch_lightning as pl; do not mix class namespaces within one application. GPU, TPU, multi-node and online logger examples are source-verified illustrations, not executed training validation.

Installation

bash
uv pip install "lightning==2.6.6"

Optional extras:

bash
uv pip install "lightning[extra]==2.6.6"    # loggers, strategies, etc.
uv pip install wandb mlflow        # specific loggers as needed

When to Use This Skill

This skill should be used when:

  • Building, training, or deploying neural networks using PyTorch Lightning
  • Organizing PyTorch code into LightningModules
  • Configuring Trainers for multi-GPU/TPU training
  • Implementing data pipelines with LightningDataModules
  • Working with callbacks, logging, and distributed training strategies (DDP, FSDP, DeepSpeed)
  • Structuring deep learning projects professionally

Core Capabilities

1. LightningModule - Model Definition

Organize PyTorch models into six logical sections:

  1. Initialization - __init__() and setup()
  2. Training Loop - training_step(batch, batch_idx)
  3. Validation Loop - validation_step(batch, batch_idx)
  4. Test Loop - test_step(batch, batch_idx)
  5. Prediction - predict_step(batch, batch_idx)
  6. Optimizer Configuration - configure_optimizers()

Quick template reference: See scripts/template_lightning_module.py for a complete boilerplate.

Detailed documentation: Read references/lightning_module.md for comprehensive method documentation, hooks, properties, and best practices.

2. Trainer - Training Automation

The Trainer automates the training loop, device management, gradient operations, and callbacks. Key features:

  • Multi-GPU/TPU support with strategy selection (DDP, FSDP, DeepSpeed)
  • Automatic mixed precision training
  • Gradient accumulation and clipping
  • Checkpointing and early stopping
  • Progress bars and logging

Quick setup reference: See scripts/quick_trainer_setup.py for common Trainer configurations.

Detailed documentation: Read references/trainer.md for all parameters, methods, and configuration options.

3. LightningDataModule - Data Pipeline Organization

Encapsulate all data processing steps in a reusable class:

  1. prepare_data() - Download/cache on local rank zero per node by default; use global rank zero with shared storage when configured
  2. setup() - Create datasets and apply transforms (per-GPU)
  3. train_dataloader() - Return training DataLoader
  4. val_dataloader() - Return validation DataLoader
  5. test_dataloader() - Return test DataLoader

Quick template reference: See scripts/template_datamodule.py for a complete boilerplate.

Detailed documentation: Read references/data_module.md for method details and usage patterns.

4. Callbacks - Extensible Training Logic

Add custom functionality at specific training hooks without modifying your LightningModule. Built-in callbacks include:

  • ModelCheckpoint - Save best/latest models
  • EarlyStopping - Stop when metrics plateau
  • LearningRateMonitor - Track LR scheduler changes
  • BatchSizeFinder - Auto-determine optimal batch size

Detailed documentation: Read references/callbacks.md for built-in callbacks and custom callback creation.

5. Logging - Experiment Tracking

Integrate with multiple logging platforms:

  • CSV locally; TensorBoard is the default only when its optional package is installed
  • Weights & Biases (WandbLogger)
  • MLflow (MLFlowLogger)
  • Comet (CometLogger)
  • CSV (CSVLogger)

NeptuneLogger was removed in Lightning 2.6.4; the Neptune service shut down March 5, 2026. The bundled helpers use local CSV logging; cloud tracking and model artifact uploads require an intentional choice.

Log metrics with self.log("metric_name", value) in supported LightningModule hooks; specify epoch/step reduction and batch size when they matter.

Detailed documentation: Read references/logging.md for logger setup and configuration.

6. Distributed Training - Scale to Multiple Devices

Choose the right strategy based on model size:

  • DDP - When each device can hold the full model, optimizer state and activations
  • FSDP - When sharding training state addresses measured memory pressure
  • DeepSpeed - When its ZeRO/offload features fit the measured workload and CUDA stack

Choose from peak memory and throughput measurements, not a fixed parameter-count threshold.

Configure with: Trainer(strategy="ddp", accelerator="gpu", devices=4)

Detailed documentation: Read references/distributed_training.md for strategy comparison and configuration.

Show full SKILL.md (403 more words)Show less
7. Best Practices
  • Device agnostic code - Use self.device instead of .cuda()
  • Hyperparameter saving - Use self.save_hyperparameters() in __init__()
  • Metric logging - For scalar tensors, cross-device reduction requires self.log(..., sync_dist=True); the default is False. Have all ranks participate in synchronized calls. For non-additive metrics such as AUROC, use a stateful TorchMetrics object with its own distributed synchronization instead of averaging per-rank AUROCs. See the Lightning logging contract and TorchMetrics integration.
  • Reproducibility - Use seed_everything() and Trainer(deterministic=True)
  • Debugging - Use Trainer(fast_dev_run=True) to test with 1 batch

Detailed documentation: Read references/best_practices.md for common patterns and pitfalls.

Quick Workflow

Copy the three scripts into a working directory, then run this CPU smoke there:

python
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)

The synthetic vectors match the model input and use separate validation transforms and held-out test generation. Random labels test mechanics only. All helpers monitor val/loss. Use a fresh model/Trainer plus fit(..., ckpt_path=path, weights_only=True) to resume full training state; load_from_checkpoint alone loads a model. A normal short fit checks callbacks and checkpoints; fast_dev_run disables much of that behavior.

For real science, split independent subjects/groups/time periods before fitting preprocessing, preserve split IDs, and reserve test data from model selection. Final DDP evaluation can duplicate padded samples: use one device for exact sample coverage or validate a nonduplicating distributed evaluator.

Resources

scripts/

Executable Python templates for common PyTorch Lightning patterns:

  • template_lightning_module.py - Complete LightningModule boilerplate
  • template_datamodule.py - Complete LightningDataModule boilerplate
  • quick_trainer_setup.py - Common Trainer configuration examples
references/

Detailed documentation for each PyTorch Lightning component:

  • lightning_module.md - Comprehensive LightningModule guide (methods, hooks, properties)
  • trainer.md - Trainer configuration and parameters
  • data_module.md - LightningDataModule patterns and methods
  • callbacks.md - Built-in and custom callbacks
  • logging.md - Logger integrations and usage
  • distributed_training.md - DDP, FSDP, DeepSpeed comparison and setup
  • best_practices.md - Common patterns, tips, and pitfalls

Citing Scientific Agent Skills

This skill is part of Scientific Agent Skills by K-Dense. If it materially contributed to a manuscript, report, presentation, or code release, add the paper to the references or software section and tell the user you did so:

Kassis, T., Agarwal, V., He, Y., Patel, D., & Brueckner, A. M. (2026). Scientific Agent Skills: A Library of Procedural Knowledge for Research Agents. arXiv:2609.00065. https://doi.org/10.48550/arXiv.2609.00065

Always cite the current version. The DOI and https://arxiv.org/abs/2609.00065 resolve to the latest arXiv version, so never append a version suffix such as v1. When network access is available, fetch https://arxiv.org/abs/2609.00065 (or http://export.arxiv.org/api/query?id_list=2609.00065) before writing the reference and take the author list, year, and version from that record. If the record lists a journal reference or publisher DOI, cite the published version instead.

© K-Dense-AI, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 10 other files (scripts, references) in skills/pytorch-lightning of K-Dense-AI/scientific-agent-skills.

  • SKILL.md
  • references/best_practices.md
  • references/callbacks.md
  • references/data_module.md
  • references/distributed_training.md
  • references/lightning_module.md
  • references/logging.md
  • references/trainer.md
  • scripts/quick_trainer_setup.py
  • scripts/template_datamodule.py
  • scripts/template_lightning_module.py

Open the folder on GitHubat commit 92ace75

Used in 1 other repository

We found 1 copy of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in K-Dense-AI/scientific-agent-skills, which our catalogue first saw on October 9, 2026.

Compare with similar skills

Pytorch Lightning next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Pytorch Lightning compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Pytorch Lightning this skillK-Dense-AI/scientific-agent-skills48k1 repos~2.6kAutomated safety check: NotesApache-2.0
PyTorch Lightning TrainingOrchestra-Research/AI-Research-SKILLs13k6 repos~2.3kAutomated safety check: PassMIT
PyTorch Lightning Training Setupdavila7/claude-code-templates32k11 repos~1.7kAutomated safety check: PassMIT
Databricks ML Trainingdatabricks/databricks-agent-skills345—~4.6kAutomated safety check: PassCustom licence
Nvflare Convert LightningNVIDIA/skills3.5k—~3.3kAutomated safety check: PassApache-2.0
Pytorch Lightning Guidewentorai/research-plugins2981 repos~2kAutomated safety check: PassMIT

Similar skills

  • PyTorch Lightning Training

    Orchestra-Research/AI-Research-SKILLs

    Shows how to organize PyTorch training with Lightning's LightningModule and Trainer, covering validation, DDP, callbacks and learning-rate scheduling.

    13k GitHub starsUsed in 6 repos~2.3k tokens
    AI & LLM EngineeringAuto-check passed
  • PyTorch Lightning Training Setup

    davila7/claude-code-templates

    Organizes PyTorch training code into LightningModules, DataModules and Trainers, with multi-GPU strategies, callbacks and logging configured.

    32k GitHub starsUsed in 11 repos~1.7k tokens
    AI & LLM EngineeringAuto-check passed
  • Databricks ML Training

    databricks/databricks-agent-skills

    Official

    Train ML models on Databricks. An agent skill from databricks/databricks-agent-skills.

    345 GitHub stars~4.6k tokensUpdated today
    AI & LLM EngineeringAuto-check passed
  • Official

    Convert existing PyTorch Lightning training code into an NVFLARE federated job using the Lightning Client API patch, local validation, and job export; use only when the request names…

    3.5k GitHub stars~3.3k tokensUpdated today
    AI & LLM EngineeringAuto-check passed
  • Pytorch Lightning Guide

    wentorai/research-plugins

    PyTorch Lightning framework for scalable model training and research

    298 GitHub starsUsed in 1 repo~2k tokens
    AI & LLM EngineeringAuto-check passed
  • RWKV Architecture Guide

    Orchestra-Research/AI-Research-SKILLs

    Explains RWKV, a hybrid that trains in parallel like a GPT and runs inference like an RNN with constant memory per token, plus usage, fine-tuning and troubleshooting.

    13k GitHub starsUsed in 2 repos~1.8k tokens
    AI & LLM EngineeringAuto-check passed

More from K-Dense-AI/scientific-agent-skills

All 153 skills in this repo
  • 13C Metabolic Flux Analysis

    K-Dense-AI/scientific-agent-skills

    Estimates reaction fluxes inside cells from steady-state carbon-13 labeling data with a bundled mfapy-based solver, and reports which fluxes the data pin down.

    48k GitHub starsUsed in 1 repo~3.2k tokens
    Auto-check passed
  • Analytical Method Validation Planner

    K-Dense-AI/scientific-agent-skills

    Plans, runs, and documents analytical method validation, verification, or transfer studies under ICH Q2(R2)/Q14, USP, ICH M10, CLSI EP, or ISO/IEC 17025.

    48k GitHub starsUsed in 1 repo~4.9k tokens
    Auto-check: notes
  • Cantera Ignition Delay

    K-Dense-AI/scientific-agent-skills

    Runs Cantera constant-volume or constant-pressure ignition simulations and reports temperature-based ignition delay with mechanism provenance and checks.

    48k GitHub starsUsed in 1 repo~2.2k tokens
    Auto-check passed
  • DiffDock Molecular Docking

    K-Dense-AI/scientific-agent-skills

    Predicts how small molecules bind to a protein with DiffDock, covering batch docking, pose ranking by confidence and checks on the results; not for binding affinity.

    48k GitHub starsUsed in 1 repo~3k tokens
    Auto-check: notes
  • HypoGeniC Hypothesis Generation

    K-Dense-AI/scientific-agent-skills

    Plans and audits runs of the HypoGeniC and HypoRefine packages, which propose hypotheses from labeled text datasets, with local checks before any model call.

    48k GitHub starsUsed in 1 repo~3.6k tokens
    Auto-check: notes
  • ISO Standards Readiness Evidence

    K-Dense-AI/scientific-agent-skills

    Organizes scope, controlled documents, risk files and traceability into draft evidence for human review against ISO 13485, 14971, 17025 and 15189.

    48k GitHub starsUsed in 1 repo~4.6k tokens
    Auto-check: notes

Questions about Pytorch Lightning

What does Pytorch Lightning do?

Deep learning framework (PyTorch Lightning / lightning package). Pytorch Lightning is an agent skill from K-Dense-AI/scientific-agent-skills. Deep learning framework (PyTorch Lightning / lightning package).

When should I use Pytorch Lightning?

Pytorch Lightning fits situations like: tasks that involve Deep learning.

How do I install Pytorch Lightning in Claude Code?

Run `npx skills add K-Dense-AI/scientific-agent-skills --skill pytorch-lightning -a claude-code`. Or copy the skill folder (skills/pytorch-lightning in K-Dense-AI/scientific-agent-skills) into .claude/skills/pytorch-lightning in your project. Claude Code loads it when a task matches its description.

How do I install Pytorch Lightning in Codex?

Run `npx skills add K-Dense-AI/scientific-agent-skills --skill pytorch-lightning -a codex`. Or copy the skill folder (skills/pytorch-lightning in K-Dense-AI/scientific-agent-skills) into .agents/skills/pytorch-lightning in your project. Codex loads it when a task matches its description.

Can I use Pytorch Lightning in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add K-Dense-AI/scientific-agent-skills --skill pytorch-lightning -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/pytorch-lightning, .gemini/skills/pytorch-lightning, .github/skills/pytorch-lightning and .opencode/skills/pytorch-lightning in your project.

What does Pytorch Lightning need to run?

Going by SKILL.md and its folder, Pytorch Lightning needs Python for the scripts in its folder and the command-line tools its instructions call (uv). Our summary lists: Python 3. Its frontmatter pre-approves these tools: Read, Write, Edit, Bash. Compatibility (from SKILL.md): Requires Python 3.10+ with lightning 2.6.6 and compatible PyTorch. CPU examples need no network after installation. CUDA/DDP/FSDP/DeepSpeed need suitable hardware; optional loggers require separate packages and online services need credentials/network..

Does Pytorch Lightning access the network?

SKILL.md names 5 domains. As links in the text: lightning.ai, arxiv.org, github.com, doi.org and export.arxiv.org. This is read from the text; nothing was executed.

Is Pytorch Lightning safe to install?

Our automated static check of SKILL.md found notes only (pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does Pytorch Lightning use?

Pytorch Lightning is published under the Apache-2.0 licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Pytorch Lightning use?

About 2.6k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 11k tokens, read only when the agent opens those files.

What are the alternatives to Pytorch Lightning?

Skills that share tags, products or a category with Pytorch Lightning: PyTorch Lightning Training (Orchestra-Research/AI-Research-SKILLs, 13k stars), PyTorch Lightning Training Setup (davila7/claude-code-templates, 32k stars), Databricks ML Training (databricks/databricks-agent-skills, 345 stars) and Nvflare Convert Lightning (NVIDIA/skills, 3.5k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Pytorch Lightning?

K-Dense-AI (a GitHub organization) maintains it in K-Dense-AI/scientific-agent-skills, which has 48,095 GitHub stars. The repository holds 153 skills in this directory. The repository was last updated on October 5, 2026.

Source: K-Dense-AI/scientific-agent-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.