


"""simple docstring"""



UpperCAmelCase      		=			[
    '''Audio''',
    '''Array2D''',
    '''Array3D''',
    '''Array4D''',
    '''Array5D''',
    '''ClassLabel''',
    '''Features''',
    '''Sequence''',
    '''Value''',
    '''Image''',
    '''Translation''',
    '''TranslationVariableLanguages''',
]
from .audio import Audio
from .features import ArrayaD, ArrayaD, ArrayaD, ArrayaD, ClassLabel, Features, Sequence, Value
from .image import Image
from .translation import Translation, TranslationVariableLanguages





"""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 					__magic_name__		(			__UpperCAmelCase			,						__UpperCAmelCase			,						unittest.TestCase     ):
       __A			:      List[str]        =   VQModel
       __A			:      Any        =   "sample"






       @property
       def  __snake_case						(   self  :    int  ,     snake_case__  :    int=(3_2, 3_2)				):

              '''simple docstring'''






              lowercase		:Optional[int]       							=				4
              lowercase		:Tuple       							=				3

              lowercase		:List[str]       							=				floats_tensor((batch_size, num_channels) + sizes				).to(snake_case__				)

              return {"sample": image}






       @property
       def  __snake_case						(   self  :    Union[str, Any]				):

              '''simple docstring'''






              return (3, 3_2, 3_2)






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

              '''simple docstring'''






              return (3, 3_2, 3_2)






       def  __snake_case						(   self  :    Dict				):

              '''simple docstring'''






              lowercase		:Optional[int]       							=				{
                  '''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,
              }
              lowercase		:Dict       							=				self.dummy_input
              return init_dict, inputs_dict






       def  __snake_case						(   self  :    Optional[int]				):

              '''simple docstring'''






              pass






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

              '''simple docstring'''






              pass






       def  __snake_case						(   self  :    Dict				):

              '''simple docstring'''






              lowercase							,  lowercase		:Optional[int]       							=				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__				)
              lowercase		:List[str]       							=				model(**self.dummy_input				)

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







       def  __snake_case						(   self  :    Optional[int]				):

              '''simple docstring'''






              lowercase		:Optional[int]       							=				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				)

              lowercase		:List[Any]       							=				torch.randn(1  ,     model.config.in_channels  ,     model.config.sample_size  ,     model.config.sample_size				)
              lowercase		:int       							=				image.to(snake_case__				)
              with torch.no_grad():
                     lowercase		:str       							=				model(snake_case__				).sample

              lowercase		:List[Any]       							=				output[0, -1, -3:, -3:].flatten().cpu()
              # fmt: off
              lowercase		:Tuple       							=				torch.tensor([-0.01_53, -0.40_44, -0.18_80, -0.51_61, -0.24_18, -0.40_72, -0.16_12, -0.06_33, -0.01_43]				)
              # fmt: on
              self.assertTrue(torch.allclose(snake_case__  ,     snake_case__  ,     atol=1e-3				)				)

