



from pathlib import PurePosixPath
from typing import Optional

import fsspec
from fsspec import AbstractFileSystem
from huggingface_hub.hf_api import DatasetInfo

from ..utils.file_utils import get_authentication_headers_for_url
from ..utils.hub import hf_hub_url


class 	lowerCamelCase__	(       _A):



 """simple docstring"""

 a__					: Union[str, Any] =  ""
 a__					: Optional[int] =  "hf-legacy"  # "hf://"" is reserved for hffs

 def __init__(    self					:					List[str]			,						__lowerCAmelCase					:					Optional[DatasetInfo] = None			,						__lowerCAmelCase					:					Optional[str] = None			,						**__lowerCAmelCase					:					str			,						)   ->	Tuple:
    super().__init__(self			,						**__lowerCAmelCase      )
    _A      =       repo_info
    _A      =       token
    _A      =       None

 def     snake_case_      (    self					:					Dict      )   ->	str:
    if self.dir_cache is None:
       _A      =       {}
       for hf_file in self.repo_info.siblings:
          # TODO(QL): add sizes
          _A      =       {
              '''name''': hf_file.rfilename,
              '''size''': None,
              '''type''': '''file''',
          }
          self.dir_cache.update(
              {
                  str(__lowerCAmelCase      ): {'''name''': str(__lowerCAmelCase      ), '''size''': None, '''type''': '''directory'''}
                  for d in list(PurePosixPath(hf_file.rfilename      ).parents      )[:-1]
              }      )

 def     snake_case_      (    self					:					List[str]			,						__lowerCAmelCase					:					str			,						__lowerCAmelCase					:					str = "rb"			,						**__lowerCAmelCase					:					Tuple			,						)   ->	Dict:
    if not isinstance(self.repo_info			,						__lowerCAmelCase      ):
       raise NotImplementedError(f'''Open is only implemented for dataset repositories, but got {self.repo_info}'''      )
    _A      =       hf_hub_url(self.repo_info.id			,						__lowerCAmelCase			,						revision=self.repo_info.sha      )
    return fsspec.open(
        __lowerCAmelCase			,						mode=__lowerCAmelCase			,						headers=get_authentication_headers_for_url(__lowerCAmelCase			,						use_auth_token=self.token      )			,						client_kwargs={'''trust_env''': True}			,						).open()

 def     snake_case_      (    self					:					Optional[int]			,						__lowerCAmelCase					:					List[str]			,						**__lowerCAmelCase					:					int      )   ->	Optional[Any]:
    self._get_dirs()
    _A      =       self._strip_protocol(__lowerCAmelCase      )
    if path in self.dir_cache:
       return self.dir_cache[path]
    else:
       raise FileNotFoundError(__lowerCAmelCase      )

 def     snake_case_      (    self					:					Tuple			,						__lowerCAmelCase					:					str			,						__lowerCAmelCase					:					int=False			,						**__lowerCAmelCase					:					Any      )   ->	Union[str, Any]:
    self._get_dirs()
    _A      =       PurePosixPath(path.strip('''/'''      )      )
    _A      =       {}
    for p, f in self.dir_cache.items():
       _A      =       PurePosixPath(p.strip('''/'''      )      )
       _A      =       p.parent
       if root == path:
          _A      =       f
    _A      =       list(paths.values()      )
    if detail:
       return out
    else:
       return sorted(f['''name'''] for f in out      )








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 	lowerCamelCase__	(       _A):



 """simple docstring"""

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

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

    _A      =       initializer_range
    _A      =       layer_norm_eps

    _A      =       dropout
    _A      =       mem_len
    _A      =       reuse_len
    _A      =       bi_data
    _A      =       clamp_len
    _A      =       same_length

    _A      =       summary_type
    _A      =       summary_use_proj
    _A      =       summary_activation
    _A      =       summary_last_dropout
    _A      =       start_n_top
    _A      =       end_n_top

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

    _A      =       use_mems_eval
    _A      =       use_mems_train
    super().__init__(pad_token_id=__lowerCAmelCase			,						bos_token_id=__lowerCAmelCase			,						eos_token_id=__lowerCAmelCase			,						**__lowerCAmelCase      )

 @property
 def     snake_case_      (    self					:					Optional[Any]      )   ->	Union[str, 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     snake_case_      (    self					:					Tuple			,						__lowerCAmelCase					:					Optional[Any]      )   ->	Dict:
    # 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.'''      )



