


'''simple docstring'''







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


A__:    int					    =       logging.get_logger(__name__)

A__:    Optional[int]					    =       {
    '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/config.json''',
    '''funnel-transformer/small-base''': '''https://huggingface.co/funnel-transformer/small-base/resolve/main/config.json''',
    '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/config.json''',
    '''funnel-transformer/medium-base''': '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/config.json''',
    '''funnel-transformer/intermediate''': (
        '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/config.json'''
    ),
    '''funnel-transformer/intermediate-base''': (
        '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/config.json'''
    ),
    '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/config.json''',
    '''funnel-transformer/large-base''': '''https://huggingface.co/funnel-transformer/large-base/resolve/main/config.json''',
    '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/config.json''',
    '''funnel-transformer/xlarge-base''': '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/config.json''',
}







class A__       (						UpperCAmelCase__      ):
      __UpperCamelCase       :  Tuple	       =							"funnel"
      __UpperCamelCase       :  Tuple	       =							{
          "hidden_size": "d_model",
          "num_attention_heads": "n_head",
      }






      def __init__( self			:str     ,						SCREAMING_SNAKE_CASE			:List[str]=3_0_5_2_2     ,						SCREAMING_SNAKE_CASE			:Optional[int]=[4, 4, 4]     ,						SCREAMING_SNAKE_CASE			:List[str]=None     ,						SCREAMING_SNAKE_CASE			:int=2     ,						SCREAMING_SNAKE_CASE			:int=7_6_8     ,						SCREAMING_SNAKE_CASE			:Optional[int]=1_2     ,						SCREAMING_SNAKE_CASE			:Optional[Any]=6_4     ,						SCREAMING_SNAKE_CASE			:Dict=3_0_7_2     ,						SCREAMING_SNAKE_CASE			:Any="gelu_new"     ,						SCREAMING_SNAKE_CASE			:Any=0.1     ,						SCREAMING_SNAKE_CASE			:str=0.1     ,						SCREAMING_SNAKE_CASE			:List[Any]=0.0     ,						SCREAMING_SNAKE_CASE			:Dict=0.1     ,						SCREAMING_SNAKE_CASE			:Any=None     ,						SCREAMING_SNAKE_CASE			:List[Any]=1e-9     ,						SCREAMING_SNAKE_CASE			:Union[str, Any]="mean"     ,						SCREAMING_SNAKE_CASE			:Optional[int]="relative_shift"     ,						SCREAMING_SNAKE_CASE			:Tuple=True     ,						SCREAMING_SNAKE_CASE			:Union[str, Any]=True     ,						SCREAMING_SNAKE_CASE			:int=True     ,						**SCREAMING_SNAKE_CASE			:List[str]     ,						)       ->					Tuple:




             '''simple docstring'''
             _a    : str     					=vocab_size
             _a    : List[Any]     					=block_sizes
             _a    : Tuple     					=[1] * len(SCREAMING_SNAKE_CASE	) if block_repeats is None else block_repeats
             assert len(SCREAMING_SNAKE_CASE	) == len(
                 self.block_repeats	), "`block_sizes` and `block_repeats` should have the same length."
             _a    : List[str]     					=num_decoder_layers
             _a    : List[Any]     					=d_model
             _a    : Tuple     					=n_head
             _a    : str     					=d_head
             _a    : int     					=d_inner
             _a    : Optional[Any]     					=hidden_act
             _a    : Optional[Any]     					=hidden_dropout
             _a    : List[Any]     					=attention_dropout
             _a    : int     					=activation_dropout
             _a    : Optional[int]     					=initializer_range
             _a    : str     					=initializer_std
             _a    : Tuple     					=layer_norm_eps
             assert pooling_type in [
                 "mean",
                 "max",
             ], f"Got {pooling_type} for `pooling_type` but only 'mean' and 'max' are supported."
             _a    : int     					=pooling_type
             assert attention_type in [
                 "relative_shift",
                 "factorized",
             ], f"Got {attention_type} for `attention_type` but only 'relative_shift' and 'factorized' are supported."
             _a    : Optional[Any]     					=attention_type
             _a    : Any     					=separate_cls
             _a    : Optional[int]     					=truncate_seq
             _a    : Dict     					=pool_q_only

             super().__init__(**SCREAMING_SNAKE_CASE	)






      @property
      def __UpperCAmelCase       ( self			:int	)       ->					Dict:




             '''simple docstring'''
             return sum(self.block_sizes	)






      @num_hidden_layers.setter
      def __UpperCAmelCase       ( self			:List[str]     ,						SCREAMING_SNAKE_CASE			:Any	)       ->					Optional[Any]:




             '''simple docstring'''
             raise NotImplementedError(
                 """This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`."""	)






      @property
      def __UpperCAmelCase       ( self			:Tuple	)       ->					Any:




             '''simple docstring'''
             return len(self.block_sizes	)






      @num_blocks.setter
      def __UpperCAmelCase       ( self			:List[Any]     ,						SCREAMING_SNAKE_CASE			:Tuple	)       ->					Dict:




             '''simple docstring'''
             raise NotImplementedError("""This model does not support the setting of `num_blocks`. Please set `block_sizes`."""	)






'''simple docstring'''







import pytest

from datasets.utils.sharding import _distribute_shards, _number_of_shards_in_gen_kwargs, _split_gen_kwargs


@pytest.mark.parametrize(
    """kwargs, expected"""    ,[
        ({"""num_shards""": 0, """max_num_jobs""": 1}, []),
        ({"""num_shards""": 10, """max_num_jobs""": 1}, [range(10  )]),
        ({"""num_shards""": 10, """max_num_jobs""": 10}, [range(_UpperCAmelCase    ,i + 1  ) for i in range(10  )]),
        ({"""num_shards""": 1, """max_num_jobs""": 10}, [range(1  )]),
        ({"""num_shards""": 10, """max_num_jobs""": 3}, [range(0    ,4  ), range(4    ,7  ), range(7    ,10  )]),
        ({"""num_shards""": 3, """max_num_jobs""": 10}, [range(0    ,1  ), range(1    ,2  ), range(2    ,3  )]),
    ]    ,)
def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	Union[str, Any]    ,_UpperCAmelCase	:	Dict  )  ->			Optional[Any]:
       _a    : Tuple     					=_distribute_shards(**_UpperCAmelCase  )
       assert out == expected


@pytest.mark.parametrize(
    """gen_kwargs, max_num_jobs, expected"""    ,[
        ({"""foo""": 0}, 10, [{"""foo""": 0}]),
        ({"""shards""": [0, 1, 2, 3]}, 1, [{"""shards""": [0, 1, 2, 3]}]),
        ({"""shards""": [0, 1, 2, 3]}, 4, [{"""shards""": [0]}, {"""shards""": [1]}, {"""shards""": [2]}, {"""shards""": [3]}]),
        ({"""shards""": [0, 1]}, 4, [{"""shards""": [0]}, {"""shards""": [1]}]),
        ({"""shards""": [0, 1, 2, 3]}, 2, [{"""shards""": [0, 1]}, {"""shards""": [2, 3]}]),
    ]    ,)
def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	Tuple    ,_UpperCAmelCase	:	List[Any]    ,_UpperCAmelCase	:	Union[str, Any]  )  ->			List[str]:
       _a    : List[str]     					=_split_gen_kwargs(_UpperCAmelCase    ,_UpperCAmelCase  )
       assert out == expected


@pytest.mark.parametrize(
    """gen_kwargs, expected"""    ,[
        ({"""foo""": 0}, 1),
        ({"""shards""": [0]}, 1),
        ({"""shards""": [0, 1, 2, 3]}, 4),
        ({"""shards""": [0, 1, 2, 3], """foo""": 0}, 4),
        ({"""shards""": [0, 1, 2, 3], """other""": (0, 1)}, 4),
        ({"""shards""": [0, 1, 2, 3], """shards2""": [0, 1]}, RuntimeError),
    ]    ,)
def 	SCREAMING_SNAKE_CASE_					(  _UpperCAmelCase	:	Optional[Any]    ,_UpperCAmelCase	:	List[Any]  )  ->			Union[str, Any]:
       if expected is RuntimeError:
              with pytest.raises(_UpperCAmelCase  ):
                     _number_of_shards_in_gen_kwargs(_UpperCAmelCase  )
       else:
              _a    : Dict     					=_number_of_shards_in_gen_kwargs(_UpperCAmelCase  )
              assert out == expected


