

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"""



      A          =    VQModel
      A          =    "sample"
      @property
      def 			snake_case_      (   self    ,	_lowerCAmelCase=(32, 32)		):



          '''simple docstring'''
          lowerCAmelCase__   :List[Any]      							=				4
          lowerCAmelCase__   :Dict      							=				3

          lowerCAmelCase__   :Any      							=				floats_tensor((batch_size, num_channels) + sizes		).to(__a		)

          return {"sample": image}
      @property
      def 			snake_case_      (   self		):



          '''simple docstring'''
          return (3, 32, 32)
      @property
      def 			snake_case_      (   self		):



          '''simple docstring'''
          return (3, 32, 32)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				{
              "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__   :List[Any]      							=				self.dummy_input
          return init_dict, inputs_dict
      def 			snake_case_      (   self		):



          '''simple docstring'''
          pass
      def 			snake_case_      (   self		):



          '''simple docstring'''
          pass
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Any      							=				VQModel.from_pretrained("fusing/vqgan-dummy"    ,	output_loading_info=__a		)
          self.assertIsNotNone(__a		)
          self.assertEqual(len(loading_info["missing_keys"]		)    ,	0		)

          model.to(__a		)
          lowerCAmelCase__   :List[str]      							=				model(**self.dummy_input		)

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



      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Dict      							=				VQModel.from_pretrained("fusing/vqgan-dummy"		)
          model.to(__a		).eval()

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

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

          lowerCAmelCase__   :str      							=				output[0, -1, -3:, -3:].flatten().cpu()
          # fmt: off
          lowerCAmelCase__   :str      							=				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(__a    ,	__a    ,	atol=1e-3		)		)











def 				snake_case__							(							UpperCAmelCase							:  str       ):
    return "".join(chr(ord(UpperCAmelCase       ) - 3_2       ) if "a" <= char <= "z" else char for char in word       )


if __name__ == "__main__":
 from doctest import testmod

 testmod()



