


'''simple docstring'''



from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__A						={'configuration_mmbt': ['MMBTConfig']}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__A						=['MMBTForClassification', 'MMBTModel', 'ModalEmbeddings']


if TYPE_CHECKING:
		from .configuration_mmbt import MMBTConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mmbt import MMBTForClassification, MMBTModel, ModalEmbeddings

else:
		import sys

		__A						=_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





'''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 	_snake_case:






 def __init__(self       :  Any    ,		a       :  str    ,		a       :  Union[str, Any]=12    ,		a       :  List[str]=7    ,		a       :  Dict=True    ,		a       :  Tuple=True    ,		a       :  Any=True    ,		a       :  Optional[Any]=99    ,		a       :  Optional[Any]=32    ,		a       :  Tuple=32    ,		a       :  List[Any]=2    ,		a       :  str=4    ,		a       :  Dict=37    ,		a       :  Optional[Any]=0.1    ,		a       :  List[Any]=0.1    ,		a       :  Dict=5_12    ,		a       :  List[Any]=0.02    ,		a       :  Any=0    ,		a       :  Optional[int]=None    ,		)       ->   List[Any]:






    """simple docstring"""


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






 def 						_UpperCamelCase (self       :  Union[str, Any]    )       ->   List[Any]:






    """simple docstring"""


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

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

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

    A__       =     self.get_config()

    return config, input_ids, tf.convert_to_tensor(a    )






 def 						_UpperCamelCase (self       :  Tuple    )       ->   Union[str, 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       :  Optional[int]    ,		a       :  Any    ,		a       :  List[Any]    ,		a       :  Union[str, Any]    )       ->   Any:






    """simple docstring"""


    A__       =     TFBlipTextModel(config=a    )
    A__       =     model(a    ,		attention_mask=a    ,		training=a    )
    A__       =     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       :  str    )       ->   List[Any]:






    """simple docstring"""


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




@require_tf
class 	_snake_case(			UpperCAmelCase       , unittest.TestCase      ):
 __snake_case:							Optional[int]						=					(TFBlipTextModel,) if is_tf_available() else ()
 __snake_case:							Union[str, Any]						=					False
 __snake_case:							Any						=					False
 __snake_case:							Union[str, Any]						=					False






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






    """simple docstring"""


    A__       =     BlipTextModelTester(self    )
    A__       =     ConfigTester(self    ,		config_class=a    ,		hidden_size=37    )






 def 						_UpperCamelCase (self       :  Tuple    )       ->   str:






    """simple docstring"""


    self.config_tester.run_common_tests()






 def 						_UpperCamelCase (self       :  Any    )       ->   Dict:






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*a    )






 def 						_UpperCamelCase (self       :  Dict    )       ->   Dict:






    """simple docstring"""


    pass






 def 						_UpperCamelCase (self       :  str    )       ->   int:






    """simple docstring"""


    pass






 @unittest.skip(reason='Blip does not use inputs_embeds'    )
 def 						_UpperCamelCase (self       :  Union[str, Any]    )       ->   str:






    """simple docstring"""


    pass






 @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'    )
 def 						_UpperCamelCase (self       :  int    )       ->   List[Any]:






    """simple docstring"""


    pass






 @unittest.skip(reason='BlipTextModel has no base class and is not available in MODEL_MAPPING'    )
 def 						_UpperCamelCase (self       :  int    )       ->   Optional[Any]:






    """simple docstring"""


    pass






 @slow
 def 						_UpperCamelCase (self       :  int    )       ->   Optional[Any]:






    """simple docstring"""


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






 def 						_UpperCamelCase (self       :  str    ,		a       :  Optional[int]=True    )       ->   List[Any]:






    """simple docstring"""


    super().test_pt_tf_model_equivalence(allow_missing_keys=a    )


