





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		:					str		,lowerCamelCase__		:					List[str]		,lowerCamelCase__		:					Tuple=12		,lowerCamelCase__		:					Optional[int]=7		,lowerCamelCase__		:					Union[str, Any]=True		,lowerCamelCase__		:					List[str]=True		,lowerCamelCase__		:					Any=True		,lowerCamelCase__		:					str=99		,lowerCamelCase__		:					Union[str, Any]=32		,lowerCamelCase__		:					Dict=32		,lowerCamelCase__		:					Union[str, Any]=2		,lowerCamelCase__		:					str=4		,lowerCamelCase__		:					int=37		,lowerCamelCase__		:					Union[str, Any]=0.1		,lowerCamelCase__		:					Optional[int]=0.1		,lowerCamelCase__		:					List[Any]=512		,lowerCamelCase__		:					List[Any]=0.02		,lowerCamelCase__		:					str=0		,lowerCamelCase__		:					List[Any]=None		,)  ->	str:




           '''simple docstring'''


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






     def        SCREAMING_SNAKE_CASE__						(							self		:					Dict )  ->	List[Any]:




           '''simple docstring'''


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

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

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

           SCREAMING_SNAKE_CASE	=		self.get_config()

           return config, input_ids, tf.convert_to_tensor(lowerCamelCase__ )






     def        SCREAMING_SNAKE_CASE__						(							self		:					Optional[Any] )  ->	Dict:




           '''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		:					Tuple		,lowerCamelCase__		:					int		,lowerCamelCase__		:					int		,lowerCamelCase__		:					Dict )  ->	List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		TFBlipTextModel(config=lowerCamelCase__ )
           SCREAMING_SNAKE_CASE	=		model(lowerCamelCase__		,attention_mask=lowerCamelCase__		,training=lowerCamelCase__ )
           SCREAMING_SNAKE_CASE	=		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		:					Tuple )  ->	List[Any]:




           '''simple docstring'''


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

@require_tf
class 	UpperCamelCase__				(   lowerCAmelCase_							,   unittest.TestCase     ):



     '''simple docstring'''

     __snake_case					:			str				=    (TFBlipTextModel,) if is_tf_available() else ()
     __snake_case					:			Tuple				=    False
     __snake_case					:			Optional[Any]				=    False
     __snake_case					:			str				=    False






     def        SCREAMING_SNAKE_CASE__						(							self		:					Tuple )  ->	Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		BlipTextModelTester(self )
           SCREAMING_SNAKE_CASE	=		ConfigTester(self		,config_class=lowerCamelCase__		,hidden_size=37 )






     def        SCREAMING_SNAKE_CASE__						(							self		:					Tuple )  ->	Dict:




           '''simple docstring'''


           self.config_tester.run_common_tests()






     def        SCREAMING_SNAKE_CASE__						(							self		:					Optional[int] )  ->	List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE	=		self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*lowerCamelCase__ )






     def        SCREAMING_SNAKE_CASE__						(							self		:					List[Any] )  ->	str:




           '''simple docstring'''


           pass






     def        SCREAMING_SNAKE_CASE__						(							self		:					List[Any] )  ->	Tuple:




           '''simple docstring'''


           pass






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




           '''simple docstring'''


           pass






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




           '''simple docstring'''


           pass






     @unittest.skip(reason="""BlipTextModel has no base class and is not available in MODEL_MAPPING""" )
     def        SCREAMING_SNAKE_CASE__						(							self		:					Union[str, Any] )  ->	str:




           '''simple docstring'''


           pass






     @slow
     def        SCREAMING_SNAKE_CASE__						(							self		:					Tuple )  ->	Tuple:




           '''simple docstring'''


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






     def        SCREAMING_SNAKE_CASE__						(							self		:					List[str]		,lowerCamelCase__		:					Any=True )  ->	List[str]:




           '''simple docstring'''


           super().test_pt_tf_model_equivalence(allow_missing_keys=lowerCamelCase__ )









from ..utils import DummyObject, requires_backends

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					Any		,**lowerCamelCase__		:					Any )  ->	str:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					Any		,*lowerCamelCase__		:					str		,**lowerCamelCase__		:					List[Any] )  ->	str:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			str				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					Union[str, Any]		,**lowerCamelCase__		:					Optional[int] )  ->	Optional[int]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					Tuple		,*lowerCamelCase__		:					Dict		,**lowerCamelCase__		:					Any )  ->	Union[str, Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					Optional[int]		,*lowerCamelCase__		:					List[Any]		,**lowerCamelCase__		:					Optional[int] )  ->	str:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[str]				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					Union[str, Any]		,**lowerCamelCase__		:					Optional[Any] )  ->	Tuple:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[str]				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					List[str]		,**lowerCamelCase__		:					str )  ->	Optional[int]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			int				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					List[Any]		,**lowerCamelCase__		:					Optional[Any] )  ->	int:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[Any]				=    ["sentencepiece"]






     def __init__(							self		:					List[str]		,*lowerCamelCase__		:					List[str]		,**lowerCamelCase__		:					int )  ->	Tuple:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					str		,*lowerCamelCase__		:					Union[str, Any]		,**lowerCamelCase__		:					List[str] )  ->	Optional[int]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Any				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					Dict		,**lowerCamelCase__		:					List[Any] )  ->	List[str]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Any				=    ["sentencepiece"]






     def __init__(							self		:					Dict		,*lowerCamelCase__		:					Any		,**lowerCamelCase__		:					Optional[int] )  ->	Union[str, Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Tuple				=    ["sentencepiece"]






     def __init__(							self		:					Dict		,*lowerCamelCase__		:					int		,**lowerCamelCase__		:					Optional[int] )  ->	Optional[Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[Any]				=    ["sentencepiece"]






     def __init__(							self		:					Optional[Any]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					int )  ->	Any:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Tuple				=    ["sentencepiece"]






     def __init__(							self		:					Optional[Any]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					Dict )  ->	Union[str, Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[Any]				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					str		,**lowerCamelCase__		:					Optional[Any] )  ->	Dict:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			int				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					Any		,**lowerCamelCase__		:					str )  ->	List[Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					Any		,**lowerCamelCase__		:					Dict )  ->	List[Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			int				=    ["sentencepiece"]






     def __init__(							self		:					List[Any]		,*lowerCamelCase__		:					str		,**lowerCamelCase__		:					Any )  ->	int:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					Dict		,*lowerCamelCase__		:					Optional[int]		,**lowerCamelCase__		:					str )  ->	Tuple:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			str				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					int		,**lowerCamelCase__		:					Any )  ->	List[str]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Any				=    ["sentencepiece"]






     def __init__(							self		:					Dict		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					str )  ->	int:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			List[str]				=    ["sentencepiece"]






     def __init__(							self		:					Optional[int]		,*lowerCamelCase__		:					Optional[int]		,**lowerCamelCase__		:					Union[str, Any] )  ->	Tuple:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			str				=    ["sentencepiece"]






     def __init__(							self		:					Optional[Any]		,*lowerCamelCase__		:					Optional[int]		,**lowerCamelCase__		:					List[Any] )  ->	Any:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Optional[Any]				=    ["sentencepiece"]






     def __init__(							self		:					List[str]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					str )  ->	Union[str, Any]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Optional[int]				=    ["sentencepiece"]






     def __init__(							self		:					Optional[Any]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					str )  ->	Dict:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Tuple				=    ["sentencepiece"]






     def __init__(							self		:					Any		,*lowerCamelCase__		:					Optional[int]		,**lowerCamelCase__		:					Any )  ->	Optional[int]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Dict				=    ["sentencepiece"]






     def __init__(							self		:					Union[str, Any]		,*lowerCamelCase__		:					List[str]		,**lowerCamelCase__		:					List[Any] )  ->	str:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			str				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					str		,**lowerCamelCase__		:					str )  ->	Dict:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					int		,*lowerCamelCase__		:					List[Any]		,**lowerCamelCase__		:					Optional[int] )  ->	List[str]:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )

class 	UpperCamelCase__				(   metaclass=lowerCAmelCase_     ):



     '''simple docstring'''

     __snake_case					:			Union[str, Any]				=    ["sentencepiece"]






     def __init__(							self		:					List[Any]		,*lowerCamelCase__		:					Tuple		,**lowerCamelCase__		:					Dict )  ->	Dict:




           '''simple docstring'''


           requires_backends(self		,["""sentencepiece"""] )


