

from typing import TYPE_CHECKING

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


a_						     =    {
    'configuration_transfo_xl': ['TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TransfoXLConfig'],
    'tokenization_transfo_xl': ['TransfoXLCorpus', 'TransfoXLTokenizer'],
}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			a_						     =    [
			    'TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
			    'AdaptiveEmbedding',
			    'TransfoXLForSequenceClassification',
			    'TransfoXLLMHeadModel',
			    'TransfoXLModel',
			    'TransfoXLPreTrainedModel',
			    'load_tf_weights_in_transfo_xl',
			]

try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			a_						     =    [
			    'TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
			    'TFAdaptiveEmbedding',
			    'TFTransfoXLForSequenceClassification',
			    'TFTransfoXLLMHeadModel',
			    'TFTransfoXLMainLayer',
			    'TFTransfoXLModel',
			    'TFTransfoXLPreTrainedModel',
			]


if TYPE_CHECKING:
			from .configuration_transfo_xl import TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP, TransfoXLConfig
			from .tokenization_transfo_xl import TransfoXLCorpus, TransfoXLTokenizer

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_transfo_xl import (
						    TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
						    AdaptiveEmbedding,
						    TransfoXLForSequenceClassification,
						    TransfoXLLMHeadModel,
						    TransfoXLModel,
						    TransfoXLPreTrainedModel,
						    load_tf_weights_in_transfo_xl,
						)

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_transfo_xl import (
						    TF_TRANSFO_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFAdaptiveEmbedding,
						    TFTransfoXLForSequenceClassification,
						    TFTransfoXLLMHeadModel,
						    TFTransfoXLMainLayer,
						    TFTransfoXLModel,
						    TFTransfoXLPreTrainedModel,
						)

else:
			import sys

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


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 _UpperCamelCase							(							__A   ):
			'''simple docstring'''







			lowerCamelCase__           ='gptj'
			lowerCamelCase__           ={
			    'max_position_embeddings': 'n_positions',
			    'hidden_size': 'n_embd',
			    'num_attention_heads': 'n_head',
			    'num_hidden_layers': 'n_layer',
			}
			def __init__(			self							: Dict      ,      a							: Optional[Any]=5_0400      ,      a							: List[str]=2048      ,      a							: List[Any]=4096      ,      a							: int=28      ,      a							: Union[str, Any]=16      ,      a							: List[Any]=64      ,      a							: int=None      ,      a							: Optional[int]="gelu_new"      ,      a							: Optional[Any]=0.0      ,      a							: Any=0.0      ,      a							: Union[str, Any]=0.0      ,      a							: Union[str, Any]=1e-5      ,      a							: Any=0.02      ,      a							: Optional[int]=True      ,      a							: Tuple=5_0256      ,      a							: Union[str, Any]=5_0256      ,      a							: List[Any]=False      ,      **a							: str      ,      )							->       Optional[Any]:

				"""simple docstring"""

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

				SCREAMING_SNAKE_CASE   :      Union[str, Any]				     =       bos_token_id
				SCREAMING_SNAKE_CASE   :      List[Any]				     =       eos_token_id

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






class _UpperCamelCase							(							__A   ):
			'''simple docstring'''







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

				"""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?
					SCREAMING_SNAKE_CASE   :      Dict				     =       0
			@property
			def 							__UpperCamelCase (			self							: Any	)							->       Mapping[str, Mapping[int, str]]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      List[Any]				     =       OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}	)
				if self.use_past:
					self.fill_with_past_key_values_(a      ,      direction="inputs"	)
					SCREAMING_SNAKE_CASE   :      int				     =       {0: "batch", 1: "past_sequence + sequence"}
				else:
					SCREAMING_SNAKE_CASE   :      Any				     =       {0: "batch", 1: "sequence"}

				return common_inputs
			@property
			def 							__UpperCamelCase (			self							: Any	)							->       int:

				"""simple docstring"""

				return self._config.n_layer
			@property
			def 							__UpperCamelCase (			self							: str	)							->       int:

				"""simple docstring"""

				return self._config.n_head
			def 							__UpperCamelCase (			self							: str      ,      a							: PreTrainedTokenizer      ,      a							: int = -1      ,      a							: int = -1      ,      a							: bool = False      ,      a							: Optional[TensorType] = None      ,      )							->       Mapping[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE   :      int				     =       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   :      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

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

				SCREAMING_SNAKE_CASE   :      Optional[int]				     =       common_inputs["attention_mask"]
				if self.use_past:
					SCREAMING_SNAKE_CASE   :      List[str]				     =       ordered_inputs["attention_mask"].dtype
					SCREAMING_SNAKE_CASE   :      Any				     =       torch.cat(
					    [ordered_inputs["attention_mask"], torch.ones(a      ,      a      ,      dtype=a	)]      ,      dim=1	)

				return ordered_inputs






			@property
			def 							__UpperCamelCase (			self							: Optional[Any]	)							->       int:

				"""simple docstring"""

				return 13