class_docstr: Override TGA to use a different tree search decoder.
code: def _treesearch_factory(
      self, device: int, verbose=False
  ) -> TreeSearch:
      method = self.opt.get("inference", "greedy")
      beam_size = self.opt.get("beam_size", 1)
      pacer_kwargs = {
          "classifier": self.classifier,
          "pacer_n_tokens": self.opt["pacer_n_tokens"],
          "pacer_frequency_ratio": self.opt["pacer_frequency_ratio"],
          "agent": self,
      }
      if method == "greedy":
          return PacerGreedySearch(
              beam_size,
              min_length=0,
              block_ngram=self.beam_block_ngram,
              context_block_ngram=self.beam_context_block_ngram,
              length_penalty=self.opt.get("beam_length_penalty", 0.65),
              padding_token=self.NULL_IDX,
              bos_token=self.START_IDX,
              eos_token=self.END_IDX,
              device=device,
              verbose=verbose,
              **pacer_kwargs,
          )
      elif method == "beam":
          return PacerBeamSearch(
              beam_size,
              min_length=self.beam_min_length,
              block_ngram=self.beam_block_ngram,
              context_block_ngram=self.beam_context_block_ngram,
              length_penalty=self.opt.get("beam_length_penalty", 0.65),
              padding_token=self.NULL_IDX,
              bos_token=self.START_IDX,
              eos_token=self.END_IDX,
              device=device,
              verbose=verbose,
              **pacer_kwargs,
          )
      elif method == "delayedbeam":
          return PacerDelayedBeamSearch(
              self.opt["topk"],
              self.opt["beam_delay"],
              beam_size,
              min_length=self.beam_min_length,
              block_ngram=self.beam_block_ngram,
              context_block_ngram=self.beam_context_block_ngram,
              length_penalty=self.opt.get("beam_length_penalty", 0.65),
              padding_token=self.NULL_IDX,
              bos_token=self.START_IDX,
              eos_token=self.END_IDX,
              device=device,
              verbose=verbose,
              **pacer_kwargs,
          )
      elif method == "topk":
          return PacerTopKSampling(
              self.opt["topk"],
              beam_size,
              min_length=self.beam_min_length,
              block_ngram=self.beam_block_ngram,
              context_block_ngram=self.beam_context_block_ngram,
              length_penalty=self.opt.get("beam_length_penalty", 0.65),
              padding_token=self.NULL_IDX,
              bos_token=self.START_IDX,
              eos_token=self.END_IDX,
              device=device,
              verbose=verbose,
              **pacer_kwargs,
          )
      elif method == "nucleus":
          return PacerNucleusSampling(
              self.opt["topp"],
              beam_size,
              min_length=self.beam_min_length,
              block_ngram=self.beam_block_ngram,
              context_block_ngram=self.beam_context_block_ngram,
              length_penalty=self.opt.get("beam_length_penalty", 0.65),
              padding_token=self.NULL_IDX,
              bos_token=self.START_IDX,
              eos_token=self.END_IDX,
              device=device,
              verbose=verbose,
              **pacer_kwargs,
          )
      else:
          raise NotImplementedError(
              f"Other gen methods not available for PACER: {method}"
          )
  
imports: import random
  import torch
  import torch.nn.functional
  from typing import Optional, Any, Dict, List
  from parlai.agents.rag.retrievers import clean_vec
  from parlai.agents.transformer.transformer import TransformerGeneratorAgent
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.core.torch_generator_agent import TreeSearch, GreedySearch, BeamSearch, DelayedBeamSearch, TopKSampling, NucleusSampling, TSType
  import parlai.utils.logging
  from parlai.utils.torch import neginf
  from projects.light_whoami.agents.rpa_rerank import RPAReranker, RPARerankAgent, LongRPARerankAgent
  from projects.light_whoami.task.utils import extract_characters
  from projects.msc.agents.long_tga import TransformerVariantAgent
  from parlai.agents.reranker.reranker import AbstractReranker
label_desc: Use image node_id 6 for calling the PacerAgentMixin obj's underlying member method code with example usage: obj._treesearch_factory(device, verbose) and returns: PacerGreedySearch, PacerBeamSearch, PacerDelayedBeamSearch, PacerTopKSampling, PacerNucleusSampling