class_docstr: Class that controls the training process.
  
  Args:
      model(:py:class:`onmt.models.model.NMTModel`): model to train
      train_loss(:obj:`onmt.utils.loss.LossComputeBase`):
        training loss computation
      valid_loss(:obj:`onmt.utils.loss.LossComputeBase`):
        training loss computation
      scoring_preparator(:obj:`onmt.translate.utils.ScoringPreparator`):
        preparator for the calculation of metrics via the
        _eval_handler method
      valid_scorers (dict): keeps in memory the current values
        of the validation metrics
      optim(:obj:`onmt.utils.optimizers.Optimizer`):
        the optimizer responsible for update
      trunc_size(int): length of truncated back propagation
        through time
      accum_count(list): accumulate gradients this many times.
      accum_steps(list): steps for accum gradients changes.
      n_gpu (int): number of gpu.
      gpu_rank (int): ordinal rank of the gpu in the list.
      report_manager(:obj:`onmt.utils.ReportMgrBase`):
        the object that creates reports, or None
      with_align (bool): whether to jointly lear alignment
        (Transformer)
      model_saver(:obj:`onmt.models.ModelSaverBase`): the saver is
        used to save a checkpoint.
        Thus nothing will be saved if this parameter is None.
      average_decay (float): cf opt.average_decay
      average_every (int): average model every x steps.
      model_dtype (str): fp32 or fp16.
      earlystopper (:obj:`onmt.utils.EarlyStopping`): add early
        stopping mecanism
      dropout (float): dropout value in RNN or FF layers.
      attention_dropout (float): dropaout in attention layers.
      dropout_steps (list): dropout values scheduling in steps.
      zero_out_prompt_loss (bool): whether to zero-out the prompt loss
          (mostly for LLM finetuning).
class_docstr_tok: ["Class","that","controls","the","training","process",".","Args",":","model","(",":","py",":","class",":","`","onmt.models.model.NMTModel","`",")",":","model","to","train","train_loss","(",":","obj",":","`","onmt.utils.loss.LossComputeBase","`",")",":","training","loss","computation","valid_loss","(",":","obj",":","`","onmt.utils.loss.LossComputeBase","`",")",":","training","loss","computation","scoring_preparator","(",":","obj",":","`","onmt.translate.utils.ScoringPreparator","`",")",":","preparator","for","the","calculation","of","metrics","via","the","_eval_handler","method","valid_scorers","(","dict",")",":","keeps","in","memory","the","current","values","of","the","validation","metrics","optim","(",":","obj",":","`","onmt.utils.optimizers.Optimizer","`",")",":","the","optimizer","responsible","for","update","trunc_size","(","int",")",":","length","of","truncated","back","propagation","through","time","accum_count","(","list",")",":","accumulate","gradients","this","many","times",".","accum_steps","(","list",")",":","steps","for","accum","gradients","changes",".","n_gpu","(","int",")",":","number","of","gpu",".","gpu_rank","(","int",")",":","ordinal","rank","of","the","gpu","in","the","list",".","report_manager","(",":","obj",":","`","onmt.utils.ReportMgrBase","`",")",":","the","object","that","creates","reports",",","or","None","with_align","(","bool",")",":","whether","to","jointly","lear","alignment","(","Transformer",")","model_saver","(",":","obj",":","`","onmt.models.ModelSaverBase","`",")",":","the","saver","is","used","to","save","a","checkpoint",".","Thus","nothing","will","be","saved","if","this","parameter","is","None",".","average_decay","(","float",")",":","cf","opt.average_decay","average_every","(","int",")",":","average","model","every","x","steps",".","model_dtype","(","str",")",":","fp32","or","fp16",".","earlystopper","(",":","obj",":","`","onmt.utils.EarlyStopping","`",")",":","add","early","stopping","mecanism","dropout","(","float",")",":","dropout","value","in","RNN","or","FF","layers",".","attention_dropout","(","float",")",":","dropaout","in","attention","layers",".","dropout_steps","(","list",")",":","dropout","values","scheduling","in","steps",".","zero_out_prompt_loss","(","bool",")",":","whether","to","zero-out","the","prompt","loss","(","mostly","for","LLM","finetuning",")","."]
docstr: Trigger metrics calculations
  
  Args:
      scorer (:obj:``onmt.scorer.Scorer``): scorer.
      preds, texts_ref: outputs of the scorer's `translate` method.
  
  Returns:
      The metric calculated by the scorer.
docstr_tok: ["Trigger","metrics","calculations","Args",":","scorer","(",":","obj",":","``","onmt.scorer.Scorer","``",")",":","scorer",".","preds",",","texts_ref",":","outputs","of","the","scorer","'s","`","translate","`","method",".","Returns",":","The","metric","calculated","by","the","scorer","."]
code: def _eval_handler(self, scorer, preds, texts_ref):
      """Trigger metrics calculations
  
      Args:
          scorer (:obj:``onmt.scorer.Scorer``): scorer.
          preds, texts_ref: outputs of the scorer's `translate` method.
  
      Returns:
          The metric calculated by the scorer."""
  
      return scorer.compute_score(preds, texts_ref)
  
imports: import time
  import sys
  import torch
  import traceback
  import onmt.utils
  from onmt.utils.loss import LossCompute
  from onmt.utils.logging import logger
  from onmt.utils.scoring_utils import ScoringPreparator
  from onmt.scorers import get_scorers_cls, build_scorers
label_desc: Use image node_id 2 for calling the Trainer obj's underlying member method code with example usage: obj._eval_handler(scorer, preds, texts_ref) and returns: scorer