mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-08-21 11:20:03 +08:00
* add doctest to circleci * Revert "add doctest to circleci" This reverts commit c45b34ea911a81f87989f6c3a832b1e8d8c471c6. * Revert "Revert "add doctest to circleci"" This reverts commit 41fca97fdcfe1cf4f6bdb3bbba75d25fa3b11f70. * doctest docs rst files * Revert "doctest docs rst files" This reverts commit b4a2e83e3da5ed1909de500ec14b6b614527c07f. * doctest only rst * doctest debugging.rst * doctest apex * doctest callbacks * doctest early stopping * doctest for child modules * doctest experiment reporting * indentation * doctest fast training * doctest for hyperparams * doctests for lr_finder * doctests multi-gpu * more doctest * make doctest drone * fix label build error * update fast training * update invalid imports * fix problem with int device count * rebase stuff * wip * wip * wip * intro guide * add missing code block * circleci * logger import for doctest * test if doctest runs on drone * fix mnist download * also run install deps for building docs * install cmake * try sudo * hide output * try pip stuff * try to mock horovod * Tranfer -> Transfer * add torchvision to extras * revert pip stuff * mlflow file location * do not mock torch * torchvision * drone extra req. * try higher sphinx version * Revert "try higher sphinx version" This reverts commit 490ac28e46d6fd52352640dfdf0d765befa56988. * try coverage command * try coverage command * try undoc flag * newline * undo drone * report coverage * review Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * remove torchvision from extras * skip tests only if torchvision not available * fix testoutput torchvision Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
101 lines
2.1 KiB
ReStructuredText
101 lines
2.1 KiB
ReStructuredText
.. testsetup:: *
|
|
|
|
from pytorch_lightning.trainer.trainer import Trainer
|
|
from pytorch_lightning.callbacks.base import Callback
|
|
|
|
.. 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:
|
|
|
|
.. testcode::
|
|
|
|
class MyPrintingCallback(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 = Trainer(callbacks=[MyPrintingCallback()])
|
|
|
|
.. testoutput::
|
|
|
|
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 |