LightningModule — PyTorch Lightning 2.4.0 documentation
When you convert to use Lightning, the code IS NOT abstracted - just organized. All the other code that’s not in the LightningModule has been automated for you by the Trainer. There are no .cuda() or .to(device) calls required. Lightning does these for you. When running under a distributed strategy, Lightning handles the distributed sampler for you by default. A LightningModule is a torch.nn.Module but with added functionality. Use it as such! Thus, to use Lightning, you just need to organize your code which takes about 30 minutes, (and let’s be real, you probably should do anyway). Here are the only required methods. Which you can train by doing: The LightningModule has many convenient methods, but the core ones you need to know about are: Name Description __init__ and setup() Define initialization here forward() To run data through your model only (separate from training_step) training_step() the complete training step validation_step() the complete validation step test_step() the co
LightningModule ¶ A LightningModule organizes your PyTorch code into 6 sections: Initialization ( __init__ and setup() ). Train Loop ( training_step() ) Validation Loop ( validation_step() ) Test Loop ( test_step() ) Prediction Loop ( predict_step() ) Optimizers and LR Schedulers ( configure_optimizers() ) When you convert to use Lightning, the code IS NOT abstracted - just organized. All the other code that’s not in the LightningModule has been automated for you by the Trainer . net = MyLightningModuleNet () trainer = Trainer () trainer . fit ( net ) There are no .cuda() or .to(device) calls
Explore this link on the map →related reading
- Trainer - PyTorch Lightning 2.6.1 documentationlightning.ai
- Optimization - PyTorch Lightning 2.6.1 documentationlightning.ai
- Get Started with Distributed Training using PyTorch Lightning — Ray 2.56.0docs.ray.io
- ⚡ Migrating from PTL - Composerdocs.mosaicml.com
- Saving and loading checkpoints (basic) - PyTorch Lightning 2.6.1 documentationlightning.ai
- Customize checkpointing behavior (intermediate) - PyTorch Lightning 2.6.1 documentationlightning.ai
- Composer2.pdfcursor.com
- frontier model training methodologies | Alex Wa's Blogdjdumpling.github.io
- PyTorch internals : ezyang's blogblog.ezyang.com
- ModelCheckpoint - PyTorch Lightning 2.6.1 documentationlightning.ai
- [2604.13010] Lightning OPD: Efficient Post-Training for Large Reasoning Models with Offline On-Policy Distillationarxiv.org
- 👨👩👧👦 Distributed Training - Composerdocs.mosaicml.com