


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


lowercase_							 =       logging.get_logger(__name__)

lowercase_							 =       {
    """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	(   _a       ):
				lowerCamelCase    :					int 					='gpt2'
				lowerCamelCase    :					Optional[Any] 					=['past_key_values']
				lowerCamelCase    :					Tuple 					={
				    'hidden_size': 'n_embd',
				    'max_position_embeddings': 'n_positions',
				    'num_attention_heads': 'n_head',
				    'num_hidden_layers': 'n_layer',
				}







				def __init__(   self			,  UpperCAmelCase=5_0257			,  UpperCAmelCase=1024			,  UpperCAmelCase=768			,  UpperCAmelCase=12			,  UpperCAmelCase=12			,  UpperCAmelCase=None			,  UpperCAmelCase="gelu_new"			,  UpperCAmelCase=0.1			,  UpperCAmelCase=0.1			,  UpperCAmelCase=0.1			,  UpperCAmelCase=1E-5			,  UpperCAmelCase=0.0_2			,  UpperCAmelCase="cls_index"			,  UpperCAmelCase=True			,  UpperCAmelCase=None			,  UpperCAmelCase=True			,  UpperCAmelCase=0.1			,  UpperCAmelCase=True			,  UpperCAmelCase=True			,  UpperCAmelCase=5_0256			,  UpperCAmelCase=5_0256			,  UpperCAmelCase=False			,  UpperCAmelCase=False			,  **UpperCAmelCase			,  ):

					'''simple docstring'''






					lowerCAmelCase_       = vocab_size
					lowerCAmelCase_       = n_positions
					lowerCAmelCase_       = n_embd
					lowerCAmelCase_       = n_layer
					lowerCAmelCase_       = n_head
					lowerCAmelCase_       = n_inner
					lowerCAmelCase_       = activation_function
					lowerCAmelCase_       = resid_pdrop
					lowerCAmelCase_       = embd_pdrop
					lowerCAmelCase_       = attn_pdrop
					lowerCAmelCase_       = layer_norm_epsilon
					lowerCAmelCase_       = initializer_range
					lowerCAmelCase_       = summary_type
					lowerCAmelCase_       = summary_use_proj
					lowerCAmelCase_       = summary_activation
					lowerCAmelCase_       = summary_first_dropout
					lowerCAmelCase_       = summary_proj_to_labels
					lowerCAmelCase_       = scale_attn_weights
					lowerCAmelCase_       = use_cache
					lowerCAmelCase_       = scale_attn_by_inverse_layer_idx
					lowerCAmelCase_       = reorder_and_upcast_attn

					lowerCAmelCase_       = bos_token_id
					lowerCAmelCase_       = eos_token_id

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







class       __a	(   _a       ):







				def __init__(   self			,  UpperCAmelCase			,  UpperCAmelCase = "default"			,  UpperCAmelCase = None			,  UpperCAmelCase = False			,  ):

					'''simple docstring'''






					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?
						lowerCAmelCase_       = 0







				@property
				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					lowerCAmelCase_       = OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}      )
					if self.use_past:
						self.fill_with_past_key_values_(lowerCamelCase__			,  direction='''inputs'''      )
						lowerCAmelCase_       = {0: "batch", 1: "past_sequence + sequence"}
					else:
						lowerCAmelCase_       = {0: "batch", 1: "sequence"}

					return common_inputs







				@property
				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					return self._config.n_layer







				@property
				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					return self._config.n_head







				def     lowerCamelCase_    (   self			,  UpperCAmelCase			,  UpperCAmelCase = -1			,  UpperCAmelCase = -1			,  UpperCAmelCase = False			,  UpperCAmelCase = None			,  ):

					'''simple docstring'''






					lowerCAmelCase_       = 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()
					lowerCAmelCase_       = 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

							lowerCAmelCase_       = common_inputs["input_ids"].shape
							# Not using the same length for past_key_values
							lowerCAmelCase_       = seqlen + 2
							lowerCAmelCase_       = (
							    batch,
							    self.num_attention_heads,
							    past_key_values_length,
							    self._config.hidden_size // self.num_attention_heads,
							)
							lowerCAmelCase_       = [
							    (torch.zeros(lowerCamelCase__      ), torch.zeros(lowerCamelCase__      )) for _ in range(self.num_layers      )
							]

					lowerCAmelCase_       = common_inputs["attention_mask"]
					if self.use_past:
						lowerCAmelCase_       = ordered_inputs["attention_mask"].dtype
						lowerCAmelCase_       = torch.cat(
						    [ordered_inputs['''attention_mask'''], torch.ones(lowerCamelCase__			,  lowerCamelCase__			,  dtype=lowerCamelCase__      )]			,  dim=1      )

					return ordered_inputs







				@property
				def     lowerCamelCase_    (   self      ):

					'''simple docstring'''






					return 13



"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase_							 =       {
    'configuration_prophetnet': ['PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ProphetNetConfig'],
    'tokenization_prophetnet': ['ProphetNetTokenizer'],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase_							 =       [
		    'PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'ProphetNetDecoder',
		    'ProphetNetEncoder',
		    'ProphetNetForCausalLM',
		    'ProphetNetForConditionalGeneration',
		    'ProphetNetModel',
		    'ProphetNetPreTrainedModel',
		]


if TYPE_CHECKING:
		from .configuration_prophetnet import PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP, ProphetNetConfig
		from .tokenization_prophetnet import ProphetNetTokenizer

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_prophetnet import (
				    PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST,
				    ProphetNetDecoder,
				    ProphetNetEncoder,
				    ProphetNetForCausalLM,
				    ProphetNetForConditionalGeneration,
				    ProphetNetModel,
				    ProphetNetPreTrainedModel,
				)

else:
		import sys

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