code: def test_encoder_decoder_save_load_from_encoder_decoder_from_pt(self):
      config = self.get_encoder_decoder_config_small()
  
      # create two random ViT/GPT2 models for vit-gpt2 & initialize weights (+cross_attention weights)
      encoder_pt = ViTModel(config.encoder).to(torch_device).eval()
      decoder_pt = (
          GPT2LMHeadModel(config.decoder).to(torch_device).eval()
      )
  
      encoder_decoder_pt = (
          VisionEncoderDecoderModel(
              encoder=encoder_pt, decoder=decoder_pt
          )
          .to(torch_device)
          .eval()
      )
  
      pixel_values = floats_tensor(
          [
              13,
              encoder_pt.config.num_channels,
              encoder_pt.config.image_size,
              encoder_pt.config.image_size,
          ]
      )
      decoder_input_ids = ids_tensor(
          [13, 1], decoder_pt.config.vocab_size
      )
  
      pt_pixel_values = torch.tensor(
          pixel_values.numpy(), device=torch_device, dtype=torch.float
      )
      pt_decoder_input_ids = torch.tensor(
          decoder_input_ids.numpy(),
          device=torch_device,
          dtype=torch.long,
      )
  
      logits_pt = encoder_decoder_pt(
          pixel_values=pt_pixel_values,
          decoder_input_ids=pt_decoder_input_ids,
      ).logits
  
      # PyTorch => TensorFlow
      with tempfile.TemporaryDirectory() as tmp_dirname_1, tempfile.TemporaryDirectory() as tmp_dirname_2:
          encoder_decoder_pt.encoder.save_pretrained(tmp_dirname_1)
          encoder_decoder_pt.decoder.save_pretrained(tmp_dirname_2)
          encoder_decoder_tf = TFVisionEncoderDecoderModel.from_encoder_decoder_pretrained(
              tmp_dirname_1,
              tmp_dirname_2,
              encoder_from_pt=True,
              decoder_from_pt=True,
          )
  
      logits_tf = encoder_decoder_tf(
          pixel_values=pixel_values, decoder_input_ids=decoder_input_ids
      ).logits
  
      max_diff = np.max(
          np.abs(logits_pt.detach().cpu().numpy() - logits_tf.numpy())
      )
      self.assertAlmostEqual(max_diff, 0.0, places=3)
  
      # Make sure `from_pretrained` following `save_pretrained` work and give the same result
      # (See https://github.com/huggingface/transformers/pull/14016)
      with tempfile.TemporaryDirectory() as tmp_dirname:
          encoder_decoder_tf.save_pretrained(tmp_dirname)
          encoder_decoder_tf = (
              TFVisionEncoderDecoderModel.from_pretrained(tmp_dirname)
          )
  
          logits_tf_2 = encoder_decoder_tf(
              pixel_values=pixel_values,
              decoder_input_ids=decoder_input_ids,
          ).logits
  
          max_diff = np.max(
              np.abs(logits_tf_2.numpy() - logits_tf.numpy())
          )
          self.assertAlmostEqual(max_diff, 0.0, places=3)
  
imports: import copy
  import os
  import tempfile
  import unittest
  import numpy
  from transformers import is_tf_available, is_torch_available, is_vision_available
  from transformers.testing_utils import is_pt_tf_cross_test, require_tf, require_torch, require_vision, slow, torch_device
  from transformers.utils.generic import ModelOutput
  from ...test_modeling_tf_common import floats_tensor, ids_tensor
  from ..gpt2.test_modeling_tf_gpt2 import TFGPT2ModelTester
  from ..vit.test_modeling_tf_vit import TFViTModelTester
label_desc: Use image node_id 4 for calling the TFVisionEncoderDecoderModelSaveLoadTests obj's underlying member method code with example usage: obj.test_encoder_decoder_save_load_from_encoder_decoder_from_pt() without return types