code: def get_valid_stats(
      cfg: DictConfig,
      trainer: Trainer,
      stats: Dict[str, Any],
      tracking_best: bool,
  ) -> Dict[str, Any]:
      stats["num_updates"] = trainer.get_num_updates()
      if tracking_best and hasattr(
          checkpoint_utils.save_checkpoint, "best"
      ):
          key = "best_{0}".format(cfg.checkpoint.best_checkpoint_metric)
          best_function = (
              max
              if cfg.checkpoint.maximize_best_checkpoint_metric
              else min
          )
          stats[key] = best_function(
              checkpoint_utils.save_checkpoint.best,
              stats[cfg.checkpoint.best_checkpoint_metric],
          )
      return stats
  
imports: import argparse
  import logging
  import math
  import os
  import sys
  from typing import Any, Callable, Dict, List, Optional, Tuple
  import numpy
  import torch
  from omegaconf import DictConfig, OmegaConf
  from fairseq import checkpoint_utils, options, quantization_utils, tasks, utils
  from fairseq.data import data_utils, iterators
  from fairseq.data.plasma_utils import PlasmaStore
  from fairseq.dataclass.configs import FairseqConfig
  from fairseq.dataclass.initialize import add_defaults
  from fairseq.dataclass.utils import convert_namespace_to_omegaconf
  from fairseq.distributed import fsdp_enable_wrap, fsdp_wrap
  from fairseq.distributed import utils
  from fairseq.file_io import PathManager
  from fairseq.logging import meters, metrics, progress_bar
  from fairseq.model_parallel.megatron_trainer import MegatronTrainer
  from fairseq.trainer import Trainer
label_desc: Use image node_id 8 for calling a global function with example usage: get_valid_stats(cfg, trainer, stats, tracking_best) and returns: stats