






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



  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__=2 ,		snake_case__=4 ,		snake_case__=37 ,		snake_case__=0.1 ,		snake_case__=0.1 ,		snake_case__=5_12 ,		snake_case__=0.02 ,		snake_case__=0 ,		snake_case__=None ,		)			->			Tuple:



         """simple docstring"""





         UpperCAmelCase	    =			parent
         UpperCAmelCase	    =			batch_size
         UpperCAmelCase	    =			seq_length
         UpperCAmelCase	    =			is_training
         UpperCAmelCase	    =			use_input_mask
         UpperCAmelCase	    =			use_labels
         UpperCAmelCase	    =			vocab_size
         UpperCAmelCase	    =			hidden_size
         UpperCAmelCase	    =			projection_dim
         UpperCAmelCase	    =			num_hidden_layers
         UpperCAmelCase	    =			num_attention_heads
         UpperCAmelCase	    =			intermediate_size
         UpperCAmelCase	    =			dropout
         UpperCAmelCase	    =			attention_dropout
         UpperCAmelCase	    =			max_position_embeddings
         UpperCAmelCase	    =			initializer_range
         UpperCAmelCase	    =			scope
         UpperCAmelCase	    =			bos_token_id



  def 		UpperCamelCase_				(      self				)			->			str:



         """simple docstring"""





         UpperCAmelCase	    =			ids_tensor([self.batch_size, self.seq_length] ,		self.vocab_size				)

         UpperCAmelCase	    =			None
         if self.use_input_mask:
                UpperCAmelCase	    =			random_attention_mask([self.batch_size, self.seq_length]				)

         if input_mask is not None:
                UpperCAmelCase	    =			input_mask.numpy()
                UpperCAmelCase    ,       UpperCAmelCase	    =			input_mask.shape
                UpperCAmelCase	    =			np.random.randint(1 ,		seq_length - 1 ,		size=(batch_size,)				)
                for batch_idx, start_index in enumerate(snake_case__				):
                       UpperCAmelCase	    =			1
                       UpperCAmelCase	    =			0

         UpperCAmelCase	    =			self.get_config()

         return config, input_ids, tf.convert_to_tensor(snake_case__				)



  def 		UpperCamelCase_				(      self				)			->			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 		UpperCamelCase_				(      self ,		snake_case__ ,		snake_case__ ,		snake_case__				)			->			Any:



         """simple docstring"""





         UpperCAmelCase	    =			TFBlipTextModel(config=snake_case__				)
         UpperCAmelCase	    =			model(snake_case__ ,		attention_mask=snake_case__ ,		training=snake_case__				)
         UpperCAmelCase	    =			model(snake_case__ ,		training=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				)			->			Tuple:



         """simple docstring"""





         UpperCAmelCase	    =			self.prepare_config_and_inputs()
         UpperCAmelCase    ,       UpperCAmelCase    ,       UpperCAmelCase	    =			config_and_inputs
         UpperCAmelCase	    =			{"""input_ids""": input_ids, """attention_mask""": input_mask}
         return config, inputs_dict





@require_tf
class   UpperCamelCase_ (       a_   ,					unittest.TestCase  ):
  _A       :					Optional[Any]				=	(TFBlipTextModel,) if is_tf_available() else ()
  _A       :					Tuple				=	False
  _A       :					List[Any]				=	False
  _A       :					Any				=	False



  def 		UpperCamelCase_				(      self				)			->			int:



         """simple docstring"""





         UpperCAmelCase	    =			BlipTextModelTester(self				)
         UpperCAmelCase	    =			ConfigTester(self ,		config_class=snake_case__ ,		hidden_size=37				)



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



         """simple docstring"""





         self.config_tester.run_common_tests()



  def 		UpperCamelCase_				(      self				)			->			str:



         """simple docstring"""





         UpperCAmelCase	    =			self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*snake_case__				)



  def 		UpperCamelCase_				(      self				)			->			Optional[Any]:



         """simple docstring"""





         pass



  def 		UpperCamelCase_				(      self				)			->			Tuple:



         """simple docstring"""





         pass



  @unittest.skip(reason="""Blip does not use inputs_embeds"""				)
  def 		UpperCamelCase_				(      self				)			->			Optional[int]:



         """simple docstring"""





         pass



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



         """simple docstring"""





         pass



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



         """simple docstring"""





         pass



  @slow
  def 		UpperCamelCase_				(      self				)			->			Any:



         """simple docstring"""





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



  def 		UpperCamelCase_				(      self ,		snake_case__=True				)			->			Optional[int]:



         """simple docstring"""





         super().test_pt_tf_model_equivalence(allow_missing_keys=snake_case__				)








"""simple docstring"""







def       _lowerCAmelCase       (      lowerCAmelCase		):







       '''simple docstring'''
       if not isinstance(lowerCAmelCase	,      lowerCAmelCase		):
              UpperCAmelCase	    =			F'''Input value of [number={number}] must be an integer'''
              raise TypeError(lowerCAmelCase		)
       if number < 0:
              return False
       UpperCAmelCase	    =			number * number
       while number > 0:
              if number % 10 != number_square % 10:
                     return False
              number //= 10
              number_square //= 10
       return True


if __name__ == "__main__":
 import doctest

 doctest.testmod()
