code: def set_early_stop(trainer, args, is_lm=False):
      """Sets the early stop trigger given the program arguments
  
      :param trainer: The trainer used for training
      :param args: The program arguments
      :param is_lm: If the trainer is for a LM (epoch instead of epochs)
      """
      patience = args.patience
      criterion = args.early_stop_criterion
      epochs = args.epoch if is_lm else args.epochs
      mode = "max" if "acc" in criterion else "min"
      if patience > 0:
          trainer.stop_trigger = (
              chainer.training.triggers.EarlyStoppingTrigger(
                  monitor=criterion,
                  mode=mode,
                  patients=patience,
                  max_trigger=(epochs, "epoch"),
              )
          )
  
label_desc: Use image node_id 2 for calling a global function with example usage: set_early_stop(trainer, args, is_lm) without return types