


'''simple docstring'''






import os
import unittest

from transformers import MobileBertTokenizer, MobileBertTokenizerFast
from transformers.models.bert.tokenization_bert import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english






@require_tokenizers
class        __snake_case	(       _SCREAMING_SNAKE_CASE     ,unittest.TestCase):







    """simple docstring"""



    lowercase       			= MobileBertTokenizer
    lowercase       			= MobileBertTokenizerFast
    lowercase       			= True
    lowercase       			= True
    lowercase       			= filter_non_english
    lowercase       			= 'google/mobilebert-uncased'

    def __lowercase       (       self   :  Any		)       ->  List[str]:
      super().setUp()

      lowerCAmelCase_      :				List[Any]      =       [
          """[UNK]""",
          """[CLS]""",
          """[SEP]""",
          """[PAD]""",
          """[MASK]""",
          """want""",
          """##want""",
          """##ed""",
          """wa""",
          """un""",
          """runn""",
          """##ing""",
          """,""",
          """low""",
          """lowest""",
      ]
      lowerCAmelCase_      :				Tuple      =       os.path.join(self.tmpdirname   ,						VOCAB_FILES_NAMES["""vocab_file"""]		)
      with open(self.vocab_file   ,						"""w"""   ,						encoding="""utf-8"""		) as vocab_writer:
        vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]		)		)

      lowerCAmelCase_      :				Any      =       [
          (tokenizer_def[0], self.pre_trained_model_path, tokenizer_def[2])  # else the 'google/' prefix is stripped
          for tokenizer_def in self.tokenizers_list
      ]

    def __lowercase       (       self   :  Union[str, Any]   ,						lowerCamelCase   :  Any		)       ->  Optional[int]:
      lowerCAmelCase_      :				int      =       """UNwant\u00E9d,running"""
      lowerCAmelCase_      :				str      =       """unwanted, running"""
      return input_text, output_text

    def __lowercase       (       self   :  Optional[int]		)       ->  Tuple:
      lowerCAmelCase_      :				int      =       self.tokenizer_class(self.vocab_file		)

      lowerCAmelCase_      :				List[str]      =       tokenizer.tokenize("""UNwant\u00E9d,running"""		)
      self.assertListEqual(lowerCamelCase   ,						["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]		)
      self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase		)   ,						[9, 6, 7, 12, 10, 11]		)

    def __lowercase       (       self   :  Optional[int]		)       ->  Any:
      if not self.test_rust_tokenizer:
        return

      lowerCAmelCase_      :				Tuple      =       self.get_tokenizer()
      lowerCAmelCase_      :				Union[str, Any]      =       self.get_rust_tokenizer()

      lowerCAmelCase_      :				int      =       """UNwant\u00E9d,running"""

      lowerCAmelCase_      :				Optional[Any]      =       tokenizer.tokenize(lowerCamelCase		)
      lowerCAmelCase_      :				Optional[Any]      =       rust_tokenizer.tokenize(lowerCamelCase		)
      self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)

      lowerCAmelCase_      :				Optional[int]      =       tokenizer.encode(lowerCamelCase   ,						add_special_tokens=lowerCamelCase		)
      lowerCAmelCase_      :				Dict      =       rust_tokenizer.encode(lowerCamelCase   ,						add_special_tokens=lowerCamelCase		)
      self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)

      lowerCAmelCase_      :				Any      =       self.get_rust_tokenizer()
      lowerCAmelCase_      :				Tuple      =       tokenizer.encode(lowerCamelCase		)
      lowerCAmelCase_      :				Tuple      =       rust_tokenizer.encode(lowerCamelCase		)
      self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)

      # With lower casing
      lowerCAmelCase_      :				List[str]      =       self.get_tokenizer(do_lower_case=lowerCamelCase		)
      lowerCAmelCase_      :				List[str]      =       self.get_rust_tokenizer(do_lower_case=lowerCamelCase		)

      lowerCAmelCase_      :				Union[str, Any]      =       """UNwant\u00E9d,running"""

      lowerCAmelCase_      :				Dict      =       tokenizer.tokenize(lowerCamelCase		)
      lowerCAmelCase_      :				Union[str, Any]      =       rust_tokenizer.tokenize(lowerCamelCase		)
      self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)

      lowerCAmelCase_      :				int      =       tokenizer.encode(lowerCamelCase   ,						add_special_tokens=lowerCamelCase		)
      lowerCAmelCase_      :				Dict      =       rust_tokenizer.encode(lowerCamelCase   ,						add_special_tokens=lowerCamelCase		)
      self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)

      lowerCAmelCase_      :				int      =       self.get_rust_tokenizer()
      lowerCAmelCase_      :				Any      =       tokenizer.encode(lowerCamelCase		)
      lowerCAmelCase_      :				Union[str, Any]      =       rust_tokenizer.encode(lowerCamelCase		)
      self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)

    def __lowercase       (       self   :  Optional[int]		)       ->  Tuple:
      lowerCAmelCase_      :				Optional[Any]      =       BasicTokenizer()

      self.assertListEqual(tokenizer.tokenize("""ah\u535A\u63A8zz"""		)   ,						["""ah""", """\u535A""", """\u63A8""", """zz"""]		)

    def __lowercase       (       self   :  int		)       ->  Union[str, Any]:
      lowerCAmelCase_      :				Optional[Any]      =       BasicTokenizer(do_lower_case=lowerCamelCase		)

      self.assertListEqual(
          tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """		)   ,						["""hello""", """!""", """how""", """are""", """you""", """?"""]		)
      self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""		)   ,						["""hello"""]		)

    def __lowercase       (       self   :  Any		)       ->  List[Any]:
      lowerCAmelCase_      :				int      =       BasicTokenizer(do_lower_case=lowerCamelCase   ,						strip_accents=lowerCamelCase		)

      self.assertListEqual(
          tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """		)   ,						["""hällo""", """!""", """how""", """are""", """you""", """?"""]		)
      self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""		)   ,						["""h\u00E9llo"""]		)

    def __lowercase       (       self   :  int		)       ->  str:
      lowerCAmelCase_      :				Union[str, Any]      =       BasicTokenizer(do_lower_case=lowerCamelCase   ,						strip_accents=lowerCamelCase		)

      self.assertListEqual(
          tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """		)   ,						["""hallo""", """!""", """how""", """are""", """you""", """?"""]		)
      self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""		)   ,						["""hello"""]		)

    def __lowercase       (       self   :  Optional[int]		)       ->  Optional[Any]:
      lowerCAmelCase_      :				Optional[int]      =       BasicTokenizer(do_lower_case=lowerCamelCase		)

      self.assertListEqual(
          tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """		)   ,						["""hallo""", """!""", """how""", """are""", """you""", """?"""]		)
      self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""		)   ,						["""hello"""]		)

    def __lowercase       (       self   :  List[str]		)       ->  int:
      lowerCAmelCase_      :				List[Any]      =       BasicTokenizer(do_lower_case=lowerCamelCase		)

      self.assertListEqual(
          tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """		)   ,						["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?"""]		)

    def __lowercase       (       self   :  Optional[int]		)       ->  List[Any]:
      lowerCAmelCase_      :				Dict      =       BasicTokenizer(do_lower_case=lowerCamelCase   ,						strip_accents=lowerCamelCase		)

      self.assertListEqual(
          tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """		)   ,						["""HäLLo""", """!""", """how""", """Are""", """yoU""", """?"""]		)

    def __lowercase       (       self   :  Dict		)       ->  Optional[Any]:
      lowerCAmelCase_      :				List[str]      =       BasicTokenizer(do_lower_case=lowerCamelCase   ,						strip_accents=lowerCamelCase		)

      self.assertListEqual(
          tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """		)   ,						["""HaLLo""", """!""", """how""", """Are""", """yoU""", """?"""]		)

    def __lowercase       (       self   :  Optional[Any]		)       ->  List[str]:
      lowerCAmelCase_      :				Any      =       BasicTokenizer(do_lower_case=lowerCamelCase   ,						never_split=["""[UNK]"""]		)

      self.assertListEqual(
          tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU? [UNK]"""		)   ,						["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?""", """[UNK]"""]		)

    def __lowercase       (       self   :  Optional[Any]		)       ->  int:
      lowerCAmelCase_      :				List[str]      =       ["""[UNK]""", """[CLS]""", """[SEP]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing"""]

      lowerCAmelCase_      :				List[Any]      =       {}
      for i, token in enumerate(lowerCamelCase		):
        lowerCAmelCase_      :				int      =       i
      lowerCAmelCase_      :				List[str]      =       WordpieceTokenizer(vocab=lowerCamelCase   ,						unk_token="""[UNK]"""		)

      self.assertListEqual(tokenizer.tokenize(""""""		)   ,						[]		)

      self.assertListEqual(tokenizer.tokenize("""unwanted running"""		)   ,						["""un""", """##want""", """##ed""", """runn""", """##ing"""]		)

      self.assertListEqual(tokenizer.tokenize("""unwantedX running"""		)   ,						["""[UNK]""", """runn""", """##ing"""]		)

    def __lowercase       (       self   :  List[Any]		)       ->  Any:
      self.assertTrue(_is_whitespace(""" """		)		)
      self.assertTrue(_is_whitespace("""\t"""		)		)
      self.assertTrue(_is_whitespace("""\r"""		)		)
      self.assertTrue(_is_whitespace("""\n"""		)		)
      self.assertTrue(_is_whitespace("""\u00A0"""		)		)

      self.assertFalse(_is_whitespace("""A"""		)		)
      self.assertFalse(_is_whitespace("""-"""		)		)

    def __lowercase       (       self   :  Optional[Any]		)       ->  List[Any]:
      self.assertTrue(_is_control("""\u0005"""		)		)

      self.assertFalse(_is_control("""A"""		)		)
      self.assertFalse(_is_control(""" """		)		)
      self.assertFalse(_is_control("""\t"""		)		)
      self.assertFalse(_is_control("""\r"""		)		)

    def __lowercase       (       self   :  Tuple		)       ->  List[str]:
      self.assertTrue(_is_punctuation("""-"""		)		)
      self.assertTrue(_is_punctuation("""$"""		)		)
      self.assertTrue(_is_punctuation("""`"""		)		)
      self.assertTrue(_is_punctuation("""."""		)		)

      self.assertFalse(_is_punctuation("""A"""		)		)
      self.assertFalse(_is_punctuation(""" """		)		)

    def __lowercase       (       self   :  Tuple		)       ->  int:
      lowerCAmelCase_      :				int      =       self.get_tokenizer()
      lowerCAmelCase_      :				Optional[Any]      =       self.get_rust_tokenizer()

      # Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
      self.assertListEqual([tokenizer.tokenize(lowerCamelCase		) for t in ["""Test""", """\xad""", """test"""]]   ,						[["""[UNK]"""], [], ["""[UNK]"""]]		)

      self.assertListEqual(
          [rust_tokenizer.tokenize(lowerCamelCase		) for t in ["""Test""", """\xad""", """test"""]]   ,						[["""[UNK]"""], [], ["""[UNK]"""]]		)

    @slow
    def __lowercase       (       self   :  Dict		)       ->  str:
      lowerCAmelCase_      :				str      =       self.tokenizer_class.from_pretrained("""google/mobilebert-uncased"""		)

      lowerCAmelCase_      :				Dict      =       tokenizer.encode("""sequence builders"""   ,						add_special_tokens=lowerCamelCase		)
      lowerCAmelCase_      :				List[str]      =       tokenizer.encode("""multi-sequence build"""   ,						add_special_tokens=lowerCamelCase		)

      lowerCAmelCase_      :				Dict      =       tokenizer.build_inputs_with_special_tokens(lowerCamelCase		)
      lowerCAmelCase_      :				Union[str, Any]      =       tokenizer.build_inputs_with_special_tokens(lowerCamelCase   ,						lowerCamelCase		)

      assert encoded_sentence == [1_01] + text + [1_02]
      assert encoded_pair == [1_01] + text + [1_02] + text_a + [1_02]

    def __lowercase       (       self   :  List[Any]		)       ->  Dict:
      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
        with self.subTest(F'{tokenizer.__class__.__name__} ({pretrained_name})'		):
          lowerCAmelCase_      :				Union[str, Any]      =       self.rust_tokenizer_class.from_pretrained(lowerCamelCase   ,						**lowerCamelCase		)

          lowerCAmelCase_      :				Any      =       F'A, naïve {tokenizer_r.mask_token} AllenNLP sentence.'
          lowerCAmelCase_      :				Optional[Any]      =       tokenizer_r.encode_plus(
              lowerCamelCase   ,						return_attention_mask=lowerCamelCase   ,						return_token_type_ids=lowerCamelCase   ,						return_offsets_mapping=lowerCamelCase   ,						add_special_tokens=lowerCamelCase   ,						)

          lowerCAmelCase_      :				str      =       tokenizer_r.do_lower_case if hasattr(lowerCamelCase   ,						"""do_lower_case"""		) else False
          lowerCAmelCase_      :				Optional[Any]      =       (
              [
                  ((0, 0), tokenizer_r.cls_token),
                  ((0, 1), """A"""),
                  ((1, 2), ""","""),
                  ((3, 5), """na"""),
                  ((5, 6), """##ï"""),
                  ((6, 8), """##ve"""),
                  ((9, 15), tokenizer_r.mask_token),
                  ((16, 21), """Allen"""),
                  ((21, 23), """##NL"""),
                  ((23, 24), """##P"""),
                  ((25, 33), """sentence"""),
                  ((33, 34), """."""),
                  ((0, 0), tokenizer_r.sep_token),
              ]
              if not do_lower_case
              else [
                  ((0, 0), tokenizer_r.cls_token),
                  ((0, 1), """a"""),
                  ((1, 2), ""","""),
                  ((3, 8), """naive"""),
                  ((9, 15), tokenizer_r.mask_token),
                  ((16, 21), """allen"""),
                  ((21, 23), """##nl"""),
                  ((23, 24), """##p"""),
                  ((25, 33), """sentence"""),
                  ((33, 34), """."""),
                  ((0, 0), tokenizer_r.sep_token),
              ]
          )

          self.assertEqual(
              [e[1] for e in expected_results]   ,						tokenizer_r.convert_ids_to_tokens(tokens["""input_ids"""]		)		)
          self.assertEqual([e[0] for e in expected_results]   ,						tokens["""offset_mapping"""]		)





    def __lowercase       (       self   :  int		)       ->  Tuple:
      lowerCAmelCase_      :				Tuple      =       ["""的""", """人""", """有"""]
      lowerCAmelCase_      :				List[Any]      =       """""".join(lowerCamelCase		)
      for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
        with self.subTest(F'{tokenizer.__class__.__name__} ({pretrained_name})'		):
          lowerCAmelCase_      :				Tuple      =       True
          lowerCAmelCase_      :				Optional[int]      =       self.tokenizer_class.from_pretrained(lowerCamelCase   ,						**lowerCamelCase		)
          lowerCAmelCase_      :				Dict      =       self.rust_tokenizer_class.from_pretrained(lowerCamelCase   ,						**lowerCamelCase		)

          lowerCAmelCase_      :				str      =       tokenizer_p.encode(lowerCamelCase   ,						add_special_tokens=lowerCamelCase		)
          lowerCAmelCase_      :				Dict      =       tokenizer_r.encode(lowerCamelCase   ,						add_special_tokens=lowerCamelCase		)

          lowerCAmelCase_      :				str      =       tokenizer_r.convert_ids_to_tokens(lowerCamelCase		)
          lowerCAmelCase_      :				int      =       tokenizer_p.convert_ids_to_tokens(lowerCamelCase		)

          # it is expected that each Chinese character is not preceded by "##"
          self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)
          self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)

          lowerCAmelCase_      :				Optional[Any]      =       False
          lowerCAmelCase_      :				List[str]      =       self.rust_tokenizer_class.from_pretrained(lowerCamelCase   ,						**lowerCamelCase		)
          lowerCAmelCase_      :				List[Any]      =       self.tokenizer_class.from_pretrained(lowerCamelCase   ,						**lowerCamelCase		)

          lowerCAmelCase_      :				str      =       tokenizer_r.encode(lowerCamelCase   ,						add_special_tokens=lowerCamelCase		)
          lowerCAmelCase_      :				Optional[int]      =       tokenizer_p.encode(lowerCamelCase   ,						add_special_tokens=lowerCamelCase		)

          lowerCAmelCase_      :				List[Any]      =       tokenizer_r.convert_ids_to_tokens(lowerCamelCase		)
          lowerCAmelCase_      :				Union[str, Any]      =       tokenizer_p.convert_ids_to_tokens(lowerCamelCase		)

          # it is expected that only the first Chinese character is not preceded by "##".
          lowerCAmelCase_      :				List[str]      =       [
              F'##{token}' if idx != 0 else token for idx, token in enumerate(lowerCamelCase		)
          ]
          self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)
          self.assertListEqual(lowerCamelCase   ,						lowerCamelCase		)







'''simple docstring'''






from typing import List

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


__A :  Dict    							=				logging.get_logger(__name__)

__A :  int    							=				{
    "snap-research/efficientformer-l1-300": (
        "https://huggingface.co/snap-research/efficientformer-l1-300/resolve/main/config.json"
    ),
}






class        __snake_case	(       _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    lowercase       			= 'efficientformer'

    def __init__(       self   :  Any   ,						lowerCamelCase   :  List[int] = [3, 2, 6, 4]   ,						lowerCamelCase   :  List[int] = [48, 96, 2_24, 4_48]   ,						lowerCamelCase   :  List[bool] = [True, True, True, True]   ,						lowerCamelCase   :  int = 4_48   ,						lowerCamelCase   :  int = 32   ,						lowerCamelCase   :  int = 4   ,						lowerCamelCase   :  int = 7   ,						lowerCamelCase   :  int = 5   ,						lowerCamelCase   :  int = 8   ,						lowerCamelCase   :  int = 4   ,						lowerCamelCase   :  float = 0.0   ,						lowerCamelCase   :  int = 16   ,						lowerCamelCase   :  int = 3   ,						lowerCamelCase   :  int = 3   ,						lowerCamelCase   :  int = 3   ,						lowerCamelCase   :  int = 2   ,						lowerCamelCase   :  int = 1   ,						lowerCamelCase   :  float = 0.0   ,						lowerCamelCase   :  int = 1   ,						lowerCamelCase   :  bool = True   ,						lowerCamelCase   :  bool = True   ,						lowerCamelCase   :  float = 1E-5   ,						lowerCamelCase   :  str = "gelu"   ,						lowerCamelCase   :  float = 0.02   ,						lowerCamelCase   :  float = 1E-12   ,						lowerCamelCase   :  int = 2_24   ,						lowerCamelCase   :  float = 1E-05   ,						**lowerCamelCase   :  int   ,						)       ->  None:
      super().__init__(**lowerCamelCase		)

      lowerCAmelCase_      :				List[str]      =       hidden_act
      lowerCAmelCase_      :				List[Any]      =       hidden_dropout_prob
      lowerCAmelCase_      :				Any      =       hidden_sizes
      lowerCAmelCase_      :				List[Any]      =       num_hidden_layers
      lowerCAmelCase_      :				Union[str, Any]      =       num_attention_heads
      lowerCAmelCase_      :				Tuple      =       initializer_range
      lowerCAmelCase_      :				Union[str, Any]      =       layer_norm_eps
      lowerCAmelCase_      :				int      =       patch_size
      lowerCAmelCase_      :				List[str]      =       num_channels
      lowerCAmelCase_      :				Dict      =       depths
      lowerCAmelCase_      :				int      =       mlp_expansion_ratio
      lowerCAmelCase_      :				Optional[Any]      =       downsamples
      lowerCAmelCase_      :				Union[str, Any]      =       dim
      lowerCAmelCase_      :				Union[str, Any]      =       key_dim
      lowerCAmelCase_      :				str      =       attention_ratio
      lowerCAmelCase_      :				Tuple      =       resolution
      lowerCAmelCase_      :				Optional[Any]      =       pool_size
      lowerCAmelCase_      :				str      =       downsample_patch_size
      lowerCAmelCase_      :				Dict      =       downsample_stride
      lowerCAmelCase_      :				str      =       downsample_pad
      lowerCAmelCase_      :				str      =       drop_path_rate
      lowerCAmelCase_      :				List[Any]      =       num_metaad_blocks
      lowerCAmelCase_      :				Tuple      =       distillation
      lowerCAmelCase_      :				Optional[Any]      =       use_layer_scale
      lowerCAmelCase_      :				Dict      =       layer_scale_init_value
      lowerCAmelCase_      :				Optional[Any]      =       image_size
      lowerCAmelCase_      :				Optional[Any]      =       batch_norm_eps



