






"""simple docstring"""



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


A__			:							Dict					   =   logging.get_logger(__name__)

A__			:							Optional[Any]					   =   {
    '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   lowercase__     (				snake_case__  ):
			_UpperCAmelCase						:Optional[int]       =					"""funnel"""
			_UpperCAmelCase						:Union[str, Any]       =					{
			    """hidden_size""": """d_model""",
			    """num_attention_heads""": """n_head""",
			}


			def __init__( self	:    List[Any]  ,			snake_case__	:    Union[str, Any]=3_0522  ,			snake_case__	:    str=[4, 4, 4]  ,			snake_case__	:    Any=None  ,			snake_case__	:    List[str]=2  ,			snake_case__	:    Any=768  ,			snake_case__	:    List[Any]=12  ,			snake_case__	:    str=64  ,			snake_case__	:    str=3072  ,			snake_case__	:    int="gelu_new"  ,			snake_case__	:    Optional[int]=0.1  ,			snake_case__	:    int=0.1  ,			snake_case__	:    Optional[Any]=0.0  ,			snake_case__	:    List[Any]=0.1  ,			snake_case__	:    List[Any]=None  ,			snake_case__	:    Union[str, Any]=1E-9  ,			snake_case__	:    Optional[Any]="mean"  ,			snake_case__	:    List[str]="relative_shift"  ,			snake_case__	:    int=True  ,			snake_case__	:    Optional[Any]=True  ,			snake_case__	:    int=True  ,			**snake_case__	:    Tuple  ,			):
										lowerCamelCase_			:				Optional[int]										=vocab_size
										lowerCamelCase_			:				Optional[int]										=block_sizes
										lowerCamelCase_			:				Tuple										=[1] * len(snake_case__   ) if block_repeats is None else block_repeats
										assert len(snake_case__   ) == len(
										    self.block_repeats   ), "`block_sizes` and `block_repeats` should have the same length."
										lowerCamelCase_			:				Optional[Any]										=num_decoder_layers
										lowerCamelCase_			:				Tuple										=d_model
										lowerCamelCase_			:				int										=n_head
										lowerCamelCase_			:				Any										=d_head
										lowerCamelCase_			:				Tuple										=d_inner
										lowerCamelCase_			:				Optional[Any]										=hidden_act
										lowerCamelCase_			:				List[str]										=hidden_dropout
										lowerCamelCase_			:				Any										=attention_dropout
										lowerCamelCase_			:				List[str]										=activation_dropout
										lowerCamelCase_			:				Any										=initializer_range
										lowerCamelCase_			:				str										=initializer_std
										lowerCamelCase_			:				List[Any]										=layer_norm_eps
										assert pooling_type in [
										    "mean",
										    "max",
										], F"""Got {pooling_type} for `pooling_type` but only 'mean' and 'max' are supported."""
										lowerCamelCase_			:				Optional[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."""
										lowerCamelCase_			:				int										=attention_type
										lowerCamelCase_			:				List[str]										=separate_cls
										lowerCamelCase_			:				Union[str, Any]										=truncate_seq
										lowerCamelCase_			:				Any										=pool_q_only

										super().__init__(**snake_case__   )


			@property
			def       UpperCAmelCase__		( self	:    Optional[int]   ):
										return sum(self.block_sizes   )


			@num_hidden_layers.setter
			def       UpperCAmelCase__		( self	:    Any  ,			snake_case__	:    Any   ):
										raise NotImplementedError(
										    "This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`."   )


			@property
			def       UpperCAmelCase__		( self	:    Tuple   ):
										return len(self.block_sizes   )


			@num_blocks.setter
			def       UpperCAmelCase__		( self	:    Optional[int]  ,			snake_case__	:    int   ):
										raise NotImplementedError("This model does not support the setting of `num_blocks`. Please set `block_sizes`."   )







import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)



class 						_UpperCAmelCase      (     unittest.TestCase							):






		def _snake_case		(						self				:     Union[str, Any]):
				SCREAMING_SNAKE_CASE_				:Optional[int]				     =						["a", "b", "c"]

				# Defaults to last layer if both are None
				SCREAMING_SNAKE_CASE_     ,				SCREAMING_SNAKE_CASE_				:Dict				     =						get_aligned_output_features_output_indices(UpperCAmelCase   ,  UpperCAmelCase   ,  UpperCAmelCase)
				self.assertEqual(UpperCAmelCase   ,  ["c"])
				self.assertEqual(UpperCAmelCase   ,  [2])

				# Out indices set to match out features
				SCREAMING_SNAKE_CASE_     ,				SCREAMING_SNAKE_CASE_				:Tuple				     =						get_aligned_output_features_output_indices(["a", "c"]   ,  UpperCAmelCase   ,  UpperCAmelCase)
				self.assertEqual(UpperCAmelCase   ,  ["a", "c"])
				self.assertEqual(UpperCAmelCase   ,  [0, 2])

				# Out features set to match out indices
				SCREAMING_SNAKE_CASE_     ,				SCREAMING_SNAKE_CASE_				:int				     =						get_aligned_output_features_output_indices(UpperCAmelCase   ,  [0, 2]   ,  UpperCAmelCase)
				self.assertEqual(UpperCAmelCase   ,  ["a", "c"])
				self.assertEqual(UpperCAmelCase   ,  [0, 2])

				# Out features selected from negative indices
				SCREAMING_SNAKE_CASE_     ,				SCREAMING_SNAKE_CASE_				:Any				     =						get_aligned_output_features_output_indices(UpperCAmelCase   ,  [-3, -1]   ,  UpperCAmelCase)
				self.assertEqual(UpperCAmelCase   ,  ["a", "c"])
				self.assertEqual(UpperCAmelCase   ,  [-3, -1])






		def _snake_case		(						self				:     str):
				# Stage names must be set
				with self.assertRaises(UpperCAmelCase):
						verify_out_features_out_indices(["a", "b"]   ,  (0, 1)   ,  UpperCAmelCase)

				# Out features must be a list
				with self.assertRaises(UpperCAmelCase):
						verify_out_features_out_indices(("a", "b")   ,  (0, 1)   ,  ["a", "b"])

				# Out features must be a subset of stage names
				with self.assertRaises(UpperCAmelCase):
						verify_out_features_out_indices(["a", "b"]   ,  (0, 1)   ,  ["a"])

				# Out indices must be a list or tuple
				with self.assertRaises(UpperCAmelCase):
						verify_out_features_out_indices(UpperCAmelCase   ,  0   ,  ["a", "b"])

				# Out indices must be a subset of stage names
				with self.assertRaises(UpperCAmelCase):
						verify_out_features_out_indices(UpperCAmelCase   ,  (0, 1)   ,  ["a"])

				# Out features and out indices must be the same length
				with self.assertRaises(UpperCAmelCase):
						verify_out_features_out_indices(["a", "b"]   ,  (0,)   ,  ["a", "b", "c"])

				# Out features should match out indices
				with self.assertRaises(UpperCAmelCase):
						verify_out_features_out_indices(["a", "b"]   ,  (0, 2)   ,  ["a", "b", "c"])

				# Out features and out indices should be in order
				with self.assertRaises(UpperCAmelCase):
						verify_out_features_out_indices(["b", "a"]   ,  (0, 1)   ,  ["a", "b"])

				# Check passes with valid inputs
				verify_out_features_out_indices(["a", "b", "d"]   ,  (0, 1, -1)   ,  ["a", "b", "c", "d"])







		def _snake_case		(						self				:     Tuple):
				SCREAMING_SNAKE_CASE_				:int				     =						BackboneMixin()

				SCREAMING_SNAKE_CASE_				:List[str]				     =						["a", "b", "c"]
				SCREAMING_SNAKE_CASE_				:str				     =						["a", "c"]
				SCREAMING_SNAKE_CASE_				:Union[str, Any]				     =						[0, 2]

				# Check that the output features and indices are set correctly
				self.assertEqual(backbone.out_features   ,  ["a", "c"])
				self.assertEqual(backbone.out_indices   ,  [0, 2])

				# Check out features and indices are updated correctly
				SCREAMING_SNAKE_CASE_				:Tuple				     =						["a", "b"]
				self.assertEqual(backbone.out_features   ,  ["a", "b"])
				self.assertEqual(backbone.out_indices   ,  [0, 1])

				SCREAMING_SNAKE_CASE_				:List[str]				     =						[-3, -1]
				self.assertEqual(backbone.out_features   ,  ["a", "c"])
				self.assertEqual(backbone.out_indices   ,  [-3, -1])






