


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						:		Tuple  ,     SCREAMING_SNAKE_CASE						:		Optional[int]  ,     SCREAMING_SNAKE_CASE						:		Any=1_2  ,     SCREAMING_SNAKE_CASE						:		Optional[int]=7  ,     SCREAMING_SNAKE_CASE						:		List[str]=True  ,     SCREAMING_SNAKE_CASE						:		int=True  ,     SCREAMING_SNAKE_CASE						:		Optional[Any]=True  ,     SCREAMING_SNAKE_CASE						:		Dict=9_9  ,     SCREAMING_SNAKE_CASE						:		Optional[int]=3_2  ,     SCREAMING_SNAKE_CASE						:		int=3_2  ,     SCREAMING_SNAKE_CASE						:		Tuple=2  ,     SCREAMING_SNAKE_CASE						:		Any=4  ,     SCREAMING_SNAKE_CASE						:		Union[str, Any]=3_7  ,     SCREAMING_SNAKE_CASE						:		List[str]=0.1  ,     SCREAMING_SNAKE_CASE						:		Tuple=0.1  ,     SCREAMING_SNAKE_CASE						:		List[Any]=5_1_2  ,     SCREAMING_SNAKE_CASE						:		List[Any]=0.02  ,     SCREAMING_SNAKE_CASE						:		int=0  ,     SCREAMING_SNAKE_CASE						:		Dict=None  ,     )      ->						Dict:




											'''simple docstring'''

											__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 				SCREAMING_SNAKE_CASE_	(    self						:		int    )      ->						List[str]:




											'''simple docstring'''

											__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(SCREAMING_SNAKE_CASE    ):
																							__snake_case				=		1
																							__snake_case				=		0

											__snake_case				=		self.get_config()

											return config, input_ids, tf.convert_to_tensor(SCREAMING_SNAKE_CASE    )


					def 				SCREAMING_SNAKE_CASE_	(    self						:		Optional[Any]    )      ->						Dict:




											'''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 				SCREAMING_SNAKE_CASE_	(    self						:		List[str]  ,     SCREAMING_SNAKE_CASE						:		Tuple  ,     SCREAMING_SNAKE_CASE						:		Any  ,     SCREAMING_SNAKE_CASE						:		Any    )      ->						Any:




											'''simple docstring'''

											__snake_case				=		TFBlipTextModel(config=SCREAMING_SNAKE_CASE    )
											__snake_case				=		model(SCREAMING_SNAKE_CASE  ,     attention_mask=SCREAMING_SNAKE_CASE  ,     training=SCREAMING_SNAKE_CASE    )
											__snake_case				=		model(SCREAMING_SNAKE_CASE  ,     training=SCREAMING_SNAKE_CASE    )
											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 				SCREAMING_SNAKE_CASE_	(    self						:		List[str]    )      ->						Optional[int]:




											'''simple docstring'''

											__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      UpperCamelCase(	_a  ,				unittest.TestCase ):
					snake_case_		:					str    					=						(TFBlipTextModel,) if is_tf_available() else ()
					snake_case_		:					Optional[Any]    					=						False
					snake_case_		:					Optional[Any]    					=						False
					snake_case_		:					List[Any]    					=						False


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




											'''simple docstring'''

											__snake_case				=		BlipTextModelTester(self    )
											__snake_case				=		ConfigTester(self  ,     config_class=SCREAMING_SNAKE_CASE  ,     hidden_size=3_7    )


					def 				SCREAMING_SNAKE_CASE_	(    self						:		List[Any]    )      ->						List[str]:




											'''simple docstring'''

											self.config_tester.run_common_tests()


					def 				SCREAMING_SNAKE_CASE_	(    self						:		str    )      ->						Any:




											'''simple docstring'''

											__snake_case				=		self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE    )


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




											'''simple docstring'''

											pass


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




											'''simple docstring'''

											pass


					@unittest.skip(reason="Blip does not use inputs_embeds"    )
					def 				SCREAMING_SNAKE_CASE_	(    self						:		Optional[int]    )      ->						Tuple:




											'''simple docstring'''

											pass


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




											'''simple docstring'''

											pass


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




											'''simple docstring'''

											pass


					@slow
					def 				SCREAMING_SNAKE_CASE_	(    self						:		List[str]    )      ->						Union[str, Any]:




											'''simple docstring'''

											for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	__snake_case				=		TFBlipTextModel.from_pretrained(SCREAMING_SNAKE_CASE    )
																	self.assertIsNotNone(SCREAMING_SNAKE_CASE    )






					def 				SCREAMING_SNAKE_CASE_	(    self						:		int  ,     SCREAMING_SNAKE_CASE						:		Optional[Any]=True    )      ->						List[str]:




											'''simple docstring'''

											super().test_pt_tf_model_equivalence(allow_missing_keys=SCREAMING_SNAKE_CASE    )









A				:       Any      =  '\n# Transformers installation\n! pip install transformers datasets\n# To install from source instead of the last release, comment the command above and uncomment the following one.\n# ! pip install git+https://github.com/huggingface/transformers.git\n'

A				:       Optional[int]      =  [{'type': 'code', 'content': INSTALL_CONTENT}]
A				:       Optional[int]      =  {
    '{processor_class}': 'FakeProcessorClass',
    '{model_class}': 'FakeModelClass',
    '{object_class}': 'FakeObjectClass',
}





