class_docstr: [`TFEncoderDecoderModel`] is a generic model class that will be instantiated as a transformer architecture with one
  of the base model classes of the library as encoder and another one as decoder when created with the
  [`~TFAutoModel.from_pretrained`] class method for the encoder and [`~TFAutoModelForCausalLM.from_pretrained`] class
  method for the decoder.
class_docstr_tok: ["[","`","TFEncoderDecoderModel","`","]","is","a","generic","model","class","that","will","be","instantiated","as","a","transformer","architecture","with","one","of","the","base","model","classes","of","the","library","as","encoder","and","another","one","as","decoder","when","created","with","the","[","`","~TFAutoModel.from_pretrained","`","]","class","method","for","the","encoder","and","[","`","~TFAutoModelForCausalLM.from_pretrained","`","]","class","method","for","the","decoder","."]
code: def __init__(
      self,
      config: Optional[PretrainedConfig] = None,
      encoder: Optional[TFPreTrainedModel] = None,
      decoder: Optional[TFPreTrainedModel] = None,
  ):
      if config is None and (encoder is None or decoder is None):
          raise ValueError(
              "Either a configuration or an encoder and a decoder has to be provided."
          )
      if config is None:
          config = EncoderDecoderConfig.from_encoder_decoder_configs(
              encoder.config, decoder.config
          )
      else:
          if not isinstance(config, self.config_class):
              raise ValueError(
                  f"config: {config} has to be of type {self.config_class}"
              )
  
      if config.decoder.cross_attention_hidden_size is not None:
          if (
              config.decoder.cross_attention_hidden_size
              != config.encoder.hidden_size
          ):
              raise ValueError(
                  "If `cross_attention_hidden_size` is specified in the decoder's configuration, it has to be equal"
                  f" to the encoder's `hidden_size`. Got {config.decoder.cross_attention_hidden_size} for"
                  f" `config.decoder.cross_attention_hidden_size` and {config.encoder.hidden_size} for"
                  " `config.encoder.hidden_size`."
              )
  
      # initialize with config
      super().__init__(config)
  
      if encoder is None:
          encoder = TFAutoModel.from_config(
              config.encoder, name="encoder"
          )
  
      if decoder is None:
          decoder = TFAutoModelForCausalLM.from_config(
              config.decoder, name="decoder"
          )
  
      self.encoder = encoder
      self.decoder = decoder
  
      if self.encoder.config.to_dict() != self.config.encoder.to_dict():
          logger.warning(
              f"Config of the encoder: {self.encoder.__class__} is overwritten by shared encoder config:"
              f" {self.config.encoder}"
          )
      if self.decoder.config.to_dict() != self.config.decoder.to_dict():
          logger.warning(
              f"Config of the decoder: {self.decoder.__class__} is overwritten by shared decoder config:"
              f" {self.config.decoder}"
          )
  
      # make sure that the individual model's config refers to the shared config
      # so that the updates to the config will be synced
      self.encoder.config = self.config.encoder
      self.decoder.config = self.config.decoder
  
      # encoder outputs might need to be projected to different dimension for decoder
      if (
          self.encoder.config.hidden_size
          != self.decoder.config.hidden_size
          and self.decoder.config.cross_attention_hidden_size is None
      ):
          self.enc_to_dec_proj = tf.keras.layers.Dense(
              units=self.decoder.config.hidden_size,
              kernel_initializer=get_initializer(
                  config.encoder.initializer_range
              ),
              name="enc_to_dec_proj",
          )
  
      if self.encoder.get_output_embeddings() is not None:
          raise ValueError(
              f"The encoder {self.encoder} should not have a LM Head. Please use a model without LM Head"
          )
  
imports: import gc
  import os
  import tempfile
  import warnings
  from typing import Optional
  import tensorflow
  from ...configuration_utils import PretrainedConfig
  from ...modeling_tf_outputs import TFBaseModelOutput, TFSeq2SeqLMOutput
  from ...modeling_tf_utils import TFCausalLanguageModelingLoss, TFPreTrainedModel, get_initializer, unpack_inputs
  from ...tf_utils import shape_list
  from ...utils import DUMMY_INPUTS, ModelOutput, add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from ..auto.configuration_auto import AutoConfig
  from ..auto.modeling_tf_auto import TFAutoModel, TFAutoModelForCausalLM
  from .configuration_encoder_decoder import EncoderDecoderConfig
label_desc: Use image node_id 1 to create a new TFEncoderDecoderModel object from inherited base classes: TFPreTrainedModel, TFCausalLanguageModelingLoss with example: obj = TFEncoderDecoderModel(config, encoder, decoder)