


"""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__       :							Optional[int]        =  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 				UpperCamelCase_			(				UpperCamelCase):
	snake_case__       :						str					      =    "gptj"
	snake_case__       :						List[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__    :       List[Any]=5_0_4_0_0    ,    UpperCAmelCase__    :       Tuple=2_0_4_8    ,    UpperCAmelCase__    :       Any=4_0_9_6    ,    UpperCAmelCase__    :       List[str]=2_8    ,    UpperCAmelCase__    :       Optional[int]=1_6    ,    UpperCAmelCase__    :       Any=6_4    ,    UpperCAmelCase__    :       Any=None    ,    UpperCAmelCase__    :       List[Any]="gelu_new"    ,    UpperCAmelCase__    :       Any=0.0    ,    UpperCAmelCase__    :       int=0.0    ,    UpperCAmelCase__    :       Tuple=0.0    ,    UpperCAmelCase__    :       List[str]=1E-5    ,    UpperCAmelCase__    :       int=0.02    ,    UpperCAmelCase__    :       Any=True    ,    UpperCAmelCase__    :       str=5_0_2_5_6    ,    UpperCAmelCase__    :       Dict=5_0_2_5_6    ,    UpperCAmelCase__    :       List[str]=False    ,    **UpperCAmelCase__    :       Tuple    ,    ) ->			Union[str, Any]:
						__SCREAMING_SNAKE_CASE		     =       vocab_size
						__SCREAMING_SNAKE_CASE		     =       n_positions
						__SCREAMING_SNAKE_CASE		     =       n_embd
						__SCREAMING_SNAKE_CASE		     =       n_layer
						__SCREAMING_SNAKE_CASE		     =       n_head
						__SCREAMING_SNAKE_CASE		     =       n_inner
						__SCREAMING_SNAKE_CASE		     =       rotary_dim
						__SCREAMING_SNAKE_CASE		     =       activation_function
						__SCREAMING_SNAKE_CASE		     =       resid_pdrop
						__SCREAMING_SNAKE_CASE		     =       embd_pdrop
						__SCREAMING_SNAKE_CASE		     =       attn_pdrop
						__SCREAMING_SNAKE_CASE		     =       layer_norm_epsilon
						__SCREAMING_SNAKE_CASE		     =       initializer_range
						__SCREAMING_SNAKE_CASE		     =       use_cache

						__SCREAMING_SNAKE_CASE		     =       bos_token_id
						__SCREAMING_SNAKE_CASE		     =       eos_token_id

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




class 				UpperCamelCase_			(				UpperCamelCase):




	def __init__(				self    :       List[str]    ,    UpperCAmelCase__    :       PretrainedConfig    ,    UpperCAmelCase__    :       str = "default"    ,    UpperCAmelCase__    :       List[PatchingSpec] = None    ,    UpperCAmelCase__    :       bool = False    ,    ) ->			List[str]:
						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?
											__SCREAMING_SNAKE_CASE		     =       0




	@property
	def 						UpperCAmelCase_   (				self    :       Union[str, Any]     ) ->			Mapping[str, Mapping[int, str]]:
						__SCREAMING_SNAKE_CASE		     =       OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}     )
						if self.use_past:
											self.fill_with_past_key_values_(__A    ,    direction="inputs"     )
											__SCREAMING_SNAKE_CASE		     =       {0: "batch", 1: "past_sequence + sequence"}
						else:
											__SCREAMING_SNAKE_CASE		     =       {0: "batch", 1: "sequence"}

						return common_inputs




	@property
	def 						UpperCAmelCase_   (				self    :       Any     ) ->			int:
						return self._config.n_layer




	@property
	def 						UpperCAmelCase_   (				self    :       Any     ) ->			int:
						return self._config.n_head




	def 						UpperCAmelCase_   (				self    :       List[Any]    ,    UpperCAmelCase__    :       PreTrainedTokenizer    ,    UpperCAmelCase__    :       int = -1    ,    UpperCAmelCase__    :       int = -1    ,    UpperCAmelCase__    :       bool = False    ,    UpperCAmelCase__    :       Optional[TensorType] = None    ,    ) ->			Mapping[str, Any]:
						__SCREAMING_SNAKE_CASE		     =       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()
						__SCREAMING_SNAKE_CASE		     =       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

																__SCREAMING_SNAKE_CASE     ,						__SCREAMING_SNAKE_CASE		     =       common_inputs["input_ids"].shape
																# Not using the same length for past_key_values
																__SCREAMING_SNAKE_CASE		     =       seqlen + 2
																__SCREAMING_SNAKE_CASE		     =       (
																    batch,
																    self.num_attention_heads,
																    past_key_values_length,
																    self._config.hidden_size // self.num_attention_heads,
																)
																__SCREAMING_SNAKE_CASE		     =       [
																    (torch.zeros(__A     ), torch.zeros(__A     )) for _ in range(self.num_layers     )
																]

						__SCREAMING_SNAKE_CASE		     =       common_inputs["attention_mask"]
						if self.use_past:
											__SCREAMING_SNAKE_CASE		     =       ordered_inputs["attention_mask"].dtype
											__SCREAMING_SNAKE_CASE		     =       torch.cat(
											    [ordered_inputs["attention_mask"], torch.ones(__A    ,    __A    ,    dtype=__A     )]    ,    dim=1     )

						return ordered_inputs




	@property
	def 						UpperCAmelCase_   (				self    :       int     ) ->			int:
						return 1_3




"""simple docstring"""







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available


a__       :							List[str]        =  {}


try:
		if not is_sentencepiece_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		a__       :							int        =  ['''MLukeTokenizer''']

if TYPE_CHECKING:
		try:
				if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .tokenization_mluke import MLukeTokenizer


else:
		import sys

		a__       :							Optional[Any]        =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
