


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				,  __lowercase				,  __lowercase=1_2				,  __lowercase=7				,  __lowercase=True				,  __lowercase=True				,  __lowercase=True				,  __lowercase=9_9				,  __lowercase=3_2				,  __lowercase=3_2				,  __lowercase=5				,  __lowercase=4				,  __lowercase=3_7				,  __lowercase=0.1				,  __lowercase=0.1				,  __lowercase=5_1_2				,  __lowercase=0.02				,  __lowercase=0				,  __lowercase=None				,  )   ->      Union[str, Any]:
										lowerCAmelCase_	: List[str]      			=			parent
										lowerCAmelCase_	: Union[str, Any]      			=			batch_size
										lowerCAmelCase_	: Dict      			=			seq_length
										lowerCAmelCase_	: str      			=			is_training
										lowerCAmelCase_	: List[str]      			=			use_input_mask
										lowerCAmelCase_	: List[str]      			=			use_labels
										lowerCAmelCase_	: Union[str, Any]      			=			vocab_size
										lowerCAmelCase_	: Dict      			=			hidden_size
										lowerCAmelCase_	: int      			=			projection_dim
										lowerCAmelCase_	: Union[str, Any]      			=			num_hidden_layers
										lowerCAmelCase_	: Optional[Any]      			=			num_attention_heads
										lowerCAmelCase_	: int      			=			intermediate_size
										lowerCAmelCase_	: Optional[int]      			=			dropout
										lowerCAmelCase_	: Optional[Any]      			=			attention_dropout
										lowerCAmelCase_	: Tuple      			=			max_position_embeddings
										lowerCAmelCase_	: Tuple      			=			initializer_range
										lowerCAmelCase_	: Optional[int]      			=			scope
										lowerCAmelCase_	: Any      			=			bos_token_id




						def   lowercase_	(			self							)   ->      Optional[int]:
										lowerCAmelCase_	: List[Any]      			=			ids_tensor([self.batch_size, self.seq_length]				,  self.vocab_size							)

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

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

										lowerCAmelCase_	: int      			=			self.get_config()

										return config, input_ids, input_mask




						def   lowercase_	(			self							)   ->      str:
										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   lowercase_	(			self				,  __lowercase				,  __lowercase				,  __lowercase							)   ->      Dict:
										lowerCAmelCase_	: Union[str, Any]      			=			BlipTextModel(config=__lowercase							)
										model.to(__lowercase							)
										model.eval()
										with torch.no_grad():
														lowerCAmelCase_	: Any      			=			model(__lowercase				,  attention_mask=__lowercase							)
														lowerCAmelCase_	: Dict      			=			model(__lowercase							)
										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   lowercase_	(			self							)   ->      Optional[int]:
										lowerCAmelCase_	: Optional[Any]      			=			self.prepare_config_and_inputs()
										lowerCAmelCase_	: Dict      			=			config_and_inputs
										lowerCAmelCase_	: Union[str, Any]      			=			{'''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__ :					int   =							(BlipTextModel,) if is_torch_available() else ()
						SCREAMING_SNAKE_CASE__ :					Any   =							False
						SCREAMING_SNAKE_CASE__ :					Optional[int]   =							False
						SCREAMING_SNAKE_CASE__ :					Dict   =							False




						def   lowercase_	(			self							)   ->      str:
										lowerCAmelCase_	: int      			=			BlipTextModelTester(self							)
										lowerCAmelCase_	: Dict      			=			ConfigTester(self				,  config_class=__lowercase				,  hidden_size=3_7							)




						def   lowercase_	(			self							)   ->      List[Any]:
										self.config_tester.run_common_tests()




						def   lowercase_	(			self							)   ->      Dict:
										lowerCAmelCase_	: Optional[int]      			=			self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_model(*__lowercase							)




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




						def   lowercase_	(			self							)   ->      Any:
										pass




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




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




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




						@slow
						def   lowercase_	(			self							)   ->      Dict:
										for model_name in BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														lowerCAmelCase_	: Union[str, Any]      			=			BlipTextModel.from_pretrained(__lowercase							)
														self.assertIsNotNone(__lowercase							)




						def   lowercase_	(			self							)   ->      Optional[int]:
										super().test_pt_tf_model_equivalence(allow_missing_keys=__lowercase							)



from __future__ import annotations



def      lowerCAmelCase	(						lowerCAmelCase_	,				lowerCAmelCase_	,				lowerCAmelCase_	)->	int | float:
				if len(lowerCAmelCase_	) == 0:
								raise ValueError('''find_min() arg is an empty sequence'''	)
				if (
				    left >= len(lowerCAmelCase_	)
				    or left < -len(lowerCAmelCase_	)
				    or right >= len(lowerCAmelCase_	)
				    or right < -len(lowerCAmelCase_	)
				):
								raise IndexError('''list index out of range'''	)
				if left == right:
								return nums[left]
				lowerCAmelCase_	: Any      			=			(left + right) >> 1  # the middle
				lowerCAmelCase_	: Tuple      			=			find_min(lowerCAmelCase_	,				lowerCAmelCase_	,				lowerCAmelCase_	)  # find min in range[left, mid]
				lowerCAmelCase_	: Any      			=			find_min(lowerCAmelCase_	,				mid + 1	,				lowerCAmelCase_	)  # find min in range[mid + 1, right]

				return left_min if left_min <= right_min else right_min


if __name__ == "__main__":
						import doctest

						doctest.testmod(verbose=True)