code: 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    __lowerCAmelCase  (       a_						):
  
  
  
   '''simple docstring'''
   _lowerCamelCase						:	Any				    = 'gpt2'
   _lowerCamelCase						:	Tuple				    = ['past_key_values']
   _lowerCamelCase						:	Tuple				    = {
       'hidden_size': 'n_embd',
       'max_position_embeddings': 'n_positions',
       'num_attention_heads': 'n_head',
       'num_hidden_layers': 'n_layer',
   }
  
   def __init__(			self       :		str       ,			lowerCamelCase       :		Optional[int]=5_0_2_5_7       ,			lowerCamelCase       :		Tuple=1_0_2_4       ,			lowerCamelCase       :		Union[str, Any]=7_6_8       ,			lowerCamelCase       :		Any=1_2       ,			lowerCamelCase       :		Tuple=1_2       ,			lowerCamelCase       :		Dict=None       ,			lowerCamelCase       :		Optional[int]="gelu_new"       ,			lowerCamelCase       :		Optional[int]=0.1       ,			lowerCamelCase       :		List[str]=0.1       ,			lowerCamelCase       :		List[Any]=0.1       ,			lowerCamelCase       :		Tuple=1e-5       ,			lowerCamelCase       :		List[Any]=0.0_2       ,			lowerCamelCase       :		Optional[int]="cls_index"       ,			lowerCamelCase       :		str=True       ,			lowerCamelCase       :		Dict=None       ,			lowerCamelCase       :		List[str]=True       ,			lowerCamelCase       :		str=0.1       ,			lowerCamelCase       :		Optional[int]=True       ,			lowerCamelCase       :		List[str]=True       ,			lowerCamelCase       :		List[Any]=5_0_2_5_6       ,			lowerCamelCase       :		Dict=5_0_2_5_6       ,			lowerCamelCase       :		Any=False       ,			lowerCamelCase       :		Dict=False       ,			**lowerCamelCase       :		List[Any]       ,			) ->							Union[str, Any]:
          _UpperCamelCase     :       int  						=  vocab_size
          _UpperCamelCase     :       int  						=  n_positions
          _UpperCamelCase     :       Tuple  						=  n_embd
          _UpperCamelCase     :       List[str]  						=  n_layer
          _UpperCamelCase     :       str  						=  n_head
          _UpperCamelCase     :       List[Any]  						=  n_inner
          _UpperCamelCase     :       int  						=  activation_function
          _UpperCamelCase     :       Dict  						=  resid_pdrop
          _UpperCamelCase     :       List[Any]  						=  embd_pdrop
          _UpperCamelCase     :       Tuple  						=  attn_pdrop
          _UpperCamelCase     :       Union[str, Any]  						=  layer_norm_epsilon
          _UpperCamelCase     :       str  						=  initializer_range
          _UpperCamelCase     :       Union[str, Any]  						=  summary_type
          _UpperCamelCase     :       str  						=  summary_use_proj
          _UpperCamelCase     :       int  						=  summary_activation
          _UpperCamelCase     :       Any  						=  summary_first_dropout
          _UpperCamelCase     :       str  						=  summary_proj_to_labels
          _UpperCamelCase     :       Optional[int]  						=  scale_attn_weights
          _UpperCamelCase     :       List[Any]  						=  use_cache
          _UpperCamelCase     :       Optional[int]  						=  scale_attn_by_inverse_layer_idx
          _UpperCamelCase     :       List[str]  						=  reorder_and_upcast_attn
  
          _UpperCamelCase     :       Any  						=  bos_token_id
          _UpperCamelCase     :       Union[str, Any]  						=  eos_token_id
  
          super().__init__(bos_token_id=lowerCamelCase       ,			eos_token_id=lowerCamelCase       ,			**lowerCamelCase  )
  
  
  
  
  
  
  
  class    __lowerCAmelCase  (       a_						):
  
  
  
   '''simple docstring'''
  
   def __init__(			self       :		Dict       ,			lowerCamelCase       :		PretrainedConfig       ,			lowerCamelCase       :		str = "default"       ,			lowerCamelCase       :		List[PatchingSpec] = None       ,			lowerCamelCase       :		bool = False       ,			) ->							List[Any]:
          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     :       Optional[Any]  						=  0
  
   @property
   def 					__snake_case					(			self       :		Union[str, Any]  ) ->							Mapping[str, Mapping[int, str]]:
          _UpperCamelCase     :       int  						=  OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}}  )
          if self.use_past:
                 self.fill_with_past_key_values_(lowerCamelCase       ,			direction='inputs'  )
                 _UpperCamelCase     :       Any  						=  {0: 'batch', 1: 'past_sequence + sequence'}
          else:
                 _UpperCamelCase     :       Tuple  						=  {0: 'batch', 1: 'sequence'}
  
          return common_inputs
  
   @property
   def 					__snake_case					(			self       :		Tuple  ) ->							int:
          return self._config.n_layer
  
   @property
   def 					__snake_case					(			self       :		str  ) ->							int:
          return self._config.n_head
  
   def 					__snake_case					(			self       :		Any       ,			lowerCamelCase       :		PreTrainedTokenizer       ,			lowerCamelCase       :		int = -1       ,			lowerCamelCase       :		int = -1       ,			lowerCamelCase       :		bool = False       ,			lowerCamelCase       :		Optional[TensorType] = None       ,			) ->							Mapping[str, Any]:
          _UpperCamelCase     :       Union[str, 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()
          _UpperCamelCase     :       Optional[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						,      _UpperCamelCase     :       str  						=  common_inputs['input_ids'].shape
                        # Not using the same length for past_key_values
                        _UpperCamelCase     :       List[str]  						=  seqlen + 2
                        _UpperCamelCase     :       int  						=  (
                            batch,
                            self.num_attention_heads,
                            past_key_values_length,
                            self._config.hidden_size // self.num_attention_heads,
                        )
                        _UpperCamelCase     :       Optional[int]  						=  [
                            (torch.zeros(lowerCamelCase  ), torch.zeros(lowerCamelCase  )) for _ in range(self.num_layers  )
                        ]
  
          _UpperCamelCase     :       List[str]  						=  common_inputs['attention_mask']
          if self.use_past:
                 _UpperCamelCase     :       Any  						=  ordered_inputs['attention_mask'].dtype
                 _UpperCamelCase     :       List[str]  						=  torch.cat(
                     [ordered_inputs['attention_mask'], torch.ones(lowerCamelCase       ,			lowerCamelCase       ,			dtype=lowerCamelCase  )]       ,			dim=1  )
  
          return ordered_inputs
  
   @property
   def 					__snake_case					(			self       :		Optional[int]  ) ->							int:
          return 1_3
  
  
  
  
style_context: from ..utils import requires_backends
  
  
  UpperCAmelCase					=				None
  
  
  
  
  class    __lowerCAmelCase  :
  
  
  
   '''simple docstring'''
  
   def __init__(			self       :		Optional[int]       ,			*lowerCamelCase       :		Dict       ,			**lowerCamelCase       :		int  ) ->							Tuple:
          requires_backends(self       ,			['detectron2']  )
  
   @classmethod
   def 					__snake_case					(			cls       :		Optional[Any]       ,			*lowerCamelCase       :		Optional[int]       ,			**lowerCamelCase       :		Tuple  ) ->							List[str]:
          requires_backends(cls       ,			['detectron2']  )
  
  
  
  