





"""simple docstring"""





from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_clip import CLIPTokenizer


SCREAMING_SNAKE_CASE__ =       logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__ =       {"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

SCREAMING_SNAKE_CASE__ =       {
    """vocab_file""": {
        """openai/clip-vit-base-patch32""": """https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """openai/clip-vit-base-patch32""": """https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/merges.txt""",
    },
    """tokenizer_file""": {
        """openai/clip-vit-base-patch32""": (
            """https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/tokenizer.json"""
        ),
    },
}

SCREAMING_SNAKE_CASE__ =       {
    """openai/clip-vit-base-patch32""": 77,
}

class 		lowercase ( a_ ):
						_SCREAMING_SNAKE_CASE         =				VOCAB_FILES_NAMES
						_SCREAMING_SNAKE_CASE         =				PRETRAINED_VOCAB_FILES_MAP
						_SCREAMING_SNAKE_CASE         =				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						_SCREAMING_SNAKE_CASE         =				['input_ids', 'attention_mask']
						_SCREAMING_SNAKE_CASE         =				CLIPTokenizer





						def __init__(	self				,						lowercase=None				,						lowercase=None				,						lowercase=None				,						lowercase="<|endoftext|>"				,						lowercase="<|startoftext|>"				,						lowercase="<|endoftext|>"				,						lowercase="<|endoftext|>"				,						**lowercase				,						)		->					str:
												super().__init__(
												    snake_case__				,						snake_case__				,						tokenizer_file=snake_case__				,						unk_token=snake_case__				,						bos_token=snake_case__				,						eos_token=snake_case__				,						pad_token=snake_case__				,						**snake_case__				,						)

												if not isinstance(self.backend_tokenizer.pre_tokenizer				,						pre_tokenizers.Sequence			):
																		raise ValueError(
																		    """The `backend_tokenizer` provided does not match the expected format. The CLIP tokenizer has been"""
																		    """ heavily modified from transformers version 4.17.0. You need to convert the tokenizer you are using"""
																		    """ to be compatible with this version.The easiest way to do so is"""
																		    """ `CLIPTokenizerFast.from_pretrained(\"path_to_local_folder_or_hub_repo, from_slow=True)`. If you want"""
																		    """ to use your existing tokenizer, you will have to revert to a version prior to 4.17.0 of"""
																		    """ transformers."""			)

												self._wrap_decode_method_backend_tokenizer()





						def    _snake_case      (	self			)		->					Optional[int]:
												lowerCAmelCase  						=	self.backend_tokenizer.decode

												def new_decode_method(*lowercase				,						**lowercase			):
																		lowerCAmelCase  						=	orig_decode_method(*snake_case__				,						**snake_case__			)
																		lowerCAmelCase  						=	text.replace(self.backend_tokenizer.model.end_of_word_suffix				,						""" """			).strip()
																		return text

												lowerCAmelCase  						=	new_decode_method





						def    _snake_case      (	self				,						lowercase				,						lowercase = None			)		->					Optional[int]:
												lowerCAmelCase  						=	[self.bos_token_id]
												lowerCAmelCase  						=	[self.eos_token_id]

												if token_ids_a is None:
																		return bos_token + token_ids_a + eos_token
												return bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token





						def    _snake_case      (	self				,						lowercase				,						lowercase = None			)		->					int:
												lowerCAmelCase  						=	[self.bos_token_id]
												lowerCAmelCase  						=	[self.eos_token_id]

												if token_ids_a is None:
																		return len(bos_token + token_ids_a + eos_token			) * [0]
												return len(bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token			) * [0]





						def    _snake_case      (	self				,						lowercase				,						lowercase = None			)		->					str:
												lowerCAmelCase  						=	self._tokenizer.model.save(snake_case__				,						name=snake_case__			)
												return tuple(snake_case__			)













"""simple docstring"""





import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput

@dataclass
class 		lowercase ( _UpperCAmelCase ):
      _SCREAMING_SNAKE_CASE         =				42
      _SCREAMING_SNAKE_CASE         =				None
      _SCREAMING_SNAKE_CASE         =				None







class 		lowercase ( unittest.TestCase ):





      def    _snake_case      (	self			)		->					Optional[Any]:
            lowerCAmelCase  						=	ModelOutputTest(a=30			)
            self.assertEqual(x.a				,						30			)
            self.assertIsNone(x.b			)
            self.assertIsNone(x.c			)
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x.d





      def    _snake_case      (	self			)		->					Optional[Any]:
            lowerCAmelCase  						=	ModelOutputTest(a=30				,						b=10			)
            self.assertEqual(x[0]				,						30			)
            self.assertEqual(x[1]				,						10			)
            self.assertEqual(x[:2]				,						(30, 10)			)
            self.assertEqual(x[:]				,						(30, 10)			)

            lowerCAmelCase  						=	ModelOutputTest(a=30				,						c=10			)
            self.assertEqual(x[0]				,						30			)
            self.assertEqual(x[1]				,						10			)
            self.assertEqual(x[:2]				,						(30, 10)			)
            self.assertEqual(x[:]				,						(30, 10)			)





      def    _snake_case      (	self			)		->					Tuple:
            lowerCAmelCase  						=	ModelOutputTest(a=30				,						b=10			)
            self.assertEqual(x["""a"""]				,						30			)
            self.assertEqual(x["""b"""]				,						10			)
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x["""c"""]

            lowerCAmelCase  						=	ModelOutputTest(a=30				,						c=10			)
            self.assertEqual(x["""a"""]				,						30			)
            self.assertEqual(x["""c"""]				,						10			)
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x["""b"""]





      def    _snake_case      (	self			)		->					Union[str, Any]:
            lowerCAmelCase  						=	ModelOutputTest(a=30			)
            self.assertEqual(list(x.keys()			)				,						["""a"""]			)
            self.assertEqual(list(x.values()			)				,						[30]			)
            self.assertEqual(list(x.items()			)				,						[("""a""", 30)]			)
            self.assertEqual(list(lowercase			)				,						["""a"""]			)

            lowerCAmelCase  						=	ModelOutputTest(a=30				,						b=10			)
            self.assertEqual(list(x.keys()			)				,						["""a""", """b"""]			)
            self.assertEqual(list(x.values()			)				,						[30, 10]			)
            self.assertEqual(list(x.items()			)				,						[("""a""", 30), ("""b""", 10)]			)
            self.assertEqual(list(lowercase			)				,						["""a""", """b"""]			)

            lowerCAmelCase  						=	ModelOutputTest(a=30				,						c=10			)
            self.assertEqual(list(x.keys()			)				,						["""a""", """c"""]			)
            self.assertEqual(list(x.values()			)				,						[30, 10]			)
            self.assertEqual(list(x.items()			)				,						[("""a""", 30), ("""c""", 10)]			)
            self.assertEqual(list(lowercase			)				,						["""a""", """c"""]			)

            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x.update({"""d""": 20}			)
            with self.assertRaises(lowercase			):
                  del x["a"]
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x.pop("""a"""			)
            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	x.setdefault("""d"""				,						32			)





      def    _snake_case      (	self			)		->					Dict:
            lowerCAmelCase  						=	ModelOutputTest(a=30			)
            lowerCAmelCase  						=	10
            self.assertEqual(x.a				,						10			)
            self.assertEqual(x["""a"""]				,						10			)





      def    _snake_case      (	self			)		->					List[str]:
            lowerCAmelCase  						=	ModelOutputTest(a=30			)
            lowerCAmelCase  						=	10
            self.assertEqual(x.a				,						10			)
            self.assertEqual(x["""a"""]				,						10			)





      def    _snake_case      (	self			)		->					str:
            lowerCAmelCase  						=	ModelOutputTest({"""a""": 30, """b""": 10}			)
            self.assertEqual(list(x.keys()			)				,						["""a""", """b"""]			)
            self.assertEqual(x.a				,						30			)
            self.assertEqual(x.b				,						10			)





      def    _snake_case      (	self			)		->					Dict:
            lowerCAmelCase  						=	ModelOutputTest([("""a""", 30), ("""b""", 10)]			)
            self.assertEqual(list(x.keys()			)				,						["""a""", """b"""]			)
            self.assertEqual(x.a				,						30			)
            self.assertEqual(x.b				,						10			)

            with self.assertRaises(lowercase			):
                  lowerCAmelCase  						=	ModelOutputTest([("""a""", 30), (10, 10)]			)

            lowerCAmelCase  						=	ModelOutputTest(a=(30, 30)			)
            self.assertEqual(list(x.keys()			)				,						["""a"""]			)
            self.assertEqual(x.a				,						(30, 30)			)






