




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    snake_case__							:
	"""simple docstring"""



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





	def 							__UpperCAmelCase							(				self    :					Any							) ->					List[Any]:
				a   =      ids_tensor([self.batch_size, self.seq_length] ,				self.vocab_size							)

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

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

				a   =      self.get_config()

				return config, input_ids, input_mask





	def 							__UpperCAmelCase							(				self    :					str							) ->					Tuple:
				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] ,				__lowerCamelCase    :					Optional[Any] ,				__lowerCamelCase    :					str ,				__lowerCamelCase    :					Any							) ->					Any:
				a   =      BlipTextModel(config=__lowerCamelCase							)
				model.to(__lowerCamelCase							)
				model.eval()
				with torch.no_grad():
							a   =      model(__lowerCamelCase ,				attention_mask=__lowerCamelCase							)
							a   =      model(__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 							__UpperCAmelCase							(				self    :					List[Any]							) ->					List[Any]:
				a   =      self.prepare_config_and_inputs()
				a   ,		a   ,		a   =      config_and_inputs
				a   =      {"input_ids": input_ids, "attention_mask": input_mask}
				return config, inputs_dict




@require_torch
class    snake_case__							(_UpperCamelCase   ,	unittest.TestCase       ):
	"""simple docstring"""



	SCREAMING_SNAKE_CASE_	:							Dict										= (BlipTextModel,) if is_torch_available() else ()
	SCREAMING_SNAKE_CASE_	:							Dict										= False
	SCREAMING_SNAKE_CASE_	:							Union[str, Any]										= False
	SCREAMING_SNAKE_CASE_	:							int										= False





	def 							__UpperCAmelCase							(				self    :					Union[str, Any]							) ->					List[str]:
				a   =      BlipTextModelTester(self							)
				a   =      ConfigTester(self ,				config_class=__lowerCamelCase ,				hidden_size=37							)





	def 							__UpperCAmelCase							(				self    :					Optional[int]							) ->					List[str]:
				self.config_tester.run_common_tests()





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





	def 							__UpperCAmelCase							(				self    :					Optional[Any]							) ->					List[Any]:
				pass





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





	@unittest.skip(reason="Blip does not use inputs_embeds"							)
	def 							__UpperCAmelCase							(				self    :					List[str]							) ->					List[str]:
				pass





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





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





	@slow
	def 							__UpperCAmelCase							(				self    :					Optional[int]							) ->					Optional[int]:
				for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							a   =      BlipTextModel.from_pretrained(__lowerCamelCase							)
							self.assertIsNotNone(__lowerCamelCase							)





	def 							__UpperCAmelCase							(				self    :					Union[str, Any]							) ->					Optional[int]:
				super().test_pt_tf_model_equivalence(allow_missing_keys=__lowerCamelCase							)












from ..utils import DummyObject, requires_backends




class    snake_case__							(metaclass=_UpperCamelCase       ):
				"""simple docstring"""



				SCREAMING_SNAKE_CASE_	:							List[str]										= ["""torch""", """transformers""", """k_diffusion"""]





				def __init__(				self    :					Optional[int] ,				*__lowerCamelCase    :					Union[str, Any] ,				**__lowerCamelCase    :					List[Any]							) ->					Optional[Any]:
							requires_backends(self ,				["torch", "transformers", "k_diffusion"]							)





				@classmethod
				def 							__UpperCAmelCase							(				cls    :					str ,				*__lowerCamelCase    :					Union[str, Any] ,				**__lowerCamelCase    :					Tuple							) ->					List[Any]:
							requires_backends(cls ,				["torch", "transformers", "k_diffusion"]							)





				@classmethod
				def 							__UpperCAmelCase							(				cls    :					Optional[Any] ,				*__lowerCamelCase    :					List[str] ,				**__lowerCamelCase    :					int							) ->					Dict:
							requires_backends(cls ,				["torch", "transformers", "k_diffusion"]							)






