class_docstr: Represents a sequence-to-sequence generator based on beam search.
class_docstr_tok: ["Represents","a","sequence-to-sequence","generator","based","on","beam","search","."]
docstr: :param model:
      The encoder-decoder model to use for generation.
  :param algorithm:
      The beam search algorithm.
  :param beam_size:
      The beam size.
  :param min_gen_len:
      The minimum allowed generation length.
  :param max_gen_len:
      The maximum allowed generation length as ``ax + b``, where ``x`` is
      the source sequence length.
  :param max_seq_len:
      The maximum allowed sequence length including prompt.
  :param echo_prompt:
      If ``True``, returns generated sequences with prompts appended.
  :param normalize_scores:
      If ``True``, normalizes scores by lengths of generated sequences.
  :param temperature:
      The logit temperature, where values greater than 1.0 produce more
      uniform logits; values less than 1.0 produce sharper logits.
  :param unk_penalty:
      The UNK symbol penalty, where values less than 0 produce more UNKs;
      values greater than 0 produce fewer UNKs.
  :param len_penalty:
      The length penalty, where values less than 1.0 favor shorter
      sequences; values greater than 1.0 favor longer sequences.
  :param prefill_chunk_size:
      The prefill will be performed incrementally by chunks of this size.
      If ``None``, the entire prefill will be performed at once.
  :param decode_capacity_increment:
      The sequence length capacity of state tensors will be incremented by
      multiples of this value. If ``None``, state tensors will be
      preallocated with a capacity of ``max_seq_len``.
  :param step_processors:
      The processors to call at each generation step.
code: def __init__(
      self,
      model: EncoderDecoderModel,
      *,
      algorithm: Optional[BeamSearchAlgorithm] = None,
      beam_size: int = 5,
      min_gen_len: int = 1,
      max_gen_len: Tuple[int, int] = (1, 128),
      max_seq_len: int = 1024,
      echo_prompt: bool = False,
      normalize_scores: bool = True,
      temperature: float = 1.0,
      unk_penalty: float = 0.0,
      len_penalty: float = 1.0,
      prefill_chunk_size: Optional[int] = 512,
      decode_capacity_increment: Optional[int] = 16,
      step_processors: Optional[Sequence[StepProcessor]] = None,
  ) -> None:
      """
      :param model:
          The encoder-decoder model to use for generation.
      :param algorithm:
          The beam search algorithm.
      :param beam_size:
          The beam size.
      :param min_gen_len:
          The minimum allowed generation length.
      :param max_gen_len:
          The maximum allowed generation length as ``ax + b``, where ``x`` is
          the source sequence length.
      :param max_seq_len:
          The maximum allowed sequence length including prompt.
      :param echo_prompt:
          If ``True``, returns generated sequences with prompts appended.
      :param normalize_scores:
          If ``True``, normalizes scores by lengths of generated sequences.
      :param temperature:
          The logit temperature, where values greater than 1.0 produce more
          uniform logits; values less than 1.0 produce sharper logits.
      :param unk_penalty:
          The UNK symbol penalty, where values less than 0 produce more UNKs;
          values greater than 0 produce fewer UNKs.
      :param len_penalty:
          The length penalty, where values less than 1.0 favor shorter
          sequences; values greater than 1.0 favor longer sequences.
      :param prefill_chunk_size:
          The prefill will be performed incrementally by chunks of this size.
          If ``None``, the entire prefill will be performed at once.
      :param decode_capacity_increment:
          The sequence length capacity of state tensors will be incremented by
          multiples of this value. If ``None``, state tensors will be
          preallocated with a capacity of ``max_seq_len``.
      :param step_processors:
          The processors to call at each generation step.
      """
      super().__init__(model)
  
      if min_gen_len < 1:
          raise ValueError(
              f"`min_gen_len` must be greater than or equal to 1, but is {min_gen_len} instead."
          )
  
      if prefill_chunk_size is not None and prefill_chunk_size < 1:
          raise ValueError(
              f"`prefill_chunk_size` must be greater than or equal to 1, but is {prefill_chunk_size} instead."
          )
  
      if (
          decode_capacity_increment is not None
          and decode_capacity_increment < 1
      ):
          raise ValueError(
              f"`decode_capacity_increment` must be greater than or equal to 1, but is {decode_capacity_increment} instead."
          )
  
      self.algorithm = algorithm or StandardBeamSearchAlgorithm()
      self.beam_size = beam_size
      self.min_gen_len = min_gen_len
      self.max_gen_len = max_gen_len
      self.max_seq_len = max_seq_len
      self.echo_prompt = echo_prompt
      self.normalize_scores = normalize_scores
      self.temperature = temperature
      self.unk_penalty = unk_penalty
      self.len_penalty = len_penalty
      self.prefill_chunk_size = prefill_chunk_size
      self.decode_capacity_increment = decode_capacity_increment
  
      if step_processors:
          self.step_processors = list(step_processors)
      else:
          self.step_processors = []
  
imports: from __future__ import annotations
  from abc import ABC, abstractmethod
  from dataclasses import dataclass
  from typing import Dict, List, Optional, Sequence, Tuple, Union, final
  import torch
  from torch import Tensor
  from torch.nn.functional import log_softmax
  from fairseq2.data import VocabularyInfo
  from fairseq2.generation.generator import Hypothesis, Seq2SeqGenerator, Seq2SeqGeneratorOutput, SequenceGenerator, SequenceGeneratorOutput, StepHook
  from fairseq2.generation.step_processor import StepProcessor
  from fairseq2.models.decoder import DecoderModel
  from fairseq2.models.encoder_decoder import EncoderDecoderModel
  from fairseq2.models.sequence import SequenceModelOutput
  from fairseq2.nn.incremental_state import IncrementalStateBag
  from fairseq2.nn.padding import PaddingMask
  from fairseq2.typing import finaloverride, override
label_desc: Use image node_id 1 to create a new BeamSearchSeq2SeqGenerator object from inherited base classes: Seq2SeqGenerator with example: obj = BeamSearchSeq2SeqGenerator(model)