





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


_UpperCAmelCase										=					logging.get_logger(__name__)

_UpperCAmelCase										=					{
    'gpt2': 'https://huggingface.co/gpt2/resolve/main/config.json',
    'gpt2-medium': 'https://huggingface.co/gpt2-medium/resolve/main/config.json',
    'gpt2-large': 'https://huggingface.co/gpt2-large/resolve/main/config.json',
    'gpt2-xl': 'https://huggingface.co/gpt2-xl/resolve/main/config.json',
    'distilgpt2': 'https://huggingface.co/distilgpt2/resolve/main/config.json',
}



class 				_UpperCamelCase       (						lowercase_  ):
       _UpperCamelCase					:       List[Any]       = '''gpt2'''
       _UpperCamelCase					:       str       = ['''past_key_values''']
       _UpperCamelCase					:       Optional[int]       = {
           '''hidden_size''': '''n_embd''',
           '''max_position_embeddings''': '''n_positions''',
           '''num_attention_heads''': '''n_head''',
           '''num_hidden_layers''': '''n_layer''',
       }

       def __init__(		self:			Any       , _SCREAMING_SNAKE_CASE:			int=50257       , _SCREAMING_SNAKE_CASE:			List[str]=1024       , _SCREAMING_SNAKE_CASE:			str=768       , _SCREAMING_SNAKE_CASE:			str=12       , _SCREAMING_SNAKE_CASE:			Optional[Any]=12       , _SCREAMING_SNAKE_CASE:			int=None       , _SCREAMING_SNAKE_CASE:			Optional[Any]="gelu_new"       , _SCREAMING_SNAKE_CASE:			int=0.1       , _SCREAMING_SNAKE_CASE:			int=0.1       , _SCREAMING_SNAKE_CASE:			List[str]=0.1       , _SCREAMING_SNAKE_CASE:			Optional[Any]=1e-5       , _SCREAMING_SNAKE_CASE:			Union[str, Any]=0.02       , _SCREAMING_SNAKE_CASE:			Any="cls_index"       , _SCREAMING_SNAKE_CASE:			Dict=True       , _SCREAMING_SNAKE_CASE:			int=None       , _SCREAMING_SNAKE_CASE:			Optional[Any]=True       , _SCREAMING_SNAKE_CASE:			Optional[int]=0.1       , _SCREAMING_SNAKE_CASE:			Optional[int]=True       , _SCREAMING_SNAKE_CASE:			Optional[int]=True       , _SCREAMING_SNAKE_CASE:			Any=50256       , _SCREAMING_SNAKE_CASE:			List[Any]=50256       , _SCREAMING_SNAKE_CASE:			Optional[int]=False       , _SCREAMING_SNAKE_CASE:			int=False       , **_SCREAMING_SNAKE_CASE:			Any       , )							->			Any:




              """simple docstring"""


              UpperCamelCase_ 							=	vocab_size
              UpperCamelCase_ 							=	n_positions
              UpperCamelCase_ 							=	n_embd
              UpperCamelCase_ 							=	n_layer
              UpperCamelCase_ 							=	n_head
              UpperCamelCase_ 							=	n_inner
              UpperCamelCase_ 							=	activation_function
              UpperCamelCase_ 							=	resid_pdrop
              UpperCamelCase_ 							=	embd_pdrop
              UpperCamelCase_ 							=	attn_pdrop
              UpperCamelCase_ 							=	layer_norm_epsilon
              UpperCamelCase_ 							=	initializer_range
              UpperCamelCase_ 							=	summary_type
              UpperCamelCase_ 							=	summary_use_proj
              UpperCamelCase_ 							=	summary_activation
              UpperCamelCase_ 							=	summary_first_dropout
              UpperCamelCase_ 							=	summary_proj_to_labels
              UpperCamelCase_ 							=	scale_attn_weights
              UpperCamelCase_ 							=	use_cache
              UpperCamelCase_ 							=	scale_attn_by_inverse_layer_idx
              UpperCamelCase_ 							=	reorder_and_upcast_attn

              UpperCamelCase_ 							=	bos_token_id
              UpperCamelCase_ 							=	eos_token_id

              super().__init__(bos_token_id=__UpperCamelCase       , eos_token_id=__UpperCamelCase       , **__UpperCamelCase		)



class 				_UpperCamelCase       (						lowercase_  ):

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




              """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?
                     UpperCamelCase_ 							=	0

       @property
       def lowercase			(		self:			str		)							->			Optional[int]:




              """simple docstring"""


              UpperCamelCase_ 							=	OrderedDict({"input_ids": {0: "batch", 1: "sequence"}}		)
              if self.use_past:
                     self.fill_with_past_key_values_(__UpperCamelCase       , direction="inputs"		)
                     UpperCamelCase_ 							=	{0: "batch", 1: "past_sequence + sequence"}
              else:
                     UpperCamelCase_ 							=	{0: "batch", 1: "sequence"}

              return common_inputs

       @property
       def lowercase			(		self:			str		)							->			str:




              """simple docstring"""


              return self._config.n_layer

       @property
       def lowercase			(		self:			Tuple		)							->			str:




              """simple docstring"""


              return self._config.n_head

       def lowercase			(		self:			Union[str, Any]       , _SCREAMING_SNAKE_CASE:			PreTrainedTokenizer       , _SCREAMING_SNAKE_CASE:			int = -1       , _SCREAMING_SNAKE_CASE:			int = -1       , _SCREAMING_SNAKE_CASE:			bool = False       , _SCREAMING_SNAKE_CASE:			Optional[TensorType] = None       , )							->			List[str]:




              """simple docstring"""


              UpperCamelCase_ 							=	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()
              UpperCamelCase_ 							=	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_							,			UpperCamelCase_ 							=	common_inputs["input_ids"].shape
                            # Not using the same length for past_key_values
                            UpperCamelCase_ 							=	seqlen + 2
                            UpperCamelCase_ 							=	(
                                batch,
                                self.num_attention_heads,
                                past_key_values_length,
                                self._config.hidden_size // self.num_attention_heads,
                            )
                            UpperCamelCase_ 							=	[
                                (torch.zeros(__UpperCamelCase		), torch.zeros(__UpperCamelCase		)) for _ in range(self.num_layers		)
                            ]

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

              return ordered_inputs



       @property
       def lowercase			(		self:			Dict		)							->			Dict:




              """simple docstring"""


              return 13








"""simple docstring"""
import copy

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


_snake_case	:						int					=					logging.get_logger(__name__)

_snake_case	:						Optional[int]					=					{}






class    _UpperCAmelCase  (      lowercase_					):
					UpperCamelCase						=				'''fsmt_decoder'''


					def __init__(   self     :Optional[int]	,			__UpperCamelCase     :Tuple=0	,			__UpperCamelCase     :List[str]=0						):
												super().__init__()
												A						=    vocab_size
												A						=    bos_token_id







class    _UpperCAmelCase  (      lowercase_					):
					UpperCamelCase						=				'''fsmt'''
					UpperCamelCase						=				{'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}


					def __init__(   self     :Dict	,			__UpperCamelCase     :List[str]=["en", "de"]	,			__UpperCamelCase     :List[str]=4_20_24	,			__UpperCamelCase     :Dict=4_20_24	,			__UpperCamelCase     :Tuple="relu"	,			__UpperCamelCase     :Optional[Any]=10_24	,			__UpperCamelCase     :Dict=2_00	,			__UpperCamelCase     :Optional[Any]=10_24	,			__UpperCamelCase     :Optional[Any]=40_96	,			__UpperCamelCase     :Union[str, Any]=12	,			__UpperCamelCase     :Dict=16	,			__UpperCamelCase     :Optional[Any]=0.0	,			__UpperCamelCase     :Dict=40_96	,			__UpperCamelCase     :Dict=12	,			__UpperCamelCase     :str=16	,			__UpperCamelCase     :Any=0.0	,			__UpperCamelCase     :str=0.0	,			__UpperCamelCase     :List[Any]=0.1	,			__UpperCamelCase     :List[Any]=0.0	,			__UpperCamelCase     :str=0.02	,			__UpperCamelCase     :List[str]=2	,			__UpperCamelCase     :Union[str, Any]=True	,			__UpperCamelCase     :Optional[Any]=True	,			__UpperCamelCase     :int=False	,			__UpperCamelCase     :List[str]=5	,			__UpperCamelCase     :Optional[int]=1.0	,			__UpperCamelCase     :List[str]=False	,			__UpperCamelCase     :Any=True	,			__UpperCamelCase     :List[str]=1	,			__UpperCamelCase     :int=0	,			__UpperCamelCase     :str=2	,			__UpperCamelCase     :Dict=2	,			**__UpperCamelCase     :Optional[int]	,			):
												A						=    langs
												A						=    src_vocab_size
												A						=    tgt_vocab_size
												A						=    d_model  # encoder_embed_dim and decoder_embed_dim

												A						=    encoder_ffn_dim
												A						=    A						=    encoder_layers
												A						=    encoder_attention_heads
												A						=    encoder_layerdrop
												A						=    decoder_layerdrop
												A						=    decoder_ffn_dim
												A						=    decoder_layers
												A						=    decoder_attention_heads
												A						=    max_position_embeddings
												A						=    init_std  # Normal(0, this parameter)
												A						=    activation_function

												A						=    DecoderConfig(vocab_size=__UpperCamelCase	,			bos_token_id=__UpperCamelCase						)
												if "decoder" in common_kwargs:
																			del common_kwargs["decoder"]

												A						=    scale_embedding  # scale factor will be sqrt(d_model) if True

												# 3 Types of Dropout
												A						=    attention_dropout
												A						=    activation_dropout
												A						=    dropout

												A						=    use_cache
												super().__init__(
												    pad_token_id=__UpperCamelCase	,			bos_token_id=__UpperCamelCase	,			eos_token_id=__UpperCamelCase	,			decoder_start_token_id=__UpperCamelCase	,			is_encoder_decoder=__UpperCamelCase	,			tie_word_embeddings=__UpperCamelCase	,			forced_eos_token_id=__UpperCamelCase	,			max_length=__UpperCamelCase	,			num_beams=__UpperCamelCase	,			length_penalty=__UpperCamelCase	,			early_stopping=__UpperCamelCase	,			**__UpperCamelCase	,			)


					def       lowerCamelCase			(   self     :List[str]						):
												A						=    copy.deepcopy(self.__dict__						)
												A						=    self.decoder.to_dict()
												A						=    self.__class__.model_type
												return output


