1515import os
1616from abc import ABC
1717from argparse import ArgumentParser , Namespace
18- from typing import List , Optional , Type , TypeVar , Union , cast
18+ from typing import cast , List , Optional , Type , TypeVar , Union
1919
2020from pytorch_lightning .accelerators .accelerator import Accelerator
21- from pytorch_lightning .callbacks import Callback , ModelCheckpoint , ProgressBarBase
21+ from pytorch_lightning .callbacks import Callback , EarlyStopping , ModelCheckpoint , ProgressBarBase
2222from pytorch_lightning .core .lightning import LightningModule
2323from pytorch_lightning .core .optimizer import is_lightning_optimizer
2424from pytorch_lightning .loggers .base import LightningLoggerBase
2727from pytorch_lightning .trainer .connectors .logger_connector import LoggerConnector
2828from pytorch_lightning .trainer .connectors .model_connector import ModelConnector
2929from pytorch_lightning .trainer .states import TrainerState
30- from pytorch_lightning .utilities import HOROVOD_AVAILABLE , TPU_AVAILABLE , argparse_utils , rank_zero_warn
30+ from pytorch_lightning .utilities import argparse_utils , HOROVOD_AVAILABLE , rank_zero_warn , TPU_AVAILABLE
3131from pytorch_lightning .utilities .cloud_io import get_filesystem
3232from pytorch_lightning .utilities .model_utils import is_overridden
3333
@@ -196,7 +196,7 @@ def enable_validation(self) -> bool:
196196 """ Check if we should run validation during training. """
197197 model_ref = self .model_connector .get_model ()
198198 val_loop_enabled = is_overridden ('validation_step' , model_ref ) and self .limit_val_batches > 0
199- return val_loop_enabled or self . fast_dev_run
199+ return val_loop_enabled
200200
201201 @property
202202 def default_root_dir (self ) -> str :
@@ -218,18 +218,38 @@ def weights_save_path(self) -> str:
218218 return os .path .normpath (self ._weights_save_path )
219219 return self ._weights_save_path
220220
221+ @property
222+ def early_stopping_callback (self ) -> Optional [EarlyStopping ]:
223+ """
224+ The first :class:`~pytorch_lightning.callbacks.early_stopping.EarlyStopping`
225+ callback in the Trainer.callbacks list, or ``None`` if it doesn't exist.
226+ """
227+ callbacks = self .early_stopping_callbacks
228+ return callbacks [0 ] if len (callbacks ) > 0 else None
229+
230+ @property
231+ def early_stopping_callbacks (self ) -> List [EarlyStopping ]:
232+ """
233+ A list of all instances of :class:`~pytorch_lightning.callbacks.early_stopping.EarlyStopping`
234+ found in the Trainer.callbacks list.
235+ """
236+ return [c for c in self .callbacks if isinstance (c , EarlyStopping )]
237+
221238 @property
222239 def checkpoint_callback (self ) -> Optional [ModelCheckpoint ]:
223240 """
224- The first checkpoint callback in the Trainer .callbacks list, or ``None`` if
225- no checkpoint callbacks exist.
241+ The first :class:`~pytorch_lightning .callbacks.model_checkpoint.ModelCheckpoint`
242+ callback in the Trainer. callbacks list, or ``None`` if it doesn't exist.
226243 """
227244 callbacks = self .checkpoint_callbacks
228245 return callbacks [0 ] if len (callbacks ) > 0 else None
229246
230247 @property
231248 def checkpoint_callbacks (self ) -> List [ModelCheckpoint ]:
232- """ A list of all instances of ModelCheckpoint found in the Trainer.callbacks list. """
249+ """
250+ A list of all instances of :class:`~pytorch_lightning.callbacks.model_checkpoint.ModelCheckpoint`
251+ found in the Trainer.callbacks list.
252+ """
233253 return [c for c in self .callbacks if isinstance (c , ModelCheckpoint )]
234254
235255 def save_checkpoint (self , filepath , weights_only : bool = False ):
0 commit comments