2020-01-21 20:18:32 +00:00
|
|
|
.. role:: hidden
|
|
|
|
:class: hidden-section
|
|
|
|
|
2020-03-20 19:49:01 +00:00
|
|
|
.. _callbacks:
|
|
|
|
|
2020-01-21 20:18:32 +00:00
|
|
|
Callbacks
|
2020-02-11 12:41:15 +00:00
|
|
|
=========
|
2020-02-27 22:21:51 +00:00
|
|
|
|
|
|
|
Lightning has a callback system to execute arbitrary code. Callbacks should capture NON-ESSENTIAL
|
2020-04-05 09:38:52 +00:00
|
|
|
logic that is NOT required for your :class:`~pytorch_lightning.core.LightningModule` to run.
|
2020-02-27 22:21:51 +00:00
|
|
|
|
|
|
|
An overall Lightning system should have:
|
|
|
|
|
|
|
|
1. Trainer for all engineering
|
|
|
|
2. LightningModule for all research code.
|
|
|
|
3. Callbacks for non-essential code.
|
|
|
|
|
|
|
|
|
2020-04-05 09:38:52 +00:00
|
|
|
Example:
|
|
|
|
|
|
|
|
.. doctest::
|
|
|
|
|
|
|
|
>>> import pytorch_lightning as pl
|
|
|
|
>>> class MyPrintingCallback(pl.Callback):
|
|
|
|
...
|
|
|
|
... def on_init_start(self, trainer):
|
|
|
|
... print('Starting to init trainer!')
|
|
|
|
...
|
|
|
|
... def on_init_end(self, trainer):
|
|
|
|
... print('trainer is init now')
|
|
|
|
...
|
|
|
|
... def on_train_end(self, trainer, pl_module):
|
|
|
|
... print('do something when training ends')
|
|
|
|
...
|
|
|
|
>>> trainer = pl.Trainer(callbacks=[MyPrintingCallback()])
|
|
|
|
Starting to init trainer!
|
|
|
|
trainer is init now
|
|
|
|
|
|
|
|
We successfully extended functionality without polluting our super clean
|
|
|
|
:class:`~pytorch_lightning.core.LightningModule` research code.
|
2020-02-27 22:21:51 +00:00
|
|
|
|
2020-03-03 21:42:49 +00:00
|
|
|
---------
|
|
|
|
|
2020-03-03 16:39:43 +00:00
|
|
|
.. automodule:: pytorch_lightning.callbacks.base
|
|
|
|
:noindex:
|
|
|
|
:exclude-members:
|
|
|
|
_del_model,
|
|
|
|
_save_model,
|
|
|
|
_abc_impl,
|
|
|
|
check_monitor_top_k,
|
|
|
|
|
2020-03-03 21:42:49 +00:00
|
|
|
---------
|
|
|
|
|
2020-03-03 16:39:43 +00:00
|
|
|
.. automodule:: pytorch_lightning.callbacks.early_stopping
|
|
|
|
:noindex:
|
|
|
|
:exclude-members:
|
|
|
|
_del_model,
|
|
|
|
_save_model,
|
|
|
|
_abc_impl,
|
|
|
|
check_monitor_top_k,
|
|
|
|
|
2020-03-03 21:42:49 +00:00
|
|
|
---------
|
|
|
|
|
2020-03-03 16:39:43 +00:00
|
|
|
.. automodule:: pytorch_lightning.callbacks.model_checkpoint
|
|
|
|
:noindex:
|
|
|
|
:exclude-members:
|
|
|
|
_del_model,
|
|
|
|
_save_model,
|
|
|
|
_abc_impl,
|
|
|
|
check_monitor_top_k,
|
2020-02-27 22:21:51 +00:00
|
|
|
|
2020-03-03 21:42:49 +00:00
|
|
|
---------
|
|
|
|
|
2020-03-03 16:39:43 +00:00
|
|
|
.. automodule:: pytorch_lightning.callbacks.gradient_accumulation_scheduler
|
2020-02-27 21:07:51 +00:00
|
|
|
:noindex:
|
2020-01-21 20:18:32 +00:00
|
|
|
:exclude-members:
|
|
|
|
_del_model,
|
|
|
|
_save_model,
|
2020-02-27 22:21:51 +00:00
|
|
|
_abc_impl,
|
2020-01-21 20:18:32 +00:00
|
|
|
check_monitor_top_k,
|