flâneur — a map of the web's best reading

LightningModule — PyTorch Lightning 2.4.0 documentation

lightning.ai · 13,946 words · saved by 1 readers

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