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__							):
         UpperCAmelCase__       :      Dict       =						"gpt2"
         UpperCAmelCase__       :      Optional[int]       =						["past_key_values"]
         UpperCAmelCase__       :      Any       =						{
             "hidden_size": "n_embd",
             "max_position_embeddings": "n_positions",
             "num_attention_heads": "n_head",
             "num_hidden_layers": "n_layer",
         }
         def __init__(    self,    SCREAMING_SNAKE_CASE_=5_0257,    SCREAMING_SNAKE_CASE_=1024,    SCREAMING_SNAKE_CASE_=768,    SCREAMING_SNAKE_CASE_=12,    SCREAMING_SNAKE_CASE_=12,    SCREAMING_SNAKE_CASE_=None,    SCREAMING_SNAKE_CASE_="gelu_new",    SCREAMING_SNAKE_CASE_=0.1,    SCREAMING_SNAKE_CASE_=0.1,    SCREAMING_SNAKE_CASE_=0.1,    SCREAMING_SNAKE_CASE_=1e-5,    SCREAMING_SNAKE_CASE_=0.02,    SCREAMING_SNAKE_CASE_="cls_index",    SCREAMING_SNAKE_CASE_=True,    SCREAMING_SNAKE_CASE_=None,    SCREAMING_SNAKE_CASE_=True,    SCREAMING_SNAKE_CASE_=0.1,    SCREAMING_SNAKE_CASE_=True,    SCREAMING_SNAKE_CASE_=True,    SCREAMING_SNAKE_CASE_=5_0256,    SCREAMING_SNAKE_CASE_=5_0256,    SCREAMING_SNAKE_CASE_=False,    SCREAMING_SNAKE_CASE_=False,    **SCREAMING_SNAKE_CASE_,    )  ->	List[Any]:
            UpperCamelCase					:						int					=			vocab_size
            UpperCamelCase					:						List[str]					=			n_positions
            UpperCamelCase					:						Any					=			n_embd
            UpperCamelCase					:						Optional[Any]					=			n_layer
            UpperCamelCase					:						Optional[int]					=			n_head
            UpperCamelCase					:						Optional[Any]					=			n_inner
            UpperCamelCase					:						str					=			activation_function
            UpperCamelCase					:						Any					=			resid_pdrop
            UpperCamelCase					:						Tuple					=			embd_pdrop
            UpperCamelCase					:						Any					=			attn_pdrop
            UpperCamelCase					:						Dict					=			layer_norm_epsilon
            UpperCamelCase					:						Tuple					=			initializer_range
            UpperCamelCase					:						str					=			summary_type
            UpperCamelCase					:						int					=			summary_use_proj
            UpperCamelCase					:						Union[str, Any]					=			summary_activation
            UpperCamelCase					:						List[str]					=			summary_first_dropout
            UpperCamelCase					:						List[str]					=			summary_proj_to_labels
            UpperCamelCase					:						Dict					=			scale_attn_weights
            UpperCamelCase					:						List[Any]					=			use_cache
            UpperCamelCase					:						Optional[Any]					=			scale_attn_by_inverse_layer_idx
            UpperCamelCase					:						int					=			reorder_and_upcast_attn
  
            UpperCamelCase					:						Union[str, Any]					=			bos_token_id
            UpperCamelCase					:						Optional[int]					=			eos_token_id
  
            super().__init__(bos_token_id=SCREAMING_SNAKE_CASE_,    eos_token_id=SCREAMING_SNAKE_CASE_,    **SCREAMING_SNAKE_CASE_ )
  
  
  
  
  
  
  class        lowerCAmelCase_	(						a__							):
         def __init__(    self,    SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_ = "default",    SCREAMING_SNAKE_CASE_ = None,    SCREAMING_SNAKE_CASE_ = False,    )  ->	Tuple:
            super().__init__(SCREAMING_SNAKE_CASE_,    task=SCREAMING_SNAKE_CASE_,    patching_specs=SCREAMING_SNAKE_CASE_,    use_past=SCREAMING_SNAKE_CASE_ )
            if not getattr(self._config,    'pad_token_id',    SCREAMING_SNAKE_CASE_ ):
               # TODO: how to do that better?
               UpperCamelCase					:						Optional[Any]					=			0
         @property
         def       snake_case_ (    self )  ->	Mapping[str, Mapping[int, str]]:
            UpperCamelCase					:						Union[str, Any]					=			OrderedDict({'input_ids': {0: 'batch', 1: 'sequence'}} )
            if self.use_past:
               self.fill_with_past_key_values_(SCREAMING_SNAKE_CASE_,    direction='inputs' )
               UpperCamelCase					:						str					=			{0: 'batch', 1: 'past_sequence + sequence'}
            else:
               UpperCamelCase					:						List[str]					=			{0: 'batch', 1: 'sequence'}
  
            return common_inputs
         @property
         def       snake_case_ (    self )  ->	int:
            return self._config.n_layer
         @property
         def       snake_case_ (    self )  ->	int:
            return self._config.n_head
         def       snake_case_ (    self,    SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_ = -1,    SCREAMING_SNAKE_CASE_ = -1,    SCREAMING_SNAKE_CASE_ = False,    SCREAMING_SNAKE_CASE_ = None,    )  ->	Mapping[str, Any]:
            UpperCamelCase					:						Optional[int]					=			super(SCREAMING_SNAKE_CASE_,    self ).generate_dummy_inputs(
                SCREAMING_SNAKE_CASE_,    batch_size=SCREAMING_SNAKE_CASE_,    seq_length=SCREAMING_SNAKE_CASE_,    is_pair=SCREAMING_SNAKE_CASE_,    framework=SCREAMING_SNAKE_CASE_ )
  
            # We need to order the input in the way they appears in the forward()
            UpperCamelCase					:						str					=			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					:						str					=			seqlen + 2
                  UpperCamelCase					:						int					=			(
                      batch,
                      self.num_attention_heads,
                      past_key_values_length,
                      self._config.hidden_size // self.num_attention_heads,
                  )
                  UpperCamelCase					:						List[str]					=			[
                      (torch.zeros(SCREAMING_SNAKE_CASE_ ), torch.zeros(SCREAMING_SNAKE_CASE_ )) for _ in range(self.num_layers )
                  ]
  
            UpperCamelCase					:						int					=			common_inputs['attention_mask']
            if self.use_past:
               UpperCamelCase					:						int					=			ordered_inputs['attention_mask'].dtype
               UpperCamelCase					:						Optional[Any]					=			torch.cat(
                   [ordered_inputs['attention_mask'], torch.ones(SCREAMING_SNAKE_CASE_,    SCREAMING_SNAKE_CASE_,    dtype=SCREAMING_SNAKE_CASE_ )],    dim=1 )
  
            return ordered_inputs
  
  
  
  
  
  
         @property
         def       snake_case_ (    self )  ->	int:
            return 13
  
  
  
  
style_context: 
  
  
  
  from typing import TYPE_CHECKING
  
  from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available
  
  
  __UpperCAmelCase      = {
      '''configuration_deta''': ['''DETA_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DetaConfig'''],
  }
  
  try:
      if not is_vision_available():
          raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
      pass
  else:
      __UpperCAmelCase      = ['''DetaImageProcessor''']
  
  try:
      if not is_torch_available():
          raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
      pass
  else:
      __UpperCAmelCase      = [
          '''DETA_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''DetaForObjectDetection''',
          '''DetaModel''',
          '''DetaPreTrainedModel''',
      ]
  
  
  if TYPE_CHECKING:
      from .configuration_deta import DETA_PRETRAINED_CONFIG_ARCHIVE_MAP, DetaConfig
  
      try:
          if not is_vision_available():
              raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
          pass
      else:
          from .image_processing_deta import DetaImageProcessor
  
      try:
          if not is_torch_available():
              raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
          pass
      else:
          from .modeling_deta import (
              DETA_PRETRAINED_MODEL_ARCHIVE_LIST,
              DetaForObjectDetection,
              DetaModel,
              DetaPreTrainedModel,
          )
  
  else:
      import sys
  
      __UpperCAmelCase      = _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
  
  
  
  