class_docstr: A class containing all of the functions supporting generation, to be used as a mixin in [`TFPreTrainedModel`].
  
  The class exposes [`~generation.TFGenerationMixin.generate`], which can be used for:
      - *greedy decoding* by calling [`~generation.TFGenerationMixin.greedy_search`] if `num_beams=1` and
        `do_sample=False`
      - *contrastive search* by calling [`~generation.TFGenerationMixin.contrastive_search`] if `penalty_alpha>0` and
        `top_k>1`
      - *multinomial sampling* by calling [`~generation.TFGenerationMixin.sample`] if `num_beams=1` and
        `do_sample=True`
      - *beam-search decoding* by calling [`~generation.TFGenerationMixin.beam_search`] if `num_beams>1`
  
  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","of","the","functions","supporting","generation",",","to","be","used","as","a","mixin","in","[","`","TFPreTrainedModel","`","]",".","The","class","exposes","[","`","~generation.TFGenerationMixin.generate","`","]",",","which","can","be","used","for",":","-","*","greedy","decoding","*","by","calling","[","`","~generation.TFGenerationMixin.greedy_search","`","]","if","`","num_beams=1","`","and","`","do_sample=False","`","-","*","contrastive","search","*","by","calling","[","`","~generation.TFGenerationMixin.contrastive_search","`","]","if","`","penalty_alpha",">","0","`","and","`","top_k",">","1","`","-","*","multinomial","sampling","*","by","calling","[","`","~generation.TFGenerationMixin.sample","`","]","if","`","num_beams=1","`","and","`","do_sample=True","`","-","*","beam-search","decoding","*","by","calling","[","`","~generation.TFGenerationMixin.beam_search","`","]","if","`","num_beams",">","1","`","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: Expands tensors from [batch_size, ...] to [batch_size * expand_size, ...] or [batch_size, expand_size, ...],
  depending on `expand_in_new_axis`. Beam-based approaches expect this function to be used with
  `expand_in_new_axis=True`
code: def _expand_inputs_for_generation(
      expand_size: int = 1,
      is_encoder_decoder: bool = False,
      input_ids: Optional[tf.Tensor] = None,
      expand_in_new_axis: bool = False,
      **model_kwargs,
  ) -> Tuple[tf.Tensor, Dict[str, Any]]:
      """
      Expands tensors from [batch_size, ...] to [batch_size * expand_size, ...] or [batch_size, expand_size, ...],
      depending on `expand_in_new_axis`. Beam-based approaches expect this function to be used with
      `expand_in_new_axis=True`
      """
  
      def _expand_tensor(tensor: tf.Tensor):
          if expand_in_new_axis:
              shape = shape_list(tensor)
              return tf.broadcast_to(
                  tensor[:, None],
                  (shape[0], expand_size) + tuple(shape[1:]),
              )
          else:
              return tf.repeat(tensor, expand_size, axis=0)
  
      def _expand_dict_for_generation(dict_to_expand):
          for key in dict_to_expand:
              if dict_to_expand[key] is not None and isinstance(
                  dict_to_expand[key], tf.Tensor
              ):
                  dict_to_expand[key] = _expand_tensor(
                      dict_to_expand[key]
                  )
          return dict_to_expand
  
      if input_ids is not None:
          input_ids = _expand_tensor(input_ids)
  
      model_kwargs = _expand_dict_for_generation(model_kwargs)
  
      if is_encoder_decoder:
          if model_kwargs.get("encoder_outputs") is None:
              raise ValueError(
                  "If `is_encoder_decoder` is True, make sure that `encoder_outputs` is defined."
              )
          model_kwargs["encoder_outputs"] = _expand_dict_for_generation(
              model_kwargs["encoder_outputs"]
          )
  
      return input_ids, model_kwargs
  
imports: import copy
  import inspect
  import warnings
  from dataclasses import dataclass
  from typing import Any, Dict, Optional, Tuple, Union
  import numpy
  import tensorflow
  from tensorflow.compiler.tf2xla.python.xla import dynamic_update_slice
  from ..modeling_tf_outputs import TFCausalLMOutputWithPast, TFSeq2SeqLMOutput
  from ..models.auto import TF_MODEL_FOR_CAUSAL_LM_MAPPING, TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING, TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING, TF_MODEL_FOR_VISION_2_SEQ_MAPPING
  from ..tf_utils import shape_list, stable_softmax
  from ..utils import ModelOutput, logging
  from .configuration_utils import GenerationConfig
  from .tf_logits_process import TFForcedBOSTokenLogitsProcessor, TFForcedEOSTokenLogitsProcessor, TFForceTokensLogitsProcessor, TFLogitsProcessorList, TFMinLengthLogitsProcessor, TFNoBadWordsLogitsProcessor, TFNoRepeatNGramLogitsProcessor, TFRepetitionPenaltyLogitsProcessor, TFSuppressTokensAtBeginLogitsProcessor, TFSuppressTokensLogitsProcessor, TFTemperatureLogitsWarper, TFTopKLogitsWarper, TFTopPLogitsWarper
label_desc: Use image node_id 11 for calling the TFGenerationMixin obj's underlying member method code with example usage: obj._expand_inputs_for_generation(expand_size, is_encoder_decoder, input_ids, expand_in_new_axis) and returns: input_ids,  model_kwargs, dict_to_expand, tf, tf