from __future__ import annotations

import copy
import inspect
import json
import math
import os
import tempfile
import unittest
from importlib import import_module

import numpy as np

from transformers import ViTMAEConfig
from transformers.file_utils import cached_property, is_tf_available, is_vision_available
from transformers.testing_utils import require_tf, require_vision, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
  import tensorflow as tf

  from transformers import TFViTMAEForPreTraining, TFViTMAEModel


if is_vision_available():
  from PIL import Image

  from transformers import ViTImageProcessor




class 			__magic_name__	:





   """simple docstring"""




   def __init__(						self       :	List[str]		,	_lowercase       :	List[str]		,	_lowercase       :	Dict=13		,	_lowercase       :	str=30		,	_lowercase       :	int=2		,	_lowercase       :	Union[str, Any]=3		,	_lowercase       :	List[Any]=True		,	_lowercase       :	int=True		,	_lowercase       :	str=32		,	_lowercase       :	List[Any]=2		,	_lowercase       :	Dict=4		,	_lowercase       :	Union[str, Any]=37		,	_lowercase       :	Optional[int]="gelu"		,	_lowercase       :	Tuple=0.1		,	_lowercase       :	Dict=0.1		,	_lowercase       :	List[str]=10		,	_lowercase       :	Tuple=0.02		,	_lowercase       :	Tuple=3		,	_lowercase       :	List[Any]=0.6		,	_lowercase       :	Union[str, Any]=None		,	):



    """simple docstring"""



    _UpperCamelCase:  Optional[int]    						=			parent
    _UpperCamelCase:  Union[str, Any]    						=			batch_size
    _UpperCamelCase:  Optional[int]    						=			image_size
    _UpperCamelCase:  Tuple    						=			patch_size
    _UpperCamelCase:  Union[str, Any]    						=			num_channels
    _UpperCamelCase:  List[Any]    						=			is_training
    _UpperCamelCase:  List[str]    						=			use_labels
    _UpperCamelCase:  Dict    						=			hidden_size
    _UpperCamelCase:  int    						=			num_hidden_layers
    _UpperCamelCase:  List[str]    						=			num_attention_heads
    _UpperCamelCase:  Any    						=			intermediate_size
    _UpperCamelCase:  Union[str, Any]    						=			hidden_act
    _UpperCamelCase:  List[str]    						=			hidden_dropout_prob
    _UpperCamelCase:  Optional[Any]    						=			attention_probs_dropout_prob
    _UpperCamelCase:  Union[str, Any]    						=			type_sequence_label_size
    _UpperCamelCase:  Any    						=			initializer_range
    _UpperCamelCase:  Union[str, Any]    						=			mask_ratio
    _UpperCamelCase:  int    						=			scope

    # in ViTMAE, the expected sequence length = (num_patches + 1) * (1 - config.mask_ratio), rounded above
    # (we add 1 for the [CLS] token)
    _UpperCamelCase:  int    						=			(image_size // patch_size) ** 2
    _UpperCamelCase:  Optional[int]    						=			int(math.ceil((1 - mask_ratio) * (num_patches + 1)				)				)



   def 	lowerCAmelCase    (						self       :	str				):



    """simple docstring"""



    _UpperCamelCase:  Any    						=			floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]				)

    _UpperCamelCase:  Optional[int]    						=			None
    if self.use_labels:
     _UpperCamelCase:  int    						=			ids_tensor([self.batch_size]		,	self.type_sequence_label_size				)

    _UpperCamelCase:  List[Any]    						=			self.get_config()

    return config, pixel_values, labels



   def 	lowerCAmelCase    (						self       :	str				):



    """simple docstring"""



    return ViTMAEConfig(
        image_size=self.image_size		,	patch_size=self.patch_size		,	num_channels=self.num_channels		,	hidden_size=self.hidden_size		,	num_hidden_layers=self.num_hidden_layers		,	num_attention_heads=self.num_attention_heads		,	intermediate_size=self.intermediate_size		,	decoder_hidden_size=self.hidden_size		,	decoder_num_hidden_layers=self.num_hidden_layers		,	decoder_num_attention_heads=self.num_attention_heads		,	decoder_intermediate_size=self.intermediate_size		,	hidden_act=self.hidden_act		,	hidden_dropout_prob=self.hidden_dropout_prob		,	attention_probs_dropout_prob=self.attention_probs_dropout_prob		,	is_decoder=_lowercase		,	initializer_range=self.initializer_range		,	mask_ratio=self.mask_ratio		,	)



   def 	lowerCAmelCase    (						self       :	Union[str, Any]		,	_lowercase       :	Optional[int]		,	_lowercase       :	List[str]		,	_lowercase       :	Optional[int]				):



    """simple docstring"""



    _UpperCamelCase:  int    						=			TFViTMAEModel(config=_lowercase				)
    _UpperCamelCase:  Optional[int]    						=			model(_lowercase		,	training=_lowercase				)
    self.parent.assertEqual(result.last_hidden_state.shape		,	(self.batch_size, self.seq_length, self.hidden_size)				)



   def 	lowerCAmelCase    (						self       :	str		,	_lowercase       :	List[Any]		,	_lowercase       :	Any		,	_lowercase       :	Tuple				):



    """simple docstring"""



    _UpperCamelCase:  Dict    						=			TFViTMAEForPreTraining(_lowercase				)
    _UpperCamelCase:  Optional[int]    						=			model(_lowercase		,	training=_lowercase				)
    # expected sequence length = num_patches
    _UpperCamelCase:  Any    						=			(self.image_size // self.patch_size) ** 2
    _UpperCamelCase:  Any    						=			self.patch_size**2 * self.num_channels
    self.parent.assertEqual(result.logits.shape		,	(self.batch_size, num_patches, expected_num_channels)				)

    # test greyscale images
    _UpperCamelCase:  str    						=			1
    _UpperCamelCase:  str    						=			TFViTMAEForPreTraining(_lowercase				)

    _UpperCamelCase:  List[str]    						=			floats_tensor([self.batch_size, 1, self.image_size, self.image_size]				)
    _UpperCamelCase:  Optional[Any]    						=			model(_lowercase		,	training=_lowercase				)
    _UpperCamelCase:  int    						=			self.patch_size**2
    self.parent.assertEqual(result.logits.shape		,	(self.batch_size, num_patches, expected_num_channels)				)



   def 	lowerCAmelCase    (						self       :	str				):



    """simple docstring"""



    _UpperCamelCase:  int    						=			self.prepare_config_and_inputs()
    ((_UpperCamelCase)						,				(_UpperCamelCase)						,				(_UpperCamelCase)):  Optional[Any]    						=			config_and_inputs
    _UpperCamelCase:  int    						=			{'''pixel_values''': pixel_values}
    return config, inputs_dict




@require_tf
class 			__magic_name__	(		__a   ,						__a   ,						unittest.TestCase     ):





   """simple docstring"""




   lowerCAmelCase   :     str	      = (TFViTMAEModel, TFViTMAEForPreTraining) if is_tf_available() else ()
   lowerCAmelCase   :     int	      = {'''feature-extraction''': TFViTMAEModel} if is_tf_available() else {}

   lowerCAmelCase   :     Union[str, Any]	      = False
   lowerCAmelCase   :     Any	      = False
   lowerCAmelCase   :     Any	      = False
   lowerCAmelCase   :     Optional[Any]	      = False



   def 	lowerCAmelCase    (						self       :	List[str]				):



    """simple docstring"""



    _UpperCamelCase:  Optional[Any]    						=			TFViTMAEModelTester(self				)
    _UpperCamelCase:  List[Any]    						=			ConfigTester(self		,	config_class=_lowercase		,	has_text_modality=_lowercase		,	hidden_size=37				)



   def 	lowerCAmelCase    (						self       :	List[str]				):



    """simple docstring"""



    self.config_tester.run_common_tests()



   @unittest.skip(reason='''ViTMAE does not use inputs_embeds'''				)
   def 	lowerCAmelCase    (						self       :	Any				):



    """simple docstring"""



    pass



   def 	lowerCAmelCase    (						self       :	Optional[Any]				):



    """simple docstring"""



    _UpperCamelCase						,				_UpperCamelCase:  int    						=			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
     _UpperCamelCase:  Union[str, Any]    						=			model_class(_lowercase				)
     self.assertIsInstance(model.get_input_embeddings()		,	(tf.keras.layers.Layer)				)
     _UpperCamelCase:  Optional[Any]    						=			model.get_output_embeddings()
     self.assertTrue(x is None or isinstance(_lowercase		,	tf.keras.layers.Layer				)				)



   def 	lowerCAmelCase    (						self       :	Union[str, Any]				):



    """simple docstring"""



    _UpperCamelCase						,				_UpperCamelCase:  Dict    						=			self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
     _UpperCamelCase:  Union[str, Any]    						=			model_class(_lowercase				)
     _UpperCamelCase:  Optional[Any]    						=			inspect.signature(model.call				)
     # signature.parameters is an OrderedDict => so arg_names order is deterministic
     _UpperCamelCase:  Optional[Any]    						=			[*signature.parameters.keys()]

     _UpperCamelCase:  List[str]    						=			['''pixel_values''']
     self.assertListEqual(arg_names[:1]		,	_lowercase				)



   def 	lowerCAmelCase    (						self       :	Any				):



    """simple docstring"""



    _UpperCamelCase:  List[str]    						=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*_lowercase				)



   def 	lowerCAmelCase    (						self       :	str				):



    """simple docstring"""



    _UpperCamelCase:  List[str]    						=			self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_pretraining(*_lowercase				)



   def 	lowerCAmelCase    (						self       :	Optional[Any]				):



    """simple docstring"""



    np.random.seed(2				)

    _UpperCamelCase						,				_UpperCamelCase:  Any    						=			self.model_tester.prepare_config_and_inputs_for_common()

    _UpperCamelCase:  str    						=			int((config.image_size // config.patch_size) ** 2				)
    _UpperCamelCase:  Optional[Any]    						=			np.random.uniform(size=(self.model_tester.batch_size, num_patches)				)

    for model_class in self.all_model_classes:
     _UpperCamelCase:  Optional[Any]    						=			model_class(_lowercase				)
     _UpperCamelCase:  List[str]    						=			self._prepare_for_class(_lowercase		,	_lowercase				)

     _UpperCamelCase:  List[Any]    						=			model(_lowercase		,	noise=_lowercase				)

     _UpperCamelCase:  Optional[Any]    						=			copy.deepcopy(self._prepare_for_class(_lowercase		,	_lowercase				)				)
     _UpperCamelCase:  int    						=			model(**_lowercase		,	noise=_lowercase				)
     _UpperCamelCase:  List[Any]    						=			outputs_dict[0].numpy()
     _UpperCamelCase:  Dict    						=			outputs_keywords[0].numpy()

     self.assertLess(np.sum(np.abs(output_dict - output_keywords				)				)		,	1E-6				)



   def 	lowerCAmelCase    (						self       :	Tuple				):



    """simple docstring"""



    np.random.seed(2				)

    _UpperCamelCase						,				_UpperCamelCase:  Dict    						=			self.model_tester.prepare_config_and_inputs_for_common()

    _UpperCamelCase:  Any    						=			int((config.image_size // config.patch_size) ** 2				)
    _UpperCamelCase:  Optional[Any]    						=			np.random.uniform(size=(self.model_tester.batch_size, num_patches)				)

    def prepare_numpy_arrays(_lowercase       :	Dict				):
     _UpperCamelCase:  int    						=			{}
     for k, v in inputs_dict.items():
      if tf.is_tensor(_lowercase				):
       _UpperCamelCase:  Any    						=			v.numpy()
      else:
       _UpperCamelCase:  Optional[int]    						=			np.array(_lowercase				)

     return inputs_np_dict

    for model_class in self.all_model_classes:
     _UpperCamelCase:  Any    						=			model_class(_lowercase				)

     _UpperCamelCase:  int    						=			self._prepare_for_class(_lowercase		,	_lowercase				)
     _UpperCamelCase:  str    						=			prepare_numpy_arrays(_lowercase				)

     _UpperCamelCase:  Optional[int]    						=			model(_lowercase		,	noise=_lowercase				)
     _UpperCamelCase:  Optional[Any]    						=			model(**_lowercase		,	noise=_lowercase				)
     self.assert_outputs_same(_lowercase		,	_lowercase				)



   def 	lowerCAmelCase    (						self       :	Union[str, Any]		,	_lowercase       :	List[str]		,	_lowercase       :	Dict		,	_lowercase       :	str				):



    """simple docstring"""



    np.random.seed(2				)

    _UpperCamelCase:  List[Any]    						=			int((tf_model.config.image_size // tf_model.config.patch_size) ** 2				)
    _UpperCamelCase:  int    						=			np.random.uniform(size=(self.model_tester.batch_size, num_patches)				)
    _UpperCamelCase:  List[Any]    						=			tf.constant(_lowercase				)

    # Add `noise` argument.
    # PT inputs will be prepared in `super().check_pt_tf_models()` with this added `noise` argument
    _UpperCamelCase:  Any    						=			tf_noise

    super().check_pt_tf_models(_lowercase		,	_lowercase		,	_lowercase				)



   def 	lowerCAmelCase    (						self       :	int				):



    """simple docstring"""



    np.random.seed(2				)

    _UpperCamelCase						,				_UpperCamelCase:  str    						=			self.model_tester.prepare_config_and_inputs_for_common()

    _UpperCamelCase:  Union[str, Any]    						=			{
        module_member
        for model_class in self.all_model_classes
        for module in (import_module(model_class.__module__				),)
        for module_member_name in dir(_lowercase				)
        if module_member_name.endswith('''MainLayer'''				)
        # This condition is required, since `modeling_tf_clip.py` has 3 classes whose names end with `MainLayer`.
        and module_member_name[: -len('''MainLayer'''				)] == model_class.__name__[: -len('''Model'''				)]
        for module_member in (getattr(_lowercase		,	_lowercase				),)
        if isinstance(_lowercase		,	_lowercase				)
        and tf.keras.layers.Layer in module_member.__bases__
        and getattr(_lowercase		,	'''_keras_serializable'''		,	_lowercase				)
    }

    _UpperCamelCase:  Optional[int]    						=			int((config.image_size // config.patch_size) ** 2				)
    _UpperCamelCase:  Tuple    						=			np.random.uniform(size=(self.model_tester.batch_size, num_patches)				)
    _UpperCamelCase:  Tuple    						=			tf.convert_to_tensor(_lowercase				)
    inputs_dict.update({'''noise''': noise}				)

    for main_layer_class in tf_main_layer_classes:
     _UpperCamelCase:  Optional[int]    						=			main_layer_class(_lowercase				)

     _UpperCamelCase:  str    						=			{
         name: tf.keras.Input(tensor.shape[1:]		,	dtype=tensor.dtype				) for name, tensor in inputs_dict.items()
     }

     _UpperCamelCase:  int    						=			tf.keras.Model(_lowercase		,	outputs=main_layer(_lowercase				)				)
     _UpperCamelCase:  int    						=			model(_lowercase				)

     with tempfile.TemporaryDirectory() as tmpdirname:
      _UpperCamelCase:  List[str]    						=			os.path.join(_lowercase		,	'''keras_model.h5'''				)
      model.save(_lowercase				)
      _UpperCamelCase:  List[str]    						=			tf.keras.models.load_model(
          _lowercase		,	custom_objects={main_layer_class.__name__: main_layer_class}				)
      assert isinstance(_lowercase		,	tf.keras.Model				)
      _UpperCamelCase:  List[Any]    						=			model(_lowercase				)
      self.assert_outputs_same(_lowercase		,	_lowercase				)



   @slow
   def 	lowerCAmelCase    (						self       :	List[str]				):



    """simple docstring"""



    np.random.seed(2				)

    _UpperCamelCase						,				_UpperCamelCase:  Any    						=			self.model_tester.prepare_config_and_inputs_for_common()

    _UpperCamelCase:  int    						=			int((config.image_size // config.patch_size) ** 2				)
    _UpperCamelCase:  Union[str, Any]    						=			np.random.uniform(size=(self.model_tester.batch_size, num_patches)				)

    for model_class in self.all_model_classes:
     _UpperCamelCase:  str    						=			model_class(_lowercase				)
     _UpperCamelCase:  List[str]    						=			self._prepare_for_class(_lowercase		,	_lowercase				)
     _UpperCamelCase:  Union[str, Any]    						=			model(_lowercase		,	noise=_lowercase				)

     if model_class.__name__ == "TFViTMAEModel":
      _UpperCamelCase:  int    						=			outputs.last_hidden_state.numpy()
      _UpperCamelCase:  List[str]    						=			0
     else:
      _UpperCamelCase:  Optional[int]    						=			outputs.logits.numpy()
      _UpperCamelCase:  Dict    						=			0

     with tempfile.TemporaryDirectory() as tmpdirname:
      model.save_pretrained(_lowercase		,	saved_model=_lowercase				)
      _UpperCamelCase:  Dict    						=			model_class.from_pretrained(_lowercase				)
      _UpperCamelCase:  Optional[int]    						=			model(_lowercase		,	noise=_lowercase				)

      if model_class.__name__ == "TFViTMAEModel":
       _UpperCamelCase:  int    						=			after_outputs['''last_hidden_state'''].numpy()
       _UpperCamelCase:  int    						=			0
      else:
       _UpperCamelCase:  Dict    						=			after_outputs['''logits'''].numpy()
       _UpperCamelCase:  Union[str, Any]    						=			0

      _UpperCamelCase:  List[str]    						=			np.amax(np.abs(out_a - out_a				)				)
      self.assertLessEqual(_lowercase		,	1E-5				)



   def 	lowerCAmelCase    (						self       :	Optional[int]				):



    """simple docstring"""



    np.random.seed(2				)

    _UpperCamelCase						,				_UpperCamelCase:  Tuple    						=			self.model_tester.prepare_config_and_inputs_for_common()

    _UpperCamelCase:  Optional[Any]    						=			int((config.image_size // config.patch_size) ** 2				)
    _UpperCamelCase:  List[str]    						=			np.random.uniform(size=(self.model_tester.batch_size, num_patches)				)

    for model_class in self.all_model_classes:
     _UpperCamelCase:  str    						=			model_class(_lowercase				)
     _UpperCamelCase:  Optional[int]    						=			self._prepare_for_class(_lowercase		,	_lowercase				)

     _UpperCamelCase:  Dict    						=			model(_lowercase		,	noise=_lowercase				)
     _UpperCamelCase:  Optional[Any]    						=			model.get_config()
     # make sure that returned config is jsonifiable, which is required by keras
     json.dumps(_lowercase				)
     _UpperCamelCase:  Dict    						=			model_class.from_config(model.get_config()				)
     # make sure it also accepts a normal config
     _UpperCamelCase:  Union[str, Any]    						=			model_class.from_config(model.config				)
     _UpperCamelCase:  Optional[Any]    						=			new_model(_lowercase				)  # Build model
     new_model.set_weights(model.get_weights()				)
     _UpperCamelCase:  Optional[Any]    						=			new_model(_lowercase		,	noise=_lowercase				)

     self.assert_outputs_same(_lowercase		,	_lowercase				)



   @unittest.skip(
       reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load
    to get deterministic results.'''				)
   def 	lowerCAmelCase    (						self       :	Optional[Any]				):



    """simple docstring"""



    pass



   @unittest.skip(reason='''ViTMAE returns a random mask + ids_restore in each forward pass. See test_save_load'''				)
   def 	lowerCAmelCase    (						self       :	int				):



    """simple docstring"""



    pass



   @slow
   def 	lowerCAmelCase    (						self       :	List[str]				):



    """simple docstring"""



    _UpperCamelCase:  Tuple    						=			TFViTMAEModel.from_pretrained('''google/vit-base-patch16-224'''				)
    self.assertIsNotNone(_lowercase				)




def    lowerCAmelCase_  (		)     ->					Dict:







 '''simple docstring'''
 _UpperCamelCase:  Dict    						=			Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
 return image





@require_tf
@require_vision
class 			__magic_name__	(		unittest.TestCase     ):





   """simple docstring"""




   @cached_property
   def 	lowerCAmelCase    (						self       :	Tuple				):



    """simple docstring"""



    return ViTImageProcessor.from_pretrained('''facebook/vit-mae-base'''				) if is_vision_available() else None



   @slow
   def 	lowerCAmelCase    (						self       :	List[str]				):



    """simple docstring"""



    np.random.seed(2				)

    _UpperCamelCase:  int    						=			TFViTMAEForPreTraining.from_pretrained('''facebook/vit-mae-base'''				)

    _UpperCamelCase:  Tuple    						=			self.default_image_processor
    _UpperCamelCase:  List[str]    						=			prepare_img()
    _UpperCamelCase:  Tuple    						=			image_processor(images=_lowercase		,	return_tensors='''tf'''				)

    # prepare a noise vector that will be also used for testing the TF model
    # (this way we can ensure that the PT and TF models operate on the same inputs)
    _UpperCamelCase:  int    						=			ViTMAEConfig()
    _UpperCamelCase:  List[Any]    						=			int((vit_mae_config.image_size // vit_mae_config.patch_size) ** 2				)
    _UpperCamelCase:  Dict    						=			np.random.uniform(size=(1, num_patches)				)

    # forward pass
    _UpperCamelCase:  Optional[Any]    						=			model(**_lowercase		,	noise=_lowercase				)

    # verify the logits
    _UpperCamelCase:  Optional[int]    						=			tf.convert_to_tensor([1, 196, 768]				)
    self.assertEqual(outputs.logits.shape		,	_lowercase				)

    _UpperCamelCase:  int    						=			tf.convert_to_tensor(
        [[-0.0548, -1.7023, -0.9325], [0.3721, -0.5670, -0.2233], [0.8235, -1.3878, -0.3524]]				)

    tf.debugging.assert_near(outputs.logits[0, :3, :3]		,	_lowercase		,	atol=1E-4				)
import unittest

import torch

from diffusers import VQModel
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()




class 			__magic_name__	(		__a   ,						__a   ,						unittest.TestCase     ):





   """simple docstring"""




   lowerCAmelCase   :     Dict	      = VQModel
   lowerCAmelCase   :     List[str]	      = '''sample'''



   @property
   def 	lowerCAmelCase    (						self       :	List[Any]		,	_lowercase       :	Tuple=(32, 32)				):



    """simple docstring"""



    _UpperCamelCase:  List[Any]    						=			4
    _UpperCamelCase:  Tuple    						=			3

    _UpperCamelCase:  List[str]    						=			floats_tensor((batch_size, num_channels) + sizes				).to(_lowercase				)

    return {"sample": image}



   @property
   def 	lowerCAmelCase    (						self       :	List[Any]				):



    """simple docstring"""



    return (3, 32, 32)



   @property
   def 	lowerCAmelCase    (						self       :	str				):



    """simple docstring"""



    return (3, 32, 32)



   def 	lowerCAmelCase    (						self       :	Optional[int]				):



    """simple docstring"""



    _UpperCamelCase:  Any    						=			{
        '''block_out_channels''': [32, 64],
        '''in_channels''': 3,
        '''out_channels''': 3,
        '''down_block_types''': ['''DownEncoderBlock2D''', '''DownEncoderBlock2D'''],
        '''up_block_types''': ['''UpDecoderBlock2D''', '''UpDecoderBlock2D'''],
        '''latent_channels''': 3,
    }
    _UpperCamelCase:  Optional[Any]    						=			self.dummy_input
    return init_dict, inputs_dict



   def 	lowerCAmelCase    (						self       :	List[Any]				):



    """simple docstring"""



    pass



   def 	lowerCAmelCase    (						self       :	List[Any]				):



    """simple docstring"""



    pass



   def 	lowerCAmelCase    (						self       :	Optional[Any]				):



    """simple docstring"""



    _UpperCamelCase						,				_UpperCamelCase:  int    						=			VQModel.from_pretrained('''fusing/vqgan-dummy'''		,	output_loading_info=_lowercase				)
    self.assertIsNotNone(_lowercase				)
    self.assertEqual(len(loading_info['''missing_keys''']				)		,	0				)

    model.to(_lowercase				)
    _UpperCamelCase:  Tuple    						=			model(**self.dummy_input				)

    assert image is not None, "Make sure output is not None"



   def 	lowerCAmelCase    (						self       :	Optional[Any]				):



    """simple docstring"""



    _UpperCamelCase:  Dict    						=			VQModel.from_pretrained('''fusing/vqgan-dummy'''				)
    model.to(_lowercase				).eval()

    torch.manual_seed(0				)
    if torch.cuda.is_available():
     torch.cuda.manual_seed_all(0				)

    _UpperCamelCase:  int    						=			torch.randn(1		,	model.config.in_channels		,	model.config.sample_size		,	model.config.sample_size				)
    _UpperCamelCase:  Tuple    						=			image.to(_lowercase				)
    with torch.no_grad():
     _UpperCamelCase:  Optional[int]    						=			model(_lowercase				).sample

    _UpperCamelCase:  List[Any]    						=			output[0, -1, -3:, -3:].flatten().cpu()
    # fmt: off
    _UpperCamelCase:  Any    						=			torch.tensor([-0.0153, -0.4044, -0.1880, -0.5161, -0.2418, -0.4072, -0.1612, -0.0633, -0.0143]				)
    # fmt: on
    self.assertTrue(torch.allclose(_lowercase		,	_lowercase		,	atol=1E-3				)				)