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





       '''simple docstring'''



       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.0_2     ,       __lowerCAmelCase=0     ,       __lowerCAmelCase=None     ,       )  ->  List[str]:
        lowercase__    :   List[str]						= parent
        lowercase__    :   List[Any]						= batch_size
        lowercase__    :   Any						= seq_length
        lowercase__    :   Any						= is_training
        lowercase__    :   List[str]						= use_input_mask
        lowercase__    :   Dict						= use_labels
        lowercase__    :   Optional[Any]						= vocab_size
        lowercase__    :   Optional[Any]						= hidden_size
        lowercase__    :   Union[str, Any]						= projection_dim
        lowercase__    :   Tuple						= num_hidden_layers
        lowercase__    :   Tuple						= num_attention_heads
        lowercase__    :   Optional[int]						= intermediate_size
        lowercase__    :   Tuple						= dropout
        lowercase__    :   Optional[Any]						= attention_dropout
        lowercase__    :   Union[str, Any]						= max_position_embeddings
        lowercase__    :   int						= initializer_range
        lowercase__    :   Tuple						= scope
        lowercase__    :   Optional[int]						= bos_token_id

       def _lowerCAmelCase(						self			)  ->  List[str]:
        lowercase__    :   str						= ids_tensor([self.batch_size, self.seq_length]     ,       self.vocab_size			)

        lowercase__    :   List[str]						= None
        if self.use_input_mask:
         lowercase__    :   Union[str, Any]						= random_attention_mask([self.batch_size, self.seq_length]			)

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

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

        return config, input_ids, tf.convert_to_tensor(__lowerCAmelCase			)

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



@require_tf
class       UpperCAmelCase  (						a__   ,						unittest.TestCase ):





       '''simple docstring'''



       SCREAMING_SNAKE_CASE 		=   (TFBlipTextModel,) if is_tf_available() else ()
       SCREAMING_SNAKE_CASE 		=   False
       SCREAMING_SNAKE_CASE 		=   False
       SCREAMING_SNAKE_CASE 		=   False

       def _lowerCAmelCase(						self			)  ->  Optional[int]:
        lowercase__    :   Dict						= BlipTextModelTester(self			)
        lowercase__    :   int						= ConfigTester(self     ,       config_class=__lowerCAmelCase     ,       hidden_size=37			)

       def _lowerCAmelCase(						self			)  ->  Dict:
        self.config_tester.run_common_tests()

       def _lowerCAmelCase(						self			)  ->  Dict:
        lowercase__    :   Optional[Any]						= self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__lowerCAmelCase			)

       def _lowerCAmelCase(						self			)  ->  int:
        pass

       def _lowerCAmelCase(						self			)  ->  List[str]:
        pass

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

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

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

       @slow
       def _lowerCAmelCase(						self			)  ->  Dict:
        for model_name in TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         lowercase__    :   int						= TFBlipTextModel.from_pretrained(__lowerCAmelCase			)
         self.assertIsNotNone(__lowerCAmelCase			)


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase=True			)  ->  Optional[Any]:
        super().test_pt_tf_model_equivalence(allow_missing_keys=__lowerCAmelCase			)


'''simple docstring'''

import numpy as np
def       __UpperCamelCase	(       UpperCAmelCase					):
 return 1 / (1 + np.exp(-vector					))
def       __UpperCamelCase	(       UpperCAmelCase					):
 return vector * sigmoid(UpperCAmelCase					)


if __name__ == "__main__":
  import doctest

  doctest.testmod()

