


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__       (					A_   ,  A_   ,  unittest.TestCase		):



    """simple docstring"""






    UpperCAmelCase__						:		Dict      =  VQModel
    UpperCAmelCase__						:		Union[str, Any]      =  "sample"






    @property
    def _a					(			self					,   A_=(32, 32)    )  ->       Dict:
         __UpperCamelCase    							=4
         __UpperCamelCase    							=3

         __UpperCamelCase    							=floats_tensor((batch_size, num_channels) + sizes    ).to(A_    )

         return {"sample": image}






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






    @property
    def _a					(			self    )  ->       int:
         return (3, 32, 32)






    def _a					(			self    )  ->       List[Any]:
         __UpperCamelCase    							={
             '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    							=self.dummy_input
         return init_dict, inputs_dict






    def _a					(			self    )  ->       List[str]:
         pass






    def _a					(			self    )  ->       Union[str, Any]:
         pass






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

         model.to(A_    )
         __UpperCamelCase    							=model(**self.dummy_input    )

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






    def _a					(			self    )  ->       Dict:
         __UpperCamelCase    							=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    )

         __UpperCamelCase    							=torch.randn(1					,   model.config.in_channels					,   model.config.sample_size					,   model.config.sample_size    )
         __UpperCamelCase    							=image.to(A_    )
         with torch.no_grad():
              __UpperCamelCase    							=model(A_    ).sample

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











"""simple docstring"""






lowercase__     						=						{
    """meter""": """m""",
    """kilometer""": """km""",
    """megametre""": """Mm""",
    """gigametre""": """Gm""",
    """terametre""": """Tm""",
    """petametre""": """Pm""",
    """exametre""": """Em""",
    """zettametre""": """Zm""",
    """yottametre""": """Ym""",
}
# Exponent of the factor(meter)
lowercase__     						=						{
    """m""": 0,
    """km""": 3,
    """Mm""": 6,
    """Gm""": 9,
    """Tm""": 12,
    """Pm""": 15,
    """Em""": 18,
    """Zm""": 21,
    """Ym""": 24,
}







def      _snake_case			(				lowercase__							,    lowercase__							,    lowercase__		):
				_lowerCamelCase     :			List[Any]    =    from_type.lower().strip('s'		)
				_lowerCamelCase     :			List[Any]    =    to_type.lower().strip('s'		)

				_lowerCamelCase     :			Optional[int]    =    UNIT_SYMBOL.get(lowercase__							,    lowercase__		)
				_lowerCamelCase     :			Any    =    UNIT_SYMBOL.get(lowercase__							,    lowercase__		)

				if from_sanitized not in METRIC_CONVERSION:
								_lowerCamelCase     :			Tuple    =    (
								    f'''Invalid \'from_type\' value: {from_type!r}.\n'''
								    f'''Conversion abbreviations are: {', '.join(lowercase__		)}'''
								)
								raise ValueError(lowercase__		)
				if to_sanitized not in METRIC_CONVERSION:
								_lowerCamelCase     :			Any    =    (
								    f'''Invalid \'to_type\' value: {to_type!r}.\n'''
								    f'''Conversion abbreviations are: {', '.join(lowercase__		)}'''
								)
								raise ValueError(lowercase__		)
				_lowerCamelCase     :			List[Any]    =    METRIC_CONVERSION[from_sanitized]
				_lowerCamelCase     :			int    =    METRIC_CONVERSION[to_sanitized]
				_lowerCamelCase     :			List[str]    =    1

				if from_exponent > to_exponent:
								_lowerCamelCase     :			List[str]    =    from_exponent - to_exponent
				else:
								_lowerCamelCase     :			List[Any]    =    -(to_exponent - from_exponent)

				return value * pow(10							,    lowercase__		)


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

			testmod()