lightning
Build, configure, debug, distribute, and deploy PyTorch Lightning and Lightning Fabric workflows using Trainer, LightningModule, LightningCLI, Fabric, accelerators, strategies, and serving utilities.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- lightning
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- description
- Build, configure, debug, distribute, and deploy PyTorch Lightning and Lightning Fabric workflows using Trainer, LightningModule, LightningCLI, Fabric, accelerators, strategies, and serving utilities.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/package-overview.md2.9 KB
- 参考文档references/repo-provenance.md1.4 KB
- 参考文档references/repo-routing-metadata.json446 B
- 参考文档references/troubleshooting.md2.8 KB
- 脚本scripts/lightning_env_report.py2.6 KB
03 SKILL.md 正文
Lightning Repo Skill
Use this skill when working with Lightning, PyTorch Lightning, or Lightning Fabric training code, CLI/config-driven experiments, distributed accelerators, expert Fabric loops, or production prediction/serving workflows.
Start Here
- Prefer modern imports for new code:
import lightning as L,import lightning.pytorch as pl, orfrom lightning.fabric import Fabric. - Run a minimal import check before deeper debugging:
python -c "import lightning as L; import lightning.pytorch as pl; from lightning.fabric import Fabric; print(L.__version__, pl.Trainer, Fabric)"
- Pick the route by user intent, not by source module name.
- Use bundled smoke scripts for safe local validation before suggesting long training, downloads, GPUs, multi-process launch, or servers.
- Treat original Lightning examples and tests as evidence only. This skill bundles reusable scripts and distilled references so future agents do not need the source checkout.
Route Map
sub-skills/training-core/SKILL.md: standardLightningModule,LightningDataModule,Trainer, callbacks, loggers, checkpointing, tuning, reproducibility, conversion from raw PyTorch, and train/validate/test/predict loops.sub-skills/fabric-expert-loops/SKILL.md: expert-controlled PyTorch loops withFabric,fabric.setup,fabric.backward, manual optimizer steps, launch, logging, checkpoint IO, and custom trainers.sub-skills/cli-configuration/SKILL.md:LightningCLI,LightningArgumentParser, YAML config, environment variables,--print_config, subclass modes, optimizer/scheduler injection, and saved config behavior.sub-skills/distributed-accelerators/SKILL.md:accelerator,devices,strategy,precision, DDP, FSDP, DeepSpeed, model/tensor parallel, MPS/TPU/GPU, cluster, and backend troubleshooting.sub-skills/deployment-serving/SKILL.md: prediction-only code, checkpoint inference, pure PyTorch conversion, TorchScript/ONNX/torch.export, pruning/quantization,ServableModule, and serving validation.
Shared References
references/package-overview.md: package layout, install variants, import aliases, optional extras, and compatibility notes.references/troubleshooting.md: cross-cutting install/import, dependency, version, optional-extra, and environment issues.references/repo-provenance.md: source repository state, evidence paths, version, and refresh baseline.scripts/lightning_env_report.py: self-contained environment/import diagnostic helper for Lightning installations.
Common Decisions
- Use
Trainerwhen Lightning should own loops, devices, precision, callbacks, logging, and checkpoints. - Use
Fabricwhen the user needs a custom PyTorch loop but wants Lightning to handle device, precision, distributed setup, logging, or checkpoint helpers. - Use
LightningCLIwhen classes should be instantiated from command-line/YAML/env config instead of hand-written argparse. - Use
distributed-acceleratorsbefore recommending FSDP, DeepSpeed, TPU, MPS, FP8, or multi-node settings; runtime GPU/distributed validation is environment-specific. - Use
deployment-servingwhen the goal is inference, export, serving, or removing Lightning from a production runtime.
Safe Validation Commands
python scripts/lightning_env_report.py --json
python sub-skills/training-core/scripts/lightning_smoke.py --help
python sub-skills/fabric-expert-loops/scripts/fabric_smoke.py --help
python sub-skills/cli-configuration/scripts/lightning_cli_smoke.py --help
python sub-skills/distributed-accelerators/scripts/strategy_config_check.py --help
python sub-skills/deployment-serving/scripts/servable_smoke.py --help
Run tiny CPU smoke executions only when the target environment has Lightning and Torch installed. Do not run long training, downloads, multi-process launch, server startup, or GPU-specific checks unless the user explicitly asks and the environment is suitable.
Compatibility Notes
- New code should prefer the
lightningpackage andlightning.pytorchnamespace. - Existing code may still use
pytorch_lightning; keep migration advice practical and avoid rewriting imports unless it is part of the task. - Some optional workflows require extras such as
jsonargparse[signatures], server packages, logger integrations,deepspeed, XLA, or accelerator-specific packages. Install the smallest extra that matches the selected workflow.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).