





"""simple docstring"""




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  __UpperCamelCase       :






							def __init__(     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__=12   ,      lowerCAmelCase__=7   ,      lowerCAmelCase__=True   ,      lowerCAmelCase__=True   ,      lowerCAmelCase__=True   ,      lowerCAmelCase__=99   ,      lowerCAmelCase__=32   ,      lowerCAmelCase__=32   ,      lowerCAmelCase__=2   ,      lowerCAmelCase__=4   ,      lowerCAmelCase__=37   ,      lowerCAmelCase__=0.1   ,      lowerCAmelCase__=0.1   ,      lowerCAmelCase__=512   ,      lowerCAmelCase__=0.02   ,      lowerCAmelCase__=0   ,      lowerCAmelCase__=None   ,      )			->				List[Any]:
								a   :	List[str]			=       parent
								a   :	Dict			=       batch_size
								a   :	List[Any]			=       seq_length
								a   :	int			=       is_training
								a   :	str			=       use_input_mask
								a   :	str			=       use_labels
								a   :	Dict			=       vocab_size
								a   :	Tuple			=       hidden_size
								a   :	Tuple			=       projection_dim
								a   :	List[str]			=       num_hidden_layers
								a   :	Dict			=       num_attention_heads
								a   :	str			=       intermediate_size
								a   :	str			=       dropout
								a   :	Union[str, Any]			=       attention_dropout
								a   :	Optional[int]			=       max_position_embeddings
								a   :	Union[str, Any]			=       initializer_range
								a   :	Dict			=       scope
								a   :	Union[str, Any]			=       bos_token_id






							def 					__a     (     self   )			->				Dict:
								a   :	List[str]			=       ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size   )

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

								if input_mask is not None:
									a   :	Dict			=       input_mask.numpy()
									a, a   :	Union[str, Any]			=       input_mask.shape
									a   :	str			=       np.random.randint(1   ,      seq_length - 1   ,      size=(batch_size,)   )
									for batch_idx, start_index in enumerate(lowerCAmelCase__   ):
										a   :	Optional[int]			=       1
										a   :	Union[str, Any]			=       0

								a   :	int			=       self.get_config()

								return config, input_ids, tf.convert_to_tensor(lowerCAmelCase__   )






							def 					__a     (     self   )			->				str:
								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 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__   ,      lowerCAmelCase__   )			->				Optional[Any]:
								a   :	List[Any]			=       TFBlipTextModel(config=lowerCAmelCase__   )
								a   :	Tuple			=       model(lowerCAmelCase__   ,      attention_mask=lowerCAmelCase__   ,      training=lowerCAmelCase__   )
								a   :	List[str]			=       model(lowerCAmelCase__   ,      training=lowerCAmelCase__   )
								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 					__a     (     self   )			->				Optional[Any]:
								a   :	Optional[Any]			=       self.prepare_config_and_inputs()
								a, a, a   :	Tuple			=       config_and_inputs
								a   :	Any			=       {"input_ids": input_ids, "attention_mask": input_mask}
								return config, inputs_dict


@require_tf
class  __UpperCamelCase       (		a__	, unittest.TestCase		):
							lowerCamelCase     :      int         =(TFBlipTextModel,) if is_tf_available() else ()
							lowerCamelCase     :      Any         =False
							lowerCamelCase     :      Union[str, Any]         =False
							lowerCamelCase     :      Any         =False






							def 					__a     (     self   )			->				Optional[Any]:
								a   :	Any			=       BlipTextModelTester(self   )
								a   :	Dict			=       ConfigTester(self   ,      config_class=lowerCAmelCase__   ,      hidden_size=37   )






							def 					__a     (     self   )			->				Optional[int]:
								self.config_tester.run_common_tests()






							def 					__a     (     self   )			->				List[str]:
								a   :	Any			=       self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*lowerCAmelCase__   )






							def 					__a     (     self   )			->				Dict:
								pass






							def 					__a     (     self   )			->				Tuple:
								pass






							@unittest.skip(reason="Blip does not use inputs_embeds"   )
							def 					__a     (     self   )			->				Optional[Any]:
								pass






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






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






							@slow
							def 					__a     (     self   )			->				Optional[int]:
								for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									a   :	Tuple			=       TFBlipTextModel.from_pretrained(lowerCAmelCase__   )
									self.assertIsNotNone(lowerCAmelCase__   )






							def 					__a     (     self   ,      lowerCAmelCase__=True   )			->				Any:
								super().test_pt_tf_model_equivalence(allow_missing_keys=lowerCAmelCase__   )









"""simple docstring"""




import os
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
		from .tokenization_albert import AlbertTokenizer
else:
		a		:				Tuple  			=    None

a		:				Any  			=    logging.get_logger(__name__)
a		:				List[Any]  			=    {'''vocab_file''': '''spiece.model''', '''tokenizer_file''': '''tokenizer.json'''}

a		:				str  			=    {
    '''vocab_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/spiece.model''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/spiece.model''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/spiece.model''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/spiece.model''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model''',
    },
    '''tokenizer_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/tokenizer.json''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/tokenizer.json''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/tokenizer.json''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/tokenizer.json''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/tokenizer.json''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/tokenizer.json''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/tokenizer.json''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/tokenizer.json''',
    },
}

a		:				str  			=    {
    '''albert-base-v1''': 512,
    '''albert-large-v1''': 512,
    '''albert-xlarge-v1''': 512,
    '''albert-xxlarge-v1''': 512,
    '''albert-base-v2''': 512,
    '''albert-large-v2''': 512,
    '''albert-xlarge-v2''': 512,
    '''albert-xxlarge-v2''': 512,
}

a		:				Union[str, Any]  			=    '''▁'''


class  __UpperCamelCase       (		a__		):
							lowerCamelCase     :      Union[str, Any]         =VOCAB_FILES_NAMES
							lowerCamelCase     :      Dict         =PRETRAINED_VOCAB_FILES_MAP
							lowerCamelCase     :      List[Any]         =PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							lowerCamelCase     :      List[Any]         =AlbertTokenizer






							def __init__(     self   ,      lowerCAmelCase__=None   ,      lowerCAmelCase__=None   ,      lowerCAmelCase__=True   ,      lowerCAmelCase__=True   ,      lowerCAmelCase__=False   ,      lowerCAmelCase__="[CLS]"   ,      lowerCAmelCase__="[SEP]"   ,      lowerCAmelCase__="<unk>"   ,      lowerCAmelCase__="[SEP]"   ,      lowerCAmelCase__="<pad>"   ,      lowerCAmelCase__="[CLS]"   ,      lowerCAmelCase__="[MASK]"   ,      **lowerCAmelCase__   ,      )			->				Union[str, Any]:
								# Mask token behave like a normal word, i.e. include the space before it and
								# is included in the raw text, there should be a match in a non-normalized sentence.
								a   :	Optional[int]			=       (
								    AddedToken(lowerCAmelCase__   ,      lstrip=lowerCAmelCase__   ,      rstrip=lowerCAmelCase__   ,      normalized=lowerCAmelCase__   )
								    if isinstance(lowerCAmelCase__   ,      lowerCAmelCase__   )
								    else mask_token
								)

								super().__init__(
								    lowerCAmelCase__   ,      tokenizer_file=lowerCAmelCase__   ,      do_lower_case=lowerCAmelCase__   ,      remove_space=lowerCAmelCase__   ,      keep_accents=lowerCAmelCase__   ,      bos_token=lowerCAmelCase__   ,      eos_token=lowerCAmelCase__   ,      unk_token=lowerCAmelCase__   ,      sep_token=lowerCAmelCase__   ,      pad_token=lowerCAmelCase__   ,      cls_token=lowerCAmelCase__   ,      mask_token=lowerCAmelCase__   ,      **lowerCAmelCase__   ,      )

								a   :	Dict			=       do_lower_case
								a   :	Any			=       remove_space
								a   :	Optional[Any]			=       keep_accents
								a   :	List[str]			=       vocab_file
								a   :	Optional[Any]			=       False if not self.vocab_file else True






							def 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__ = None   )			->				List[int]:
								a   :	Optional[Any]			=       [self.sep_token_id]
								a   :	int			=       [self.cls_token_id]
								if token_ids_a is None:
									return cls + token_ids_a + sep
								return cls + token_ids_a + sep + token_ids_a + sep






							def 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__ = None   )			->				List[int]:
								a   :	Optional[Any]			=       [self.sep_token_id]
								a   :	int			=       [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 					__a     (     self   ,      lowerCAmelCase__   ,      lowerCAmelCase__ = None   )			->				Tuple[str]:
								if not self.can_save_slow_tokenizer:
									raise ValueError(
									    "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
									    "tokenizer."   )

								if not os.path.isdir(lowerCAmelCase__   ):
									logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""   )
									return
								a   :	Dict			=       os.path.join(
								    lowerCAmelCase__   ,      (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]   )

								if os.path.abspath(self.vocab_file   ) != os.path.abspath(lowerCAmelCase__   ):
									copyfile(self.vocab_file   ,      lowerCAmelCase__   )

								return (out_vocab_file,)


