class_docstr: [`EncoderDecoderModel`] 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: ["[","`","EncoderDecoderModel","`","]","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","."]
docstr: Example:
  
  ```python
  >>> from transformers import EncoderDecoderModel
  
  >>> model = EncoderDecoderModel.from_pretrained("patrickvonplaten/bert2bert-cnn_dailymail-fp16")
  ```
docstr_tok: ["Example",":","``","`","python",">",">",">","from","transformers","import","EncoderDecoderModel",">",">",">","model","=","EncoderDecoderModel.from_pretrained","(","``","patrickvonplaten\/bert2bert-cnn_dailymail-fp16","''",")","``","`"]
code: def from_pretrained(
      cls, pretrained_model_name_or_path, *model_args, **kwargs
  ):
      r"""
      Example:
  
      ```python
      >>> from transformers import EncoderDecoderModel
  
      >>> model = EncoderDecoderModel.from_pretrained("patrickvonplaten/bert2bert-cnn_dailymail-fp16")
      ```"""
  
      from_tf = kwargs.pop("from_tf", False)
      if from_tf:
          from transformers import TFEncoderDecoderModel
  
          # a workaround to load from tensorflow checkpoint
          # Using `_tf_model` won't work, because the weight names in the encoder/decoder of `_tf_model` get
          # extended before saving those components. For example, The name of `_tf_model.encoder.vit` is
          # `[top model name]/encoder/vit`, but the name of `tf_model.encoder.vit` is `[top model name]/vit`. The
          # [top model name] is handled (stripped) by the conversion method, and the former case gets extra `encoder`,
          # which should not occur when we want to save the components alone.
          # There was a (very) ugly potential fix, which wasn't integrated to `transformers`: see
          #   https://github.com/huggingface/transformers/pull/13222/commits/dbb3c9de76eee235791d2064094654637c99f36d#r697304245
          #   (the change in `src/transformers/modeling_tf_utils.py`)
          _tf_model = TFEncoderDecoderModel.from_pretrained(
              pretrained_model_name_or_path, *model_args, **kwargs
          )
          config = _tf_model.config
  
          # Using `tf_model` instead
          encoder = _tf_model.encoder.__class__(
              _tf_model.config.encoder
          )
          decoder = _tf_model.decoder.__class__(
              _tf_model.config.decoder
          )
          # Make sure models are built
          encoder(encoder.dummy_inputs)
          decoder(decoder.dummy_inputs)
  
          # Get the variable correspondence between `_tf_model` and `encoder` and `decoder`
          encoder_variables = {}
          for v in (
              encoder.trainable_variables
              + encoder.non_trainable_variables
          ):
              encoder_variables["/".join(v.name.split("/")[1:])] = v
          decoder_variables = {}
          for v in (
              decoder.trainable_variables
              + decoder.non_trainable_variables
          ):
              decoder_variables["/".join(v.name.split("/")[1:])] = v
  
          _encoder_variables = {}
          for v in (
              _tf_model.encoder.trainable_variables
              + _tf_model.encoder.non_trainable_variables
          ):
              _encoder_variables["/".join(v.name.split("/")[2:])] = v
          _decoder_variables = {}
          for v in (
              _tf_model.decoder.trainable_variables
              + _tf_model.decoder.non_trainable_variables
          ):
              _decoder_variables["/".join(v.name.split("/")[2:])] = v
  
          # assign weight values to `encoder` and `decoder` from `_tf_model`
          for name, v in encoder_variables.items():
              v.assign(_encoder_variables[name])
          for name, v in decoder_variables.items():
              v.assign(_decoder_variables[name])
  
          tf_model = TFEncoderDecoderModel(
              encoder=encoder, decoder=decoder
          )
  
          # Deal with `enc_to_dec_proj`
          if hasattr(_tf_model, "enc_to_dec_proj"):
              tf_model(tf_model.dummy_inputs)
              tf_model.enc_to_dec_proj.kernel.assign(
                  _tf_model.enc_to_dec_proj.kernel
              )
              tf_model.enc_to_dec_proj.bias.assign(
                  _tf_model.enc_to_dec_proj.bias
              )
  
          with tempfile.TemporaryDirectory() as tmpdirname:
              encoder_dir = os.path.join(tmpdirname, "encoder")
              decoder_dir = os.path.join(tmpdirname, "decoder")
              tf_model.encoder.save_pretrained(encoder_dir)
              tf_model.decoder.save_pretrained(decoder_dir)
  
              if hasattr(tf_model, "enc_to_dec_proj"):
                  enc_to_dec_proj_weight = torch.transpose(
                      torch.from_numpy(
                          tf_model.enc_to_dec_proj.kernel.numpy()
                      ),
                      1,
                      0,
                  )
                  enc_to_dec_proj_bias = torch.from_numpy(
                      tf_model.enc_to_dec_proj.bias.numpy()
                  )
  
              del _tf_model
              del tf_model
              gc.collect()
  
              model = (
                  EncoderDecoderModel.from_encoder_decoder_pretrained(
                      encoder_dir,
                      decoder_dir,
                      encoder_from_tf=True,
                      decoder_from_tf=True,
                  )
              )
              # This is only for copying some specific attributes of this particular model.
              model.config = config
  
              if hasattr(model, "enc_to_dec_proj"):
                  model.enc_to_dec_proj.weight.data = (
                      enc_to_dec_proj_weight.contiguous()
                  )
                  model.enc_to_dec_proj.bias.data = (
                      enc_to_dec_proj_bias.contiguous()
                  )
  
              return model
  
      # At the moment fast initialization is not supported for composite models
      if kwargs.get("_fast_init", False):
          logger.warning(
              "Fast initialization is currently not supported for EncoderDecoderModel. "
              "Falling back to slow initialization..."
          )
      kwargs["_fast_init"] = False
  
      return super().from_pretrained(
          pretrained_model_name_or_path, *model_args, **kwargs
      )
  
imports: import gc
  import inspect
  import os
  import tempfile
  import warnings
  from typing import Optional, Tuple, Union
  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_encoder_decoder import EncoderDecoderConfig
label_desc: Use image node_id 8 for calling the EncoderDecoderModel obj's underlying member method code with example usage: obj.from_pretrained(cls, pretrained_model_name_or_path) and returns: super, model