mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-01 12:32:04 +08:00
* base implementation * docs + implementation * fix styling * add lr string * renaming * CHANGELOG.md * add tests * Apply suggestions from code review Co-Authored-By: Adrian Wälchli <aedu.waelchli@gmail.com> * Apply suggestions from code review * Update pytorch_lightning/callbacks/lr_logger.py * Update pytorch_lightning/callbacks/lr_logger.py * add test for naming * base implementation * docs + implementation * fix styling * add lr string * renaming * CHANGELOG.md * add tests * Apply suggestions from code review Co-Authored-By: Adrian Wälchli <aedu.waelchli@gmail.com> * Apply suggestions from code review * Update pytorch_lightning/callbacks/lr_logger.py * Update pytorch_lightning/callbacks/lr_logger.py * add test for naming * Update pytorch_lightning/callbacks/lr_logger.py Co-Authored-By: Adrian Wälchli <aedu.waelchli@gmail.com> * suggestions from code review * fix styling * rebase * fix tests Co-authored-by: Nicki Skafte <nugginea@gmail.com> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
94 lines
2.1 KiB
ReStructuredText
94 lines
2.1 KiB
ReStructuredText
.. role:: hidden
|
|
:class: hidden-section
|
|
|
|
.. _callbacks:
|
|
|
|
Callbacks
|
|
=========
|
|
|
|
Lightning has a callback system to execute arbitrary code. Callbacks should capture NON-ESSENTIAL
|
|
logic that is NOT required for your :class:`~pytorch_lightning.core.LightningModule` to run.
|
|
|
|
An overall Lightning system should have:
|
|
|
|
1. Trainer for all engineering
|
|
2. LightningModule for all research code.
|
|
3. Callbacks for non-essential code.
|
|
|
|
|
|
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.
|
|
|
|
---------
|
|
|
|
.. automodule:: pytorch_lightning.callbacks.base
|
|
:noindex:
|
|
:exclude-members:
|
|
_del_model,
|
|
_save_model,
|
|
_abc_impl,
|
|
check_monitor_top_k,
|
|
|
|
---------
|
|
|
|
.. automodule:: pytorch_lightning.callbacks.early_stopping
|
|
:noindex:
|
|
:exclude-members:
|
|
_del_model,
|
|
_save_model,
|
|
_abc_impl,
|
|
check_monitor_top_k,
|
|
|
|
---------
|
|
|
|
.. automodule:: pytorch_lightning.callbacks.model_checkpoint
|
|
:noindex:
|
|
:exclude-members:
|
|
_del_model,
|
|
_save_model,
|
|
_abc_impl,
|
|
check_monitor_top_k,
|
|
|
|
---------
|
|
|
|
.. automodule:: pytorch_lightning.callbacks.gradient_accumulation_scheduler
|
|
:noindex:
|
|
:exclude-members:
|
|
_del_model,
|
|
_save_model,
|
|
_abc_impl,
|
|
check_monitor_top_k,
|
|
|
|
---------
|
|
|
|
.. automodule:: pytorch_lightning.callbacks.progress
|
|
:noindex:
|
|
:exclude-members:
|
|
|
|
---------
|
|
|
|
.. automodule:: pytorch_lightning.callbacks.lr_logger
|
|
:noindex:
|
|
:exclude-members:
|
|
_extract_lr,
|
|
_find_names |