


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[Any]        =  logging.get_logger(__name__)

snake_case       :					Dict        =  {
    '''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 	_snake_case						(   _snake_case							):
 SCREAMING_SNAKE_CASE__   = 'gpt2'
 SCREAMING_SNAKE_CASE__   = ['past_key_values']
 SCREAMING_SNAKE_CASE__   = {
     'hidden_size': 'n_embd',
     'max_position_embeddings': 'n_positions',
     'num_attention_heads': 'n_head',
     'num_hidden_layers': 'n_layer',
 }




 def __init__(	self      ,						_lowerCamelCase=5_0257      ,						_lowerCamelCase=1024      ,						_lowerCamelCase=768      ,						_lowerCamelCase=12      ,						_lowerCamelCase=12      ,						_lowerCamelCase=None      ,						_lowerCamelCase="gelu_new"      ,						_lowerCamelCase=0.1      ,						_lowerCamelCase=0.1      ,						_lowerCamelCase=0.1      ,						_lowerCamelCase=1e-5      ,						_lowerCamelCase=0.02      ,						_lowerCamelCase="cls_index"      ,						_lowerCamelCase=True      ,						_lowerCamelCase=None      ,						_lowerCamelCase=True      ,						_lowerCamelCase=0.1      ,						_lowerCamelCase=True      ,						_lowerCamelCase=True      ,						_lowerCamelCase=5_0256      ,						_lowerCamelCase=5_0256      ,						_lowerCamelCase=False      ,						_lowerCamelCase=False      ,						**_lowerCamelCase      ,						):
       a		:Optional[int]											= vocab_size
       a		:List[Any]											= n_positions
       a		:Union[str, Any]											= n_embd
       a		:Optional[int]											= n_layer
       a		:Dict											= n_head
       a		:Union[str, Any]											= n_inner
       a		:List[Any]											= activation_function
       a		:Any											= resid_pdrop
       a		:List[str]											= embd_pdrop
       a		:int											= attn_pdrop
       a		:int											= layer_norm_epsilon
       a		:Optional[int]											= initializer_range
       a		:Any											= summary_type
       a		:Tuple											= summary_use_proj
       a		:int											= summary_activation
       a		:Any											= summary_first_dropout
       a		:Optional[Any]											= summary_proj_to_labels
       a		:Tuple											= scale_attn_weights
       a		:Union[str, Any]											= use_cache
       a		:str											= scale_attn_by_inverse_layer_idx
       a		:str											= reorder_and_upcast_attn

       a		:Union[str, Any]											= bos_token_id
       a		:str											= eos_token_id

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







class 	_snake_case						(   _snake_case							):




 def __init__(	self      ,						_lowerCamelCase      ,						_lowerCamelCase = "default"      ,						_lowerCamelCase = None      ,						_lowerCamelCase = False      ,						):
       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?
             a		:List[str]											= 0




 @property
 def  SCREAMING_SNAKE_CASE__       (	self					):
       a		:str											= OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}}					)
       if self.use_past:
             self.fill_with_past_key_values_(_lowerCamelCase      ,						direction='''inputs'''					)
             a		:Dict											= {0: '''batch''', 1: '''past_sequence + sequence'''}
       else:
             a		:List[Any]											= {0: '''batch''', 1: '''sequence'''}

       return common_inputs




 @property
 def  SCREAMING_SNAKE_CASE__       (	self					):
       return self._config.n_layer




 @property
 def  SCREAMING_SNAKE_CASE__       (	self					):
       return self._config.n_head




 def  SCREAMING_SNAKE_CASE__       (	self      ,						_lowerCamelCase      ,						_lowerCamelCase = -1      ,						_lowerCamelCase = -1      ,						_lowerCamelCase = False      ,						_lowerCamelCase = None      ,						):
       a		:Optional[Any]											= 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()
       a		:Union[str, 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

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

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

       return ordered_inputs




 @property
 def  SCREAMING_SNAKE_CASE__       (	self					):
       return 13









import warnings

from ...utils import logging
from .image_processing_convnext import ConvNextImageProcessor


snake_case       :					Tuple        =  logging.get_logger(__name__)







class 	_snake_case						(   _snake_case							):




 def __init__(	self      ,						*_lowerCamelCase      ,						**_lowerCamelCase					):
       warnings.warn(
           '''The class ConvNextFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'''
           ''' Please use ConvNextImageProcessor instead.'''      ,						_lowerCamelCase      ,						)
       super().__init__(*_lowerCamelCase      ,						**_lowerCamelCase					)





