mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +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>
67 lines
2.4 KiB
ReStructuredText
67 lines
2.4 KiB
ReStructuredText
.. testsetup:: *
|
|
|
|
from pytorch_lightning.trainer.trainer import Trainer
|
|
from pytorch_lightning.callbacks.early_stopping import EarlyStopping
|
|
|
|
|
|
Early stopping
|
|
==============
|
|
|
|
Stopping an epoch early
|
|
-----------------------
|
|
You can stop an epoch early by overriding :meth:`~pytorch_lightning.core.lightning.LightningModule.on_batch_start` to return `-1` when some condition is met.
|
|
|
|
If you do this repeatedly, for every epoch you had originally requested, then this will stop your entire run.
|
|
|
|
Default Epoch End Callback Behavior
|
|
-----------------------------------
|
|
By default early stopping will be enabled if `'val_loss'`
|
|
is found in :meth:`~pytorch_lightning.core.lightning.LightningModule.validation_epoch_end`'s
|
|
return dict. Otherwise training will proceed with early stopping disabled.
|
|
|
|
Enable Early Stopping using Callbacks on epoch end
|
|
--------------------------------------------------
|
|
There are two ways to enable early stopping using callbacks on epoch end.
|
|
|
|
- Set early_stop_callback to True. Will look for 'val_loss' in validation_epoch_end() return dict.
|
|
If it is not found an error is raised.
|
|
|
|
.. testcode::
|
|
|
|
trainer = Trainer(early_stop_callback=True)
|
|
|
|
- Or configure your own callback
|
|
|
|
.. testcode::
|
|
|
|
early_stop_callback = EarlyStopping(
|
|
monitor='val_loss',
|
|
min_delta=0.00,
|
|
patience=3,
|
|
verbose=False,
|
|
mode='min'
|
|
)
|
|
trainer = Trainer(early_stop_callback=early_stop_callback)
|
|
|
|
In any case, the callback will fall back to the training metrics (returned in
|
|
:meth:`~pytorch_lightning.core.lightning.LightningModule.training_step`,
|
|
:meth:`~pytorch_lightning.core.lightning.LightningModule.training_step_end`)
|
|
looking for a key to monitor if validation is disabled or
|
|
:meth:`~pytorch_lightning.core.lightning.LightningModule.validation_epoch_end`
|
|
is not defined.
|
|
|
|
.. seealso::
|
|
- :class:`~pytorch_lightning.trainer.trainer.Trainer`
|
|
- :class:`~pytorch_lightning.callbacks.early_stopping.EarlyStopping`
|
|
|
|
Disable Early Stopping with callbacks on epoch end
|
|
--------------------------------------------------
|
|
To disable early stopping pass ``False`` to the
|
|
:paramref:`~pytorch_lightning.trainer.trainer.Trainer.early_stop_callback`.
|
|
Note that ``None`` will not disable early stopping but will lead to the
|
|
default behaviour.
|
|
|
|
.. seealso::
|
|
- :class:`~pytorch_lightning.trainer.trainer.Trainer`
|
|
- :class:`~pytorch_lightning.callbacks.early_stopping.EarlyStopping`
|