




import warnings

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


SCREAMING_SNAKE_CASE__ 						=logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__ 						={
    """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  __magic_name__						(  __UpperCAmelCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Any	      =					"xlnet"
				SCREAMING_SNAKE_CASE__					:							List[str]	      =					["mems"]
				SCREAMING_SNAKE_CASE__					:							Union[str, Any]	      =					{
				    "n_token": "vocab_size",  # Backward compatibility
				    "hidden_size": "d_model",
				    "num_attention_heads": "n_head",
				    "num_hidden_layers": "n_layer",
				}


				def __init__(							self:   Dict		,					_lowerCamelCase:   Optional[int]=3_20_00		,					_lowerCamelCase:   List[Any]=10_24		,					_lowerCamelCase:   Dict=24		,					_lowerCamelCase:   Tuple=16		,					_lowerCamelCase:   Union[str, Any]=40_96		,					_lowerCamelCase:   Optional[int]="gelu"		,					_lowerCamelCase:   Tuple=True		,					_lowerCamelCase:   Optional[Any]="bi"		,					_lowerCamelCase:   str=0.02		,					_lowerCamelCase:   List[Any]=1E-12		,					_lowerCamelCase:   Optional[int]=0.1		,					_lowerCamelCase:   Dict=5_12		,					_lowerCamelCase:   Any=None		,					_lowerCamelCase:   Optional[Any]=True		,					_lowerCamelCase:   Optional[int]=False		,					_lowerCamelCase:   Optional[int]=False		,					_lowerCamelCase:   Union[str, Any]=-1		,					_lowerCamelCase:   Tuple=False		,					_lowerCamelCase:   str="last"		,					_lowerCamelCase:   Tuple=True		,					_lowerCamelCase:   int="tanh"		,					_lowerCamelCase:   Any=0.1		,					_lowerCamelCase:   Union[str, Any]=5		,					_lowerCamelCase:   Any=5		,					_lowerCamelCase:   int=5		,					_lowerCamelCase:   str=1		,					_lowerCamelCase:   Optional[Any]=2		,					**_lowerCamelCase:   Optional[int]		,					):
											SCREAMING_SNAKE_CASE_   	=    vocab_size
											SCREAMING_SNAKE_CASE_   	=    d_model
											SCREAMING_SNAKE_CASE_   	=    n_layer
											SCREAMING_SNAKE_CASE_   	=    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})"		)
											SCREAMING_SNAKE_CASE_   	=    d_model // n_head
											SCREAMING_SNAKE_CASE_   	=    ff_activation
											SCREAMING_SNAKE_CASE_   	=    d_inner
											SCREAMING_SNAKE_CASE_   	=    untie_r
											SCREAMING_SNAKE_CASE_   	=    attn_type

											SCREAMING_SNAKE_CASE_   	=    initializer_range
											SCREAMING_SNAKE_CASE_   	=    layer_norm_eps

											SCREAMING_SNAKE_CASE_   	=    dropout
											SCREAMING_SNAKE_CASE_   	=    mem_len
											SCREAMING_SNAKE_CASE_   	=    reuse_len
											SCREAMING_SNAKE_CASE_   	=    bi_data
											SCREAMING_SNAKE_CASE_   	=    clamp_len
											SCREAMING_SNAKE_CASE_   	=    same_length

											SCREAMING_SNAKE_CASE_   	=    summary_type
											SCREAMING_SNAKE_CASE_   	=    summary_use_proj
											SCREAMING_SNAKE_CASE_   	=    summary_activation
											SCREAMING_SNAKE_CASE_   	=    summary_last_dropout
											SCREAMING_SNAKE_CASE_   	=    start_n_top
											SCREAMING_SNAKE_CASE_   	=    end_n_top

											SCREAMING_SNAKE_CASE_   	=    bos_token_id
											SCREAMING_SNAKE_CASE_   	=    pad_token_id
											SCREAMING_SNAKE_CASE_   	=    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		,					)
																		SCREAMING_SNAKE_CASE_   	=    kwargs['''use_cache''']

											SCREAMING_SNAKE_CASE_   	=    use_mems_eval
											SCREAMING_SNAKE_CASE_   	=    use_mems_train
											super().__init__(pad_token_id=_lowerCamelCase		,					bos_token_id=_lowerCamelCase		,					eos_token_id=_lowerCamelCase		,					**_lowerCamelCase		)


				@property
				def     _A							(							self:   List[Any]		):
											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     _A							(							self:   str		,					_lowerCamelCase:   List[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."		)








# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
			import torch






class  __magic_name__						(  TensorFormatter[Mapping, "torch.Tensor", Mapping]):
				'''simple docstring'''







				def __init__(							self:   int		,					_lowerCamelCase:   int=None		,					**_lowerCamelCase:   List[Any]		):
											super().__init__(features=_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    torch_tensor_kwargs
											import torch  # noqa import torch at initialization


				def     _A							(							self:   Union[str, Any]		,					_lowerCamelCase:   Optional[Any]		):
											import torch

											if isinstance(_lowerCamelCase		,					_lowerCamelCase		) and column:
																		if all(
																		    isinstance(_lowerCamelCase		,					torch.Tensor		) and x.shape == column[0].shape and x.dtype == column[0].dtype
																		    for x in column		):
																									return torch.stack(_lowerCamelCase		)
											return column


				def     _A							(							self:   Tuple		,					_lowerCamelCase:   List[str]		):
											import torch

											if isinstance(_lowerCamelCase		,					(str, bytes, type(_lowerCamelCase		))		):
																		return value
											elif isinstance(_lowerCamelCase		,					(np.character, np.ndarray)		) and np.issubdtype(value.dtype		,					np.character		):
																		return value.tolist()

											SCREAMING_SNAKE_CASE_   	=    {}

											if isinstance(_lowerCamelCase		,					(np.number, np.ndarray)		) and np.issubdtype(value.dtype		,					np.integer		):
																		SCREAMING_SNAKE_CASE_   	=    {'''dtype''': torch.intaa}
											elif isinstance(_lowerCamelCase		,					(np.number, np.ndarray)		) and np.issubdtype(value.dtype		,					np.floating		):
																		SCREAMING_SNAKE_CASE_   	=    {'''dtype''': torch.floataa}
											elif config.PIL_AVAILABLE and "PIL" in sys.modules:
																		import PIL.Image

																		if isinstance(_lowerCamelCase		,					PIL.Image.Image		):
																									SCREAMING_SNAKE_CASE_   	=    np.asarray(_lowerCamelCase		)
											return torch.tensor(_lowerCamelCase		,					**{**default_dtype, **self.torch_tensor_kwargs}		)


				def     _A							(							self:   Union[str, Any]		,					_lowerCamelCase:   Dict		):
											import torch

											# support for torch, tf, jax etc.
											if hasattr(_lowerCamelCase		,					'''__array__'''		) and not isinstance(_lowerCamelCase		,					torch.Tensor		):
																		SCREAMING_SNAKE_CASE_   	=    data_struct.__array__()
											# support for nested types like struct of list of struct
											if isinstance(_lowerCamelCase		,					np.ndarray		):
																		if data_struct.dtype == object:  # torch tensors cannot be instantied from an array of objects
																									return self._consolidate([self.recursive_tensorize(_lowerCamelCase		) for substruct in data_struct]		)
											elif isinstance(_lowerCamelCase		,					(list, tuple)		):
																		return self._consolidate([self.recursive_tensorize(_lowerCamelCase		) for substruct in data_struct]		)
											return self._tensorize(_lowerCamelCase		)


				def     _A							(							self:   str		,					_lowerCamelCase:   dict		):
											return map_nested(self._recursive_tensorize		,					_lowerCamelCase		,					map_list=_lowerCamelCase		)


				def     _A							(							self:   Optional[int]		,					_lowerCamelCase:   pa.Table		):
											SCREAMING_SNAKE_CASE_   	=    self.numpy_arrow_extractor().extract_row(_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    self.python_features_decoder.decode_row(_lowerCamelCase		)
											return self.recursive_tensorize(_lowerCamelCase		)


				def     _A							(							self:   Optional[Any]		,					_lowerCamelCase:   pa.Table		):
											SCREAMING_SNAKE_CASE_   	=    self.numpy_arrow_extractor().extract_column(_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    self.python_features_decoder.decode_column(_lowerCamelCase		,					pa_table.column_names[0]		)
											SCREAMING_SNAKE_CASE_   	=    self.recursive_tensorize(_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    self._consolidate(_lowerCamelCase		)
											return column





				def     _A							(							self:   Optional[Any]		,					_lowerCamelCase:   pa.Table		):
											SCREAMING_SNAKE_CASE_   	=    self.numpy_arrow_extractor().extract_batch(_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    self.python_features_decoder.decode_batch(_lowerCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    self.recursive_tensorize(_lowerCamelCase		)
											for column_name in batch:
																		SCREAMING_SNAKE_CASE_   	=    self._consolidate(batch[column_name]		)
											return batch


