


"""simple docstring"""



from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


UpperCAmelCase      		=			logging.get_logger(__name__)

UpperCAmelCase      		=			{
    '''google/vit-base-patch16-224''': '''https://huggingface.co/vit-base-patch16-224/resolve/main/config.json''',
    # See all ViT models at https://huggingface.co/models?filter=vit
}
class 					__magic_name__		(			__UpperCAmelCase     ):
							__A			:      Optional[int]        =   "vit"






							def __init__(   self  :    Tuple  ,     snake_case__  :    int=7_6_8  ,     snake_case__  :    Optional[int]=1_2  ,     snake_case__  :    str=1_2  ,     snake_case__  :    Tuple=3_0_7_2  ,     snake_case__  :    Optional[int]="gelu"  ,     snake_case__  :    Optional[int]=0.0  ,     snake_case__  :    str=0.0  ,     snake_case__  :    str=0.02  ,     snake_case__  :    Union[str, Any]=1e-1_2  ,     snake_case__  :    int=2_2_4  ,     snake_case__  :    Optional[int]=1_6  ,     snake_case__  :    Optional[int]=3  ,     snake_case__  :    List[str]=True  ,     snake_case__  :    Tuple=1_6  ,     **snake_case__  :    str  ,     ):

														'''simple docstring'''






														super().__init__(**snake_case__				)

														lowercase		:Tuple       							=				hidden_size
														lowercase		:Optional[int]       							=				num_hidden_layers
														lowercase		:Optional[int]       							=				num_attention_heads
														lowercase		:Any       							=				intermediate_size
														lowercase		:Union[str, Any]       							=				hidden_act
														lowercase		:Any       							=				hidden_dropout_prob
														lowercase		:Dict       							=				attention_probs_dropout_prob
														lowercase		:Tuple       							=				initializer_range
														lowercase		:int       							=				layer_norm_eps
														lowercase		:int       							=				image_size
														lowercase		:List[Any]       							=				patch_size
														lowercase		:str       							=				num_channels
														lowercase		:Optional[int]       							=				qkv_bias
														lowercase		:Optional[Any]       							=				encoder_stride







class 					__magic_name__		(			__UpperCAmelCase     ):
							__A			:      List[str]        =   version.parse("1.11"     )






							@property
							def  __snake_case						(   self  :    Any				):

														'''simple docstring'''






														return OrderedDict(
														    [
														        ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
														    ]				)







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

														'''simple docstring'''






														return 1e-4





"""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				)				)

