
'''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     ):
	snake_case__   :Optional[Any]   =  VQModel
	snake_case__   :str   =  'sample'





	@property
	def 				__SCREAMING_SNAKE_CASE	(       self      :							Dict   ,				__magic_name__      :							Dict=(32, 32)				):


				"""simple docstring"""

				lowerCAmelCase__										=				4
				lowerCAmelCase__										=				3

				lowerCAmelCase__										=				floats_tensor((batch_size, num_channels) + sizes				).to(__magic_name__				)

				return {"sample": image}





	@property
	def 				__SCREAMING_SNAKE_CASE	(       self      :							str				):


				"""simple docstring"""

				return (3, 32, 32)





	@property
	def 				__SCREAMING_SNAKE_CASE	(       self      :							Any				):


				"""simple docstring"""

				return (3, 32, 32)





	def 				__SCREAMING_SNAKE_CASE	(       self      :							List[str]				):


				"""simple docstring"""

				lowerCAmelCase__										=				{
				    "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__										=				self.dummy_input
				return init_dict, inputs_dict





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Any				):


				"""simple docstring"""

				pass





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Tuple				):


				"""simple docstring"""

				pass





	def 				__SCREAMING_SNAKE_CASE	(       self      :							Any				):


				"""simple docstring"""

				lowerCAmelCase__						,lowerCAmelCase__										=				VQModel.from_pretrained("fusing/vqgan-dummy"   ,				output_loading_info=__magic_name__				)
				self.assertIsNotNone(__magic_name__				)
				self.assertEqual(len(loading_info["missing_keys"]				)   ,				0				)

				model.to(__magic_name__				)
				lowerCAmelCase__										=				model(**self.dummy_input				)

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







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


				"""simple docstring"""

				lowerCAmelCase__										=				VQModel.from_pretrained("fusing/vqgan-dummy"				)
				model.to(__magic_name__				).eval()

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

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

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












"""simple docstring"""




def  _SCREAMING_SNAKE_CASE						(      _lowercase		:       list[int]   )					->float:






	'''simple docstring'''






	if not nums:  # Makes sure that the list is not empty
		raise ValueError("List is empty"   )

	a :						Dict      =							sum(_lowercase   ) / len(_lowercase   )  # Calculate the average
	return sum(abs(x - average   ) for x in nums   ) / len(_lowercase   )


if __name__ == "__main__":
		import doctest

		doctest.testmod()


