




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


_A													=      logging.get_logger(__name__)

_A													=      {
    """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    (					a_						):
   _lowerCamelCase    :Union[str, Any]     				=     "gptj"
   _lowerCamelCase    :List[Any]     				=     {
       "max_position_embeddings": "n_positions",
       "hidden_size": "n_embd",
       "num_attention_heads": "n_head",
       "num_hidden_layers": "n_layer",
   }






   def __init__(		self       :		List[Any]   ,     UpperCamelCase       :		Tuple=5_04_00   ,     UpperCamelCase       :		str=20_48   ,     UpperCamelCase       :		Union[str, Any]=40_96   ,     UpperCamelCase       :		Dict=28   ,     UpperCamelCase       :		List[str]=16   ,     UpperCamelCase       :		Any=64   ,     UpperCamelCase       :		Optional[int]=None   ,     UpperCamelCase       :		Union[str, Any]="gelu_new"   ,     UpperCamelCase       :		Tuple=0.0   ,     UpperCamelCase       :		Dict=0.0   ,     UpperCamelCase       :		Tuple=0.0   ,     UpperCamelCase       :		Tuple=1E-5   ,     UpperCamelCase       :		str=0.02   ,     UpperCamelCase       :		List[Any]=True   ,     UpperCamelCase       :		Optional[int]=5_02_56   ,     UpperCamelCase       :		int=5_02_56   ,     UpperCamelCase       :		Dict=False   ,     **UpperCamelCase       :		List[Any]   ,     )			->						str:

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

         lowerCAmelCase__      :			int   =	bos_token_id
         lowerCAmelCase__      :			Optional[Any]   =	eos_token_id

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






class _lowerCamelCase    (					a_						):






   def __init__(		self       :		str   ,     UpperCamelCase       :		PretrainedConfig   ,     UpperCamelCase       :		str = "default"   ,     UpperCamelCase       :		List[PatchingSpec] = None   ,     UpperCamelCase       :		bool = False   ,     )			->						Union[str, Any]:

         """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__      :			List[str]   =	0






   @property
   def 	_lowerCAmelCase   (		self       :		List[Any]   )			->						Mapping[str, Mapping[int, str]]:

         """simple docstring"""
         lowerCAmelCase__      :			Dict   =	OrderedDict({"""input_ids""": {0: """batch""", 1: """sequence"""}}   )
         if self.use_past:
               self.fill_with_past_key_values_(UpperCamelCase   ,     direction="""inputs"""   )
               lowerCAmelCase__      :			Union[str, Any]   =	{0: """batch""", 1: """past_sequence + sequence"""}
         else:
               lowerCAmelCase__      :			List[Any]   =	{0: """batch""", 1: """sequence"""}

         return common_inputs






   @property
   def 	_lowerCAmelCase   (		self       :		Union[str, Any]   )			->						int:

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






   @property
   def 	_lowerCAmelCase   (		self       :		int   )			->						int:

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






   def 	_lowerCAmelCase   (		self       :		List[Any]   ,     UpperCamelCase       :		PreTrainedTokenizer   ,     UpperCamelCase       :		int = -1   ,     UpperCamelCase       :		int = -1   ,     UpperCamelCase       :		bool = False   ,     UpperCamelCase       :		Optional[TensorType] = None   ,     )			->						Mapping[str, Any]:

         """simple docstring"""
         lowerCAmelCase__      :			Tuple   =	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__      :			int   =	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[Any]   =	common_inputs["""input_ids"""].shape
                     # Not using the same length for past_key_values
                     lowerCAmelCase__      :			Optional[Any]   =	seqlen + 2
                     lowerCAmelCase__      :			int   =	(
                         batch,
                         self.num_attention_heads,
                         past_key_values_length,
                         self._config.hidden_size // self.num_attention_heads,
                     )
                     lowerCAmelCase__      :			List[str]   =	[
                         (torch.zeros(UpperCamelCase   ), torch.zeros(UpperCamelCase   )) 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__      :			int   =	torch.cat(
                   [ordered_inputs["""attention_mask"""], torch.ones(UpperCamelCase   ,     UpperCamelCase   ,     dtype=UpperCamelCase   )]   ,     dim=1   )

         return ordered_inputs






   @property
   def 	_lowerCAmelCase   (		self       :		Any   )			->						int:

         """simple docstring"""
         return 13











"""simple docstring"""


# This is the module that test_patching.py uses to test patch_submodule()

import os  # noqa: this is just for tests
import os as renamed_os  # noqa: this is just for tests
from os import path  # noqa: this is just for tests
from os import path as renamed_path  # noqa: this is just for tests
from os.path import join  # noqa: this is just for tests
from os.path import join as renamed_join  # noqa: this is just for tests


_A													=      open  # noqa: we just need to have a builtin inside this module to test it properly





