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: Prepares `decoder_input_ids` for generation with encoder-decoder models
code: def _prepare_decoder_input_ids_for_generation(
      self,
      batch_size: int,
      model_input_name: str,
      model_kwargs: Dict[str, tf.Tensor],
      decoder_start_token_id: int = None,
      bos_token_id: int = None,
  ) -> Tuple[tf.Tensor, Dict[str, tf.Tensor]]:
      """Prepares `decoder_input_ids` for generation with encoder-decoder models"""
      # 1. Check whether the user has defined `decoder_input_ids` manually. To facilitate in terms of input naming,
      # we also allow the user to pass it under `input_ids`, if the encoder does not use it as the main input.
      if (
          model_kwargs is not None
          and "decoder_input_ids" in model_kwargs
      ):
          decoder_input_ids = model_kwargs.pop("decoder_input_ids")
      elif (
          "input_ids" in model_kwargs
          and model_input_name != "input_ids"
      ):
          decoder_input_ids = model_kwargs.pop("input_ids")
      else:
          decoder_input_ids = None
  
      # 2. Encoder-decoder models expect the `decoder_input_ids` to start with a special token. Let's ensure that.
      decoder_start_token_id = self._get_decoder_start_token_id(
          decoder_start_token_id, bos_token_id
      )
      decoder_input_ids_start = (
          tf.ones((batch_size, 1), dtype=tf.int32)
          * decoder_start_token_id
      )
  
      # no user input -> use decoder_start_token_id as decoder_input_ids
      if decoder_input_ids is None:
          decoder_input_ids = decoder_input_ids_start
      # user input but doesn't start with decoder_start_token_id -> prepend decoder_start_token_id (and adjust
      # decoder_attention_mask if provided)
      elif tf.reduce_all(
          decoder_input_ids[:, 0] != decoder_start_token_id
      ):
          decoder_input_ids = tf.concat(
              [decoder_input_ids_start, decoder_input_ids], axis=-1
          )
          if "decoder_attention_mask" in model_kwargs:
              decoder_attention_mask = model_kwargs[
                  "decoder_attention_mask"
              ]
              decoder_attention_mask = tf.concat(
                  (
                      tf.ones_like(decoder_attention_mask)[:, :1],
                      decoder_attention_mask,
                  ),
                  axis=-1,
              )
              model_kwargs[
                  "decoder_attention_mask"
              ] = decoder_attention_mask
  
      return decoder_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 9 for calling the TFGenerationMixin obj's underlying member method code with example usage: obj._prepare_decoder_input_ids_for_generation(batch_size, model_input_name, model_kwargs, decoder_start_token_id, bos_token_id) and returns: decoder_input_ids,  model_kwargs