


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







    """simple docstring"""




    def __init__(					self				:    Tuple				, __UpperCAmelCase				:    str				, __UpperCAmelCase				:    Any=12				, __UpperCAmelCase				:    List[str]=7				, __UpperCAmelCase				:    Tuple=True				, __UpperCAmelCase				:    Optional[int]=True				, __UpperCAmelCase				:    Optional[int]=True				, __UpperCAmelCase				:    Dict=99				, __UpperCAmelCase				:    Union[str, Any]=32				, __UpperCAmelCase				:    Union[str, Any]=32				, __UpperCAmelCase				:    Optional[Any]=2				, __UpperCAmelCase				:    int=4				, __UpperCAmelCase				:    Dict=37				, __UpperCAmelCase				:    Optional[int]=0.1				, __UpperCAmelCase				:    str=0.1				, __UpperCAmelCase				:    Tuple=512				, __UpperCAmelCase				:    Union[str, Any]=0.02				, __UpperCAmelCase				:    List[str]=0				, __UpperCAmelCase				:    Dict=None				, ):
      a						:		int      							=			parent
      a						:		List[Any]      							=			batch_size
      a						:		Any      							=			seq_length
      a						:		List[str]      							=			is_training
      a						:		int      							=			use_input_mask
      a						:		List[str]      							=			use_labels
      a						:		Optional[int]      							=			vocab_size
      a						:		Union[str, Any]      							=			hidden_size
      a						:		int      							=			projection_dim
      a						:		int      							=			num_hidden_layers
      a						:		Dict      							=			num_attention_heads
      a						:		Any      							=			intermediate_size
      a						:		str      							=			dropout
      a						:		List[Any]      							=			attention_dropout
      a						:		Optional[int]      							=			max_position_embeddings
      a						:		Any      							=			initializer_range
      a						:		List[Any]      							=			scope
      a						:		Tuple      							=			bos_token_id






    def 	__snake_case							(					self				:    int):
      a						:		Dict      							=			ids_tensor([self.batch_size, self.seq_length]				, self.vocab_size)

      a						:		Dict      							=			None
      if self.use_input_mask:
        a						:		int      							=			random_attention_mask([self.batch_size, self.seq_length])

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

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

      return config, input_ids, tf.convert_to_tensor(__UpperCAmelCase)






    def 	__snake_case							(					self				:    Tuple):
      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 	__snake_case							(					self				:    Union[str, Any]				, __UpperCAmelCase				:    Union[str, Any]				, __UpperCAmelCase				:    Dict				, __UpperCAmelCase				:    List[Any]):
      a						:		Optional[Any]      							=			TFBlipTextModel(config=__UpperCAmelCase)
      a						:		Any      							=			model(__UpperCAmelCase				, attention_mask=__UpperCAmelCase				, training=__UpperCAmelCase)
      a						:		Optional[Any]      							=			model(__UpperCAmelCase				, training=__UpperCAmelCase)
      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 	__snake_case							(					self				:    Optional[int]):
      a						:		Optional[int]      							=			self.prepare_config_and_inputs()
      a							,		a							,		a						:		str      							=			config_and_inputs
      a						:		Optional[Any]      							=			{"input_ids": input_ids, "attention_mask": input_mask}
      return config, inputs_dict






@require_tf
class 						_A  (  _a    ,unittest.TestCase  ):







    """simple docstring"""




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






    def 	__snake_case							(					self				:    Dict):
      a						:		Any      							=			BlipTextModelTester(self)
      a						:		Optional[Any]      							=			ConfigTester(self				, config_class=__UpperCAmelCase				, hidden_size=37)






    def 	__snake_case							(					self				:    int):
      self.config_tester.run_common_tests()






    def 	__snake_case							(					self				:    List[Any]):
      a						:		int      							=			self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__UpperCAmelCase)






    def 	__snake_case							(					self				:    int):
      pass






    def 	__snake_case							(					self				:    Dict):
      pass






    @unittest.skip(reason="Blip does not use inputs_embeds")
    def 	__snake_case							(					self				:    List[str]):
      pass






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






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






    @slow
    def 	__snake_case							(					self				:    str):
      for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        a						:		str      							=			TFBlipTextModel.from_pretrained(__UpperCAmelCase)
        self.assertIsNotNone(__UpperCAmelCase)






    def 	__snake_case							(					self				:    Optional[Any]				, __UpperCAmelCase				:    int=True):
      super().test_pt_tf_model_equivalence(allow_missing_keys=__UpperCAmelCase)










"""simple docstring"""







from abc import ABC, abstractmethod
from argparse import ArgumentParser




class  UpperCamelCase_	( UpperCamelCase):

	"""simple docstring"""





	@staticmethod
	@abstractmethod
	def   UpperCAmelCase_      ( UpperCAmelCase__			:				ArgumentParser   )       ->	int:
						raise NotImplementedError()




	@abstractmethod
	def   UpperCAmelCase_      ( self			:				int   )       ->	Optional[int]:
						raise NotImplementedError()
