






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


UpperCAmelCase				:							Tuple								=logging.get_logger(__name__)

UpperCAmelCase				:							int								={
    """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  _lowercase				(a_ ):
				'''simple docstring'''







				lowercase__				  =  """bigbird_pegasus"""
				lowercase__				  =  ["""past_key_values"""]
				lowercase__				  =  {
				    """num_attention_heads""": """encoder_attention_heads""",
				    """hidden_size""": """d_model""",
				    """attention_probs_dropout_prob""": """attention_dropout""",
				}

				def __init__(	self       ,	snake_case__=9_6103       ,	snake_case__=4096       ,	snake_case__=16       ,	snake_case__=4096       ,	snake_case__=16       ,	snake_case__=16       ,	snake_case__=4096       ,	snake_case__=16       ,	snake_case__=0.0       ,	snake_case__=0.0       ,	snake_case__=True       ,	snake_case__=True       ,	snake_case__="gelu_new"       ,	snake_case__=1024       ,	snake_case__=0.1       ,	snake_case__=0.0       ,	snake_case__=0.0       ,	snake_case__=0.02       ,	snake_case__=2       ,	snake_case__=0.0       ,	snake_case__=True       ,	snake_case__=0       ,	snake_case__=2       ,	snake_case__=1       ,	snake_case__="block_sparse"       ,	snake_case__=64       ,	snake_case__=3       ,	snake_case__=False       ,	**snake_case__       ,	):

									'''simple docstring'''


									UpperCamelCase_											=				vocab_size
									UpperCamelCase_											=				max_position_embeddings
									UpperCamelCase_											=				d_model
									UpperCamelCase_											=				encoder_ffn_dim
									UpperCamelCase_											=				encoder_layers
									UpperCamelCase_											=				encoder_attention_heads
									UpperCamelCase_											=				decoder_ffn_dim
									UpperCamelCase_											=				decoder_layers
									UpperCamelCase_											=				decoder_attention_heads
									UpperCamelCase_											=				dropout
									UpperCamelCase_											=				attention_dropout
									UpperCamelCase_											=				activation_dropout
									UpperCamelCase_											=				activation_function
									UpperCamelCase_											=				init_std
									UpperCamelCase_											=				encoder_layerdrop
									UpperCamelCase_											=				decoder_layerdrop
									UpperCamelCase_											=				classifier_dropout
									UpperCamelCase_											=				use_cache
									UpperCamelCase_											=				encoder_layers
									UpperCamelCase_											=				scale_embedding  # scale factor will be sqrt(d_model) if True

									# extra config
									UpperCamelCase_											=				attention_type
									UpperCamelCase_											=				block_size
									UpperCamelCase_											=				num_random_blocks
									UpperCamelCase_											=				use_bias

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




class  _lowercase				(a_ ):
				'''simple docstring'''







				@property
				def  _lowerCamelCase   (	self      ):

									'''simple docstring'''


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

														if self.use_past:
																			UpperCamelCase_											=				{0: "batch"}
																			UpperCamelCase_											=				{0: "batch", 1: "past_decoder_sequence + sequence"}
														else:
																			UpperCamelCase_											=				{0: "batch", 1: "decoder_sequence"}
																			UpperCamelCase_											=				{0: "batch", 1: "decoder_sequence"}

														if self.use_past:
																			self.fill_with_past_key_values_(snake_case__       ,	direction="inputs"      )
									elif self.task == "causal-lm":
														# TODO: figure this case out.
														UpperCamelCase_											=				OrderedDict(
														    [
														        ("input_ids", {0: "batch", 1: "encoder_sequence"}),
														        ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
														    ]      )
														if self.use_past:
																			UpperCamelCase_					,      UpperCamelCase_											=				self.num_layers
																			for i in range(snake_case__      ):
																								UpperCamelCase_											=				{0: "batch", 2: "past_sequence + sequence"}
																								UpperCamelCase_											=				{0: "batch", 2: "past_sequence + sequence"}
									else:
														UpperCamelCase_											=				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  _lowerCamelCase   (	self      ):

									'''simple docstring'''


									if self.task in ["default", "seq2seq-lm"]:
														UpperCamelCase_											=				super().outputs
									else:
														UpperCamelCase_											=				super(snake_case__       ,	self      ).outputs
														if self.use_past:
																			UpperCamelCase_					,      UpperCamelCase_											=				self.num_layers
																			for i in range(snake_case__      ):
																								UpperCamelCase_											=				{0: "batch", 2: "past_sequence + sequence"}
																								UpperCamelCase_											=				{0: "batch", 2: "past_sequence + sequence"}
									return common_outputs

				def  _lowerCamelCase   (	self       ,	snake_case__       ,	snake_case__ = -1       ,	snake_case__ = -1       ,	snake_case__ = False       ,	snake_case__ = None       ,	):

									'''simple docstring'''


									UpperCamelCase_											=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
									    snake_case__       ,	snake_case__       ,	snake_case__       ,	snake_case__       ,	snake_case__      )

									# Generate decoder inputs
									UpperCamelCase_											=				seq_length if not self.use_past else 1
									UpperCamelCase_											=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
									    snake_case__       ,	snake_case__       ,	snake_case__       ,	snake_case__       ,	snake_case__      )
									UpperCamelCase_											=				{F"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
									UpperCamelCase_											=				dict(**snake_case__       ,	**snake_case__      )

									if self.use_past:
														if not is_torch_available():
																			raise ValueError("Cannot generate dummy past_keys inputs without PyTorch installed."      )
														else:
																			import torch
														UpperCamelCase_					,      UpperCamelCase_											=				common_inputs["input_ids"].shape
														UpperCamelCase_											=				common_inputs["decoder_input_ids"].shape[1]
														UpperCamelCase_					,      UpperCamelCase_											=				self.num_attention_heads
														UpperCamelCase_											=				(
														    batch,
														    num_encoder_attention_heads,
														    encoder_seq_length,
														    self._config.hidden_size // num_encoder_attention_heads,
														)
														UpperCamelCase_											=				decoder_seq_length + 3
														UpperCamelCase_											=				(
														    batch,
														    num_decoder_attention_heads,
														    decoder_past_length,
														    self._config.hidden_size // num_decoder_attention_heads,
														)

														UpperCamelCase_											=				torch.cat(
														    [common_inputs["decoder_attention_mask"], torch.ones(snake_case__       ,	snake_case__      )]       ,	dim=1      )

														UpperCamelCase_											=				[]
														# If the number of encoder and decoder layers are present in the model configuration, both are considered
														UpperCamelCase_					,      UpperCamelCase_											=				self.num_layers
														UpperCamelCase_											=				min(snake_case__       ,	snake_case__      )
														UpperCamelCase_											=				max(snake_case__       ,	snake_case__      ) - min_num_layers
														UpperCamelCase_											=				"encoder" if num_encoder_layers > num_decoder_layers else "decoder"

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

				def  _lowerCamelCase   (	self       ,	snake_case__       ,	snake_case__ = -1       ,	snake_case__ = -1       ,	snake_case__ = False       ,	snake_case__ = None       ,	):

									'''simple docstring'''


									UpperCamelCase_											=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
									    snake_case__       ,	snake_case__       ,	snake_case__       ,	snake_case__       ,	snake_case__      )

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

														UpperCamelCase_											=				common_inputs["attention_mask"].dtype
														UpperCamelCase_											=				torch.cat(
														    [common_inputs["attention_mask"], torch.ones(snake_case__       ,	snake_case__       ,	dtype=snake_case__      )]       ,	dim=1      )
														UpperCamelCase_											=				[
														    (torch.zeros(snake_case__      ), torch.zeros(snake_case__      )) for _ in range(snake_case__      )
														]
									return common_inputs

				def  _lowerCamelCase   (	self       ,	snake_case__       ,	snake_case__ = -1       ,	snake_case__ = -1       ,	snake_case__ = False       ,	snake_case__ = None       ,	):

									'''simple docstring'''


									UpperCamelCase_											=				compute_effective_axis_dimension(
									    snake_case__       ,	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
									UpperCamelCase_											=				tokenizer.num_special_tokens_to_add(snake_case__      )
									UpperCamelCase_											=				compute_effective_axis_dimension(
									    snake_case__       ,	fixed_dimension=OnnxConfig.default_fixed_sequence       ,	num_token_to_add=snake_case__      )

									# Generate dummy inputs according to compute batch and sequence
									UpperCamelCase_											=				[" ".join([tokenizer.unk_token]      ) * seq_length] * batch_size
									UpperCamelCase_											=				dict(tokenizer(snake_case__       ,	return_tensors=snake_case__      )      )
									return common_inputs

				def  _lowerCamelCase   (	self       ,	snake_case__       ,	snake_case__ = -1       ,	snake_case__ = -1       ,	snake_case__ = False       ,	snake_case__ = None       ,	):

									'''simple docstring'''


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

									elif self.task == "causal-lm":
														UpperCamelCase_											=				self._generate_dummy_inputs_for_causal_lm(
														    snake_case__       ,	batch_size=snake_case__       ,	seq_length=snake_case__       ,	is_pair=snake_case__       ,	framework=snake_case__      )
									else:
														UpperCamelCase_											=				self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
														    snake_case__       ,	batch_size=snake_case__       ,	seq_length=snake_case__       ,	is_pair=snake_case__       ,	framework=snake_case__      )

									return common_inputs

				def  _lowerCamelCase   (	self       ,	snake_case__       ,	snake_case__       ,	snake_case__       ,	snake_case__      ):

									'''simple docstring'''


									if self.task in ["default", "seq2seq-lm"]:
														UpperCamelCase_											=				super()._flatten_past_key_values_(snake_case__       ,	snake_case__       ,	snake_case__       ,	snake_case__      )
									else:
														UpperCamelCase_											=				super(snake_case__       ,	self      )._flatten_past_key_values_(
														    snake_case__       ,	snake_case__       ,	snake_case__       ,	snake_case__      )





from typing import Literal

UpperCAmelCase				:							Tuple								="""ABCDEFGHIJKLMNOPQRSTUVWXYZ"""



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase				,		_lowerCAmelCase):
					UpperCamelCase_											=				LETTERS if mode == "decrypt" else key
					UpperCamelCase_											=				key if mode == "decrypt" else LETTERS
					UpperCamelCase_											=				""
					# loop through each symbol in the message
					for symbol in message:
										if symbol.upper() in chars_a:
															# encrypt/decrypt the symbol
															UpperCamelCase_											=				chars_a.find(symbol.upper())
															if symbol.isupper():
																				translated += chars_b[sym_index].upper()
															else:
																				translated += chars_b[sym_index].lower()
										else:
															# symbol is not in LETTERS, just add it
															translated += symbol
					return translated



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase):
					return translate_message(_lowerCAmelCase				,		_lowerCAmelCase				,		"encrypt")



def 				_lowerCAmelCase      (_lowerCAmelCase				,		_lowerCAmelCase):
					return translate_message(_lowerCAmelCase				,		_lowerCAmelCase				,		"decrypt")



def 				_lowerCAmelCase      ():
					UpperCamelCase_											=				"Hello World"
					UpperCamelCase_											=				"QWERTYUIOPASDFGHJKLZXCVBNM"
					UpperCamelCase_											=				"decrypt"  # set to 'encrypt' or 'decrypt'

					if mode == "encrypt":
										UpperCamelCase_											=				encrypt_message(_lowerCAmelCase				,		_lowerCAmelCase)
					elif mode == "decrypt":
										UpperCamelCase_											=				decrypt_message(_lowerCAmelCase				,		_lowerCAmelCase)
					print(f"""Using the key {key}, the {mode}ed message is: {translated}""")


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	main()
