


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

	"""simple docstring"""





	snake_case__       :						Dict					      =    VQModel
	snake_case__       :						Optional[Any]					      =    "sample"




	@property
	def 						UpperCAmelCase_   (				self    :       Tuple    ,    UpperCAmelCase__    :       Dict=(3_2, 3_2)     ) ->			str:
						__SCREAMING_SNAKE_CASE		     =       4
						__SCREAMING_SNAKE_CASE		     =       3

						__SCREAMING_SNAKE_CASE		     =       floats_tensor((batch_size, num_channels) + sizes     ).to(UpperCAmelCase__     )

						return {"sample": image}




	@property
	def 						UpperCAmelCase_   (				self    :       str     ) ->			Optional[int]:
						return (3, 3_2, 3_2)




	@property
	def 						UpperCAmelCase_   (				self    :       List[Any]     ) ->			List[Any]:
						return (3, 3_2, 3_2)




	def 						UpperCAmelCase_   (				self    :       Optional[int]     ) ->			List[str]:
						__SCREAMING_SNAKE_CASE		     =       {
						    "block_out_channels": [3_2, 6_4],
						    "in_channels": 3,
						    "out_channels": 3,
						    "down_block_types": ["DownEncoderBlock2D", "DownEncoderBlock2D"],
						    "up_block_types": ["UpDecoderBlock2D", "UpDecoderBlock2D"],
						    "latent_channels": 3,
						}
						__SCREAMING_SNAKE_CASE		     =       self.dummy_input
						return init_dict, inputs_dict




	def 						UpperCAmelCase_   (				self    :       List[Any]     ) ->			Dict:
						pass




	def 						UpperCAmelCase_   (				self    :       Dict     ) ->			Dict:
						pass




	def 						UpperCAmelCase_   (				self    :       Dict     ) ->			str:
						__SCREAMING_SNAKE_CASE     ,						__SCREAMING_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__     )
						__SCREAMING_SNAKE_CASE		     =       model(**self.dummy_input     )

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




	def 						UpperCAmelCase_   (				self    :       Dict     ) ->			Tuple:
						__SCREAMING_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     )

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

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







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a__       :							Optional[Any]        =  {
    '''configuration_jukebox''': [
        '''JUKEBOX_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''JukeboxConfig''',
        '''JukeboxPriorConfig''',
        '''JukeboxVQVAEConfig''',
    ],
    '''tokenization_jukebox''': ['''JukeboxTokenizer'''],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		a__       :							int        =  [
		    '''JUKEBOX_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''JukeboxModel''',
		    '''JukeboxPreTrainedModel''',
		    '''JukeboxVQVAE''',
		    '''JukeboxPrior''',
		]

if TYPE_CHECKING:
		from .configuration_jukebox import (
		    JUKEBOX_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    JukeboxConfig,
		    JukeboxPriorConfig,
		    JukeboxVQVAEConfig,
		)
		from .tokenization_jukebox import JukeboxTokenizer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_jukebox import (
				    JUKEBOX_PRETRAINED_MODEL_ARCHIVE_LIST,
				    JukeboxModel,
				    JukeboxPreTrainedModel,
				    JukeboxPrior,
				    JukeboxVQVAE,
				)

else:
		import sys

		a__       :							Union[str, Any]        =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
