






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


a_      = logging.get_logger(__name__)

a_      = {
    """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__   (     _a    ):
		_UpperCAmelCase         ='''gpt2'''
		_UpperCAmelCase         =['''past_key_values''']
		_UpperCAmelCase         ={
		    '''hidden_size''': '''n_embd''',
		    '''max_position_embeddings''': '''n_positions''',
		    '''num_attention_heads''': '''n_head''',
		    '''num_hidden_layers''': '''n_layer''',
		}



		def __init__(    self:    Optional[Any]				,   a:    Optional[int]=5_02_57				,   a:    List[Any]=10_24				,   a:    str=7_68				,   a:    Optional[int]=12				,   a:    Optional[int]=12				,   a:    int=None				,   a:    Optional[int]="gelu_new"				,   a:    int=0.1				,   a:    int=0.1				,   a:    Dict=0.1				,   a:    List[str]=1e-5				,   a:    Union[str, Any]=0.02				,   a:    List[str]="cls_index"				,   a:    Tuple=True				,   a:    str=None				,   a:    Any=True				,   a:    List[Any]=0.1				,   a:    Union[str, Any]=True				,   a:    List[str]=True				,   a:    Dict=5_02_56				,   a:    List[Any]=5_02_56				,   a:    List[str]=False				,   a:    int=False				,   **a:    int				,   )  ->Dict:






								'''simple docstring'''


								a_				     =   vocab_size
								a_				     =   n_positions
								a_				     =   n_embd
								a_				     =   n_layer
								a_				     =   n_head
								a_				     =   n_inner
								a_				     =   activation_function
								a_				     =   resid_pdrop
								a_				     =   embd_pdrop
								a_				     =   attn_pdrop
								a_				     =   layer_norm_epsilon
								a_				     =   initializer_range
								a_				     =   summary_type
								a_				     =   summary_use_proj
								a_				     =   summary_activation
								a_				     =   summary_first_dropout
								a_				     =   summary_proj_to_labels
								a_				     =   scale_attn_weights
								a_				     =   use_cache
								a_				     =   scale_attn_by_inverse_layer_idx
								a_				     =   reorder_and_upcast_attn

								a_				     =   bos_token_id
								a_				     =   eos_token_id

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





class 		SCREAMING_SNAKE_CASE__   (     _a    ):



		def __init__(    self:    Any				,   a:    List[Any]				,   a:    Optional[int] = "default"				,   a:    Optional[int] = None				,   a:    str = False				,   )  ->Optional[int]:






								'''simple docstring'''


								super().__init__(lowerCamelCase__				,   task=lowerCamelCase__				,   patching_specs=lowerCamelCase__				,   use_past=lowerCamelCase__)
								if not getattr(self._config				,   "pad_token_id"				,   lowerCamelCase__):
														# TODO: how to do that better?
														a_				     =   0



		@property
		def _lowerCAmelCase     (    self:    Any)  ->Tuple:






								'''simple docstring'''


								a_				     =   OrderedDict({"input_ids": {0: "batch", 1: "sequence"}})
								if self.use_past:
														self.fill_with_past_key_values_(lowerCamelCase__				,   direction="inputs")
														a_				     =   {0: "batch", 1: "past_sequence + sequence"}
								else:
														a_				     =   {0: "batch", 1: "sequence"}

								return common_inputs



		@property
		def _lowerCAmelCase     (    self:    Union[str, Any])  ->Optional[Any]:






								'''simple docstring'''


								return self._config.n_layer



		@property
		def _lowerCAmelCase     (    self:    Any)  ->Union[str, Any]:






								'''simple docstring'''


								return self._config.n_head



		def _lowerCAmelCase     (    self:    Union[str, Any]				,   a:    Tuple				,   a:    Any = -1				,   a:    Optional[int] = -1				,   a:    List[str] = False				,   a:    List[Any] = None				,   )  ->int:






								'''simple docstring'''


								a_				     =   super(lowerCamelCase__				,   self).generate_dummy_inputs(
								    lowerCamelCase__				,   batch_size=lowerCamelCase__				,   seq_length=lowerCamelCase__				,   is_pair=lowerCamelCase__				,   framework=lowerCamelCase__)

								# We need to order the input in the way they appears in the forward()
								a_				     =   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

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

								a_				     =   common_inputs["attention_mask"]
								if self.use_past:
														a_				     =   ordered_inputs["attention_mask"].dtype
														a_				     =   torch.cat(
														    [ordered_inputs["attention_mask"], torch.ones(lowerCamelCase__				,   lowerCamelCase__				,   dtype=lowerCamelCase__)]				,   dim=1)

								return ordered_inputs




		@property
		def _lowerCAmelCase     (    self:    Dict)  ->Optional[int]:






								'''simple docstring'''


								return 13











'''simple docstring'''





from collections import OrderedDict
from typing import Mapping

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


a_      = logging.get_logger(__name__)

a_      = {
    'google/mobilebert-uncased': 'https://huggingface.co/google/mobilebert-uncased/resolve/main/config.json'
}





class 		SCREAMING_SNAKE_CASE__   (     lowercase_    ):
		_UpperCAmelCase         =MOBILEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP
		_UpperCAmelCase         ='''mobilebert'''



		def __init__(    self:    Union[str, Any]				,   a:    str=3_05_22				,   a:    List[str]=5_12				,   a:    List[str]=24				,   a:    Dict=4				,   a:    List[str]=5_12				,   a:    Optional[int]="relu"				,   a:    Dict=0.0				,   a:    Union[str, Any]=0.1				,   a:    int=5_12				,   a:    Optional[Any]=2				,   a:    List[Any]=0.02				,   a:    Optional[Any]=1e-12				,   a:    List[Any]=0				,   a:    Optional[int]=1_28				,   a:    Union[str, Any]=True				,   a:    Dict=True				,   a:    List[Any]=1_28				,   a:    Any=False				,   a:    Any=True				,   a:    Dict=4				,   a:    List[Any]="no_norm"				,   a:    Any=True				,   a:    Tuple=None				,   **a:    Any				,   )  ->Any:






								'''simple docstring'''


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

								a_				     =   vocab_size
								a_				     =   hidden_size
								a_				     =   num_hidden_layers
								a_				     =   num_attention_heads
								a_				     =   hidden_act
								a_				     =   intermediate_size
								a_				     =   hidden_dropout_prob
								a_				     =   attention_probs_dropout_prob
								a_				     =   max_position_embeddings
								a_				     =   type_vocab_size
								a_				     =   initializer_range
								a_				     =   layer_norm_eps
								a_				     =   embedding_size
								a_				     =   trigram_input
								a_				     =   use_bottleneck
								a_				     =   intra_bottleneck_size
								a_				     =   use_bottleneck_attention
								a_				     =   key_query_shared_bottleneck
								a_				     =   num_feedforward_networks
								a_				     =   normalization_type
								a_				     =   classifier_activation

								if self.use_bottleneck:
														a_				     =   intra_bottleneck_size
								else:
														a_				     =   hidden_size

								a_				     =   classifier_dropout





class 		SCREAMING_SNAKE_CASE__   (     lowercase_    ):



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






								'''simple docstring'''


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



