


'''simple docstring'''



import collections
import inspect
import unittest

from transformers import SwinvaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import SwinvaForImageClassification, SwinvaForMaskedImageModeling, SwinvaModel
      from transformers.models.swinva.modeling_swinva import SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor





class    UpperCAmelCase_  :





    """simple docstring"""






    def __init__(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_=13			,     SCREAMING_SNAKE_CASE_=32			,     SCREAMING_SNAKE_CASE_=2			,     SCREAMING_SNAKE_CASE_=3			,     SCREAMING_SNAKE_CASE_=16			,     SCREAMING_SNAKE_CASE_=[1, 2, 1]			,     SCREAMING_SNAKE_CASE_=[2, 2, 4]			,     SCREAMING_SNAKE_CASE_=2			,     SCREAMING_SNAKE_CASE_=2.0			,     SCREAMING_SNAKE_CASE_=True			,     SCREAMING_SNAKE_CASE_=0.0			,     SCREAMING_SNAKE_CASE_=0.0			,     SCREAMING_SNAKE_CASE_=0.1			,     SCREAMING_SNAKE_CASE_="gelu"			,     SCREAMING_SNAKE_CASE_=False			,     SCREAMING_SNAKE_CASE_=True			,     SCREAMING_SNAKE_CASE_=0.0_2			,     SCREAMING_SNAKE_CASE_=1E-5			,     SCREAMING_SNAKE_CASE_=True			,     SCREAMING_SNAKE_CASE_=None			,     SCREAMING_SNAKE_CASE_=True			,     SCREAMING_SNAKE_CASE_=10			,     SCREAMING_SNAKE_CASE_=8			,     )				->     Optional[int]:
         __lowerCamelCase   :	Optional[int]								=		parent
         __lowerCamelCase   :	Union[str, Any]								=		batch_size
         __lowerCamelCase   :	Any								=		image_size
         __lowerCamelCase   :	List[Any]								=		patch_size
         __lowerCamelCase   :	int								=		num_channels
         __lowerCamelCase   :	int								=		embed_dim
         __lowerCamelCase   :	Dict								=		depths
         __lowerCamelCase   :	str								=		num_heads
         __lowerCamelCase   :	Optional[int]								=		window_size
         __lowerCamelCase   :	List[str]								=		mlp_ratio
         __lowerCamelCase   :	str								=		qkv_bias
         __lowerCamelCase   :	List[str]								=		hidden_dropout_prob
         __lowerCamelCase   :	Optional[int]								=		attention_probs_dropout_prob
         __lowerCamelCase   :	int								=		drop_path_rate
         __lowerCamelCase   :	Optional[int]								=		hidden_act
         __lowerCamelCase   :	int								=		use_absolute_embeddings
         __lowerCamelCase   :	Union[str, Any]								=		patch_norm
         __lowerCamelCase   :	int								=		layer_norm_eps
         __lowerCamelCase   :	Optional[Any]								=		initializer_range
         __lowerCamelCase   :	Union[str, Any]								=		is_training
         __lowerCamelCase   :	Dict								=		scope
         __lowerCamelCase   :	str								=		use_labels
         __lowerCamelCase   :	Union[str, Any]								=		type_sequence_label_size
         __lowerCamelCase   :	Dict								=		encoder_stride







    def       lowercase_				(							self	)				->     Optional[Any]:
         __lowerCamelCase   :	int								=		floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]	)

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

         __lowerCamelCase   :	Optional[Any]								=		self.get_config()

         return config, pixel_values, labels







    def       lowercase_				(							self	)				->     Optional[int]:
         return SwinvaConfig(
             image_size=self.image_size			,     patch_size=self.patch_size			,     num_channels=self.num_channels			,     embed_dim=self.embed_dim			,     depths=self.depths			,     num_heads=self.num_heads			,     window_size=self.window_size			,     mlp_ratio=self.mlp_ratio			,     qkv_bias=self.qkv_bias			,     hidden_dropout_prob=self.hidden_dropout_prob			,     attention_probs_dropout_prob=self.attention_probs_dropout_prob			,     drop_path_rate=self.drop_path_rate			,     hidden_act=self.hidden_act			,     use_absolute_embeddings=self.use_absolute_embeddings			,     path_norm=self.patch_norm			,     layer_norm_eps=self.layer_norm_eps			,     initializer_range=self.initializer_range			,     encoder_stride=self.encoder_stride			,     )







    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     str:
         __lowerCamelCase   :	Optional[int]								=		SwinvaModel(config=SCREAMING_SNAKE_CASE_	)
         model.to(SCREAMING_SNAKE_CASE_	)
         model.eval()
         __lowerCamelCase   :	int								=		model(SCREAMING_SNAKE_CASE_	)

         __lowerCamelCase   :	str								=		((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths	) - 1))
         __lowerCamelCase   :	int								=		int(config.embed_dim * 2 ** (len(config.depths	) - 1)	)

         self.parent.assertEqual(result.last_hidden_state.shape			,     (self.batch_size, expected_seq_len, expected_dim)	)







    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     List[str]:
         __lowerCamelCase   :	Optional[Any]								=		SwinvaForMaskedImageModeling(config=SCREAMING_SNAKE_CASE_	)
         model.to(SCREAMING_SNAKE_CASE_	)
         model.eval()
         __lowerCamelCase   :	Optional[int]								=		model(SCREAMING_SNAKE_CASE_	)
         self.parent.assertEqual(
             result.logits.shape			,     (self.batch_size, self.num_channels, self.image_size, self.image_size)	)

         # test greyscale images
         __lowerCamelCase   :	Any								=		1
         __lowerCamelCase   :	Optional[Any]								=		SwinvaForMaskedImageModeling(SCREAMING_SNAKE_CASE_	)
         model.to(SCREAMING_SNAKE_CASE_	)
         model.eval()

         __lowerCamelCase   :	Any								=		floats_tensor([self.batch_size, 1, self.image_size, self.image_size]	)
         __lowerCamelCase   :	Any								=		model(SCREAMING_SNAKE_CASE_	)
         self.parent.assertEqual(result.logits.shape			,     (self.batch_size, 1, self.image_size, self.image_size)	)







    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     Optional[Any]:
         __lowerCamelCase   :	Dict								=		self.type_sequence_label_size
         __lowerCamelCase   :	Any								=		SwinvaForImageClassification(SCREAMING_SNAKE_CASE_	)
         model.to(SCREAMING_SNAKE_CASE_	)
         model.eval()
         __lowerCamelCase   :	Dict								=		model(SCREAMING_SNAKE_CASE_			,     labels=SCREAMING_SNAKE_CASE_	)
         self.parent.assertEqual(result.logits.shape			,     (self.batch_size, self.type_sequence_label_size)	)







    def       lowercase_				(							self	)				->     List[str]:
         __lowerCamelCase   :	Dict								=		self.prepare_config_and_inputs()
         __lowerCamelCase				,       __lowerCamelCase				,       __lowerCamelCase   :	Optional[int]								=		config_and_inputs
         __lowerCamelCase   :	Union[str, Any]								=		{'pixel_values': pixel_values}
         return config, inputs_dict







@require_torch
class    UpperCAmelCase_  (_UpperCAmelCase					,		_UpperCAmelCase					,		unittest.TestCase  ):





    """simple docstring"""






    lowerCamelCase  :					int							     =			(
        (SwinvaModel, SwinvaForImageClassification, SwinvaForMaskedImageModeling) if is_torch_available() else ()
    )
    lowerCamelCase  :					int							     =			(
        {'feature-extraction': SwinvaModel, 'image-classification': SwinvaForImageClassification}
        if is_torch_available()
        else {}
    )

    lowerCamelCase  :					str							     =			False
    lowerCamelCase  :					List[str]							     =			False
    lowerCamelCase  :					Dict							     =			False
    lowerCamelCase  :					Tuple							     =			False







    def       lowercase_				(							self	)				->     Dict:
         __lowerCamelCase   :	Dict								=		SwinvaModelTester(self	)
         __lowerCamelCase   :	int								=		ConfigTester(self			,     config_class=SCREAMING_SNAKE_CASE_			,     embed_dim=37	)







    def       lowercase_				(							self	)				->     Union[str, Any]:
         self.config_tester.create_and_test_config_to_json_string()
         self.config_tester.create_and_test_config_to_json_file()
         self.config_tester.create_and_test_config_from_and_save_pretrained()
         self.config_tester.create_and_test_config_with_num_labels()
         self.config_tester.check_config_can_be_init_without_params()
         self.config_tester.check_config_arguments_init()







    def       lowercase_				(							self	)				->     Any:
         __lowerCamelCase   :	List[Any]								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE_	)







    @unittest.skip(reason='Got `CUDA error: misaligned address` with PyTorch 2.0.0.'	)
    def       lowercase_				(							self	)				->     List[Any]:
         pass







    @unittest.skip(reason='Swinv2 does not use inputs_embeds'	)
    def       lowercase_				(							self	)				->     Any:
         pass







    def       lowercase_				(							self	)				->     Union[str, Any]:
         __lowerCamelCase				,       __lowerCamelCase   :	Optional[int]								=		self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
              __lowerCamelCase   :	List[Any]								=		model_class(SCREAMING_SNAKE_CASE_	)
              self.assertIsInstance(model.get_input_embeddings()			,     (nn.Module)	)
              __lowerCamelCase   :	Dict								=		model.get_output_embeddings()
              self.assertTrue(x is None or isinstance(SCREAMING_SNAKE_CASE_			,     nn.Linear	)	)







    def       lowercase_				(							self	)				->     Union[str, Any]:
         __lowerCamelCase				,       __lowerCamelCase   :	Any								=		self.model_tester.prepare_config_and_inputs_for_common()

         for model_class in self.all_model_classes:
              __lowerCamelCase   :	int								=		model_class(SCREAMING_SNAKE_CASE_	)
              __lowerCamelCase   :	str								=		inspect.signature(model.forward	)
              # signature.parameters is an OrderedDict => so arg_names order is deterministic
              __lowerCamelCase   :	int								=		[*signature.parameters.keys()]

              __lowerCamelCase   :	Any								=		['pixel_values']
              self.assertListEqual(arg_names[:1]			,     SCREAMING_SNAKE_CASE_	)







    def       lowercase_				(							self	)				->     Tuple:
         __lowerCamelCase				,       __lowerCamelCase   :	str								=		self.model_tester.prepare_config_and_inputs_for_common()
         __lowerCamelCase   :	str								=		True

         for model_class in self.all_model_classes:
              __lowerCamelCase   :	Tuple								=		True
              __lowerCamelCase   :	Any								=		False
              __lowerCamelCase   :	int								=		True
              __lowerCamelCase   :	List[Any]								=		model_class(SCREAMING_SNAKE_CASE_	)
              model.to(SCREAMING_SNAKE_CASE_	)
              model.eval()
              with torch.no_grad():
                   __lowerCamelCase   :	int								=		model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)	)
              __lowerCamelCase   :	Dict								=		outputs.attentions
              __lowerCamelCase   :	Any								=		len(self.model_tester.depths	)
              self.assertEqual(len(SCREAMING_SNAKE_CASE_	)			,     SCREAMING_SNAKE_CASE_	)

              # check that output_attentions also work using config
              del inputs_dict["output_attentions"]
              __lowerCamelCase   :	str								=		True
              __lowerCamelCase   :	List[str]								=		config.window_size**2
              __lowerCamelCase   :	List[str]								=		model_class(SCREAMING_SNAKE_CASE_	)
              model.to(SCREAMING_SNAKE_CASE_	)
              model.eval()
              with torch.no_grad():
                   __lowerCamelCase   :	List[str]								=		model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)	)
              __lowerCamelCase   :	Any								=		outputs.attentions
              self.assertEqual(len(SCREAMING_SNAKE_CASE_	)			,     SCREAMING_SNAKE_CASE_	)

              self.assertListEqual(
                  list(attentions[0].shape[-3:]	)			,     [self.model_tester.num_heads[0], window_size_squared, window_size_squared]			,     )
              __lowerCamelCase   :	int								=		len(SCREAMING_SNAKE_CASE_	)

              # Check attention is always last and order is fine
              __lowerCamelCase   :	List[str]								=		True
              __lowerCamelCase   :	str								=		True
              __lowerCamelCase   :	Union[str, Any]								=		model_class(SCREAMING_SNAKE_CASE_	)
              model.to(SCREAMING_SNAKE_CASE_	)
              model.eval()
              with torch.no_grad():
                   __lowerCamelCase   :	str								=		model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)	)

              if hasattr(self.model_tester			,     'num_hidden_states_types'	):
                   __lowerCamelCase   :	str								=		self.model_tester.num_hidden_states_types
              else:
                   # also another +1 for reshaped_hidden_states
                   __lowerCamelCase   :	List[Any]								=		2
              self.assertEqual(out_len + added_hidden_states			,     len(SCREAMING_SNAKE_CASE_	)	)

              __lowerCamelCase   :	Tuple								=		outputs.attentions

              self.assertEqual(len(SCREAMING_SNAKE_CASE_	)			,     SCREAMING_SNAKE_CASE_	)

              self.assertListEqual(
                  list(self_attentions[0].shape[-3:]	)			,     [self.model_tester.num_heads[0], window_size_squared, window_size_squared]			,     )







    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     List[str]:
         __lowerCamelCase   :	Dict								=		model_class(SCREAMING_SNAKE_CASE_	)
         model.to(SCREAMING_SNAKE_CASE_	)
         model.eval()

         with torch.no_grad():
              __lowerCamelCase   :	Optional[Any]								=		model(**self._prepare_for_class(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)	)

         __lowerCamelCase   :	List[Any]								=		outputs.hidden_states

         __lowerCamelCase   :	Dict								=		getattr(
             self.model_tester			,     'expected_num_hidden_layers'			,     len(self.model_tester.depths	) + 1	)
         self.assertEqual(len(SCREAMING_SNAKE_CASE_	)			,     SCREAMING_SNAKE_CASE_	)

         # Swinv2 has a different seq_length
         __lowerCamelCase   :	str								=		(
             config.patch_size
             if isinstance(config.patch_size			,     collections.abc.Iterable	)
             else (config.patch_size, config.patch_size)
         )

         __lowerCamelCase   :	List[str]								=		(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

         self.assertListEqual(
             list(hidden_states[0].shape[-2:]	)			,     [num_patches, self.model_tester.embed_dim]			,     )

         __lowerCamelCase   :	Tuple								=		outputs.reshaped_hidden_states
         self.assertEqual(len(SCREAMING_SNAKE_CASE_	)			,     SCREAMING_SNAKE_CASE_	)

         __lowerCamelCase				,       __lowerCamelCase				,       __lowerCamelCase				,       __lowerCamelCase   :	List[Any]								=		reshaped_hidden_states[0].shape
         __lowerCamelCase   :	Optional[int]								=		(
             reshaped_hidden_states[0].view(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     height * width	).permute(0			,     2			,     1	)
         )
         self.assertListEqual(
             list(reshaped_hidden_states.shape[-2:]	)			,     [num_patches, self.model_tester.embed_dim]			,     )







    def       lowercase_				(							self	)				->     Dict:
         __lowerCamelCase				,       __lowerCamelCase   :	Tuple								=		self.model_tester.prepare_config_and_inputs_for_common()

         __lowerCamelCase   :	Any								=		(
             self.model_tester.image_size
             if isinstance(self.model_tester.image_size			,     collections.abc.Iterable	)
             else (self.model_tester.image_size, self.model_tester.image_size)
         )

         for model_class in self.all_model_classes:
              __lowerCamelCase   :	Tuple								=		True
              self.check_hidden_states_output(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)

              # check that output_hidden_states also work using config
              del inputs_dict["output_hidden_states"]
              __lowerCamelCase   :	int								=		True

              self.check_hidden_states_output(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)







    def       lowercase_				(							self	)				->     str:
         __lowerCamelCase				,       __lowerCamelCase   :	Optional[int]								=		self.model_tester.prepare_config_and_inputs_for_common()
         __lowerCamelCase   :	Optional[Any]								=		3

         __lowerCamelCase   :	Union[str, Any]								=		(
             self.model_tester.image_size
             if isinstance(self.model_tester.image_size			,     collections.abc.Iterable	)
             else (self.model_tester.image_size, self.model_tester.image_size)
         )
         __lowerCamelCase   :	Optional[Any]								=		(
             config.patch_size
             if isinstance(config.patch_size			,     collections.abc.Iterable	)
             else (config.patch_size, config.patch_size)
         )

         __lowerCamelCase   :	Tuple								=		image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
         __lowerCamelCase   :	Any								=		image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

         for model_class in self.all_model_classes:
              __lowerCamelCase   :	Union[str, Any]								=		True
              self.check_hidden_states_output(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     (padded_height, padded_width)	)

              # check that output_hidden_states also work using config
              del inputs_dict["output_hidden_states"]
              __lowerCamelCase   :	Tuple								=		True
              self.check_hidden_states_output(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     (padded_height, padded_width)	)







    def       lowercase_				(							self	)				->     List[str]:
         __lowerCamelCase   :	str								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_image_modeling(*SCREAMING_SNAKE_CASE_	)







    def       lowercase_				(							self	)				->     str:
         __lowerCamelCase   :	Any								=		self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE_	)







    @slow
    def       lowercase_				(							self	)				->     Dict:
         for model_name in SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              __lowerCamelCase   :	Optional[int]								=		SwinvaModel.from_pretrained(SCREAMING_SNAKE_CASE_	)
              self.assertIsNotNone(SCREAMING_SNAKE_CASE_	)







    def       lowercase_				(							self	)				->     Tuple:
         __lowerCamelCase				,       __lowerCamelCase   :	List[Any]								=		self.model_tester.prepare_config_and_inputs_for_common()

         __lowerCamelCase   :	Any								=		_config_zero_init(SCREAMING_SNAKE_CASE_	)
         for model_class in self.all_model_classes:
              __lowerCamelCase   :	str								=		model_class(config=SCREAMING_SNAKE_CASE_	)
              for name, param in model.named_parameters():
                   if "embeddings" not in name and "logit_scale" not in name and param.requires_grad:
                        self.assertIn(
                            ((param.data.mean() * 1E9).round() / 1E9).item()			,     [0.0, 1.0]			,     msg=f'Parameter {name} of model {model_class} seems not properly initialized'			,     )







@require_vision
@require_torch
class    UpperCAmelCase_  (unittest.TestCase  ):





    """simple docstring"""






    @cached_property
    def       lowercase_				(							self	)				->     Tuple:
         return (
             AutoImageProcessor.from_pretrained('microsoft/swinv2-tiny-patch4-window8-256'	)
             if is_vision_available()
             else None
         )







    @slow
    def       lowercase_				(							self	)				->     Optional[int]:
         __lowerCamelCase   :	List[str]								=		SwinvaForImageClassification.from_pretrained('microsoft/swinv2-tiny-patch4-window8-256'	).to(
             SCREAMING_SNAKE_CASE_	)
         __lowerCamelCase   :	Tuple								=		self.default_image_processor

         __lowerCamelCase   :	Optional[int]								=		Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'	)
         __lowerCamelCase   :	Optional[Any]								=		image_processor(images=SCREAMING_SNAKE_CASE_			,     return_tensors='pt'	).to(SCREAMING_SNAKE_CASE_	)

         # forward pass
         with torch.no_grad():
              __lowerCamelCase   :	str								=		model(**SCREAMING_SNAKE_CASE_	)

         # verify the logits
         __lowerCamelCase   :	Optional[Any]								=		torch.Size((1, 10_00)	)
         self.assertEqual(outputs.logits.shape			,     SCREAMING_SNAKE_CASE_	)
         __lowerCamelCase   :	str								=		torch.tensor([-0.3_9_4_7, -0.4_3_0_6, 0.0_0_2_6]	).to(SCREAMING_SNAKE_CASE_	)
         self.assertTrue(torch.allclose(outputs.logits[0, :3]			,     SCREAMING_SNAKE_CASE_			,     atol=1E-4	)	)










'''simple docstring'''



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    UpperCAmelCase_  (_UpperCAmelCase					,		_UpperCAmelCase					,		unittest.TestCase  ):





    """simple docstring"""






    lowerCamelCase  :					Union[str, Any]							     =			VQModel
    lowerCamelCase  :					Union[str, Any]							     =			'sample'







    @property
    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_=(32, 32)	)				->     Any:
         __lowerCamelCase   :	Tuple								=		4
         __lowerCamelCase   :	Union[str, Any]								=		3

         __lowerCamelCase   :	List[Any]								=		floats_tensor((batch_size, num_channels) + sizes	).to(SCREAMING_SNAKE_CASE_	)

         return {"sample": image}







    @property
    def       lowercase_				(							self	)				->     Optional[int]:
         return (3, 32, 32)







    @property
    def       lowercase_				(							self	)				->     List[Any]:
         return (3, 32, 32)







    def       lowercase_				(							self	)				->     Optional[int]:
         __lowerCamelCase   :	Optional[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,
         }
         __lowerCamelCase   :	Union[str, Any]								=		self.dummy_input
         return init_dict, inputs_dict







    def       lowercase_				(							self	)				->     str:
         pass







    def       lowercase_				(							self	)				->     Optional[int]:
         pass







    def       lowercase_				(							self	)				->     Any:
         __lowerCamelCase				,       __lowerCamelCase   :	Union[str, Any]								=		VQModel.from_pretrained('fusing/vqgan-dummy'			,     output_loading_info=SCREAMING_SNAKE_CASE_	)
         self.assertIsNotNone(SCREAMING_SNAKE_CASE_	)
         self.assertEqual(len(loading_info['missing_keys']	)			,     0	)

         model.to(SCREAMING_SNAKE_CASE_	)
         __lowerCamelCase   :	List[Any]								=		model(**self.dummy_input	)

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







    def       lowercase_				(							self	)				->     int:
         __lowerCamelCase   :	List[Any]								=		VQModel.from_pretrained('fusing/vqgan-dummy'	)
         model.to(SCREAMING_SNAKE_CASE_	).eval()

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

         __lowerCamelCase   :	List[str]								=		torch.randn(1			,     model.config.in_channels			,     model.config.sample_size			,     model.config.sample_size	)
         __lowerCamelCase   :	Optional[int]								=		image.to(SCREAMING_SNAKE_CASE_	)
         with torch.no_grad():
              __lowerCamelCase   :	int								=		model(SCREAMING_SNAKE_CASE_	).sample

         __lowerCamelCase   :	List[str]								=		output[0, -1, -3:, -3:].flatten().cpu()
         # fmt: off
         __lowerCamelCase   :	Union[str, Any]								=		torch.tensor([-0.0_1_5_3, -0.4_0_4_4, -0.1_8_8_0, -0.5_1_6_1, -0.2_4_1_8, -0.4_0_7_2, -0.1_6_1_2, -0.0_6_3_3, -0.0_1_4_3]	)
         # fmt: on
         self.assertTrue(torch.allclose(SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     atol=1E-3	)	)






