



"""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 	__snake_case	:




  def __init__(			self					:						Any						, __lowerCAmelCase					:						List[Any]						, __lowerCAmelCase					:						Optional[Any]=1_2						, __lowerCAmelCase					:						Optional[Any]=7						, __lowerCAmelCase					:						Tuple=True						, __lowerCAmelCase					:						Optional[int]=True						, __lowerCAmelCase					:						Dict=True						, __lowerCAmelCase					:						Any=9_9						, __lowerCAmelCase					:						int=3_2						, __lowerCAmelCase					:						Tuple=3_2						, __lowerCAmelCase					:						Tuple=2						, __lowerCAmelCase					:						Any=4						, __lowerCAmelCase					:						Union[str, Any]=3_7						, __lowerCAmelCase					:						str=0.1						, __lowerCAmelCase					:						List[Any]=0.1						, __lowerCAmelCase					:						Tuple=5_1_2						, __lowerCAmelCase					:						List[str]=0.02						, __lowerCAmelCase					:						str=0						, __lowerCAmelCase					:						Any=None						, ):






         """simple docstring"""






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




  def 						SCREAMING_SNAKE_CASE    (			self					:						List[str]		):






         """simple docstring"""






         _lowerCamelCase						:    Optional[Any]         =			ids_tensor([self.batch_size, self.seq_length]						, self.vocab_size		)

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

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

         _lowerCamelCase						:    Union[str, Any]         =			self.get_config()

         return config, input_ids, tf.convert_to_tensor(__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE    (			self					:						List[str]		):






         """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 						SCREAMING_SNAKE_CASE    (			self					:						Optional[int]						, __lowerCAmelCase					:						Any						, __lowerCAmelCase					:						List[Any]						, __lowerCAmelCase					:						int		):






         """simple docstring"""






         _lowerCamelCase						:    Optional[Any]         =			TFBlipTextModel(config=__lowerCAmelCase		)
         _lowerCamelCase						:    Dict         =			model(__lowerCAmelCase						, attention_mask=__lowerCAmelCase						, training=__lowerCAmelCase		)
         _lowerCamelCase						:    Dict         =			model(__lowerCAmelCase						, training=__lowerCAmelCase		)
         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 						SCREAMING_SNAKE_CASE    (			self					:						str		):






         """simple docstring"""






         _lowerCamelCase						:    str         =			self.prepare_config_and_inputs()
         _lowerCamelCase      ,   _lowerCamelCase      ,   _lowerCamelCase						:    Optional[Any]         =			config_and_inputs
         _lowerCamelCase						:    Optional[int]         =			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
         return config, inputs_dict






@require_tf
class 	__snake_case	(     _lowercase  ,					unittest.TestCase):
  snake_case__    :       Tuple        =						(TFBlipTextModel,) if is_tf_available() else ()
  snake_case__    :       Union[str, Any]        =						False
  snake_case__    :       Dict        =						False
  snake_case__    :       List[Any]        =						False




  def 						SCREAMING_SNAKE_CASE    (			self					:						Tuple		):






         """simple docstring"""






         _lowerCamelCase						:    List[str]         =			BlipTextModelTester(self		)
         _lowerCamelCase						:    int         =			ConfigTester(self						, config_class=__lowerCAmelCase						, hidden_size=3_7		)




  def 						SCREAMING_SNAKE_CASE    (			self					:						Union[str, Any]		):






         """simple docstring"""






         self.config_tester.run_common_tests()




  def 						SCREAMING_SNAKE_CASE    (			self					:						Optional[int]		):






         """simple docstring"""






         _lowerCamelCase						:    Dict         =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE    (			self					:						Optional[Any]		):






         """simple docstring"""






         pass




  def 						SCREAMING_SNAKE_CASE    (			self					:						List[str]		):






         """simple docstring"""






         pass




  @unittest.skip(reason='''Blip does not use inputs_embeds'''		)
  def 						SCREAMING_SNAKE_CASE    (			self					:						int		):






         """simple docstring"""






         pass




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






         """simple docstring"""






         pass




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






         """simple docstring"""






         pass




  @slow
  def 						SCREAMING_SNAKE_CASE    (			self					:						List[str]		):






         """simple docstring"""






         for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                _lowerCamelCase						:    Dict         =			TFBlipTextModel.from_pretrained(__lowerCAmelCase		)
                self.assertIsNotNone(__lowerCAmelCase		)




  def 						SCREAMING_SNAKE_CASE    (			self					:						List[Any]						, __lowerCAmelCase					:						str=True		):






         """simple docstring"""






         super().test_pt_tf_model_equivalence(allow_missing_keys=__lowerCAmelCase		)







"""simple docstring"""






def 	snake_case_  (				A_ :		float						):


       '''simple docstring'''





       if edge <= 0 or not isinstance(A_,    A_						):
              raise ValueError('''Length must be a positive.'''						)
       return 3 * ((25 + 10 * (5 ** (1 / 2))) ** (1 / 2)) * (edge**2)






def 	snake_case_  (				A_ :		float						):


       '''simple docstring'''





       if edge <= 0 or not isinstance(A_,    A_						):
              raise ValueError('''Length must be a positive.'''						)
       return ((15 + (7 * (5 ** (1 / 2)))) / 4) * (edge**3)


if __name__ == "__main__":
   import doctest

   doctest.testmod()


