






from typing import Dict, List, Optional

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


UpperCAmelCase__      			=						logging.get_logger(__name__)


UpperCAmelCase__      			=						{
    '''nielsr/canine-s''': 2048,
}

# Unicode defines 1,114,112 total “codepoints”
UpperCAmelCase__      			=						111_4112

# Below: Constants defining canonical codepoints for special, pseudo-characters.
# Copied from https://github.com/google-research/language/blob/master/language/canine/special_codepoints.py
UpperCAmelCase__      			=						0

UpperCAmelCase__      			=						0xe000
UpperCAmelCase__      			=						0xe001
UpperCAmelCase__      			=						0xe002
UpperCAmelCase__      			=						0xe003
UpperCAmelCase__      			=						0xe004

# Maps special codepoints to human-readable names.
UpperCAmelCase__      			=						{
    # Special symbols are represented using codepoints values that are valid,
    # but designated as "Private Use", meaning that they will never be assigned
    # characters by the Unicode Consortium, and are thus safe for use here.
    #
    # NOTE: Do *NOT* add any sort of [UNK_CHAR] here. They are explicitly
    # excluded and should fail with a hard error.
    CLS: "[CLS]",
    SEP: "[SEP]",
    BOS: "[BOS]",
    MASK: "[MASK]",
    PAD: "[PAD]",
    RESERVED: "[RESERVED]",
}

# Maps special codepoint human-readable names to their codepoint values.
UpperCAmelCase__      			=						{name: codepoint for codepoint, name in SPECIAL_CODEPOINTS.items()}




class 							snake_case_       (    __UpperCamelCase      ):

						"""simple docstring"""



						snake_case__        =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES



						def __init__(self:					List[str] ,					__UpperCAmelCase:					List[Any]=chr(__UpperCAmelCase   ) ,					__UpperCAmelCase:					Tuple=chr(__UpperCAmelCase   ) ,					__UpperCAmelCase:					str=chr(__UpperCAmelCase   ) ,					__UpperCAmelCase:					Optional[int]=chr(__UpperCAmelCase   ) ,					__UpperCAmelCase:					Tuple=chr(__UpperCAmelCase   ) ,					__UpperCAmelCase:					List[str]=chr(__UpperCAmelCase   ) ,					__UpperCAmelCase:					Union[str, Any]=False ,					__UpperCAmelCase:					Optional[int]=2048 ,					**__UpperCAmelCase:					Optional[Any] ,					)    ->     Dict:




											'''simple docstring'''



											__a					:						Dict      =					AddedToken(__UpperCAmelCase ,					lstrip=__UpperCAmelCase ,					rstrip=__UpperCAmelCase   ) if isinstance(__UpperCAmelCase ,					__UpperCAmelCase   ) else bos_token
											__a					:						Any      =					AddedToken(__UpperCAmelCase ,					lstrip=__UpperCAmelCase ,					rstrip=__UpperCAmelCase   ) if isinstance(__UpperCAmelCase ,					__UpperCAmelCase   ) else eos_token
											__a					:						Dict      =					AddedToken(__UpperCAmelCase ,					lstrip=__UpperCAmelCase ,					rstrip=__UpperCAmelCase   ) if isinstance(__UpperCAmelCase ,					__UpperCAmelCase   ) else sep_token
											__a					:						Union[str, Any]      =					AddedToken(__UpperCAmelCase ,					lstrip=__UpperCAmelCase ,					rstrip=__UpperCAmelCase   ) if isinstance(__UpperCAmelCase ,					__UpperCAmelCase   ) else cls_token
											__a					:						Tuple      =					AddedToken(__UpperCAmelCase ,					lstrip=__UpperCAmelCase ,					rstrip=__UpperCAmelCase   ) if isinstance(__UpperCAmelCase ,					__UpperCAmelCase   ) else pad_token

											# Mask token behave like a normal word, i.e. include the space before it
											__a					:						Any      =					AddedToken(__UpperCAmelCase ,					lstrip=__UpperCAmelCase ,					rstrip=__UpperCAmelCase   ) if isinstance(__UpperCAmelCase ,					__UpperCAmelCase   ) else mask_token

											super().__init__(
											    bos_token=__UpperCAmelCase ,					eos_token=__UpperCAmelCase ,					sep_token=__UpperCAmelCase ,					cls_token=__UpperCAmelCase ,					pad_token=__UpperCAmelCase ,					mask_token=__UpperCAmelCase ,					add_prefix_space=__UpperCAmelCase ,					model_max_length=__UpperCAmelCase ,					**__UpperCAmelCase ,					)

											# Creates a mapping for looking up the IDs of special symbols.
											__a					:						Dict[str, int]      =					{}
											for codepoint, name in SPECIAL_CODEPOINTS.items():
																__a					:						Any      =					codepoint

											# Creates a mapping for looking up the string forms of special symbol IDs.
											__a					:						Dict[int, str]      =					{
											    codepoint: name for name, codepoint in self._special_codepoints.items()
											}

											__a					:						Tuple      =					UNICODE_VOCAB_SIZE
											__a					:						Union[str, Any]      =					len(self._special_codepoints   )



						@property
						def        UpperCAmelCase__					(self:					Union[str, Any]   )    ->     int:




											'''simple docstring'''



											return self._unicode_vocab_size



						def        UpperCAmelCase__					(self:					Union[str, Any] ,					__UpperCAmelCase:					str   )    ->     List[str]:




											'''simple docstring'''



											return list(__UpperCAmelCase   )



						def        UpperCAmelCase__					(self:					Optional[int] ,					__UpperCAmelCase:					str   )    ->     int:




											'''simple docstring'''



											try:
																return ord(__UpperCAmelCase   )
											except TypeError:
																raise ValueError(f'invalid token: \'{token}\''   )



						def        UpperCAmelCase__					(self:					List[str] ,					__UpperCAmelCase:					int   )    ->     str:




											'''simple docstring'''



											try:
																if index in SPECIAL_CODEPOINTS:
																					return SPECIAL_CODEPOINTS[index]
																return chr(__UpperCAmelCase   )
											except TypeError:
																raise ValueError(f'invalid id: {index}'   )



						def        UpperCAmelCase__					(self:					Tuple ,					__UpperCAmelCase:					Optional[int]   )    ->     List[Any]:




											'''simple docstring'''



											return "".join(__UpperCAmelCase   )



						def        UpperCAmelCase__					(self:					Tuple ,					__UpperCAmelCase:					List[int] ,					__UpperCAmelCase:					Optional[List[int]] = None   )    ->     List[int]:




											'''simple docstring'''



											__a					:						Union[str, Any]      =					[self.sep_token_id]
											__a					:						Any      =					[self.cls_token_id]

											__a					:						str      =					cls + token_ids_a + sep
											if token_ids_a is not None:
																result += token_ids_a + sep
											return result



						def        UpperCAmelCase__					(self:					List[str] ,					__UpperCAmelCase:					List[int] ,					__UpperCAmelCase:					Optional[List[int]] = None ,					__UpperCAmelCase:					bool = False   )    ->     List[int]:




											'''simple docstring'''



											if already_has_special_tokens:
																return super().get_special_tokens_mask(
																    token_ids_a=__UpperCAmelCase ,					token_ids_a=__UpperCAmelCase ,					already_has_special_tokens=__UpperCAmelCase   )

											__a					:						List[str]      =					[1] + ([0] * len(__UpperCAmelCase   )) + [1]
											if token_ids_a is not None:
																result += ([0] * len(__UpperCAmelCase   )) + [1]
											return result



						def        UpperCAmelCase__					(self:					List[str] ,					__UpperCAmelCase:					List[int] ,					__UpperCAmelCase:					Optional[List[int]] = None   )    ->     List[int]:




											'''simple docstring'''



											__a					:						str      =					[self.sep_token_id]
											__a					:						Any      =					[self.cls_token_id]

											__a					:						Dict      =					len(cls + token_ids_a + sep   ) * [0]
											if token_ids_a is not None:
																result += len(token_ids_a + sep   ) * [1]
											return result



						def        UpperCAmelCase__					(self:					Optional[Any] ,					__UpperCAmelCase:					str ,					__UpperCAmelCase:					Optional[str] = None   )    ->     int:




											'''simple docstring'''



											return ()













from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
			import tensorflow as tf

			from transformers import TFBlipTextModel
			from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST




class 							snake_case_       :

						"""simple docstring"""



						def __init__(self:					Optional[Any] ,					__UpperCAmelCase:					List[str] ,					__UpperCAmelCase:					int=12 ,					__UpperCAmelCase:					Dict=7 ,					__UpperCAmelCase:					str=True ,					__UpperCAmelCase:					Tuple=True ,					__UpperCAmelCase:					Tuple=True ,					__UpperCAmelCase:					Optional[int]=99 ,					__UpperCAmelCase:					str=32 ,					__UpperCAmelCase:					Any=32 ,					__UpperCAmelCase:					int=2 ,					__UpperCAmelCase:					List[str]=4 ,					__UpperCAmelCase:					Tuple=37 ,					__UpperCAmelCase:					Optional[int]=0.1 ,					__UpperCAmelCase:					List[Any]=0.1 ,					__UpperCAmelCase:					Dict=512 ,					__UpperCAmelCase:					Union[str, Any]=0.02 ,					__UpperCAmelCase:					List[Any]=0 ,					__UpperCAmelCase:					str=None ,					)    ->     Tuple:




											'''simple docstring'''



											__a					:						Union[str, Any]      =					parent
											__a					:						Dict      =					batch_size
											__a					:						Optional[Any]      =					seq_length
											__a					:						int      =					is_training
											__a					:						Union[str, Any]      =					use_input_mask
											__a					:						str      =					use_labels
											__a					:						Tuple      =					vocab_size
											__a					:						Dict      =					hidden_size
											__a					:						Optional[int]      =					projection_dim
											__a					:						Tuple      =					num_hidden_layers
											__a					:						Dict      =					num_attention_heads
											__a					:						Any      =					intermediate_size
											__a					:						Optional[int]      =					dropout
											__a					:						Dict      =					attention_dropout
											__a					:						List[Any]      =					max_position_embeddings
											__a					:						Any      =					initializer_range
											__a					:						Tuple      =					scope
											__a					:						Dict      =					bos_token_id



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




											'''simple docstring'''



											__a					:						Optional[Any]      =					ids_tensor([self.batch_size, self.seq_length] ,					self.vocab_size   )

											__a					:						Any      =					None
											if self.use_input_mask:
																__a					:						Tuple      =					random_attention_mask([self.batch_size, self.seq_length]   )

											if input_mask is not None:
																__a					:						Tuple      =					input_mask.numpy()
																__a      ,			__a					:						int      =					input_mask.shape
																__a					:						Dict      =					np.random.randint(1 ,					seq_length - 1 ,					size=(batch_size,)   )
																for batch_idx, start_index in enumerate(__UpperCAmelCase   ):
																					__a					:						Any      =					1
																					__a					:						int      =					0

											__a					:						Union[str, Any]      =					self.get_config()

											return config, input_ids, tf.convert_to_tensor(__UpperCAmelCase   )



						def        UpperCAmelCase__					(self:					List[str]   )    ->     Optional[int]:




											'''simple docstring'''



											return BlipTextConfig(
											    vocab_size=self.vocab_size ,					hidden_size=self.hidden_size ,					projection_dim=self.projection_dim ,					num_hidden_layers=self.num_hidden_layers ,					num_attention_heads=self.num_attention_heads ,					intermediate_size=self.intermediate_size ,					dropout=self.dropout ,					attention_dropout=self.attention_dropout ,					max_position_embeddings=self.max_position_embeddings ,					initializer_range=self.initializer_range ,					bos_token_id=self.bos_token_id ,					)



						def        UpperCAmelCase__					(self:					List[str] ,					__UpperCAmelCase:					Any ,					__UpperCAmelCase:					Dict ,					__UpperCAmelCase:					str   )    ->     List[str]:




											'''simple docstring'''



											__a					:						int      =					TFBlipTextModel(config=__UpperCAmelCase   )
											__a					:						List[str]      =					model(__UpperCAmelCase ,					attention_mask=__UpperCAmelCase ,					training=__UpperCAmelCase   )
											__a					:						Any      =					model(__UpperCAmelCase ,					training=__UpperCAmelCase   )
											self.parent.assertEqual(result.last_hidden_state.shape ,					(self.batch_size, self.seq_length, self.hidden_size)   )
											self.parent.assertEqual(result.pooler_output.shape ,					(self.batch_size, self.hidden_size)   )



						def        UpperCAmelCase__					(self:					List[str]   )    ->     str:




											'''simple docstring'''



											__a					:						Tuple      =					self.prepare_config_and_inputs()
											__a      ,			__a      ,			__a					:						Dict      =					config_and_inputs
											__a					:						Union[str, Any]      =					{"input_ids": input_ids, "attention_mask": input_mask}
											return config, inputs_dict




@require_tf
class 							snake_case_       (    __UpperCamelCase		,							unittest.TestCase      ):

						"""simple docstring"""



						snake_case__        =      (TFBlipTextModel,) if is_tf_available() else ()
						snake_case__        =      False
						snake_case__        =      False
						snake_case__        =      False



						def        UpperCAmelCase__					(self:					List[str]   )    ->     Optional[int]:




											'''simple docstring'''



											__a					:						str      =					BlipTextModelTester(self   )
											__a					:						str      =					ConfigTester(self ,					config_class=__UpperCAmelCase ,					hidden_size=37   )



						def        UpperCAmelCase__					(self:					str   )    ->     str:




											'''simple docstring'''



											self.config_tester.run_common_tests()



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




											'''simple docstring'''



											__a					:						int      =					self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__UpperCAmelCase   )



						def        UpperCAmelCase__					(self:					Tuple   )    ->     Dict:




											'''simple docstring'''



											pass



						def        UpperCAmelCase__					(self:					Union[str, Any]   )    ->     Optional[int]:




											'''simple docstring'''



											pass



						@unittest.skip(reason="Blip does not use inputs_embeds"   )
						def        UpperCAmelCase__					(self:					Any   )    ->     Dict:




											'''simple docstring'''



											pass



						@unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"   )
						def        UpperCAmelCase__					(self:					List[Any]   )    ->     List[str]:




											'''simple docstring'''



											pass



						@unittest.skip(reason="BlipTextModel has no base class and is not available in MODEL_MAPPING"   )
						def        UpperCAmelCase__					(self:					Union[str, Any]   )    ->     int:




											'''simple docstring'''



											pass



						@slow
						def        UpperCAmelCase__					(self:					Optional[Any]   )    ->     Tuple:




											'''simple docstring'''



											for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__a					:						List[str]      =					TFBlipTextModel.from_pretrained(__UpperCAmelCase   )
																self.assertIsNotNone(__UpperCAmelCase   )



						def        UpperCAmelCase__					(self:					Dict ,					__UpperCAmelCase:					Optional[Any]=True   )    ->     Any:




											'''simple docstring'''



											super().test_pt_tf_model_equivalence(allow_missing_keys=__UpperCAmelCase   )





