


'''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__  :





							'''simple docstring'''


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






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				ids_tensor([self.batch_size, self.seq_length]   , self.vocab_size  )

											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				None
											if self.use_input_mask:
															_SCREAMING_SNAKE_CASE			:	str							=				random_attention_mask([self.batch_size, self.seq_length]  )

											if input_mask is not None:
															_SCREAMING_SNAKE_CASE		,	_SCREAMING_SNAKE_CASE			:	Tuple							=				input_mask.shape
															_SCREAMING_SNAKE_CASE			:	Any							=				np.random.randint(1   , seq_length - 1   , size=(batch_size,)  )
															for batch_idx, start_index in enumerate(__snake_case  ):
																			_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				1
																			_SCREAMING_SNAKE_CASE			:	Optional[int]							=				0

											_SCREAMING_SNAKE_CASE			:	Optional[int]							=				self.get_config()

											return config, input_ids, input_mask






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





@require_torch
class    lowercase__  (						_snake_case					,					unittest.TestCase ):





							'''simple docstring'''


							A_							:				str				     =  (BlipTextModel,) if is_torch_available() else ()
							A_							:				Optional[int]				     =  False
							A_							:				Optional[Any]				     =  False
							A_							:				List[Any]				     =  False






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				BlipTextModelTester(self  )
											_SCREAMING_SNAKE_CASE			:	Tuple							=				ConfigTester(self   , config_class=__snake_case   , hidden_size=37  )






							def UpperCAmelCase_     (   self  ):
											self.config_tester.run_common_tests()






							def UpperCAmelCase_     (   self  ):
											_SCREAMING_SNAKE_CASE			:	str							=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__snake_case  )






							def UpperCAmelCase_     (   self  ):
											pass






							def UpperCAmelCase_     (   self  ):
											pass






							@unittest.skip(reason="""Blip does not use inputs_embeds"""  )
							def UpperCAmelCase_     (   self  ):
											pass






							@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""  )
							def UpperCAmelCase_     (   self  ):
											pass






							@unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING"""  )
							def UpperCAmelCase_     (   self  ):
											pass






							@slow
							def UpperCAmelCase_     (   self  ):
											for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															_SCREAMING_SNAKE_CASE			:	List[Any]							=				BlipTextModel.from_pretrained(__snake_case  )
															self.assertIsNotNone(__snake_case  )






							def UpperCAmelCase_     (   self  ):
											super().test_pt_tf_model_equivalence(allow_missing_keys=__snake_case  )








'''simple docstring'''


def       snake_case_       (  SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE			:	Tuple							=				1
				while b > 0:
								if b & 1:
												res *= a

								a *= a
								b >>= 1

				return res







def       snake_case_       (  SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__							,				SCREAMING_SNAKE_CASE__					):







				"""simple docstring"""





				_SCREAMING_SNAKE_CASE			:	Union[str, Any]							=				1
				while b > 0:
								if b & 1:
												_SCREAMING_SNAKE_CASE			:	Tuple							=				((res % c) * (a % c)) % c

								a *= a
								b >>= 1

				return res




