code: def add_early_stopping_by_val_score(
      patience: int,
      evaluator: Engine,
      trainer: Engine,
      metric_name: str,
      score_sign: float = 1.0,
  ) -> EarlyStopping:
      """Method setups early stopping handler based on the score (named by `metric_name`) provided by `evaluator`.
      Metric value should increase in order to keep training and not early stop.
  
      Args:
          patience: number of events to wait if no improvement and then stop the training.
          evaluator: evaluation engine used to provide the score
          trainer: trainer engine to stop the run if no improvement.
          metric_name: metric name to use for score evaluation. This metric should be present in
              `evaluator.state.metrics`.
          score_sign: sign of the score: 1.0 or -1.0. For error-like metrics, e.g. smaller is better,
              a negative score sign should be used (objects with larger score are retained). Default, 1.0.
  
      Returns:
          A :class:`~ignite.handlers.early_stopping.EarlyStopping` handler.
      """
      es_handler = EarlyStopping(
          patience=patience,
          score_function=get_default_score_fn(
              metric_name, score_sign=score_sign
          ),
          trainer=trainer,
      )
      evaluator.add_event_handler(Events.COMPLETED, es_handler)
  
      return es_handler
  
imports: import numbers
  import warnings
  from functools import partial
  from typing import Any, Callable, cast, Dict, Iterable, Mapping, Optional, Sequence, Union
  import torch
  import torch.nn
  from torch.optim.optimizer import Optimizer
  from torch.utils.data.distributed import DistributedSampler
  import ignite.distributed
  from ignite.contrib.handlers import ClearMLLogger, global_step_from_engine, MLflowLogger, NeptuneLogger, PolyaxonLogger, ProgressBar, TensorboardLogger, VisdomLogger, WandBLogger
  from ignite.contrib.handlers.base_logger import BaseLogger
  from ignite.contrib.metrics import GpuInfo
  from ignite.engine import Engine, Events
  from ignite.handlers import Checkpoint, DiskSaver, EarlyStopping, TerminateOnNan
  from ignite.handlers.checkpoint import BaseSaveHandler
  from ignite.handlers.param_scheduler import ParamScheduler
  from ignite.metrics import RunningAverage
  from ignite.metrics.metric import RunningBatchWise
  from ignite.utils import deprecated
label_desc: Use image node_id 17 for calling a global function with example usage: add_early_stopping_by_val_score(patience, evaluator, trainer, metric_name, score_sign) and returns: es_handler