442 lines
11 KiB
ReStructuredText
Raw Normal View History

doctest for .rst files (#1511) * 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>
2020-05-05 04:16:54 +02:00
.. testsetup:: *
from pytorch_lightning.trainer.trainer import Trainer
from pytorch_lightning.callbacks.base import Callback
Clean docs (#725) * updated gitignore * updated gitignore * updated links in ninja file * updated docs * finished callbacks * finished callbacks * finished callbacks * fixed left menu * added callbacks to menu * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * updated gitignore * updated links in ninja file * updated docs * finished callbacks * finished callbacks * finished callbacks * fixed left menu * added callbacks to menu * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * finished rebase * making private members * making private members * making private members * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * set auto dp if no backend * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * fixed lightning import * cleared spaces * cleared spaces * cleared spaces * cleared spaces * cleared spaces * cleared spaces * cleared spaces * cleared spaces * cleared spaces * cleared spaces * finished lightning module * finished lightning module * finished lightning module * finished lightning module * added callbacks * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * set auto dp if no backend * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * flake 8 * flake 8 * fix docs path * updated gitignore * updated gitignore * updated links in ninja file * updated docs * finished callbacks * finished callbacks * finished callbacks * fixed left menu * added callbacks to menu * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * updated gitignore * updated docs * finished callbacks * finished callbacks * finished callbacks * fixed left menu * added callbacks to menu * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * added direct links to docs * finished rebase * making private members * making private members * making private members * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * set auto dp if no backend * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * working on trainer docs * fixed lightning import * cleared spaces * cleared spaces * cleared spaces * cleared spaces * cleared spaces * finished lightning module * finished lightning module * finished lightning module * finished lightning module * added callbacks * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * added loggers * flake 8 * flake 8 * fix docs path * flake 8 * Update theme_variables.jinja
2020-01-21 15:18:32 -05:00
.. role:: hidden
:class: hidden-section
CI: Force docs warnings to be raised as errors (+ fix all) (#1191) * add argument to force warn * fix automodule error * fix permalink error * fix indentation warning * fix warning * fix import warnings * fix duplicate label warning * fix bullet point indentation warning * fix duplicate label warning * fix "import not top level" warning * line too long * fix indentation * fix bullet points indentation warning * fix hooks warnings * fix reference problem with excluded test_tube * fix indentation in print * change imports for trains logger * remove pandas type annotation * Update pytorch_lightning/core/lightning.py * include bullet points inside note * remove old quick start guide (unused) * fix unused warning * fix formatting * fix duplicate label issue * fix duplicate label warning (replaced by class ref) * fix tick * fix indentation warnings * docstring ticks * remove obsolete docstring typing * Revert "remove old quick start guide (unused)" This reverts commit d51bb40695442c8fa11bc9df74f6db56264f7509. * added old quick start guide to navigation * remove unused tutorials file * ignore some modules that got deprecated and are not used anymore * fix duplicate label warning * move examples doc and exclude pl_examples from autodoc * fix formatting for configure_optimizer * fix no blank line warnings * fix "see also" labels and add paramref extension * fix more reference problems * fix multi-gpu reference * fix weird warning * fix indentation and unrecognized characters in code block * fix warning "... not included in toctree" * fix PIL import error * fix duplicate target "here" warning * fix broken link * revert accidentally moved pl_examples * changelog * stdout * note some things to know Co-Authored-By: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: J. Borovec <jirka.borovec@seznam.cz> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com>
2020-03-20 20:49:01 +01:00
.. _callbacks:
Callback
========
.. raw:: html
2020-10-12 17:57:51 -04:00
<video width="100%" max-width="400px" controls
poster="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/pl_docs/trainer_flags/thumb/callbacks.jpg"
src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/pl_docs/trainer_flags/callbacks.mp4"></video>
|
2020-08-13 09:58:05 -04:00
A callback is a self-contained program that can be reused across projects.
2020-08-13 09:58:05 -04:00
Lightning has a callback system to execute callbacks when needed. Callbacks should capture NON-ESSENTIAL
logic that is NOT required for your :doc:`lightning module <../common/lightning_module>` to run.
Here's the flow of how the callback hooks are executed:
.. raw:: html
2020-10-12 17:57:51 -04:00
<video width="100%" max-width="400px" controls autoplay muted playsinline src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/pl_docs/pt_callbacks_mov.m4v"></video>
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 for .rst files (#1511) * 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>
2020-05-05 04:16:54 +02:00
.. testcode::
2020-10-12 20:22:28 -04:00
from pytorch_lightning.callbacks import Callback
2020-10-12 18:30:57 -04:00
doctest for .rst files (#1511) * 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>
2020-05-05 04:16:54 +02:00
class MyPrintingCallback(Callback):
doctest for .rst files (#1511) * 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>
2020-05-05 04:16:54 +02:00
def on_init_start(self, trainer):
print("Starting to init trainer!")
doctest for .rst files (#1511) * 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>
2020-05-05 04:16:54 +02:00
def on_init_end(self, trainer):
print("trainer is init now")
doctest for .rst files (#1511) * 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>
2020-05-05 04:16:54 +02:00
def on_train_end(self, trainer, pl_module):
print("do something when training ends")
doctest for .rst files (#1511) * 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>
2020-05-05 04:16:54 +02:00
trainer = Trainer(callbacks=[MyPrintingCallback()])
.. testoutput::
Starting to init trainer!
trainer is init now
We successfully extended functionality without polluting our super clean
:doc:`lightning module <../common/lightning_module>` research code.
2020-08-13 09:58:05 -04:00
-----------
Examples
--------
You can do pretty much anything with callbacks.
- `Add a MLP to fine-tune self-supervised networks <https://lightning-bolts.readthedocs.io/en/latest/self_supervised_callbacks.html#sslonlineevaluator>`_.
- `Find how to modify an image input to trick the classification result <https://lightning-bolts.readthedocs.io/en/latest/vision_callbacks.html#confused-logit>`_.
- `Interpolate the latent space of any variational model <https://lightning-bolts.readthedocs.io/en/latest/variational_callbacks.html#latent-dim-interpolator>`_.
- `Log images to Tensorboard for any model <https://lightning-bolts.readthedocs.io/en/latest/vision_callbacks.html#tensorboard-image-generator>`_.
2020-08-13 09:58:05 -04:00
--------------
Built-in Callbacks
------------------
Lightning has a few built-in callbacks.
.. note::
For a richer collection of callbacks, check out our
`bolts library <https://lightning-bolts.readthedocs.io/en/latest/callbacks.html>`_.
2020-08-13 09:58:05 -04:00
.. currentmodule:: pytorch_lightning.callbacks
.. autosummary::
:toctree: generated
:nosignatures:
:template: classtemplate.rst
BackboneFinetuning
BaseFinetuning
BasePredictionWriter
Callback
DeviceStatsMonitor
EarlyStopping
GPUStatsMonitor
GradientAccumulationScheduler
LambdaCallback
LearningRateMonitor
ModelCheckpoint
ModelPruning
ModelSummary
ProgressBar
ProgressBarBase
RichModelSummary
RichProgressBar
QuantizationAwareTraining
StochasticWeightAveraging
XLAStatsMonitor
2020-08-13 09:58:05 -04:00
----------
.. _Persisting Callback State:
Persisting State
----------------
Some callbacks require internal state in order to function properly. You can optionally
choose to persist your callback's state as part of model checkpoint files using the callback hooks
:meth:`~pytorch_lightning.callbacks.Callback.on_save_checkpoint` and :meth:`~pytorch_lightning.callbacks.Callback.on_load_checkpoint`.
Note that the returned state must be able to be pickled.
When your callback is meant to be used only as a singleton callback then implementing the above two hooks is enough
to persist state effectively. However, if passing multiple instances of the callback to the Trainer is supported, then
the callback must define a :attr:`~pytorch_lightning.callbacks.Callback.state_key` property in order for Lightning
to be able to distinguish the different states when loading the callback state. This concept is best illustrated by
the following example.
.. testcode::
class Counter(Callback):
def __init__(self, what="epochs", verbose=True):
self.what = what
self.verbose = verbose
self.state = {"epochs": 0, "batches": 0}
@property
def state_key(self):
# note: we do not include `verbose` here on purpose
return self._generate_state_key(what=self.what)
def on_train_epoch_end(self, *args, **kwargs):
if self.what == "epochs":
self.state["epochs"] += 1
def on_train_batch_end(self, *args, **kwargs):
if self.what == "batches":
self.state["batches"] += 1
def on_load_checkpoint(self, trainer, pl_module, callback_state):
self.state.update(callback_state)
def on_save_checkpoint(self, trainer, pl_module, checkpoint):
return self.state.copy()
# two callbacks of the same type are being used
trainer = Trainer(callbacks=[Counter(what="epochs"), Counter(what="batches")])
A Lightning checkpoint from this Trainer with the two stateful callbacks will include the following information:
.. code-block::
{
"state_dict": ...,
"callbacks": {
"Counter{'what': 'batches'}": {"batches": 32, "epochs": 0},
"Counter{'what': 'epochs'}": {"batches": 0, "epochs": 2},
...
}
}
The implementation of a :attr:`~pytorch_lightning.callbacks.Callback.state_key` is essential here. If it were missing,
Lightning would not be able to disambiguate the state for these two callbacks, and :attr:`~pytorch_lightning.callbacks.Callback.state_key`
by default only defines the class name as the key, e.g., here ``Counter``.
Best Practices
--------------
The following are best practices when using/designing callbacks.
1. Callbacks should be isolated in their functionality.
2. Your callback should not rely on the behavior of other callbacks in order to work properly.
3. Do not manually call methods from the callback.
4. Directly calling methods (eg. `on_validation_end`) is strongly discouraged.
5. Whenever possible, your callbacks should not depend on the order in which they are executed.
2020-10-12 17:57:51 -04:00
-----------
.. _hooks:
Available Callback hooks
------------------------
setup
^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.setup
:noindex:
teardown
^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.teardown
:noindex:
on_init_start
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_init_start
2020-10-12 17:57:51 -04:00
:noindex:
on_init_end
^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_init_end
2020-10-12 17:57:51 -04:00
:noindex:
on_fit_start
^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_fit_start
2020-10-12 17:57:51 -04:00
:noindex:
on_fit_end
^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_fit_end
2020-10-12 17:57:51 -04:00
:noindex:
on_sanity_check_start
^^^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_sanity_check_start
:noindex:
on_sanity_check_end
^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_sanity_check_end
:noindex:
on_train_batch_start
^^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_train_batch_start
:noindex:
on_train_batch_end
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_train_batch_end
2020-10-12 17:57:51 -04:00
:noindex:
on_train_epoch_start
^^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_train_epoch_start
:noindex:
on_train_epoch_end
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_train_epoch_end
2020-10-12 17:57:51 -04:00
:noindex:
on_validation_epoch_start
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_validation_epoch_start
2020-10-12 17:57:51 -04:00
:noindex:
on_validation_epoch_end
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_validation_epoch_end
2020-10-12 17:57:51 -04:00
:noindex:
on_test_epoch_start
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_test_epoch_start
2020-10-12 17:57:51 -04:00
:noindex:
on_test_epoch_end
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_test_epoch_end
2020-10-12 17:57:51 -04:00
:noindex:
on_epoch_start
^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_epoch_start
2020-10-12 17:57:51 -04:00
:noindex:
on_epoch_end
^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_epoch_end
2020-10-12 17:57:51 -04:00
:noindex:
on_batch_start
^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_batch_start
2020-10-12 17:57:51 -04:00
:noindex:
on_validation_batch_start
^^^^^^^^^^^^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_validation_batch_start
2020-10-12 17:57:51 -04:00
:noindex:
on_validation_batch_end
^^^^^^^^^^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_validation_batch_end
2020-10-12 17:57:51 -04:00
:noindex:
on_test_batch_start
^^^^^^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_test_batch_start
2020-10-12 17:57:51 -04:00
:noindex:
on_test_batch_end
^^^^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_test_batch_end
2020-10-12 17:57:51 -04:00
:noindex:
on_batch_end
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_batch_end
2020-10-12 17:57:51 -04:00
:noindex:
on_train_start
^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_train_start
2020-10-12 17:57:51 -04:00
:noindex:
on_train_end
^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_train_end
2020-10-12 17:57:51 -04:00
:noindex:
on_pretrain_routine_start
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_pretrain_routine_start
2020-10-12 17:57:51 -04:00
:noindex:
on_pretrain_routine_end
2020-10-12 17:57:51 -04:00
^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_pretrain_routine_end
2020-10-12 17:57:51 -04:00
:noindex:
on_validation_start
^^^^^^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_validation_start
2020-10-12 17:57:51 -04:00
:noindex:
on_validation_end
^^^^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_validation_end
2020-10-12 17:57:51 -04:00
:noindex:
on_test_start
^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_test_start
2020-10-12 17:57:51 -04:00
:noindex:
on_test_end
^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_test_end
2020-10-12 17:57:51 -04:00
:noindex:
on_keyboard_interrupt
^^^^^^^^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_keyboard_interrupt
2020-10-12 17:57:51 -04:00
:noindex:
on_exception
^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_exception
:noindex:
on_save_checkpoint
^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_save_checkpoint
:noindex:
on_load_checkpoint
^^^^^^^^^^^^^^^^^^
2020-10-12 17:57:51 -04:00
.. automethod:: pytorch_lightning.callbacks.Callback.on_load_checkpoint
2020-10-12 17:57:51 -04:00
:noindex:
Add the `on_before_backward` hook (#7865) * Add callback to hook tests and add predict test * Fix lambda callback test * Simplify lambda call test * Use LambdaCallback * Dynamically append to called for the model * Remove print * Consistency * Consistency * Prepare args/kwargs testing * yapf doesn't like dict literals * Add arguments for fit no val test * Add arguments for fit no val test * add before_backward_hook * add test * resolve flake8 * resolve tests * update changelog * add on_before_backward to LightningModule * update on comments * Test arguments * Datamodule refactor * Fix eval test * remove extra file * resolve bug * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * move to hooks * update * resolve flake8 * update on comments * Update full fit + val test * Update test * Remove FIXME * Remove FIXME * Undo change * Fix * Parametrize fit hook test * Comment * Parametrize fit hook test with different precision plugins * Fix tests * Parametrize fit hook test with manual optimization * Unnecessary parenthesis * WIP * Comments * Fix message * Test CI error * Revert "Test CI error" This reverts commit 39c4a85a83cf32081b721f939ff83500b93f2dd3. * Add ddp training type teardown * Update CHANGELOG * Adrian's fix * Use destructor * Update CHANGELOG.md * RPC destructor * Update pytorch_lightning/plugins/training_type/ddp.py * Why do you not work :( * Missing condition * Fix deepspeed test * GC collect in conftest * Do not show warnings for special tests * Needs to run on 1.8 To avoid: "RuntimeError: NCCL error in: /pytorch/torch/lib/c10d/ProcessGroupNCCL.cpp:32, unhandled cuda error, NCCL version 2.4.8" * Run torch 1.8 * Skip test due to 'Python bus error' * Debug NCCL * shm size * Disable warnings for special tests * Remove NCCL_DEBUG statement * Try smaller shm size * Revert "Skip test due to 'Python bus error'" This reverts commit e0a3e8785d2fecd63667da433a648f958d60ef89. * README and adjust versions * Avoid self.on_gpu call * empty cache cleanup * More garbage collection * Unroll parametrizations * Do not reuse mock * Undo changes * Undo notebooks modification * resolve test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * delete file * Undo * Fix test * Revert "WIP" This reverts commit f5828a8c426ff44275f560aec8d898f56da2cbfe. * Rename * Remove optimizers * Fix bug with LightningOptimizer * Add optimizers * update * update * Update CHANGELOG * On after backward refactor * Do not call super * Fixes * Remove should_accumulate * pre/post backward refactor * Call the LM backward hook * Update tests * Remove dev debug patch * Fix test * Remove optimizer arguments and typing * Docs fixes * Fix comment * Undo changes * Split manual and auto * Undo change * Deepsource * Remove optimizers * Undo changes * Call the hook * Docs * Docs Co-authored-by: Carlos Mocholi <carlossmocholi@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Adrian Wälchli <aedu.waelchli@gmail.com>
2021-07-09 08:15:57 +02:00
on_before_backward
^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_before_backward
:noindex:
on_after_backward
^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_after_backward
:noindex:
on_before_optimizer_step
^^^^^^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_before_optimizer_step
:noindex:
on_before_zero_grad
^^^^^^^^^^^^^^^^^^^
.. automethod:: pytorch_lightning.callbacks.Callback.on_before_zero_grad
:noindex: