Lightning AI Studios: Never set up a local environment again →

Log in or create a free Lightning.ai account to track your progress and access additional course materials  

Organizing Your Code with Lightning

References

What we covered in this video lecture

In this video, we introduced the core Lightning API components for PyTorch models, namely, the LightningModule and the Trainer.

The LightningModule is a wrapper around a PyTorch model, and the Trainer is trains the wrapped model via the .fit() method.

Additional resources if you want to learn more

If you want to learn more about the capabilities of the Trainer, I recommend checking out the “Trainer flags” in the Trainer API documentation referenced above. However, since the Trainer comes with many bells and whistles, I recommend just bookmarking this resource and revisiting it later once you finish units 5 and 6 — we will go through a lot of its core functionality in these two units.

Log in or create a free Lightning.ai account to access:

  • Quizzes
  • Completion badges
  • Progress tracking
  • Additional downloadable content
  • Additional AI education resources
  • Notifications when new units are released
  • Free cloud computing credits

Quiz: 5.1 Organizing Your Code with PyTorch Lightning

Which of the following five methods are essential methods of a LightningModule?

Correct. The forward method defines the forward pass for calling the PyTorch model. We can use it inside the other methods below. Furthermore, it’s required if we want to use the LightningModule for inference without the trainer, i.e., via my_lightning_model = MyLightningModel(PyTorchModel, ...); my_lightning_model(data).

Correct. This method defines how we run a forward pass on a single batch, and it returns the loss for optimization.

Correct. This method returns defines how we create the predictions for an input batch. (Often, the content is similar to test_step).

Correct. This method returns defines how we create the predictions for an input batch. (Often, the content is similar to validation_step).

Correct. Here we configure the optimizers that are used for model training.

Please answer all questions to proceed.
Watch Video 1

Unit 5.1

Videos
Follow along in a Lightning Studio

DL Fundamentals 5: PyTorch Lightning

Sebastian
Launch Studio →
Questions or Feedback?

Join the Discussion