






"""simple docstring"""





import argparse
import json
from pathlib import Path

import requests
import torch
from huggingface_hub import hf_hub_download
from PIL import Image

from transformers import ConvNextConfig, ConvNextForImageClassification, ConvNextImageProcessor
from transformers.utils import logging


logging.set_verbosity_info()
UpperCamelCase			=      logging.get_logger(__name__)






def     A(  snake_case_		):
       """simple docstring"""





       lowercase__:    Optional[Any]        =      ConvNextConfig()

       if "tiny" in checkpoint_url:
              lowercase__:    Optional[Any]        =      [3, 3, 9, 3]
              lowercase__:    List[str]        =      [96, 192, 384, 768]
       if "small" in checkpoint_url:
              lowercase__:    Optional[int]        =      [3, 3, 27, 3]
              lowercase__:    Dict        =      [96, 192, 384, 768]
       if "base" in checkpoint_url:
              lowercase__:    Any        =      [3, 3, 27, 3]
              lowercase__:    List[str]        =      [128, 256, 512, 1024]
       if "large" in checkpoint_url:
              lowercase__:    List[Any]        =      [3, 3, 27, 3]
              lowercase__:    Dict        =      [192, 384, 768, 1536]
       if "xlarge" in checkpoint_url:
              lowercase__:    Tuple        =      [3, 3, 27, 3]
              lowercase__:    Union[str, Any]        =      [256, 512, 1024, 2048]

       if "1k" in checkpoint_url:
              lowercase__:    Tuple        =      1000
              lowercase__:    int        =      "imagenet-1k-id2label.json"
              lowercase__:    List[Any]        =      (1, 1000)
       else:
              lowercase__:    str        =      21841
              lowercase__:    Optional[int]        =      "imagenet-22k-id2label.json"
              lowercase__:    int        =      (1, 21841)

       lowercase__:    str        =      "huggingface/label-files"
       lowercase__:    Optional[Any]        =      num_labels
       lowercase__:    Optional[int]        =      json.load(open(hf_hub_download(snake_case_						,       snake_case_						,       repo_type="dataset"		)						,       "r"		)		)
       lowercase__:    Any        =      {int(snake_case_		): v for k, v in idalabel.items()}
       if "1k" not in checkpoint_url:
              # this dataset contains 21843 labels but the model only has 21841
              # we delete the classes as mentioned in https://github.com/google-research/big_transfer/issues/18
              del idalabel[9205]
              del idalabel[15027]
       lowercase__:    Optional[Any]        =      idalabel
       lowercase__:    List[Any]        =      {v: k for k, v in idalabel.items()}
       lowercase__:    Union[str, Any]        =      hidden_sizes
       lowercase__:    str        =      depths

       return config, expected_shape






def     A(  snake_case_		):
       """simple docstring"""





       if "downsample_layers.0.0" in name:
              lowercase__:    Optional[Any]        =      name.replace("downsample_layers.0.0"						,       "embeddings.patch_embeddings"		)
       if "downsample_layers.0.1" in name:
              lowercase__:    List[Any]        =      name.replace("downsample_layers.0.1"						,       "embeddings.norm"		)  # we rename to layernorm later on
       if "downsample_layers.1.0" in name:
              lowercase__:    Optional[Any]        =      name.replace("downsample_layers.1.0"						,       "stages.1.downsampling_layer.0"		)
       if "downsample_layers.1.1" in name:
              lowercase__:    Optional[int]        =      name.replace("downsample_layers.1.1"						,       "stages.1.downsampling_layer.1"		)
       if "downsample_layers.2.0" in name:
              lowercase__:    int        =      name.replace("downsample_layers.2.0"						,       "stages.2.downsampling_layer.0"		)
       if "downsample_layers.2.1" in name:
              lowercase__:    Union[str, Any]        =      name.replace("downsample_layers.2.1"						,       "stages.2.downsampling_layer.1"		)
       if "downsample_layers.3.0" in name:
              lowercase__:    List[str]        =      name.replace("downsample_layers.3.0"						,       "stages.3.downsampling_layer.0"		)
       if "downsample_layers.3.1" in name:
              lowercase__:    str        =      name.replace("downsample_layers.3.1"						,       "stages.3.downsampling_layer.1"		)
       if "stages" in name and "downsampling_layer" not in name:
              # stages.0.0. for instance should be renamed to stages.0.layers.0.
              lowercase__:    Dict        =      name[: len("stages.0"		)] + ".layers" + name[len("stages.0"		) :]
       if "stages" in name:
              lowercase__:    Union[str, Any]        =      name.replace("stages"						,       "encoder.stages"		)
       if "norm" in name:
              lowercase__:    List[str]        =      name.replace("norm"						,       "layernorm"		)
       if "gamma" in name:
              lowercase__:    Union[str, Any]        =      name.replace("gamma"						,       "layer_scale_parameter"		)
       if "head" in name:
              lowercase__:    int        =      name.replace("head"						,       "classifier"		)

       return name






def     A(  ):
       """simple docstring"""





       lowercase__:    str        =      "http://images.cocodataset.org/val2017/000000039769.jpg"
       lowercase__:    int        =      Image.open(requests.get(snake_case_						,       stream=snake_case_		).raw		)
       return im






@torch.no_grad()
def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





       lowercase__  ,     lowercase__:    Optional[int]        =      get_convnext_config(snake_case_		)
       # load original state_dict from URL
       lowercase__:    List[str]        =      torch.hub.load_state_dict_from_url(snake_case_		)["model"]
       # rename keys
       for key in state_dict.copy().keys():
              lowercase__:    Optional[int]        =      state_dict.pop(snake_case_		)
              lowercase__:    Tuple        =      val
       # add prefix to all keys expect classifier head
       for key in state_dict.copy().keys():
              lowercase__:    Any        =      state_dict.pop(snake_case_		)
              if not key.startswith("classifier"		):
                     lowercase__:    int        =      "convnext." + key
              lowercase__:    str        =      val

       # load HuggingFace model
       lowercase__:    int        =      ConvNextForImageClassification(snake_case_		)
       model.load_state_dict(snake_case_		)
       model.eval()

       # Check outputs on an image, prepared by ConvNextImageProcessor
       lowercase__:    Dict        =      224 if "224" in checkpoint_url else 384
       lowercase__:    str        =      ConvNextImageProcessor(size=snake_case_		)
       lowercase__:    Optional[Any]        =      image_processor(images=prepare_img()						,       return_tensors="pt"		).pixel_values

       lowercase__:    Dict        =      model(snake_case_		).logits

       # note: the logits below were obtained without center cropping
       if checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_tiny_1k_224_ema.pth":
              lowercase__:    Any        =      torch.tensor([-0.12_10, -0.66_05, 0.19_18]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_small_1k_224_ema.pth":
              lowercase__:    Tuple        =      torch.tensor([-0.44_73, -0.18_47, -0.63_65]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_1k_224_ema.pth":
              lowercase__:    int        =      torch.tensor([0.45_25, 0.75_39, 0.03_08]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_1k_384.pth":
              lowercase__:    List[Any]        =      torch.tensor([0.35_61, 0.63_50, -0.03_84]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_1k_224_ema.pth":
              lowercase__:    Any        =      torch.tensor([0.41_74, -0.09_89, 0.14_89]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_1k_384.pth":
              lowercase__:    Any        =      torch.tensor([0.25_13, -0.13_49, -0.16_13]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_22k_224.pth":
              lowercase__:    List[Any]        =      torch.tensor([1.29_80, 0.36_31, -0.11_98]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_22k_224.pth":
              lowercase__:    List[Any]        =      torch.tensor([1.29_63, 0.12_27, 0.17_23]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_224.pth":
              lowercase__:    int        =      torch.tensor([1.79_56, 0.83_90, 0.28_20]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_22k_1k_224.pth":
              lowercase__:    Any        =      torch.tensor([-0.28_22, -0.05_02, -0.08_78]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_base_22k_1k_384.pth":
              lowercase__:    int        =      torch.tensor([-0.56_72, -0.07_30, -0.43_48]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_22k_1k_224.pth":
              lowercase__:    List[Any]        =      torch.tensor([0.26_81, 0.23_65, 0.62_46]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_large_22k_1k_384.pth":
              lowercase__:    List[str]        =      torch.tensor([-0.26_42, 0.39_31, 0.51_16]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_1k_224_ema.pth":
              lowercase__:    Any        =      torch.tensor([-0.66_77, -0.18_73, -0.83_79]		)
       elif checkpoint_url == "https://dl.fbaipublicfiles.com/convnext/convnext_xlarge_22k_1k_384_ema.pth":
              lowercase__:    Optional[int]        =      torch.tensor([-0.77_49, -0.29_67, -0.64_44]		)
       else:
              raise ValueError(F"""Unknown URL: {checkpoint_url}"""		)

       assert torch.allclose(logits[0, :3]						,       snake_case_						,       atol=1E-3		)
       assert logits.shape == expected_shape

       Path(snake_case_		).mkdir(exist_ok=snake_case_		)
       print(F"""Saving model to {pytorch_dump_folder_path}"""		)
       model.save_pretrained(snake_case_		)
       print(F"""Saving image processor to {pytorch_dump_folder_path}"""		)
       image_processor.save_pretrained(snake_case_		)

       print("Pushing model to the hub..."		)
       lowercase__:    int        =      "convnext"
       if "tiny" in checkpoint_url:
              model_name += "-tiny"
       elif "small" in checkpoint_url:
              model_name += "-small"
       elif "base" in checkpoint_url:
              model_name += "-base"
       elif "xlarge" in checkpoint_url:
              model_name += "-xlarge"
       elif "large" in checkpoint_url:
              model_name += "-large"
       if "224" in checkpoint_url:
              model_name += "-224"
       elif "384" in checkpoint_url:
              model_name += "-384"
       if "22k" in checkpoint_url and "1k" not in checkpoint_url:
              model_name += "-22k"
       if "22k" in checkpoint_url and "1k" in checkpoint_url:
              model_name += "-22k-1k"

       model.push_to_hub(
           repo_path_or_name=Path(snake_case_						,       snake_case_		)						,       organization="nielsr"						,       commit_message="Add model"						,       )


if __name__ == "__main__":
  UpperCamelCase			=      argparse.ArgumentParser()
  # Required parameters
  parser.add_argument(
      """--checkpoint_url""",
      default="""https://dl.fbaipublicfiles.com/convnext/convnext_tiny_1k_224_ema.pth""",
      type=str,
      help="""URL of the original ConvNeXT checkpoint you'd like to convert.""",
  )
  parser.add_argument(
      """--pytorch_dump_folder_path""",
      default=None,
      type=str,
      required=True,
      help="""Path to the output PyTorch model directory.""",
  )

  UpperCamelCase			=      parser.parse_args()
  convert_convnext_checkpoint(args.checkpoint_url, args.pytorch_dump_folder_path)














"""simple docstring"""





import os
import unittest

from transformers import ElectraTokenizerFast
from transformers.models.electra.tokenization_electra import (
    VOCAB_FILES_NAMES,
    BasicTokenizer,
    ElectraTokenizer,
    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 		_a       (						lowercase_    ,					unittest.TestCase   ):





   '''simple docstring'''






   UpperCamelCase__      					=    ElectraTokenizer
   UpperCamelCase__      					=    ElectraTokenizerFast
   UpperCamelCase__      					=    True
   UpperCamelCase__      					=    True
   UpperCamelCase__      					=    filter_non_english





   def __lowercase    (   self)	-> str:




          '''simple docstring'''




          super().setUp()

          lowercase__:    List[str]        =      [
              "[UNK]",
              "[CLS]",
              "[SEP]",
              "[PAD]",
              "[MASK]",
              "want",
              "##want",
              "##ed",
              "wa",
              "un",
              "runn",
              "##ing",
              ",",
              "low",
              "lowest",
          ]
          lowercase__:    int        =      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]))





   def __lowercase    (   self			,				UpperCAmelCase_)	-> Dict:




          '''simple docstring'''




          lowercase__:    str        =      "UNwant\u00E9d,running"
          lowercase__:    List[Any]        =      "unwanted, running"
          return input_text, output_text





   def __lowercase    (   self)	-> Union[str, Any]:




          '''simple docstring'''




          lowercase__:    str        =      self.tokenizer_class(self.vocab_file)

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





   def __lowercase    (   self)	-> Optional[int]:




          '''simple docstring'''




          if not self.test_rust_tokenizer:
                 return

          lowercase__:    Dict        =      self.get_tokenizer()
          lowercase__:    List[Any]        =      self.get_rust_tokenizer()

          lowercase__:    Optional[Any]        =      "UNwant\u00E9d,running"

          lowercase__:    Tuple        =      tokenizer.tokenize(UpperCAmelCase_)
          lowercase__:    Tuple        =      rust_tokenizer.tokenize(UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          lowercase__:    List[str]        =      tokenizer.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
          lowercase__:    Optional[Any]        =      rust_tokenizer.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          lowercase__:    List[Any]        =      self.get_rust_tokenizer()
          lowercase__:    int        =      tokenizer.encode(UpperCAmelCase_)
          lowercase__:    str        =      rust_tokenizer.encode(UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          # With lower casing
          lowercase__:    Optional[Any]        =      self.get_tokenizer(do_lower_case=UpperCAmelCase_)
          lowercase__:    List[Any]        =      self.get_rust_tokenizer(do_lower_case=UpperCAmelCase_)

          lowercase__:    str        =      "UNwant\u00E9d,running"

          lowercase__:    str        =      tokenizer.tokenize(UpperCAmelCase_)
          lowercase__:    Tuple        =      rust_tokenizer.tokenize(UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          lowercase__:    List[Any]        =      tokenizer.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
          lowercase__:    List[str]        =      rust_tokenizer.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)

          lowercase__:    Any        =      self.get_rust_tokenizer()
          lowercase__:    Dict        =      tokenizer.encode(UpperCAmelCase_)
          lowercase__:    List[Any]        =      rust_tokenizer.encode(UpperCAmelCase_)
          self.assertListEqual(UpperCAmelCase_			,				UpperCAmelCase_)





   def __lowercase    (   self)	-> Dict:




          '''simple docstring'''




          lowercase__:    Optional[int]        =      BasicTokenizer()

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





   def __lowercase    (   self)	-> Optional[int]:




          '''simple docstring'''




          lowercase__:    str        =      BasicTokenizer(do_lower_case=UpperCAmelCase_)

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





   def __lowercase    (   self)	-> Union[str, Any]:




          '''simple docstring'''




          lowercase__:    Any        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				strip_accents=UpperCAmelCase_)

          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:




          '''simple docstring'''




          lowercase__:    Tuple        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				strip_accents=UpperCAmelCase_)

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





   def __lowercase    (   self)	-> Union[str, Any]:




          '''simple docstring'''




          lowercase__:    int        =      BasicTokenizer(do_lower_case=UpperCAmelCase_)

          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[Any]:




          '''simple docstring'''




          lowercase__:    Optional[int]        =      BasicTokenizer(do_lower_case=UpperCAmelCase_)

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





   def __lowercase    (   self)	-> Optional[Any]:




          '''simple docstring'''




          lowercase__:    Optional[Any]        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				strip_accents=UpperCAmelCase_)

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





   def __lowercase    (   self)	-> Union[str, Any]:




          '''simple docstring'''




          lowercase__:    Any        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				strip_accents=UpperCAmelCase_)

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





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    List[Any]        =      BasicTokenizer(do_lower_case=UpperCAmelCase_			,				never_split=["[UNK]"])

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





   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    List[str]        =      ["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

          lowercase__:    Dict        =      {}
          for i, token in enumerate(UpperCAmelCase_):
                 lowercase__:    Optional[int]        =      i
          lowercase__:    str        =      WordpieceTokenizer(vocab=UpperCAmelCase_			,				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)	-> Dict:




          '''simple docstring'''




          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)	-> List[Any]:




          '''simple docstring'''




          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)	-> List[Any]:




          '''simple docstring'''




          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:




          '''simple docstring'''




          lowercase__:    Optional[Any]        =      self.get_tokenizer()
          lowercase__:    str        =      self.get_rust_tokenizer()

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

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





   @slow
   def __lowercase    (   self)	-> int:




          '''simple docstring'''




          lowercase__:    Dict        =      self.tokenizer_class.from_pretrained("google/electra-base-discriminator")

          lowercase__:    Optional[int]        =      tokenizer.encode("sequence builders"			,				add_special_tokens=UpperCAmelCase_)
          lowercase__:    List[str]        =      tokenizer.encode("multi-sequence build"			,				add_special_tokens=UpperCAmelCase_)

          lowercase__:    Dict        =      tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_)
          lowercase__:    Union[str, Any]        =      tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_			,				UpperCAmelCase_)

          assert encoded_sentence == [101] + text + [102]
          assert encoded_pair == [101] + text + [102] + text_a + [102]





   def __lowercase    (   self)	-> List[Any]:




          '''simple docstring'''




          for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
                 with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""):
                        lowercase__:    Any        =      self.rust_tokenizer_class.from_pretrained(UpperCAmelCase_			,				**UpperCAmelCase_)

                        lowercase__:    int        =      F"""A, naïve {tokenizer_r.mask_token} AllenNLP sentence."""
                        lowercase__:    Tuple        =      tokenizer_r.encode_plus(
                            UpperCAmelCase_			,				return_attention_mask=UpperCAmelCase_			,				return_token_type_ids=UpperCAmelCase_			,				return_offsets_mapping=UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_			,				)

                        lowercase__:    str        =      tokenizer_r.do_lower_case if hasattr(UpperCAmelCase_			,				"do_lower_case") else False
                        lowercase__:    List[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)	-> List[Any]:




          '''simple docstring'''




          lowercase__:    Union[str, Any]        =      ["的", "人", "有"]
          lowercase__:    Any        =      "".join(UpperCAmelCase_)
          for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
                 with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""):
                        lowercase__:    Optional[Any]        =      True
                        lowercase__:    List[str]        =      self.tokenizer_class.from_pretrained(UpperCAmelCase_			,				**UpperCAmelCase_)
                        lowercase__:    Dict        =      self.rust_tokenizer_class.from_pretrained(UpperCAmelCase_			,				**UpperCAmelCase_)

                        lowercase__:    str        =      tokenizer_p.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
                        lowercase__:    Optional[int]        =      tokenizer_r.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)

                        lowercase__:    Union[str, Any]        =      tokenizer_r.convert_ids_to_tokens(UpperCAmelCase_)
                        lowercase__:    List[str]        =      tokenizer_p.convert_ids_to_tokens(UpperCAmelCase_)

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

                        lowercase__:    Dict        =      False
                        lowercase__:    Optional[int]        =      self.rust_tokenizer_class.from_pretrained(UpperCAmelCase_			,				**UpperCAmelCase_)
                        lowercase__:    int        =      self.tokenizer_class.from_pretrained(UpperCAmelCase_			,				**UpperCAmelCase_)

                        lowercase__:    str        =      tokenizer_r.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)
                        lowercase__:    Tuple        =      tokenizer_p.encode(UpperCAmelCase_			,				add_special_tokens=UpperCAmelCase_)

                        lowercase__:    Union[str, Any]        =      tokenizer_r.convert_ids_to_tokens(UpperCAmelCase_)
                        lowercase__:    List[str]        =      tokenizer_p.convert_ids_to_tokens(UpperCAmelCase_)

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






