code: def get_checkpoints_iterator(checkpoint_steps, model_dir):
      """Get checkpoints from model directory.
  
      **Note**: This only works for models checkpoints saved using Tensorflow.
  
      Args:
        checkpoint_steps: list, int or str. If checkpoint_step is an int, find the
          checkpoint with the closest global step and return a singleton list. If
          checkpoint_step is a list of ints, replace each int with the path to the
          checkpoint with the closest global step. If checkpoint_step == "all",
          return the path of every checkpoint in model_dir, starting from the
          earliest checkpoint. if the checkpoint_steps is None, returns step from
          the tf.train.checkpoint_iterator for continuous eval. If -1, get the
          latest checkpoint from the model directory.
        model_dir: str, model directory. If model_dir is None, then checkpoint_steps
          must be an integer or list of integers.
      Returns:
        a iterator with the checkpoint steps (integers).
      """
  
      def _get_closest_checkpoint(target_checkpoint):
          """Returns checkpoint with closest global step to `target_checkpoint`."""
          checkpoints = set()
          for f in tf.io.gfile.listdir(model_dir):
              try:
                  checkpoints.add(int(get_step_from_checkpoint_path(f)))
              except ValueError:
                  continue
          if not checkpoints:
              raise ValueError(
                  "No checkpoint files found in {}".format(model_dir)
              )
          closest = float("inf")
          for c in checkpoints:
              if abs(target_checkpoint - c) < abs(
                  target_checkpoint - closest
              ):
                  closest = c
          if closest != target_checkpoint:
              logging.info(
                  "Using checkpoint at step %d which is closest to requested step %d",
                  closest,
                  target_checkpoint,
              )
          return closest
  
      if checkpoint_steps is None:
          if model_dir is None:
              raise ValueError(
                  "checkpoint_steps and model_dir both cannot be None."
              )
  
          def _generate_checkpoints():
              for c in tf.train.checkpoints_iterator(model_dir):
                  yield get_step_from_checkpoint_path(c)
  
          return _generate_checkpoints()
  
      elif checkpoint_steps == "all":
          if model_dir is None:
              raise ValueError(
                  "model_dir cannot be None when checkpoint_steps={}".format(
                      checkpoint_steps
                  )
              )
          ckpt_paths = tf.gfile.Glob(
              os.path.join(model_dir, "model.ckpt*")
          )
          return [get_step_from_checkpoint_path(c) for c in ckpt_paths]
      elif isinstance(checkpoint_steps, int):
          if model_dir:
              if checkpoint_steps == -1:
                  return [get_latest_checkpoint_from_dir(model_dir)]
              else:
                  return [_get_closest_checkpoint(checkpoint_steps)]
          else:
              return [checkpoint_steps]
      else:
          if model_dir:
              closests = np.unique(
                  [_get_closest_checkpoint(c) for c in checkpoint_steps]
              )
              return closests
          else:
              return checkpoint_steps
  
imports: import functools
  import os
  import re
  from typing import Any, Callable, Iterable, Mapping, MutableSequence, Optional, Sequence, Tuple, Union
  from absl import logging
  import gin
  import numpy
  import seqio
  import t5.data
  import tensorflow.compat.v1
  import tensorflow_datasets
  import typing_extensions
label_desc: Use image node_id 7 for calling a global function with example usage: get_checkpoints_iterator(checkpoint_steps, model_dir) and returns: closest, _generate_checkpoints, unknown, list, closests, checkpoint_steps, list, list