code: def eval_and_log_summary(
      *,
      train_state: utils.OptaxTrainState,
      writer: metric_writers.MetricWriter,
      iterator,
      eval_step_fn,
      eval_steps,
      train_iteration,
      num_eval_examples,
      compute_recall_metrics=True,
      text_to_video_retrieval=True,
  ):
      """Eval the model and write the summary."""
      output_dicts = {}
      logging.info("Total number of eval steps is %s", eval_steps)
      logging.info(
          "Total number of eval examples is %s", num_eval_examples
      )
      # Do this to ensure we definitely cover the full test set
      eval_steps = int(np.ceil(1.3 * eval_steps))
      logging.info(
          "The modified total number of eval steps is %s", eval_steps
      )
      for step in range(eval_steps):
          logging.info("Step %s/%s", step + 1, eval_steps)
          with jax.profiler.StepTraceAnnotation("eval", step_num=step):
              eval_batch = next(iterator)
              assert compute_recall_metrics
              assert "key" in eval_batch, "Keys must be added to batch"
              keys = utils.convert_strings_to_uint8_arrays(
                  eval_batch["key"], 30
              )
              keys = utils.all_gather_and_unreplicate(keys)
              del eval_batch["key"]
              batch_masks = utils.all_gather_and_unreplicate(
                  eval_batch["batch_mask"]
              )
  
              video_embeddings, text_embeddings = eval_step_fn(
                  train_state, eval_batch
              )
              # Unreplicate the output of eval_step_pmapped (used `lax.all_gather`).
              video_embeddings = jax_utils.unreplicate(video_embeddings)
              text_embeddings = jax_utils.unreplicate(text_embeddings)
              batch_size = batch_masks.shape[0] * batch_masks.shape[1]
              text_embeddings = text_embeddings.reshape(
                  batch_size, -1, text_embeddings.shape[-1]
              )
              batch_masks = batch_masks.reshape((batch_size,)).astype(
                  bool
              )
              keys = keys.reshape((batch_size, -1))
              for i, mask in enumerate(batch_masks):
                  if mask:
                      key = utils.convert_uint8_array_to_string(keys[i])
                      output_dicts[key] = {
                          "text_emb": text_embeddings[i],
                          "video_emb": video_embeddings[i],
                      }
      logging.info(
          "The number of the unique eval examples is %d",
          len(output_dicts),
      )
      text_embeddings_array = np.stack(
          [v["text_emb"] for v in output_dicts.values()], axis=0
      )
      video_embeddings_array = np.stack(
          [v["video_emb"] for v in output_dicts.values()], axis=0
      )
  
      logging.info(
          "Shape of text embedding array in val set is %s",
          text_embeddings_array.shape,
      )
      additional_summary = utils.compute_recall_at_k(
          video_embeddings=video_embeddings_array,
          text_embeddings=text_embeddings_array,
          k_values={1, 5, 10},
          text_to_video_retrieval=text_to_video_retrieval,
      )
      return train_utils.log_eval_summary(
          step=train_iteration,
          eval_metrics=[],
          extra_eval_summary=additional_summary,
          writer=writer,
          key_separator="/",
      )
  
imports: import functools
  from typing import Any, Dict, Optional, Tuple
  from absl import logging
  from clu import metric_writers
  from clu import periodic_actions
  from clu import platform
  from flax import jax_utils
  import flax.linen
  import jax
  import jax.example_libraries.optimizers
  import jax.profiler
  import ml_collections
  import numpy
  import optax
  from scenic.projects.verbs_in_action import utils
  from scenic.train_lib import train_utils
label_desc: Use image node_id 5 for calling a global function with example usage: eval_and_log_summary() and returns: train_utils