





"""simple docstring"""
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


lowerCamelCase_          =	logging.get_logger(__name__)

lowerCamelCase_          =	{
    "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						):
       SCREAMING_SNAKE_CASE_     :   Any					=						'''gpt2'''
       SCREAMING_SNAKE_CASE_     :   Tuple					=						['''past_key_values''']
       SCREAMING_SNAKE_CASE_     :   Optional[int]					=						{
           '''hidden_size''': '''n_embd''',
           '''max_position_embeddings''': '''n_positions''',
           '''num_attention_heads''': '''n_head''',
           '''num_hidden_layers''': '''n_layer''',
       }




       def __init__(		self	,SCREAMING_SNAKE_CASE__=5_02_57	,SCREAMING_SNAKE_CASE__=10_24	,SCREAMING_SNAKE_CASE__=7_68	,SCREAMING_SNAKE_CASE__=12	,SCREAMING_SNAKE_CASE__=12	,SCREAMING_SNAKE_CASE__=None	,SCREAMING_SNAKE_CASE__="gelu_new"	,SCREAMING_SNAKE_CASE__=0.1	,SCREAMING_SNAKE_CASE__=0.1	,SCREAMING_SNAKE_CASE__=0.1	,SCREAMING_SNAKE_CASE__=1E-5	,SCREAMING_SNAKE_CASE__=0.0_2	,SCREAMING_SNAKE_CASE__="cls_index"	,SCREAMING_SNAKE_CASE__=True	,SCREAMING_SNAKE_CASE__=None	,SCREAMING_SNAKE_CASE__=True	,SCREAMING_SNAKE_CASE__=0.1	,SCREAMING_SNAKE_CASE__=True	,SCREAMING_SNAKE_CASE__=True	,SCREAMING_SNAKE_CASE__=5_02_56	,SCREAMING_SNAKE_CASE__=5_02_56	,SCREAMING_SNAKE_CASE__=False	,SCREAMING_SNAKE_CASE__=False	,**SCREAMING_SNAKE_CASE__	,)    ->   Dict:





             """simple docstring"""






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

             __SCREAMING_SNAKE_CASE     :Optional[int]	       =						bos_token_id
             __SCREAMING_SNAKE_CASE     :int	       =						eos_token_id

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






class       _SCREAMING_SNAKE_CASE(     A						):




       def __init__(		self	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__ = "default"	,SCREAMING_SNAKE_CASE__ = None	,SCREAMING_SNAKE_CASE__ = False	,)    ->   Tuple:





             """simple docstring"""






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




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





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :Tuple	       =						OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}							)
             if self.use_past:
                   self.fill_with_past_key_values_(SCREAMING_SNAKE_CASE__	,direction='''inputs'''							)
                   __SCREAMING_SNAKE_CASE     :Tuple	       =						{0: '''batch''', 1: '''past_sequence + sequence'''}
             else:
                   __SCREAMING_SNAKE_CASE     :int	       =						{0: '''batch''', 1: '''sequence'''}

             return common_inputs




       @property
       def 					_UpperCamelCase  (		self							)    ->   int:





             """simple docstring"""






             return self._config.n_layer




       @property
       def 					_UpperCamelCase  (		self							)    ->   int:





             """simple docstring"""






             return self._config.n_head




       def 					_UpperCamelCase  (		self	,SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__ = -1	,SCREAMING_SNAKE_CASE__ = -1	,SCREAMING_SNAKE_CASE__ = False	,SCREAMING_SNAKE_CASE__ = None	,)    ->   Mapping[str, Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE     :Any	       =						super(SCREAMING_SNAKE_CASE__	,self							).generate_dummy_inputs(
                 SCREAMING_SNAKE_CASE__	,batch_size=SCREAMING_SNAKE_CASE__	,seq_length=SCREAMING_SNAKE_CASE__	,is_pair=SCREAMING_SNAKE_CASE__	,framework=SCREAMING_SNAKE_CASE__							)

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

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

             __SCREAMING_SNAKE_CASE     :Any	       =						common_inputs['''attention_mask''']
             if self.use_past:
                   __SCREAMING_SNAKE_CASE     :int	       =						ordered_inputs['''attention_mask'''].dtype
                   __SCREAMING_SNAKE_CASE     :str	       =						torch.cat(
                       [ordered_inputs['''attention_mask'''], torch.ones(SCREAMING_SNAKE_CASE__	,SCREAMING_SNAKE_CASE__	,dtype=SCREAMING_SNAKE_CASE__							)]	,dim=1							)

             return ordered_inputs




       @property
       def 					_UpperCamelCase  (		self							)    ->   int:





             """simple docstring"""






             return 13






"""simple docstring"""
def   __lowerCamelCase     (							a_  :	str							)    ->   int:
      __SCREAMING_SNAKE_CASE     :List[Any]	       =						0
      for plain_chr in plain_text:
            __SCREAMING_SNAKE_CASE     :List[str]	       =						(
                ord(a_							) + (hash_value << 6) + (hash_value << 16) - hash_value
            )
      return hash_value