

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 :				Dict							,   _UpperCamelCase :				List[Any]							,   _UpperCamelCase :				str=1_2							,   _UpperCamelCase :				Optional[Any]=7							,   _UpperCamelCase :				Optional[int]=True							,   _UpperCamelCase :				Union[str, Any]=True							,   _UpperCamelCase :				Optional[int]=True							,   _UpperCamelCase :				Dict=9_9							,   _UpperCamelCase :				Union[str, Any]=3_2							,   _UpperCamelCase :				Dict=3_2							,   _UpperCamelCase :				Dict=2							,   _UpperCamelCase :				Tuple=4							,   _UpperCamelCase :				Optional[int]=3_7							,   _UpperCamelCase :				Tuple=0.1							,   _UpperCamelCase :				Union[str, Any]=0.1							,   _UpperCamelCase :				Optional[Any]=5_1_2							,   _UpperCamelCase :				Tuple=0.02							,   _UpperCamelCase :				Union[str, Any]=0							,   _UpperCamelCase :				Optional[int]=None							,   )      ->int:
									snake_case_   =	parent
									snake_case_   =	batch_size
									snake_case_   =	seq_length
									snake_case_   =	is_training
									snake_case_   =	use_input_mask
									snake_case_   =	use_labels
									snake_case_   =	vocab_size
									snake_case_   =	hidden_size
									snake_case_   =	projection_dim
									snake_case_   =	num_hidden_layers
									snake_case_   =	num_attention_heads
									snake_case_   =	intermediate_size
									snake_case_   =	dropout
									snake_case_   =	attention_dropout
									snake_case_   =	max_position_embeddings
									snake_case_   =	initializer_range
									snake_case_   =	scope
									snake_case_   =	bos_token_id







			def 				snake_case__(     self :				List[Any]							)      ->Union[str, Any]:
									snake_case_   =	ids_tensor([self.batch_size, self.seq_length]							,   self.vocab_size							)

									snake_case_   =	None
									if self.use_input_mask:
															snake_case_   =	random_attention_mask([self.batch_size, self.seq_length]							)

									if input_mask is not None:
															snake_case_   =	input_mask.numpy()
															snake_case_,    snake_case_   =	input_mask.shape
															snake_case_   =	np.random.randint(1							,   seq_length - 1							,   size=(batch_size,)							)
															for batch_idx, start_index in enumerate(_UpperCamelCase							):
																					snake_case_   =	1
																					snake_case_   =	0

									snake_case_   =	self.get_config()

									return config, input_ids, tf.convert_to_tensor(_UpperCamelCase							)







			def 				snake_case__(     self :				str							)      ->Optional[int]:
									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 				snake_case__(     self :				List[Any]							,   _UpperCamelCase :				List[Any]							,   _UpperCamelCase :				Union[str, Any]							,   _UpperCamelCase :				Dict							)      ->Any:
									snake_case_   =	TFBlipTextModel(config=_UpperCamelCase							)
									snake_case_   =	model(_UpperCamelCase							,   attention_mask=_UpperCamelCase							,   training=_UpperCamelCase							)
									snake_case_   =	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 				snake_case__(     self :				str							)      ->Union[str, Any]:
									snake_case_   =	self.prepare_config_and_inputs()
									snake_case_,    snake_case_,    snake_case_   =	config_and_inputs
									snake_case_   =	{'''input_ids''': input_ids, '''attention_mask''': input_mask}
									return config, inputs_dict






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







			'''simple docstring'''

			SCREAMING_SNAKE_CASE     :   List[Any]									=				(TFBlipTextModel,) if is_tf_available() else ()
			SCREAMING_SNAKE_CASE     :   Any									=				False
			SCREAMING_SNAKE_CASE     :   Optional[Any]									=				False
			SCREAMING_SNAKE_CASE     :   str									=				False







			def 				snake_case__(     self :				Union[str, Any]							)      ->Dict:
									snake_case_   =	BlipTextModelTester(self							)
									snake_case_   =	ConfigTester(self							,   config_class=_UpperCamelCase							,   hidden_size=3_7							)







			def 				snake_case__(     self :				int							)      ->Union[str, Any]:
									self.config_tester.run_common_tests()







			def 				snake_case__(     self :				Dict							)      ->Any:
									snake_case_   =	self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_UpperCamelCase							)







			def 				snake_case__(     self :				Any							)      ->int:
									pass







			def 				snake_case__(     self :				int							)      ->List[Any]:
									pass







			@unittest.skip(reason='''Blip does not use inputs_embeds'''							)
			def 				snake_case__(     self :				Optional[int]							)      ->Dict:
									pass







			@unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''							)
			def 				snake_case__(     self :				Tuple							)      ->int:
									pass







			@unittest.skip(reason='''BlipTextModel has no base class and is not available in MODEL_MAPPING'''							)
			def 				snake_case__(     self :				int							)      ->int:
									pass







			@slow
			def 				snake_case__(     self :				str							)      ->str:
									for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															snake_case_   =	TFBlipTextModel.from_pretrained(_UpperCamelCase							)
															self.assertIsNotNone(_UpperCamelCase							)







			def 				snake_case__(     self :				List[str]							,   _UpperCamelCase :				Tuple=True							)      ->Optional[int]:
									super().test_pt_tf_model_equivalence(allow_missing_keys=_UpperCamelCase							)


from collections import deque

from .hash_table import HashTable





class 	snake_case_   (		__A					):







			'''simple docstring'''

			def __init__(     self :				int							,   *_UpperCamelCase :				int							,   **_UpperCamelCase :				Tuple							)      ->Tuple:
									super().__init__(*_UpperCamelCase							,   **_UpperCamelCase							)







			def 				snake_case__(     self :				Dict							,   _UpperCamelCase :				List[str]							,   _UpperCamelCase :				Dict							)      ->Tuple:
									snake_case_   =	deque([]							) if self.values[key] is None else self.values[key]
									self.values[key].appendleft(_UpperCamelCase							)
									snake_case_   =	self.values[key]







			def 				snake_case__(     self :				List[Any]							)      ->str:
									return (
									    sum(self.charge_factor - len(_UpperCamelCase							) for slot in self.values							)
									    / self.size_table
									    * self.charge_factor
									)







			def 				snake_case__(     self :				Dict							,   _UpperCamelCase :				Union[str, Any]							,   _UpperCamelCase :				Optional[int]=None							)      ->str:
									if not (
									    len(self.values[key]							) == self.charge_factor and self.values.count(_UpperCamelCase							) == 0
									):
															return key
									return super()._collision_resolution(_UpperCamelCase							,   _UpperCamelCase							)