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


_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 	__UpperCAmelCase						(a_    ):







			'''simple docstring'''
			_UpperCamelCase     :	Any				    =							'gpt2'
			_UpperCamelCase     :	Tuple				    =							['past_key_values']
			_UpperCamelCase     :	Tuple				    =							{
			    'hidden_size': 'n_embd',
			    'max_position_embeddings': 'n_positions',
			    'num_attention_heads': 'n_head',
			    'num_hidden_layers': 'n_layer',
			}





			def __init__( self      ,			snake_case_=50_257      ,			snake_case_=1_024      ,			snake_case_=768      ,			snake_case_=12      ,			snake_case_=12      ,			snake_case_=None      ,			snake_case_="gelu_new"      ,			snake_case_=0.1      ,			snake_case_=0.1      ,			snake_case_=0.1      ,			snake_case_=1E-5      ,			snake_case_=0.02      ,			snake_case_="cls_index"      ,			snake_case_=True      ,			snake_case_=None      ,			snake_case_=True      ,			snake_case_=0.1      ,			snake_case_=True      ,			snake_case_=True      ,			snake_case_=50_256      ,			snake_case_=50_256      ,			snake_case_=False      ,			snake_case_=False      ,			**snake_case_      ,			):







										'''simple docstring'''


										A__					:    int														= vocab_size
										A__					:    int														= n_positions
										A__					:    Tuple														= n_embd
										A__					:    List[str]														= n_layer
										A__					:    str														= n_head
										A__					:    List[Any]														= n_inner
										A__					:    int														= activation_function
										A__					:    Dict														= resid_pdrop
										A__					:    List[Any]														= embd_pdrop
										A__					:    Tuple														= attn_pdrop
										A__					:    Union[str, Any]														= layer_norm_epsilon
										A__					:    str														= initializer_range
										A__					:    Union[str, Any]														= summary_type
										A__					:    str														= summary_use_proj
										A__					:    int														= summary_activation
										A__					:    Any														= summary_first_dropout
										A__					:    str														= summary_proj_to_labels
										A__					:    Optional[int]														= scale_attn_weights
										A__					:    List[Any]														= use_cache
										A__					:    Optional[int]														= scale_attn_by_inverse_layer_idx
										A__					:    List[str]														= reorder_and_upcast_attn

										A__					:    Any														= bos_token_id
										A__					:    Union[str, Any]														= eos_token_id

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





class 	__UpperCAmelCase						(a_    ):







			'''simple docstring'''





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







										'''simple docstring'''


										super().__init__(snake_case_      ,			task=snake_case_      ,			patching_specs=snake_case_      ,			use_past=snake_case_       )
										if not getattr(self._config      ,			"""pad_token_id"""      ,			snake_case_       ):
																	# TODO: how to do that better?
																	A__					:    Optional[Any]														= 0





			@property
			def 		lowerCamelCase				( self       ):







										'''simple docstring'''


										A__					:    int														= OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}       )
										if self.use_past:
																	self.fill_with_past_key_values_(snake_case_      ,			direction="""inputs"""       )
																	A__					:    Any														= {0: 'batch', 1: 'past_sequence + sequence'}
										else:
																	A__					:    Tuple														= {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      ,			snake_case_      ,			snake_case_ = -1      ,			snake_case_ = -1      ,			snake_case_ = False      ,			snake_case_ = None      ,			):







										'''simple docstring'''


										A__					:    Union[str, Any]														= super(snake_case_      ,			self       ).generate_dummy_inputs(
										    snake_case_      ,			batch_size=snake_case_      ,			seq_length=snake_case_      ,			is_pair=snake_case_      ,			framework=snake_case_       )

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

																								A__					:    str														= common_inputs['input_ids'].shape
																								# Not using the same length for past_key_values
																								A__					:    List[str]														= seqlen + 2
																								A__					:    int														= (
																								    batch,
																								    self.num_attention_heads,
																								    past_key_values_length,
																								    self._config.hidden_size // self.num_attention_heads,
																								)
																								A__					:    Optional[int]														= [
																								    (torch.zeros(snake_case_       ), torch.zeros(snake_case_       )) for _ in range(self.num_layers       )
																								]

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

										return ordered_inputs





			@property
			def 		lowerCamelCase				( self       ):







										'''simple docstring'''


										return 13






"""simple docstring"""



import enum
import inspect
import warnings
from functools import wraps
from typing import Callable, Optional

from .logging import get_logger


_UpperCamelCase         =		set()
_UpperCamelCase         =		get_logger(__name__)

def    _A(		lowerCAmelCase = None       ):

							def decorator(lowerCAmelCase       ):
														global _emitted_deprecation_warnings

														if inspect.isclass(lowerCAmelCase       ):
																					A__					:    List[Any]														= deprecated_class_or_function.__init__
																					A__					:    Any														= deprecated_class_or_function.__name__
														else:
																					A__					:    Dict														= deprecated_class_or_function
																					A__					:    Optional[int]														= deprecated_function.__name__
																					# Support deprecating __init__ class method: class name instead
																					A__					:    List[str]														= name if name != """__init__""" else deprecated_function.__qualname__.split("""."""       )[-2]

														A__					:    Union[str, Any]														= (
														    F'''{name} is deprecated and will be removed in the next major version of datasets.''' + F''' {help_message}'''
														    if help_message
														    else """"""
														)

														@wraps(lowerCAmelCase       )
														def wrapper(*lowerCAmelCase ,     **lowerCAmelCase       ):
																					A__					:    Tuple														= hash(lowerCAmelCase       )
																					if func_hash not in _emitted_deprecation_warnings:
																												warnings.warn(lowerCAmelCase ,     category=lowerCAmelCase ,     stacklevel=2       )
																												_emitted_deprecation_warnings.add(lowerCAmelCase       )
																					return deprecated_function(*lowerCAmelCase ,     **lowerCAmelCase       )

														A__					:    int														= """deprecated"""

														if inspect.isclass(lowerCAmelCase       ):
																					A__					:    Union[str, Any]														= wrapper
																					return deprecated_class_or_function
														else:
																					return wrapper

							return decorator
class 	__UpperCAmelCase						(enum.EnumMeta    ):







			'''simple docstring'''





			def __getattribute__( cls      ,			snake_case_       ):







										'''simple docstring'''


										A__					:    Union[str, Any]														= super().__getattribute__(snake_case_       )
										if isinstance(snake_case_      ,			enum.Enum       ) and obj._on_access:
																	obj._on_access()
										return obj





			def __getitem__( cls      ,			snake_case_       ):







										'''simple docstring'''


										A__					:    Tuple														= super().__getitem__(snake_case_       )
										if member._on_access:
																	member._on_access()
										return member





			def __call__( cls      ,			snake_case_      ,			snake_case_=None      ,			*, snake_case_=None      ,			snake_case_=None      ,			snake_case_=None      ,			snake_case_=1       ):







										'''simple docstring'''


										A__					:    List[Any]														= super().__call__(snake_case_      ,			snake_case_      ,			module=snake_case_      ,			qualname=snake_case_      ,			type=snake_case_      ,			start=snake_case_       )
										if isinstance(snake_case_      ,			enum.Enum       ) and obj._on_access:
																	obj._on_access()
										return obj





class 	__UpperCAmelCase						(enum.Enum       ,      metaclass=__A    ):







			'''simple docstring'''





			def __new__( cls      ,			snake_case_       ):







										'''simple docstring'''


										A__					:    Tuple														= object.__new__(cls       )
										A__					:    int														= value
										A__					:    Optional[int]														= member.deprecate
										return member





			@property
			def 		lowerCamelCase				( self       ):







										'''simple docstring'''


										return ""





			def 		lowerCamelCase				( self       ):







										'''simple docstring'''


										A__					:    Tuple														= F''' {self.help_message}''' if self.help_message else """"""
										warnings.warn(
										    F'''\'{self.__objclass__.__name__}\' is deprecated and will be removed in the next major version of datasets.'''
										    + help_message      ,			snake_case_      ,			stacklevel=3      ,			)





