

from collections import deque
from math import floor
from random import random
from time import time

class 							UpperCAmelCase_						:
							"""simple docstring"""







							def __init__(     self			)       ->       List[str]:
												_a      :       Any   =						{}


							def 							__lowercase							(     self			,				_a			,				_a			,				_a=1			)       ->       Tuple:
												if self.graph.get(_a			):
																	if self.graph[u].count([w, v]			) == 0:
																						self.graph[u].append([w, v]			)
												else:
																	_a      :       Union[str, Any]   =						[[w, v]]
												if not self.graph.get(_a			):
																	_a      :       Dict   =						[]


							def 							__lowercase							(     self			)       ->       Union[str, Any]:
												return list(self.graph			)


							def 							__lowercase							(     self			,				_a			,				_a			)       ->       Optional[Any]:
												if self.graph.get(_a			):
																	for _ in self.graph[u]:
																						if _[1] == v:
																											self.graph[u].remove(_a			)


							def 							__lowercase							(     self			,				_a=-2			,				_a=-1			)       ->       Dict:
												if s == d:
																	return []
												_a      :       Optional[int]   =						[]
												_a      :       int   =						[]
												if s == -2:
																	_a      :       Optional[int]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Union[str, Any]   =						s

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       Union[str, Any]   =						s
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																if node[1] == d:
																																					visited.append(_a			)
																																					return visited
																																else:
																																					stack.append(node[1]			)
																																					visited.append(node[1]			)
																																					_a      :       List[str]   =						node[1]
																																					break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						if len(_a			) != 0:
																											_a      :       Any   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Dict   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return visited


							def 							__lowercase							(     self			,				_a=-1			)       ->       List[str]:
												if c == -1:
																	_a      :       List[str]   =						floor(random() * 1_0_0_0_0			) + 1_0
												for i in range(_a			):
																	# every vertex has max 100 edges
																	for _ in range(floor(random() * 1_0_2			) + 1			):
																						_a      :       Optional[Any]   =						floor(random() * c			) + 1
																						if n != i:
																											self.add_pair(_a			,				_a			,				1			)


							def 							__lowercase							(     self			,				_a=-2			)       ->       List[Any]:
												_a      :       Any   =						deque()
												_a      :       List[str]   =						[]
												if s == -2:
																	_a      :       Any   =						list(self.graph			)[0]
												d.append(_a			)
												visited.append(_a			)
												while d:
																	_a      :       Optional[Any]   =						d.popleft()
																	if len(self.graph[s]			) != 0:
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																d.append(node[1]			)
																																visited.append(node[1]			)
												return visited


							def 							__lowercase							(     self			,				_a			)       ->       Optional[Any]:
												_a      :       Optional[int]   =						0
												for x in self.graph:
																	for y in self.graph[x]:
																						if y[1] == u:
																											count += 1
												return count


							def 							__lowercase							(     self			,				_a			)       ->       int:
												return len(self.graph[u]			)


							def 							__lowercase							(     self			,				_a=-2			)       ->       int:
												_a      :       str   =						[]
												_a      :       str   =						[]
												if s == -2:
																	_a      :       Any   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Dict   =						s
												_a      :       Union[str, Any]   =						[]

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       int   =						s
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       Optional[int]   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						sorted_nodes.append(stack.pop()			)
																						if len(_a			) != 0:
																											_a      :       List[Any]   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Dict   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return sorted_nodes


							def 							__lowercase							(     self			)       ->       Any:
												_a      :       List[str]   =						[]
												_a      :       Optional[Any]   =						[]
												_a      :       Optional[Any]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Any   =						-2
												_a      :       Optional[int]   =						[]
												_a      :       str   =						s
												_a      :       List[Any]   =						False
												_a      :       Optional[int]   =						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       Optional[Any]   =						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]			) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]			) > 0
																											    and not on_the_way_back
																											):
																																_a      :       int   =						len(_a			) - 1
																																while len_stack >= 0:
																																					if stack[len_stack] == node[1]:
																																										anticipating_nodes.add(node[1]			)
																																										break
																																					else:
																																										anticipating_nodes.add(stack[len_stack]			)
																																										len_stack -= 1
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       Optional[int]   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						_a      :       Union[str, Any]   =						True
																						if len(_a			) != 0:
																											_a      :       Any   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Optional[int]   =						False
																						indirect_parents.append(_a			)
																						_a      :       Dict   =						s
																						_a      :       Union[str, Any]   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return list(_a			)


							def 							__lowercase							(     self			)       ->       Any:
												_a      :       Any   =						[]
												_a      :       Union[str, Any]   =						[]
												_a      :       List[str]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       List[str]   =						-2
												_a      :       Dict   =						[]
												_a      :       str   =						s
												_a      :       Optional[Any]   =						False
												_a      :       str   =						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       str   =						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]			) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]			) > 0
																											    and not on_the_way_back
																											):
																																_a      :       int   =						len(_a			) - 1
																																while len_stack_minus_one >= 0:
																																					if stack[len_stack_minus_one] == node[1]:
																																										anticipating_nodes.add(node[1]			)
																																										break
																																					else:
																																										return True
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       Any   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						_a      :       Optional[Any]   =						True
																						if len(_a			) != 0:
																											_a      :       Tuple   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Union[str, Any]   =						False
																						indirect_parents.append(_a			)
																						_a      :       Union[str, Any]   =						s
																						_a      :       List[Any]   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return False


							def 							__lowercase							(     self			,				_a=-2			,				_a=-1			)       ->       List[str]:
												_a      :       Dict   =						time()
												self.dfs(_a			,				_a			)
												_a      :       Tuple   =						time()
												return end - begin




							def 							__lowercase							(     self			,				_a=-2			)       ->       Optional[int]:
												_a      :       int   =						time()
												self.bfs(_a			)
												_a      :       List[Any]   =						time()
												return end - begin



class 							UpperCAmelCase_						:
							"""simple docstring"""







							def __init__(     self			)       ->       Optional[Any]:
												_a      :       Union[str, Any]   =						{}


							def 							__lowercase							(     self			,				_a			,				_a			,				_a=1			)       ->       List[Any]:
												# check if the u exists
												if self.graph.get(_a			):
																	# if there already is a edge
																	if self.graph[u].count([w, v]			) == 0:
																						self.graph[u].append([w, v]			)
												else:
																	# if u does not exist
																	_a      :       int   =						[[w, v]]
												# add the other way
												if self.graph.get(_a			):
																	# if there already is a edge
																	if self.graph[v].count([w, u]			) == 0:
																						self.graph[v].append([w, u]			)
												else:
																	# if u does not exist
																	_a      :       int   =						[[w, u]]


							def 							__lowercase							(     self			,				_a			,				_a			)       ->       List[Any]:
												if self.graph.get(_a			):
																	for _ in self.graph[u]:
																						if _[1] == v:
																											self.graph[u].remove(_a			)
        # the other way round
												if self.graph.get(_a			):
																	for _ in self.graph[v]:
																						if _[1] == u:
																											self.graph[v].remove(_a			)


							def 							__lowercase							(     self			,				_a=-2			,				_a=-1			)       ->       Any:
												if s == d:
																	return []
												_a      :       str   =						[]
												_a      :       Optional[Any]   =						[]
												if s == -2:
																	_a      :       List[str]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       List[Any]   =						s

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       Optional[Any]   =						s
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																if node[1] == d:
																																					visited.append(_a			)
																																					return visited
																																else:
																																					stack.append(node[1]			)
																																					visited.append(node[1]			)
																																					_a      :       Optional[Any]   =						node[1]
																																					break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						if len(_a			) != 0:
																											_a      :       Dict   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Union[str, Any]   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return visited


							def 							__lowercase							(     self			,				_a=-1			)       ->       int:
												if c == -1:
																	_a      :       Any   =						floor(random() * 1_0_0_0_0			) + 1_0
												for i in range(_a			):
																	# every vertex has max 100 edges
																	for _ in range(floor(random() * 1_0_2			) + 1			):
																						_a      :       Optional[Any]   =						floor(random() * c			) + 1
																						if n != i:
																											self.add_pair(_a			,				_a			,				1			)


							def 							__lowercase							(     self			,				_a=-2			)       ->       Tuple:
												_a      :       Optional[Any]   =						deque()
												_a      :       List[Any]   =						[]
												if s == -2:
																	_a      :       int   =						list(self.graph			)[0]
												d.append(_a			)
												visited.append(_a			)
												while d:
																	_a      :       List[Any]   =						d.popleft()
																	if len(self.graph[s]			) != 0:
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																d.append(node[1]			)
																																visited.append(node[1]			)
												return visited


							def 							__lowercase							(     self			,				_a			)       ->       Optional[Any]:
												return len(self.graph[u]			)


							def 							__lowercase							(     self			)       ->       List[Any]:
												_a      :       List[str]   =						[]
												_a      :       Optional[Any]   =						[]
												_a      :       str   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Any   =						-2
												_a      :       int   =						[]
												_a      :       Optional[Any]   =						s
												_a      :       str   =						False
												_a      :       Optional[Any]   =						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       List[Any]   =						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]			) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]			) > 0
																											    and not on_the_way_back
																											):
																																_a      :       Optional[int]   =						len(_a			) - 1
																																while len_stack >= 0:
																																					if stack[len_stack] == node[1]:
																																										anticipating_nodes.add(node[1]			)
																																										break
																																					else:
																																										anticipating_nodes.add(stack[len_stack]			)
																																										len_stack -= 1
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       int   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						_a      :       str   =						True
																						if len(_a			) != 0:
																											_a      :       List[Any]   =						stack[len(_a			) - 1]
																	else:
																						_a      :       List[Any]   =						False
																						indirect_parents.append(_a			)
																						_a      :       Tuple   =						s
																						_a      :       Tuple   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return list(_a			)


							def 							__lowercase							(     self			)       ->       List[str]:
												_a      :       str   =						[]
												_a      :       Optional[int]   =						[]
												_a      :       List[Any]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Tuple   =						-2
												_a      :       List[Any]   =						[]
												_a      :       Dict   =						s
												_a      :       List[str]   =						False
												_a      :       Optional[Any]   =						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       Optional[int]   =						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]			) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]			) > 0
																											    and not on_the_way_back
																											):
																																_a      :       Union[str, Any]   =						len(_a			) - 1
																																while len_stack_minus_one >= 0:
																																					if stack[len_stack_minus_one] == node[1]:
																																										anticipating_nodes.add(node[1]			)
																																										break
																																					else:
																																										return True
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       Union[str, Any]   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						_a      :       Union[str, Any]   =						True
																						if len(_a			) != 0:
																											_a      :       Optional[Any]   =						stack[len(_a			) - 1]
																	else:
																						_a      :       List[str]   =						False
																						indirect_parents.append(_a			)
																						_a      :       Dict   =						s
																						_a      :       str   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return False


							def 							__lowercase							(     self			)       ->       Union[str, Any]:
												return list(self.graph			)


							def 							__lowercase							(     self			,				_a=-2			,				_a=-1			)       ->       Union[str, Any]:
												_a      :       Optional[Any]   =						time()
												self.dfs(_a			,				_a			)
												_a      :       str   =						time()
												return end - begin




							def 							__lowercase							(     self			,				_a=-2			)       ->       Dict:
												_a      :       Union[str, Any]   =						time()
												self.bfs(_a			)
												_a      :       Optional[int]   =						time()
												return end - begin






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_						(     __lowercase  ):
							"""simple docstring"""







							UpperCAmelCase__			:		Optional[int]             =       "funnel"
							UpperCAmelCase__			:		Tuple             =       {
							    "hidden_size": "d_model",
							    "num_attention_heads": "n_head",
							}


							def __init__(     self			,				_a=3_0_5_2_2			,				_a=[4, 4, 4]			,				_a=None			,				_a=2			,				_a=7_6_8			,				_a=1_2			,				_a=6_4			,				_a=3_0_7_2			,				_a="gelu_new"			,				_a=0.1			,				_a=0.1			,				_a=0.0			,				_a=0.1			,				_a=None			,				_a=1e-9			,				_a="mean"			,				_a="relative_shift"			,				_a=True			,				_a=True			,				_a=True			,				**_a			,				)       ->       List[Any]:
												_a      :       Optional[int]   =						vocab_size
												_a      :       Dict   =						block_sizes
												_a      :       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."
												_a      :       int   =						num_decoder_layers
												_a      :       List[str]   =						d_model
												_a      :       Optional[Any]   =						n_head
												_a      :       Tuple   =						d_head
												_a      :       Dict   =						d_inner
												_a      :       List[str]   =						hidden_act
												_a      :       int   =						hidden_dropout
												_a      :       Union[str, Any]   =						attention_dropout
												_a      :       Tuple   =						activation_dropout
												_a      :       Optional[Any]   =						initializer_range
												_a      :       Dict   =						initializer_std
												_a      :       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."""
												_a      :       Any   =						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      :       int   =						separate_cls
												_a      :       Tuple   =						truncate_seq
												_a      :       List[Any]   =						pool_q_only

												super().__init__(**_a			)


							@property
							def 							__lowercase							(     self			)       ->       Tuple:
												return sum(self.block_sizes			)


							@num_hidden_layers.setter
							def 							__lowercase							(     self			,				_a			)       ->       List[str]:
												raise NotImplementedError(
												    '''This model does not support the setting of `num_hidden_layers`. Please set `block_sizes`.'''			)


							@property
							def 							__lowercase							(     self			)       ->       Optional[int]:
												return len(self.block_sizes			)




							@num_blocks.setter
							def 							__lowercase							(     self			,				_a			)       ->       Dict:
												raise NotImplementedError('''This model does not support the setting of `num_blocks`. Please set `block_sizes`.'''			)



