





'''simple docstring'''




from collections import OrderedDict
from typing import Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...feature_extraction_utils import FeatureExtractionMixin
from ...onnx import OnnxConfig
from ...onnx.utils import compute_effective_axis_dimension
from ...tokenization_utils_base import PreTrainedTokenizerBase
from ...utils import TensorType, logging


__UpperCAmelCase			    =    logging.get_logger(__name__)

__UpperCAmelCase			    =    {
    """deepmind/language-perceiver""": """https://huggingface.co/deepmind/language-perceiver/resolve/main/config.json""",
    # See all Perceiver models at https://huggingface.co/models?filter=perceiver
}




class 			UpperCamelCase__ ( _a       ):




					"""simple docstring"""
					SCREAMING_SNAKE_CASE__            =     '''perceiver'''


					def __init__(		self							:       int	,		lowerCamelCase_							:       List[str]=2_56	,		lowerCamelCase_							:       Optional[int]=12_80	,		lowerCamelCase_							:       Optional[Any]=7_68	,		lowerCamelCase_							:       Union[str, Any]=1	,		lowerCamelCase_							:       str=26	,		lowerCamelCase_							:       Optional[Any]=8	,		lowerCamelCase_							:       List[str]=8	,		lowerCamelCase_							:       Tuple=None	,		lowerCamelCase_							:       Any=None	,		lowerCamelCase_							:       List[str]="kv"	,		lowerCamelCase_							:       Optional[Any]=1	,		lowerCamelCase_							:       Union[str, Any]=1	,		lowerCamelCase_							:       Union[str, Any]="gelu"	,		lowerCamelCase_							:       Any=0.1	,		lowerCamelCase_							:       Tuple=0.02	,		lowerCamelCase_							:       Any=1e-12	,		lowerCamelCase_							:       str=True	,		lowerCamelCase_							:       List[str]=2_62	,		lowerCamelCase_							:       List[str]=20_48	,		lowerCamelCase_							:       Union[str, Any]=56	,		lowerCamelCase_							:       Union[str, Any]=[3_68, 4_96]	,		lowerCamelCase_							:       Union[str, Any]=16	,		lowerCamelCase_							:       Optional[Any]=19_20	,		lowerCamelCase_							:       Tuple=16	,		lowerCamelCase_							:       Dict=[1, 16, 2_24, 2_24]	,		**lowerCamelCase_							:       Optional[Any]	,		):

							'''simple docstring'''



							super().__init__(**lowerCamelCase_		)

							SCREAMING_SNAKE_CASE      :							Union[str, Any]						=       num_latents
							SCREAMING_SNAKE_CASE      :							Union[str, Any]						=       d_latents
							SCREAMING_SNAKE_CASE      :							Union[str, Any]						=       d_model
							SCREAMING_SNAKE_CASE      :							str						=       num_blocks
							SCREAMING_SNAKE_CASE      :							Optional[int]						=       num_self_attends_per_block
							SCREAMING_SNAKE_CASE      :							Optional[int]						=       num_self_attention_heads
							SCREAMING_SNAKE_CASE      :							Optional[int]						=       num_cross_attention_heads
							SCREAMING_SNAKE_CASE      :							Dict						=       qk_channels
							SCREAMING_SNAKE_CASE      :							Optional[Any]						=       v_channels
							SCREAMING_SNAKE_CASE      :							Tuple						=       cross_attention_shape_for_attention
							SCREAMING_SNAKE_CASE      :							Union[str, Any]						=       self_attention_widening_factor
							SCREAMING_SNAKE_CASE      :							Optional[int]						=       cross_attention_widening_factor
							SCREAMING_SNAKE_CASE      :							Dict						=       hidden_act
							SCREAMING_SNAKE_CASE      :							Optional[int]						=       attention_probs_dropout_prob
							SCREAMING_SNAKE_CASE      :							str						=       initializer_range
							SCREAMING_SNAKE_CASE      :							List[Any]						=       layer_norm_eps
							SCREAMING_SNAKE_CASE      :							List[Any]						=       use_query_residual
							# masked language modeling attributes
							SCREAMING_SNAKE_CASE      :							int						=       vocab_size
							SCREAMING_SNAKE_CASE      :							List[Any]						=       max_position_embeddings
							# image classification attributes
							SCREAMING_SNAKE_CASE      :							Tuple						=       image_size
							# flow attributes
							SCREAMING_SNAKE_CASE      :							Any						=       train_size
							# multimodal autoencoding attributes
							SCREAMING_SNAKE_CASE      :							Any						=       num_frames
							SCREAMING_SNAKE_CASE      :							Optional[Any]						=       audio_samples_per_frame
							SCREAMING_SNAKE_CASE      :							Any						=       samples_per_patch
							SCREAMING_SNAKE_CASE      :							Optional[Any]						=       output_shape







class 			UpperCamelCase__ ( _a       ):




					"""simple docstring"""


					@property
					def lowerCamelCase_       (		self							:       Optional[int]		):

							'''simple docstring'''



							if self.task == "multiple-choice":
									SCREAMING_SNAKE_CASE      :							int						=       {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
							else:
									SCREAMING_SNAKE_CASE      :							Any						=       {0: '''batch''', 1: '''sequence'''}
							return OrderedDict(
							    [
							        ("""inputs""", dynamic_axis),
							        ("""attention_mask""", dynamic_axis),
							    ]		)


					@property
					def lowerCamelCase_       (		self							:       List[Any]		):

							'''simple docstring'''



							return 1e-4



					def lowerCamelCase_       (		self							:       str	,		lowerCamelCase_							:       Any	,		lowerCamelCase_							:       Tuple = -1	,		lowerCamelCase_							:       Tuple = -1	,		lowerCamelCase_							:       Any = -1	,		lowerCamelCase_							:       Any = False	,		lowerCamelCase_							:       List[Any] = None	,		lowerCamelCase_							:       Dict = 3	,		lowerCamelCase_							:       List[str] = 40	,		lowerCamelCase_							:       Optional[Any] = 40	,		):

							'''simple docstring'''



							if isinstance(lowerCamelCase_	,		lowerCamelCase_		):
									# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
									SCREAMING_SNAKE_CASE      :							Tuple						=       compute_effective_axis_dimension(
									    lowerCamelCase_	,		fixed_dimension=OnnxConfig.default_fixed_batch	,		num_token_to_add=0		)
									# If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
									SCREAMING_SNAKE_CASE      :							Any						=       preprocessor.num_special_tokens_to_add(lowerCamelCase_		)
									SCREAMING_SNAKE_CASE      :							Dict						=       compute_effective_axis_dimension(
									    lowerCamelCase_	,		fixed_dimension=OnnxConfig.default_fixed_sequence	,		num_token_to_add=lowerCamelCase_		)
									# Generate dummy inputs according to compute batch and sequence
									SCREAMING_SNAKE_CASE      :							Tuple						=       [''' '''.join(["""a"""]		) * seq_length] * batch_size
									SCREAMING_SNAKE_CASE      :							str						=       dict(preprocessor(lowerCamelCase_	,		return_tensors=lowerCamelCase_		)		)
									SCREAMING_SNAKE_CASE      :							Optional[Any]						=       inputs.pop("""input_ids"""		)
									return inputs
							elif isinstance(lowerCamelCase_	,		lowerCamelCase_		) and preprocessor.model_input_names[0] == "pixel_values":
									# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
									SCREAMING_SNAKE_CASE      :							Dict						=       compute_effective_axis_dimension(lowerCamelCase_	,		fixed_dimension=OnnxConfig.default_fixed_batch		)
									SCREAMING_SNAKE_CASE      :							str						=       self._generate_dummy_images(lowerCamelCase_	,		lowerCamelCase_	,		lowerCamelCase_	,		lowerCamelCase_		)
									SCREAMING_SNAKE_CASE      :							List[Any]						=       dict(preprocessor(images=lowerCamelCase_	,		return_tensors=lowerCamelCase_		)		)
									SCREAMING_SNAKE_CASE      :							Dict						=       inputs.pop("""pixel_values"""		)
									return inputs
							else:
									raise ValueError(
									    """Unable to generate dummy inputs for the model. Please provide a tokenizer or a preprocessor."""		)










from math import factorial

lowerCAmelCase_    =				{str(digit): factorial(digit) for digit in range(1_0)}






def      lowerCamelCase_						(				_UpperCamelCase )		->						int:






				"""simple docstring"""


				if not isinstance(_UpperCamelCase ,				_UpperCamelCase ):
								raise TypeError('''Parameter number must be int''' )

				if number < 0:
								raise ValueError('''Parameter number must be greater than or equal to 0''' )

				# Converts number in string to iterate on its digits and adds its factorial.
				return sum(DIGIT_FACTORIAL[digit] for digit in str(_UpperCamelCase ) )






def      lowerCamelCase_						(				_UpperCamelCase = 60 ,				_UpperCamelCase = 1_000_000 )		->						int:






				"""simple docstring"""


				if not isinstance(_UpperCamelCase ,				_UpperCamelCase ) or not isinstance(_UpperCamelCase ,				_UpperCamelCase ):
								raise TypeError('''Parameters chain_length and number_limit must be int''' )

				if chain_length <= 0 or number_limit <= 0:
								raise ValueError(
								    '''Parameters chain_length and number_limit must be greater than 0''' )

				# the counter for the chains with the exact desired length
				snake_case_						:    Optional[Any]				=  0
				# the cached sizes of the previous chains
				snake_case_						:    dict[int, int]				=  {}

				for start_chain_element in range(1 ,				_UpperCamelCase ):
								# The temporary set will contain the elements of the chain
								snake_case_						:    List[str]				=  set()
								snake_case_						:    List[Any]				=  0

								# Stop computing the chain when you find a cached size, a repeating item or the
								# length is greater then the desired one.
								snake_case_						:    Any				=  start_chain_element
								while (
								    chain_element not in chain_sets_lengths
								    and chain_element not in chain_set
								    and chain_set_length <= chain_length
								):
												chain_set.add(_UpperCamelCase )
												chain_set_length += 1
												snake_case_						:    List[Any]				=  digit_factorial_sum(_UpperCamelCase )

								if chain_element in chain_sets_lengths:
												chain_set_length += chain_sets_lengths[chain_element]

								snake_case_						:    List[str]				=  chain_set_length

								# If chain contains the exact amount of elements increase the counter
								if chain_set_length == chain_length:
												chains_counter += 1

				return chains_counter


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	print(F'''{solution()}''')
