# Path: t5/models/utils.py
# _MODEL_FEATURES = [
#     "inputs", "inputs_position", "inputs_segmentation", "targets",
#     "targets_position", "targets_segmentation", "targets_subsegmentation"
# ]
# def filter_features(ex):
# def write_lines_to_file(lines, filename):
# def get_step_from_checkpoint_path(checkpoint_path):
# def write_targets_and_examples(summary_dir, targets, datasets):
# def get_vocabulary(mixture_or_task_name=None):
# def get_latest_checkpoint_from_dir(model_dir):
# def get_checkpoints_iterator(checkpoint_steps, model_dir):
#   def _get_closest_checkpoint(target_checkpoint):
#     def _generate_checkpoints():
#   def __call__(
#       self,
#       checkpoint_step: int,
#       vocabulary: seqio.Vocabulary,
#       tasks: Sequence[seqio.Task],
#       datasets: Mapping[str, tf.data.Dataset],
#       sequence_length: Union[None, Mapping[str, int]]
#   ) -> MutableSequence[Union[str, float]]: ...
#   def __call__(
#       self,
#       task: seqio.Task,
#       sequence_length: Mapping[str, int],
#       split: str,
#   ) -> tf.data.Dataset: ...
# def run_eval(
#     mixture_or_task_name: str,
#     predict_or_score_fn: PredictOrScoreFnCallable,
#     checkpoint_steps: Iterable[int],
#     dataset_fn: DatasetFnCallable,
#     summary_dir: Optional[str] = None,
#     split: Optional[str] = "validation",
#     sequence_length: Optional[Mapping[str, int]] = None,
#     batch_size: Optional[int] = None):
# class PredictOrScoreFnCallable(typing_extensions.Protocol):
# class DatasetFnCallable(typing_extensions.Protocol):
# 
# Path: t5/models/t5_model.py
# class T5Model(metaclass=abc.ABCMeta):
#   """Abstract Base class for T5 Model API."""
# 
#   @abc.abstractmethod
#   def train(self, mixture_or_task_name, steps):
#     raise NotImplementedError()
# 
#   @abc.abstractmethod
#   def eval(self, mixture_or_task_name):
#     raise NotImplementedError()
# 
#   @abc.abstractmethod
#   def predict(self):
#     raise NotImplementedError()
# 
#   @abc.abstractmethod
#   def finetune(self, mixture_or_task_name, finetune_steps):
#     raise NotImplementedError()


import functools
import itertools
import os
import re
import time
import mesh_tensorflow.transformer.dataset as transformer_dataset
import t5.data
import tensorflow.compat.v1 as tf
import tensorflow_datasets as tfds
import torch
import torch.utils.tensorboard
    import transformers  # pylint: disable=import-outside-toplevel,g-import-not-at-top
from absl import logging
from t5.models import utils
from t5.models.t5_model import T5Model
        else:
          ds = datasets[task.name]

        ds = list(tokens_to_batches(
            ds, sequence_length, batch_size, tuple(task.output_features), task))
        for batch in ds:
          predicted_tokens = self._model.generate(
              input_ids=self.to_tensor(batch["inputs"]), **generate_kwargs
          )
          predicted_tokens = predicted_tokens.cpu().numpy().tolist()
          predictions = [vocab.decode(p) for p in predicted_tokens]

          outputs.extend(predictions)

      return outputs

    if checkpoint_steps is None:
      checkpoint_steps = [self._step]
    elif isinstance(checkpoint_steps, int):
      checkpoint_steps = [checkpoint_steps]
    elif checkpoint_steps == "all":
      checkpoint_steps = self.get_all_checkpoint_steps()
    elif not isinstance(checkpoint_steps, (list, tuple)):
      raise ValueError(
          f"checkpoint_steps must be None, int or list; got {checkpoint_steps}"
      )

    summary_dir = summary_dir or os.path.join(self._model_dir, f"{split}_eval")
    tf.io.gfile.makedirs(summary_dir)


# Path: t5/models/utils.py
# _MODEL_FEATURES = [
#     "inputs", "inputs_position", "inputs_segmentation", "targets",
#     "targets_position", "targets_segmentation", "targets_subsegmentation"
# ]
# def filter_features(ex):
# def write_lines_to_file(lines, filename):
# def get_step_from_checkpoint_path(checkpoint_path):
# def write_targets_and_examples(summary_dir, targets, datasets):
# def get_vocabulary(mixture_or_task_name=None):
# def get_latest_checkpoint_from_dir(model_dir):
# def get_checkpoints_iterator(checkpoint_steps, model_dir):
#   def _get_closest_checkpoint(target_checkpoint):
#     def _generate_checkpoints():
#   def __call__(
#       self,
#       checkpoint_step: int,
#       vocabulary: seqio.Vocabulary,
#       tasks: Sequence[seqio.Task],
#       datasets: Mapping[str, tf.data.Dataset],
#       sequence_length: Union[None, Mapping[str, int]]
#   ) -> MutableSequence[Union[str, float]]: ...
#   def __call__(
#       self,
#       task: seqio.Task,
#       sequence_length: Mapping[str, int],
#       split: str,
#   ) -> tf.data.Dataset: ...
# def run_eval(
#     mixture_or_task_name: str,
#     predict_or_score_fn: PredictOrScoreFnCallable,
#     checkpoint_steps: Iterable[int],
#     dataset_fn: DatasetFnCallable,
#     summary_dir: Optional[str] = None,
#     split: Optional[str] = "validation",
#     sequence_length: Optional[Mapping[str, int]] = None,
#     batch_size: Optional[int] = None):
# class PredictOrScoreFnCallable(typing_extensions.Protocol):
# class DatasetFnCallable(typing_extensions.Protocol):
# 
# Path: t5/models/t5_model.py
# class T5Model(metaclass=abc.ABCMeta):
#   """Abstract Base class for T5 Model API."""
# 
#   @abc.abstractmethod
#   def train(self, mixture_or_task_name, steps):
#     raise NotImplementedError()
# 
#   @abc.abstractmethod
#   def eval(self, mixture_or_task_name):
#     raise NotImplementedError()
# 
#   @abc.abstractmethod
#   def predict(self):
#     raise NotImplementedError()
# 
#   @abc.abstractmethod
#   def finetune(self, mixture_or_task_name, finetune_steps):
#     raise NotImplementedError()


# Path: t5/models/hf_model.py
import functools
import itertools
import os
import re
import time
import mesh_tensorflow.transformer.dataset as transformer_dataset
import t5.data
import tensorflow.compat.v1 as tf
import tensorflow_datasets as tfds
import torch
import torch.utils.tensorboard
    import transformers  # pylint: disable=import-outside-toplevel,g-import-not-at-top
from absl import logging
from t5.models import utils
from t5.models.t5_model import T5Model

        else:
          ds = datasets[task.name]

        ds = list(tokens_to_batches(
            ds, sequence_length, batch_size, tuple(task.output_features), task))
        for batch in ds:
          predicted_tokens = self._model.generate(
              input_ids=self.to_tensor(batch["inputs"]), **generate_kwargs
          )
          predicted_tokens = predicted_tokens.cpu().numpy().tolist()
          predictions = [vocab.decode(p) for p in predicted_tokens]

          outputs.extend(predictions)

      return outputs

    if checkpoint_steps is None:
      checkpoint_steps = [self._step]
    elif isinstance(checkpoint_steps, int):
      checkpoint_steps = [checkpoint_steps]
    elif checkpoint_steps == "all":
      checkpoint_steps = self.get_all_checkpoint_steps()
    elif not isinstance(checkpoint_steps, (list, tuple)):
      raise ValueError(
          f"checkpoint_steps must be None, int or list; got {checkpoint_steps}"
      )

    summary_dir = summary_dir or os.path.join(self._model_dir, f"{split}_eval")
    tf.io.gfile.makedirs(summary_dir)


    utils.run_eval(