






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 						lowerCamelCase   (_a    ):







		'''simple docstring'''



		_snake_case					:					Dict 		=						'''gpt2'''
		_snake_case					:					Optional[Any] 		=						['''past_key_values''']
		_snake_case					:					List[Any] 		=						{
		    '''hidden_size''': '''n_embd''',
		    '''max_position_embeddings''': '''n_positions''',
		    '''num_attention_heads''': '''n_head''',
		    '''num_hidden_layers''': '''n_layer''',
		}



		def __init__(							self       ,	_UpperCamelCase=5_0_2_5_7       ,	_UpperCamelCase=1_0_2_4       ,	_UpperCamelCase=7_6_8       ,	_UpperCamelCase=1_2       ,	_UpperCamelCase=1_2       ,	_UpperCamelCase=None       ,	_UpperCamelCase="gelu_new"       ,	_UpperCamelCase=0.1       ,	_UpperCamelCase=0.1       ,	_UpperCamelCase=0.1       ,	_UpperCamelCase=1E-5       ,	_UpperCamelCase=0.02       ,	_UpperCamelCase="cls_index"       ,	_UpperCamelCase=True       ,	_UpperCamelCase=None       ,	_UpperCamelCase=True       ,	_UpperCamelCase=0.1       ,	_UpperCamelCase=True       ,	_UpperCamelCase=True       ,	_UpperCamelCase=5_0_2_5_6       ,	_UpperCamelCase=5_0_2_5_6       ,	_UpperCamelCase=False       ,	_UpperCamelCase=False       ,	**_UpperCamelCase       ,	)			->							Union[str, Any]:
							UpperCAmelCase_					:   Dict   =		vocab_size
							UpperCAmelCase_					:   List[str]   =		n_positions
							UpperCAmelCase_					:   Optional[int]   =		n_embd
							UpperCAmelCase_					:   Tuple   =		n_layer
							UpperCAmelCase_					:   Dict   =		n_head
							UpperCAmelCase_					:   int   =		n_inner
							UpperCAmelCase_					:   Dict   =		activation_function
							UpperCAmelCase_					:   Optional[Any]   =		resid_pdrop
							UpperCAmelCase_					:   List[str]   =		embd_pdrop
							UpperCAmelCase_					:   Union[str, Any]   =		attn_pdrop
							UpperCAmelCase_					:   Tuple   =		layer_norm_epsilon
							UpperCAmelCase_					:   Any   =		initializer_range
							UpperCAmelCase_					:   str   =		summary_type
							UpperCAmelCase_					:   Union[str, Any]   =		summary_use_proj
							UpperCAmelCase_					:   Union[str, Any]   =		summary_activation
							UpperCAmelCase_					:   Dict   =		summary_first_dropout
							UpperCAmelCase_					:   List[str]   =		summary_proj_to_labels
							UpperCAmelCase_					:   Optional[Any]   =		scale_attn_weights
							UpperCAmelCase_					:   Optional[int]   =		use_cache
							UpperCAmelCase_					:   List[Any]   =		scale_attn_by_inverse_layer_idx
							UpperCAmelCase_					:   Dict   =		reorder_and_upcast_attn

							UpperCAmelCase_					:   Any   =		bos_token_id
							UpperCAmelCase_					:   Tuple   =		eos_token_id

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





class 						lowerCamelCase   (_a    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	_UpperCamelCase = "default"       ,	_UpperCamelCase = None       ,	_UpperCamelCase = False       ,	)			->							List[Any]:
							super().__init__(lowerCamelCase__       ,	task=lowerCamelCase__       ,	patching_specs=lowerCamelCase__       ,	use_past=lowerCamelCase__     )
							if not getattr(self._config       ,	'pad_token_id'       ,	lowerCamelCase__     ):
												# TODO: how to do that better?
												UpperCAmelCase_					:   Union[str, Any]   =		0



		@property
		def       __UpperCAmelCase    (							self     )			->							Dict:
							UpperCAmelCase_					:   Optional[Any]   =		OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}     )
							if self.use_past:
												self.fill_with_past_key_values_(lowerCamelCase__       ,	direction='inputs'     )
												UpperCAmelCase_					:   Dict   =		{0: "batch", 1: "past_sequence + sequence"}
							else:
												UpperCAmelCase_					:   Tuple   =		{0: "batch", 1: "sequence"}

							return common_inputs



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



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



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = -1       ,	_UpperCamelCase = -1       ,	_UpperCamelCase = False       ,	_UpperCamelCase = None       ,	)			->							Optional[int]:
							UpperCAmelCase_					:   List[Any]   =		super(lowerCamelCase__       ,	self     ).generate_dummy_inputs(
							    lowerCamelCase__       ,	batch_size=lowerCamelCase__       ,	seq_length=lowerCamelCase__       ,	is_pair=lowerCamelCase__       ,	framework=lowerCamelCase__     )

							# We need to order the input in the way they appears in the forward()
							UpperCAmelCase_					:   Tuple   =		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_					:   Optional[Any]   =		common_inputs["input_ids"].shape
																	# Not using the same length for past_key_values
																	UpperCAmelCase_					:   Tuple   =		seqlen + 2
																	UpperCAmelCase_					:   Dict   =		(
																	    batch,
																	    self.num_attention_heads,
																	    past_key_values_length,
																	    self._config.hidden_size // self.num_attention_heads,
																	)
																	UpperCAmelCase_					:   Optional[Any]   =		[
																	    (torch.zeros(lowerCamelCase__     ), torch.zeros(lowerCamelCase__     )) for _ in range(self.num_layers     )
																	]

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

							return ordered_inputs



		@property
		def       __UpperCAmelCase    (							self     )			->							List[Any]:
							return 1_3














from typing import TYPE_CHECKING

from ...utils import _LazyModule


__UpperCAmelCase										=		{'tokenization_phobert': ['PhobertTokenizer']}


if TYPE_CHECKING:
		from .tokenization_phobert import PhobertTokenizer

else:
		import sys

		__UpperCAmelCase										=		_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






