


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						:str 							=       parent
       a						:Dict 							=       batch_size
       a						:List[Any] 							=       seq_length
       a						:int 							=       is_training
       a						:List[Any] 							=       use_input_mask
       a						:List[Any] 							=       use_labels
       a						:Optional[int] 							=       vocab_size
       a						:Any 							=       hidden_size
       a						:int 							=       projection_dim
       a						:List[Any] 							=       num_hidden_layers
       a						:Any 							=       num_attention_heads
       a						:Tuple 							=       intermediate_size
       a						:Tuple 							=       dropout
       a						:Tuple 							=       attention_dropout
       a						:Any 							=       max_position_embeddings
       a						:Optional[Any] 							=       initializer_range
       a						:List[Any] 							=       scope
       a						:Tuple 							=       bos_token_id




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

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

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

       a						:Tuple 							=       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						:Optional[int] 							=       TFBlipTextModel(config=_lowerCamelCase    )
       a						:str 							=       model(_lowerCamelCase					,  attention_mask=_lowerCamelCase					,  training=_lowerCamelCase    )
       a						:Optional[int] 							=       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						:str 							=       self.prepare_config_and_inputs()
       a							,				a							,				a						:Tuple 							=       config_and_inputs
       a						:Dict 							=       {'''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						:Tuple 							=       BlipTextModelTester(self    )
       a						:List[str] 							=       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						:Any 							=       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						:Any 							=       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 dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Features, Value
from .base import TaskTemplate







@dataclass(frozen=a			)
class 			__A( a			):
				snake_case_						   =    field(default='''language-modeling'''  ,   metadata={'''include_in_asdict_even_if_is_default''': True}			)

				snake_case_						   =    Features({'''text''': Value('''string'''			)}			)
				snake_case_						   =    Features({}			)
				snake_case_						   =    "text"




				@property
				def 				SCREAMING_SNAKE_CASE_		(     self				)    ->      Dict[str, str]:


								'''simple docstring'''




								return {self.text_column: "text"}