




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        _lowerCamelCase  (	_SCREAMING_SNAKE_CASE      ):

      """simple docstring"""

      lowerCAmelCase__	:       Tuple			=    "gpt2"
      lowerCAmelCase__	:       List[str]			=    ["past_key_values"]
      lowerCAmelCase__	:       str			=    {
          "hidden_size": "n_embd",
          "max_position_embeddings": "n_positions",
          "num_attention_heads": "n_head",
          "num_hidden_layers": "n_layer",
      }







      def __init__(   self    :       Union[str, Any]       ,				snake_case    :       Tuple=50257       ,				snake_case    :       List[Any]=1024       ,				snake_case    :       List[Any]=768       ,				snake_case    :       int=12       ,				snake_case    :       List[Any]=12       ,				snake_case    :       List[Any]=None       ,				snake_case    :       Optional[int]="gelu_new"       ,				snake_case    :       Union[str, Any]=0.1       ,				snake_case    :       Any=0.1       ,				snake_case    :       Any=0.1       ,				snake_case    :       Optional[int]=1E-5       ,				snake_case    :       Union[str, Any]=0.02       ,				snake_case    :       str="cls_index"       ,				snake_case    :       Optional[Any]=True       ,				snake_case    :       List[Any]=None       ,				snake_case    :       Optional[Any]=True       ,				snake_case    :       List[str]=0.1       ,				snake_case    :       Optional[Any]=True       ,				snake_case    :       Dict=True       ,				snake_case    :       List[Any]=50256       ,				snake_case    :       Tuple=50256       ,				snake_case    :       Union[str, Any]=False       ,				snake_case    :       Union[str, Any]=False       ,				**snake_case    :       List[Any]       ,				):
          __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=snake_case       ,				eos_token_id=snake_case       ,				**snake_case )







class        _lowerCamelCase  (	_SCREAMING_SNAKE_CASE      ):

      """simple docstring"""

      def __init__(   self    :       str       ,				snake_case    :       PretrainedConfig       ,				snake_case    :       str = "default"       ,				snake_case    :       List[PatchingSpec] = None       ,				snake_case    :       bool = False       ,				):
          super().__init__(snake_case       ,				task=snake_case       ,				patching_specs=snake_case       ,				use_past=snake_case )
          if not getattr(self._config       ,				'''pad_token_id'''       ,				snake_case ):
              # TODO: how to do that better?
              __UpperCamelCase     						=  0







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

          return common_inputs







      @property
      def 					snake_case		(   self    :       str ):
          return self._config.n_layer







      @property
      def 					snake_case		(   self    :       Tuple ):
          return self._config.n_head







      def 					snake_case		(   self    :       List[str]       ,				snake_case    :       PreTrainedTokenizer       ,				snake_case    :       int = -1       ,				snake_case    :       int = -1       ,				snake_case    :       bool = False       ,				snake_case    :       Optional[TensorType] = None       ,				):
          __UpperCamelCase     						=  super(snake_case       ,				self ).generate_dummy_inputs(
              snake_case       ,				batch_size=snake_case       ,				seq_length=snake_case       ,				is_pair=snake_case       ,				framework=snake_case )

          # 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(snake_case ), torch.zeros(snake_case )) 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(snake_case       ,				snake_case       ,				dtype=snake_case )]       ,				dim=1 )

          return ordered_inputs







      @property
      def 					snake_case		(   self    :       Optional[int] ):
          return 13













"""simple docstring"""




from functools import lru_cache





@lru_cache
def        a_				(							_lowercase   ):
						if not isinstance(_lowercase       ,						_lowercase   ):
												raise TypeError('''k must be an integer.'''   )
						if k < 0:
												raise ValueError('''k integer must be greater or equal to zero.'''   )
						if k == 0:
												return 0
						elif k == 1:
												return 1
						else:
												return fibonacci(k - 1   ) + fibonacci(k - 2   )





def        a_				(							_lowercase       ,						_lowercase   ):
						_UpperCamelCase			:					Any     =    len(_lowercase   )
						# Find m such that F_m >= n where F_i is the i_th fibonacci number.
						_UpperCamelCase			:					Optional[int]     =    0
						while True:
												if fibonacci(_lowercase   ) >= len_list:
																		_UpperCamelCase			:					List[Any]     =    i
																		break
												i += 1
						_UpperCamelCase			:					Tuple     =    0
						while fibb_k > 0:
												_UpperCamelCase			:					Union[str, Any]     =    min(
												    offset + fibonacci(fibb_k - 1   )       ,						len_list - 1   )  # Prevent out of range
												_UpperCamelCase			:					Any     =    arr[index_k]
												if item_k_1 == val:
																		return index_k
												elif val < item_k_1:
																		fibb_k -= 1
												elif val > item_k_1:
																		offset += fibonacci(fibb_k - 1   )
																		fibb_k -= 2
						else:
												return -1


if __name__ == "__main__":
						import doctest

						doctest.testmod()



