



"""simple docstring"""






import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import TaBlock, TaConfig, TaLayerNorm

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin



class      A__  (    __SCREAMING_SNAKE_CASE    ,						__SCREAMING_SNAKE_CASE    ,						__SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	@register_to_config
	def __init__(	self:						List[str]			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						float			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						int			,     _SCREAMING_SNAKE_CASE:						str			,     _SCREAMING_SNAKE_CASE:						bool = False			,     )							->			Any:

				"""simple docstring"""

				super().__init__()

				__lowerCAmelCase :    str				=			nn.Embedding(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Dict				=			nn.Embedding(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    str				=			False

				__lowerCAmelCase :    Optional[Any]				=			nn.Dropout(p=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Dict				=			TaConfig(
				    vocab_size=_SCREAMING_SNAKE_CASE			,     d_model=_SCREAMING_SNAKE_CASE			,     num_heads=_SCREAMING_SNAKE_CASE			,     d_kv=_SCREAMING_SNAKE_CASE			,     d_ff=_SCREAMING_SNAKE_CASE			,     dropout_rate=_SCREAMING_SNAKE_CASE			,     feed_forward_proj=_SCREAMING_SNAKE_CASE			,     is_decoder=_SCREAMING_SNAKE_CASE			,     is_encoder_decoder=_SCREAMING_SNAKE_CASE			,     )

				__lowerCAmelCase :    str				=			nn.ModuleList()
				for lyr_num in range(_SCREAMING_SNAKE_CASE):
							__lowerCAmelCase :    int				=			TaBlock(_SCREAMING_SNAKE_CASE)
							self.encoders.append(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Dict				=			TaLayerNorm(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    Any				=			nn.Dropout(p=_SCREAMING_SNAKE_CASE)







	def 				_SCREAMING_SNAKE_CASE  (	self:						Any			,     _SCREAMING_SNAKE_CASE:						Tuple			,     _SCREAMING_SNAKE_CASE:						str)							->			List[str]:

				"""simple docstring"""

				__lowerCAmelCase :    Union[str, Any]				=			self.token_embedder(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    Optional[Any]				=			encoder_input_tokens.shape[1]
				__lowerCAmelCase :    List[Any]				=			torch.arange(_SCREAMING_SNAKE_CASE			,     device=encoder_input_tokens.device)
				x += self.position_encoding(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    List[Any]				=			self.dropout_pre(_SCREAMING_SNAKE_CASE)

				# inverted the attention mask
				__lowerCAmelCase :    List[Any]				=			encoder_input_tokens.size()
				__lowerCAmelCase :    Any				=			self.get_extended_attention_mask(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)

				for lyr in self.encoders:
							__lowerCAmelCase :    Union[str, Any]				=			lyr(_SCREAMING_SNAKE_CASE			,     _SCREAMING_SNAKE_CASE)[0]
				__lowerCAmelCase :    int				=			self.layer_norm(_SCREAMING_SNAKE_CASE)

				return self.dropout_post(_SCREAMING_SNAKE_CASE), encoder_inputs_mask




"""simple docstring"""






import warnings

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


__snake_case				:  Tuple =       logging.get_logger(__name__)

__snake_case				:  Tuple =       {
    '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      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'xlnet'
	SCREAMING_SNAKE_CASE        =      ['mems']
	SCREAMING_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:						Tuple			,     _SCREAMING_SNAKE_CASE:						List[str]=3_2000			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=1024			,     _SCREAMING_SNAKE_CASE:						Dict=24			,     _SCREAMING_SNAKE_CASE:						Optional[int]=16			,     _SCREAMING_SNAKE_CASE:						List[str]=4096			,     _SCREAMING_SNAKE_CASE:						Tuple="gelu"			,     _SCREAMING_SNAKE_CASE:						int=True			,     _SCREAMING_SNAKE_CASE:						List[Any]="bi"			,     _SCREAMING_SNAKE_CASE:						Any=0.02			,     _SCREAMING_SNAKE_CASE:						List[str]=1e-12			,     _SCREAMING_SNAKE_CASE:						Any=0.1			,     _SCREAMING_SNAKE_CASE:						Any=512			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=None			,     _SCREAMING_SNAKE_CASE:						Any=True			,     _SCREAMING_SNAKE_CASE:						Any=False			,     _SCREAMING_SNAKE_CASE:						Tuple=False			,     _SCREAMING_SNAKE_CASE:						List[Any]=-1			,     _SCREAMING_SNAKE_CASE:						Union[str, Any]=False			,     _SCREAMING_SNAKE_CASE:						Optional[int]="last"			,     _SCREAMING_SNAKE_CASE:						Tuple=True			,     _SCREAMING_SNAKE_CASE:						Dict="tanh"			,     _SCREAMING_SNAKE_CASE:						int=0.1			,     _SCREAMING_SNAKE_CASE:						Tuple=5			,     _SCREAMING_SNAKE_CASE:						List[str]=5			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=5			,     _SCREAMING_SNAKE_CASE:						Optional[int]=1			,     _SCREAMING_SNAKE_CASE:						Tuple=2			,     **_SCREAMING_SNAKE_CASE:						str			,     )							->			Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase :    Dict				=			vocab_size
				__lowerCAmelCase :    Optional[int]				=			d_model
				__lowerCAmelCase :    Union[str, Any]				=			n_layer
				__lowerCAmelCase :    List[Any]				=			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})""")
				__lowerCAmelCase :    Optional[Any]				=			d_model // n_head
				__lowerCAmelCase :    Tuple				=			ff_activation
				__lowerCAmelCase :    Union[str, Any]				=			d_inner
				__lowerCAmelCase :    Any				=			untie_r
				__lowerCAmelCase :    int				=			attn_type

				__lowerCAmelCase :    Any				=			initializer_range
				__lowerCAmelCase :    List[Any]				=			layer_norm_eps

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

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

				__lowerCAmelCase :    str				=			bos_token_id
				__lowerCAmelCase :    Optional[Any]				=			pad_token_id
				__lowerCAmelCase :    Optional[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."			,     _SCREAMING_SNAKE_CASE			,     )
							__lowerCAmelCase :    Optional[int]				=			kwargs["use_cache"]

				__lowerCAmelCase :    Optional[int]				=			use_mems_eval
				__lowerCAmelCase :    Any				=			use_mems_train
				super().__init__(pad_token_id=_SCREAMING_SNAKE_CASE			,     bos_token_id=_SCREAMING_SNAKE_CASE			,     eos_token_id=_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

	@property
	def 				_SCREAMING_SNAKE_CASE  (	self:						Any)							->			int:

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

				"""simple docstring"""

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