




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        __SCREAMING_SNAKE_CASE							(	lowerCamelCase						):
					_lowerCamelCase     :   List[Any]							=				"""gpt2"""
					_lowerCamelCase     :   Union[str, Any]							=				["""past_key_values"""]
					_lowerCamelCase     :   List[Any]							=				{
					    """hidden_size""": """n_embd""",
					    """max_position_embeddings""": """n_positions""",
					    """num_attention_heads""": """n_head""",
					    """num_hidden_layers""": """n_layer""",
					}

					def __init__(       self				, __lowercase=50_257				, __lowercase=1_024				, __lowercase=768				, __lowercase=12				, __lowercase=12				, __lowercase=None				, __lowercase="gelu_new"				, __lowercase=0.1				, __lowercase=0.1				, __lowercase=0.1				, __lowercase=1E-5				, __lowercase=0.02				, __lowercase="cls_index"				, __lowercase=True				, __lowercase=None				, __lowercase=True				, __lowercase=0.1				, __lowercase=True				, __lowercase=True				, __lowercase=50_256				, __lowercase=50_256				, __lowercase=False				, __lowercase=False				, **__lowercase				, ):







						'''simple docstring'''




						lowerCamelCase_							:	Optional[int]							     =							vocab_size
						lowerCamelCase_							:	Union[str, Any]							     =							n_positions
						lowerCamelCase_							:	Optional[Any]							     =							n_embd
						lowerCamelCase_							:	Tuple							     =							n_layer
						lowerCamelCase_							:	Any							     =							n_head
						lowerCamelCase_							:	Union[str, Any]							     =							n_inner
						lowerCamelCase_							:	Optional[int]							     =							activation_function
						lowerCamelCase_							:	Optional[int]							     =							resid_pdrop
						lowerCamelCase_							:	Dict							     =							embd_pdrop
						lowerCamelCase_							:	List[Any]							     =							attn_pdrop
						lowerCamelCase_							:	Tuple							     =							layer_norm_epsilon
						lowerCamelCase_							:	Optional[int]							     =							initializer_range
						lowerCamelCase_							:	List[str]							     =							summary_type
						lowerCamelCase_							:	Tuple							     =							summary_use_proj
						lowerCamelCase_							:	List[Any]							     =							summary_activation
						lowerCamelCase_							:	Optional[int]							     =							summary_first_dropout
						lowerCamelCase_							:	int							     =							summary_proj_to_labels
						lowerCamelCase_							:	Union[str, Any]							     =							scale_attn_weights
						lowerCamelCase_							:	Any							     =							use_cache
						lowerCamelCase_							:	Tuple							     =							scale_attn_by_inverse_layer_idx
						lowerCamelCase_							:	Optional[Any]							     =							reorder_and_upcast_attn

						lowerCamelCase_							:	Union[str, Any]							     =							bos_token_id
						lowerCamelCase_							:	Optional[int]							     =							eos_token_id

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


class        __SCREAMING_SNAKE_CASE							(	lowerCamelCase						):

					def __init__(       self				, __lowercase				, __lowercase = "default"				, __lowercase = None				, __lowercase = False				, ):







						'''simple docstring'''




						super().__init__(__lowercase				, task=__lowercase				, patching_specs=__lowercase				, use_past=__lowercase      )
						if not getattr(self._config				, 'pad_token_id'				, __lowercase      ):
							# TODO: how to do that better?
							lowerCamelCase_							:	Optional[int]							     =							0

					@property
					def 			lowercase_							(       self      ):







						'''simple docstring'''




						lowerCamelCase_							:	List[str]							     =							OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}      )
						if self.use_past:
							self.fill_with_past_key_values_(__lowercase				, direction='inputs'      )
							lowerCamelCase_							:	Union[str, Any]							     =							{0: '''batch''', 1: '''past_sequence + sequence'''}
						else:
							lowerCamelCase_							:	Tuple							     =							{0: '''batch''', 1: '''sequence'''}

						return common_inputs

					@property
					def 			lowercase_							(       self      ):







						'''simple docstring'''




						return self._config.n_layer

					@property
					def 			lowercase_							(       self      ):







						'''simple docstring'''




						return self._config.n_head

					def 			lowercase_							(       self				, __lowercase				, __lowercase = -1				, __lowercase = -1				, __lowercase = False				, __lowercase = None				, ):







						'''simple docstring'''




						lowerCamelCase_							:	int							     =							super(__lowercase				, self      ).generate_dummy_inputs(
						    __lowercase				, batch_size=__lowercase				, seq_length=__lowercase				, is_pair=__lowercase				, framework=__lowercase      )

						# We need to order the input in the way they appears in the forward()
						lowerCamelCase_							:	List[Any]							     =							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

								lowerCamelCase_							:	Optional[Any]							     =							common_inputs['''input_ids'''].shape
								# Not using the same length for past_key_values
								lowerCamelCase_							:	Optional[Any]							     =							seqlen + 2
								lowerCamelCase_							:	Union[str, Any]							     =							(
								    batch,
								    self.num_attention_heads,
								    past_key_values_length,
								    self._config.hidden_size // self.num_attention_heads,
								)
								lowerCamelCase_							:	List[Any]							     =							[
								    (torch.zeros(__lowercase      ), torch.zeros(__lowercase      )) for _ in range(self.num_layers      )
								]

						lowerCamelCase_							:	int							     =							common_inputs['''attention_mask''']
						if self.use_past:
							lowerCamelCase_							:	int							     =							ordered_inputs['''attention_mask'''].dtype
							lowerCamelCase_							:	Dict							     =							torch.cat(
							    [ordered_inputs['attention_mask'], torch.ones(__lowercase				, __lowercase				, dtype=__lowercase      )]				, dim=1      )

						return ordered_inputs





					@property
					def 			lowercase_							(       self      ):







						'''simple docstring'''




						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        __SCREAMING_SNAKE_CASE							(	lowerCamelCase						):
					_lowerCamelCase							=				"""deberta"""

					def __init__(       self				, __lowercase=50_265				, __lowercase=768				, __lowercase=12				, __lowercase=12				, __lowercase=3_072				, __lowercase="gelu"				, __lowercase=0.1				, __lowercase=0.1				, __lowercase=512				, __lowercase=0				, __lowercase=0.02				, __lowercase=1E-7				, __lowercase=False				, __lowercase=-1				, __lowercase=0				, __lowercase=True				, __lowercase=None				, __lowercase=0				, __lowercase="gelu"				, **__lowercase				, ):







						'''simple docstring'''




						super().__init__(**__lowercase      )

						lowerCamelCase_							:	Dict							     =							hidden_size
						lowerCamelCase_							:	Tuple							     =							num_hidden_layers
						lowerCamelCase_							:	Dict							     =							num_attention_heads
						lowerCamelCase_							:	Tuple							     =							intermediate_size
						lowerCamelCase_							:	Tuple							     =							hidden_act
						lowerCamelCase_							:	List[Any]							     =							hidden_dropout_prob
						lowerCamelCase_							:	Dict							     =							attention_probs_dropout_prob
						lowerCamelCase_							:	List[Any]							     =							max_position_embeddings
						lowerCamelCase_							:	List[Any]							     =							type_vocab_size
						lowerCamelCase_							:	Union[str, Any]							     =							initializer_range
						lowerCamelCase_							:	int							     =							relative_attention
						lowerCamelCase_							:	Tuple							     =							max_relative_positions
						lowerCamelCase_							:	Optional[Any]							     =							pad_token_id
						lowerCamelCase_							:	int							     =							position_biased_input

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

						lowerCamelCase_							:	Any							     =							pos_att_type
						lowerCamelCase_							:	Any							     =							vocab_size
						lowerCamelCase_							:	List[str]							     =							layer_norm_eps

						lowerCamelCase_							:	str							     =							kwargs.get('pooler_hidden_size'				, __lowercase      )
						lowerCamelCase_							:	List[Any]							     =							pooler_dropout
						lowerCamelCase_							:	str							     =							pooler_hidden_act


class        __SCREAMING_SNAKE_CASE							(	lowerCamelCase						):

					@property
					def 			lowercase_							(       self      ):







						'''simple docstring'''




						if self.task == "multiple-choice":
							lowerCamelCase_							:	Tuple							     =							{0: 'batch', 1: 'choice', 2: 'sequence'}
						else:
							lowerCamelCase_							:	List[str]							     =							{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 			lowercase_							(       self      ):







						'''simple docstring'''




						return 12





					def 			lowercase_							(       self				, __lowercase				, __lowercase = -1				, __lowercase = -1				, __lowercase = -1				, __lowercase = False				, __lowercase = None				, __lowercase = 3				, __lowercase = 40				, __lowercase = 40				, __lowercase = None				, ):







						'''simple docstring'''




						lowerCamelCase_							:	Optional[Any]							     =							super().generate_dummy_inputs(preprocessor=__lowercase				, framework=__lowercase      )
						if self._config.type_vocab_size == 0 and "token_type_ids" in dummy_inputs:
							del dummy_inputs["token_type_ids"]
						return dummy_inputs
