class_docstr: [`FlaxSpeechEncoderDecoderModel`] is a generic model class that will be instantiated as a transformer architecture
  with the module (flax.nn.Module) of one of the base model classes of the library as encoder module and another one
  as decoder module when created with the :meth*~transformers.FlaxAutoModel.from_pretrained* class method for the
  encoder and :meth*~transformers.FlaxAutoModelForCausalLM.from_pretrained* class method for the decoder.
class_docstr_tok: ["[","`","FlaxSpeechEncoderDecoderModel","`","]","is","a","generic","model","class","that","will","be","instantiated","as","a","transformer","architecture","with","the","module","(","flax.nn.Module",")","of","one","of","the","base","model","classes","of","the","library","as","encoder","module","and","another","one","as","decoder","module","when","created","with","the",":","meth","*","~transformers.FlaxAutoModel.from_pretrained","*","class","method","for","the","encoder","and",":","meth","*","~transformers.FlaxAutoModelForCausalLM.from_pretrained","*","class","method","for","the","decoder","."]
docstr: Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
  checkpoints.
  
  Params:
      encoder_pretrained_model_name_or_path (`Union[str, os.PathLike]`, *optional*):
          Information necessary to initiate the encoder. Can be either:
  
              - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
                user or organization name, like `dbmdz/bert-base-german-cased`.
              - A path to a *directory* containing model weights saved using
                [`~FlaxPreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.
  
      decoder_pretrained_model_name_or_path (`Union[str, os.PathLike]`, *optional*, defaults to `None`):
          Information necessary to initiate the decoder. Can be either:
  
              - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
                user or organization name, like `dbmdz/bert-base-german-cased`.
              - A path to a *directory* containing model weights saved using
                [`~FlaxPreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.
  
      model_args (remaining positional arguments, *optional*):
          All remaning positional arguments will be passed to the underlying model's `__init__` method.
  
      kwargs (remaining dictionary of keyword arguments, *optional*):
          Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
          `output_attentions=True`).
  
          - To update the encoder configuration, use the prefix *encoder_* for each configuration parameter.
          - To update the decoder configuration, use the prefix *decoder_* for each configuration parameter.
          - To update the parent model configuration, do not use a prefix for each configuration parameter.
  
          Behaves differently depending on whether a `config` is provided or automatically loaded.
  
  Example:
  
  ```python
  >>> from transformers import FlaxSpeechEncoderDecoderModel
  
  >>> # initialize a wav2vec2-2-bart from pretrained wav2vec2 and bart models. Note that the cross-attention layers will be randomly initialized
  >>> model = FlaxSpeechEncoderDecoderModel.from_encoder_decoder_pretrained(
  ...     "facebook/wav2vec2-large-lv60", "facebook/bart-large"
  ... )
  >>> # saving model after fine-tuning
  >>> model.save_pretrained("./wav2vec2-2-bart-large")
  >>> # load fine-tuned model
  >>> model = FlaxSpeechEncoderDecoderModel.from_pretrained("./wav2vec2-2-bart-large")
  ```
docstr_tok: ["Instantiate","an","encoder","and","a","decoder","from","one","or","two","base","classes","of","the","library","from","pretrained","model","checkpoints",".","Params",":","encoder_pretrained_model_name_or_path","(","`","Union","[","str",",","os.PathLike","]","`",",","*","optional","*",")",":","Information","necessary","to","initiate","the","encoder",".","Can","be","either",":","-","A","string",",","the","*","model","id","*","of","a","pretrained","model","hosted","inside","a","model","repo","on","huggingface.co",".","Valid","model","ids","can","be","located","at","the","root-level",",","like","`","bert-base-uncased","`",",","or","namespaced","under","a","user","or","organization","name",",","like","`","dbmdz\/bert-base-german-cased","`",".","-","A","path","to","a","*","directory","*","containing","model","weights","saved","using","[","`","~FlaxPreTrainedModel.save_pretrained","`","]",",","e.g.",",","`",".\/my_model_directory\/","`",".","decoder_pretrained_model_name_or_path","(","`","Union","[","str",",","os.PathLike","]","`",",","*","optional","*",",","defaults","to","`","None","`",")",":","Information","necessary","to","initiate","the","decoder",".","Can","be","either",":","-","A","string",",","the","*","model","id","*","of","a","pretrained","model","hosted","inside","a","model","repo","on","huggingface.co",".","Valid","model","ids","can","be","located","at","the","root-level",",","like","`","bert-base-uncased","`",",","or","namespaced","under","a","user","or","organization","name",",","like","`","dbmdz\/bert-base-german-cased","`",".","-","A","path","to","a","*","directory","*","containing","model","weights","saved","using","[","`","~FlaxPreTrainedModel.save_pretrained","`","]",",","e.g.",",","`",".\/my_model_directory\/","`",".","model_args","(","remaining","positional","arguments",",","*","optional","*",")",":","All","remaning","positional","arguments","will","be","passed","to","the","underlying","model","'s","`","__init__","`","method",".","kwargs","(","remaining","dictionary","of","keyword","arguments",",","*","optional","*",")",":","Can","be","used","to","update","the","configuration","object","(","after","it","being","loaded",")","and","initiate","the","model","(","e.g.",",","`","output_attentions=True","`",")",".","-","To","update","the","encoder","configuration",",","use","the","prefix","*","encoder_","*","for","each","configuration","parameter",".","-","To","update","the","decoder","configuration",",","use","the","prefix","*","decoder_","*","for","each","configuration","parameter",".","-","To","update","the","parent","model","configuration",",","do","not","use","a","prefix","for","each","configuration","parameter",".","Behaves","differently","depending","on","whether","a","`","config","`","is","provided","or","automatically","loaded",".","Example",":","``","`","python",">",">",">","from","transformers","import","FlaxSpeechEncoderDecoderModel",">",">",">","#","initialize","a","wav2vec2-2-bart","from","pretrained","wav2vec2","and","bart","models",".","Note","that","the","cross-attention","layers","will","be","randomly","initialized",">",">",">","model","=","FlaxSpeechEncoderDecoderModel.from_encoder_decoder_pretrained","(","...","``","facebook\/wav2vec2-large-lv60","''",",","``","facebook\/bart-large","''","...",")",">",">",">","#","saving","model","after","fine-tuning",">",">",">","model.save_pretrained","(","``",".\/wav2vec2-2-bart-large","''",")",">",">",">","#","load","fine-tuned","model",">",">",">","model","=","FlaxSpeechEncoderDecoderModel.from_pretrained","(","``",".\/wav2vec2-2-bart-large","''",")","``","`"]
code: def from_encoder_decoder_pretrained(
      cls,
      encoder_pretrained_model_name_or_path: Optional[
          Union[str, os.PathLike]
      ] = None,
      decoder_pretrained_model_name_or_path: Optional[
          Union[str, os.PathLike]
      ] = None,
      *model_args,
      **kwargs,
  ) -> FlaxPreTrainedModel:
      r"""
      Instantiate an encoder and a decoder from one or two base classes of the library from pretrained model
      checkpoints.
  
      Params:
          encoder_pretrained_model_name_or_path (`Union[str, os.PathLike]`, *optional*):
              Information necessary to initiate the encoder. Can be either:
  
                  - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                    Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
                    user or organization name, like `dbmdz/bert-base-german-cased`.
                  - A path to a *directory* containing model weights saved using
                    [`~FlaxPreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.
  
          decoder_pretrained_model_name_or_path (`Union[str, os.PathLike]`, *optional*, defaults to `None`):
              Information necessary to initiate the decoder. Can be either:
  
                  - A string, the *model id* of a pretrained model hosted inside a model repo on huggingface.co.
                    Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
                    user or organization name, like `dbmdz/bert-base-german-cased`.
                  - A path to a *directory* containing model weights saved using
                    [`~FlaxPreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.
  
          model_args (remaining positional arguments, *optional*):
              All remaning positional arguments will be passed to the underlying model's `__init__` method.
  
          kwargs (remaining dictionary of keyword arguments, *optional*):
              Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
              `output_attentions=True`).
  
              - To update the encoder configuration, use the prefix *encoder_* for each configuration parameter.
              - To update the decoder configuration, use the prefix *decoder_* for each configuration parameter.
              - To update the parent model configuration, do not use a prefix for each configuration parameter.
  
              Behaves differently depending on whether a `config` is provided or automatically loaded.
  
      Example:
  
      ```python
      >>> from transformers import FlaxSpeechEncoderDecoderModel
  
      >>> # initialize a wav2vec2-2-bart from pretrained wav2vec2 and bart models. Note that the cross-attention layers will be randomly initialized
      >>> model = FlaxSpeechEncoderDecoderModel.from_encoder_decoder_pretrained(
      ...     "facebook/wav2vec2-large-lv60", "facebook/bart-large"
      ... )
      >>> # saving model after fine-tuning
      >>> model.save_pretrained("./wav2vec2-2-bart-large")
      >>> # load fine-tuned model
      >>> model = FlaxSpeechEncoderDecoderModel.from_pretrained("./wav2vec2-2-bart-large")
      ```"""
  
      kwargs_encoder = {
          argument[len("encoder_") :]: value
          for argument, value in kwargs.items()
          if argument.startswith("encoder_")
      }
  
      kwargs_decoder = {
          argument[len("decoder_") :]: value
          for argument, value in kwargs.items()
          if argument.startswith("decoder_")
      }
  
      # remove encoder, decoder kwargs from kwargs
      for key in kwargs_encoder.keys():
          del kwargs["encoder_" + key]
      for key in kwargs_decoder.keys():
          del kwargs["decoder_" + key]
  
      # Load and initialize the encoder and decoder
      # The distinction between encoder and decoder at the model level is made
      # by the value of the flag `is_decoder` that we need to set correctly.
      encoder = kwargs_encoder.pop("model", None)
      if encoder is None:
          if encoder_pretrained_model_name_or_path is None:
              raise ValueError(
                  "If `encoder_model` is not defined as an argument, a `encoder_pretrained_model_name_or_path` has "
                  "to be defined."
              )
  
          if "config" not in kwargs_encoder:
              (
                  encoder_config,
                  kwargs_encoder,
              ) = AutoConfig.from_pretrained(
                  encoder_pretrained_model_name_or_path,
                  **kwargs_encoder,
                  return_unused_kwargs=True,
              )
              if (
                  encoder_config.is_decoder is True
                  or encoder_config.add_cross_attention is True
              ):
                  logger.info(
                      f"Initializing {encoder_pretrained_model_name_or_path} as a encoder model "
                      "from a decoder model. Cross-attention and casual mask are disabled."
                  )
                  encoder_config.is_decoder = False
                  encoder_config.add_cross_attention = False
  
              kwargs_encoder["config"] = encoder_config
  
          encoder = FlaxAutoModel.from_pretrained(
              encoder_pretrained_model_name_or_path,
              *model_args,
              **kwargs_encoder,
          )
  
      decoder = kwargs_decoder.pop("model", None)
      if decoder is None:
          if decoder_pretrained_model_name_or_path is None:
              raise ValueError(
                  "If `decoder_model` is not defined as an argument, a `decoder_pretrained_model_name_or_path` has "
                  "to be defined."
              )
  
          if "config" not in kwargs_decoder:
              (
                  decoder_config,
                  kwargs_decoder,
              ) = AutoConfig.from_pretrained(
                  decoder_pretrained_model_name_or_path,
                  **kwargs_decoder,
                  return_unused_kwargs=True,
              )
              if (
                  decoder_config.is_decoder is False
                  or decoder_config.add_cross_attention is False
              ):
                  logger.info(
                      f"Initializing {decoder_pretrained_model_name_or_path} as a decoder model. Cross attention"
                      f" layers are added to {decoder_pretrained_model_name_or_path} and randomly initialized if"
                      f" {decoder_pretrained_model_name_or_path}'s architecture allows for cross attention layers."
                  )
                  decoder_config.is_decoder = True
                  decoder_config.add_cross_attention = True
  
              kwargs_decoder["config"] = decoder_config
  
          if (
              kwargs_decoder["config"].is_decoder is False
              or kwargs_decoder["config"].add_cross_attention is False
          ):
              logger.warning(
                  f"Decoder model {decoder_pretrained_model_name_or_path} is not initialized as a decoder. "
                  f"In order to initialize {decoder_pretrained_model_name_or_path} as a decoder, "
                  "make sure that the attributes `is_decoder` and `add_cross_attention` of `decoder_config` "
                  "passed to `.from_encoder_decoder_pretrained(...)` are set to `True` or do not pass a "
                  "`decoder_config` to `.from_encoder_decoder_pretrained(...)`"
              )
  
          decoder = FlaxAutoModelForCausalLM.from_pretrained(
              decoder_pretrained_model_name_or_path, **kwargs_decoder
          )
  
      # instantiate config with corresponding kwargs
      dtype = kwargs.pop("dtype", jnp.float32)
      config = SpeechEncoderDecoderConfig.from_encoder_decoder_configs(
          encoder.config, decoder.config, **kwargs
      )
  
      # make sure input & output word embeddings are not tied
      config.tie_word_embeddings = False
  
      # init model
      model = cls(config, dtype=dtype)
      model.params["encoder"] = encoder.params
      model.params["decoder"] = decoder.params
  
      return model
  
imports: import os
  from typing import Optional, Tuple, Union
  import flax.linen
  import jax
  import jax.numpy
  from flax.core.frozen_dict import FrozenDict, freeze, unfreeze
  from flax.traverse_util import flatten_dict, unflatten_dict
  from jax import lax
  from jax.random import PRNGKey
  from ...modeling_flax_outputs import FlaxBaseModelOutput, FlaxCausalLMOutputWithCrossAttentions, FlaxSeq2SeqLMOutput
  from ...modeling_flax_utils import FlaxPreTrainedModel
  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_flax_auto import FlaxAutoModel, FlaxAutoModelForCausalLM
  from .configuration_speech_encoder_decoder import SpeechEncoderDecoderConfig
label_desc: Use image node_id 10 for calling the FlaxSpeechEncoderDecoderModel obj's underlying member method code with example usage: obj.from_encoder_decoder_pretrained(cls, encoder_pretrained_model_name_or_path, decoder_pretrained_model_name_or_path) and returns: model