





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

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


UpperCAmelCase_											=  logging.get_logger(__name__)

UpperCAmelCase_											=  {
    "gpt2": "https://huggingface.co/gpt2/resolve/main/config.json",
    "gpt2-medium": "https://huggingface.co/gpt2-medium/resolve/main/config.json",
    "gpt2-large": "https://huggingface.co/gpt2-large/resolve/main/config.json",
    "gpt2-xl": "https://huggingface.co/gpt2-xl/resolve/main/config.json",
    "distilgpt2": "https://huggingface.co/distilgpt2/resolve/main/config.json",
}




class  __UpperCamelCase						(       A__						):
     __A  :     Union[str, Any]            =      """gpt2"""
     __A  :     Union[str, Any]            =      ["""past_key_values"""]
     __A  :     Dict            =      {
         """hidden_size""": """n_embd""",
         """max_position_embeddings""": """n_positions""",
         """num_attention_heads""": """n_head""",
         """num_hidden_layers""": """n_layer""",
     }





     def __init__(    self							,       _UpperCamelCase=50257							,       _UpperCamelCase=1024							,       _UpperCamelCase=768							,       _UpperCamelCase=12							,       _UpperCamelCase=12							,       _UpperCamelCase=None							,       _UpperCamelCase="gelu_new"							,       _UpperCamelCase=0.1							,       _UpperCamelCase=0.1							,       _UpperCamelCase=0.1							,       _UpperCamelCase=1e-5							,       _UpperCamelCase=0.02							,       _UpperCamelCase="cls_index"							,       _UpperCamelCase=True							,       _UpperCamelCase=None							,       _UpperCamelCase=True							,       _UpperCamelCase=0.1							,       _UpperCamelCase=True							,       _UpperCamelCase=True							,       _UpperCamelCase=50256							,       _UpperCamelCase=50256							,       _UpperCamelCase=False							,       _UpperCamelCase=False							,       **_UpperCamelCase							,       ):
        _UpperCAmelCase											=      vocab_size
        _UpperCAmelCase											=      n_positions
        _UpperCAmelCase											=      n_embd
        _UpperCAmelCase											=      n_layer
        _UpperCAmelCase											=      n_head
        _UpperCAmelCase											=      n_inner
        _UpperCAmelCase											=      activation_function
        _UpperCAmelCase											=      resid_pdrop
        _UpperCAmelCase											=      embd_pdrop
        _UpperCAmelCase											=      attn_pdrop
        _UpperCAmelCase											=      layer_norm_epsilon
        _UpperCAmelCase											=      initializer_range
        _UpperCAmelCase											=      summary_type
        _UpperCAmelCase											=      summary_use_proj
        _UpperCAmelCase											=      summary_activation
        _UpperCAmelCase											=      summary_first_dropout
        _UpperCAmelCase											=      summary_proj_to_labels
        _UpperCAmelCase											=      scale_attn_weights
        _UpperCAmelCase											=      use_cache
        _UpperCAmelCase											=      scale_attn_by_inverse_layer_idx
        _UpperCAmelCase											=      reorder_and_upcast_attn

        _UpperCAmelCase											=      bos_token_id
        _UpperCAmelCase											=      eos_token_id

        super().__init__(bos_token_id=_UpperCamelCase							,       eos_token_id=_UpperCamelCase							,       **_UpperCamelCase				)




class  __UpperCamelCase						(       A__						):





     def __init__(    self							,       _UpperCamelCase							,       _UpperCamelCase = "default"							,       _UpperCamelCase = None							,       _UpperCamelCase = False							,       ):
        super().__init__(_UpperCamelCase							,       task=_UpperCamelCase							,       patching_specs=_UpperCamelCase							,       use_past=_UpperCamelCase				)
        if not getattr(self._config							,       '''pad_token_id'''							,       _UpperCamelCase				):
           # TODO: how to do that better?
           _UpperCAmelCase											=      0





     @property
     def 		UpperCamelCase(    self				):
        _UpperCAmelCase											=      OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}				)
        if self.use_past:
           self.fill_with_past_key_values_(_UpperCamelCase							,       direction='''inputs'''				)
           _UpperCAmelCase											=      {0: '''batch''', 1: '''past_sequence + sequence'''}
        else:
           _UpperCAmelCase											=      {0: '''batch''', 1: '''sequence'''}

        return common_inputs





     @property
     def 		UpperCamelCase(    self				):
        return self._config.n_layer





     @property
     def 		UpperCamelCase(    self				):
        return self._config.n_head





     def 		UpperCamelCase(    self							,       _UpperCamelCase							,       _UpperCamelCase = -1							,       _UpperCamelCase = -1							,       _UpperCamelCase = False							,       _UpperCamelCase = None							,       ):
        _UpperCAmelCase											=      super(_UpperCamelCase							,       self				).generate_dummy_inputs(
            _UpperCamelCase							,       batch_size=_UpperCamelCase							,       seq_length=_UpperCamelCase							,       is_pair=_UpperCamelCase							,       framework=_UpperCamelCase				)

        # We need to order the input in the way they appears in the forward()
        _UpperCAmelCase											=      OrderedDict({'''input_ids''': common_inputs['''input_ids''']}				)

        # Need to add the past_keys
        if self.use_past:
           if not is_torch_available():
              raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''				)
           else:
              import torch

              _UpperCAmelCase					,			_UpperCAmelCase											=      common_inputs['''input_ids'''].shape
              # Not using the same length for past_key_values
              _UpperCAmelCase											=      seqlen + 2
              _UpperCAmelCase											=      (
                  batch,
                  self.num_attention_heads,
                  past_key_values_length,
                  self._config.hidden_size // self.num_attention_heads,
              )
              _UpperCAmelCase											=      [
                  (torch.zeros(_UpperCamelCase				), torch.zeros(_UpperCamelCase				)) for _ in range(self.num_layers				)
              ]

        _UpperCAmelCase											=      common_inputs['''attention_mask''']
        if self.use_past:
           _UpperCAmelCase											=      ordered_inputs['''attention_mask'''].dtype
           _UpperCAmelCase											=      torch.cat(
               [ordered_inputs['''attention_mask'''], torch.ones(_UpperCamelCase							,       _UpperCamelCase							,       dtype=_UpperCamelCase				)]							,       dim=1				)

        return ordered_inputs





     @property
     def 		UpperCamelCase(    self				):
        return 13






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

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


if TYPE_CHECKING:
   from ... import FeatureExtractionMixin, PreTrainedTokenizerBase, TensorType


UpperCAmelCase_											=  logging.get_logger(__name__)

UpperCAmelCase_											=  {
    "microsoft/deberta-base": "https://huggingface.co/microsoft/deberta-base/resolve/main/config.json",
    "microsoft/deberta-large": "https://huggingface.co/microsoft/deberta-large/resolve/main/config.json",
    "microsoft/deberta-xlarge": "https://huggingface.co/microsoft/deberta-xlarge/resolve/main/config.json",
    "microsoft/deberta-base-mnli": "https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/config.json",
    "microsoft/deberta-large-mnli": "https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/config.json",
    "microsoft/deberta-xlarge-mnli": "https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/config.json",
}




class  __UpperCamelCase						(       A__						):
     __A  :     Dict            =      """deberta"""





     def __init__(    self							,       _UpperCamelCase=50265							,       _UpperCamelCase=768							,       _UpperCamelCase=12							,       _UpperCamelCase=12							,       _UpperCamelCase=3072							,       _UpperCamelCase="gelu"							,       _UpperCamelCase=0.1							,       _UpperCamelCase=0.1							,       _UpperCamelCase=512							,       _UpperCamelCase=0							,       _UpperCamelCase=0.02							,       _UpperCamelCase=1e-7							,       _UpperCamelCase=False							,       _UpperCamelCase=-1							,       _UpperCamelCase=0							,       _UpperCamelCase=True							,       _UpperCamelCase=None							,       _UpperCamelCase=0							,       _UpperCamelCase="gelu"							,       **_UpperCamelCase							,       ):
        super().__init__(**_UpperCamelCase				)

        _UpperCAmelCase											=      hidden_size
        _UpperCAmelCase											=      num_hidden_layers
        _UpperCAmelCase											=      num_attention_heads
        _UpperCAmelCase											=      intermediate_size
        _UpperCAmelCase											=      hidden_act
        _UpperCAmelCase											=      hidden_dropout_prob
        _UpperCAmelCase											=      attention_probs_dropout_prob
        _UpperCAmelCase											=      max_position_embeddings
        _UpperCAmelCase											=      type_vocab_size
        _UpperCAmelCase											=      initializer_range
        _UpperCAmelCase											=      relative_attention
        _UpperCAmelCase											=      max_relative_positions
        _UpperCAmelCase											=      pad_token_id
        _UpperCAmelCase											=      position_biased_input

        # Backwards compatibility
        if type(_UpperCamelCase				) == str:
           _UpperCAmelCase											=      [x.strip() for x in pos_att_type.lower().split('''|'''				)]

        _UpperCAmelCase											=      pos_att_type
        _UpperCAmelCase											=      vocab_size
        _UpperCAmelCase											=      layer_norm_eps

        _UpperCAmelCase											=      kwargs.get('''pooler_hidden_size'''							,       _UpperCamelCase				)
        _UpperCAmelCase											=      pooler_dropout
        _UpperCAmelCase											=      pooler_hidden_act




class  __UpperCamelCase						(       A__						):





     @property
     def 		UpperCamelCase(    self				):
        if self.task == "multiple-choice":
           _UpperCAmelCase											=      {0: '''batch''', 1: '''choice''', 2: '''sequence'''}
        else:
           _UpperCAmelCase											=      {0: '''batch''', 1: '''sequence'''}
        if self._config.type_vocab_size > 0:
           return OrderedDict(
               [('''input_ids''', dynamic_axis), ('''attention_mask''', dynamic_axis), ('''token_type_ids''', dynamic_axis)]				)
        else:
           return OrderedDict([('''input_ids''', dynamic_axis), ('''attention_mask''', dynamic_axis)]				)





     @property
     def 		UpperCamelCase(    self				):
        return 12





     def 		UpperCamelCase(    self							,       _UpperCamelCase							,       _UpperCamelCase = -1							,       _UpperCamelCase = -1							,       _UpperCamelCase = -1							,       _UpperCamelCase = False							,       _UpperCamelCase = None							,       _UpperCamelCase = 3							,       _UpperCamelCase = 40							,       _UpperCamelCase = 40							,       _UpperCamelCase = None							,       ):
        _UpperCAmelCase											=      super().generate_dummy_inputs(preprocessor=_UpperCamelCase							,       framework=_UpperCamelCase				)
        if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
           del dummy_inputs["token_type_ids"]
        return dummy_inputs