import warnings

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


A__           =							logging.get_logger(__name__)

A__           =							{
    """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   _lowerCAmelCase		(     __SCREAMING_SNAKE_CASE				):
							_UpperCAmelCase						    =     'xlnet'
							_UpperCAmelCase						    =     ['mems']
							_UpperCAmelCase						    =     {
							    'n_token': 'vocab_size',  # Backward compatibility
							    'hidden_size': 'd_model',
							    'num_attention_heads': 'n_head',
							    'num_hidden_layers': 'n_layer',
							}







							def __init__(				self     :    List[str]	,					__snake_case     :    List[str]=32000	,					__snake_case     :    List[Any]=1024	,					__snake_case     :    List[str]=24	,					__snake_case     :    Union[str, Any]=16	,					__snake_case     :    Tuple=4096	,					__snake_case     :    Any="gelu"	,					__snake_case     :    Dict=True	,					__snake_case     :    Tuple="bi"	,					__snake_case     :    Tuple=0.0_2	,					__snake_case     :    Dict=1e-1_2	,					__snake_case     :    Union[str, Any]=0.1	,					__snake_case     :    str=512	,					__snake_case     :    int=None	,					__snake_case     :    Optional[int]=True	,					__snake_case     :    Optional[int]=False	,					__snake_case     :    Optional[Any]=False	,					__snake_case     :    Any=-1	,					__snake_case     :    Any=False	,					__snake_case     :    Optional[int]="last"	,					__snake_case     :    int=True	,					__snake_case     :    Any="tanh"	,					__snake_case     :    Any=0.1	,					__snake_case     :    int=5	,					__snake_case     :    str=5	,					__snake_case     :    Optional[int]=5	,					__snake_case     :    Dict=1	,					__snake_case     :    Optional[int]=2	,					**__snake_case     :    Union[str, Any]	,					):
										lowerCamelCase						:Optional[int]						  =     vocab_size
										lowerCamelCase						:Any						  =     d_model
										lowerCamelCase						:Union[str, Any]						  =     n_layer
										lowerCamelCase						:Union[str, 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						:str						  =     d_model // n_head
										lowerCamelCase						:int						  =     ff_activation
										lowerCamelCase						:Dict						  =     d_inner
										lowerCamelCase						:int						  =     untie_r
										lowerCamelCase						:Optional[int]						  =     attn_type

										lowerCamelCase						:Optional[Any]						  =     initializer_range
										lowerCamelCase						:Dict						  =     layer_norm_eps

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

										lowerCamelCase						:Optional[Any]						  =     summary_type
										lowerCamelCase						:Union[str, Any]						  =     summary_use_proj
										lowerCamelCase						:Optional[Any]						  =     summary_activation
										lowerCamelCase						:Optional[Any]						  =     summary_last_dropout
										lowerCamelCase						:List[str]						  =     start_n_top
										lowerCamelCase						:int						  =     end_n_top

										lowerCamelCase						:Any						  =     bos_token_id
										lowerCamelCase						:Optional[Any]						  =     pad_token_id
										lowerCamelCase						:Union[str, 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.'''	,					__snake_case	,					)
													lowerCamelCase						:Optional[int]						  =     kwargs['''use_cache''']

										lowerCamelCase						:Optional[int]						  =     use_mems_eval
										lowerCamelCase						:Optional[int]						  =     use_mems_train
										super().__init__(pad_token_id=__snake_case	,					bos_token_id=__snake_case	,					eos_token_id=__snake_case	,					**__snake_case		)







							@property
							def 				snake_case  (				self     :    Dict		):
										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     :    Optional[Any]	,					__snake_case     :    int		):
										# 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 os
from typing import Optional

import fsspec
from fsspec.archive import AbstractArchiveFileSystem
from fsspec.utils import DEFAULT_BLOCK_SIZE
class   _lowerCAmelCase		(     __SCREAMING_SNAKE_CASE				):
							_UpperCAmelCase						    =     ''
							_UpperCAmelCase						    =     (
							    None  # protocol passed in prefix to the url. ex: "gzip", for gzip://file.txt::http://foo.bar/file.txt.gz
							)
							_UpperCAmelCase						    =     None  # compression type in fsspec. ex: "gzip"
							_UpperCAmelCase						    =     None  # extension of the filename to strip. ex: "".gz" to get file.txt from file.txt.gz







							def __init__(				self     :    str	,					__snake_case     :    str = ""	,					__snake_case     :    Optional[str] = None	,					__snake_case     :    Optional[dict] = None	,					**__snake_case     :    Dict		):
										super().__init__(self	,					**__snake_case		)
										# always open as "rb" since fsspec can then use the TextIOWrapper to make it work for "r" mode
										lowerCamelCase						:Optional[Any]						  =     fsspec.open(
										    __snake_case	,					mode='''rb'''	,					protocol=__snake_case	,					compression=self.compression	,					client_kwargs={
										        '''requote_redirect_url''': False,  # see https://github.com/huggingface/datasets/pull/5459
										        '''trust_env''': True,  # Enable reading proxy env variables.
										        **(target_options or {}).pop('''client_kwargs'''	,					{}		),  # To avoid issues if it was already passed.
										    }	,					**(target_options or {})	,					)
										lowerCamelCase						:List[str]						  =     os.path.basename(self.file.path.split('''::'''		)[0]		)
										lowerCamelCase						:Dict						  =     (
										    self.compressed_name[: self.compressed_name.rindex('''.'''		)]
										    if '''.''' in self.compressed_name
										    else self.compressed_name
										)
										lowerCamelCase						:List[str]						  =     None







							@classmethod
							def 				snake_case  (				cls     :    Any	,					__snake_case     :    Any		):
										# compressed file paths are always relative to the archive root
										return super()._strip_protocol(__snake_case		).lstrip('''/'''		)







							def 				snake_case  (				self     :    Any		):
										if self.dir_cache is None:
													lowerCamelCase						:Optional[Any]						  =     {**self.file.fs.info(self.file.path		), '''name''': self.uncompressed_name}
													lowerCamelCase						:Optional[Any]						  =     {f['''name''']: f}







							def 				snake_case  (				self     :    Union[str, Any]	,					__snake_case     :    str		):
										return self.file.open().read()







							def 				snake_case  (				self     :    Optional[int]	,					__snake_case     :    str	,					__snake_case     :    str = "rb"	,					__snake_case     :    int=None	,					__snake_case     :    Optional[int]=True	,					__snake_case     :    str=None	,					**__snake_case     :    str	,					):
										lowerCamelCase						:List[str]						  =     self._strip_protocol(__snake_case		)
										if mode != "rb":
													raise ValueError(F"Tried to read with mode {mode} on file {self.file.path} opened with mode 'rb'"		)
										return self.file.open()


class   _lowerCAmelCase		(     __SCREAMING_SNAKE_CASE				):
							_UpperCAmelCase						    =     'bz2'
							_UpperCAmelCase						    =     'bz2'
							_UpperCAmelCase						    =     '.bz2'


class   _lowerCAmelCase		(     __SCREAMING_SNAKE_CASE				):
							_UpperCAmelCase						    =     'gzip'
							_UpperCAmelCase						    =     'gzip'
							_UpperCAmelCase						    =     '.gz'


class   _lowerCAmelCase		(     __SCREAMING_SNAKE_CASE				):
							_UpperCAmelCase						    =     'lz4'
							_UpperCAmelCase						    =     'lz4'
							_UpperCAmelCase						    =     '.lz4'


class   _lowerCAmelCase		(     __SCREAMING_SNAKE_CASE				):
							_UpperCAmelCase						    =     'xz'
							_UpperCAmelCase						    =     'xz'
							_UpperCAmelCase						    =     '.xz'


class   _lowerCAmelCase		(     __SCREAMING_SNAKE_CASE				):
							_UpperCAmelCase						    =     'zstd'
							_UpperCAmelCase						    =     'zstd'
							_UpperCAmelCase						    =     '.zst'







							def __init__(				self     :    str	,					__snake_case     :    str	,					__snake_case     :    str = "rb"	,					__snake_case     :    Optional[str] = None	,					__snake_case     :    Optional[dict] = None	,					__snake_case     :    int = DEFAULT_BLOCK_SIZE	,					**__snake_case     :    int	,					):
										super().__init__(
										    fo=__snake_case	,					mode=__snake_case	,					target_protocol=__snake_case	,					target_options=__snake_case	,					block_size=__snake_case	,					**__snake_case	,					)
										# We need to wrap the zstd decompressor to avoid this error in fsspec==2021.7.0 and zstandard==0.15.2:
										#
										# File "/Users/user/.virtualenvs/hf-datasets/lib/python3.7/site-packages/fsspec/core.py", line 145, in open
										#     out.close = close
										# AttributeError: 'zstd.ZstdDecompressionReader' object attribute 'close' is read-only
										#
										# see https://github.com/intake/filesystem_spec/issues/725
										lowerCamelCase						:Tuple						  =     self.file.__enter__
										class   _lowerCAmelCase		:







																	def __init__(				self     :    Dict	,					__snake_case     :    Tuple		):
																				lowerCamelCase						:Optional[int]						  =     file_







																	def __enter__(				self     :    Optional[int]		):
																				self._file.__enter__()
																				return self







																	def __exit__(				self     :    str	,					*__snake_case     :    Optional[Any]	,					**__snake_case     :    List[Any]		):
																				self._file.__exit__(*__snake_case	,					**__snake_case		)







																	def __iter__(				self     :    Optional[Any]		):
																				return iter(self._file		)







																	def 				snake_case  (				self     :    List[Any]		):
																				return next(self._file		)







																	def __getattr__(				self     :    Any	,					__snake_case     :    str		):
																				return getattr(self._file	,					__snake_case		)

										def fixed_enter(*__snake_case     :    Optional[int]	,					**__snake_case     :    str		):
													return WrappedFile(_enter(*__snake_case	,					**__snake_case		)		)

										lowerCamelCase						:Dict						  =     fixed_enter



