



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	:



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


           '''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 		_lowerCamelCase      (		self							:					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							=    input_mask.shape
               __a							=    np.random.randint(1					,		seq_length - 1					,		size=(batch_size,))
               for batch_idx, start_index in enumerate(_snake_case):
                   __a							=    1
                   __a							=    0

           __a							=    self.get_config()

           return config, input_ids, tf.convert_to_tensor(_snake_case)



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


           '''simple docstring'''

           __a							=    TFBlipTextModel(config=_snake_case)
           __a							=    model(_snake_case					,		attention_mask=_snake_case					,		training=_snake_case)
           __a							=    model(_snake_case					,		training=_snake_case)
           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 		_lowerCamelCase      (		self							:					Union[str, Any]):


           '''simple docstring'''

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


@require_tf
class    _A	(     __SCREAMING_SNAKE_CASE				,unittest.TestCase   ):
       UpperCamelCase__  :   Tuple						 =						(TFBlipTextModel,) if is_tf_available() else ()
       UpperCamelCase__  :   List[Any]						 =						False
       UpperCamelCase__  :   List[Any]						 =						False
       UpperCamelCase__  :   Any						 =						False



       def 		_lowerCamelCase      (		self							:					Any):


           '''simple docstring'''

           __a							=    BlipTextModelTester(self)
           __a							=    ConfigTester(self					,		config_class=_snake_case					,		hidden_size=37)



       def 		_lowerCamelCase      (		self							:					List[str]):


           '''simple docstring'''

           self.config_tester.run_common_tests()



       def 		_lowerCamelCase      (		self							:					Union[str, Any]):


           '''simple docstring'''

           __a							=    self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*_snake_case)



       def 		_lowerCamelCase      (		self							:					Optional[Any]):


           '''simple docstring'''

           pass



       def 		_lowerCamelCase      (		self							:					str):


           '''simple docstring'''

           pass



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


           '''simple docstring'''

           pass



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


           '''simple docstring'''

           pass



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


           '''simple docstring'''

           pass



       @slow
       def 		_lowerCamelCase      (		self							:					str):


           '''simple docstring'''

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





       def 		_lowerCamelCase      (		self							:					str					,		__SCREAMING_SNAKE_CASE							:					Any=True):


           '''simple docstring'''

           super().test_pt_tf_model_equivalence(allow_missing_keys=_snake_case)










def 					__snake_case     (      _UpperCAmelCase    ):
    if not isinstance(_UpperCAmelCase       ,			_UpperCAmelCase    ):
        raise TypeError('''Input value must be an \'int\' type'''    )

    __a							=    0
    while number:
        position += 1
        number >>= 1

    return position


if __name__ == "__main__":
 import doctest

 doctest.testmod()





