


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 ,  _lowerCamelCase ,  _lowerCamelCase=12 ,  _lowerCamelCase=7 ,  _lowerCamelCase=True ,  _lowerCamelCase=True ,  _lowerCamelCase=True ,  _lowerCamelCase=99 ,  _lowerCamelCase=32 ,  _lowerCamelCase=32 ,  _lowerCamelCase=2 ,  _lowerCamelCase=4 ,  _lowerCamelCase=37 ,  _lowerCamelCase=0.1 ,  _lowerCamelCase=0.1 ,  _lowerCamelCase=512 ,  _lowerCamelCase=0.02 ,  _lowerCamelCase=0 ,  _lowerCamelCase=None ,  ):
       a						:List[Any]										=	parent
       a						:Union[str, Any]										=	batch_size
       a						:Optional[int]										=	seq_length
       a						:List[Any]										=	is_training
       a						:Tuple										=	use_input_mask
       a						:Any										=	use_labels
       a						:Any										=	vocab_size
       a						:str										=	hidden_size
       a						:Optional[int]										=	projection_dim
       a						:Union[str, Any]										=	num_hidden_layers
       a						:str										=	num_attention_heads
       a						:Optional[Any]										=	intermediate_size
       a						:List[Any]										=	dropout
       a						:Optional[Any]										=	attention_dropout
       a						:int										=	max_position_embeddings
       a						:str										=	initializer_range
       a						:Tuple										=	scope
       a						:Union[str, Any]										=	bos_token_id




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

       a						:Optional[Any]										=	None
       if self.use_input_mask:
             a						:List[Any]										=	random_attention_mask([self.batch_size, self.seq_length]   )

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

       a						:List[str]										=	self.get_config()

       return config, input_ids, tf.convert_to_tensor(_lowerCamelCase   )




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







@require_tf
class 		_snake_case  (				_snake_case						,   unittest.TestCase							):
 SCREAMING_SNAKE_CASE__				=	(TFBlipTextModel,) if is_tf_available() else ()
 SCREAMING_SNAKE_CASE__				=	False
 SCREAMING_SNAKE_CASE__				=	False
 SCREAMING_SNAKE_CASE__				=	False




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




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       self.config_tester.run_common_tests()




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       a						:Dict										=	self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*_lowerCamelCase   )




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       pass




 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       pass




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




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




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




 @slow
 def 	SCREAMING_SNAKE_CASE__    (		self   ):
       for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             a						:Dict										=	TFBlipTextModel.from_pretrained(_lowerCamelCase   )
             self.assertIsNotNone(_lowerCamelCase   )




 def 	SCREAMING_SNAKE_CASE__    (		self ,  _lowerCamelCase=True   ):
       super().test_pt_tf_model_equivalence(allow_missing_keys=_lowerCamelCase   )









from ...configuration_utils import PretrainedConfig







class 		_snake_case  (				_snake_case							):
 SCREAMING_SNAKE_CASE__				=	'bert-generation'




 def __init__(		self ,  _lowerCamelCase=5_0358 ,  _lowerCamelCase=1024 ,  _lowerCamelCase=24 ,  _lowerCamelCase=16 ,  _lowerCamelCase=4096 ,  _lowerCamelCase="gelu" ,  _lowerCamelCase=0.1 ,  _lowerCamelCase=0.1 ,  _lowerCamelCase=512 ,  _lowerCamelCase=0.02 ,  _lowerCamelCase=1e-12 ,  _lowerCamelCase=0 ,  _lowerCamelCase=2 ,  _lowerCamelCase=1 ,  _lowerCamelCase="absolute" ,  _lowerCamelCase=True ,  **_lowerCamelCase ,  ):
       super().__init__(pad_token_id=_lowerCamelCase ,  bos_token_id=_lowerCamelCase ,  eos_token_id=_lowerCamelCase ,  **_lowerCamelCase   )

       a						:Optional[int]										=	vocab_size
       a						:Tuple										=	hidden_size
       a						:Any										=	num_hidden_layers
       a						:Any										=	num_attention_heads
       a						:List[Any]										=	hidden_act
       a						:Tuple										=	intermediate_size
       a						:Any										=	hidden_dropout_prob
       a						:int										=	attention_probs_dropout_prob
       a						:Dict										=	max_position_embeddings
       a						:int										=	initializer_range
       a						:Union[str, Any]										=	layer_norm_eps
       a						:str										=	position_embedding_type
       a						:int										=	use_cache





