






import warnings

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


UpperCAmelCase__      			=						logging.get_logger(__name__)

UpperCAmelCase__      			=						{
    'xlnet-base-cased': 'https://huggingface.co/xlnet-base-cased/resolve/main/config.json',
    'xlnet-large-cased': 'https://huggingface.co/xlnet-large-cased/resolve/main/config.json',
}




class 							snake_case_       (    _SCREAMING_SNAKE_CASE      ):

						"""simple docstring"""



						snake_case__        =      """xlnet"""
						snake_case__        =      ["""mems"""]
						snake_case__        =      {
						    """n_token""": """vocab_size""",  # Backward compatibility
						    """hidden_size""": """d_model""",
						    """num_attention_heads""": """n_head""",
						    """num_hidden_layers""": """n_layer""",
						}



						def __init__(self:					str ,					__UpperCAmelCase:					Optional[int]=32000 ,					__UpperCAmelCase:					Optional[Any]=1024 ,					__UpperCAmelCase:					str=24 ,					__UpperCAmelCase:					Any=16 ,					__UpperCAmelCase:					Union[str, Any]=4096 ,					__UpperCAmelCase:					List[str]="gelu" ,					__UpperCAmelCase:					Tuple=True ,					__UpperCAmelCase:					Optional[int]="bi" ,					__UpperCAmelCase:					Any=0.02 ,					__UpperCAmelCase:					List[Any]=1E-12 ,					__UpperCAmelCase:					Any=0.1 ,					__UpperCAmelCase:					List[Any]=512 ,					__UpperCAmelCase:					int=None ,					__UpperCAmelCase:					Dict=True ,					__UpperCAmelCase:					str=False ,					__UpperCAmelCase:					str=False ,					__UpperCAmelCase:					str=-1 ,					__UpperCAmelCase:					Dict=False ,					__UpperCAmelCase:					int="last" ,					__UpperCAmelCase:					List[Any]=True ,					__UpperCAmelCase:					Optional[int]="tanh" ,					__UpperCAmelCase:					Union[str, Any]=0.1 ,					__UpperCAmelCase:					Any=5 ,					__UpperCAmelCase:					List[Any]=5 ,					__UpperCAmelCase:					Optional[int]=5 ,					__UpperCAmelCase:					Optional[int]=1 ,					__UpperCAmelCase:					Dict=2 ,					**__UpperCAmelCase:					str ,					)    ->     Tuple:




											'''simple docstring'''



											__a					:						Optional[int]      =					vocab_size
											__a					:						Dict      =					d_model
											__a					:						Any      =					n_layer
											__a					:						Dict      =					n_head
											if d_model % n_head != 0:
																raise ValueError(f'\'d_model % n_head\' ({d_model % n_head}) should be equal to 0'   )
											if "d_head" in kwargs:
																if kwargs["d_head"] != d_model // n_head:
																					raise ValueError(
																					    f'`d_head` ({kwargs["d_head"]}) should be equal to `d_model // n_head` ({d_model // n_head})'   )
											__a					:						Union[str, Any]      =					d_model // n_head
											__a					:						List[str]      =					ff_activation
											__a					:						Any      =					d_inner
											__a					:						Dict      =					untie_r
											__a					:						Optional[int]      =					attn_type

											__a					:						Optional[Any]      =					initializer_range
											__a					:						Union[str, Any]      =					layer_norm_eps

											__a					:						List[Any]      =					dropout
											__a					:						Dict      =					mem_len
											__a					:						Union[str, Any]      =					reuse_len
											__a					:						List[str]      =					bi_data
											__a					:						Optional[int]      =					clamp_len
											__a					:						str      =					same_length

											__a					:						Optional[int]      =					summary_type
											__a					:						Dict      =					summary_use_proj
											__a					:						int      =					summary_activation
											__a					:						Tuple      =					summary_last_dropout
											__a					:						Optional[Any]      =					start_n_top
											__a					:						List[str]      =					end_n_top

											__a					:						Any      =					bos_token_id
											__a					:						Any      =					pad_token_id
											__a					:						Any      =					eos_token_id

											if "use_cache" in kwargs:
																warnings.warn(
																    "The `use_cache` argument is deprecated and will be removed in a future version, use `use_mems_eval`"
																    " instead." ,					_lowerCAmelCase ,					)
																__a					:						Tuple      =					kwargs["use_cache"]

											__a					:						str      =					use_mems_eval
											__a					:						Union[str, Any]      =					use_mems_train
											super().__init__(pad_token_id=_lowerCAmelCase ,					bos_token_id=_lowerCAmelCase ,					eos_token_id=_lowerCAmelCase ,					**_lowerCAmelCase   )



						@property
						def        UpperCAmelCase__					(self:					Union[str, Any]   )    ->     Union[str, Any]:




											'''simple docstring'''



											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        UpperCAmelCase__					(self:					List[str] ,					__UpperCAmelCase:					Optional[int]   )    ->     str:




											'''simple docstring'''



											raise NotImplementedError(
											    f'The model {self.model_type} is one of the few models that has no sequence length limit.'   )











import unittest
from typing import Tuple

import torch

from diffusers.utils import floats_tensor, randn_tensor, torch_all_close, torch_device
from diffusers.utils.testing_utils import require_torch





@require_torch
class 			lowerCamelCase_				:


 '''simple docstring'''







 @property
 def  lowerCAmelCase_    (				self    :						Optional[Any]		):
       return self.get_dummy_input()



 @property
 def  lowerCAmelCase_    (				self    :						Union[str, Any]		):
       if self.block_type == "down":
             return (4, 32, 16, 16)
       elif self.block_type == "mid":
             return (4, 32, 32, 32)
       elif self.block_type == "up":
             return (4, 32, 64, 64)

       raise ValueError(F"'{self.block_type}' is not a supported block_type. Set it to 'up', 'mid', or 'down'."		)



 def  lowerCAmelCase_    (				self    :						List[str]							,							_lowerCAmelCase    :						Optional[Any]=True							,							_lowerCAmelCase    :						str=False							,							_lowerCAmelCase    :						Optional[int]=False							,							_lowerCAmelCase    :						Dict=False							,							):
       SCREAMING_SNAKE_CASE_      		=     4
       SCREAMING_SNAKE_CASE_      		=     32
       SCREAMING_SNAKE_CASE_      		=     (32, 32)

       SCREAMING_SNAKE_CASE_      		=     torch.manual_seed(0		)
       SCREAMING_SNAKE_CASE_      		=     torch.device(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     (batch_size, num_channels) + sizes
       SCREAMING_SNAKE_CASE_      		=     randn_tensor(_lowerCAmelCase							,							generator=_lowerCAmelCase							,							device=_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     {'hidden_states': hidden_states}

       if include_temb:
             SCREAMING_SNAKE_CASE_      		=     128
             SCREAMING_SNAKE_CASE_      		=     randn_tensor((batch_size, temb_channels)							,							generator=_lowerCAmelCase							,							device=_lowerCAmelCase		)

       if include_res_hidden_states_tuple:
             SCREAMING_SNAKE_CASE_      		=     torch.manual_seed(1		)
             SCREAMING_SNAKE_CASE_      		=     (randn_tensor(_lowerCAmelCase							,							generator=_lowerCAmelCase							,							device=_lowerCAmelCase		),)

       if include_encoder_hidden_states:
             SCREAMING_SNAKE_CASE_      		=     floats_tensor((batch_size, 32, 32)		).to(_lowerCAmelCase		)

       if include_skip_sample:
             SCREAMING_SNAKE_CASE_      		=     randn_tensor(((batch_size, 3) + sizes)							,							generator=_lowerCAmelCase							,							device=_lowerCAmelCase		)

       return dummy_input



 def  lowerCAmelCase_    (				self    :						Optional[int]		):
       SCREAMING_SNAKE_CASE_      		=     {
           'in_channels': 32,
           'out_channels': 32,
           'temb_channels': 128,
       }
       if self.block_type == "up":
             SCREAMING_SNAKE_CASE_      		=     32

       if self.block_type == "mid":
             init_dict.pop('out_channels'		)

       SCREAMING_SNAKE_CASE_      		=     self.dummy_input
       return init_dict, inputs_dict



 def  lowerCAmelCase_    (				self    :						Dict							,							_lowerCAmelCase    :						Optional[Any]		):
       SCREAMING_SNAKE_CASE_		,					SCREAMING_SNAKE_CASE_      		=     self.prepare_init_args_and_inputs_for_common()
       SCREAMING_SNAKE_CASE_      		=     self.block_class(**_lowerCAmelCase		)
       unet_block.to(_lowerCAmelCase		)
       unet_block.eval()

       with torch.no_grad():
             SCREAMING_SNAKE_CASE_      		=     unet_block(**_lowerCAmelCase		)

       if isinstance(_lowerCAmelCase							,							_lowerCAmelCase		):
             SCREAMING_SNAKE_CASE_      		=     output[0]

       self.assertEqual(output.shape							,							self.output_shape		)

       SCREAMING_SNAKE_CASE_      		=     output[0, -1, -3:, -3:]
       SCREAMING_SNAKE_CASE_      		=     torch.tensor(_lowerCAmelCase		).to(_lowerCAmelCase		)
       assert torch_all_close(output_slice.flatten()							,							_lowerCAmelCase							,							atol=5E-3		)




 @unittest.skipIf(torch_device == 'mps'							,							'Training is not supported in mps'		)
 def  lowerCAmelCase_    (				self    :						Any		):
       SCREAMING_SNAKE_CASE_		,					SCREAMING_SNAKE_CASE_      		=     self.prepare_init_args_and_inputs_for_common()
       SCREAMING_SNAKE_CASE_      		=     self.block_class(**_lowerCAmelCase		)
       model.to(_lowerCAmelCase		)
       model.train()
       SCREAMING_SNAKE_CASE_      		=     model(**_lowerCAmelCase		)

       if isinstance(_lowerCAmelCase							,							_lowerCAmelCase		):
             SCREAMING_SNAKE_CASE_      		=     output[0]

       SCREAMING_SNAKE_CASE_      		=     torch.device(_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     randn_tensor(output.shape							,							device=_lowerCAmelCase		)
       SCREAMING_SNAKE_CASE_      		=     torch.nn.functional.mse_loss(_lowerCAmelCase							,							_lowerCAmelCase		)
       loss.backward()