






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


__snake_case			:			Tuple			   =   logging.get_logger(__name__)

__snake_case			:			Tuple			   =   {
    """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 			__SCREAMING_SNAKE_CASE    (      __lowercase):
						_SCREAMING_SNAKE_CASE		:				Union[str, Any]            =    '''gpt2'''
						_SCREAMING_SNAKE_CASE		:				Dict            =    ['''past_key_values''']
						_SCREAMING_SNAKE_CASE		:				List[str]            =    {
						    '''hidden_size''': '''n_embd''',
						    '''max_position_embeddings''': '''n_positions''',
						    '''num_attention_heads''': '''n_head''',
						    '''num_hidden_layers''': '''n_layer''',
						}






						def __init__(		self   ,  _UpperCamelCase=5_02_57   ,  _UpperCamelCase=10_24   ,  _UpperCamelCase=7_68   ,  _UpperCamelCase=12   ,  _UpperCamelCase=12   ,  _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_02_56   ,  _UpperCamelCase=5_02_56   ,  _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=_UpperCamelCase   ,  eos_token_id=_UpperCamelCase   ,  **_UpperCamelCase      )




class 			__SCREAMING_SNAKE_CASE    (      __lowercase):






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






												"""simple docstring"""
												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?
																		lowerCAmelCase__			  =  0






						@property
						def 					UpperCamelCase__					(		self      ):






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

												return common_inputs






						@property
						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												return self._config.n_layer






						@property
						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												return self._config.n_head






						def 					UpperCamelCase__					(		self   ,  _UpperCamelCase   ,  _UpperCamelCase = -1   ,  _UpperCamelCase = -1   ,  _UpperCamelCase = False   ,  _UpperCamelCase = None   ,  ):






												"""simple docstring"""
												lowerCAmelCase__			  =  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()
												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__  ,				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(_UpperCamelCase      ), torch.zeros(_UpperCamelCase      )) 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(_UpperCamelCase   ,  _UpperCamelCase   ,  dtype=_UpperCamelCase      )]   ,  dim=1      )

												return ordered_inputs







						@property
						def 					UpperCamelCase__					(		self      ):






												"""simple docstring"""
												return 13













from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__snake_case			:			Optional[int]			   =   {"""configuration_sew_d""": ["""SEW_D_PRETRAINED_CONFIG_ARCHIVE_MAP""", """SEWDConfig"""]}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					__snake_case			:			List[Any]			   =   [
					    """SEW_D_PRETRAINED_MODEL_ARCHIVE_LIST""",
					    """SEWDForCTC""",
					    """SEWDForSequenceClassification""",
					    """SEWDModel""",
					    """SEWDPreTrainedModel""",
					]

if TYPE_CHECKING:
					from .configuration_sew_d import SEW_D_PRETRAINED_CONFIG_ARCHIVE_MAP, SEWDConfig

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_sew_d import (
										    SEW_D_PRETRAINED_MODEL_ARCHIVE_LIST,
										    SEWDForCTC,
										    SEWDForSequenceClassification,
										    SEWDModel,
										    SEWDPreTrainedModel,
										)


else:
					import sys

					__snake_case			:			Dict			   =   _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





