
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


lowerCamelCase  =logging.get_logger(__name__)

lowerCamelCase  ={
    "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 					_lowerCamelCase			(   UpperCamelCase_			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	'''gptj'''
     SCREAMING_SNAKE_CASE_		 =	{
         '''max_position_embeddings''': '''n_positions''',
         '''hidden_size''': '''n_embd''',
         '''num_attention_heads''': '''n_head''',
         '''num_hidden_layers''': '''n_layer''',
     }






     def __init__(				self    ,    __SCREAMING_SNAKE_CASE=5_0_4_0_0    ,    __SCREAMING_SNAKE_CASE=2_0_4_8    ,    __SCREAMING_SNAKE_CASE=4_0_9_6    ,    __SCREAMING_SNAKE_CASE=2_8    ,    __SCREAMING_SNAKE_CASE=1_6    ,    __SCREAMING_SNAKE_CASE=6_4    ,    __SCREAMING_SNAKE_CASE=None    ,    __SCREAMING_SNAKE_CASE="gelu_new"    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=0.0    ,    __SCREAMING_SNAKE_CASE=1e-5    ,    __SCREAMING_SNAKE_CASE=0.02    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=5_0_2_5_6    ,    __SCREAMING_SNAKE_CASE=5_0_2_5_6    ,    __SCREAMING_SNAKE_CASE=False    ,    **__SCREAMING_SNAKE_CASE    ,    )	-> Union[str, Any]:




           """simple docstring"""







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

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

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




class 					_lowerCamelCase			(   UpperCamelCase_			):





     """simple docstring"""







     def __init__(				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE = "default"    ,    __SCREAMING_SNAKE_CASE = None    ,    __SCREAMING_SNAKE_CASE = False    ,    )	-> Union[str, Any]:




           """simple docstring"""







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






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




           """simple docstring"""







           UpperCamelCase__     : List[str]											=					OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}	)
           if self.use_past:
                 self.fill_with_past_key_values_(__SCREAMING_SNAKE_CASE    ,    direction='''inputs'''	)
                 UpperCamelCase__     : List[Any]											=					{0: '''batch''', 1: '''past_sequence + sequence'''}
           else:
                 UpperCamelCase__     : Dict											=					{0: '''batch''', 1: '''sequence'''}

           return common_inputs






     @property
     def  __SCREAMING_SNAKE_CASE      (				self	)	-> int:




           """simple docstring"""







           return self._config.n_layer






     @property
     def  __SCREAMING_SNAKE_CASE      (				self	)	-> int:




           """simple docstring"""







           return self._config.n_head






     def  __SCREAMING_SNAKE_CASE      (				self    ,    __SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE = -1    ,    __SCREAMING_SNAKE_CASE = -1    ,    __SCREAMING_SNAKE_CASE = False    ,    __SCREAMING_SNAKE_CASE = None    ,    )	-> Mapping[str, Any]:




           """simple docstring"""







           UpperCamelCase__     : str											=					super(__SCREAMING_SNAKE_CASE    ,    self	).generate_dummy_inputs(
               __SCREAMING_SNAKE_CASE    ,    batch_size=__SCREAMING_SNAKE_CASE    ,    seq_length=__SCREAMING_SNAKE_CASE    ,    is_pair=__SCREAMING_SNAKE_CASE    ,    framework=__SCREAMING_SNAKE_CASE	)

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

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

           UpperCamelCase__     : Dict											=					common_inputs['''attention_mask''']
           if self.use_past:
                 UpperCamelCase__     : int											=					ordered_inputs['''attention_mask'''].dtype
                 UpperCamelCase__     : Tuple											=					torch.cat(
                     [ordered_inputs['''attention_mask'''], torch.ones(__SCREAMING_SNAKE_CASE    ,    __SCREAMING_SNAKE_CASE    ,    dtype=__SCREAMING_SNAKE_CASE	)]    ,    dim=1	)

           return ordered_inputs






     @property
     def  __SCREAMING_SNAKE_CASE      (				self	)	-> int:




           """simple docstring"""







           return 1_3




from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCamelCase  =logging.get_logger(__name__)

lowerCamelCase  ={
    "abeja/gpt-neox-japanese-2.7b": "https://huggingface.co/abeja/gpt-neox-japanese-2.7b/resolve/main/config.json",
}




class 					_lowerCamelCase			(   UpperCamelCase_			):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		 =	'''gpt_neox_japanese'''






     def __init__(				self    ,    __SCREAMING_SNAKE_CASE=3_2_0_0_0    ,    __SCREAMING_SNAKE_CASE=2_5_6_0    ,    __SCREAMING_SNAKE_CASE=3_2    ,    __SCREAMING_SNAKE_CASE=3_2    ,    __SCREAMING_SNAKE_CASE=4    ,    __SCREAMING_SNAKE_CASE="gelu"    ,    __SCREAMING_SNAKE_CASE=1.00    ,    __SCREAMING_SNAKE_CASE=1_0_0_0_0    ,    __SCREAMING_SNAKE_CASE=2_0_4_8    ,    __SCREAMING_SNAKE_CASE=0.02    ,    __SCREAMING_SNAKE_CASE=1e-5    ,    __SCREAMING_SNAKE_CASE=True    ,    __SCREAMING_SNAKE_CASE=3_1_9_9_6    ,    __SCREAMING_SNAKE_CASE=3_1_9_9_9    ,    __SCREAMING_SNAKE_CASE=0.1    ,    __SCREAMING_SNAKE_CASE=0.0    ,    **__SCREAMING_SNAKE_CASE    ,    )	-> List[str]:




           """simple docstring"""







           super().__init__(bos_token_id=__SCREAMING_SNAKE_CASE    ,    eos_token_id=__SCREAMING_SNAKE_CASE    ,    **__SCREAMING_SNAKE_CASE	)
           UpperCamelCase__     : List[str]											=					vocab_size
           UpperCamelCase__     : int											=					max_position_embeddings
           UpperCamelCase__     : Union[str, Any]											=					hidden_size
           UpperCamelCase__     : Any											=					num_hidden_layers
           UpperCamelCase__     : List[Any]											=					num_attention_heads
           UpperCamelCase__     : int											=					intermediate_multiple_size
           UpperCamelCase__     : List[Any]											=					hidden_act
           UpperCamelCase__     : Tuple											=					rotary_pct
           UpperCamelCase__     : Optional[int]											=					rotary_emb_base
           UpperCamelCase__     : Optional[Any]											=					initializer_range
           UpperCamelCase__     : Optional[int]											=					layer_norm_eps
           UpperCamelCase__     : Optional[Any]											=					use_cache
           UpperCamelCase__     : List[str]											=					attention_dropout
           UpperCamelCase__     : Optional[int]											=					hidden_dropout


