Trainer — PyTorch Lightning 2.4.0 documentation
Once you’ve organized your PyTorch code into a LightningModule, the Trainer automates everything else. The Trainer achieves the following: You maintain control over all aspects via PyTorch code in your LightningModule. The trainer uses best practices embedded by contributors and users from top AI labs such as Facebook AI Research, NYU, MIT, Stanford, etc… The trainer allows disabling any key part that you don’t want automated. This is the basic use of the trainer: The Lightning Trainer does much more than just “training”. Under the hood, it handles all loop details for you, some examples include: Automatically enabling/disabling grads Running the training, validation and test dataloaders Calling the Callbacks at the appropriate times Putting batches and computations on the correct devices Here’s the pseudocode for what the trainer does under the hood (showing the train loop only) In Python scripts, it’s recommended you use a main function to call the Trainer. So you can run it like so:
Trainer ¶ Once you’ve organized your PyTorch code into a LightningModule , the Trainer automates everything else. The Trainer achieves the following: You maintain control over all aspects via PyTorch code in your LightningModule . The trainer uses best practices embedded by contributors and users from top AI labs such as Facebook AI Research, NYU, MIT, Stanford, etc… The trainer allows disabling any key part that you don’t want automated. Basic use ¶ This is the basic use of the trainer: model = MyLightningModule () trainer = Trainer () trainer . fit ( model , train_dataloader , val_dataloader
related reading
- LightningModule - 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
- Saving and loading checkpoints (basic) - PyTorch Lightning 2.6.1 documentationlightning.ai
- ⚡ Migrating from PTL - Composerdocs.mosaicml.com
- Customize checkpointing behavior (intermediate) - PyTorch Lightning 2.6.1 documentationlightning.ai
- Making Deep Learning go Brrrr From First Principleshorace.io
- ModelCheckpoint - PyTorch Lightning 2.6.1 documentationlightning.ai
- Trainer · Hugging Facehuggingface.co
- Fine-tuning a model with the Trainer API · Hugging Facehuggingface.co
- PyTorch in One Hour: From Tensors to Training Neural Networks on Multiple GPUssebastianraschka.com
- A Recipe for Training Neural Networkskarpathy.github.io