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





							def __init__(			self  :       Any					,			_UpperCAmelCase  :       List[Any]					,			_UpperCAmelCase  :       Optional[Any]=12					,			_UpperCAmelCase  :       Tuple=7					,			_UpperCAmelCase  :       Optional[int]=True					,			_UpperCAmelCase  :       int=True					,			_UpperCAmelCase  :       Any=True					,			_UpperCAmelCase  :       Tuple=99					,			_UpperCAmelCase  :       Optional[int]=32					,			_UpperCAmelCase  :       str=32					,			_UpperCAmelCase  :       Tuple=5					,			_UpperCAmelCase  :       List[str]=4					,			_UpperCAmelCase  :       str=37					,			_UpperCAmelCase  :       Dict=0.1					,			_UpperCAmelCase  :       Dict=0.1					,			_UpperCAmelCase  :       str=5_12					,			_UpperCAmelCase  :       str=0.02					,			_UpperCAmelCase  :       Tuple=0					,			_UpperCAmelCase  :       Optional[Any]=None					,			)						->		str:



											"""simple docstring"""


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





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



											"""simple docstring"""


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

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

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

											__lowercase								= self.get_config()

											return config, input_ids, input_mask





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



											"""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       a__			(			self  :       Tuple					,			_UpperCAmelCase  :       Optional[int]					,			_UpperCAmelCase  :       Any					,			_UpperCAmelCase  :       str    )						->		List[Any]:



											"""simple docstring"""


											__lowercase								= BlipTextModel(config=_UpperCAmelCase    )
											model.to(_UpperCAmelCase    )
											model.eval()
											with torch.no_grad():
															__lowercase								= model(_UpperCAmelCase					,			attention_mask=_UpperCAmelCase    )
															__lowercase								= model(_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       a__			(			self  :       Tuple    )						->		int:



											"""simple docstring"""


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






@require_torch
class      A__       (						lowerCAmelCase__   ,						unittest.TestCase    ):
							lowerCAmelCase__		:						Optional[int]         =							(BlipTextModel,) if is_torch_available() else ()
							lowerCAmelCase__		:						Tuple         =							False
							lowerCAmelCase__		:						Optional[Any]         =							False
							lowerCAmelCase__		:						Union[str, Any]         =							False





							def       a__			(			self  :       int    )						->		str:



											"""simple docstring"""


											__lowercase								= BlipTextModelTester(self    )
											__lowercase								= ConfigTester(self					,			config_class=_UpperCAmelCase					,			hidden_size=37    )





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



											"""simple docstring"""


											self.config_tester.run_common_tests()





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



											"""simple docstring"""


											__lowercase								= self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*_UpperCAmelCase    )





							def       a__			(			self  :       Optional[int]    )						->		Any:



											"""simple docstring"""


											pass





							def       a__			(			self  :       List[Any]    )						->		Tuple:



											"""simple docstring"""


											pass





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



											"""simple docstring"""


											pass





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



											"""simple docstring"""


											pass





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



											"""simple docstring"""


											pass





							@slow
							def       a__			(			self  :       Optional[int]    )						->		Any:



											"""simple docstring"""


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





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



											"""simple docstring"""


											super().test_pt_tf_model_equivalence(allow_missing_keys=_UpperCAmelCase    )







from __future__ import annotations

from enum import Enum
class      A__       (						lowerCAmelCase__    ):
							lowerCAmelCase__		:						Dict         =							24
							lowerCAmelCase__		:						Dict         =							21
							lowerCAmelCase__		:						Union[str, Any]         =							18
							lowerCAmelCase__		:						Dict         =							15
							lowerCAmelCase__		:						Any         =							12
							lowerCAmelCase__		:						Union[str, Any]         =							9
							lowerCAmelCase__		:						Any         =							6
							lowerCAmelCase__		:						Optional[Any]         =							3
							lowerCAmelCase__		:						Union[str, Any]         =							2
							lowerCAmelCase__		:						List[Any]         =							1
							lowerCAmelCase__		:						Optional[Any]         =							-1
							lowerCAmelCase__		:						Tuple         =							-2
							lowerCAmelCase__		:						Dict         =							-3
							lowerCAmelCase__		:						Union[str, Any]         =							-6
							lowerCAmelCase__		:						Any         =							-9
							lowerCAmelCase__		:						Union[str, Any]         =							-12
							lowerCAmelCase__		:						str         =							-15
							lowerCAmelCase__		:						Optional[int]         =							-18
							lowerCAmelCase__		:						Any         =							-21
							lowerCAmelCase__		:						Any         =							-24






class      A__       (						lowerCAmelCase__    ):
							lowerCAmelCase__		:						Tuple         =							8
							lowerCAmelCase__		:						Union[str, Any]         =							7
							lowerCAmelCase__		:						Optional[Any]         =							6
							lowerCAmelCase__		:						Tuple         =							5
							lowerCAmelCase__		:						Optional[int]         =							4
							lowerCAmelCase__		:						Optional[int]         =							3
							lowerCAmelCase__		:						Optional[int]         =							2
							lowerCAmelCase__		:						Any         =							1






def 							__SCREAMING_SNAKE_CASE       (		SCREAMING_SNAKE_CASE	:				float   ,							SCREAMING_SNAKE_CASE	:				str | SIUnit   ,							SCREAMING_SNAKE_CASE	:				str | SIUnit   ,							)					->						float:
				if isinstance(SCREAMING_SNAKE_CASE   ,							SCREAMING_SNAKE_CASE      ):
								__lowercase								= SIUnit[known_prefix.lower()]
				if isinstance(SCREAMING_SNAKE_CASE   ,							SCREAMING_SNAKE_CASE      ):
								__lowercase								= SIUnit[unknown_prefix.lower()]
				__lowercase								= known_amount * (
				    10 ** (known_prefix.value - unknown_prefix.value)
				)
				return unknown_amount




def 							__SCREAMING_SNAKE_CASE       (		SCREAMING_SNAKE_CASE	:				float   ,							SCREAMING_SNAKE_CASE	:				str | BinaryUnit   ,							SCREAMING_SNAKE_CASE	:				str | BinaryUnit   ,							)					->						float:
				if isinstance(SCREAMING_SNAKE_CASE   ,							SCREAMING_SNAKE_CASE      ):
								__lowercase								= BinaryUnit[known_prefix.lower()]
				if isinstance(SCREAMING_SNAKE_CASE   ,							SCREAMING_SNAKE_CASE      ):
								__lowercase								= BinaryUnit[unknown_prefix.lower()]
				__lowercase								= known_amount * (
				    2 ** ((known_prefix.value - unknown_prefix.value) * 10)
				)
				return unknown_amount


if __name__ == "__main__":
							import doctest

							doctest.testmod()





