
"""simple docstring"""


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


lowerCAmelCase								=						logging.get_logger(__name__)

lowerCAmelCase								=						{
    """uw-madison/nystromformer-512""": """https://huggingface.co/uw-madison/nystromformer-512/resolve/main/config.json""",
    # See all Nystromformer models at https://huggingface.co/models?filter=nystromformer
}

class    A_     (					A__       ):



							"""simple docstring"""






							SCREAMING_SNAKE_CASE_     				=       """nystromformer"""





							def __init__(  self  :Optional[Any]					,							lowerCamelCase_  :Optional[Any]=30_000					,							lowerCamelCase_  :str=768					,							lowerCamelCase_  :str=12					,							lowerCamelCase_  :str=12					,							lowerCamelCase_  :Any=3_072					,							lowerCamelCase_  :Optional[int]="gelu_new"					,							lowerCamelCase_  :List[Any]=0.1					,							lowerCamelCase_  :List[str]=0.1					,							lowerCamelCase_  :Any=510					,							lowerCamelCase_  :Optional[int]=2					,							lowerCamelCase_  :List[Any]=64					,							lowerCamelCase_  :Union[str, Any]=64					,							lowerCamelCase_  :str=65					,							lowerCamelCase_  :Union[str, Any]=False					,							lowerCamelCase_  :str=0.02					,							lowerCamelCase_  :Any=1e-5					,							lowerCamelCase_  :int=1					,							lowerCamelCase_  :Optional[int]=0					,							lowerCamelCase_  :str=2					,							**lowerCamelCase_  :int					,							):





										"""simple docstring"""

										lowerCamelCase__     :					int		=vocab_size
										lowerCamelCase__     :					Optional[int]		=max_position_embeddings
										lowerCamelCase__     :					List[Any]		=hidden_size
										lowerCamelCase__     :					Tuple		=num_hidden_layers
										lowerCamelCase__     :					Optional[Any]		=num_attention_heads
										lowerCamelCase__     :					List[str]		=intermediate_size
										lowerCamelCase__     :					Union[str, Any]		=hidden_act
										lowerCamelCase__     :					int		=hidden_dropout_prob
										lowerCamelCase__     :					Tuple		=attention_probs_dropout_prob
										lowerCamelCase__     :					Dict		=initializer_range
										lowerCamelCase__     :					Tuple		=type_vocab_size
										lowerCamelCase__     :					Any		=segment_means_seq_len
										lowerCamelCase__     :					int		=num_landmarks
										lowerCamelCase__     :					Tuple		=conv_kernel_size
										lowerCamelCase__     :					Optional[int]		=inv_coeff_init_option
										lowerCamelCase__     :					List[str]		=layer_norm_eps
										super().__init__(pad_token_id=lowerCamelCase_					,							bos_token_id=lowerCamelCase_					,							eos_token_id=lowerCamelCase_					,							**lowerCamelCase_	)

"""simple docstring"""


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

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


lowerCAmelCase								=						logging.get_logger(__name__)

lowerCAmelCase								=						{
    """facebook/blenderbot-3B""": """https://huggingface.co/facebook/blenderbot-3B/resolve/main/config.json""",
    # See all Blenderbot models at https://huggingface.co/models?filter=blenderbot
}

class    A_     (					A__       ):



							"""simple docstring"""






							SCREAMING_SNAKE_CASE_     				=       """blenderbot"""
							SCREAMING_SNAKE_CASE_     				=       ["""past_key_values"""]
							SCREAMING_SNAKE_CASE_     				=       {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}





							def __init__(  self  :Optional[int]					,							lowerCamelCase_  :Optional[Any]=8_008					,							lowerCamelCase_  :Optional[Any]=128					,							lowerCamelCase_  :Optional[int]=2					,							lowerCamelCase_  :Tuple=10_240					,							lowerCamelCase_  :Optional[int]=32					,							lowerCamelCase_  :Optional[int]=24					,							lowerCamelCase_  :Optional[Any]=10_240					,							lowerCamelCase_  :Union[str, Any]=32					,							lowerCamelCase_  :Any=0.0					,							lowerCamelCase_  :int=0.0					,							lowerCamelCase_  :str=True					,							lowerCamelCase_  :List[Any]=True					,							lowerCamelCase_  :Tuple="gelu"					,							lowerCamelCase_  :str=2_560					,							lowerCamelCase_  :Union[str, Any]=0.1					,							lowerCamelCase_  :Optional[int]=0.0					,							lowerCamelCase_  :Union[str, Any]=0.0					,							lowerCamelCase_  :List[str]=0.02					,							lowerCamelCase_  :Any=1					,							lowerCamelCase_  :List[Any]=False					,							lowerCamelCase_  :str=0					,							lowerCamelCase_  :Dict=1					,							lowerCamelCase_  :List[Any]=2					,							lowerCamelCase_  :int=3					,							lowerCamelCase_  :int=2					,							**lowerCamelCase_  :List[str]					,							):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[int]		=vocab_size
										lowerCamelCase__     :					Optional[int]		=max_position_embeddings
										lowerCamelCase__     :					Dict		=d_model
										lowerCamelCase__     :					str		=encoder_ffn_dim
										lowerCamelCase__     :					Optional[Any]		=encoder_layers
										lowerCamelCase__     :					List[Any]		=encoder_attention_heads
										lowerCamelCase__     :					Any		=decoder_ffn_dim
										lowerCamelCase__     :					Any		=decoder_layers
										lowerCamelCase__     :					Any		=decoder_attention_heads
										lowerCamelCase__     :					Dict		=dropout
										lowerCamelCase__     :					Any		=attention_dropout
										lowerCamelCase__     :					Dict		=activation_dropout
										lowerCamelCase__     :					Tuple		=activation_function
										lowerCamelCase__     :					List[Any]		=init_std
										lowerCamelCase__     :					str		=encoder_layerdrop
										lowerCamelCase__     :					Any		=decoder_layerdrop
										lowerCamelCase__     :					Union[str, Any]		=use_cache
										lowerCamelCase__     :					List[str]		=encoder_layers
										lowerCamelCase__     :					Optional[int]		=scale_embedding  # scale factor will be sqrt(d_model) if True

										super().__init__(
										    pad_token_id=lowerCamelCase_					,							bos_token_id=lowerCamelCase_					,							eos_token_id=lowerCamelCase_					,							is_encoder_decoder=lowerCamelCase_					,							decoder_start_token_id=lowerCamelCase_					,							encoder_no_repeat_ngram_size=lowerCamelCase_					,							forced_eos_token_id=lowerCamelCase_					,							**lowerCamelCase_					,							)






class    A_     (					A__       ):



							"""simple docstring"""






							@property
							def 				UpperCAmelCase__							(  self  :Tuple	):





										"""simple docstring"""

										if self.task in ["default", "seq2seq-lm"]:
													lowerCamelCase__     :					Dict		=OrderedDict(
													    [
													        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
													        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
													    ]	)
													if self.use_past:
																lowerCamelCase__     :					Dict		={0: 'batch'}
																lowerCamelCase__     :					Tuple		={0: 'batch', 1: 'past_decoder_sequence + sequence'}
													else:
																lowerCamelCase__     :					Optional[int]		={0: 'batch', 1: 'decoder_sequence'}
																lowerCamelCase__     :					Tuple		={0: 'batch', 1: 'decoder_sequence'}
													if self.use_past:
																self.fill_with_past_key_values_(lowerCamelCase_					,							direction='inputs'	)
										elif self.task == "causal-lm":
													lowerCamelCase__     :					Any		=OrderedDict(
													    [
													        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
													        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
													    ]	)
													if self.use_past:
																lowerCamelCase__	,    lowerCamelCase__     :					List[Any]		=self.num_layers
																for i in range(lowerCamelCase_	):
																			lowerCamelCase__     :					Tuple		={0: 'batch', 2: 'past_sequence + sequence'}
																			lowerCamelCase__     :					Optional[int]		={0: 'batch', 2: 'past_sequence + sequence'}
										else:
													lowerCamelCase__     :					List[str]		=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
							# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
							def 				UpperCAmelCase__							(  self  :List[str]	):





										"""simple docstring"""

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





							def 				UpperCAmelCase__							(  self  :List[Any]					,							lowerCamelCase_  :PreTrainedTokenizer					,							lowerCamelCase_  :int = -1					,							lowerCamelCase_  :int = -1					,							lowerCamelCase_  :bool = False					,							lowerCamelCase_  :Optional[TensorType] = None					,							):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[int]		=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
										    lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_	)
										# Generate decoder inputs
										lowerCamelCase__     :					List[str]		=seq_length if not self.use_past else 1
										lowerCamelCase__     :					Optional[Any]		=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
										    lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_	)
										lowerCamelCase__     :					int		={f"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
										lowerCamelCase__     :					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__     :					List[str]		=common_inputs['input_ids'].shape
													lowerCamelCase__     :					Tuple		=common_inputs['decoder_input_ids'].shape[1]
													lowerCamelCase__	,    lowerCamelCase__     :					int		=self.num_attention_heads
													lowerCamelCase__     :					Optional[Any]		=(
													    batch,
													    num_encoder_attention_heads,
													    encoder_seq_length,
													    self._config.hidden_size // num_encoder_attention_heads,
													)
													lowerCamelCase__     :					Any		=decoder_seq_length
													lowerCamelCase__     :					Optional[Any]		=(
													    batch,
													    num_decoder_attention_heads,
													    decoder_past_length,
													    self._config.hidden_size // num_decoder_attention_heads,
													)
													lowerCamelCase__     :					Optional[int]		=torch.cat(
													    [common_inputs['decoder_attention_mask'], torch.ones(lowerCamelCase_					,							lowerCamelCase_	)]					,							dim=1	)
													lowerCamelCase__     :					List[str]		=[]
													lowerCamelCase__	,    lowerCamelCase__     :					Dict		=self.num_layers

													for _ in range(lowerCamelCase_	):
																common_inputs["past_key_values"].append(
																    (
																        torch.zeros(lowerCamelCase_	),
																        torch.zeros(lowerCamelCase_	),
																        torch.zeros(lowerCamelCase_	),
																        torch.zeros(lowerCamelCase_	),
																    )	)
										return common_inputs





							def 				UpperCAmelCase__							(  self  :int					,							lowerCamelCase_  :PreTrainedTokenizer					,							lowerCamelCase_  :int = -1					,							lowerCamelCase_  :int = -1					,							lowerCamelCase_  :bool = False					,							lowerCamelCase_  :Optional[TensorType] = None					,							):





										"""simple docstring"""

										lowerCamelCase__     :					Union[str, 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__     :					Optional[int]		=common_inputs['input_ids'].shape
													lowerCamelCase__     :					List[Any]		=seqlen
													lowerCamelCase__	,    lowerCamelCase__     :					Tuple		=self.num_layers
													lowerCamelCase__	,    lowerCamelCase__     :					List[str]		=self.num_attention_heads
													lowerCamelCase__     :					Optional[int]		=(
													    batch,
													    num_encoder_attention_heads,
													    past_key_values_length,
													    self._config.hidden_size // num_encoder_attention_heads,
													)
													lowerCamelCase__     :					List[str]		=common_inputs['attention_mask'].dtype
													lowerCamelCase__     :					Tuple		=torch.cat(
													    [common_inputs['attention_mask'], torch.ones(lowerCamelCase_					,							lowerCamelCase_					,							dtype=lowerCamelCase_	)]					,							dim=1	)
													lowerCamelCase__     :					Optional[int]		=[
													    (torch.zeros(lowerCamelCase_	), torch.zeros(lowerCamelCase_	)) for _ in range(lowerCamelCase_	)
													]
										return common_inputs





							def 				UpperCAmelCase__							(  self  :Union[str, Any]					,							lowerCamelCase_  :PreTrainedTokenizer					,							lowerCamelCase_  :int = -1					,							lowerCamelCase_  :int = -1					,							lowerCamelCase_  :bool = False					,							lowerCamelCase_  :Optional[TensorType] = None					,							):





										"""simple docstring"""

										lowerCamelCase__     :					List[Any]		=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__     :					Optional[int]		=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__     :					Optional[Any]		=dict(tokenizer(lowerCamelCase_					,							return_tensors=lowerCamelCase_	)	)
										return common_inputs





							def 				UpperCAmelCase__							(  self  :Tuple					,							lowerCamelCase_  :PreTrainedTokenizer					,							lowerCamelCase_  :int = -1					,							lowerCamelCase_  :int = -1					,							lowerCamelCase_  :bool = False					,							lowerCamelCase_  :Optional[TensorType] = None					,							):





										"""simple docstring"""

										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__     :					List[Any]		=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 				UpperCAmelCase__							(  self  :Optional[int]					,							lowerCamelCase_  :Tuple					,							lowerCamelCase_  :Optional[Any]					,							lowerCamelCase_  :List[Any]					,							lowerCamelCase_  :Dict	):





										"""simple docstring"""

										if self.task in ["default", "seq2seq-lm"]:
													lowerCamelCase__     :					List[Any]		=super()._flatten_past_key_values_(lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_	)
										else:
													lowerCamelCase__     :					List[Any]		=super(lowerCamelCase_					,							self	)._flatten_past_key_values_(
													    lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_					,							lowerCamelCase_	)





							def 				UpperCAmelCase__							(  self  :Any					,							lowerCamelCase_  :Mapping[str, Mapping[int, str]]					,							lowerCamelCase_  :str	):





										"""simple docstring"""

										if direction not in ["inputs", "outputs"]:
													raise ValueError(f"""direction must either be \"inputs\" or \"outputs\", but {direction} was given"""	)

										lowerCamelCase__     :					Optional[Any]		='past_key_values' if direction == 'inputs' else 'present'
										lowerCamelCase__	,    lowerCamelCase__     :					Union[str, Any]		=self.num_layers

										lowerCamelCase__     :					Optional[Any]		='past_encoder_sequence'
										lowerCamelCase__     :					Union[str, Any]		='past_decoder_sequence' if direction == 'inputs' else 'past_decoder_sequence + sequence'

										for i in range(lowerCamelCase_	):
													lowerCamelCase__     :					Union[str, Any]		={0: 'batch', 2: decoder_sequence}
													lowerCamelCase__     :					Any		={0: 'batch', 2: decoder_sequence}
													lowerCamelCase__     :					List[Any]		={0: 'batch', 2: encoder_sequence}
													lowerCamelCase__     :					Tuple		={0: 'batch', 2: encoder_sequence}