





'''simple docstring'''




from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ..auto import CONFIG_MAPPING


lowercase__    :      int						=    logging.get_logger(__name__)

lowercase__    :      str						=    {
    '''microsoft/table-transformer-detection''': (
        '''https://huggingface.co/microsoft/table-transformer-detection/resolve/main/config.json'''
    ),
}


class  SCREAMING_SNAKE_CASE    (a__							):
     lowerCAmelCase					=       '''table-transformer'''
     lowerCAmelCase					=       ['''past_key_values''']
     lowerCAmelCase					=       {
         '''hidden_size''': '''d_model''',
         '''num_attention_heads''': '''encoder_attention_heads''',
     }


     def __init__(						self						,	_UpperCAmelCase=True						,	_UpperCAmelCase=None						,	_UpperCAmelCase=3						,	_UpperCAmelCase=100						,	_UpperCAmelCase=6						,	_UpperCAmelCase=2048						,	_UpperCAmelCase=8						,	_UpperCAmelCase=6						,	_UpperCAmelCase=2048						,	_UpperCAmelCase=8						,	_UpperCAmelCase=0.0						,	_UpperCAmelCase=0.0						,	_UpperCAmelCase=True						,	_UpperCAmelCase="relu"						,	_UpperCAmelCase=256						,	_UpperCAmelCase=0.1						,	_UpperCAmelCase=0.0						,	_UpperCAmelCase=0.0						,	_UpperCAmelCase=0.02						,	_UpperCAmelCase=1.0						,	_UpperCAmelCase=False						,	_UpperCAmelCase="sine"						,	_UpperCAmelCase="resnet50"						,	_UpperCAmelCase=True						,	_UpperCAmelCase=False						,	_UpperCAmelCase=1						,	_UpperCAmelCase=5						,	_UpperCAmelCase=2						,	_UpperCAmelCase=1						,	_UpperCAmelCase=1						,	_UpperCAmelCase=5						,	_UpperCAmelCase=2						,	_UpperCAmelCase=0.1						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          if backbone_config is not None and use_timm_backbone:
               raise ValueError('You can\'t specify both `backbone_config` and `use_timm_backbone`.')

          if not use_timm_backbone:
               if backbone_config is None:
                    logger.info('`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.')
                    __A						: str      =       CONFIG_MAPPING['resnet'](out_features=['stage4'])
               elif isinstance(_UpperCAmelCase						,	_UpperCAmelCase):
                    __A						: Any      =       backbone_config.get('model_type')
                    __A						: List[str]      =       CONFIG_MAPPING[backbone_model_type]
                    __A						: Optional[Any]      =       config_class.from_dict(_UpperCAmelCase)
               # set timm attributes to None
               __A ,__A ,__A						: str      =       None, None, None

          __A						: Tuple      =       use_timm_backbone
          __A						: str      =       backbone_config
          __A						: Union[str, Any]      =       num_channels
          __A						: Optional[Any]      =       num_queries
          __A						: List[Any]      =       d_model
          __A						: Optional[int]      =       encoder_ffn_dim
          __A						: Optional[int]      =       encoder_layers
          __A						: List[Any]      =       encoder_attention_heads
          __A						: Dict      =       decoder_ffn_dim
          __A						: int      =       decoder_layers
          __A						: Tuple      =       decoder_attention_heads
          __A						: int      =       dropout
          __A						: List[Any]      =       attention_dropout
          __A						: Any      =       activation_dropout
          __A						: str      =       activation_function
          __A						: str      =       init_std
          __A						: str      =       init_xavier_std
          __A						: List[Any]      =       encoder_layerdrop
          __A						: List[str]      =       decoder_layerdrop
          __A						: Tuple      =       encoder_layers
          __A						: List[Any]      =       auxiliary_loss
          __A						: Tuple      =       position_embedding_type
          __A						: List[Any]      =       backbone
          __A						: Dict      =       use_pretrained_backbone
          __A						: Union[str, Any]      =       dilation
          # Hungarian matcher
          __A						: Union[str, Any]      =       class_cost
          __A						: Optional[int]      =       bbox_cost
          __A						: Tuple      =       giou_cost
          # Loss coefficients
          __A						: Dict      =       mask_loss_coefficient
          __A						: List[str]      =       dice_loss_coefficient
          __A						: int      =       bbox_loss_coefficient
          __A						: Union[str, Any]      =       giou_loss_coefficient
          __A						: int      =       eos_coefficient
          super().__init__(is_encoder_decoder=_UpperCAmelCase						,	**_UpperCAmelCase)


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return self.encoder_attention_heads


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return self.d_model




class  SCREAMING_SNAKE_CASE    (a__							):
     lowerCAmelCase					=       version.parse('''1.11'''							)


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return OrderedDict(
              [
                  ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
                  ('pixel_mask', {0: 'batch'}),
              ])


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return 1e-5


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return 12






'''simple docstring'''




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


lowercase__    :      List[Any]						=    logging.get_logger(__name__)

lowercase__    :      str						=    {}


class  SCREAMING_SNAKE_CASE    (a__							):
     lowerCAmelCase					=       '''llama'''
     lowerCAmelCase					=       ['''past_key_values''']


     def __init__(						self						,	_UpperCAmelCase=3_2000						,	_UpperCAmelCase=4096						,	_UpperCAmelCase=1_1008						,	_UpperCAmelCase=32						,	_UpperCAmelCase=32						,	_UpperCAmelCase=None						,	_UpperCAmelCase="silu"						,	_UpperCAmelCase=2048						,	_UpperCAmelCase=0.02						,	_UpperCAmelCase=1e-6						,	_UpperCAmelCase=True						,	_UpperCAmelCase=0						,	_UpperCAmelCase=1						,	_UpperCAmelCase=2						,	_UpperCAmelCase=1						,	_UpperCAmelCase=False						,	_UpperCAmelCase=None						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          __A						: Union[str, Any]      =       vocab_size
          __A						: Union[str, Any]      =       max_position_embeddings
          __A						: Any      =       hidden_size
          __A						: Optional[Any]      =       intermediate_size
          __A						: str      =       num_hidden_layers
          __A						: Optional[Any]      =       num_attention_heads

          # for backward compatibility
          if num_key_value_heads is None:
               __A						: List[Any]      =       num_attention_heads

          __A						: int      =       num_key_value_heads
          __A						: List[Any]      =       hidden_act
          __A						: Union[str, Any]      =       initializer_range
          __A						: List[Any]      =       rms_norm_eps
          __A						: Any      =       pretraining_tp
          __A						: Optional[Any]      =       use_cache
          __A						: Dict      =       rope_scaling
          self._rope_scaling_validation()

          super().__init__(
              pad_token_id=_UpperCAmelCase						,	bos_token_id=_UpperCAmelCase						,	eos_token_id=_UpperCAmelCase						,	tie_word_embeddings=_UpperCAmelCase						,	**_UpperCAmelCase						,	)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          if self.rope_scaling is None:
               return

          if not isinstance(self.rope_scaling						,	_UpperCAmelCase) or len(self.rope_scaling) != 2:
               raise ValueError(
                   '`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '
                   F'got {self.rope_scaling}')
          __A						: Optional[Any]      =       self.rope_scaling.get('type'						,	_UpperCAmelCase)
          __A						: Tuple      =       self.rope_scaling.get('factor'						,	_UpperCAmelCase)
          if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
               raise ValueError(
                   F'`rope_scaling`\'s name field must be one of [\'linear\', \'dynamic\'], got {rope_scaling_type}')
          if rope_scaling_factor is None or not isinstance(_UpperCAmelCase						,	_UpperCAmelCase) or rope_scaling_factor <= 1.0:
               raise ValueError(F'`rope_scaling`\'s factor field must be an float > 1, got {rope_scaling_factor}')