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				:

     '''simple docstring'''

     def __init__(					self				,				A_				,				A_=12				,				A_=7				,				A_=True				,				A_=True				,				A_=True				,				A_=99				,				A_=32				,				A_=32				,				A_=2				,				A_=4				,				A_=37				,				A_=0.1				,				A_=0.1				,				A_=5_12				,				A_=0.02				,				A_=0				,				A_=None				,				) ->				Optional[Any]:






           """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 		UpperCamelCase_						(					self						) ->				Dict:






           """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(A_						):
                       _lowerCamelCase			    =				1
                       _lowerCamelCase			    =				0

           _lowerCamelCase			    =				self.get_config()

           return config, input_ids, tf.convert_to_tensor(A_						)



     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				,				A_				,				A_				,				A_						) ->				List[str]:






           """simple docstring"""
           _lowerCamelCase			    =				TFBlipTextModel(config=A_						)
           _lowerCamelCase			    =				model(A_				,				attention_mask=A_				,				training=A_						)
           _lowerCamelCase			    =				model(A_				,				training=A_						)
           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						) ->				Optional[Any]:






           """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  UpperCamelCase				( lowercase__   ,  unittest.TestCase ):

     '''simple docstring'''

     A_										=  (TFBlipTextModel,) if is_tf_available() else ()
     A_										=  False
     A_										=  False
     A_										=  False



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






           """simple docstring"""
           _lowerCamelCase			    =				BlipTextModelTester(self						)
           _lowerCamelCase			    =				ConfigTester(self				,				config_class=A_				,				hidden_size=37						)



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






           """simple docstring"""
           self.config_tester.run_common_tests()



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






           """simple docstring"""
           _lowerCamelCase			    =				self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*A_						)



     def 		UpperCamelCase_						(					self						) ->				Dict:






           """simple docstring"""
           pass



     def 		UpperCamelCase_						(					self						) ->				Tuple:






           """simple docstring"""
           pass



     @unittest.skip(reason='''Blip does not use inputs_embeds'''						)
     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						) ->				str:






           """simple docstring"""
           pass



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






           """simple docstring"""
           pass



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






           """simple docstring"""
           for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                 _lowerCamelCase			    =				TFBlipTextModel.from_pretrained(A_						)
                 self.assertIsNotNone(A_						)





     def 		UpperCamelCase_						(					self				,				A_=True						) ->				Optional[Any]:






           """simple docstring"""
           super().test_pt_tf_model_equivalence(allow_missing_keys=A_						)


def       __magic_name__(  __UpperCAmelCase ,						__UpperCAmelCase		)						->    str:



      '''simple docstring'''

      _lowerCamelCase			    =				0
      while b > 0:
            if b & 1:
                  res += a

            a += a
            b >>= 1

      return res
def       __magic_name__(  __UpperCAmelCase ,						__UpperCAmelCase ,						__UpperCAmelCase		)						->    Optional[Any]:



      '''simple docstring'''

      _lowerCamelCase			    =				0
      while b > 0:
            if b & 1:
                  _lowerCamelCase			    =				((res % c) + (a % c)) % c

            a += a
            b >>= 1

      return res