5.8 Add Functionality with Callbacks
What we covered in this video lecture
In this lecture, we learned how we can extend the Trainer functionality using pre-built and custom callbacks. A callback is a function or program that is passed as an argument to another function or class (in this case, the Lightning Trainer) and is executed after the outer function has completed.
In other words, a callback is a function that is called at the completion of a given task. This allows other code to be run in the meantime and prevents any blocking or waiting for the task to complete.
The Lightning Trainer has a callback mechanism for executing functions as needed. Callbacks are intended to handle non-critical logic that is not necessary for the proper functioning of a Lightning module. These functions can be executed after the main module has completed its execution.
For example, as we have seen in the video, we can execute callback functions when the training starts or finishes. But there are many additional entry points (see the
on_..._end methods in the documentation [here].
Additional resources if you want to learn more
Before building your own callbacks, it maybe a good idea to check the gallery of pre-built callbacks.
Log in or create a free Lightning.ai account to access:
- Completion badges
- Progress tracking
- Additional downloadable content
- Additional AI education resources
- Notifications when new units are released
- Free cloud computing credits