



'''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_small-90M""": """https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/config.json""",
    # See all BlenderbotSmall models at https://huggingface.co/models?filter=blenderbot_small
}





class _UpperCamelCase		(  __a		):





				'''simple docstring'''





				lowerCAmelCase__            =     """blenderbot-small"""
				lowerCAmelCase__            =     ["""past_key_values"""]
				lowerCAmelCase__            =     {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}

				def __init__(				self	:	Optional[Any]	,							_lowerCAmelCase	:	str=5_0_2_6_5	,							_lowerCAmelCase	:	str=5_1_2	,							_lowerCAmelCase	:	Dict=8	,							_lowerCAmelCase	:	List[str]=2_0_4_8	,							_lowerCAmelCase	:	List[str]=1_6	,							_lowerCAmelCase	:	Optional[int]=8	,							_lowerCAmelCase	:	Dict=2_0_4_8	,							_lowerCAmelCase	:	Tuple=1_6	,							_lowerCAmelCase	:	int=0.0	,							_lowerCAmelCase	:	str=0.0	,							_lowerCAmelCase	:	str=True	,							_lowerCAmelCase	:	List[Any]=True	,							_lowerCAmelCase	:	Optional[int]="gelu"	,							_lowerCAmelCase	:	int=5_1_2	,							_lowerCAmelCase	:	Dict=0.1	,							_lowerCAmelCase	:	int=0.0	,							_lowerCAmelCase	:	Tuple=0.0	,							_lowerCAmelCase	:	Optional[Any]=0.02	,							_lowerCAmelCase	:	int=1	,							_lowerCAmelCase	:	Optional[Any]=False	,							_lowerCAmelCase	:	Tuple=0	,							_lowerCAmelCase	:	List[Any]=1	,							_lowerCAmelCase	:	Optional[Any]=2	,							_lowerCAmelCase	:	List[str]=2	,							**_lowerCAmelCase	:	List[str]	,							):







											'''simple docstring'''

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

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





class _UpperCamelCase		(  __a		):





				'''simple docstring'''





				@property
				def 					__lowerCamelCase  (				self	:	Any):







											'''simple docstring'''

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

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

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







											'''simple docstring'''

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

				def 					__lowerCamelCase  (				self	:	Dict	,							_lowerCAmelCase	:	Dict	,							_lowerCAmelCase	:	str = -1	,							_lowerCAmelCase	:	Optional[Any] = -1	,							_lowerCAmelCase	:	Union[str, Any] = False	,							_lowerCAmelCase	:	Any = None	,							):







											'''simple docstring'''

											__lowercase													=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
											    _UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase)

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

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

																		__lowercase													=torch.cat(
																		    [common_inputs['decoder_attention_mask'], torch.ones(_UpperCamelCase	,							_UpperCamelCase)]	,							dim=1)

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

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

				def 					__lowerCamelCase  (				self	:	Dict	,							_lowerCAmelCase	:	Optional[Any]	,							_lowerCAmelCase	:	int = -1	,							_lowerCAmelCase	:	str = -1	,							_lowerCAmelCase	:	Optional[int] = False	,							_lowerCAmelCase	:	Union[str, Any] = None	,							):







											'''simple docstring'''

											__lowercase													=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
											    _UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase	,							_UpperCamelCase)

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

																		__lowercase													=common_inputs['attention_mask'].dtype
																		__lowercase													=torch.cat(
																		    [common_inputs['attention_mask'], torch.ones(_UpperCamelCase	,							_UpperCamelCase	,							dtype=_UpperCamelCase)]	,							dim=1)
																		__lowercase													=[
																		    (torch.zeros(_UpperCamelCase), torch.zeros(_UpperCamelCase)) for _ in range(_UpperCamelCase)
																		]
											return common_inputs

				def 					__lowerCamelCase  (				self	:	Tuple	,							_lowerCAmelCase	:	Optional[Any]	,							_lowerCAmelCase	:	str = -1	,							_lowerCAmelCase	:	List[Any] = -1	,							_lowerCAmelCase	:	Optional[Any] = False	,							_lowerCAmelCase	:	str = None	,							):







											'''simple docstring'''

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

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

				def 					__lowerCamelCase  (				self	:	int	,							_lowerCAmelCase	:	Any	,							_lowerCAmelCase	:	Tuple = -1	,							_lowerCAmelCase	:	str = -1	,							_lowerCAmelCase	:	Optional[int] = False	,							_lowerCAmelCase	:	Optional[int] = None	,							):







											'''simple docstring'''

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

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

											return common_inputs

				def 					__lowerCamelCase  (				self	:	List[str]	,							_lowerCAmelCase	:	List[str]	,							_lowerCAmelCase	:	List[Any]	,							_lowerCAmelCase	:	Optional[int]	,							_lowerCAmelCase	:	Union[str, Any]):







											'''simple docstring'''

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





from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_A  =	logging.get_logger(__name__)

_A  =	{
    "kssteven/ibert-roberta-base": "https://huggingface.co/kssteven/ibert-roberta-base/resolve/main/config.json",
    "kssteven/ibert-roberta-large": "https://huggingface.co/kssteven/ibert-roberta-large/resolve/main/config.json",
    "kssteven/ibert-roberta-large-mnli": (
        "https://huggingface.co/kssteven/ibert-roberta-large-mnli/resolve/main/config.json"
    ),
}





class       _lowerCAmelCase   (      __a			):
				_lowercase     						='''ibert'''




				def __init__(   self							,							_UpperCamelCase=30_522							,							_UpperCamelCase=768							,							_UpperCamelCase=12							,							_UpperCamelCase=12							,							_UpperCamelCase=3_072							,							_UpperCamelCase="gelu"							,							_UpperCamelCase=0.1							,							_UpperCamelCase=0.1							,							_UpperCamelCase=512							,							_UpperCamelCase=2							,							_UpperCamelCase=0.02							,							_UpperCamelCase=1e-1_2							,							_UpperCamelCase=1							,							_UpperCamelCase=0							,							_UpperCamelCase=2							,							_UpperCamelCase="absolute"							,							_UpperCamelCase=False							,							_UpperCamelCase="none"							,							**_UpperCamelCase							,							)							-> List[str]:
							super().__init__(pad_token_id=_UpperCamelCase							,							bos_token_id=_UpperCamelCase							,							eos_token_id=_UpperCamelCase							,							**_UpperCamelCase	)

							lowerCAmelCase_         =      vocab_size
							lowerCAmelCase_         =      hidden_size
							lowerCAmelCase_         =      num_hidden_layers
							lowerCAmelCase_         =      num_attention_heads
							lowerCAmelCase_         =      hidden_act
							lowerCAmelCase_         =      intermediate_size
							lowerCAmelCase_         =      hidden_dropout_prob
							lowerCAmelCase_         =      attention_probs_dropout_prob
							lowerCAmelCase_         =      max_position_embeddings
							lowerCAmelCase_         =      type_vocab_size
							lowerCAmelCase_         =      initializer_range
							lowerCAmelCase_         =      layer_norm_eps
							lowerCAmelCase_         =      position_embedding_type
							lowerCAmelCase_         =      quant_mode
							lowerCAmelCase_         =      force_dequant





class       _lowerCAmelCase   (      __a			):




				@property
				def 	__a		(   self	)							-> Mapping[str, Mapping[int, str]]:
							if self.task == "multiple-choice":
										lowerCAmelCase_         =      {0: "batch", 1: "choice", 2: "sequence"}
							else:
										lowerCAmelCase_         =      {0: "batch", 1: "sequence"}
							return OrderedDict(
							    [
							        ("input_ids", dynamic_axis),
							        ("attention_mask", dynamic_axis),
							    ]	)



