






"""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_					:						Union[str, Any]      = logging.get_logger(__name__)

lowerCamelCase_					:						List[Any]      = {
    '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 			_UpperCAmelCase  (       UpperCAmelCase__		):



      '''simple docstring'''
      lowercase_				:			Optional[int]        =       """blenderbot"""
      lowercase_				:			Any        =       ["""past_key_values"""]
      lowercase_				:			int        =       {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}

      def __init__(					self ,				snake_case_=8_0_0_8 ,				snake_case_=1_2_8 ,				snake_case_=2 ,				snake_case_=1_0_2_4_0 ,				snake_case_=3_2 ,				snake_case_=2_4 ,				snake_case_=1_0_2_4_0 ,				snake_case_=3_2 ,				snake_case_=0.0 ,				snake_case_=0.0 ,				snake_case_=True ,				snake_case_=True ,				snake_case_="gelu" ,				snake_case_=2_5_6_0 ,				snake_case_=0.1 ,				snake_case_=0.0 ,				snake_case_=0.0 ,				snake_case_=0.02 ,				snake_case_=1 ,				snake_case_=False ,				snake_case_=0 ,				snake_case_=1 ,				snake_case_=2 ,				snake_case_=3 ,				snake_case_=2 ,				**snake_case_ ,				):

        """simple docstring"""

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

        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_ ,				encoder_no_repeat_ngram_size=snake_case_ ,				forced_eos_token_id=snake_case_ ,				**snake_case_ ,				)


class 			_UpperCAmelCase  (       UpperCAmelCase__		):



      '''simple docstring'''

      @property
      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        if self.task in ["default", "seq2seq-lm"]:
          A_  :	Tuple    						=  OrderedDict(
              [
                  ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                  ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
              ]  )
          if self.use_past:
            A_  :	str    						=  {0: 'batch'}
            A_  :	Optional[Any]    						=  {0: 'batch', 1: 'past_decoder_sequence + sequence'}
          else:
            A_  :	Any    						=  {0: 'batch', 1: 'decoder_sequence'}
            A_  :	Union[str, Any]    						=  {0: 'batch', 1: 'decoder_sequence'}
          if self.use_past:
            self.fill_with_past_key_values_(snake_case_ ,				direction='inputs'  )
        elif self.task == "causal-lm":
          A_  :	List[Any]    						=  OrderedDict(
              [
                  ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
                  ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
              ]  )
          if self.use_past:
            A_  :	Dict    						=  self.num_layers
            for i in range(snake_case_  ):
              A_  :	Any    						=  {0: 'batch', 2: 'past_sequence + sequence'}
              A_  :	str    						=  {0: 'batch', 2: 'past_sequence + sequence'}
        else:
          A_  :	Tuple    						=  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  lowerCamelCase_      (					self  ):

        """simple docstring"""

        if self.task in ["default", "seq2seq-lm"]:
          A_  :	List[str]    						=  super().outputs
        else:
          A_  :	int    						=  super(snake_case_ ,				self  ).outputs
          if self.use_past:
            A_  :	Any    						=  self.num_layers
            for i in range(snake_case_  ):
              A_  :	Any    						=  {0: 'batch', 2: 'past_sequence + sequence'}
              A_  :	Dict    						=  {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"""

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

          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_  ),
                )  )
        return common_inputs

      def  lowerCamelCase_      (					self ,				snake_case_ ,				snake_case_ = -1 ,				snake_case_ = -1 ,				snake_case_ = False ,				snake_case_ = None ,				):

        """simple docstring"""

        A_  :	List[Any]    						=  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
          A_  :	Union[str, Any]    						=  common_inputs['input_ids'].shape
          A_  :	str    						=  seqlen
          A_  :	List[str]    						=  self.num_layers
          A_  :	int    						=  self.num_attention_heads
          A_  :	Any    						=  (
              batch,
              num_encoder_attention_heads,
              past_key_values_length,
              self._config.hidden_size // num_encoder_attention_heads,
          )
          A_  :	str    						=  common_inputs['attention_mask'].dtype
          A_  :	List[str]    						=  torch.cat(
              [common_inputs['attention_mask'], torch.ones(snake_case_ ,				snake_case_ ,				dtype=snake_case_  )] ,				dim=1  )
          A_  :	str    						=  [
              (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"""

        A_  :	Tuple    						=  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
        A_  :	str    						=  tokenizer.num_special_tokens_to_add(snake_case_  )
        A_  :	Any    						=  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
        A_  :	int    						=  [' '.join([tokenizer.unk_token]  ) * seq_length] * batch_size
        A_  :	Any    						=  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"]:
          A_  :	List[str]    						=  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":
          A_  :	Dict    						=  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:
          A_  :	int    						=  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"]:
          A_  :	str    						=  super()._flatten_past_key_values_(snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_  )
        else:
          A_  :	int    						=  super(snake_case_ ,				self  )._flatten_past_key_values_(
              snake_case_ ,				snake_case_ ,				snake_case_ ,				snake_case_  )

      def  lowerCamelCase_      (					self ,				snake_case_ ,				snake_case_  ):

        """simple docstring"""

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

        A_  :	Optional[int]    						=  'past_key_values' if direction == 'inputs' else 'present'
        A_  :	Optional[Any]    						=  self.num_layers

        A_  :	Optional[int]    						=  'past_encoder_sequence'
        A_  :	List[Any]    						=  'past_decoder_sequence' if direction == 'inputs' else 'past_decoder_sequence + sequence'

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






"""simple docstring"""




from collections import OrderedDict
from typing import Mapping

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


lowerCamelCase_					:						List[str]      = logging.get_logger(__name__)

lowerCamelCase_					:						Optional[int]      = {
    'google/electra-small-generator': 'https://huggingface.co/google/electra-small-generator/resolve/main/config.json',
    'google/electra-base-generator': 'https://huggingface.co/google/electra-base-generator/resolve/main/config.json',
    'google/electra-large-generator': 'https://huggingface.co/google/electra-large-generator/resolve/main/config.json',
    'google/electra-small-discriminator': (
        'https://huggingface.co/google/electra-small-discriminator/resolve/main/config.json'
    ),
    'google/electra-base-discriminator': (
        'https://huggingface.co/google/electra-base-discriminator/resolve/main/config.json'
    ),
    'google/electra-large-discriminator': (
        'https://huggingface.co/google/electra-large-discriminator/resolve/main/config.json'
    ),
}

class 			_UpperCAmelCase  (       UpperCAmelCase__		):



      '''simple docstring'''
      lowercase_				:			Tuple        =       """electra"""

      def __init__(					self ,				snake_case_=3_0_5_2_2 ,				snake_case_=1_2_8 ,				snake_case_=2_5_6 ,				snake_case_=1_2 ,				snake_case_=4 ,				snake_case_=1_0_2_4 ,				snake_case_="gelu" ,				snake_case_=0.1 ,				snake_case_=0.1 ,				snake_case_=5_1_2 ,				snake_case_=2 ,				snake_case_=0.02 ,				snake_case_=1E-12 ,				snake_case_="first" ,				snake_case_=True ,				snake_case_="gelu" ,				snake_case_=0.1 ,				snake_case_=0 ,				snake_case_="absolute" ,				snake_case_=True ,				snake_case_=None ,				**snake_case_ ,				):

        """simple docstring"""

        super().__init__(pad_token_id=snake_case_ ,				**snake_case_  )

        A_  :	Optional[Any]    						=  vocab_size
        A_  :	Any    						=  embedding_size
        A_  :	Optional[int]    						=  hidden_size
        A_  :	Tuple    						=  num_hidden_layers
        A_  :	Tuple    						=  num_attention_heads
        A_  :	List[Any]    						=  intermediate_size
        A_  :	Any    						=  hidden_act
        A_  :	str    						=  hidden_dropout_prob
        A_  :	Any    						=  attention_probs_dropout_prob
        A_  :	str    						=  max_position_embeddings
        A_  :	Optional[Any]    						=  type_vocab_size
        A_  :	Dict    						=  initializer_range
        A_  :	Optional[int]    						=  layer_norm_eps

        A_  :	int    						=  summary_type
        A_  :	List[str]    						=  summary_use_proj
        A_  :	Optional[Any]    						=  summary_activation
        A_  :	Optional[Any]    						=  summary_last_dropout
        A_  :	List[Any]    						=  position_embedding_type
        A_  :	Union[str, Any]    						=  use_cache
        A_  :	Tuple    						=  classifier_dropout


class 			_UpperCAmelCase  (       UpperCAmelCase__		):



      '''simple docstring'''

      @property
      def  lowerCamelCase_      (					self  ):

        """simple docstring"""

        if self.task == "multiple-choice":
          A_  :	int    						=  {0: 'batch', 1: 'choice', 2: 'sequence'}
        else:
          A_  :	Optional[Any]    						=  {0: 'batch', 1: 'sequence'}
        return OrderedDict(
            [
                ('input_ids', dynamic_axis),
                ('attention_mask', dynamic_axis),
                ('token_type_ids', dynamic_axis),
            ]  )