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: Initializes input ids for generation, if necessary.
code: def _maybe_initialize_input_ids_for_generation(
      self,
      inputs: Optional[tf.Tensor] = None,
      bos_token_id: Optional[int] = None,
      model_kwargs: Optional[Dict[str, tf.Tensor]] = None,
  ) -> tf.Tensor:
      """Initializes input ids for generation, if necessary."""
      if inputs is not None:
          return inputs
  
      encoder_outputs = model_kwargs.get("encoder_outputs")
      if self.config.is_encoder_decoder and encoder_outputs is not None:
          # make dummy input_ids with value -100, as a sanity check ensuring that they won't be used for encoding
          shape = encoder_outputs.last_hidden_state.shape[:-1]
          return tf.ones(shape, dtype=tf.int32) * -100
  
      if bos_token_id is None:
          raise ValueError(
              "`bos_token_id` has to be defined when no `input_ids` are provided."
          )
  
      # If there is some tensor in `model_kwargs`, we can infer the batch size from it. This is helpful with
      # soft-prompting or in multimodal implementations built on top of decoder-only language models.
      batch_size = 1
      for value in model_kwargs.values():
          if isinstance(value, tf.Tensor):
              batch_size = value.shape[0]
              break
      return tf.ones((batch_size, 1), dtype=tf.int32) * bos_token_id
  
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 13 for calling the TFGenerationMixin obj's underlying member method code with example usage: obj._maybe_initialize_input_ids_for_generation(inputs, bos_token_id, model_kwargs) and returns: unknown, inputs, unknown