

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


lowerCAmelCase__											=	logging.get_logger(__name__)

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






class 			lowercase_	(_lowerCamelCase      ):




  """simple docstring"""




  SCREAMING_SNAKE_CASE    :  Optional[Any]							=			'table-transformer'
  SCREAMING_SNAKE_CASE    :  Union[str, Any]							=			['past_key_values']
  SCREAMING_SNAKE_CASE    :  Optional[int]							=			{
      'hidden_size': 'd_model',
      'num_attention_heads': 'encoder_attention_heads',
  }






  def __init__(      self   :     int					,lowercase__   :     Tuple=True					,lowercase__   :     int=None					,lowercase__   :     Tuple=3					,lowercase__   :     int=1_0_0					,lowercase__   :     int=6					,lowercase__   :     List[str]=2_0_4_8					,lowercase__   :     Tuple=8					,lowercase__   :     int=6					,lowercase__   :     Dict=2_0_4_8					,lowercase__   :     List[str]=8					,lowercase__   :     str=0.0					,lowercase__   :     Optional[int]=0.0					,lowercase__   :     Union[str, Any]=True					,lowercase__   :     Dict="relu"					,lowercase__   :     Dict=2_5_6					,lowercase__   :     Optional[Any]=0.1					,lowercase__   :     Union[str, Any]=0.0					,lowercase__   :     int=0.0					,lowercase__   :     List[Any]=0.0_2					,lowercase__   :     Optional[Any]=1.0					,lowercase__   :     Any=False					,lowercase__   :     Tuple="sine"					,lowercase__   :     Optional[int]="resnet50"					,lowercase__   :     Optional[Any]=True					,lowercase__   :     Optional[int]=False					,lowercase__   :     Dict=1					,lowercase__   :     Any=5					,lowercase__   :     Optional[Any]=2					,lowercase__   :     Dict=1					,lowercase__   :     Tuple=1					,lowercase__   :     int=5					,lowercase__   :     Optional[int]=2					,lowercase__   :     List[str]=0.1					,**lowercase__   :     Union[str, Any]					,):
   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.'''			)
     __lowercase							  = CONFIG_MAPPING['''resnet'''](out_features=['''stage4''']			)
    elif isinstance(_UpperCamelCase					,_UpperCamelCase			):
     __lowercase							  = backbone_config.get('''model_type'''			)
     __lowercase							  = CONFIG_MAPPING[backbone_model_type]
     __lowercase							  = config_class.from_dict(_UpperCamelCase			)
    # set timm attributes to None
    __lowercase  ,	__lowercase  ,	__lowercase							  = None, None, None

   __lowercase							  = use_timm_backbone
   __lowercase							  = backbone_config
   __lowercase							  = num_channels
   __lowercase							  = num_queries
   __lowercase							  = d_model
   __lowercase							  = encoder_ffn_dim
   __lowercase							  = encoder_layers
   __lowercase							  = encoder_attention_heads
   __lowercase							  = decoder_ffn_dim
   __lowercase							  = decoder_layers
   __lowercase							  = decoder_attention_heads
   __lowercase							  = dropout
   __lowercase							  = attention_dropout
   __lowercase							  = activation_dropout
   __lowercase							  = activation_function
   __lowercase							  = init_std
   __lowercase							  = init_xavier_std
   __lowercase							  = encoder_layerdrop
   __lowercase							  = decoder_layerdrop
   __lowercase							  = encoder_layers
   __lowercase							  = auxiliary_loss
   __lowercase							  = position_embedding_type
   __lowercase							  = backbone
   __lowercase							  = use_pretrained_backbone
   __lowercase							  = dilation
   # Hungarian matcher
   __lowercase							  = class_cost
   __lowercase							  = bbox_cost
   __lowercase							  = giou_cost
   # Loss coefficients
   __lowercase							  = mask_loss_coefficient
   __lowercase							  = dice_loss_coefficient
   __lowercase							  = bbox_loss_coefficient
   __lowercase							  = giou_loss_coefficient
   __lowercase							  = eos_coefficient
   super().__init__(is_encoder_decoder=_UpperCamelCase					,**_UpperCamelCase			)






  @property
  def 					SCREAMING_SNAKE_CASE      (      self   :     str			):
   return self.encoder_attention_heads






  @property
  def 					SCREAMING_SNAKE_CASE      (      self   :     Dict			):
   return self.d_model






class 			lowercase_	(_lowerCamelCase      ):




  """simple docstring"""




  SCREAMING_SNAKE_CASE    :  str							=			version.parse('1.11'      )






  @property
  def 					SCREAMING_SNAKE_CASE      (      self   :     List[Any]			):
   return OrderedDict(
       [
           ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
           ('''pixel_mask''', {0: '''batch'''}),
       ]			)






  @property
  def 					SCREAMING_SNAKE_CASE      (      self   :     int			):
   return 1e-5






  @property
  def 					SCREAMING_SNAKE_CASE      (      self   :     Union[str, Any]			):
   return 1_2








import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bert import BertTokenizer


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

snake_case__					:							Union[str, Any]													=     {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

snake_case__					:							int													=     {
    'vocab_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/vocab.txt',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/vocab.txt',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt'
        ),
        'bert-base-multilingual-cased': 'https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt',
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt'
        ),
        'bert-base-german-dbmdz-cased': 'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt',
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'bert-base-uncased': 'https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json',
        'bert-large-uncased': 'https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json',
        'bert-base-cased': 'https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json',
        'bert-large-cased': 'https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json',
        'bert-base-multilingual-uncased': (
            'https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json'
        ),
        'bert-base-multilingual-cased': (
            'https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-chinese': 'https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json',
        'bert-base-german-cased': 'https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json',
        'bert-large-uncased-whole-word-masking': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking': (
            'https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json'
        ),
        'bert-large-uncased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-large-cased-whole-word-masking-finetuned-squad': (
            'https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json'
        ),
        'bert-base-cased-finetuned-mrpc': (
            'https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-cased': (
            'https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json'
        ),
        'bert-base-german-dbmdz-uncased': (
            'https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-cased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json'
        ),
        'TurkuNLP/bert-base-finnish-uncased-v1': (
            'https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json'
        ),
        'wietsedv/bert-base-dutch-cased': (
            'https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json'
        ),
    },
}

snake_case__					:							int													=     {
    'bert-base-uncased': 512,
    'bert-large-uncased': 512,
    'bert-base-cased': 512,
    'bert-large-cased': 512,
    'bert-base-multilingual-uncased': 512,
    'bert-base-multilingual-cased': 512,
    'bert-base-chinese': 512,
    'bert-base-german-cased': 512,
    'bert-large-uncased-whole-word-masking': 512,
    'bert-large-cased-whole-word-masking': 512,
    'bert-large-uncased-whole-word-masking-finetuned-squad': 512,
    'bert-large-cased-whole-word-masking-finetuned-squad': 512,
    'bert-base-cased-finetuned-mrpc': 512,
    'bert-base-german-dbmdz-cased': 512,
    'bert-base-german-dbmdz-uncased': 512,
    'TurkuNLP/bert-base-finnish-cased-v1': 512,
    'TurkuNLP/bert-base-finnish-uncased-v1': 512,
    'wietsedv/bert-base-dutch-cased': 512,
}

snake_case__					:							str													=     {
    'bert-base-uncased': {'do_lower_case': True},
    'bert-large-uncased': {'do_lower_case': True},
    'bert-base-cased': {'do_lower_case': False},
    'bert-large-cased': {'do_lower_case': False},
    'bert-base-multilingual-uncased': {'do_lower_case': True},
    'bert-base-multilingual-cased': {'do_lower_case': False},
    'bert-base-chinese': {'do_lower_case': False},
    'bert-base-german-cased': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking': {'do_lower_case': False},
    'bert-large-uncased-whole-word-masking-finetuned-squad': {'do_lower_case': True},
    'bert-large-cased-whole-word-masking-finetuned-squad': {'do_lower_case': False},
    'bert-base-cased-finetuned-mrpc': {'do_lower_case': False},
    'bert-base-german-dbmdz-cased': {'do_lower_case': False},
    'bert-base-german-dbmdz-uncased': {'do_lower_case': True},
    'TurkuNLP/bert-base-finnish-cased-v1': {'do_lower_case': False},
    'TurkuNLP/bert-base-finnish-uncased-v1': {'do_lower_case': True},
    'wietsedv/bert-base-dutch-cased': {'do_lower_case': False},
}





class A_					(			_lowerCamelCase   ):
   lowerCAmelCase__        = VOCAB_FILES_NAMES
   lowerCAmelCase__        = PRETRAINED_VOCAB_FILES_MAP
   lowerCAmelCase__        = PRETRAINED_INIT_CONFIGURATION
   lowerCAmelCase__        = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   lowerCAmelCase__        = BertTokenizer




   def __init__(self	:List[str]    ,   _UpperCamelCase	:List[str]=None    ,   _UpperCamelCase	:Optional[Any]=None    ,   _UpperCamelCase	:str=True    ,   _UpperCamelCase	:Optional[Any]="[UNK]"    ,   _UpperCamelCase	:Tuple="[SEP]"    ,   _UpperCamelCase	:List[Any]="[PAD]"    ,   _UpperCamelCase	:int="[CLS]"    ,   _UpperCamelCase	:Optional[int]="[MASK]"    ,   _UpperCamelCase	:Union[str, Any]=True    ,   _UpperCamelCase	:str=None    ,   **_UpperCamelCase	:List[str]    ,   )->					str:
         super().__init__(
             _UpperCamelCase    ,   tokenizer_file=_UpperCamelCase    ,   do_lower_case=_UpperCamelCase    ,   unk_token=_UpperCamelCase    ,   sep_token=_UpperCamelCase    ,   pad_token=_UpperCamelCase    ,   cls_token=_UpperCamelCase    ,   mask_token=_UpperCamelCase    ,   tokenize_chinese_chars=_UpperCamelCase    ,   strip_accents=_UpperCamelCase    ,   **_UpperCamelCase    ,   )

         __A          =				json.loads(self.backend_tokenizer.normalizer.__getstate__() )
         if (
             normalizer_state.get('''lowercase'''    ,   _UpperCamelCase ) != do_lower_case
             or normalizer_state.get('''strip_accents'''    ,   _UpperCamelCase ) != strip_accents
             or normalizer_state.get('''handle_chinese_chars'''    ,   _UpperCamelCase ) != tokenize_chinese_chars
         ):
               __A          =				getattr(_UpperCamelCase    ,   normalizer_state.pop('''type''' ) )
               __A          =				do_lower_case
               __A          =				strip_accents
               __A          =				tokenize_chinese_chars
               __A          =				normalizer_class(**_UpperCamelCase )

         __A          =				do_lower_case




   def _lowerCAmelCase      (self	:Any    ,   _UpperCamelCase	:int    ,   _UpperCamelCase	:List[str]=None )->					List[Any]:
         __A          =				[self.cls_token_id] + token_ids_a + [self.sep_token_id]

         if token_ids_a:
               output += token_ids_a + [self.sep_token_id]

         return output




   def _lowerCAmelCase      (self	:List[str]    ,   _UpperCamelCase	:List[int]    ,   _UpperCamelCase	:Optional[List[int]] = None )->					List[int]:
         __A          =				[self.sep_token_id]
         __A          =				[self.cls_token_id]
         if token_ids_a is None:
               return len(cls + token_ids_a + sep ) * [0]
         return len(cls + token_ids_a + sep ) * [0] + len(token_ids_a + sep ) * [1]






   def _lowerCAmelCase      (self	:Any    ,   _UpperCamelCase	:str    ,   _UpperCamelCase	:Optional[str] = None )->					Tuple[str]:
         __A          =				self._tokenizer.model.save(_UpperCamelCase    ,   name=_UpperCamelCase )
         return tuple(_UpperCamelCase )





