





'''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 			lowerCamelCase					(						__UpperCAmelCase     ,							__UpperCAmelCase     ,							unittest.TestCase  ):
					_SCREAMING_SNAKE_CASE							   =    VQModel
					_SCREAMING_SNAKE_CASE							   =    "sample"


					@property
					def    SCREAMING_SNAKE_CASE_		(					self	:  List[Any]       ,     __snake_case	:  Tuple=(32, 32)       ):





											'''simple docstring'''





											_snake_case:   Dict  					=		4
											_snake_case:   str  					=		3

											_snake_case:   int  					=		floats_tensor((batch_size, num_channels) + sizes       ).to(__snake_case       )

											return {"sample": image}


					@property
					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[Any]       ):





											'''simple docstring'''





											return (3, 32, 32)


					@property
					def    SCREAMING_SNAKE_CASE_		(					self	:  List[str]       ):





											'''simple docstring'''





											return (3, 32, 32)


					def    SCREAMING_SNAKE_CASE_		(					self	:  str       ):





											'''simple docstring'''





											_snake_case:   str  					=		{
											    '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:   Union[str, Any]  					=		self.dummy_input
											return init_dict, inputs_dict


					def    SCREAMING_SNAKE_CASE_		(					self	:  str       ):





											'''simple docstring'''





											pass


					def    SCREAMING_SNAKE_CASE_		(					self	:  Any       ):





											'''simple docstring'''





											pass


					def    SCREAMING_SNAKE_CASE_		(					self	:  Dict       ):





											'''simple docstring'''





											_snake_case					,						_snake_case:   str  					=		VQModel.from_pretrained('fusing/vqgan-dummy'       ,     output_loading_info=__snake_case       )
											self.assertIsNotNone(__snake_case       )
											self.assertEqual(len(loading_info['missing_keys']       )       ,     0       )

											model.to(__snake_case       )
											_snake_case:   List[Any]  					=		model(**self.dummy_input       )

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




					def    SCREAMING_SNAKE_CASE_		(					self	:  Optional[int]       ):





											'''simple docstring'''





											_snake_case:   str  					=		VQModel.from_pretrained('fusing/vqgan-dummy'       )
											model.to(__snake_case       ).eval()

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

											_snake_case:   Tuple  					=		torch.randn(1       ,     model.config.in_channels       ,     model.config.sample_size       ,     model.config.sample_size       )
											_snake_case:   Tuple  					=		image.to(__snake_case       )
											with torch.no_grad():
																	_snake_case:   Dict  					=		model(__snake_case       ).sample

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












'''simple docstring'''






A   : List[str]             =			'\n# Transformers 설치 방법\n! pip install transformers datasets\n# 마지막 릴리스 대신 소스에서 설치하려면, 위 명령을 주석으로 바꾸고 아래 명령을 해제하세요.\n# ! pip install git+https://github.com/huggingface/transformers.git\n'

A   : List[str]             =			[{'type': 'code', 'content': INSTALL_CONTENT}]
A   : Dict             =			{
    '{processor_class}': 'FakeProcessorClass',
    '{model_class}': 'FakeModelClass',
    '{object_class}': 'FakeObjectClass',
}





