






"""simple docstring"""



import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_torch, slow, torch_device
from transformers.utils import is_torch_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask


if is_torch_available():
						import torch

						from transformers import BlipTextModel
						from transformers.models.blip.modeling_blip import BLIP_PRETRAINED_MODEL_ARCHIVE_LIST




class        __lowercase:






						def __init__(					self    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE=12    ,						_SCREAMING_SNAKE_CASE=7    ,						_SCREAMING_SNAKE_CASE=True    ,						_SCREAMING_SNAKE_CASE=True    ,						_SCREAMING_SNAKE_CASE=True    ,						_SCREAMING_SNAKE_CASE=99    ,						_SCREAMING_SNAKE_CASE=32    ,						_SCREAMING_SNAKE_CASE=32    ,						_SCREAMING_SNAKE_CASE=5    ,						_SCREAMING_SNAKE_CASE=4    ,						_SCREAMING_SNAKE_CASE=37    ,						_SCREAMING_SNAKE_CASE=0.1    ,						_SCREAMING_SNAKE_CASE=0.1    ,						_SCREAMING_SNAKE_CASE=5_12    ,						_SCREAMING_SNAKE_CASE=0.02    ,						_SCREAMING_SNAKE_CASE=0    ,						_SCREAMING_SNAKE_CASE=None    ,						)			->  Dict:




											"""simple docstring"""





											lowerCamelCase__				=parent
											lowerCamelCase__				=batch_size
											lowerCamelCase__				=seq_length
											lowerCamelCase__				=is_training
											lowerCamelCase__				=use_input_mask
											lowerCamelCase__				=use_labels
											lowerCamelCase__				=vocab_size
											lowerCamelCase__				=hidden_size
											lowerCamelCase__				=projection_dim
											lowerCamelCase__				=num_hidden_layers
											lowerCamelCase__				=num_attention_heads
											lowerCamelCase__				=intermediate_size
											lowerCamelCase__				=dropout
											lowerCamelCase__				=attention_dropout
											lowerCamelCase__				=max_position_embeddings
											lowerCamelCase__				=initializer_range
											lowerCamelCase__				=scope
											lowerCamelCase__				=bos_token_id






						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											lowerCamelCase__				=ids_tensor([self.batch_size, self.seq_length]    ,						self.vocab_size)

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

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

											lowerCamelCase__				=self.get_config()

											return config, input_ids, input_mask






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




											"""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 		lowerCAmelCase   (					self    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE    ,						_SCREAMING_SNAKE_CASE)			->  Optional[Any]:




											"""simple docstring"""





											lowerCamelCase__				=BlipTextModel(config=_SCREAMING_SNAKE_CASE)
											model.to(_SCREAMING_SNAKE_CASE)
											model.eval()
											with torch.no_grad():
																lowerCamelCase__				=model(_SCREAMING_SNAKE_CASE    ,						attention_mask=_SCREAMING_SNAKE_CASE)
																lowerCamelCase__				=model(_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 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											lowerCamelCase__				=self.prepare_config_and_inputs()
											lowerCamelCase__				,     lowerCamelCase__				,     lowerCamelCase__				=config_and_inputs
											lowerCamelCase__				={'input_ids': input_ids, 'attention_mask': input_mask}
											return config, inputs_dict




@require_torch
class        __lowercase(       _UpperCamelCase						,							unittest.TestCase  ):
						lowerCAmelCase_		:							Optional[Any]=       (BlipTextModel,) if is_torch_available() else ()
						lowerCAmelCase_		:							Optional[int]=       False
						lowerCAmelCase_		:							Any=       False
						lowerCAmelCase_		:							Dict=       False






						def 		lowerCAmelCase   (					self)			->  Optional[Any]:




											"""simple docstring"""





											lowerCamelCase__				=BlipTextModelTester(self)
											lowerCamelCase__				=ConfigTester(self    ,						config_class=_SCREAMING_SNAKE_CASE    ,						hidden_size=37)






						def 		lowerCAmelCase   (					self)			->  Dict:




											"""simple docstring"""





											self.config_tester.run_common_tests()






						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											lowerCamelCase__				=self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE)






						def 		lowerCAmelCase   (					self)			->  Optional[int]:




											"""simple docstring"""





											pass






						def 		lowerCAmelCase   (					self)			->  str:




											"""simple docstring"""





											pass






						@unittest.skip(reason='Blip does not use inputs_embeds')
						def 		lowerCAmelCase   (					self)			->  List[Any]:




											"""simple docstring"""





											pass






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




											"""simple docstring"""





											pass






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




											"""simple docstring"""





											pass






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




											"""simple docstring"""





											for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																lowerCamelCase__				=BlipTextModel.from_pretrained(_SCREAMING_SNAKE_CASE)
																self.assertIsNotNone(_SCREAMING_SNAKE_CASE)






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




											"""simple docstring"""





											super().test_pt_tf_model_equivalence(allow_missing_keys=_SCREAMING_SNAKE_CASE)







"""simple docstring"""



_snake_case       :      Dict       =					[0.485, 0.456, 0.406]
_snake_case       :      int       =					[0.229, 0.224, 0.225]
_snake_case       :      Optional[int]       =					[0.5, 0.5, 0.5]
_snake_case       :      str       =					[0.5, 0.5, 0.5]
_snake_case       :      str       =					[0.4814_5466, 0.457_8275, 0.4082_1073]
_snake_case       :      str       =					[0.2686_2954, 0.2613_0258, 0.2757_7711]