

'''simple docstring'''





from . import (
    albert,
    align,
    altclip,
    audio_spectrogram_transformer,
    auto,
    autoformer,
    bark,
    bart,
    barthez,
    bartpho,
    beit,
    bert,
    bert_generation,
    bert_japanese,
    bertweet,
    big_bird,
    bigbird_pegasus,
    biogpt,
    bit,
    blenderbot,
    blenderbot_small,
    blip,
    blip_a,
    bloom,
    bridgetower,
    byta,
    camembert,
    canine,
    chinese_clip,
    clap,
    clip,
    clipseg,
    codegen,
    conditional_detr,
    convbert,
    convnext,
    convnextva,
    cpm,
    cpmant,
    ctrl,
    cvt,
    dataavec,
    deberta,
    deberta_va,
    decision_transformer,
    deformable_detr,
    deit,
    deprecated,
    deta,
    detr,
    dialogpt,
    dinat,
    distilbert,
    dit,
    donut,
    dpr,
    dpt,
    efficientformer,
    efficientnet,
    electra,
    encodec,
    encoder_decoder,
    ernie,
    ernie_m,
    esm,
    falcon,
    flaubert,
    flava,
    fnet,
    focalnet,
    fsmt,
    funnel,
    git,
    glpn,
    gpta,
    gpt_bigcode,
    gpt_neo,
    gpt_neox,
    gpt_neox_japanese,
    gpt_swa,
    gptj,
    gptsan_japanese,
    graphormer,
    groupvit,
    herbert,
    hubert,
    ibert,
    imagegpt,
    informer,
    instructblip,
    jukebox,
    layoutlm,
    layoutlmva,
    layoutlmva,
    layoutxlm,
    led,
    levit,
    lilt,
    llama,
    longformer,
    longta,
    luke,
    lxmert,
    mam_aaa,
    marian,
    markuplm,
    maskaformer,
    maskformer,
    mbart,
    mbartaa,
    mega,
    megatron_bert,
    megatron_gpta,
    mgp_str,
    mluke,
    mobilebert,
    mobilenet_va,
    mobilenet_va,
    mobilevit,
    mobilevitva,
    mpnet,
    mra,
    mta,
    musicgen,
    mvp,
    nat,
    nezha,
    nllb,
    nllb_moe,
    nystromformer,
    oneformer,
    open_llama,
    openai,
    opt,
    owlvit,
    pegasus,
    pegasus_x,
    perceiver,
    phobert,
    pixastruct,
    plbart,
    poolformer,
    prophetnet,
    qdqbert,
    rag,
    realm,
    reformer,
    regnet,
    rembert,
    resnet,
    roberta,
    roberta_prelayernorm,
    roc_bert,
    roformer,
    rwkv,
    sam,
    segformer,
    sew,
    sew_d,
    speech_encoder_decoder,
    speech_to_text,
    speech_to_text_a,
    speechta,
    splinter,
    squeezebert,
    swiftformer,
    swin,
    swinasr,
    swinva,
    switch_transformers,
    ta,
    table_transformer,
    tapas,
    time_series_transformer,
    timesformer,
    timm_backbone,
    transfo_xl,
    trocr,
    tvlt,
    umta,
    unispeech,
    unispeech_sat,
    upernet,
    videomae,
    vilt,
    vision_encoder_decoder,
    vision_text_dual_encoder,
    visual_bert,
    vit,
    vit_hybrid,
    vit_mae,
    vit_msn,
    vivit,
    wavaveca,
    wavaveca_conformer,
    wavaveca_phoneme,
    wavaveca_with_lm,
    wavlm,
    whisper,
    x_clip,
    xglm,
    xlm,
    xlm_prophetnet,
    xlm_roberta,
    xlm_roberta_xl,
    xlnet,
    xmod,
    yolos,
    yoso,
)


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