class_docstr: TFTrainer is a simple but feature-complete training and eval loop for TensorFlow, optimized for 🤗 Transformers.
  
  Args:
      model ([`TFPreTrainedModel`]):
          The model to train, evaluate or use for predictions.
      args ([`TFTrainingArguments`]):
          The arguments to tweak training.
      train_dataset ([`~tf.data.Dataset`], *optional*):
          The dataset to use for training. The dataset should yield tuples of `(features, labels)` where `features`
          is a dict of input features and `labels` is the labels. If `labels` is a tensor, the loss is calculated by
          the model by calling `model(features, labels=labels)`. If `labels` is a dict, such as when using a
          QuestionAnswering head model with multiple targets, the loss is instead calculated by calling
          `model(features, **labels)`.
      eval_dataset ([`~tf.data.Dataset`], *optional*):
          The dataset to use for evaluation. The dataset should yield tuples of `(features, labels)` where `features`
          is a dict of input features and `labels` is the labels. If `labels` is a tensor, the loss is calculated by
          the model by calling `model(features, labels=labels)`. If `labels` is a dict, such as when using a
          QuestionAnswering head model with multiple targets, the loss is instead calculated by calling
          `model(features, **labels)`.
      compute_metrics (`Callable[[EvalPrediction], Dict]`, *optional*):
          The function that will be used to compute metrics at evaluation. Must take a [`EvalPrediction`] and return
          a dictionary string to metric values.
      tb_writer (`tf.summary.SummaryWriter`, *optional*):
          Object to write to TensorBoard.
      optimizers (`Tuple[tf.keras.optimizers.Optimizer, tf.keras.optimizers.schedules.LearningRateSchedule]`, *optional*):
          A tuple containing the optimizer and the scheduler to use. The optimizer default to an instance of
          [`tf.keras.optimizers.Adam`] if `args.weight_decay_rate` is 0 else an instance of [`AdamWeightDecay`]. The
          scheduler will default to an instance of [`tf.keras.optimizers.schedules.PolynomialDecay`] if
          `args.num_warmup_steps` is 0 else an instance of [`WarmUp`].
docstr: Prediction/evaluation loop, shared by [`~TFTrainer.evaluate`] and [`~TFTrainer.predict`].
  
  Works both with or without labels.
docstr_tok: ["Prediction\/evaluation","loop",",","shared","by","[","`","~TFTrainer.evaluate","`","]","and","[","`","~TFTrainer.predict","`","]",".","Works","both","with","or","without","labels","."]
code: def prediction_loop(
      self,
      dataset: tf.data.Dataset,
      steps: int,
      num_examples: int,
      description: str,
      prediction_loss_only: Optional[bool] = None,
  ) -> PredictionOutput:
      """
      Prediction/evaluation loop, shared by [`~TFTrainer.evaluate`] and [`~TFTrainer.predict`].
  
      Works both with or without labels.
      """
  
      prediction_loss_only = (
          prediction_loss_only
          if prediction_loss_only is not None
          else self.args.prediction_loss_only
      )
  
      logger.info(f"***** Running {description} *****")
      logger.info(f"  Num examples in dataset = {num_examples}")
      if description == "Evaluation":
          logger.info(
              f"  Num examples in used in evaluation = {self.args.eval_batch_size * steps}"
          )
      logger.info(f"  Batch size = {self.args.eval_batch_size}")
  
      label_ids: np.ndarray = None
      preds: np.ndarray = None
      self.eval_loss.reset_states()
  
      # Reset the past mems state at the beginning of the evaluation if necessary.
      if self.args.past_index >= 0:
          self._past = None
  
      for step, batch in enumerate(dataset):
          logits = self.distributed_prediction_steps(batch)
          _, labels = batch
  
          if not prediction_loss_only:
              if isinstance(logits, tuple):
                  logits = logits[0]
  
              if isinstance(labels, tuple):
                  labels = labels[0]
  
              if self.args.n_replicas > 1:
                  for val in logits.values:
                      if preds is None:
                          preds = val.numpy()
                      else:
                          preds = np.append(preds, val.numpy(), axis=0)
  
                  for val in labels.values:
                      if label_ids is None:
                          label_ids = val.numpy()
                      else:
                          label_ids = np.append(
                              label_ids, val.numpy(), axis=0
                          )
              else:
                  if preds is None:
                      preds = logits.numpy()
                  else:
                      preds = np.append(preds, logits.numpy(), axis=0)
  
                  if label_ids is None:
                      label_ids = labels.numpy()
                  else:
                      label_ids = np.append(
                          label_ids, labels.numpy(), axis=0
                      )
  
              if step == steps - 1:
                  break
  
      if (
          self.compute_metrics is not None
          and preds is not None
          and label_ids is not None
      ):
          metrics = self.compute_metrics(
              EvalPrediction(predictions=preds, label_ids=label_ids)
          )
      else:
          metrics = {}
  
      metrics["eval_loss"] = self.eval_loss.result().numpy() / steps
  
      for key in list(metrics.keys()):
          if not key.startswith("eval_"):
              metrics[f"eval_{key}"] = metrics.pop(key)
  
      if self.args.past_index and hasattr(self, "_past"):
          # Clean the state at the end of training
          delattr(self, "_past")
  
      return PredictionOutput(
          predictions=preds, label_ids=label_ids, metrics=metrics
      )
  
imports: import datetime
  import math
  import os
  import warnings
  from typing import Callable, Dict, Optional, Tuple
  from .utils import ENV_VARS_TRUE_VALUES
  from .integrations import is_comet_available, is_wandb_available
  import numpy
  import tensorflow
  from tensorflow.python.distribute.values import PerReplica
  from .modeling_tf_utils import TFPreTrainedModel
  from .optimization_tf import GradientAccumulator, create_optimizer
  from .trainer_utils import PREFIX_CHECKPOINT_DIR, EvalPrediction, IntervalStrategy, PredictionOutput, enable_full_determinism, set_seed
  from .training_args_tf import TFTrainingArguments
  from .utils import logging
label_desc: Use image node_id 8 for calling the TFTrainer obj's underlying member method code with example usage: obj.prediction_loop(dataset, steps, num_examples, description, prediction_loss_only) and returns: PredictionOutput