



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


UpperCamelCase_	       =   logging.get_logger(__name__)

UpperCamelCase_	       =   {
    "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_  (		_snake_case				):
						UpperCamelCase__      :						Union[str, Any]				       ="gpt2"
						UpperCamelCase__      :						List[str]				       =["past_key_values"]
						UpperCamelCase__      :						Optional[int]				       ={
						    "hidden_size": "n_embd",
						    "max_position_embeddings": "n_positions",
						    "num_attention_heads": "n_head",
						    "num_hidden_layers": "n_layer",
						}

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







class 							a_  (		_snake_case				):

						def __init__(    self	:int   ,						_lowercase	:PretrainedConfig   ,						_lowercase	:str = "default"   ,						_lowercase	:List[PatchingSpec] = None   ,						_lowercase	:bool = False   ,						)		->					int:
												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_     							=     0

						@property
						def 	__a       (    self	:Optional[Any])		->					Mapping[str, Mapping[int, str]]:
												UpperCAmelCase_     							=     OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}})
												if self.use_past:
																		self.fill_with_past_key_values_(_lowercase   ,						direction='''inputs''')
																		UpperCAmelCase_     							=     {0: '''batch''', 1: '''past_sequence + sequence'''}
												else:
																		UpperCAmelCase_     							=     {0: '''batch''', 1: '''sequence'''}

												return common_inputs

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

						@property
						def 	__a       (    self	:str)		->					int:
												return self._config.n_head

						def 	__a       (    self	:Optional[int]   ,						_lowercase	:PreTrainedTokenizer   ,						_lowercase	:int = -1   ,						_lowercase	:int = -1   ,						_lowercase	:bool = False   ,						_lowercase	:Optional[TensorType] = None   ,						)		->					Mapping[str, Any]:
												UpperCAmelCase_     							=     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_     							=     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(_lowercase), torch.zeros(_lowercase)) 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(_lowercase   ,						_lowercase   ,						dtype=_lowercase)]   ,						dim=1)

												return ordered_inputs




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










def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 9 / 5) + 32							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) + 273.15							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 9 / 5) + 491.67							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) - 32) * 5 / 9							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(((float(__UpperCAmelCase	) - 32) * 5 / 9) + 273.15							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) + 459.67							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) - 273.15							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(((float(__UpperCAmelCase	) - 273.15) * 9 / 5) + 32							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 9 / 5)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) - 491.67) * 5 / 9							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round(float(__UpperCAmelCase	) - 459.67							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 5 / 9)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 1.25 + 273.15)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 2.25 + 32)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 1.25)							,					__UpperCAmelCase	)







def 				A			(		__UpperCAmelCase							,					__UpperCAmelCase = 2	)       ->       float:



						'''simple docstring'''






						return round((float(__UpperCAmelCase	) * 2.25 + 32 + 459.67)							,					__UpperCAmelCase	)


if __name__ == "__main__":
							import doctest

							doctest.testmod()





