• Docs >
  • Utils >
  • torchtnt.utils.early_stop_checker.EarlyStopChecker
Shortcuts

torchtnt.utils.early_stop_checker.EarlyStopChecker

class torchtnt.utils.early_stop_checker.EarlyStopChecker(mode: Literal['min', 'max'], patience: int, min_delta: float = 0.0, check_finite: bool = True, threshold_mode: Literal['abs', 'rel'] = 'abs', stopping_threshold: Optional[float] = None, divergence_threshold: Optional[float] = None)

Monitor a metric and signal if execution should stop early.

Parameters:
  • mode – one of min, max. In min mode, signal to stop early will be given when the metric has stopped decreasing. In max mode, the signal is given when the metric has stopped increasing.
  • patience – Number of checks without improvement after which early stop will be signaled.
  • min_delta – Must be >= 0. Minimum absolute or relative change in the metric to qualify as an improvement. In rel mode, improvement_threshold = best_val * ( 1 + min_delta ) in ‘max’ mode or best_val * ( 1 - min_delta ) in min mode. In abs mode, improvement_threshold = best_val + min_delta in max mode or best_val - threshold in min mode.
  • check_finite – When set to True, signals early stop when metric becomes NaN or infinite.
  • threshold_mode – one of abs or rel, threshold delta between checks for determining whether to stop.
  • stopping_threshold – Signals early stop once the metric improves beyond this threshold.
  • divergence_threshold

    Signals early stop once the metric becomes worse than this threshold.

    Raises:
    ValueError:
    If mode is not min or max.
    ValueError:
    If min_delta < 0.
    ValueError:
    If threshold_mode is not abs or rel.
__init__(mode: Literal['min', 'max'], patience: int, min_delta: float = 0.0, check_finite: bool = True, threshold_mode: Literal['abs', 'rel'] = 'abs', stopping_threshold: Optional[float] = None, divergence_threshold: Optional[float] = None) None

Methods

__init__(mode, patience[, min_delta, ...])
check(val) Check the current value of a metric and determine whether to stop or not.
load_state_dict(state_dict) Loads the current state from a state_dict.
reset() Reset back to the default state.
state_dict() Generates a state_dict to save the current state.

Attributes

check_finite
divergence_threshold
min_delta
mode
patience
stopping_threshold
threshold_mode

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources