class_docstr: A class containing all functions for auto-regressive text generation, to be used as a mixin in [`PreTrainedModel`].
  
  The class exposes [`~generation_utils.GenerationMixin.generate`], which can be used for:
      - *greedy decoding* by calling [`~generation_utils.GenerationMixin.greedy_search`] if `num_beams=1` and
        `do_sample=False`.
      - *contrastive search* by calling [`~generation_utils.GenerationMixin.contrastive_search`] if `penalty_alpha>0`
        and `top_k>1`
      - *multinomial sampling* by calling [`~generation_utils.GenerationMixin.sample`] if `num_beams=1` and
        `do_sample=True`.
      - *beam-search decoding* by calling [`~generation_utils.GenerationMixin.beam_search`] if `num_beams>1` and
        `do_sample=False`.
      - *beam-search multinomial sampling* by calling [`~generation_utils.GenerationMixin.beam_sample`] if
        `num_beams>1` and `do_sample=True`.
      - *diverse beam-search decoding* by calling [`~generation_utils.GenerationMixin.group_beam_search`], if
        `num_beams>1` and `num_beam_groups>1`.
      - *constrained beam-search decoding* by calling [`~generation_utils.GenerationMixin.constrained_beam_search`],
        if `constraints!=None` or `force_words_ids!=None`.
class_docstr_tok: ["A","class","containing","all","functions","for","auto-regressive","text","generation",",","to","be","used","as","a","mixin","in","[","`","PreTrainedModel","`","]",".","The","class","exposes","[","`","~generation_utils.GenerationMixin.generate","`","]",",","which","can","be","used","for",":","-","*","greedy","decoding","*","by","calling","[","`","~generation_utils.GenerationMixin.greedy_search","`","]","if","`","num_beams=1","`","and","`","do_sample=False","`",".","-","*","contrastive","search","*","by","calling","[","`","~generation_utils.GenerationMixin.contrastive_search","`","]","if","`","penalty_alpha",">","0","`","and","`","top_k",">","1","`","-","*","multinomial","sampling","*","by","calling","[","`","~generation_utils.GenerationMixin.sample","`","]","if","`","num_beams=1","`","and","`","do_sample=True","`",".","-","*","beam-search","decoding","*","by","calling","[","`","~generation_utils.GenerationMixin.beam_search","`","]","if","`","num_beams",">","1","`","and","`","do_sample=False","`",".","-","*","beam-search","multinomial","sampling","*","by","calling","[","`","~generation_utils.GenerationMixin.beam_sample","`","]","if","`","num_beams",">","1","`","and","`","do_sample=True","`",".","-","*","diverse","beam-search","decoding","*","by","calling","[","`","~generation_utils.GenerationMixin.group_beam_search","`","]",",","if","`","num_beams",">","1","`","and","`","num_beam_groups",">","1","`",".","-","*","constrained","beam-search","decoding","*","by","calling","[","`","~generation_utils.GenerationMixin.constrained_beam_search","`","]",",","if","`","constraints","!","=None","`","or","`","force_words_ids","!","=None","`","."]
docstr: This class returns a [`LogitsProcessorList`] list object that contains all relevant [`LogitsProcessor`]
  instances used to modify the scores of the language model head.
docstr_tok: ["This","class","returns","a","[","`","LogitsProcessorList","`","]","list","object","that","contains","all","relevant","[","`","LogitsProcessor","`","]","instances","used","to","modify","the","scores","of","the","language","model","head","."]
code: def _get_logits_processor(
      self,
      repetition_penalty: float,
      no_repeat_ngram_size: int,
      encoder_no_repeat_ngram_size: int,
      input_ids_seq_length: int,
      encoder_input_ids: torch.LongTensor,
      bad_words_ids: List[List[int]],
      min_length: int,
      max_length: int,
      eos_token_id: int,
      forced_bos_token_id: int,
      forced_eos_token_id: int,
      prefix_allowed_tokens_fn: Callable[
          [int, torch.Tensor], List[int]
      ],
      num_beams: int,
      num_beam_groups: int,
      diversity_penalty: float,
      remove_invalid_values: bool,
      exponential_decay_length_penalty: Tuple,
      logits_processor: Optional[LogitsProcessorList],
      renormalize_logits: Optional[bool],
      suppress_tokens: Optional[List[int]] = None,
      begin_suppress_tokens: Optional[List[int]] = None,
      forced_decoder_ids: Optional[List[List[int]]] = None,
  ) -> LogitsProcessorList:
      """
      This class returns a [`LogitsProcessorList`] list object that contains all relevant [`LogitsProcessor`]
      instances used to modify the scores of the language model head.
      """
      processors = LogitsProcessorList()
  
      # init warp parameters
      repetition_penalty = (
          repetition_penalty
          if repetition_penalty is not None
          else self.config.repetition_penalty
      )
      no_repeat_ngram_size = (
          no_repeat_ngram_size
          if no_repeat_ngram_size is not None
          else self.config.no_repeat_ngram_size
      )
      encoder_no_repeat_ngram_size = (
          encoder_no_repeat_ngram_size
          if encoder_no_repeat_ngram_size is not None
          else self.config.encoder_no_repeat_ngram_size
      )
      bad_words_ids = (
          bad_words_ids
          if bad_words_ids is not None
          else self.config.bad_words_ids
      )
      eos_token_id = (
          eos_token_id
          if eos_token_id is not None
          else self.config.eos_token_id
      )
      diversity_penalty = (
          diversity_penalty
          if diversity_penalty is not None
          else self.config.diversity_penalty
      )
      forced_bos_token_id = (
          forced_bos_token_id
          if forced_bos_token_id is not None
          else self.config.forced_bos_token_id
      )
      forced_eos_token_id = (
          forced_eos_token_id
          if forced_eos_token_id is not None
          else self.config.forced_eos_token_id
      )
      remove_invalid_values = (
          remove_invalid_values
          if remove_invalid_values is not None
          else self.config.remove_invalid_values
      )
      exponential_decay_length_penalty = (
          exponential_decay_length_penalty
          if exponential_decay_length_penalty is not None
          else self.config.exponential_decay_length_penalty
      )
      suppress_tokens = (
          suppress_tokens
          if suppress_tokens is not None
          else self.config.suppress_tokens
      )
      begin_suppress_tokens = (
          begin_suppress_tokens
          if begin_suppress_tokens is not None
          else self.config.begin_suppress_tokens
      )
      if forced_decoder_ids is None and hasattr(
          self.config, "forced_decoder_ids"
      ):
          forced_decoder_ids = self.config.forced_decoder_ids
      # instantiate processors list
  
      # the following idea is largely copied from this PR: https://github.com/huggingface/transformers/pull/5420/files
      # all samplers can be found in `generation_utils_samplers.py`
      if diversity_penalty is not None and diversity_penalty > 0.0:
          processors.append(
              HammingDiversityLogitsProcessor(
                  diversity_penalty=diversity_penalty,
                  num_beams=num_beams,
                  num_beam_groups=num_beam_groups,
              )
          )
      if repetition_penalty is not None and repetition_penalty != 1.0:
          processors.append(
              RepetitionPenaltyLogitsProcessor(
                  penalty=repetition_penalty
              )
          )
      if no_repeat_ngram_size is not None and no_repeat_ngram_size > 0:
          processors.append(
              NoRepeatNGramLogitsProcessor(no_repeat_ngram_size)
          )
      if (
          encoder_no_repeat_ngram_size is not None
          and encoder_no_repeat_ngram_size > 0
      ):
          if self.config.is_encoder_decoder:
              processors.append(
                  EncoderNoRepeatNGramLogitsProcessor(
                      encoder_no_repeat_ngram_size, encoder_input_ids
                  )
              )
          else:
              raise ValueError(
                  "It's impossible to use `encoder_no_repeat_ngram_size` with decoder-only architecture"
              )
      if bad_words_ids is not None:
          processors.append(
              NoBadWordsLogitsProcessor(bad_words_ids, eos_token_id)
          )
      if (
          min_length is not None
          and eos_token_id is not None
          and min_length > 0
      ):
          processors.append(
              MinLengthLogitsProcessor(min_length, eos_token_id)
          )
      if prefix_allowed_tokens_fn is not None:
          processors.append(
              PrefixConstrainedLogitsProcessor(
                  prefix_allowed_tokens_fn, num_beams // num_beam_groups
              )
          )
      if forced_bos_token_id is not None:
          processors.append(
              ForcedBOSTokenLogitsProcessor(forced_bos_token_id)
          )
      if forced_eos_token_id is not None:
          processors.append(
              ForcedEOSTokenLogitsProcessor(
                  max_length, forced_eos_token_id
              )
          )
      if remove_invalid_values is True:
          processors.append(InfNanRemoveLogitsProcessor())
      if exponential_decay_length_penalty is not None:
          processors.append(
              ExponentialDecayLengthPenalty(
                  exponential_decay_length_penalty,
                  eos_token_id,
                  input_ids_seq_length,
              )
          )
      if suppress_tokens is not None:
          processors.append(
              SuppressTokensLogitsProcessor(suppress_tokens)
          )
      if begin_suppress_tokens is not None:
          begin_index = input_ids_seq_length
          begin_index = (
              begin_index
              if (
                  input_ids_seq_length > 1
                  or forced_bos_token_id is None
              )
              else begin_index + 1
          )
          if forced_decoder_ids is not None:
              begin_index += forced_decoder_ids[-1][
                  0
              ]  # generation starts after the last token that is forced
          processors.append(
              SuppressTokensAtBeginLogitsProcessor(
                  begin_suppress_tokens, begin_index
              )
          )
      if forced_decoder_ids is not None:
          processors.append(
              ForceTokensLogitsProcessor(forced_decoder_ids)
          )
      processors = self._merge_criteria_processor_list(
          processors, logits_processor
      )
      # `LogitNormalization` should always be the last logit processor, when present
      if renormalize_logits is True:
          processors.append(LogitNormalization())
      return processors
  
imports: import inspect
  import warnings
  from dataclasses import dataclass
  from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union
  import torch
  import torch.distributed
  from torch import nn
  from flexgen.timer import timers
  from .generation_beam_constraints import Constraint, DisjunctiveConstraint, PhrasalConstraint
  from .generation_beam_search import BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
  from .generation_logits_process import EncoderNoRepeatNGramLogitsProcessor, ExponentialDecayLengthPenalty, ForcedBOSTokenLogitsProcessor, ForcedEOSTokenLogitsProcessor, ForceTokensLogitsProcessor, HammingDiversityLogitsProcessor, InfNanRemoveLogitsProcessor, LogitNormalization, LogitsProcessorList, MinLengthLogitsProcessor, NoBadWordsLogitsProcessor, NoRepeatNGramLogitsProcessor, PrefixConstrainedLogitsProcessor, RepetitionPenaltyLogitsProcessor, SuppressTokensAtBeginLogitsProcessor, SuppressTokensLogitsProcessor, TemperatureLogitsWarper, TopKLogitsWarper, TopPLogitsWarper, TypicalLogitsWarper
  from .generation_stopping_criteria import MaxLengthCriteria, MaxTimeCriteria, StoppingCriteria, StoppingCriteriaList, validate_stopping_criteria
  from .modeling_outputs import CausalLMOutputWithPast, Seq2SeqLMOutput
  from .models.auto import MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING, MODEL_FOR_CAUSAL_LM_MAPPING, MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING, MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING, MODEL_FOR_VISION_2_SEQ_MAPPING
  from .pytorch_utils import torch_int_div
  from .utils import ModelOutput, logging
label_desc: Use image node_id 13 for calling the GenerationMixin obj's underlying member method code with example usage: obj._get_logits_processor(repetition_penalty, no_repeat_ngram_size, encoder_no_repeat_ngram_size, input_ids_seq_length, encoder_input_ids, bad_words_ids, min_length, max_length, eos_token_id, forced_bos_token_id, forced_eos_token_id, prefix_allowed_tokens_fn, num_beams, num_beam_groups, diversity_penalty, remove_invalid_values, exponential_decay_length_penalty, logits_processor, renormalize_logits, suppress_tokens, begin_suppress_tokens, forced_decoder_ids) and returns: processors