


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   __a      (   __UpperCamelCase				):
 __lowercase			:							Tuple       					=			''
 __lowercase			:							Union[str, Any]       					=			'hf-legacy'  # "hf://"" is reserved for hffs
 def __init__(       self    ,			lowerCAmelCase__ = None    ,			lowerCAmelCase__ = None    ,			**lowerCAmelCase__    ,			) ->    Any:




        '''simple docstring'''
        super().__init__(self    ,			**lowerCAmelCase__			)
        lowercase__:       Tuple        =       repo_info
        lowercase__:       List[Any]        =       token
        lowercase__:       Optional[Any]        =       None
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    int:




        '''simple docstring'''
        if self.dir_cache is None:
               lowercase__:       Optional[int]        =       {}
               for hf_file in self.repo_info.siblings:
                      # TODO(QL): add sizes
                      lowercase__:       List[str]        =       {
                          '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 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__ = "rb"    ,			**lowerCAmelCase__    ,			) ->    Tuple:




        '''simple docstring'''
        if not isinstance(self.repo_info    ,			lowerCAmelCase__			):
               raise NotImplementedError(F'Open is only implemented for dataset repositories, but got {self.repo_info}'			)
        lowercase__:       Tuple        =       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 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			**lowerCAmelCase__			) ->    str:




        '''simple docstring'''
        self._get_dirs()
        lowercase__:       Optional[int]        =       self._strip_protocol(lowerCAmelCase__			)
        if path in self.dir_cache:
               return self.dir_cache[path]
        else:
               raise FileNotFoundError(lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__=False    ,			**lowerCAmelCase__			) ->    Dict:




        '''simple docstring'''
        self._get_dirs()
        lowercase__:       List[str]        =       PurePosixPath(path.strip('/'			)			)
        lowercase__:       Any        =       {}
        for p, f in self.dir_cache.items():
               lowercase__:       str        =       PurePosixPath(p.strip('/'			)			)
               lowercase__:       Optional[int]        =       p.parent
               if root == path:
                      lowercase__:       Optional[Any]        =       f
        lowercase__:       List[Any]        =       list(paths.values()			)
        if detail:
               return out
        else:
               return sorted(f['name'] for f in out			)






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


__lowerCAmelCase			=							logging.get_logger(__name__)

__lowerCAmelCase			=							{
    '''google/pegasus-large''': '''https://huggingface.co/google/pegasus-large/resolve/main/config.json''',
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}





class   __a      (   __UpperCamelCase				):
 __lowercase			:							Any       					=			'pegasus'
 __lowercase			:							Union[str, Any]       					=			['past_key_values']
 __lowercase			:							Any       					=			{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}
 def __init__(       self    ,			lowerCAmelCase__=50_265    ,			lowerCAmelCase__=1_024    ,			lowerCAmelCase__=12    ,			lowerCAmelCase__=4_096    ,			lowerCAmelCase__=16    ,			lowerCAmelCase__=12    ,			lowerCAmelCase__=4_096    ,			lowerCAmelCase__=16    ,			lowerCAmelCase__=0.0    ,			lowerCAmelCase__=0.0    ,			lowerCAmelCase__=True    ,			lowerCAmelCase__=True    ,			lowerCAmelCase__="gelu"    ,			lowerCAmelCase__=1_024    ,			lowerCAmelCase__=0.1    ,			lowerCAmelCase__=0.0    ,			lowerCAmelCase__=0.0    ,			lowerCAmelCase__=0.0_2    ,			lowerCAmelCase__=0    ,			lowerCAmelCase__=False    ,			lowerCAmelCase__=0    ,			lowerCAmelCase__=1    ,			lowerCAmelCase__=1    ,			**lowerCAmelCase__    ,			) ->    Union[str, Any]:




        '''simple docstring'''
        lowercase__:       int        =       vocab_size
        lowercase__:       Optional[int]        =       max_position_embeddings
        lowercase__:       List[str]        =       d_model
        lowercase__:       Optional[Any]        =       encoder_ffn_dim
        lowercase__:       Optional[Any]        =       encoder_layers
        lowercase__:       Union[str, Any]        =       encoder_attention_heads
        lowercase__:       Optional[int]        =       decoder_ffn_dim
        lowercase__:       Tuple        =       decoder_layers
        lowercase__:       Union[str, Any]        =       decoder_attention_heads
        lowercase__:       Dict        =       dropout
        lowercase__:       List[str]        =       attention_dropout
        lowercase__:       List[str]        =       activation_dropout
        lowercase__:       Optional[int]        =       activation_function
        lowercase__:       Dict        =       init_std
        lowercase__:       Optional[Any]        =       encoder_layerdrop
        lowercase__:       List[str]        =       decoder_layerdrop
        lowercase__:       Union[str, Any]        =       use_cache
        lowercase__:       Any        =       encoder_layers
        lowercase__:       List[str]        =       scale_embedding  # scale factor will be sqrt(d_model) if True
        super().__init__(
            pad_token_id=lowerCAmelCase__    ,			eos_token_id=lowerCAmelCase__    ,			is_encoder_decoder=lowerCAmelCase__    ,			decoder_start_token_id=lowerCAmelCase__    ,			forced_eos_token_id=lowerCAmelCase__    ,			**lowerCAmelCase__    ,			)
 @property
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    int:




        '''simple docstring'''
        return self.encoder_attention_heads
 @property
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    int:




        '''simple docstring'''
        return self.d_model


