





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


snake_case_   :				List[str]		=     logging.get_logger(__name__)

snake_case_   :				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     __a					(a__   ):
							__a    :      Tuple  	=				"gptj"
							__a    :      Optional[Any]  	=				{
							    "max_position_embeddings": "n_positions",
							    "hidden_size": "n_embd",
							    "num_attention_heads": "n_head",
							    "num_hidden_layers": "n_layer",
							}

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







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

													UpperCAmelCase_	:					Optional[Any]     =     bos_token_id
													UpperCAmelCase_	:					List[Any]     =     eos_token_id

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





class     __a					(a__   ):

							def __init__(							self							:   int				,   __magic_name__							:   List[Any]				,   __magic_name__							:   Optional[int] = "default"				,   __magic_name__							:   Optional[int] = None				,   __magic_name__							:   Optional[Any] = False				,   )    ->				Any:







													"""simple docstring"""
													super().__init__(__lowerCAmelCase				,   task=__lowerCAmelCase				,   patching_specs=__lowerCAmelCase				,   use_past=__lowerCAmelCase      )
													if not getattr(self._config				,   '''pad_token_id'''				,   __lowerCAmelCase      ):
																			# TODO: how to do that better?
																			UpperCAmelCase_	:					List[Any]     =     0

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







													"""simple docstring"""
													UpperCAmelCase_	:					Dict     =     OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}      )
													if self.use_past:
																			self.fill_with_past_key_values_(__lowerCAmelCase				,   direction='''inputs'''      )
																			UpperCAmelCase_	:					int     =     {0: '''batch''', 1: '''past_sequence + sequence'''}
													else:
																			UpperCAmelCase_	:					List[str]     =     {0: '''batch''', 1: '''sequence'''}

													return common_inputs

							@property
							def 			UpperCAmelCase__		(							self							:   Tuple      )    ->				int:







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

							@property
							def 			UpperCAmelCase__		(							self							:   str      )    ->				int:







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

							def 			UpperCAmelCase__		(							self							:   List[Any]				,   __magic_name__							:   int				,   __magic_name__							:   Dict = -1				,   __magic_name__							:   int = -1				,   __magic_name__							:   List[str] = False				,   __magic_name__							:   Dict = None				,   )    ->				Mapping[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_	:					str     =     super(__lowerCAmelCase				,   self      ).generate_dummy_inputs(
													    __lowerCAmelCase				,   batch_size=__lowerCAmelCase				,   seq_length=__lowerCAmelCase				,   is_pair=__lowerCAmelCase				,   framework=__lowerCAmelCase      )

													# We need to order the input in the way they appears in the forward()
													UpperCAmelCase_	:					List[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_	:					Tuple     =     common_inputs['''input_ids'''].shape
																									# Not using the same length for past_key_values
																									UpperCAmelCase_	:					Optional[int]     =     seqlen + 2
																									UpperCAmelCase_	:					Any     =     (
																									    batch,
																									    self.num_attention_heads,
																									    past_key_values_length,
																									    self._config.hidden_size // self.num_attention_heads,
																									)
																									UpperCAmelCase_	:					Any     =     [
																									    (torch.zeros(__lowerCAmelCase      ), torch.zeros(__lowerCAmelCase      )) for _ in range(self.num_layers      )
																									]

													UpperCAmelCase_	:					Dict     =     common_inputs['''attention_mask''']
													if self.use_past:
																			UpperCAmelCase_	:					Optional[int]     =     ordered_inputs['''attention_mask'''].dtype
																			UpperCAmelCase_	:					List[Any]     =     torch.cat(
																			    [ordered_inputs['''attention_mask'''], torch.ones(__lowerCAmelCase				,   __lowerCAmelCase				,   dtype=__lowerCAmelCase      )]				,   dim=1      )

													return ordered_inputs



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







													"""simple docstring"""
													return 13






'''simple docstring'''

import copy

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


__a: List[str]          =   logging.get_logger(__name__)



class 			UpperCAmelCase  (						a__					):





       '''simple docstring'''



       SCREAMING_SNAKE_CASE							=    "encoder-decoder"
       SCREAMING_SNAKE_CASE							=    True

       def __init__(						self	,   **__lowerCAmelCase )  ->  int:
        super().__init__(**__lowerCAmelCase )
        assert (
            "encoder" in kwargs and "decoder" in kwargs
        ), "Config has to be initialized with encoder and decoder config"
        lowercase__				:    Optional[int]  =					kwargs.pop('''encoder''' )
        lowercase__				:    Union[str, Any]  =					encoder_config.pop('''model_type''' )
        lowercase__				:    Any  =					kwargs.pop('''decoder''' )
        lowercase__				:    Any  =					decoder_config.pop('''model_type''' )

        from ..auto.configuration_auto import AutoConfig

        lowercase__				:    Union[str, Any]  =					AutoConfig.for_model(__lowerCAmelCase	,   **__lowerCAmelCase )
        lowercase__				:    Optional[Any]  =					AutoConfig.for_model(__lowerCAmelCase	,   **__lowerCAmelCase )
        lowercase__				:    Tuple  =					True

       @classmethod
       def _lowerCAmelCase(						cls	,   __lowerCAmelCase	,   __lowerCAmelCase	,   **__lowerCAmelCase )  ->  PretrainedConfig:
        logger.info('''Set `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config''' )
        lowercase__				:    Union[str, Any]  =					True
        lowercase__				:    Any  =					True

        return cls(encoder=encoder_config.to_dict()	,   decoder=decoder_config.to_dict()	,   **__lowerCAmelCase )


       def _lowerCAmelCase(						self )  ->  Any:
        lowercase__				:    Any  =					copy.deepcopy(self.__dict__ )
        lowercase__				:    Optional[Any]  =					self.encoder.to_dict()
        lowercase__				:    Tuple  =					self.decoder.to_dict()
        lowercase__				:    Dict  =					self.__class__.model_type
        return output

