class_docstr: T5 Agent.
  
  Relies on the T5 model implemented in huggingface
class_docstr_tok: ["T5","Agent",".","Relies","on","the","T5","model","implemented","in","huggingface"]
docstr: Generate an output with beam search.
  
  Use HF's built-in generation to perform beam search.
docstr_tok: ["Generate","an","output","with","beam","search",".","Use","HF","'s","built-in","generation","to","perform","beam","search","."]
code: def _generate(
      self,
      batch: Batch,
      beam_size: int,
      max_ts: int,
      prefix_tokens: Optional[torch.LongTensor] = None,
      overrides: Optional[Dict[str, Any]] = None,
  ):
      """
      Generate an output with beam search.
  
      Use HF's built-in generation to perform beam search.
      """
      bad_words_ids = None
      if self.beam_block_list is not None:
          bad_words_ids = [
              gram
              for _, ngram in self.beam_block_list.items()
              for gram in ngram
          ]
  
      method = self.opt.get("inference", "greedy")
  
      generation_params = {
          "input_ids": batch.text_vec,
          "max_length": max_ts,
          "min_length": self.beam_min_length,
          "do_sample": self.opt["inference"] in ["topk", "topp"],
          "early_stopping": "never",
          "num_beams": beam_size,
          "temperature": self.temperature,
          "top_k": self.opt["topk"]
          if method in ["topk", "delayedbeam"]
          else None,
          "top_p": self.opt["topp"] if method == "nucleus" else None,
          "repetition_penalty": None,
          "bad_words_ids": bad_words_ids if bad_words_ids else None,
          "bos_token_id": self.START_IDX,
          "pad_token_id": self.NULL_IDX,
          "eos_token_id": self.END_IDX,
          "length_penalty": self.opt["beam_length_penalty"],
          "no_repeat_ngram_size": self.beam_block_ngram,
          "num_return_sequences": 1,
          "attention_mask": batch.text_vec != self.NULL_IDX,
          "decoder_start_token_id": self.NULL_IDX,
      }
  
      if self.opt["t5_generation_config"]:
          config = TASK_CONFIGS[self.opt["t5_generation_config"]]
          config.pop("prefix", None)
          generation_params.update(config)
      if overrides:
          generation_params.update(overrides)
  
      model = self.model
      if hasattr(self.model, "module") and not is_fsdp(self.model):
          model = self.model.module
      outputs = model.t5.generate(**generation_params)
      outputs = [(outputs[i], 0, None) for i in range(outputs.size(0))]
      return outputs, []
  
imports: import torch
  from typing import Optional, Dict, Any, Tuple
  from transformers import T5ForConditionalGeneration
  from parlai.agents.hugging_face.hugging_face import HF_VERSION
  from parlai.agents.hugging_face.dict import T5DictionaryAgent
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.core.torch_agent import Batch, TorchAgent
  from parlai.core.torch_generator_agent import TorchGeneratorAgent, TorchGeneratorModel
  from parlai.utils.fsdp import is_fsdp, delay_halving
label_desc: Use image node_id 6 for calling the T5Agent obj's underlying member method code with example usage: obj._generate(batch, beam_size, max_ts, prefix_tokens, overrides) and returns: outputs,  list