



"""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     =			logging.get_logger(__name__)

_UpperCAmelCase     =			{
    """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 					a	(  UpperCAmelCase__       ):
  UpperCamelCase	:				Tuple     						=					'blenderbot-small'
  UpperCamelCase	:				Union[str, Any]     						=					['past_key_values']
  UpperCamelCase	:				List[Any]     						=					{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}



  def __init__(						self :					List[Any]       ,		lowerCAmelCase :					Dict=5_0265       ,		lowerCAmelCase :					Dict=512       ,		lowerCAmelCase :					Any=8       ,		lowerCAmelCase :					str=2048       ,		lowerCAmelCase :					Union[str, Any]=16       ,		lowerCAmelCase :					List[str]=8       ,		lowerCAmelCase :					str=2048       ,		lowerCAmelCase :					Optional[int]=16       ,		lowerCAmelCase :					List[Any]=0.0       ,		lowerCAmelCase :					int=0.0       ,		lowerCAmelCase :					Optional[int]=True       ,		lowerCAmelCase :					Optional[Any]=True       ,		lowerCAmelCase :					int="gelu"       ,		lowerCAmelCase :					Union[str, Any]=512       ,		lowerCAmelCase :					Any=0.1       ,		lowerCAmelCase :					List[Any]=0.0       ,		lowerCAmelCase :					Union[str, Any]=0.0       ,		lowerCAmelCase :					List[Any]=0.0_2       ,		lowerCAmelCase :					Tuple=1       ,		lowerCAmelCase :					str=False       ,		lowerCAmelCase :					str=0       ,		lowerCAmelCase :					int=1       ,		lowerCAmelCase :					Any=2       ,		lowerCAmelCase :					int=2       ,		**lowerCAmelCase :					Tuple       ,		)     ->					Tuple:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=vocab_size
     SCREAMING_SNAKE_CASE_: Any     			=max_position_embeddings
     SCREAMING_SNAKE_CASE_: Any     			=d_model
     SCREAMING_SNAKE_CASE_: int     			=encoder_ffn_dim
     SCREAMING_SNAKE_CASE_: Optional[int]     			=encoder_layers
     SCREAMING_SNAKE_CASE_: Any     			=encoder_attention_heads
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=decoder_ffn_dim
     SCREAMING_SNAKE_CASE_: Optional[int]     			=decoder_layers
     SCREAMING_SNAKE_CASE_: List[str]     			=decoder_attention_heads
     SCREAMING_SNAKE_CASE_: List[Any]     			=dropout
     SCREAMING_SNAKE_CASE_: Dict     			=attention_dropout
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=activation_dropout
     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=activation_function
     SCREAMING_SNAKE_CASE_: Any     			=init_std
     SCREAMING_SNAKE_CASE_: List[str]     			=encoder_layerdrop
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=decoder_layerdrop
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=use_cache
     SCREAMING_SNAKE_CASE_: int     			=encoder_layers
     SCREAMING_SNAKE_CASE_: str     			=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 					a	(  UpperCAmelCase__       ):



  @property
  def 	lowerCamelCase__       (						self :					List[Any]		)     ->					Mapping[str, Mapping[int, str]]:


     '''simple docstring'''




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

        if self.use_past:
           SCREAMING_SNAKE_CASE_: List[Any]     			={0: """batch"""}
           SCREAMING_SNAKE_CASE_: Dict     			={0: """batch""", 1: """past_decoder_sequence + sequence"""}
        else:
           SCREAMING_SNAKE_CASE_: Optional[int]     			={0: """batch""", 1: """decoder_sequence"""}
           SCREAMING_SNAKE_CASE_: Optional[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.
        SCREAMING_SNAKE_CASE_: Union[str, Any]     			=OrderedDict(
            [
                ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
            ]		)
        if self.use_past:
           SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: Dict     			=self.num_layers
           for i in range(lowerCAmelCase		):
              SCREAMING_SNAKE_CASE_: Dict     			={0: """batch""", 2: """past_sequence + sequence"""}
              SCREAMING_SNAKE_CASE_: Union[str, Any]     			={0: """batch""", 2: """past_sequence + sequence"""}
     else:
        SCREAMING_SNAKE_CASE_: 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 	lowerCamelCase__       (						self :					Dict		)     ->					Mapping[str, Mapping[int, str]]:


     '''simple docstring'''




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



  def 	lowerCamelCase__       (						self :					List[str]       ,		lowerCAmelCase :					PreTrainedTokenizer       ,		lowerCAmelCase :					int = -1       ,		lowerCAmelCase :					int = -1       ,		lowerCAmelCase :					bool = False       ,		lowerCAmelCase :					Optional[TensorType] = None       ,		)     ->					Mapping[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[int]     			=self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
         lowerCAmelCase       ,		lowerCAmelCase       ,		lowerCAmelCase       ,		lowerCAmelCase       ,		lowerCAmelCase		)

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

        SCREAMING_SNAKE_CASE_: List[str]     			=torch.cat(
            [common_inputs["""decoder_attention_mask"""], torch.ones(lowerCAmelCase       ,		lowerCAmelCase		)]       ,		dim=1		)

        SCREAMING_SNAKE_CASE_: Any     			=[]
        # If the number of encoder and decoder layers are present in the model configuration, both are considered
        SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: int     			=self.num_layers
        SCREAMING_SNAKE_CASE_: Dict     			=min(lowerCAmelCase       ,		lowerCAmelCase		)
        SCREAMING_SNAKE_CASE_: Tuple     			=max(lowerCAmelCase       ,		lowerCAmelCase		) - min_num_layers
        SCREAMING_SNAKE_CASE_: Optional[int]     			="""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.
        SCREAMING_SNAKE_CASE_: List[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 	lowerCamelCase__       (						self :					Any       ,		lowerCAmelCase :					PreTrainedTokenizer       ,		lowerCAmelCase :					int = -1       ,		lowerCAmelCase :					int = -1       ,		lowerCAmelCase :					bool = False       ,		lowerCAmelCase :					Optional[TensorType] = None       ,		)     ->					Mapping[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[int]     			=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
        SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: Optional[int]     			=common_inputs["""input_ids"""].shape
        # Not using the same length for past_key_values
        SCREAMING_SNAKE_CASE_: List[Any]     			=seqlen + 2
        SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: Union[str, Any]     			=self.num_layers
        SCREAMING_SNAKE_CASE_			,		SCREAMING_SNAKE_CASE_: Optional[Any]     			=self.num_attention_heads
        SCREAMING_SNAKE_CASE_: List[str]     			=(
            batch,
            num_encoder_attention_heads,
            past_key_values_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )

        SCREAMING_SNAKE_CASE_: Optional[int]     			=common_inputs["""attention_mask"""].dtype
        SCREAMING_SNAKE_CASE_: List[Any]     			=torch.cat(
            [common_inputs["""attention_mask"""], torch.ones(lowerCAmelCase       ,		lowerCAmelCase       ,		dtype=lowerCAmelCase		)]       ,		dim=1		)
        SCREAMING_SNAKE_CASE_: List[str]     			=[
            (torch.zeros(lowerCAmelCase		), torch.zeros(lowerCAmelCase		)) for _ in range(lowerCAmelCase		)
        ]
     return common_inputs



  def 	lowerCamelCase__       (						self :					Any       ,		lowerCAmelCase :					PreTrainedTokenizer       ,		lowerCAmelCase :					int = -1       ,		lowerCAmelCase :					int = -1       ,		lowerCAmelCase :					bool = False       ,		lowerCAmelCase :					Optional[TensorType] = None       ,		)     ->					Mapping[str, Any]:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Tuple     			=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
     SCREAMING_SNAKE_CASE_: str     			=tokenizer.num_special_tokens_to_add(lowerCAmelCase		)
     SCREAMING_SNAKE_CASE_: str     			=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
     SCREAMING_SNAKE_CASE_: Dict     			=[""" """.join([tokenizer.unk_token]		) * seq_length] * batch_size
     SCREAMING_SNAKE_CASE_: Tuple     			=dict(tokenizer(lowerCAmelCase       ,		return_tensors=lowerCAmelCase		)		)
     return common_inputs



  def 	lowerCamelCase__       (						self :					Tuple       ,		lowerCAmelCase :					PreTrainedTokenizer       ,		lowerCAmelCase :					int = -1       ,		lowerCAmelCase :					int = -1       ,		lowerCAmelCase :					bool = False       ,		lowerCAmelCase :					Optional[TensorType] = None       ,		)     ->					Mapping[str, Any]:


     '''simple docstring'''




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


     '''simple docstring'''




     if self.task in ["default", "seq2seq-lm"]:
        SCREAMING_SNAKE_CASE_: Tuple     			=super()._flatten_past_key_values_(lowerCAmelCase       ,		lowerCAmelCase       ,		lowerCAmelCase       ,		lowerCAmelCase		)
     else:
        SCREAMING_SNAKE_CASE_: List[str]     			=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


_UpperCAmelCase     =			{
    """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	(  UpperCAmelCase__       ):
  UpperCamelCase	:				Any     						=					'albert'



  def __init__(						self :					Dict       ,		lowerCAmelCase :					List[str]=3_0000       ,		lowerCAmelCase :					List[Any]=128       ,		lowerCAmelCase :					List[str]=4096       ,		lowerCAmelCase :					str=12       ,		lowerCAmelCase :					str=1       ,		lowerCAmelCase :					Tuple=64       ,		lowerCAmelCase :					Dict=1_6384       ,		lowerCAmelCase :					int=1       ,		lowerCAmelCase :					str="gelu_new"       ,		lowerCAmelCase :					Dict=0       ,		lowerCAmelCase :					Optional[Any]=0       ,		lowerCAmelCase :					str=512       ,		lowerCAmelCase :					Optional[int]=2       ,		lowerCAmelCase :					List[Any]=0.0_2       ,		lowerCAmelCase :					Union[str, Any]=1E-12       ,		lowerCAmelCase :					Tuple=0.1       ,		lowerCAmelCase :					List[Any]="absolute"       ,		lowerCAmelCase :					List[Any]=0       ,		lowerCAmelCase :					int=2       ,		lowerCAmelCase :					Optional[int]=3       ,		**lowerCAmelCase :					int       ,		)     ->					Tuple:


     '''simple docstring'''




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

     SCREAMING_SNAKE_CASE_: List[str]     			=vocab_size
     SCREAMING_SNAKE_CASE_: Optional[int]     			=embedding_size
     SCREAMING_SNAKE_CASE_: Optional[int]     			=hidden_size
     SCREAMING_SNAKE_CASE_: Tuple     			=num_hidden_layers
     SCREAMING_SNAKE_CASE_: Any     			=num_hidden_groups
     SCREAMING_SNAKE_CASE_: List[Any]     			=num_attention_heads
     SCREAMING_SNAKE_CASE_: List[Any]     			=inner_group_num
     SCREAMING_SNAKE_CASE_: Optional[int]     			=hidden_act
     SCREAMING_SNAKE_CASE_: int     			=intermediate_size
     SCREAMING_SNAKE_CASE_: Any     			=hidden_dropout_prob
     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=attention_probs_dropout_prob
     SCREAMING_SNAKE_CASE_: int     			=max_position_embeddings
     SCREAMING_SNAKE_CASE_: Any     			=type_vocab_size
     SCREAMING_SNAKE_CASE_: int     			=initializer_range
     SCREAMING_SNAKE_CASE_: List[Any]     			=layer_norm_eps
     SCREAMING_SNAKE_CASE_: Dict     			=classifier_dropout_prob
     SCREAMING_SNAKE_CASE_: int     			=position_embedding_type







class 					a	(  UpperCAmelCase__       ):



  @property
  def 	lowerCamelCase__       (						self :					Optional[int]		)     ->					Mapping[str, Mapping[int, str]]:


     '''simple docstring'''




     if self.task == "multiple-choice":
        SCREAMING_SNAKE_CASE_: str     			={0: """batch""", 1: """choice""", 2: """sequence"""}
     else:
        SCREAMING_SNAKE_CASE_: Dict     			={0: """batch""", 1: """sequence"""}
     return OrderedDict(
         [
             ("""input_ids""", dynamic_axis),
             ("""attention_mask""", dynamic_axis),
             ("""token_type_ids""", dynamic_axis),
         ]		)



