

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


a_      =     logging.get_logger(__name__)

a_      =     {
    '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 _UpperCamelCase				(				__A ):
			'''simple docstring'''







			lowerCamelCase__							     ='funnel'
			lowerCamelCase__							     ={
			    'hidden_size': 'd_model',
			    'num_attention_heads': 'n_head',
			}
			def __init__(      self				:			Optional[int]   ,   a				:			Optional[Any]=3_0522   ,   a				:			str=[4, 4, 4]   ,   a				:			Optional[Any]=None   ,   a				:			List[str]=2   ,   a				:			int=768   ,   a				:			Union[str, Any]=12   ,   a				:			List[Any]=64   ,   a				:			List[str]=3072   ,   a				:			Optional[Any]="gelu_new"   ,   a				:			Optional[int]=0.1   ,   a				:			List[Any]=0.1   ,   a				:			str=0.0   ,   a				:			Tuple=0.1   ,   a				:			Tuple=None   ,   a				:			Union[str, Any]=1e-9   ,   a				:			Optional[Any]="mean"   ,   a				:			Dict="relative_shift"   ,   a				:			Dict=True   ,   a				:			str=True   ,   a				:			Optional[int]=True   ,   **a				:			Dict   ,   )				->							List[Any]:

				"""simple docstring"""

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

				super().__init__(**a						)
			@property
			def 				__UpperCamelCase			(      self				:			List[str]						)				->							Union[str, Any]:

				"""simple docstring"""

				return sum(self.block_sizes						)
			@num_hidden_layers.setter
			def 				__UpperCamelCase			(      self				:			Union[str, Any]   ,   a				:			List[Any]						)				->							Optional[int]:

				"""simple docstring"""

				raise NotImplementedError(
				    "This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`."						)
			@property
			def 				__UpperCamelCase			(      self				:			Tuple						)				->							Union[str, Any]:

				"""simple docstring"""

				return len(self.block_sizes						)






			@num_blocks.setter
			def 				__UpperCamelCase			(      self				:			Optional[Any]   ,   a				:			Union[str, Any]						)				->							Tuple:

				"""simple docstring"""

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






import copy
import random

from transformers import CLIPTokenizer

class 							__SCREAMING_SNAKE_CASE       (  _a							):






							def __init__(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														super().__init__(*__lowerCAmelCase	,			**__lowerCAmelCase	)
														UpperCamelCase__					  =      {}






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														UpperCamelCase__					  =      super().add_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
														if num_added_tokens == 0:
																					raise ValueError(
																					    f"""The tokenizer already contains the token {placeholder_token}. Please pass a different"""
																					    """ `placeholder_token` that is not already in the tokenizer."""	)






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=1	,			**__lowerCAmelCase	):
														UpperCamelCase__					  =      []
														if num_vec_per_token == 1:
																					self.try_adding_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
																					output.append(__lowerCAmelCase	)
														else:
																					UpperCamelCase__					  =      []
																					for i in range(__lowerCAmelCase	):
																												UpperCamelCase__					  =      placeholder_token + f"""_{i}"""
																												self.try_adding_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
																												output.append(__lowerCAmelCase	)
        # handle cases where there is a new placeholder token that contains the current placeholder token but is larger
														for token in self.token_map:
																					if token in placeholder_token:
																												raise ValueError(
																												    f"""The tokenizer already has placeholder token {token} that can get confused with"""
																												    f""" {placeholder_token}keep placeholder tokens independent"""	)
														UpperCamelCase__					  =      output






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	):
														if isinstance(__lowerCAmelCase	,			__lowerCAmelCase	):
																					UpperCamelCase__					  =      []
																					for i in range(len(__lowerCAmelCase	)	):
																												output.append(self.replace_placeholder_tokens_in_text(text[i]	,			vector_shuffle=__lowerCAmelCase	)	)
																					return output
														for placeholder_token in self.token_map:
																					if placeholder_token in text:
																												UpperCamelCase__					  =      self.token_map[placeholder_token]
																												UpperCamelCase__					  =      tokens[: 1 + int(len(__lowerCAmelCase	) * prop_tokens_to_load	)]
																												if vector_shuffle:
																																			UpperCamelCase__					  =      copy.copy(__lowerCAmelCase	)
																																			random.shuffle(__lowerCAmelCase	)
																												UpperCamelCase__					  =      text.replace(__lowerCAmelCase	,			""" """.join(__lowerCAmelCase	)	)
														return text






							def __call__(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	,			**__lowerCAmelCase	):
														return super().__call__(
														    self.replace_placeholder_tokens_in_text(
														        __lowerCAmelCase	,			vector_shuffle=__lowerCAmelCase	,			prop_tokens_to_load=__lowerCAmelCase	)	,			*__lowerCAmelCase	,			**__lowerCAmelCase	,			)







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	,			**__lowerCAmelCase	):
														return super().encode(
														    self.replace_placeholder_tokens_in_text(
														        __lowerCAmelCase	,			vector_shuffle=__lowerCAmelCase	,			prop_tokens_to_load=__lowerCAmelCase	)	,			*__lowerCAmelCase	,			**__lowerCAmelCase	,			)




