


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


A							:					Optional[int]     						=     logging.get_logger(__name__)

A							:					List[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     UpperCamelCase(  _a   ):
					snake_case_		:				int										=	"""funnel"""
					snake_case_		:				Any										=	{
					    """hidden_size""": """d_model""",
					    """num_attention_heads""": """n_head""",
					}


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




											'''simple docstring'''

											__snake_case				=		vocab_size
											__snake_case				=		block_sizes
											__snake_case				=		[1] * len(lowercase_						) if block_repeats is None else block_repeats
											assert len(lowercase_						) == len(
											    self.block_repeats						), "`block_sizes` and `block_repeats` should have the same length."
											__snake_case				=		num_decoder_layers
											__snake_case				=		d_model
											__snake_case				=		n_head
											__snake_case				=		d_head
											__snake_case				=		d_inner
											__snake_case				=		hidden_act
											__snake_case				=		hidden_dropout
											__snake_case				=		attention_dropout
											__snake_case				=		activation_dropout
											__snake_case				=		initializer_range
											__snake_case				=		initializer_std
											__snake_case				=		layer_norm_eps
											assert pooling_type in [
											    "mean",
											    "max",
											], f'''Got {pooling_type} for `pooling_type` but only \'mean\' and \'max\' are supported.'''
											__snake_case				=		pooling_type
											assert attention_type in [
											    "relative_shift",
											    "factorized",
											], f'''Got {attention_type} for `attention_type` but only \'relative_shift\' and \'factorized\' are supported.'''
											__snake_case				=		attention_type
											__snake_case				=		separate_cls
											__snake_case				=		truncate_seq
											__snake_case				=		pool_q_only

											super().__init__(**lowercase_						)


					@property
					def 							SCREAMING_SNAKE_CASE_  (						self	:		str						)			->	Dict:




											'''simple docstring'''

											return sum(self.block_sizes						)


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




											'''simple docstring'''

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


					@property
					def 							SCREAMING_SNAKE_CASE_  (						self	:		Any						)			->	Dict:




											'''simple docstring'''

											return len(self.block_sizes						)






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




											'''simple docstring'''

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









import itertools
import string
from collections.abc import Generator, Iterable





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	Generator[tuple[str, ...], None, None]:


						'''simple docstring'''






						__snake_case				=		iter(_lowerCAmelCase )
						while True:
												__snake_case				=		tuple(itertools.islice(_lowerCAmelCase      ,	_lowerCAmelCase ) )
												if not chunk:
																		return
												yield chunk





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	str:


						'''simple docstring'''






						__snake_case				=		"".join([c.upper() for c in dirty if c in string.ascii_letters] )
						__snake_case				=		""

						if len(_lowerCAmelCase ) < 2:
												return dirty

						for i in range(len(_lowerCAmelCase ) - 1 ):
												clean += dirty[i]

												if dirty[i] == dirty[i + 1]:
																		clean += "X"

						clean += dirty[-1]

						if len(_lowerCAmelCase ) & 1:
												clean += "X"

						return clean





def 	_lowerCAmelCase       (    _lowerCAmelCase )						->	list[str]:


						'''simple docstring'''






						__snake_case				=		"ABCDEFGHIKLMNOPQRSTUVWXYZ"
						# we're using a list instead of a '2d' array because it makes the math
						# for setting up the table and doing the actual encoding/decoding simpler
						__snake_case				=		[]

						# copy key chars into the table if they are in `alphabet` ignoring duplicates
						for char in key.upper():
												if char not in table and char in alphabet:
																		table.append(_lowerCAmelCase )

    # fill the rest of the table in with the remaining alphabet chars
						for char in alphabet:
												if char not in table:
																		table.append(_lowerCAmelCase )

						return table





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	str:


						'''simple docstring'''






						__snake_case				=		generate_table(_lowerCAmelCase )
						__snake_case				=		prepare_input(_lowerCAmelCase )
						__snake_case				=		""

						# https://en.wikipedia.org/wiki/Playfair_cipher#Description
						for chara, chara in chunker(_lowerCAmelCase      ,	2 ):
												__snake_case		,					__snake_case				=		divmod(table.index(_lowerCAmelCase )      ,	5 )
												__snake_case		,					__snake_case				=		divmod(table.index(_lowerCAmelCase )      ,	5 )

												if rowa == rowa:
																		ciphertext += table[rowa * 5 + (cola + 1) % 5]
																		ciphertext += table[rowa * 5 + (cola + 1) % 5]
												elif cola == cola:
																		ciphertext += table[((rowa + 1) % 5) * 5 + cola]
																		ciphertext += table[((rowa + 1) % 5) * 5 + cola]
												else:  # rectangle
																		ciphertext += table[rowa * 5 + cola]
																		ciphertext += table[rowa * 5 + cola]

						return ciphertext





def 	_lowerCAmelCase       (    _lowerCAmelCase      ,	_lowerCAmelCase )						->	str:


						'''simple docstring'''






						__snake_case				=		generate_table(_lowerCAmelCase )
						__snake_case				=		""

						# https://en.wikipedia.org/wiki/Playfair_cipher#Description
						for chara, chara in chunker(_lowerCAmelCase      ,	2 ):
												__snake_case		,					__snake_case				=		divmod(table.index(_lowerCAmelCase )      ,	5 )
												__snake_case		,					__snake_case				=		divmod(table.index(_lowerCAmelCase )      ,	5 )

												if rowa == rowa:
																		plaintext += table[rowa * 5 + (cola - 1) % 5]
																		plaintext += table[rowa * 5 + (cola - 1) % 5]
												elif cola == cola:
																		plaintext += table[((rowa - 1) % 5) * 5 + cola]
																		plaintext += table[((rowa - 1) % 5) * 5 + cola]
												else:  # rectangle
																		plaintext += table[rowa * 5 + cola]
																		plaintext += table[rowa * 5 + cola]

						return plaintext





