


from ...configuration_utils import PretrainedConfig
from ...utils import logging


_snake_case	:						Dict         =							logging.get_logger(__name__)

_snake_case	:						Optional[int]         =							{
    "transfo-xl-wt103": "https://huggingface.co/transfo-xl-wt103/resolve/main/config.json",
}

class 							a						(_lowerCAmelCase ):




							"""simple docstring"""


							__UpperCAmelCase       :				List[str]	    =    "transfo-xl"
							__UpperCAmelCase       :				List[Any]	    =    ["mems"]
							__UpperCAmelCase       :				Optional[Any]	    =    {
							    "n_token": "vocab_size",
							    "hidden_size": "d_model",
							    "num_attention_heads": "n_head",
							    "num_hidden_layers": "n_layer",
							}

							def __init__(				self			:    int       ,      lowerCamelCase			:    Tuple=267735       ,      lowerCamelCase			:    Optional[int]=[20000, 40000, 200000]       ,      lowerCamelCase			:    Tuple=1024       ,      lowerCamelCase			:    str=1024       ,      lowerCamelCase			:    Dict=16       ,      lowerCamelCase			:    str=64       ,      lowerCamelCase			:    Optional[int]=4096       ,      lowerCamelCase			:    Optional[Any]=4       ,      lowerCamelCase			:    int=False       ,      lowerCamelCase			:    Dict=18       ,      lowerCamelCase			:    Union[str, Any]=1600       ,      lowerCamelCase			:    Optional[Any]=1000       ,      lowerCamelCase			:    Union[str, Any]=True       ,      lowerCamelCase			:    Any=True       ,      lowerCamelCase			:    Optional[int]=0       ,      lowerCamelCase			:    List[Any]=-1       ,      lowerCamelCase			:    Dict=True       ,      lowerCamelCase			:    List[str]=0.1       ,      lowerCamelCase			:    List[str]=0.0       ,      lowerCamelCase			:    Tuple=True       ,      lowerCamelCase			:    List[Any]="normal"       ,      lowerCamelCase			:    int=0.01       ,      lowerCamelCase			:    Optional[int]=0.01       ,      lowerCamelCase			:    Optional[int]=0.02       ,      lowerCamelCase			:    str=1E-5       ,      lowerCamelCase			:    Tuple=0       ,      **lowerCamelCase			:    List[str]       ,      )      ->       int:
														__snake_case						:     str									=  vocab_size
														__snake_case						:     Union[str, Any]									=  []
														self.cutoffs.extend(lowerCamelCase							)
														if proj_share_all_but_first:
																					__snake_case						:     Dict									=  [False] + [True] * len(self.cutoffs							)
														else:
																					__snake_case						:     List[Any]									=  [False] + [False] * len(self.cutoffs							)
														__snake_case						:     List[Any]									=  d_model
														__snake_case						:     List[str]									=  d_embed
														__snake_case						:     str									=  d_head
														__snake_case						:     Union[str, Any]									=  d_inner
														__snake_case						:     Union[str, Any]									=  div_val
														__snake_case						:     Optional[Any]									=  pre_lnorm
														__snake_case						:     Any									=  n_layer
														__snake_case						:     Union[str, Any]									=  n_head
														__snake_case						:     Dict									=  mem_len
														__snake_case						:     Union[str, Any]									=  same_length
														__snake_case						:     Any									=  attn_type
														__snake_case						:     Any									=  clamp_len
														__snake_case						:     Any									=  sample_softmax
														__snake_case						:     List[str]									=  adaptive
														__snake_case						:     Optional[int]									=  dropout
														__snake_case						:     List[Any]									=  dropatt
														__snake_case						:     Tuple									=  untie_r
														__snake_case						:     Tuple									=  init
														__snake_case						:     Any									=  init_range
														__snake_case						:     Any									=  proj_init_std
														__snake_case						:     int									=  init_std
														__snake_case						:     Union[str, Any]									=  layer_norm_epsilon
														super().__init__(eos_token_id=lowerCamelCase       ,      **lowerCamelCase							)

							@property
							def        __snake_case   (				self			:    Optional[int]							)      ->       str:
														# Message copied from Transformer-XL documentation
														logger.info(F'The model {self.model_type} is one of the few models that has no sequence length limit.'							)
														return -1






							@max_position_embeddings.setter
							def        __snake_case   (				self			:    List[str]       ,      lowerCamelCase			:    Any							)      ->       Any:
														# Message copied from Transformer-XL documentation
														raise NotImplementedError(
														    F'The model {self.model_type} is one of the few models that has no sequence length limit.'							)


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__	(		__a   ,						__a   ,						unittest.TestCase     ):





   """simple docstring"""




   lowerCAmelCase   :     Dict	      = VQModel
   lowerCAmelCase   :     List[str]	      = '''sample'''



   @property
   def 	lowerCAmelCase    (						self       :	List[Any]		,	_lowercase       :	Tuple=(32, 32)				):



    """simple docstring"""



    _UpperCamelCase:  List[Any]    						=			4
    _UpperCamelCase:  Tuple    						=			3

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

    return {"sample": image}



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



    """simple docstring"""



    return (3, 32, 32)



   @property
   def 	lowerCAmelCase    (						self       :	str				):



    """simple docstring"""



    return (3, 32, 32)



   def 	lowerCAmelCase    (						self       :	Optional[int]				):



    """simple docstring"""



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



   def 	lowerCAmelCase    (						self       :	List[Any]				):



    """simple docstring"""



    pass



   def 	lowerCAmelCase    (						self       :	List[Any]				):



    """simple docstring"""



    pass



   def 	lowerCAmelCase    (						self       :	Optional[Any]				):



    """simple docstring"""



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

    model.to(_lowercase				)
    _UpperCamelCase:  Tuple    						=			model(**self.dummy_input				)

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



   def 	lowerCAmelCase    (						self       :	Optional[Any]				):



    """simple docstring"""



    _UpperCamelCase:  Dict    						=			VQModel.from_pretrained('''fusing/vqgan-dummy'''				)
    model.to(_lowercase				).eval()

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

    _UpperCamelCase:  int    						=			torch.randn(1		,	model.config.in_channels		,	model.config.sample_size		,	model.config.sample_size				)
    _UpperCamelCase:  Tuple    						=			image.to(_lowercase				)
    with torch.no_grad():
     _UpperCamelCase:  Optional[int]    						=			model(_lowercase				).sample

    _UpperCamelCase:  List[Any]    						=			output[0, -1, -3:, -3:].flatten().cpu()
    # fmt: off
    _UpperCamelCase:  Any    						=			torch.tensor([-0.0153, -0.4044, -0.1880, -0.5161, -0.2418, -0.4072, -0.1612, -0.0633, -0.0143]				)
    # fmt: on
    self.assertTrue(torch.allclose(_lowercase		,	_lowercase		,	atol=1E-3				)				)