






"""simple docstring"""


import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


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

UpperCAmelCase__  		=						{
    '''vocab_file''': {
        '''unc-nlp/lxmert-base-uncased''': '''https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt''',
    },
    '''tokenizer_file''': {
        '''unc-nlp/lxmert-base-uncased''': (
            '''https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json'''
        ),
    },
}

UpperCAmelCase__  		=						{
    '''unc-nlp/lxmert-base-uncased''': 5_1_2,
}

UpperCAmelCase__  		=						{
    '''unc-nlp/lxmert-base-uncased''': {'''do_lower_case''': True},
}


class        a				(		lowerCAmelCase_   ):
    _snake_case     :  Optional[int]     							=							VOCAB_FILES_NAMES
    _snake_case     :  int     							=							PRETRAINED_VOCAB_FILES_MAP
    _snake_case     :  Tuple     							=							PRETRAINED_INIT_CONFIGURATION
    _snake_case     :  Union[str, Any]     							=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    _snake_case     :  Any     							=							LxmertTokenizer


    def __init__(					self	:  int   ,				__lowerCAmelCase	:  Optional[Any]=None   ,				__lowerCAmelCase	:  Any=None   ,				__lowerCAmelCase	:  List[Any]=True   ,				__lowerCAmelCase	:  str="[UNK]"   ,				__lowerCAmelCase	:  Optional[Any]="[SEP]"   ,				__lowerCAmelCase	:  List[str]="[PAD]"   ,				__lowerCAmelCase	:  int="[CLS]"   ,				__lowerCAmelCase	:  List[Any]="[MASK]"   ,				__lowerCAmelCase	:  List[Any]=True   ,				__lowerCAmelCase	:  Optional[int]=None   ,				**__lowerCAmelCase	:  Optional[Any]   ,				):
      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_   ,				)

      _UpperCAmelCase						 =      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
      ):
        _UpperCAmelCase						 =      getattr(UpperCamelCase_   ,				normalizer_state.pop("""type"""					)					)
        _UpperCAmelCase						 =      do_lower_case
        _UpperCAmelCase						 =      strip_accents
        _UpperCAmelCase						 =      tokenize_chinese_chars
        _UpperCAmelCase						 =      normalizer_class(**UpperCamelCase_					)

      _UpperCAmelCase						 =      do_lower_case


    def      lowerCAmelCase_  (					self	:  List[str]   ,				__lowerCAmelCase	:  Union[str, Any]   ,				__lowerCAmelCase	:  Dict=None					):
      _UpperCAmelCase						 =      [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	:  Any   ,				__lowerCAmelCase	:  List[int]   ,				__lowerCAmelCase	:  Optional[List[int]] = None					):
      _UpperCAmelCase						 =      [self.sep_token_id]
      _UpperCAmelCase						 =      [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	:  Dict   ,				__lowerCAmelCase	:  str   ,				__lowerCAmelCase	:  Optional[str] = None					):
      _UpperCAmelCase						 =      self._tokenizer.model.save(UpperCamelCase_   ,				name=UpperCamelCase_					)
      return tuple(UpperCamelCase_					)

"""simple docstring"""


from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


UpperCAmelCase__  		=						logging.get_logger(__name__)

UpperCAmelCase__  		=						{
    """shi-labs/nat-mini-in1k-224""": """https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json""",
    # See all Nat models at https://huggingface.co/models?filter=nat
}


class        a				(		lowerCAmelCase_	,							lowerCAmelCase_   ):
    _snake_case     :  Union[str, Any]     							=							'nat'

    _snake_case     :  List[str]     							=							{
        'num_attention_heads': 'num_heads',
        'num_hidden_layers': 'num_layers',
    }


    def __init__(					self	:  List[Any]   ,				__lowerCAmelCase	:  int=4   ,				__lowerCAmelCase	:  Union[str, Any]=3   ,				__lowerCAmelCase	:  Dict=64   ,				__lowerCAmelCase	:  int=[3, 4, 6, 5]   ,				__lowerCAmelCase	:  List[str]=[2, 4, 8, 16]   ,				__lowerCAmelCase	:  Tuple=7   ,				__lowerCAmelCase	:  List[str]=3.0   ,				__lowerCAmelCase	:  int=True   ,				__lowerCAmelCase	:  int=0.0   ,				__lowerCAmelCase	:  Tuple=0.0   ,				__lowerCAmelCase	:  Any=0.1   ,				__lowerCAmelCase	:  List[str]="gelu"   ,				__lowerCAmelCase	:  List[Any]=0.02   ,				__lowerCAmelCase	:  Union[str, Any]=1e-5   ,				__lowerCAmelCase	:  List[Any]=0.0   ,				__lowerCAmelCase	:  Tuple=None   ,				__lowerCAmelCase	:  Optional[int]=None   ,				**__lowerCAmelCase	:  Optional[Any]   ,				):
      super().__init__(**__lowerCAmelCase					)

      _UpperCAmelCase						 =      patch_size
      _UpperCAmelCase						 =      num_channels
      _UpperCAmelCase						 =      embed_dim
      _UpperCAmelCase						 =      depths
      _UpperCAmelCase						 =      len(__lowerCAmelCase					)
      _UpperCAmelCase						 =      num_heads
      _UpperCAmelCase						 =      kernel_size
      _UpperCAmelCase						 =      mlp_ratio
      _UpperCAmelCase						 =      qkv_bias
      _UpperCAmelCase						 =      hidden_dropout_prob
      _UpperCAmelCase						 =      attention_probs_dropout_prob
      _UpperCAmelCase						 =      drop_path_rate
      _UpperCAmelCase						 =      hidden_act
      _UpperCAmelCase						 =      layer_norm_eps
      _UpperCAmelCase						 =      initializer_range
      # we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
      # this indicates the channel dimension after the last stage of the model
      _UpperCAmelCase						 =      int(embed_dim * 2 ** (len(__lowerCAmelCase					) - 1)					)
      _UpperCAmelCase						 =      layer_scale_init_value
      _UpperCAmelCase						 =      ["""stem"""] + [f'''stage{idx}''' for idx in range(1   ,				len(__lowerCAmelCase					) + 1					)]
      _UpperCAmelCase ,				_UpperCAmelCase						 =      get_aligned_output_features_output_indices(
          out_features=__lowerCAmelCase   ,				out_indices=__lowerCAmelCase   ,				stage_names=self.stage_names					)
