


"""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     (snake_case__						,		snake_case__						,		unittest.TestCase):





							'''simple docstring'''

							__lowercase:		str							      =    VQModel
							__lowercase:		Union[str, Any]							      =    """sample"""



							@property
							def 		lowerCAmelCase       (				self							:      List[str]		,       UpperCAmelCase_							:      List[str]=(32, 32)       )					->Tuple:



														"""simple docstring"""



														snake_case_           =		4
														snake_case_           =		3

														snake_case_           =		floats_tensor((batch_size, num_channels) + sizes       ).to(UpperCAmelCase_       )

														return {"sample": image}



							@property
							def 		lowerCAmelCase       (				self							:      Tuple       )					->str:



														"""simple docstring"""



														return (3, 32, 32)



							@property
							def 		lowerCAmelCase       (				self							:      List[Any]       )					->Any:



														"""simple docstring"""



														return (3, 32, 32)



							def 		lowerCAmelCase       (				self							:      Optional[int]       )					->Dict:



														"""simple docstring"""



														snake_case_           =		{
														    """block_out_channels""": [32, 64],
														    """in_channels""": 3,
														    """out_channels""": 3,
														    """down_block_types""": ["""DownEncoderBlock2D""", """DownEncoderBlock2D"""],
														    """up_block_types""": ["""UpDecoderBlock2D""", """UpDecoderBlock2D"""],
														    """latent_channels""": 3,
														}
														snake_case_           =		self.dummy_input
														return init_dict, inputs_dict



							def 		lowerCAmelCase       (				self							:      List[str]       )					->Dict:



														"""simple docstring"""



														pass



							def 		lowerCAmelCase       (				self							:      Optional[Any]       )					->List[str]:



														"""simple docstring"""



														pass



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



														"""simple docstring"""



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

														model.to(UpperCAmelCase_       )
														snake_case_           =		model(**self.dummy_input       )

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



							def 		lowerCAmelCase       (				self							:      Tuple       )					->Optional[Any]:



														"""simple docstring"""



														snake_case_           =		VQModel.from_pretrained("""fusing/vqgan-dummy"""       )
														model.to(UpperCAmelCase_       ).eval()

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

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

														snake_case_           =		output[0, -1, -3:, -3:].flatten().cpu()
														# fmt: off
														snake_case_           =		torch.tensor([-0.0_153, -0.4_044, -0.1_880, -0.5_161, -0.2_418, -0.4_072, -0.1_612, -0.0_633, -0.0_143]       )
														# fmt: on
														self.assertTrue(torch.allclose(UpperCAmelCase_		,       UpperCAmelCase_		,       atol=1E-3       )       )







"""simple docstring"""
def 						_a				(      _SCREAMING_SNAKE_CASE				)    ->				list:

							# bit count represents no. of bits in the gray code
							if bit_count < 0:
														raise ValueError("""The given input must be positive"""				)

							# get the generated string sequence
							snake_case_           =		gray_code_sequence_string(_SCREAMING_SNAKE_CASE				)
							#
							# convert them to integers
							for i in range(len(_SCREAMING_SNAKE_CASE				)				):
														snake_case_           =		int(sequence[i]				, 2				)

							return sequence







def 						_a				(      _SCREAMING_SNAKE_CASE				)    ->				list:

							# The approach is a recursive one
							# Base case achieved when either n = 0 or n=1
							if bit_count == 0:
														return ["0"]

							if bit_count == 1:
														return ["0", "1"]

							snake_case_           =		1 << bit_count  # defines the length of the sequence
							# 1<< n is equivalent to 2^n

							# recursive answer will generate answer for n-1 bits
							snake_case_           =		gray_code_sequence_string(bit_count - 1				)

							snake_case_           =		[]

							# append 0 to first half of the smaller sequence generated
							for i in range(seq_len // 2				):
														snake_case_           =		"""0""" + smaller_sequence[i]
														sequence.append(_SCREAMING_SNAKE_CASE				)

							# append 1 to second half ... start from the end of the list
							for i in reversed(range(seq_len // 2				)				):
														snake_case_           =		"""1""" + smaller_sequence[i]
														sequence.append(_SCREAMING_SNAKE_CASE				)

							return sequence


if __name__ == "__main__":
				import doctest

				doctest.testmod()



