code: def run_eval(
      global_metrics_evaluator: DeformableDetrGlobalEvaluator,
      dataset: Dataset,
      train_state: train_utils.TrainState,
      eval_step_pmapped: Callable[
          [train_utils.TrainState, ArrayDict], Any
      ],
      pool: futures.ThreadPoolExecutor,
      step: int,
      steps_per_eval: int,
  ) -> Tuple[
      Tuple[int, Any], futures.Future
  ]:  # pylint: disable=g-bare-generic
      """Run full eval on dataset."""
      future = None
  
      eval_metrics = []
      if global_metrics_evaluator is not None:
          global_metrics_evaluator.clear()
  
      for eval_step in range(steps_per_eval):
          logging.info("Running eval step %d", eval_step)
          eval_batch = next(dataset.valid_iter)
  
          # Do the eval step given the matches.
          (
              eval_batch_all_hosts,
              eval_predictions_all_hosts,
              e_metrics,
          ) = eval_step_pmapped(train_state, eval_batch)
  
          # Variable aux_outputs is not needed anymore.
          eval_predictions_all_hosts.pop("aux_outputs", None)
  
          # Collect local metrics (returned by the loss function).
          eval_metrics.append(
              train_utils.unreplicate_and_get(e_metrics)
          )
  
          if global_metrics_evaluator is not None:
              # Unreplicate the output of eval_step_pmapped (used `lax.all_gather`).
              eval_batch_all_hosts = jax_utils.unreplicate(
                  eval_batch_all_hosts
              )
              eval_predictions_all_hosts = jax_utils.unreplicate(
                  eval_predictions_all_hosts
              )
  
              # Collect preds and labels to be sent for computing global metrics.
              predictions = detr_train_utils.process_and_fetch_to_host(
                  eval_predictions_all_hosts,
                  eval_batch_all_hosts["batch_mask"],
              )
              predictions = jax.tree_util.tree_map(
                  np.asarray, predictions
              )
  
              labels = detr_train_utils.process_and_fetch_to_host(
                  eval_batch_all_hosts["label"],
                  eval_batch_all_hosts["batch_mask"],
              )
              labels = jax.tree_util.tree_map(np.asarray, labels)
  
              if eval_step == 0:
                  logging.info(
                      "Pred keys: %s", list(predictions[0].keys())
                  )
                  logging.info(
                      "Labels keys: %s", list(labels[0].keys())
                  )
  
              # Add to evaluator.
              _wait(future)
              future = pool.submit(
                  _add_examples,
                  global_metrics_evaluator,
                  predictions,
                  labels,
              )
  
              del predictions, labels
  
          del (
              eval_batch,
              eval_batch_all_hosts,
              eval_predictions_all_hosts,
          )
  
      eval_global_metrics_summary_future = None
      if global_metrics_evaluator is not None:
          _wait(future)
          logging.info(
              "Number of eval examples: %d",
              len(global_metrics_evaluator),
          )
          eval_global_metrics_summary_future = pool.submit(
              global_metrics_evaluator.compute_metrics,
              clear_annotations=False,
          )
  
      return (step, eval_metrics), eval_global_metrics_summary_future
  
file_path: scenic/scenic/projects/baselines/deformable_detr/evaluate.py
imports: from concurrent import futures
  from typing import Any, Callable, Dict, Optional, Sequence, Tuple
  from absl import logging
  from flax import jax_utils
  import flax.linen
  import jax
  import jax.numpy
  import numpy
  from scenic.dataset_lib.dataset_utils import Dataset
  from scenic.projects.baselines.deformable_detr.coco_eval import DeformableDetrGlobalEvaluator
  from scenic.projects.baselines.deformable_detr.coco_eval import prepare_coco_eval_dicts
  from scenic.projects.baselines.detr import train_utils
  from scenic.train_lib import train_utils
label_desc: Use image node_id 4 for calling a global function with example usage: run_eval(global_metrics_evaluator, dataset, train_state, eval_step_pmapped, pool, step, steps_per_eval) and returns: step,  eval_metrics,  eval_global_metrics_summary_future