





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






			def __init__(self					,							__magic_name__					,							__magic_name__=12					,							__magic_name__=7					,							__magic_name__=True					,							__magic_name__=True					,							__magic_name__=True					,							__magic_name__=99					,							__magic_name__=32					,							__magic_name__=32					,							__magic_name__=2					,							__magic_name__=4					,							__magic_name__=37					,							__magic_name__=0.1					,							__magic_name__=0.1					,							__magic_name__=512					,							__magic_name__=0.02					,							__magic_name__=0					,							__magic_name__=None					,							)     ->   Tuple:


							'''simple docstring'''



							snake_case_						:    str				=  parent
							snake_case_						:    Tuple				=  batch_size
							snake_case_						:    List[str]				=  seq_length
							snake_case_						:    Optional[Any]				=  is_training
							snake_case_						:    int				=  use_input_mask
							snake_case_						:    Optional[int]				=  use_labels
							snake_case_						:    int				=  vocab_size
							snake_case_						:    List[Any]				=  hidden_size
							snake_case_						:    Tuple				=  projection_dim
							snake_case_						:    List[Any]				=  num_hidden_layers
							snake_case_						:    Union[str, Any]				=  num_attention_heads
							snake_case_						:    Optional[int]				=  intermediate_size
							snake_case_						:    List[str]				=  dropout
							snake_case_						:    List[str]				=  attention_dropout
							snake_case_						:    Optional[Any]				=  max_position_embeddings
							snake_case_						:    int				=  initializer_range
							snake_case_						:    Dict				=  scope
							snake_case_						:    List[Any]				=  bos_token_id






			def 			lowerCamelCase  (self    )     ->   Optional[int]:


							'''simple docstring'''



							snake_case_						:    Tuple				=  ids_tensor([self.batch_size, self.seq_length]					,							self.vocab_size    )

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

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

							snake_case_						:    Optional[Any]				=  self.get_config()

							return config, input_ids, tf.convert_to_tensor(__magic_name__    )






			def 			lowerCamelCase  (self    )     ->   Optional[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					,							__magic_name__					,							__magic_name__					,							__magic_name__    )     ->   Optional[int]:


							'''simple docstring'''



							snake_case_						:    List[str]				=  TFBlipTextModel(config=__magic_name__    )
							snake_case_						:    Tuple				=  model(__magic_name__					,							attention_mask=__magic_name__					,							training=__magic_name__    )
							snake_case_						:    Optional[int]				=  model(__magic_name__					,							training=__magic_name__    )
							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    )     ->   Union[str, Any]:


							'''simple docstring'''



							snake_case_						:    Union[str, Any]				=  self.prepare_config_and_inputs()
							snake_case_			,							snake_case_			,							snake_case_						:    Dict				=  config_and_inputs
							snake_case_						:    Dict				=  {'''input_ids''': input_ids, '''attention_mask''': input_mask}
							return config, inputs_dict




@require_tf
class 					__lowerCAmelCase       (			_a,     unittest.TestCase     ):
			lowerCamelCase_     :     Optional[int]       			=      (TFBlipTextModel,) if is_tf_available() else ()
			lowerCamelCase_     :     Optional[int]       			=      False
			lowerCamelCase_     :     str       			=      False
			lowerCamelCase_     :     Optional[Any]       			=      False






			def 			lowerCamelCase  (self    )     ->   Dict:


							'''simple docstring'''



							snake_case_						:    Tuple				=  BlipTextModelTester(self    )
							snake_case_						:    List[str]				=  ConfigTester(self					,							config_class=__magic_name__					,							hidden_size=37    )






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


							'''simple docstring'''



							self.config_tester.run_common_tests()






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


							'''simple docstring'''



							snake_case_						:    Tuple				=  self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__magic_name__    )






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


							'''simple docstring'''



							pass






			def 			lowerCamelCase  (self    )     ->   str:


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






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


							'''simple docstring'''



							pass






			@slow
			def 			lowerCamelCase  (self    )     ->   Tuple:


							'''simple docstring'''



							for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											snake_case_						:    Union[str, Any]				=  TFBlipTextModel.from_pretrained(__magic_name__    )
											self.assertIsNotNone(__magic_name__    )






			def 			lowerCamelCase  (self					,							__magic_name__=True    )     ->   Optional[Any]:


							'''simple docstring'''



							super().test_pt_tf_model_equivalence(allow_missing_keys=__magic_name__    )







lowerCAmelCase_    =				{
    "joule": 1.0,
    "kilojoule": 1_0_0_0,
    "megajoule": 1_0_0_0_0_0_0,
    "gigajoule": 1_0_0_0_0_0_0_0_0_0,
    "wattsecond": 1.0,
    "watthour": 3_6_0_0,
    "kilowatthour": 3_6_0_0_0_0_0,
    "newtonmeter": 1.0,
    "calorie_nutr": 4_1_8_6.8,
    "kilocalorie_nutr": 4_1_8_6_8_0_0.0_0,
    "electronvolt": 1.602_176_634e-19,
    "britishthermalunit_it": 1_0_5_5.0_5_5_8_5,
    "footpound": 1.355_818,
}






def      lowerCamelCase_						(				_UpperCamelCase ,				_UpperCamelCase ,				_UpperCamelCase )		->						float:






				"""simple docstring"""


				if to_type not in ENERGY_CONVERSION or from_type not in ENERGY_CONVERSION:
								snake_case_						:    str				=  (
								    f'''Incorrect \'from_type\' or \'to_type\' value: {from_type!r}, {to_type!r}\n'''
								    f'''Valid values are: {", ".join(_UpperCamelCase )}'''
								)
								raise ValueError(_UpperCamelCase )
				return value * ENERGY_CONVERSION[from_type] / ENERGY_CONVERSION[to_type]


if __name__ == "__main__":
	import doctest

	doctest.testmod()
