code: def log_mid_epoch_stats(trainer, progress, extra_meters, log_output):
      stats = get_training_stats(trainer)
      for k, v in log_output.items():
          if k in [
              "loss",
              "nll_loss",
              "ntokens",
              "nsentences",
              "sample_size",
          ]:
              continue  # these are already logged above
          if "loss" in k:
              extra_meters[k].update(v, log_output["sample_size"])
          else:
              extra_meters[k].update(v)
          stats[k] = extra_meters[k].avg
      progress.log(stats)
      return stats
  
file_path: translate/pytorch_translate/evals.py
imports: import math
  import time
  from collections import defaultdict, OrderedDict
  from typing import Any, Dict, List, Optional, Tuple
  from fairseq import distributed_utils, progress_bar, utils
  from fairseq.meters import AverageMeter
  from pytorch_translate import checkpoint, generate, utils
  from pytorch_translate.dual_learning.dual_learning_task import DualLearningTask
  from pytorch_translate.tasks.pytorch_translate_multi_task import PyTorchTranslateMultiTask
label_desc: Use image node_id 1 for calling a global function with example usage: log_mid_epoch_stats(trainer, progress, extra_meters, log_output) and returns: stats