class_docstr: [`SpeechEncoderDecoderModel`] 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
  :meth*~transformers.AutoModel.from_pretrained* class method for the encoder and
  :meth*~transformers.AutoModelForCausalLM.from_pretrained* class method for the decoder.
class_docstr_tok: ["[","`","SpeechEncoderDecoderModel","`","]","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",":","meth","*","~transformers.AutoModel.from_pretrained","*","class","method","for","the","encoder","and",":","meth","*","~transformers.AutoModelForCausalLM.from_pretrained","*","class","method","for","the","decoder","."]
code: def __init__(
      self,
      config: Optional[PretrainedConfig] = None,
      encoder: Optional[PreTrainedModel] = None,
      decoder: Optional[PreTrainedModel] = 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 = (
              SpeechEncoderDecoderConfig.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
      # make sure input & output embeddings is not tied
      config.tie_word_embeddings = False
      super().__init__(config)
  
      if encoder is None:
          encoder = AutoModel.from_config(config.encoder)
  
      if decoder is None:
          decoder = AutoModelForCausalLM.from_config(config.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
  
      # get encoder output hidden size
      self.encoder_output_dim = getattr(
          config.encoder,
          "output_hidden_size",
          config.encoder.hidden_size,
      )
      if (
          self.encoder_output_dim != self.decoder.config.hidden_size
          and self.decoder.config.cross_attention_hidden_size is None
      ):
          # encoder outputs might need to be projected to different dimension for decoder
          self.enc_to_dec_proj = nn.Linear(
              self.encoder.config.hidden_size,
              self.decoder.config.hidden_size,
          )
  
      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: from typing import Optional
  import torch
  from torch import nn
  from torch.nn import CrossEntropyLoss
  from ...configuration_utils import PretrainedConfig
  from ...modeling_outputs import BaseModelOutput, Seq2SeqLMOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from ..auto.configuration_auto import AutoConfig
  from ..auto.modeling_auto import AutoModel, AutoModelForCausalLM
  from .configuration_speech_encoder_decoder import SpeechEncoderDecoderConfig
label_desc: Use image node_id 1 to create a new SpeechEncoderDecoderModel object from inherited base classes: PreTrainedModel with example: obj = SpeechEncoderDecoderModel(config, encoder, decoder)