code: def get_should_early_stop_func(
      eval_every_steps: int, no_improvements_for_n_evals: int
  ):
      assert eval_every_steps != 0
      if no_improvements_for_n_evals == 0:
          return always_false
      else:
          return lambda metarunner: (
              metarunner.train_state.global_steps is not None
              and metarunner.best_val_state is not None
              and (
                  metarunner.best_val_state.train_state.global_steps
                  - metarunner.train_state.global_steps
              )
              / eval_every_steps
              > no_improvements_for_n_evals
          )
  
imports: from dataclasses import dataclass
  from typing import Dict
  import torch.nn
  import jiant.proj.main.runner
  import jiant.proj.main.components.task_sampler
  from jiant.shared.runner import save_model_with_metadata, compare_steps_max_steps
  from jiant.utils.python.datastructures import ExtendedDataClassMixin
  from jiant.utils.python.functional import always_false
  from jiant.utils.torch_utils import copy_state_dict, CPU_DEVICE, get_model_for_saving
  from jiant.utils.zlog import BaseZLogger, PRINT_LOGGER
  from jiant.shared.metarunner import AbstractMetarunner
label_desc: Use image node_id 1 for calling a global function with example usage: get_should_early_stop_func(eval_every_steps, no_improvements_for_n_evals) and returns: always_false, function