




"""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   a__					(						_SCREAMING_SNAKE_CASE				,     _SCREAMING_SNAKE_CASE				,     unittest.TestCase ):
			lowercase_		=						VQModel
			lowercase_		=						"sample"


			@property
			def    a_  (   self   :     Dict   ,	UpperCamelCase_   :     str=(32, 32)):


						"""simple docstring"""




						__UpperCAmelCase						:			Any												=       4
						__UpperCAmelCase						:			int												=       3

						__UpperCAmelCase						:			int												=       floats_tensor((batch_size, num_channels) + sizes).to(_lowerCAmelCase)

						return {"sample": image}


			@property
			def    a_  (   self   :     str):


						"""simple docstring"""




						return (3, 32, 32)


			@property
			def    a_  (   self   :     List[str]):


						"""simple docstring"""




						return (3, 32, 32)


			def    a_  (   self   :     Optional[Any]):


						"""simple docstring"""




						__UpperCAmelCase						:			List[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						:			List[str]												=       self.dummy_input
						return init_dict, inputs_dict


			def    a_  (   self   :     Tuple):


						"""simple docstring"""




						pass


			def    a_  (   self   :     List[str]):


						"""simple docstring"""




						pass


			def    a_  (   self   :     List[Any]):


						"""simple docstring"""




						__UpperCAmelCase						,  __UpperCAmelCase						:			List[str]												=       VQModel.from_pretrained("fusing/vqgan-dummy"   ,	output_loading_info=_lowerCAmelCase)
						self.assertIsNotNone(_lowerCAmelCase)
						self.assertEqual(len(loading_info["missing_keys"])   ,	0)

						model.to(_lowerCAmelCase)
						__UpperCAmelCase						:			Optional[int]												=       model(**self.dummy_input)

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


			def    a_  (   self   :     List[Any]):


						"""simple docstring"""




						__UpperCAmelCase						:			List[Any]												=       VQModel.from_pretrained("fusing/vqgan-dummy")
						model.to(_lowerCAmelCase).eval()

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

						__UpperCAmelCase						:			List[str]												=       torch.randn(1   ,	model.config.in_channels   ,	model.config.sample_size   ,	model.config.sample_size)
						__UpperCAmelCase						:			str												=       image.to(_lowerCAmelCase)
						with torch.no_grad():
									__UpperCAmelCase						:			Dict												=       model(_lowerCAmelCase).sample

						__UpperCAmelCase						:			Any												=       output[0, -1, -3:, -3:].flatten().cpu()
						# fmt: off
						__UpperCAmelCase						:			List[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(_lowerCAmelCase   ,	_lowerCAmelCase   ,	atol=1e-3))








def    UpperCAmelCase_				( __UpperCAmelCase		:      list     ,     __UpperCAmelCase		:      int     ,     __UpperCAmelCase		:      int = 0     ,     __UpperCAmelCase		:      int = 0				)   ->					int:
      SCREAMING_SNAKE_CASE_      		=     right or len(__UpperCAmelCase				) - 1
      if left > right:
            return -1
      elif list_data[left] == key:
            return left
      elif list_data[right] == key:
            return right
      else:
            return search(__UpperCAmelCase     ,     __UpperCAmelCase     ,     left + 1     ,     right - 1				)


if __name__ == "__main__":
   import doctest

   doctest.testmod()