




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


__SCREAMING_SNAKE_CASE    :   Tuple       =logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE    :   Tuple       ={
    """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 			A			(		_lowerCAmelCase		):
     """simple docstring"""

     _snake_case:	Dict     ="gpt2"
     _snake_case:	int     =["past_key_values"]
     _snake_case:	Any     ={
         "hidden_size": "n_embd",
         "max_position_embeddings": "n_positions",
         "num_attention_heads": "n_head",
         "num_hidden_layers": "n_layer",
     }




     def __init__(    self  :   List[Any]	,  A__  :   Optional[int]=5_0_2_5_7	,  A__  :   Any=1_0_2_4	,  A__  :   List[str]=7_6_8	,  A__  :   Union[str, Any]=1_2	,  A__  :   List[str]=1_2	,  A__  :   str=None	,  A__  :   Optional[int]="gelu_new"	,  A__  :   Dict=0.1	,  A__  :   Optional[Any]=0.1	,  A__  :   Optional[int]=0.1	,  A__  :   Optional[Any]=1E-5	,  A__  :   List[str]=0.02	,  A__  :   Any="cls_index"	,  A__  :   Tuple=True	,  A__  :   List[str]=None	,  A__  :   Union[str, Any]=True	,  A__  :   Union[str, Any]=0.1	,  A__  :   str=True	,  A__  :   Optional[int]=True	,  A__  :   Tuple=5_0_2_5_6	,  A__  :   Optional[Any]=5_0_2_5_6	,  A__  :   List[str]=False	,  A__  :   int=False	,  **A__  :   List[str]	,  )				->       int:
           lowerCamelCase__        =				vocab_size
           lowerCamelCase__        =				n_positions
           lowerCamelCase__        =				n_embd
           lowerCamelCase__        =				n_layer
           lowerCamelCase__        =				n_head
           lowerCamelCase__        =				n_inner
           lowerCamelCase__        =				activation_function
           lowerCamelCase__        =				resid_pdrop
           lowerCamelCase__        =				embd_pdrop
           lowerCamelCase__        =				attn_pdrop
           lowerCamelCase__        =				layer_norm_epsilon
           lowerCamelCase__        =				initializer_range
           lowerCamelCase__        =				summary_type
           lowerCamelCase__        =				summary_use_proj
           lowerCamelCase__        =				summary_activation
           lowerCamelCase__        =				summary_first_dropout
           lowerCamelCase__        =				summary_proj_to_labels
           lowerCamelCase__        =				scale_attn_weights
           lowerCamelCase__        =				use_cache
           lowerCamelCase__        =				scale_attn_by_inverse_layer_idx
           lowerCamelCase__        =				reorder_and_upcast_attn

           lowerCamelCase__        =				bos_token_id
           lowerCamelCase__        =				eos_token_id

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






class 			A			(		_lowerCAmelCase		):
     """simple docstring"""

     def __init__(    self  :   Tuple	,  A__  :   PretrainedConfig	,  A__  :   str = "default"	,  A__  :   List[PatchingSpec] = None	,  A__  :   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?
                 lowerCamelCase__        =				0




     @property
     def  __snake_case   (    self  :   Any			)				->       Mapping[str, Mapping[int, str]]:
           lowerCamelCase__        =				OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}			)
           if self.use_past:
                 self.fill_with_past_key_values_(A__	,  direction='inputs'			)
                 lowerCamelCase__        =				{0: 'batch', 1: 'past_sequence + sequence'}
           else:
                 lowerCamelCase__        =				{0: 'batch', 1: 'sequence'}

           return common_inputs




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




     @property
     def  __snake_case   (    self  :   str			)				->       int:
           return self._config.n_head




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

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

           lowerCamelCase__        =				common_inputs['attention_mask']
           if self.use_past:
                 lowerCamelCase__        =				ordered_inputs['attention_mask'].dtype
                 lowerCamelCase__        =				torch.cat(
                     [ordered_inputs['attention_mask'], torch.ones(A__	,  A__	,  dtype=A__			)]	,  dim=1			)

           return ordered_inputs




     @property
     def  __snake_case   (    self  :   Union[str, Any]			)				->       int:
           return 1_3





from ..utils import DummyObject, requires_backends






class 			A			(		metaclass=_lowerCAmelCase		):
     """simple docstring"""

     _snake_case:	Optional[Any]     =["torch", "transformers", "invisible_watermark"]




     def __init__(    self  :   Dict	,  *A__  :   Optional[int]	,  **A__  :   Dict			)				->       Union[str, Any]:
           requires_backends(self	,  ['torch', 'transformers', 'invisible_watermark']			)




     @classmethod
     def  __snake_case   (    cls  :   Optional[int]	,  *A__  :   Dict	,  **A__  :   List[str]			)				->       Union[str, Any]:
           requires_backends(cls	,  ['torch', 'transformers', 'invisible_watermark']			)




     @classmethod
     def  __snake_case   (    cls  :   Optional[Any]	,  *A__  :   Dict	,  **A__  :   List[Any]			)				->       Dict:
           requires_backends(cls	,  ['torch', 'transformers', 'invisible_watermark']			)






class 			A			(		metaclass=_lowerCAmelCase		):
     """simple docstring"""

     _snake_case:	Dict     =["torch", "transformers", "invisible_watermark"]




     def __init__(    self  :   List[str]	,  *A__  :   str	,  **A__  :   int			)				->       List[Any]:
           requires_backends(self	,  ['torch', 'transformers', 'invisible_watermark']			)




     @classmethod
     def  __snake_case   (    cls  :   str	,  *A__  :   Any	,  **A__  :   Dict			)				->       Optional[Any]:
           requires_backends(cls	,  ['torch', 'transformers', 'invisible_watermark']			)




     @classmethod
     def  __snake_case   (    cls  :   List[str]	,  *A__  :   Optional[Any]	,  **A__  :   int			)				->       Dict:
           requires_backends(cls	,  ['torch', 'transformers', 'invisible_watermark']			)