code: def get_valid_stats(trainer):
      stats = OrderedDict()
      stats["valid_loss"] = trainer.get_meter("valid_loss").avg
      if trainer.get_meter("valid_nll_loss").count > 0:
          nll_loss = trainer.get_meter("valid_nll_loss").avg
          stats["valid_nll_loss"] = nll_loss
      else:
          nll_loss = trainer.get_meter("valid_loss").avg
      stats["valid_ppl"] = get_perplexity(nll_loss)
      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 4 for calling a global function with example usage: get_valid_stats(trainer) and returns: stats