class_docstr: Early stopping and model checkpoint plugin.
  
  The plugin checks a metric and stops the training loop when the accuracy
  on the metric stopped progressing for `patience` epochs.
  After training, the best model's checkpoint is loaded.
  
  .. warning::
      The plugin checks the metric value, which is updated by the strategy
      during the evaluation. This means that you must ensure that the
      evaluation is called frequently enough during the training loop.
  
      For example, if you set `patience=1`, you must also set `eval_every=1`
      in the `BaseTemplate`, otherwise the metric won't be updated after
      every epoch/iteration. Similarly, `peval_mode` must have the same
      value.
class_docstr_tok: ["Early","stopping","and","model","checkpoint","plugin",".","The","plugin","checks","a","metric","and","stops","the","training","loop","when","the","accuracy","on","the","metric","stopped","progressing","for","`","patience","`","epochs",".","After","training",",","the","best","model","'s","checkpoint","is","loaded",".","..","warning",":",":","The","plugin","checks","the","metric","value",",","which","is","updated","by","the","strategy","during","the","evaluation",".","This","means","that","you","must","ensure","that","the","evaluation","is","called","frequently","enough","during","the","training","loop",".","For","example",",","if","you","set","`","patience=1","`",",","you","must","also","set","`","eval_every=1","`","in","the","`","BaseTemplate","`",",","otherwise","the","metric","wo","n't","be","updated","after","every","epoch\/iteration",".","Similarly",",","`","peval_mode","`","must","have","the","same","value","."]
code: def before_training_iteration(self, strategy, **kwargs):
      if self.peval_mode == "iteration":
          ub = self._update_best(strategy)
          if ub is None or self.best_step is None:
              return
          curr_step = self._get_strategy_counter(strategy)
          if curr_step - self.best_step >= self.patience:
              strategy.model.load_state_dict(self.best_state)
              strategy.stop_training()
  
file_path: avalanche/avalanche/training/plugins/early_stopping.py
imports: import operator
  from typing import Optional
  import warnings
  from copy import deepcopy
  from avalanche.training.plugins import SupervisedPlugin
label_desc: Use image node_id 3 for calling the EarlyStoppingPlugin obj's underlying member method code with example usage: obj.before_training_iteration(strategy) without return types