
"""simple docstring"""



from __future__ import annotations

import unittest

import numpy as np

from transformers import BlipTextConfig
from transformers.testing_utils import require_tf, slow
from transformers.utils import is_tf_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask


if is_tf_available():
	import tensorflow as tf

	from transformers import TFBlipTextModel
	from transformers.models.blip.modeling_tf_blip import TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST
class        _SCREAMING_SNAKE_CASE  :






				'''simple docstring'''



				def __init__(					self	:			List[Any]				,     UpperCAmelCase_	:			Dict				,     UpperCAmelCase_	:			List[Any]=12				,     UpperCAmelCase_	:			Optional[int]=7				,     UpperCAmelCase_	:			Union[str, Any]=True				,     UpperCAmelCase_	:			Optional[Any]=True				,     UpperCAmelCase_	:			Union[str, Any]=True				,     UpperCAmelCase_	:			Optional[Any]=99				,     UpperCAmelCase_	:			Any=32				,     UpperCAmelCase_	:			Dict=32				,     UpperCAmelCase_	:			List[str]=2				,     UpperCAmelCase_	:			Optional[int]=4				,     UpperCAmelCase_	:			List[Any]=37				,     UpperCAmelCase_	:			Dict=0.1				,     UpperCAmelCase_	:			Optional[Any]=0.1				,     UpperCAmelCase_	:			Union[str, Any]=512				,     UpperCAmelCase_	:			Any=0.02				,     UpperCAmelCase_	:			Tuple=0				,     UpperCAmelCase_	:			Union[str, Any]=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	:			Optional[int]  )		->  int:







											"""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  	=			input_mask.numpy()
																		_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, tf.convert_to_tensor(_SCREAMING_SNAKE_CASE  )


				def 				__lowerCamelCase	(					self	:			str  )		->  List[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 				__lowerCamelCase	(					self	:			Optional[Any]				,     UpperCAmelCase_	:			Optional[Any]				,     UpperCAmelCase_	:			Any				,     UpperCAmelCase_	:			Optional[int]  )		->  Any:







											"""simple docstring"""




											_lowerCAmelCase  	=			TFBlipTextModel(config=_SCREAMING_SNAKE_CASE  )
											_lowerCAmelCase  	=			model(_SCREAMING_SNAKE_CASE				,     attention_mask=_SCREAMING_SNAKE_CASE				,     training=_SCREAMING_SNAKE_CASE  )
											_lowerCAmelCase  	=			model(_SCREAMING_SNAKE_CASE				,     training=_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	:			Tuple  )		->  Optional[int]:







											"""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_tf
class        _SCREAMING_SNAKE_CASE  (  lowerCAmelCase__      ,				unittest.TestCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							List[str]							=					(TFBlipTextModel,) if is_tf_available() else ()
				SCREAMING_SNAKE_CASE_:							str							=					False
				SCREAMING_SNAKE_CASE_:							Tuple							=					False
				SCREAMING_SNAKE_CASE_:							Optional[Any]							=					False


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







											"""simple docstring"""




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


				def 				__lowerCamelCase	(					self	:			Any  )		->  int:







											"""simple docstring"""




											self.config_tester.run_common_tests()


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







											"""simple docstring"""




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


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







											"""simple docstring"""




											pass


				def 				__lowerCamelCase	(					self	:			Tuple  )		->  Optional[int]:







											"""simple docstring"""




											pass


				@unittest.skip(reason='Blip does not use inputs_embeds'  )
				def 				__lowerCamelCase	(					self	:			Tuple  )		->  Dict:







											"""simple docstring"""




											pass


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







											"""simple docstring"""




											pass


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







											"""simple docstring"""




											pass


				@slow
				def 				__lowerCamelCase	(					self	:			Any  )		->  List[str]:







											"""simple docstring"""




											for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		_lowerCAmelCase  	=			TFBlipTextModel.from_pretrained(_SCREAMING_SNAKE_CASE  )
																		self.assertIsNotNone(_SCREAMING_SNAKE_CASE  )







				def 				__lowerCamelCase	(					self	:			List[str]				,     UpperCAmelCase_	:			Dict=True  )		->  int:







											"""simple docstring"""




											super().test_pt_tf_model_equivalence(allow_missing_keys=_SCREAMING_SNAKE_CASE  )



"""simple docstring"""



from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_snake_case          =						logging.get_logger(__name__)

_snake_case          =						{
    '''google/mobilenet_v1_1.0_224''': '''https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json''',
    '''google/mobilenet_v1_0.75_192''': '''https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json''',
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Dict							=					"mobilenet_v1"


				def __init__(					self	:			List[Any]				,     UpperCAmelCase_	:			Optional[int]=3				,     UpperCAmelCase_	:			str=224				,     UpperCAmelCase_	:			Union[str, Any]=1.0				,     UpperCAmelCase_	:			List[str]=8				,     UpperCAmelCase_	:			Union[str, Any]="relu6"				,     UpperCAmelCase_	:			Optional[Any]=True				,     UpperCAmelCase_	:			Optional[int]=0.999				,     UpperCAmelCase_	:			Optional[Any]=0.02				,     UpperCAmelCase_	:			Union[str, Any]=0.001				,     **UpperCAmelCase_	:			List[Any]				,     )		->  Dict:







											"""simple docstring"""




											super().__init__(**UpperCAmelCase_  )

											if depth_multiplier <= 0:
																		raise ValueError('depth_multiplier must be greater than zero.'  )

											_lowerCAmelCase  	=			num_channels
											_lowerCAmelCase  	=			image_size
											_lowerCAmelCase  	=			depth_multiplier
											_lowerCAmelCase  	=			min_depth
											_lowerCAmelCase  	=			hidden_act
											_lowerCAmelCase  	=			tf_padding
											_lowerCAmelCase  	=			classifier_dropout_prob
											_lowerCAmelCase  	=			initializer_range
											_lowerCAmelCase  	=			layer_norm_eps






class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							Optional[int]							=					version.parse("1.11"							)


				@property
				def 				__lowerCamelCase	(					self	:			List[str]  )		->  Mapping[str, Mapping[int, str]]:







											"""simple docstring"""




											return OrderedDict([('pixel_values', {0: 'batch'})]  )


				@property
				def 				__lowerCamelCase	(					self	:			Dict  )		->  Mapping[str, Mapping[int, str]]:







											"""simple docstring"""




											if self.task == "image-classification":
																		return OrderedDict([('logits', {0: 'batch'})]  )
											else:
																		return OrderedDict([('last_hidden_state', {0: 'batch'}), ('pooler_output', {0: 'batch'})]  )







				@property
				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  float:







											"""simple docstring"""




											return 1E-4






