'''simple docstring'''





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import MobileViTImageProcessor




class 			__A (					unittest.TestCase      ):



    def __init__(self       :       Tuple  ,     __a       :       List[str]  ,     __a       :       Optional[Any]=7  ,     __a       :       Union[str, Any]=3  ,     __a       :       Union[str, Any]=18  ,     __a       :       List[Any]=30  ,     __a       :       List[str]=400  ,     __a       :       Optional[int]=True  ,     __a       :       List[str]=None  ,     __a       :       Any=True  ,     __a       :       Any=None  ,     __a       :       Any=True  ,     ):
         UpperCAmelCase_			       =  size if size is not None else {"shortest_edge": 20}
         UpperCAmelCase_			       =  crop_size if crop_size is not None else {"height": 18, "width": 18}
         UpperCAmelCase_			       =  parent
         UpperCAmelCase_			       =  batch_size
         UpperCAmelCase_			       =  num_channels
         UpperCAmelCase_			       =  image_size
         UpperCAmelCase_			       =  min_resolution
         UpperCAmelCase_			       =  max_resolution
         UpperCAmelCase_			       =  do_resize
         UpperCAmelCase_			       =  size
         UpperCAmelCase_			       =  do_center_crop
         UpperCAmelCase_			       =  crop_size
         UpperCAmelCase_			       =  do_flip_channel_order






    def    _lowercase		(self       :       Dict					):
         return {
             "do_resize": self.do_resize,
             "size": self.size,
             "do_center_crop": self.do_center_crop,
             "crop_size": self.crop_size,
             "do_flip_channel_order": self.do_flip_channel_order,
         }




@require_torch
@require_vision
class 			__A (					UpperCamelCase__						,      unittest.TestCase      ):
    a__			:		Tuple			  =    MobileViTImageProcessor if is_vision_available() else None



    def    _lowercase		(self       :       Optional[Any]					):
         UpperCAmelCase_			       =  MobileViTImageProcessingTester(self					)



    @property
    def    _lowercase		(self       :       Any					):
         return self.image_processor_tester.prepare_image_processor_dict()



    def    _lowercase		(self       :       Union[str, Any]					):
         UpperCAmelCase_			       =  self.image_processing_class(**self.image_processor_dict					)
         self.assertTrue(hasattr(__a  ,     "do_resize"					)					)
         self.assertTrue(hasattr(__a  ,     "size"					)					)
         self.assertTrue(hasattr(__a  ,     "do_center_crop"					)					)
         self.assertTrue(hasattr(__a  ,     "center_crop"					)					)
         self.assertTrue(hasattr(__a  ,     "do_flip_channel_order"					)					)



    def    _lowercase		(self       :       Optional[int]					):
         UpperCAmelCase_			       =  self.image_processing_class.from_dict(self.image_processor_dict					)
         self.assertEqual(image_processor.size  ,     {"shortest_edge": 20}					)
         self.assertEqual(image_processor.crop_size  ,     {"height": 18, "width": 18}					)

         UpperCAmelCase_			       =  self.image_processing_class.from_dict(self.image_processor_dict  ,     size=42  ,     crop_size=84					)
         self.assertEqual(image_processor.size  ,     {"shortest_edge": 42}					)
         self.assertEqual(image_processor.crop_size  ,     {"height": 84, "width": 84}					)



    def    _lowercase		(self       :       Tuple					):
         pass



    def    _lowercase		(self       :       int					):
         # Initialize image_processing
         UpperCAmelCase_			       =  self.image_processing_class(**self.image_processor_dict					)
         # create random PIL images
         UpperCAmelCase_			       =  prepare_image_inputs(self.image_processor_tester  ,     equal_resolution=__a					)
         for image in image_inputs:
              self.assertIsInstance(__a  ,     Image.Image					)

         # Test not batched input
         UpperCAmelCase_			       =  image_processing(image_inputs[0]  ,     return_tensors="pt"					).pixel_values
         self.assertEqual(
             encoded_images.shape  ,     (
                 1,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size["height"],
                 self.image_processor_tester.crop_size["width"],
             )  ,     )

         # Test batched
         UpperCAmelCase_			       =  image_processing(__a  ,     return_tensors="pt"					).pixel_values
         self.assertEqual(
             encoded_images.shape  ,     (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size["height"],
                 self.image_processor_tester.crop_size["width"],
             )  ,     )



    def    _lowercase		(self       :       Any					):
         # Initialize image_processing
         UpperCAmelCase_			       =  self.image_processing_class(**self.image_processor_dict					)
         # create random numpy tensors
         UpperCAmelCase_			       =  prepare_image_inputs(self.image_processor_tester  ,     equal_resolution=__a  ,     numpify=__a					)
         for image in image_inputs:
              self.assertIsInstance(__a  ,     np.ndarray					)

         # Test not batched input
         UpperCAmelCase_			       =  image_processing(image_inputs[0]  ,     return_tensors="pt"					).pixel_values
         self.assertEqual(
             encoded_images.shape  ,     (
                 1,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size["height"],
                 self.image_processor_tester.crop_size["width"],
             )  ,     )

         # Test batched
         UpperCAmelCase_			       =  image_processing(__a  ,     return_tensors="pt"					).pixel_values
         self.assertEqual(
             encoded_images.shape  ,     (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size["height"],
                 self.image_processor_tester.crop_size["width"],
             )  ,     )






    def    _lowercase		(self       :       Tuple					):
         # Initialize image_processing
         UpperCAmelCase_			       =  self.image_processing_class(**self.image_processor_dict					)
         # create random PyTorch tensors
         UpperCAmelCase_			       =  prepare_image_inputs(self.image_processor_tester  ,     equal_resolution=__a  ,     torchify=__a					)
         for image in image_inputs:
              self.assertIsInstance(__a  ,     torch.Tensor					)

         # Test not batched input
         UpperCAmelCase_			       =  image_processing(image_inputs[0]  ,     return_tensors="pt"					).pixel_values
         self.assertEqual(
             encoded_images.shape  ,     (
                 1,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size["height"],
                 self.image_processor_tester.crop_size["width"],
             )  ,     )

         # Test batched
         UpperCAmelCase_			       =  image_processing(__a  ,     return_tensors="pt"					).pixel_values
         self.assertEqual(
             encoded_images.shape  ,     (
                 self.image_processor_tester.batch_size,
                 self.image_processor_tester.num_channels,
                 self.image_processor_tester.crop_size["height"],
                 self.image_processor_tester.crop_size["width"],
             )  ,     )








"""simple docstring"""



import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_convbert import ConvBertTokenizer


lowercase_							=							logging.get_logger(__name__)

lowercase_							=							{'vocab_file': 'vocab.txt'}

lowercase_							=							{
    'vocab_file': {
        'YituTech/conv-bert-base': 'https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt',
        'YituTech/conv-bert-medium-small': (
            'https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt'
        ),
        'YituTech/conv-bert-small': 'https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt',
    }
}

lowercase_							=							{
    'YituTech/conv-bert-base': 5_12,
    'YituTech/conv-bert-medium-small': 5_12,
    'YituTech/conv-bert-small': 5_12,
}


lowercase_							=							{
    'YituTech/conv-bert-base': {'do_lower_case': True},
    'YituTech/conv-bert-medium-small': {'do_lower_case': True},
    'YituTech/conv-bert-small': {'do_lower_case': True},
}







class    __a						( __snake_case							):
				lowerCamelCase     :       Optional[int]			       =VOCAB_FILES_NAMES
				lowerCamelCase     :       List[str]			       =PRETRAINED_VOCAB_FILES_MAP
				lowerCamelCase     :       str			       =PRETRAINED_INIT_CONFIGURATION
				lowerCamelCase     :       Any			       =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowerCamelCase     :       List[str]			       =ConvBertTokenizer







				def __init__( self      ,	UpperCAmelCase=None      ,	UpperCAmelCase=None      ,	UpperCAmelCase=True      ,	UpperCAmelCase="[UNK]"      ,	UpperCAmelCase="[SEP]"      ,	UpperCAmelCase="[PAD]"      ,	UpperCAmelCase="[CLS]"      ,	UpperCAmelCase="[MASK]"      ,	UpperCAmelCase=True      ,	UpperCAmelCase=None      ,	**UpperCAmelCase      ,	):

					'''simple docstring'''






					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      ,	)

					lowerCAmelCase_      							=			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
					):
						lowerCAmelCase_      							=			getattr(UpperCAmelCase      ,	normalizer_state.pop('''type'''   )   )
						lowerCAmelCase_      							=			do_lower_case
						lowerCAmelCase_      							=			strip_accents
						lowerCAmelCase_      							=			tokenize_chinese_chars
						lowerCAmelCase_      							=			normalizer_class(**UpperCAmelCase   )

					lowerCAmelCase_      							=			do_lower_case







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase=None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			[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      ,	UpperCAmelCase      ,	UpperCAmelCase = None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			[self.sep_token_id]
					lowerCAmelCase_      							=			[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      ,	UpperCAmelCase      ,	UpperCAmelCase = None   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self._tokenizer.model.save(UpperCAmelCase      ,	name=UpperCAmelCase   )
					return tuple(UpperCAmelCase   )