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

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxConfigWithPast, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


__SCREAMING_SNAKE_CASE     :				Any      	=       logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE     :				Dict      	=       {
    'google/bigbird-pegasus-large-arxiv': (
        'https://huggingface.co/google/bigbird-pegasus-large-arxiv/resolve/main/config.json'
    ),
    'google/bigbird-pegasus-large-pubmed': (
        'https://huggingface.co/google/bigbird-pegasus-large-pubmed/resolve/main/config.json'
    ),
    'google/bigbird-pegasus-large-bigpatent': (
        'https://huggingface.co/google/bigbird-pegasus-large-bigpatent/resolve/main/config.json'
    ),
    # See all BigBirdPegasus models at https://huggingface.co/models?filter=bigbird_pegasus
}


class 						__magic_name__				(  snake_case      ):
		_lowerCAmelCase						=		'bigbird_pegasus'
		_lowerCAmelCase						=		['past_key_values']
		_lowerCAmelCase						=		{
		    'num_attention_heads': 'encoder_attention_heads',
		    'hidden_size': 'd_model',
		    'attention_probs_dropout_prob': 'attention_dropout',
		}





		def __init__(							self      :		Optional[int]  ,					lowerCamelCase__      :		str=9_6_1_0_3  ,					lowerCamelCase__      :		Optional[int]=4_0_9_6  ,					lowerCamelCase__      :		int=1_6  ,					lowerCamelCase__      :		Tuple=4_0_9_6  ,					lowerCamelCase__      :		Tuple=1_6  ,					lowerCamelCase__      :		int=1_6  ,					lowerCamelCase__      :		Union[str, Any]=4_0_9_6  ,					lowerCamelCase__      :		List[str]=1_6  ,					lowerCamelCase__      :		Optional[Any]=0.0  ,					lowerCamelCase__      :		List[Any]=0.0  ,					lowerCamelCase__      :		str=True  ,					lowerCamelCase__      :		int=True  ,					lowerCamelCase__      :		Any="gelu_new"  ,					lowerCamelCase__      :		Union[str, Any]=1_0_2_4  ,					lowerCamelCase__      :		Dict=0.1  ,					lowerCamelCase__      :		Union[str, Any]=0.0  ,					lowerCamelCase__      :		Optional[int]=0.0  ,					lowerCamelCase__      :		str=0.0_2  ,					lowerCamelCase__      :		List[str]=2  ,					lowerCamelCase__      :		Optional[Any]=0.0  ,					lowerCamelCase__      :		List[Any]=True  ,					lowerCamelCase__      :		Any=0  ,					lowerCamelCase__      :		Optional[int]=2  ,					lowerCamelCase__      :		Optional[int]=1  ,					lowerCamelCase__      :		List[str]="block_sparse"  ,					lowerCamelCase__      :		Union[str, Any]=6_4  ,					lowerCamelCase__      :		Any=3  ,					lowerCamelCase__      :		Tuple=False  ,					**lowerCamelCase__      :		List[str]  ,					):
							lowerCAmelCase						:   Optional[Any]							=       vocab_size
							lowerCAmelCase						:   List[Any]							=       max_position_embeddings
							lowerCAmelCase						:   List[Any]							=       d_model
							lowerCAmelCase						:   str							=       encoder_ffn_dim
							lowerCAmelCase						:   Optional[Any]							=       encoder_layers
							lowerCAmelCase						:   Dict							=       encoder_attention_heads
							lowerCAmelCase						:   List[str]							=       decoder_ffn_dim
							lowerCAmelCase						:   List[Any]							=       decoder_layers
							lowerCAmelCase						:   str							=       decoder_attention_heads
							lowerCAmelCase						:   List[Any]							=       dropout
							lowerCAmelCase						:   List[str]							=       attention_dropout
							lowerCAmelCase						:   Tuple							=       activation_dropout
							lowerCAmelCase						:   Optional[Any]							=       activation_function
							lowerCAmelCase						:   str							=       init_std
							lowerCAmelCase						:   Optional[Any]							=       encoder_layerdrop
							lowerCAmelCase						:   Any							=       decoder_layerdrop
							lowerCAmelCase						:   Optional[Any]							=       classifier_dropout
							lowerCAmelCase						:   Tuple							=       use_cache
							lowerCAmelCase						:   int							=       encoder_layers
							lowerCAmelCase						:   Union[str, Any]							=       scale_embedding  # scale factor will be sqrt(d_model) if True

							# extra config
							lowerCAmelCase						:   str							=       attention_type
							lowerCAmelCase						:   Tuple							=       block_size
							lowerCAmelCase						:   Optional[Any]							=       num_random_blocks
							lowerCAmelCase						:   int							=       use_bias

							super().__init__(
							    pad_token_id=lowerCamelCase__  ,					bos_token_id=lowerCamelCase__  ,					eos_token_id=lowerCamelCase__  ,					is_encoder_decoder=lowerCamelCase__  ,					decoder_start_token_id=lowerCamelCase__  ,					**lowerCamelCase__  ,					)



class 						__magic_name__				(  snake_case      ):





		@property
		def  _A							(							self      :		Any			):



							if self.task in ["default", "seq2seq-lm"]:
												lowerCAmelCase						:   str							=       OrderedDict(
												    [
												        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
												        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
												    ]			)

												if self.use_past:
																	lowerCAmelCase						:   Union[str, Any]							=       {0: '''batch'''}
																	lowerCAmelCase						:   List[str]							=       {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
												else:
																	lowerCAmelCase						:   Any							=       {0: '''batch''', 1: '''decoder_sequence'''}
																	lowerCAmelCase						:   int							=       {0: '''batch''', 1: '''decoder_sequence'''}

												if self.use_past:
																	self.fill_with_past_key_values_(lowerCamelCase__  ,					direction='''inputs'''			)
							elif self.task == "causal-lm":
												# TODO: figure this case out.
												lowerCAmelCase						:   str							=       OrderedDict(
												    [
												        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
												        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
												    ]			)
												if self.use_past:
																	lowerCAmelCase		,							lowerCAmelCase						:   Dict							=       self.num_layers
																	for i in range(lowerCamelCase__			):
																						lowerCAmelCase						:   Tuple							=       {0: '''batch''', 2: '''past_sequence + sequence'''}
																						lowerCAmelCase						:   Union[str, Any]							=       {0: '''batch''', 2: '''past_sequence + sequence'''}
							else:
												lowerCAmelCase						:   int							=       OrderedDict(
												    [
												        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
												        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
												        ('''decoder_input_ids''', {0: '''batch''', 1: '''decoder_sequence'''}),
												        ('''decoder_attention_mask''', {0: '''batch''', 1: '''decoder_sequence'''}),
												    ]			)

							return common_inputs





		@property
		def  _A							(							self      :		int			):



							if self.task in ["default", "seq2seq-lm"]:
												lowerCAmelCase						:   Union[str, Any]							=       super().outputs
							else:
												lowerCAmelCase						:   Dict							=       super(lowerCamelCase__  ,					self			).outputs
												if self.use_past:
																	lowerCAmelCase		,							lowerCAmelCase						:   Tuple							=       self.num_layers
																	for i in range(lowerCamelCase__			):
																						lowerCAmelCase						:   Optional[int]							=       {0: '''batch''', 2: '''past_sequence + sequence'''}
																						lowerCAmelCase						:   Tuple							=       {0: '''batch''', 2: '''past_sequence + sequence'''}
							return common_outputs





		def  _A							(							self      :		Tuple  ,					lowerCamelCase__      :		Optional[Any]  ,					lowerCamelCase__      :		List[str] = -1  ,					lowerCamelCase__      :		Optional[Any] = -1  ,					lowerCamelCase__      :		int = False  ,					lowerCamelCase__      :		Optional[Any] = None  ,					):
							lowerCAmelCase						:   int							=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__			)

							# Generate decoder inputs
							lowerCAmelCase						:   Optional[int]							=       seq_length if not self.use_past else 1
							lowerCAmelCase						:   str							=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__			)
							lowerCAmelCase						:   Union[str, Any]							=       {f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
							lowerCAmelCase						:   Optional[int]							=       dict(**lowerCamelCase__  ,					**lowerCamelCase__			)

							if self.use_past:
												if not is_torch_available():
																	raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''			)
												else:
																	import torch
												lowerCAmelCase		,							lowerCAmelCase						:   str							=       common_inputs['''input_ids'''].shape
												lowerCAmelCase						:   Optional[Any]							=       common_inputs['''decoder_input_ids'''].shape[1]
												lowerCAmelCase		,							lowerCAmelCase						:   Union[str, Any]							=       self.num_attention_heads
												lowerCAmelCase						:   Dict							=       (
												    batch,
												    num_encoder_attention_heads,
												    encoder_seq_length,
												    self._config.hidden_size // num_encoder_attention_heads,
												)
												lowerCAmelCase						:   Optional[int]							=       decoder_seq_length + 3
												lowerCAmelCase						:   Tuple							=       (
												    batch,
												    num_decoder_attention_heads,
												    decoder_past_length,
												    self._config.hidden_size // num_decoder_attention_heads,
												)

												lowerCAmelCase						:   str							=       torch.cat(
												    [common_inputs['''decoder_attention_mask'''], torch.ones(lowerCamelCase__  ,					lowerCamelCase__			)]  ,					dim=1			)

												lowerCAmelCase						:   Tuple							=       []
												# If the number of encoder and decoder layers are present in the model configuration, both are considered
												lowerCAmelCase		,							lowerCAmelCase						:   Any							=       self.num_layers
												lowerCAmelCase						:   str							=       min(lowerCamelCase__  ,					lowerCamelCase__			)
												lowerCAmelCase						:   List[Any]							=       max(lowerCamelCase__  ,					lowerCamelCase__			) - min_num_layers
												lowerCAmelCase						:   Dict							=       '''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

												for _ in range(lowerCamelCase__			):
																	common_inputs["past_key_values"].append(
																	    (
																	        torch.zeros(lowerCamelCase__			),
																	        torch.zeros(lowerCamelCase__			),
																	        torch.zeros(lowerCamelCase__			),
																	        torch.zeros(lowerCamelCase__			),
																	    )			)
												# TODO: test this.
												lowerCAmelCase						:   Optional[Any]							=       encoder_shape if remaining_side_name == '''encoder''' else decoder_shape
												for _ in range(lowerCamelCase__  ,					lowerCamelCase__			):
																	common_inputs["past_key_values"].append((torch.zeros(lowerCamelCase__			), torch.zeros(lowerCamelCase__			))			)
							return common_inputs





		def  _A							(							self      :		Any  ,					lowerCamelCase__      :		Tuple  ,					lowerCamelCase__      :		Optional[Any] = -1  ,					lowerCamelCase__      :		Optional[Any] = -1  ,					lowerCamelCase__      :		List[Any] = False  ,					lowerCamelCase__      :		str = None  ,					):
							lowerCAmelCase						:   List[Any]							=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
							    lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__			)

							if self.use_past:
												if not is_torch_available():
																	raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''			)
												else:
																	import torch
												lowerCAmelCase		,							lowerCAmelCase						:   str							=       common_inputs['''input_ids'''].shape
												# Not using the same length for past_key_values
												lowerCAmelCase						:   str							=       seqlen + 2
												lowerCAmelCase		,							lowerCAmelCase						:   Any							=       self.num_layers
												lowerCAmelCase		,							lowerCAmelCase						:   List[Any]							=       self.num_attention_heads
												lowerCAmelCase						:   str							=       (
												    batch,
												    num_encoder_attention_heads,
												    past_key_values_length,
												    self._config.hidden_size // num_encoder_attention_heads,
												)

												lowerCAmelCase						:   str							=       common_inputs['''attention_mask'''].dtype
												lowerCAmelCase						:   int							=       torch.cat(
												    [common_inputs['''attention_mask'''], torch.ones(lowerCamelCase__  ,					lowerCamelCase__  ,					dtype=lowerCamelCase__			)]  ,					dim=1			)
												lowerCAmelCase						:   Tuple							=       [
												    (torch.zeros(lowerCamelCase__			), torch.zeros(lowerCamelCase__			)) for _ in range(lowerCamelCase__			)
												]
							return common_inputs





		def  _A							(							self      :		Union[str, Any]  ,					lowerCamelCase__      :		Union[str, Any]  ,					lowerCamelCase__      :		Union[str, Any] = -1  ,					lowerCamelCase__      :		Union[str, Any] = -1  ,					lowerCamelCase__      :		str = False  ,					lowerCamelCase__      :		List[Any] = None  ,					):
							lowerCAmelCase						:   str							=       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
							lowerCAmelCase						:   List[str]							=       tokenizer.num_special_tokens_to_add(lowerCamelCase__			)
							lowerCAmelCase						:   int							=       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
							lowerCAmelCase						:   List[Any]							=       [''' '''.join([tokenizer.unk_token]			) * seq_length] * batch_size
							lowerCAmelCase						:   str							=       dict(tokenizer(lowerCamelCase__  ,					return_tensors=lowerCamelCase__			)			)
							return common_inputs





		def  _A							(							self      :		Dict  ,					lowerCamelCase__      :		Optional[Any]  ,					lowerCamelCase__      :		List[str] = -1  ,					lowerCamelCase__      :		str = -1  ,					lowerCamelCase__      :		List[str] = False  ,					lowerCamelCase__      :		Tuple = None  ,					):



							if self.task in ["default", "seq2seq-lm"]:
												lowerCAmelCase						:   str							=       self._generate_dummy_inputs_for_default_and_seqaseq_lm(
												    lowerCamelCase__  ,					batch_size=lowerCamelCase__  ,					seq_length=lowerCamelCase__  ,					is_pair=lowerCamelCase__  ,					framework=lowerCamelCase__			)

							elif self.task == "causal-lm":
												lowerCAmelCase						:   Tuple							=       self._generate_dummy_inputs_for_causal_lm(
												    lowerCamelCase__  ,					batch_size=lowerCamelCase__  ,					seq_length=lowerCamelCase__  ,					is_pair=lowerCamelCase__  ,					framework=lowerCamelCase__			)
							else:
												lowerCAmelCase						:   Dict							=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
												    lowerCamelCase__  ,					batch_size=lowerCamelCase__  ,					seq_length=lowerCamelCase__  ,					is_pair=lowerCamelCase__  ,					framework=lowerCamelCase__			)

							return common_inputs





		def  _A							(							self      :		Optional[int]  ,					lowerCamelCase__      :		Dict  ,					lowerCamelCase__      :		int  ,					lowerCamelCase__      :		Optional[Any]  ,					lowerCamelCase__      :		int			):



							if self.task in ["default", "seq2seq-lm"]:
												lowerCAmelCase						:   str							=       super()._flatten_past_key_values_(lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__			)
							else:
												lowerCAmelCase						:   Tuple							=       super(lowerCamelCase__  ,					self			)._flatten_past_key_values_(
												    lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__  ,					lowerCamelCase__			)


def       UpperCAmelCase__							(    __magic_name__  :       int = 99_80_01					):


					'''simple docstring'''

					lowerCAmelCase						:   Tuple							=       0
					for i in range(9_99							,					99							,					-1					):  # 3 digit numbers range from 999 down to 100
										for j in range(9_99							,					99							,					-1					):
															lowerCAmelCase						:   Any							=       str(i * j					)
															if product_string == product_string[::-1] and i * j < n:
																				lowerCAmelCase						:   Optional[int]							=       max(__magic_name__							,					i * j					)
					return answer


if __name__ == "__main__":
		print(f"""{solution() = }""")
