




"""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__						=			{
    '''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__			(       UpperCamelCase_  ):
						snake_case__             = '''gptj'''
						snake_case__             = {
						    '''max_position_embeddings''': '''n_positions''',
						    '''hidden_size''': '''n_embd''',
						    '''num_attention_heads''': '''n_head''',
						    '''num_hidden_layers''': '''n_layer''',
						}





						def __init__(							self      :	List[Any]     ,a__      :	str=5_0400     ,a__      :	List[str]=2048     ,a__      :	int=4096     ,a__      :	int=28     ,a__      :	Optional[int]=16     ,a__      :	Optional[Any]=64     ,a__      :	Union[str, Any]=None     ,a__      :	Any="gelu_new"     ,a__      :	Union[str, Any]=0.0     ,a__      :	Union[str, Any]=0.0     ,a__      :	Dict=0.0     ,a__      :	List[Any]=1E-5     ,a__      :	Tuple=0.02     ,a__      :	List[Any]=True     ,a__      :	Dict=5_0256     ,a__      :	Any=5_0256     ,a__      :	Tuple=False     ,**a__      :	Union[str, Any]     ,)						->       List[Any]:




											"""simple docstring"""







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

											_lowerCAmelCase:Any									=  bos_token_id
											_lowerCAmelCase:Dict									=  eos_token_id

											super().__init__(
											    bos_token_id=a__     ,eos_token_id=a__     ,tie_word_embeddings=a__     ,**a__)




class   a__			(       UpperCamelCase_  ):





						def __init__(							self      :	Optional[int]     ,a__      :	PretrainedConfig     ,a__      :	str = "default"     ,a__      :	List[PatchingSpec] = None     ,a__      :	bool = False     ,)						->       Optional[int]:




											"""simple docstring"""







											super().__init__(a__     ,task=a__     ,patching_specs=a__     ,use_past=a__)
											if not getattr(self._config     ,'''pad_token_id'''     ,a__):
																# TODO: how to do that better?
																_lowerCAmelCase:str									=  0





						@property
						def       __UpperCamelCase     (							self      :	int)						->       Mapping[str, Mapping[int, str]]:




											"""simple docstring"""







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

											return common_inputs





						@property
						def       __UpperCamelCase     (							self      :	Dict)						->       int:




											"""simple docstring"""







											return self._config.n_layer





						@property
						def       __UpperCamelCase     (							self      :	Dict)						->       int:




											"""simple docstring"""







											return self._config.n_head





						def       __UpperCamelCase     (							self      :	Dict     ,a__      :	PreTrainedTokenizer     ,a__      :	int = -1     ,a__      :	int = -1     ,a__      :	bool = False     ,a__      :	Optional[TensorType] = None     ,)						->       Mapping[str, Any]:




											"""simple docstring"""







											_lowerCAmelCase:Any									=  super(a__     ,self).generate_dummy_inputs(
											    a__     ,batch_size=a__     ,seq_length=a__     ,is_pair=a__     ,framework=a__)

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

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

											_lowerCAmelCase:Dict									=  common_inputs['''attention_mask''']
											if self.use_past:
																_lowerCAmelCase:Optional[Any]									=  ordered_inputs['''attention_mask'''].dtype
																_lowerCAmelCase:List[str]									=  torch.cat(
																    [ordered_inputs['''attention_mask'''], torch.ones(a__     ,a__     ,dtype=a__)]     ,dim=1)

											return ordered_inputs







						@property
						def       __UpperCamelCase     (							self      :	Dict)						->       int:




											"""simple docstring"""







											return 13












"""simple docstring"""






import baseaa





def 							UpperCAmelCase		(		snake_case			:					str    ):
					return baseaa.aaaencode(string.encode('''utf-8'''    )    )





def 							UpperCAmelCase		(		snake_case			:					bytes    ):
					return baseaa.aaadecode(snake_case    ).decode('''utf-8'''    )


if __name__ == "__main__":
				import doctest

				doctest.testmod()






