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


_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 A_      (lowercase__ ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__     :		List[Any]    	=						"""gpt2"""
  SCREAMING_SNAKE_CASE__     :		Union[str, Any]    	=						["""past_key_values"""]
  SCREAMING_SNAKE_CASE__     :		str    	=						{
      """hidden_size""": """n_embd""",
      """max_position_embeddings""": """n_positions""",
      """num_attention_heads""": """n_head""",
      """num_hidden_layers""": """n_layer""",
  }







  def __init__(						self							,  lowercase_=5_0257							,  lowercase_=1024							,  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_=5_0256							,  lowercase_=5_0256							,  lowercase_=False							,  lowercase_=False							,  **lowercase_							,  ):

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

     UpperCAmelCase_   :   int     	=       bos_token_id
     UpperCAmelCase_   :   Any     	=       eos_token_id

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




class A_      (lowercase__ ):




  '''simple docstring'''







  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?
        UpperCAmelCase_   :   int     	=       0







  @property
  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     UpperCAmelCase_   :   Tuple     	=       OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}    )
     if self.use_past:
        self.fill_with_past_key_values_(lowercase_							,  direction="inputs"    )
        UpperCAmelCase_   :   Dict     	=       {0: "batch", 1: "past_sequence + sequence"}
     else:
        UpperCAmelCase_   :   List[Any]     	=       {0: "batch", 1: "sequence"}

     return common_inputs







  @property
  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     return self._config.n_layer







  @property
  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     return self._config.n_head







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

     """simple docstring"""
     UpperCAmelCase_   :   List[Any]     	=       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()
     UpperCAmelCase_   :   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

           UpperCAmelCase_	,  UpperCAmelCase_   :   Tuple     	=       common_inputs["input_ids"].shape
           # Not using the same length for past_key_values
           UpperCAmelCase_   :   Any     	=       seqlen + 2
           UpperCAmelCase_   :   str     	=       (
               batch,
               self.num_attention_heads,
               past_key_values_length,
               self._config.hidden_size // self.num_attention_heads,
           )
           UpperCAmelCase_   :   Dict     	=       [
               (torch.zeros(lowercase_    ), torch.zeros(lowercase_    )) for _ in range(self.num_layers    )
           ]

     UpperCAmelCase_   :   int     	=       common_inputs["attention_mask"]
     if self.use_past:
        UpperCAmelCase_   :   List[Any]     	=       ordered_inputs["attention_mask"].dtype
        UpperCAmelCase_   :   Union[str, Any]     	=       torch.cat(
            [ordered_inputs["attention_mask"], torch.ones(lowercase_							,  lowercase_							,  dtype=lowercase_    )]							,  dim=1    )

     return ordered_inputs







  @property
  def 			UpperCamelCase__   (						self    ):

     """simple docstring"""
     return 13






from hashlib import mda, shaaaa

__UpperCamelCase							:							Dict    							=					(shaaaa, mda)

class    __magic_name__						:


     def __init__(   self				:  Optional[Any]				,						lowerCamelCase__				:  int = 8      )	->   None:





      '''simple docstring'''






      UpperCamelCase__       :     int 							= 0b0
      UpperCamelCase__       :     Optional[int] 							= size


     def   UpperCAmelCase__						(   self				:  Tuple				,						lowerCamelCase__				:  str      )	->   None:





      '''simple docstring'''






      UpperCamelCase__       :     Union[str, Any] 							= self.hash_(lowerCamelCase__      )
      self.bitarray |= h


     def   UpperCAmelCase__						(   self				:  Any				,						lowerCamelCase__				:  str      )	->   bool:





      '''simple docstring'''






      UpperCamelCase__       :     Any 							= self.hash_(lowerCamelCase__      )
      return (h & self.bitarray) == h


     def __contains__(   self				:  Any				,						lowerCamelCase__				:  str      )	->   bool:





      '''simple docstring'''






      return self.exists(lowerCamelCase__      )


     def   UpperCAmelCase__						(   self				:  Union[str, Any]				,						lowerCamelCase__				:  int      )	->   str:





      '''simple docstring'''






      UpperCamelCase__       :     Optional[int] 							= bin(lowerCamelCase__      )[2:]
      return res.zfill(self.size      )


     @property
     def   UpperCAmelCase__						(   self				:  Tuple      )	->   str:





      '''simple docstring'''






      return self.format_bin(self.bitarray      )


     def   UpperCAmelCase__						(   self				:  int				,						lowerCamelCase__				:  str      )	->   int:





      '''simple docstring'''






      UpperCamelCase__       :     Union[str, Any] 							= 0b0
      for func in HASH_FUNCTIONS:
       UpperCamelCase__       :     Optional[Any] 							= (
           int.from_bytes(func(value.encode()      ).digest()				,						'''little'''      ) % self.size
       )
       res |= 2**position
      return res


     def   UpperCAmelCase__						(   self				:  Union[str, Any]				,						lowerCamelCase__				:  str      )	->   str:





      '''simple docstring'''






      return self.format_bin(self.hash_(lowerCamelCase__      )      )


     @property
     def   UpperCAmelCase__						(   self				:  str      )	->   float:





      '''simple docstring'''






      UpperCamelCase__       :     Tuple 							= bin(self.bitarray      ).count('''1'''      )
      return (n_ones / self.size) ** len(lowerCamelCase__      )


