class_docstr: [`TFVisionEncoderDecoderModel`] is a generic model class that will be instantiated as a transformer architecture
  with one of the base vision model classes of the library as encoder and another one of the base model classes 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: ["[","`","TFVisionEncoderDecoderModel","`","]","is","a","generic","model","class","that","will","be","instantiated","as","a","transformer","architecture","with","one","of","the","base","vision","model","classes","of","the","library","as","encoder","and","another","one","of","the","base","model","classes","as","decoder","when","created","with","the","[","`","~TFAutoModel.from_pretrained","`","]","class","method","for","the","encoder","and","[","`","~TFAutoModelForCausalLM.from_pretrained","`","]","class","method","for","the","decoder","."]
docstr: Example:
  
  ```python
  >>> from transformers import TFVisionEncoderDecoderModel, ViTFeatureExtractor, GPT2Tokenizer
  >>> from PIL import Image
  >>> import requests
  
  >>> feature_extractor = ViTFeatureExtractor.from_pretrained("ydshieh/vit-gpt2-coco-en")
  >>> decoder_tokenizer = GPT2Tokenizer.from_pretrained("ydshieh/vit-gpt2-coco-en")
  >>> model = TFVisionEncoderDecoderModel.from_pretrained("ydshieh/vit-gpt2-coco-en")
  
  >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
  >>> img = Image.open(requests.get(url, stream=True).raw)
  >>> pixel_values = feature_extractor(images=img, return_tensors="tf").pixel_values  # Batch size 1
  
  >>> output_ids = model.generate(
  ...     pixel_values, max_length=16, num_beams=4, return_dict_in_generate=True
  ... ).sequences
  
  >>> preds = decoder_tokenizer.batch_decode(output_ids, skip_special_tokens=True)
  >>> preds = [pred.strip() for pred in preds]
  
  >>> assert preds == ["a cat laying on top of a couch next to another cat"]
  ```
docstr_tok: ["Example",":","``","`","python",">",">",">","from","transformers","import","TFVisionEncoderDecoderModel",",","ViTFeatureExtractor",",","GPT2Tokenizer",">",">",">","from","PIL","import","Image",">",">",">","import","requests",">",">",">","feature_extractor","=","ViTFeatureExtractor.from_pretrained","(","``","ydshieh\/vit-gpt2-coco-en","''",")",">",">",">","decoder_tokenizer","=","GPT2Tokenizer.from_pretrained","(","``","ydshieh\/vit-gpt2-coco-en","''",")",">",">",">","model","=","TFVisionEncoderDecoderModel.from_pretrained","(","``","ydshieh\/vit-gpt2-coco-en","''",")",">",">",">","url","=","``","http",":","\/\/images.cocodataset.org\/val2017\/000000039769.jpg","''",">",">",">","img","=","Image.open","(","requests.get","(","url",",","stream=True",")",".raw",")",">",">",">","pixel_values","=","feature_extractor","(","images=img",",","return_tensors=","''","tf","''",")",".pixel_values","#","Batch","size","1",">",">",">","output_ids","=","model.generate","(","...","pixel_values",",","max_length=16",",","num_beams=4",",","return_dict_in_generate=True","...",")",".sequences",">",">",">","preds","=","decoder_tokenizer.batch_decode","(","output_ids",",","skip_special_tokens=True",")",">",">",">","preds","=","[","pred.strip","(",")","for","pred","in","preds","]",">",">",">","assert","preds","==","[","``","a","cat","laying","on","top","of","a","couch","next","to","another","cat","''","]","``","`"]
code: def from_pretrained(
      cls, pretrained_model_name_or_path, *model_args, **kwargs
  ):
      r"""
      Example:
  
      ```python
      >>> from transformers import TFVisionEncoderDecoderModel, ViTFeatureExtractor, GPT2Tokenizer
      >>> from PIL import Image
      >>> import requests
  
      >>> feature_extractor = ViTFeatureExtractor.from_pretrained("ydshieh/vit-gpt2-coco-en")
      >>> decoder_tokenizer = GPT2Tokenizer.from_pretrained("ydshieh/vit-gpt2-coco-en")
      >>> model = TFVisionEncoderDecoderModel.from_pretrained("ydshieh/vit-gpt2-coco-en")
  
      >>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
      >>> img = Image.open(requests.get(url, stream=True).raw)
      >>> pixel_values = feature_extractor(images=img, return_tensors="tf").pixel_values  # Batch size 1
  
      >>> output_ids = model.generate(
      ...     pixel_values, max_length=16, num_beams=4, return_dict_in_generate=True
      ... ).sequences
  
      >>> preds = decoder_tokenizer.batch_decode(output_ids, skip_special_tokens=True)
      >>> preds = [pred.strip() for pred in preds]
  
      >>> assert preds == ["a cat laying on top of a couch next to another cat"]
      ```"""
  
      from_pt = kwargs.pop("from_pt", False)
      if from_pt:
          import torch
  
          from transformers import VisionEncoderDecoderModel
  
          # a workaround to load from pytorch checkpoint
          _model = VisionEncoderDecoderModel.from_pretrained(
              pretrained_model_name_or_path, *model_args, **kwargs
          )
          config = _model.config
  
          with tempfile.TemporaryDirectory() as tmpdirname:
              encoder_dir = os.path.join(tmpdirname, "encoder")
              decoder_dir = os.path.join(tmpdirname, "decoder")
              _model.encoder.save_pretrained(encoder_dir)
              _model.decoder.save_pretrained(decoder_dir)
  
              if hasattr(_model, "enc_to_dec_proj"):
                  enc_to_dec_proj_kernel = tf.transpose(
                      tf.constant(
                          _model.enc_to_dec_proj.weight.detach()
                          .to("cpu")
                          .numpy()
                      ),
                      perm=(1, 0),
                  )
                  enc_to_dec_proj_bias = tf.constant(
                      _model.enc_to_dec_proj.bias.detach()
                      .to("cpu")
                      .numpy()
                  )
  
              del _model
              gc.collect()
              torch.cuda.empty_cache()
  
              model = TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
                  encoder_dir,
                  decoder_dir,
                  encoder_from_pt=True,
                  decoder_from_pt=True,
              )
              # This is only for copying some specific attributes of this particular model.
              model.config = config
  
              if hasattr(model, "enc_to_dec_proj"):
                  model(model.dummy_inputs)
                  model.enc_to_dec_proj.kernel.assign(
                      enc_to_dec_proj_kernel
                  )
                  model.enc_to_dec_proj.bias.assign(
                      enc_to_dec_proj_bias
                  )
  
              return model
  
      return super().from_pretrained(
          pretrained_model_name_or_path, *model_args, **kwargs
      )
  
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_vision_encoder_decoder import VisionEncoderDecoderConfig
label_desc: Use image node_id 8 for calling the TFVisionEncoderDecoderModel obj's underlying member method code with example usage: obj.from_pretrained(cls, pretrained_model_name_or_path) and returns: super, model