
"""simple docstring"""






import copy

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


__SCREAMING_SNAKE_CASE							=     logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							=     {
    'SenseTime/deformable-detr': 'https://huggingface.co/sensetime/deformable-detr/resolve/main/config.json',
    # See all Deformable DETR models at https://huggingface.co/models?filter=deformable-detr
}





class 				a__					(						A__       ):
     UpperCAmelCase__         =      '''deformable_detr'''
     UpperCAmelCase__         =      {
         '''hidden_size''': '''d_model''',
         '''num_attention_heads''': '''encoder_attention_heads''',
     }



     def __init__(							self :Union[str, Any]      ,  _lowerCamelCase :Tuple=True      ,  _lowerCamelCase :str=None      ,  _lowerCamelCase :Optional[int]=3      ,  _lowerCamelCase :Union[str, Any]=300      ,  _lowerCamelCase :Union[str, Any]=1_024      ,  _lowerCamelCase :Union[str, Any]=6      ,  _lowerCamelCase :str=1_024      ,  _lowerCamelCase :List[Any]=8      ,  _lowerCamelCase :int=6      ,  _lowerCamelCase :List[Any]=1_024      ,  _lowerCamelCase :Any=8      ,  _lowerCamelCase :List[Any]=0.0      ,  _lowerCamelCase :Any=True      ,  _lowerCamelCase :Union[str, Any]="relu"      ,  _lowerCamelCase :str=256      ,  _lowerCamelCase :Union[str, Any]=0.1      ,  _lowerCamelCase :Tuple=0.0      ,  _lowerCamelCase :Union[str, Any]=0.0      ,  _lowerCamelCase :Dict=0.02      ,  _lowerCamelCase :Union[str, Any]=1.0      ,  _lowerCamelCase :int=True      ,  _lowerCamelCase :List[str]=False      ,  _lowerCamelCase :Optional[int]="sine"      ,  _lowerCamelCase :int="resnet50"      ,  _lowerCamelCase :Any=True      ,  _lowerCamelCase :Tuple=False      ,  _lowerCamelCase :int=4      ,  _lowerCamelCase :List[str]=4      ,  _lowerCamelCase :List[str]=4      ,  _lowerCamelCase :List[Any]=False      ,  _lowerCamelCase :Union[str, Any]=300      ,  _lowerCamelCase :Dict=False      ,  _lowerCamelCase :Tuple=1      ,  _lowerCamelCase :Union[str, Any]=5      ,  _lowerCamelCase :Optional[Any]=2      ,  _lowerCamelCase :int=1      ,  _lowerCamelCase :List[Any]=1      ,  _lowerCamelCase :Optional[int]=5      ,  _lowerCamelCase :int=2      ,  _lowerCamelCase :str=0.1      ,  _lowerCamelCase :Union[str, Any]=0.25      ,  _lowerCamelCase :str=False      ,  **_lowerCamelCase :Union[str, Any]      ,  ):







      '''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.'   )
        UpperCamelCase_     :					Optional[Any]   	=CONFIG_MAPPING['resnet'](out_features=['stage4']   )
       elif isinstance(_lowerCamelCase      ,  _lowerCamelCase   ):
        UpperCamelCase_     :					Optional[Any]   	=backbone_config.get('model_type'   )
        UpperCamelCase_     :					int   	=CONFIG_MAPPING[backbone_model_type]
        UpperCamelCase_     :					Dict   	=config_class.from_dict(_lowerCamelCase   )
      UpperCamelCase_     :					Optional[int]   	=use_timm_backbone
      UpperCamelCase_     :					Any   	=backbone_config
      UpperCamelCase_     :					str   	=num_channels
      UpperCamelCase_     :					Tuple   	=num_queries
      UpperCamelCase_     :					Tuple   	=max_position_embeddings
      UpperCamelCase_     :					Dict   	=d_model
      UpperCamelCase_     :					List[Any]   	=encoder_ffn_dim
      UpperCamelCase_     :					Tuple   	=encoder_layers
      UpperCamelCase_     :					Optional[Any]   	=encoder_attention_heads
      UpperCamelCase_     :					Optional[Any]   	=decoder_ffn_dim
      UpperCamelCase_     :					List[Any]   	=decoder_layers
      UpperCamelCase_     :					List[Any]   	=decoder_attention_heads
      UpperCamelCase_     :					Dict   	=dropout
      UpperCamelCase_     :					List[Any]   	=attention_dropout
      UpperCamelCase_     :					Tuple   	=activation_dropout
      UpperCamelCase_     :					str   	=activation_function
      UpperCamelCase_     :					str   	=init_std
      UpperCamelCase_     :					List[Any]   	=init_xavier_std
      UpperCamelCase_     :					Dict   	=encoder_layerdrop
      UpperCamelCase_     :					Union[str, Any]   	=auxiliary_loss
      UpperCamelCase_     :					Dict   	=position_embedding_type
      UpperCamelCase_     :					Union[str, Any]   	=backbone
      UpperCamelCase_     :					str   	=use_pretrained_backbone
      UpperCamelCase_     :					Any   	=dilation
      # deformable attributes
      UpperCamelCase_     :					Optional[int]   	=num_feature_levels
      UpperCamelCase_     :					int   	=encoder_n_points
      UpperCamelCase_     :					Union[str, Any]   	=decoder_n_points
      UpperCamelCase_     :					Optional[int]   	=two_stage
      UpperCamelCase_     :					Tuple   	=two_stage_num_proposals
      UpperCamelCase_     :					List[Any]   	=with_box_refine
      if two_stage is True and with_box_refine is False:
       raise ValueError('If two_stage is True, with_box_refine must be True.'   )
      # Hungarian matcher
      UpperCamelCase_     :					Dict   	=class_cost
      UpperCamelCase_     :					Any   	=bbox_cost
      UpperCamelCase_     :					List[Any]   	=giou_cost
      # Loss coefficients
      UpperCamelCase_     :					Optional[Any]   	=mask_loss_coefficient
      UpperCamelCase_     :					Tuple   	=dice_loss_coefficient
      UpperCamelCase_     :					Optional[int]   	=bbox_loss_coefficient
      UpperCamelCase_     :					Tuple   	=giou_loss_coefficient
      UpperCamelCase_     :					Any   	=eos_coefficient
      UpperCamelCase_     :					List[Any]   	=focal_alpha
      UpperCamelCase_     :					List[Any]   	=disable_custom_kernels
      super().__init__(is_encoder_decoder=_lowerCamelCase      ,  **_lowerCamelCase   )



     @property
     def  lowerCamelCase_						(							self :Optional[Any]   ):







      '''simple docstring'''



      return self.encoder_attention_heads



     @property
     def  lowerCamelCase_						(							self :Optional[int]   ):







      '''simple docstring'''



      return self.d_model




     def  lowerCamelCase_						(							self :Tuple   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	=copy.deepcopy(self.__dict__   )
      if self.backbone_config is not None:
       UpperCamelCase_     :					Any   	=self.backbone_config.to_dict()
      UpperCamelCase_     :					Tuple   	=self.__class__.model_type
      return output


"""simple docstring"""






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers
from tokenizers.pre_tokenizers import BertPreTokenizer, PreTokenizer

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_roformer import RoFormerTokenizer
from .tokenization_utils import JiebaPreTokenizer


__SCREAMING_SNAKE_CASE							=     logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							=     {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

__SCREAMING_SNAKE_CASE							=     {
    'vocab_file': {
        'junnyu/roformer_chinese_small': 'https://huggingface.co/junnyu/roformer_chinese_small/resolve/main/vocab.txt',
        'junnyu/roformer_chinese_base': 'https://huggingface.co/junnyu/roformer_chinese_base/resolve/main/vocab.txt',
        'junnyu/roformer_chinese_char_small': (
            'https://huggingface.co/junnyu/roformer_chinese_char_small/resolve/main/vocab.txt'
        ),
        'junnyu/roformer_chinese_char_base': (
            'https://huggingface.co/junnyu/roformer_chinese_char_base/resolve/main/vocab.txt'
        ),
        'junnyu/roformer_small_discriminator': (
            'https://huggingface.co/junnyu/roformer_small_discriminator/resolve/main/vocab.txt'
        ),
        'junnyu/roformer_small_generator': (
            'https://huggingface.co/junnyu/roformer_small_generator/resolve/main/vocab.txt'
        ),
    }
}

__SCREAMING_SNAKE_CASE							=     {
    'junnyu/roformer_chinese_small': 1_536,
    'junnyu/roformer_chinese_base': 1_536,
    'junnyu/roformer_chinese_char_small': 512,
    'junnyu/roformer_chinese_char_base': 512,
    'junnyu/roformer_small_discriminator': 128,
    'junnyu/roformer_small_generator': 128,
}


__SCREAMING_SNAKE_CASE							=     {
    'junnyu/roformer_chinese_small': {'do_lower_case': True},
    'junnyu/roformer_chinese_base': {'do_lower_case': True},
    'junnyu/roformer_chinese_char_small': {'do_lower_case': True},
    'junnyu/roformer_chinese_char_base': {'do_lower_case': True},
    'junnyu/roformer_small_discriminator': {'do_lower_case': True},
    'junnyu/roformer_small_generator': {'do_lower_case': True},
}





class 				a__					(						A__       ):
     UpperCAmelCase__         =      VOCAB_FILES_NAMES
     UpperCAmelCase__         =      PRETRAINED_VOCAB_FILES_MAP
     UpperCAmelCase__         =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     UpperCAmelCase__         =      PRETRAINED_INIT_CONFIGURATION
     UpperCAmelCase__         =      RoFormerTokenizer



     def __init__(							self :Tuple      ,  _lowerCamelCase :Dict=None      ,  _lowerCamelCase :Dict=None      ,  _lowerCamelCase :List[Any]=True      ,  _lowerCamelCase :Dict="[UNK]"      ,  _lowerCamelCase :List[str]="[SEP]"      ,  _lowerCamelCase :str="[PAD]"      ,  _lowerCamelCase :Optional[Any]="[CLS]"      ,  _lowerCamelCase :Optional[int]="[MASK]"      ,  _lowerCamelCase :str=True      ,  _lowerCamelCase :Tuple=None      ,  **_lowerCamelCase :Any      ,  ):







      '''simple docstring'''



      super().__init__(
          _lowerCamelCase      ,  tokenizer_file=_lowerCamelCase      ,  do_lower_case=_lowerCamelCase      ,  unk_token=_lowerCamelCase      ,  sep_token=_lowerCamelCase      ,  pad_token=_lowerCamelCase      ,  cls_token=_lowerCamelCase      ,  mask_token=_lowerCamelCase      ,  tokenize_chinese_chars=_lowerCamelCase      ,  strip_accents=_lowerCamelCase      ,  **_lowerCamelCase      ,  )

      UpperCamelCase_     :					Any   	=json.loads(self.backend_tokenizer.normalizer.__getstate__()   )
      if (
          pre_tok_state.get('lowercase'      ,  _lowerCamelCase   ) != do_lower_case
          or pre_tok_state.get('strip_accents'      ,  _lowerCamelCase   ) != strip_accents
      ):
       UpperCamelCase_     :					Optional[Any]   	=getattr(_lowerCamelCase      ,  pre_tok_state.pop('type'   )   )
       UpperCamelCase_     :					Tuple   	=do_lower_case
       UpperCamelCase_     :					Union[str, Any]   	=strip_accents
       UpperCamelCase_     :					Union[str, Any]   	=pre_tok_class(**_lowerCamelCase   )

      UpperCamelCase_     :					List[str]   	=do_lower_case



     def __getstate__(							self :Any   ):







      '''simple docstring'''



      UpperCamelCase_     :					str   	=self.__dict__.copy()
      UpperCamelCase_     :					Union[str, Any]   	=BertPreTokenizer()
      return state



     def __setstate__(							self :str      ,  _lowerCamelCase :Optional[Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					int   	=d
      UpperCamelCase_     :					Optional[int]   	=self.__dict__['_tokenizer'].get_vocab()
      UpperCamelCase_     :					Any   	=PreTokenizer.custom(JiebaPreTokenizer(_lowerCamelCase   )   )



     def  lowerCamelCase_						(							self :Dict      ,  _lowerCamelCase :Optional[Any]      ,  _lowerCamelCase :Any=None   ):







      '''simple docstring'''



      UpperCamelCase_     :					int   	=[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 :Union[str, Any]      ,  _lowerCamelCase :List[int]      ,  _lowerCamelCase :Optional[List[int]] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	=[self.sep_token_id]
      UpperCamelCase_     :					List[Any]   	=[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 :Optional[int]      ,  _lowerCamelCase :str      ,  _lowerCamelCase :Optional[str] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	=self._tokenizer.model.save(_lowerCamelCase      ,  name=_lowerCamelCase   )
      return tuple(_lowerCamelCase   )




     def  lowerCamelCase_						(							self :str      ,  _lowerCamelCase :List[str]      ,  _lowerCamelCase :List[Any]=None      ,  _lowerCamelCase :Optional[Any]=None      ,  _lowerCamelCase :int=False      ,  **_lowerCamelCase :Optional[int]      ,  ):







      '''simple docstring'''



      UpperCamelCase_     :					str   	=BertPreTokenizer()
      return super().save_pretrained(_lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  **_lowerCamelCase   )
