


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


_SCREAMING_SNAKE_CASE       :   Optional[Any]        = logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE       :   Any        = {
    "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 		_snake_case    (				snake_case_		):






						'''simple docstring'''







						__snake_case   =      "gpt2"
						__snake_case   =      ["past_key_values"]
						__snake_case   =      {
						    "hidden_size": "n_embd",
						    "max_position_embeddings": "n_positions",
						    "num_attention_heads": "n_head",
						    "num_hidden_layers": "n_layer",
						}







						def __init__(  self:	Any      ,							__UpperCamelCase:	int=5_0257      ,							__UpperCamelCase:	Any=1024      ,							__UpperCamelCase:	Union[str, Any]=768      ,							__UpperCamelCase:	Optional[int]=12      ,							__UpperCamelCase:	List[str]=12      ,							__UpperCamelCase:	List[Any]=None      ,							__UpperCamelCase:	str="gelu_new"      ,							__UpperCamelCase:	Union[str, Any]=0.1      ,							__UpperCamelCase:	Dict=0.1      ,							__UpperCamelCase:	List[str]=0.1      ,							__UpperCamelCase:	Dict=1E-5      ,							__UpperCamelCase:	Optional[Any]=0.0_2      ,							__UpperCamelCase:	Dict="cls_index"      ,							__UpperCamelCase:	str=True      ,							__UpperCamelCase:	Union[str, Any]=None      ,							__UpperCamelCase:	Tuple=True      ,							__UpperCamelCase:	int=0.1      ,							__UpperCamelCase:	Union[str, Any]=True      ,							__UpperCamelCase:	List[str]=True      ,							__UpperCamelCase:	List[str]=5_0256      ,							__UpperCamelCase:	List[Any]=5_0256      ,							__UpperCamelCase:	List[Any]=False      ,							__UpperCamelCase:	Optional[Any]=False      ,							**__UpperCamelCase:	List[str]      ,							)							->	Any:
										__magic_name__				:					str						       =       vocab_size
										__magic_name__				:					int						       =       n_positions
										__magic_name__				:					List[Any]						       =       n_embd
										__magic_name__				:					Any						       =       n_layer
										__magic_name__				:					List[Any]						       =       n_head
										__magic_name__				:					Tuple						       =       n_inner
										__magic_name__				:					int						       =       activation_function
										__magic_name__				:					int						       =       resid_pdrop
										__magic_name__				:					Tuple						       =       embd_pdrop
										__magic_name__				:					List[Any]						       =       attn_pdrop
										__magic_name__				:					List[Any]						       =       layer_norm_epsilon
										__magic_name__				:					Dict						       =       initializer_range
										__magic_name__				:					Optional[int]						       =       summary_type
										__magic_name__				:					Optional[int]						       =       summary_use_proj
										__magic_name__				:					str						       =       summary_activation
										__magic_name__				:					str						       =       summary_first_dropout
										__magic_name__				:					Any						       =       summary_proj_to_labels
										__magic_name__				:					Optional[Any]						       =       scale_attn_weights
										__magic_name__				:					Tuple						       =       use_cache
										__magic_name__				:					Tuple						       =       scale_attn_by_inverse_layer_idx
										__magic_name__				:					Tuple						       =       reorder_and_upcast_attn

										__magic_name__				:					int						       =       bos_token_id
										__magic_name__				:					List[Any]						       =       eos_token_id

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






class 		_snake_case    (				snake_case_		):






						'''simple docstring'''







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







						@property
						def lowerCAmelCase__ (  self:	List[str]     )							->	Mapping[str, Mapping[int, str]]:
										__magic_name__				:					str						       =       OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}     )
										if self.use_past:
														self.fill_with_past_key_values_(__UpperCamelCase      ,							direction="inputs"     )
														__magic_name__				:					Optional[int]						       =       {0: "batch", 1: "past_sequence + sequence"}
										else:
														__magic_name__				:					Tuple						       =       {0: "batch", 1: "sequence"}

										return common_inputs







						@property
						def lowerCAmelCase__ (  self:	Dict     )							->	int:
										return self._config.n_layer







						@property
						def lowerCAmelCase__ (  self:	Optional[Any]     )							->	int:
										return self._config.n_head







						def lowerCAmelCase__ (  self:	Tuple      ,							__UpperCamelCase:	PreTrainedTokenizer      ,							__UpperCamelCase:	int = -1      ,							__UpperCamelCase:	int = -1      ,							__UpperCamelCase:	bool = False      ,							__UpperCamelCase:	Optional[TensorType] = None      ,							)							->	Mapping[str, Any]:
										__magic_name__				:					int						       =       super(__UpperCamelCase      ,							self     ).generate_dummy_inputs(
										    __UpperCamelCase      ,							batch_size=__UpperCamelCase      ,							seq_length=__UpperCamelCase      ,							is_pair=__UpperCamelCase      ,							framework=__UpperCamelCase     )

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

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

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

										return ordered_inputs







						@property
						def lowerCAmelCase__ (  self:	List[Any]     )							->	int:
										return 13



'''simple docstring'''







def 						_UpperCamelCase							( UpperCamelCase__		):






				"""simple docstring"""



				if not isinstance(UpperCamelCase__     ,   UpperCamelCase__		) or number < 0:
								raise ValueError("Input must be a non-negative integer"		)

				__magic_name__				:					str						       =       number & ~(number - 1)
				__magic_name__				:					Optional[int]						       =       0
				while intermediate:
								intermediate >>= 1
								index += 1
				return index - 1


if __name__ == "__main__":
		import doctest

		doctest.testmod(verbose=True)