


"""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


UpperCamelCase    :					Union[str, Any]							   =   logging.get_logger(__name__)

UpperCamelCase    :					Tuple							   =   {
    "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       lowerCamelCase__    ( lowerCAmelCase__      ):
						lowerCAmelCase  	=  '''blenderbot-small'''
						lowerCAmelCase  	=  ['''past_key_values''']
						lowerCAmelCase  	=  {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}







						def __init__(				self :     int      ,      _lowercase :     int=50_265      ,      _lowercase :     Union[str, Any]=512      ,      _lowercase :     Tuple=8      ,      _lowercase :     List[str]=2_048      ,      _lowercase :     str=16      ,      _lowercase :     Optional[Any]=8      ,      _lowercase :     List[str]=2_048      ,      _lowercase :     Dict=16      ,      _lowercase :     List[str]=0.0      ,      _lowercase :     Dict=0.0      ,      _lowercase :     Any=True      ,      _lowercase :     Optional[int]=True      ,      _lowercase :     List[str]="gelu"      ,      _lowercase :     Any=512      ,      _lowercase :     List[str]=0.1      ,      _lowercase :     Union[str, Any]=0.0      ,      _lowercase :     Union[str, Any]=0.0      ,      _lowercase :     Union[str, Any]=0.0_2      ,      _lowercase :     Optional[Any]=1      ,      _lowercase :     Optional[int]=False      ,      _lowercase :     Any=0      ,      _lowercase :     int=1      ,      _lowercase :     Dict=2      ,      _lowercase :     Optional[Any]=2      ,      **_lowercase :     Optional[Any]      ,      ):
								A       							=			vocab_size
								A       							=			max_position_embeddings
								A       							=			d_model
								A       							=			encoder_ffn_dim
								A       							=			encoder_layers
								A       							=			encoder_attention_heads
								A       							=			decoder_ffn_dim
								A       							=			decoder_layers
								A       							=			decoder_attention_heads
								A       							=			dropout
								A       							=			attention_dropout
								A       							=			activation_dropout
								A       							=			activation_function
								A       							=			init_std
								A       							=			encoder_layerdrop
								A       							=			decoder_layerdrop
								A       							=			use_cache
								A       							=			encoder_layers
								A       							=			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      ,      forced_eos_token_id=__lowerCAmelCase      ,      **__lowerCAmelCase      ,      )



class       lowerCamelCase__    ( lowerCAmelCase__      ):







						@property
						def __a    (				self :     Dict		):


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

										if self.use_past:
												A       							=			{0: 'batch'}
												A       							=			{0: 'batch', 1: 'past_decoder_sequence + sequence'}
										else:
												A       							=			{0: 'batch', 1: 'decoder_sequence'}
												A       							=			{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.
										A       							=			OrderedDict(
										    [
										        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
										        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
										    ]		)
										if self.use_past:
												A							,			A       							=			self.num_layers
												for i in range(__lowerCAmelCase		):
														A       							=			{0: 'batch', 2: 'past_sequence + sequence'}
														A       							=			{0: 'batch', 2: 'past_sequence + sequence'}
								else:
										A       							=			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 :     List[Any]		):


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







						def __a    (				self :     Union[str, Any]      ,      _lowercase :     Optional[Any]      ,      _lowercase :     Optional[int] = -1      ,      _lowercase :     Tuple = -1      ,      _lowercase :     int = False      ,      _lowercase :     Tuple = None      ,      ):
								A       							=			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
								    __lowerCAmelCase      ,      __lowerCAmelCase      ,      __lowerCAmelCase      ,      __lowerCAmelCase      ,      __lowerCAmelCase		)

								# Generate decoder inputs
								A       							=			seq_length if not self.use_past else 1
								A       							=			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
								    __lowerCAmelCase      ,      __lowerCAmelCase      ,      __lowerCAmelCase      ,      __lowerCAmelCase      ,      __lowerCAmelCase		)
								A       							=			{f'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
								A       							=			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
										A							,			A       							=			common_inputs['input_ids'].shape
										A       							=			common_inputs['decoder_input_ids'].shape[1]
										A							,			A       							=			self.num_attention_heads
										A       							=			(
										    batch,
										    num_encoder_attention_heads,
										    encoder_seq_length,
										    self._config.hidden_size // num_encoder_attention_heads,
										)
										A       							=			decoder_seq_length + 3
										A       							=			(
										    batch,
										    num_decoder_attention_heads,
										    decoder_past_length,
										    self._config.hidden_size // num_decoder_attention_heads,
										)

										A       							=			torch.cat(
										    [common_inputs['decoder_attention_mask'], torch.ones(__lowerCAmelCase      ,      __lowerCAmelCase		)]      ,      dim=1		)

										A       							=			[]
										# If the number of encoder and decoder layers are present in the model configuration, both are considered
										A							,			A       							=			self.num_layers
										A       							=			min(__lowerCAmelCase      ,      __lowerCAmelCase		)
										A       							=			max(__lowerCAmelCase      ,      __lowerCAmelCase		) - min_num_layers
										A       							=			'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.
										A       							=			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 :     List[Any]      ,      _lowercase :     Optional[Any]      ,      _lowercase :     Optional[Any] = -1      ,      _lowercase :     Tuple = -1      ,      _lowercase :     Optional[int] = False      ,      _lowercase :     Optional[Any] = None      ,      ):
								A       							=			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
										A							,			A       							=			common_inputs['input_ids'].shape
										# Not using the same length for past_key_values
										A       							=			seqlen + 2
										A							,			A       							=			self.num_layers
										A							,			A       							=			self.num_attention_heads
										A       							=			(
										    batch,
										    num_encoder_attention_heads,
										    past_key_values_length,
										    self._config.hidden_size // num_encoder_attention_heads,
										)

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







						def __a    (				self :     Dict      ,      _lowercase :     List[str]      ,      _lowercase :     Tuple = -1      ,      _lowercase :     Dict = -1      ,      _lowercase :     Optional[Any] = False      ,      _lowercase :     Any = None      ,      ):
								A       							=			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
								A       							=			tokenizer.num_special_tokens_to_add(__lowerCAmelCase		)
								A       							=			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
								A       							=			[' '.join([tokenizer.unk_token]		) * seq_length] * batch_size
								A       							=			dict(tokenizer(__lowerCAmelCase      ,      return_tensors=__lowerCAmelCase		)		)
								return common_inputs







						def __a    (				self :     str      ,      _lowercase :     Any      ,      _lowercase :     int = -1      ,      _lowercase :     List[Any] = -1      ,      _lowercase :     Union[str, Any] = False      ,      _lowercase :     Dict = None      ,      ):


								if self.task in ["default", "seq2seq-lm"]:
										A       							=			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":
										A       							=			self._generate_dummy_inputs_for_causal_lm(
										    __lowerCAmelCase      ,      batch_size=__lowerCAmelCase      ,      seq_length=__lowerCAmelCase      ,      is_pair=__lowerCAmelCase      ,      framework=__lowerCAmelCase		)
								else:
										A       							=			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 :     Tuple      ,      _lowercase :     List[str]      ,      _lowercase :     List[Any]      ,      _lowercase :     List[str]      ,      _lowercase :     int		):


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






'''simple docstring'''




from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig


__lowercase        =    {
    '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/config.json''',
    '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/config.json''',
    '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/config.json''',
    '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/config.json''',
    '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/config.json''',
    '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/config.json''',
    '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/config.json''',
    '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/config.json''',
}






class 							a__(   lowerCAmelCase__      ):


			'''simple docstring'''






			UpperCAmelCase_     :	List[str]						=			'''albert'''



			def __init__(  self			,       __lowerCAmelCase=30000			,       __lowerCAmelCase=128			,       __lowerCAmelCase=4096			,       __lowerCAmelCase=12			,       __lowerCAmelCase=1			,       __lowerCAmelCase=64			,       __lowerCAmelCase=16384			,       __lowerCAmelCase=1			,       __lowerCAmelCase="gelu_new"			,       __lowerCAmelCase=0			,       __lowerCAmelCase=0			,       __lowerCAmelCase=512			,       __lowerCAmelCase=2			,       __lowerCAmelCase=0.02			,       __lowerCAmelCase=1E-1_2			,       __lowerCAmelCase=0.1			,       __lowerCAmelCase="absolute"			,       __lowerCAmelCase=0			,       __lowerCAmelCase=2			,       __lowerCAmelCase=3			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					super().__init__(pad_token_id=__lowerCAmelCase			,       bos_token_id=__lowerCAmelCase			,       eos_token_id=__lowerCAmelCase			,       **__lowerCAmelCase)

					lowerCAmelCase     =    vocab_size
					lowerCAmelCase     =    embedding_size
					lowerCAmelCase     =    hidden_size
					lowerCAmelCase     =    num_hidden_layers
					lowerCAmelCase     =    num_hidden_groups
					lowerCAmelCase     =    num_attention_heads
					lowerCAmelCase     =    inner_group_num
					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     =    classifier_dropout_prob
					lowerCAmelCase     =    position_embedding_type







class 							a__(   lowerCAmelCase__      ):


			'''simple docstring'''






			@property
			def 				a_			(  self):




					"""simple docstring"""


					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),
					        ("""token_type_ids""", dynamic_axis),
					    ])




