





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


_a     :    Union[str, Any]         =						logging.get_logger(__name__)

_a     :    List[str]         =						{
    'EleutherAI/gpt-j-6B': 'https://huggingface.co/EleutherAI/gpt-j-6B/resolve/main/config.json',
    # See all GPT-J models at https://huggingface.co/models?filter=gpt_j
}
class   a_ (			A__      ):
			A__      :			Union[str, Any]       	=  'gptj'
			A__      :			Any       	=  {
			    'max_position_embeddings': 'n_positions',
			    'hidden_size': 'n_embd',
			    'num_attention_heads': 'n_head',
			    'num_hidden_layers': 'n_layer',
			}

			def __init__(   self   :  Any     , UpperCAmelCase__   :  Union[str, Any]=50_400     , UpperCAmelCase__   :  Tuple=2_048     , UpperCAmelCase__   :  Optional[int]=4_096     , UpperCAmelCase__   :  Optional[Any]=28     , UpperCAmelCase__   :  List[str]=16     , UpperCAmelCase__   :  Union[str, Any]=64     , UpperCAmelCase__   :  List[Any]=None     , UpperCAmelCase__   :  Tuple="gelu_new"     , UpperCAmelCase__   :  Union[str, Any]=0.0     , UpperCAmelCase__   :  Dict=0.0     , UpperCAmelCase__   :  str=0.0     , UpperCAmelCase__   :  int=1e-5     , UpperCAmelCase__   :  List[str]=0.02     , UpperCAmelCase__   :  str=True     , UpperCAmelCase__   :  Optional[int]=50_256     , UpperCAmelCase__   :  Dict=50_256     , UpperCAmelCase__   :  Optional[int]=False     , **UpperCAmelCase__   :  str     , ):






							"""simple docstring"""
							snake_case   :					Union[str, Any]    						=				vocab_size
							snake_case   :					List[Any]    						=				n_positions
							snake_case   :					Optional[Any]    						=				n_embd
							snake_case   :					Any    						=				n_layer
							snake_case   :					List[str]    						=				n_head
							snake_case   :					Optional[Any]    						=				n_inner
							snake_case   :					Union[str, Any]    						=				rotary_dim
							snake_case   :					Any    						=				activation_function
							snake_case   :					Dict    						=				resid_pdrop
							snake_case   :					int    						=				embd_pdrop
							snake_case   :					Optional[Any]    						=				attn_pdrop
							snake_case   :					List[str]    						=				layer_norm_epsilon
							snake_case   :					Optional[int]    						=				initializer_range
							snake_case   :					str    						=				use_cache

							snake_case   :					str    						=				bos_token_id
							snake_case   :					List[str]    						=				eos_token_id

							super().__init__(
							    bos_token_id=UpperCamelCase_     , eos_token_id=UpperCamelCase_     , tie_word_embeddings=UpperCamelCase_     , **UpperCamelCase_						)
class   a_ (			A__      ):

			def __init__(   self   :  Any     , UpperCAmelCase__   :  Optional[int]     , UpperCAmelCase__   :  List[Any] = "default"     , UpperCAmelCase__   :  Union[str, Any] = None     , UpperCAmelCase__   :  Optional[int] = 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?
											snake_case   :					Dict    						=				0

			@property
			def      lowerCAmelCase(   self   :  str						):






							"""simple docstring"""
							snake_case   :					Tuple    						=				OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}						)
							if self.use_past:
											self.fill_with_past_key_values_(UpperCamelCase_     , direction='''inputs'''						)
											snake_case   :					str    						=				{0: '''batch''', 1: '''past_sequence + sequence'''}
							else:
											snake_case   :					Union[str, Any]    						=				{0: '''batch''', 1: '''sequence'''}

							return common_inputs

			@property
			def      lowerCAmelCase(   self   :  Dict						):






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

			@property
			def      lowerCAmelCase(   self   :  Tuple						):






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

			def      lowerCAmelCase(   self   :  List[Any]     , UpperCAmelCase__   :  Any     , UpperCAmelCase__   :  Dict = -1     , UpperCAmelCase__   :  Tuple = -1     , UpperCAmelCase__   :  List[str] = False     , UpperCAmelCase__   :  Union[str, Any] = None     , ):






							"""simple docstring"""
							snake_case   :					Optional[Any]    						=				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()
							snake_case   :					Dict    						=				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

															snake_case   :					Dict    						=				common_inputs['''input_ids'''].shape
															# Not using the same length for past_key_values
															snake_case   :					Tuple    						=				seqlen + 2
															snake_case   :					Union[str, Any]    						=				(
															    batch,
															    self.num_attention_heads,
															    past_key_values_length,
															    self._config.hidden_size // self.num_attention_heads,
															)
															snake_case   :					Tuple    						=				[
															    (torch.zeros(UpperCamelCase_						), torch.zeros(UpperCamelCase_						)) for _ in range(self.num_layers						)
															]

							snake_case   :					Optional[int]    						=				common_inputs['''attention_mask''']
							if self.use_past:
											snake_case   :					Any    						=				ordered_inputs['''attention_mask'''].dtype
											snake_case   :					Tuple    						=				torch.cat(
											    [ordered_inputs['''attention_mask'''], torch.ones(UpperCamelCase_     , UpperCamelCase_     , dtype=UpperCamelCase_						)]     , dim=1						)

							return ordered_inputs



			@property
			def      lowerCAmelCase(   self   :  List[Any]						):






							"""simple docstring"""
							return 13




'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_torch_available


__snake_case				 =	{
    '''configuration_gpt_neo''': ['''GPT_NEO_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''GPTNeoConfig''', '''GPTNeoOnnxConfig'''],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case				 =	[
		    '''GPT_NEO_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''GPTNeoForCausalLM''',
		    '''GPTNeoForQuestionAnswering''',
		    '''GPTNeoForSequenceClassification''',
		    '''GPTNeoForTokenClassification''',
		    '''GPTNeoModel''',
		    '''GPTNeoPreTrainedModel''',
		    '''load_tf_weights_in_gpt_neo''',
		]

try:
		if not is_flax_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__snake_case				 =	[
		    '''FlaxGPTNeoForCausalLM''',
		    '''FlaxGPTNeoModel''',
		    '''FlaxGPTNeoPreTrainedModel''',
		]


if TYPE_CHECKING:
		from .configuration_gpt_neo import GPT_NEO_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTNeoConfig, GPTNeoOnnxConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_gpt_neo import (
				    GPT_NEO_PRETRAINED_MODEL_ARCHIVE_LIST,
				    GPTNeoForCausalLM,
				    GPTNeoForQuestionAnswering,
				    GPTNeoForSequenceClassification,
				    GPTNeoForTokenClassification,
				    GPTNeoModel,
				    GPTNeoPreTrainedModel,
				    load_tf_weights_in_gpt_neo,
				)

		try:
				if not is_flax_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_flax_gpt_neo import FlaxGPTNeoForCausalLM, FlaxGPTNeoModel, FlaxGPTNeoPreTrainedModel


else:
		import sys

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