docstr: Perform an evaluation step on :obj:`model` using obj:`inputs`.
  
  Subclass and override to inject custom behavior.
  
  Args:
      model (:obj:`nn.Module`):
          The model to evaluate.
      inputs (:obj:`Dict[str, Union[torch.Tensor, Any]]`):
          The inputs and targets of the model.
  
          The dictionary will be unpacked before being fed to the model. Most models expect the targets under the
          argument :obj:`labels`. Check your model's documentation for all accepted arguments.
      prediction_loss_only (:obj:`bool`):
          Whether or not to return the loss only.
  
  Return:
      Tuple[Optional[float], Optional[torch.Tensor], Optional[torch.Tensor]]: A tuple with the loss, logits and
      labels (each being optional).
docstr_tok: ["Perform","an","evaluation","step","on",":","obj",":","`","model","`","using","obj",":","`","inputs","`",".","Subclass","and","override","to","inject","custom","behavior",".","Args",":","model","(",":","obj",":","`","nn.Module","`",")",":","The","model","to","evaluate",".","inputs","(",":","obj",":","`","Dict","[","str",",","Union","[","torch.Tensor",",","Any","]","]","`",")",":","The","inputs","and","targets","of","the","model",".","The","dictionary","will","be","unpacked","before","being","fed","to","the","model",".","Most","models","expect","the","targets","under","the","argument",":","obj",":","`","labels","`",".","Check","your","model","'s","documentation","for","all","accepted","arguments",".","prediction_loss_only","(",":","obj",":","`","bool","`",")",":","Whether","or","not","to","return","the","loss","only",".","Return",":","Tuple","[","Optional","[","float","]",",","Optional","[","torch.Tensor","]",",","Optional","[","torch.Tensor","]","]",":","A","tuple","with","the","loss",",","logits","and","labels","(","each","being","optional",")","."]
code: def prediction_step(
      self,
      model: nn.Module,
      inputs: Dict[str, Union[torch.Tensor, Any]],
      prediction_loss_only: bool,
      ignore_keys: Optional[List[str]] = None,
  ) -> Tuple[
      Optional[float], Optional[torch.Tensor], Optional[torch.Tensor]
  ]:
      """
      Perform an evaluation step on :obj:`model` using obj:`inputs`.
  
      Subclass and override to inject custom behavior.
  
      Args:
          model (:obj:`nn.Module`):
              The model to evaluate.
          inputs (:obj:`Dict[str, Union[torch.Tensor, Any]]`):
              The inputs and targets of the model.
  
              The dictionary will be unpacked before being fed to the model. Most models expect the targets under the
              argument :obj:`labels`. Check your model's documentation for all accepted arguments.
          prediction_loss_only (:obj:`bool`):
              Whether or not to return the loss only.
  
      Return:
          Tuple[Optional[float], Optional[torch.Tensor], Optional[torch.Tensor]]: A tuple with the loss, logits and
          labels (each being optional).
      """
  
      def prefix_allowed_tokens_fn(batch_id, sent):
          # print(self.tokenizer.convert_ids_to_tokens(inputs['labels'][batch_id]))
          src_sentence = inputs["input_ids"][batch_id]
          return self.constraint_decoder.constraint_decoding(
              src_sentence=src_sentence, tgt_generated=sent
          )
  
      if not self.args.predict_with_generate or prediction_loss_only:
          return super().prediction_step(
              model=model,
              inputs=inputs,
              prediction_loss_only=prediction_loss_only,
              ignore_keys=ignore_keys,
          )
      has_labels = "labels" in inputs
      inputs = self._prepare_inputs(inputs)
  
      gen_kwargs = {
          "max_length": self.model.config.max_length,
          "num_beams": self.model.config.num_beams,
          "generation_config": self.model.t5.generation_config,  # modify by xxx
          "prefix_allowed_tokens_fn": prefix_allowed_tokens_fn
          if self.constraint_decoder
          else None,
      }
  
      generated_tokens = self.model.generate(
          inputs["input_ids"],
          attention_mask=inputs["attention_mask"],
          labels=None,
          **gen_kwargs,
      )
  
      # in case the batch is shorter than max length, the output should be padded
      if generated_tokens.shape[-1] < gen_kwargs["max_length"]:
          generated_tokens = self._pad_tensors_to_max_len(
              generated_tokens, gen_kwargs["max_length"]
          )
  
      with torch.no_grad():
          outputs = model(**inputs)
          if has_labels:
              if self.label_smoother is not None:
                  loss = (
                      self.label_smoother(outputs, inputs["labels"])
                      .mean()
                      .detach()
                  )
              else:
                  loss = (
                      (
                          outputs["loss"]
                          if isinstance(outputs, dict)
                          else outputs[0]
                      )
                      .mean()
                      .detach()
                  )
          else:
              loss = None
  
      if self.args.prediction_loss_only:
          return loss, None, None
  
      labels = inputs["labels"]
      if labels.shape[-1] < gen_kwargs["max_length"]:
          labels = self._pad_tensors_to_max_len(
              labels, gen_kwargs["max_length"]
          )
  
      return loss, generated_tokens, labels
  
imports: import torch
  import torch.nn
  from dataclasses import dataclass, field
  from typing import Union, List, Dict, Tuple, Any, Optional
  from torch.cuda.amp import autocast
  from transformers import Seq2SeqTrainer, Seq2SeqTrainingArguments
  from transformers.trainer_pt_utils import LabelSmoother
  from transformers.trainer import *
  from ..seq2seq.constraint_decoder import get_constraint_decoder
label_desc: Use image node_id 5 for calling the ConstraintSeq2SeqTrainer obj's underlying member method code with example usage: obj.prediction_step(model, inputs, prediction_loss_only, ignore_keys) and returns: loss,  generated_tokens,  labels, self, super, loss,  None,  None