class_docstr: A class containing all functions for auto-regressive text generation, to be used as a mixin in [`PreTrainedModel`].
  
  The class exposes [`~generation.GenerationMixin.generate`], which can be used for:
      - *greedy decoding* by calling [`~generation.GenerationMixin.greedy_search`] if `num_beams=1` and
        `do_sample=False`
      - *contrastive search* by calling [`~generation.GenerationMixin.contrastive_search`] if `penalty_alpha>0` and
        `top_k>1`
      - *multinomial sampling* by calling [`~generation.GenerationMixin.sample`] if `num_beams=1` and
        `do_sample=True`
      - *beam-search decoding* by calling [`~generation.GenerationMixin.beam_search`] if `num_beams>1` and
        `do_sample=False`
      - *beam-search multinomial sampling* by calling [`~generation.GenerationMixin.beam_sample`] if `num_beams>1`
        and `do_sample=True`
      - *diverse beam-search decoding* by calling [`~generation.GenerationMixin.group_beam_search`], if `num_beams>1`
        and `num_beam_groups>1`
      - *constrained beam-search decoding* by calling [`~generation.GenerationMixin.constrained_beam_search`], if
        `constraints!=None` or `force_words_ids!=None`
  
  You do not need to call any of the above methods directly. Pass custom parameter values to 'generate' instead. To
  learn more about decoding strategies refer to the [text generation strategies guide](../generation_strategies).
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.GenerationMixin.generate","`","]",",","which","can","be","used","for",":","-","*","greedy","decoding","*","by","calling","[","`","~generation.GenerationMixin.greedy_search","`","]","if","`","num_beams=1","`","and","`","do_sample=False","`","-","*","contrastive","search","*","by","calling","[","`","~generation.GenerationMixin.contrastive_search","`","]","if","`","penalty_alpha",">","0","`","and","`","top_k",">","1","`","-","*","multinomial","sampling","*","by","calling","[","`","~generation.GenerationMixin.sample","`","]","if","`","num_beams=1","`","and","`","do_sample=True","`","-","*","beam-search","decoding","*","by","calling","[","`","~generation.GenerationMixin.beam_search","`","]","if","`","num_beams",">","1","`","and","`","do_sample=False","`","-","*","beam-search","multinomial","sampling","*","by","calling","[","`","~generation.GenerationMixin.beam_sample","`","]","if","`","num_beams",">","1","`","and","`","do_sample=True","`","-","*","diverse","beam-search","decoding","*","by","calling","[","`","~generation.GenerationMixin.group_beam_search","`","]",",","if","`","num_beams",">","1","`","and","`","num_beam_groups",">","1","`","-","*","constrained","beam-search","decoding","*","by","calling","[","`","~generation.GenerationMixin.constrained_beam_search","`","]",",","if","`","constraints","!","=None","`","or","`","force_words_ids","!","=None","`","You","do","not","need","to","call","any","of","the","above","methods","directly",".","Pass","custom","parameter","values","to","'generate","'","instead",".","To","learn","more","about","decoding","strategies","refer","to","the","[","text","generation","strategies","guide","]","(","..","\/generation_strategies",")","."]
docstr: Validates model kwargs for generation. Generate argument typos will also be caught here.
docstr_tok: ["Validates","model","kwargs","for","generation",".","Generate","argument","typos","will","also","be","caught","here","."]
code: def _validate_model_kwargs(self, model_kwargs: Dict[str, Any]):
      """Validates model kwargs for generation. Generate argument typos will also be caught here."""
      # If a `Cache` instance is passed, checks whether the model is compatible with it
      if (
          isinstance(model_kwargs.get("past_key_values", None), Cache)
          and not self._supports_cache_class
      ):
          raise ValueError(
              f"{self.__class__.__name__} does not support an instance of `Cache` as `past_key_values`. Please "
              "check the model documentation for supported cache formats."
          )
  
      # Excludes arguments that are handled before calling any model function
      if self.config.is_encoder_decoder:
          for key in ["decoder_input_ids"]:
              model_kwargs.pop(key, None)
  
      unused_model_args = []
      model_args = set(
          inspect.signature(
              self.prepare_inputs_for_generation
          ).parameters
      )
      # `kwargs`/`model_kwargs` is often used to handle optional forward pass inputs like `attention_mask`. If
      # `prepare_inputs_for_generation` doesn't accept them, then a stricter check can be made ;)
      if "kwargs" in model_args or "model_kwargs" in model_args:
          model_args |= set(inspect.signature(self.forward).parameters)
  
      # Encoder-Decoder models may also need Encoder arguments from `model_kwargs`
      if self.config.is_encoder_decoder:
          base_model = getattr(self, self.base_model_prefix, None)
  
          # allow encoder kwargs
          encoder = getattr(self, "encoder", None)
          # `MusicgenForConditionalGeneration` has `text_encoder` and `audio_encoder`.
          # Also, it has `base_model_prefix = "encoder_decoder"` but there is no `self.encoder_decoder`
          # TODO: A better way to handle this.
          if encoder is None and base_model is not None:
              encoder = getattr(base_model, "encoder", None)
  
          if encoder is not None:
              encoder_model_args = set(
                  inspect.signature(encoder.forward).parameters
              )
              model_args |= encoder_model_args
  
          # allow decoder kwargs
          decoder = getattr(self, "decoder", None)
          if decoder is None and base_model is not None:
              decoder = getattr(base_model, "decoder", None)
  
          if decoder is not None:
              decoder_model_args = set(
                  inspect.signature(decoder.forward).parameters
              )
              model_args |= {f"decoder_{x}" for x in decoder_model_args}
  
          # allow assistant_encoder_outputs to be passed if we're doing assisted generating
          if "assistant_encoder_outputs" in model_kwargs:
              model_args |= {"assistant_encoder_outputs"}
  
      for key, value in model_kwargs.items():
          if value is not None and key not in model_args:
              unused_model_args.append(key)
  
      if unused_model_args:
          raise ValueError(
              f"The following `model_kwargs` are not used by the model: {unused_model_args} (note: typos in the"
              " generate arguments will also show up in this list)"
          )
  
imports: import copy
  import inspect
  import warnings
  from dataclasses import dataclass
  from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  import torch.distributed
  from torch import nn
  from ..cache_utils import Cache, DynamicCache
  from ..integrations.deepspeed import is_deepspeed_zero3_enabled
  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 ..utils import ExplicitEnum, ModelOutput, is_accelerate_available, logging
  from .beam_constraints import DisjunctiveConstraint, PhrasalConstraint
  from .beam_search import BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
  from .candidate_generator import AssistedCandidateGenerator, CandidateGenerator, PromptLookupCandidateGenerator, _crop_past_key_values, _prepare_attention_mask, _prepare_token_type_ids
  from .configuration_utils import GenerationConfig
  from .logits_process import EncoderNoRepeatNGramLogitsProcessor, EncoderRepetitionPenaltyLogitsProcessor, EpsilonLogitsWarper, EtaLogitsWarper, ExponentialDecayLengthPenalty, ForcedBOSTokenLogitsProcessor, ForcedEOSTokenLogitsProcessor, ForceTokensLogitsProcessor, HammingDiversityLogitsProcessor, InfNanRemoveLogitsProcessor, LogitNormalization, LogitsProcessorList, MinLengthLogitsProcessor, MinNewTokensLengthLogitsProcessor, NoBadWordsLogitsProcessor, NoRepeatNGramLogitsProcessor, PrefixConstrainedLogitsProcessor, RepetitionPenaltyLogitsProcessor, SequenceBiasLogitsProcessor, SuppressTokensAtBeginLogitsProcessor, SuppressTokensLogitsProcessor, TemperatureLogitsWarper, TopKLogitsWarper, TopPLogitsWarper, TypicalLogitsWarper, UnbatchedClassifierFreeGuidanceLogitsProcessor
  from .stopping_criteria import MaxLengthCriteria, MaxTimeCriteria, StoppingCriteria, StoppingCriteriaList, validate_stopping_criteria
label_desc: Use image node_id 20 for calling the GenerationMixin obj's underlying member method code with example usage: obj._validate_model_kwargs(model_kwargs) without return types