From 22985d2f43194ea57cd961b264788b5505e2f63e Mon Sep 17 00:00:00 2001 From: Joseph Turian Date: Tue, 2 Mar 2021 10:31:07 +0100 Subject: [PATCH] Improved EarlyStopping.patience documentation (#6278) * Improved early stopping documentation * Changed to 120 column format * doc * doc * doc Co-authored-by: Jirka Borovec --- notebooks/05-trainer-flags-overview.ipynb | 2 +- pytorch_lightning/callbacks/early_stopping.py | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/notebooks/05-trainer-flags-overview.ipynb b/notebooks/05-trainer-flags-overview.ipynb index a116bb2d78fbc..eb604be5e1559 100644 --- a/notebooks/05-trainer-flags-overview.ipynb +++ b/notebooks/05-trainer-flags-overview.ipynb @@ -2545,7 +2545,7 @@ "id": "7TAIerPYe_Q1" }, "source": [ - "The EarlyStopping callback runs at the end of every validation epoch, which, under the default configuration, happens after every training epoch. However, the frequency of validation can be modified by setting various parameters on the Trainer, for example check_val_every_n_epoch and val_check_interval. It must be noted that the patience parameter counts the number of validation epochs with no improvement, and not the number of training epochs. Therefore, with parameters check_val_every_n_epoch=10 and patience=3, the trainer will perform at least 40 training epochs before being stopped." + "The EarlyStopping callback runs at the end of every validation check, which, under the default configuration, happens after every training epoch. However, the frequency of validation can be modified by setting various parameters on the Trainer, for example check_val_every_n_epoch and val_check_interval. It must be noted that the patience parameter counts the number of validation checks with no improvement, and not the number of training epochs. Therefore, with parameters check_val_every_n_epoch=10 and patience=3, the trainer will perform at least 40 training epochs before being stopped." ] }, { diff --git a/pytorch_lightning/callbacks/early_stopping.py b/pytorch_lightning/callbacks/early_stopping.py index 9bcd028fa44eb..ff5cfeaf1bb96 100644 --- a/pytorch_lightning/callbacks/early_stopping.py +++ b/pytorch_lightning/callbacks/early_stopping.py @@ -33,22 +33,26 @@ class EarlyStopping(Callback): Monitor a metric and stop training when it stops improving. Args: - monitor: quantity to be monitored. Default: ``'early_stop_on'``. - min_delta: minimum change in the monitored quantity - to qualify as an improvement, i.e. an absolute - change of less than `min_delta`, will count as no - improvement. Default: ``0.0``. - patience: number of validation epochs with no improvement - after which training will be stopped. Default: ``3``. - verbose: verbosity mode. Default: ``False``. - mode: one of ``'min'``, ``'max'``. In ``'min'`` mode, - training will stop when the quantity - monitored has stopped decreasing and in ``'max'`` - mode it will stop when the quantity + monitor: quantity to be monitored. + min_delta: minimum change in the monitored quantity to qualify as an improvement, i.e. an absolute + change of less than `min_delta`, will count as no improvement. + patience: number of validation checks with no improvement + after which training will be stopped. Under the default configuration, one validation check happens after + every training epoch. However, the frequency of validation can be modified by setting various parameters on + the ``Trainer``, for example ``check_val_every_n_epoch`` and ``val_check_interval``. + + .. note:: + + It must be noted that the patience parameter counts the number of validation checks with + no improvement, and not the number of training epochs. Therefore, with parameters + ``check_val_every_n_epoch=10`` and ``patience=3``, the trainer will perform at least 40 training + epochs before being stopped. + + verbose: verbosity mode. + mode: one of ``'min'``, ``'max'``. In ``'min'`` mode, training will stop when the quantity + monitored has stopped decreasing and in ``'max'`` mode it will stop when the quantity monitored has stopped increasing. - - strict: whether to crash the training if `monitor` is - not found in the validation metrics. Default: ``True``. + strict: whether to crash the training if `monitor` is not found in the validation metrics. Raises: MisconfigurationException: