


import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import AutoConfig
from ..clip.configuration_clip import CLIPVisionConfig


__lowerCamelCase   	=  logging.get_logger(__name__)


class 	a__						(    lowerCAmelCase_     ):
       lowerCamelCase__:  Dict				     =  """vision-text-dual-encoder"""
       lowerCamelCase__:  Dict				     =  True

       def __init__( self   :  str   ,				lowerCamelCase_   :  int=5_1_2   ,				lowerCamelCase_   :  List[Any]=2.6_5_9_2   ,				**lowerCamelCase_   :  Any     ):
            super().__init__(**lowerCamelCase_     )

            if "vision_config" not in kwargs:
                 raise ValueError("""`vision_config` can not be `None`."""     )

            if "text_config" not in kwargs:
                 raise ValueError("""`text_config` can not be `None`."""     )

            a_     :  str				      =     kwargs.pop("""vision_config"""     )
            a_     :  List[str]				      =     kwargs.pop("""text_config"""     )

            a_     :  str				      =     vision_config.pop("""model_type"""     )
            a_     :  Union[str, Any]				      =     text_config.pop("""model_type"""     )

            if vision_model_type == "clip":
                 a_     :  Dict				      =     AutoConfig.for_model(lowerCamelCase_   ,				**lowerCamelCase_     ).vision_config
            elif vision_model_type == "clip_vision_model":
                 a_     :  Union[str, Any]				      =     CLIPVisionConfig(**lowerCamelCase_     )
            else:
                 a_     :  str				      =     AutoConfig.for_model(lowerCamelCase_   ,				**lowerCamelCase_     )

            a_     :  str				      =     AutoConfig.for_model(lowerCamelCase_   ,				**lowerCamelCase_     )

            a_     :  str				      =     projection_dim
            a_     :  Tuple				      =     logit_scale_init_value

       @classmethod
       def     UpperCAmelCase( cls   :  Union[str, Any]   ,				lowerCamelCase_   :  PretrainedConfig   ,				lowerCamelCase_   :  PretrainedConfig   ,				**lowerCamelCase_   :  List[Any]     ):
            return cls(vision_config=vision_config.to_dict()   ,				text_config=text_config.to_dict()   ,				**lowerCamelCase_     )

       def     UpperCAmelCase( self   :  Optional[int]     ):
            a_     :  Dict				      =     copy.deepcopy(self.__dict__     )
            a_     :  Any				      =     self.vision_config.to_dict()
            a_     :  int				      =     self.text_config.to_dict()
            a_     :  List[Any]				      =     self.__class__.model_type
            return output





'''simple docstring'''


import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
	import tensorflow as tf

	from transformers.activations_tf import get_tf_activation




@require_tf
class     __snake_case			(    unittest.TestCase	):




		def 	_snake_case	(  self					:Tuple)					->			List[Any]:






								'''simple docstring'''






								UpperCamelCase_     :	List[str]					     =     tf.constant([-1_0_0, -1.0, -0.1, 0, 0.1, 1.0, 100.0])
								UpperCamelCase_     :	Any					     =     get_tf_activation("""gelu""")
								UpperCamelCase_     :	List[Any]					     =     get_tf_activation("""gelu_10""")

								UpperCamelCase_     :	Optional[int]					     =     gelu(_SCREAMING_SNAKE_CASE)
								UpperCamelCase_     :	Dict					     =     geluaa(_SCREAMING_SNAKE_CASE)

								UpperCamelCase_     :	List[Any]					     =     tf.where(y_gelu_aa < 10.0			,    1.0			,    0.0)

								self.assertEqual(tf.math.reduce_max(_SCREAMING_SNAKE_CASE).numpy().item()			,    10.0)
								self.assertTrue(np.allclose(y_gelu * clipped_mask			,    y_gelu_aa * clipped_mask))





		def 	_snake_case	(  self					:Any)					->			Dict:






								'''simple docstring'''






								get_tf_activation("""gelu""")
								get_tf_activation("""gelu_10""")
								get_tf_activation("""gelu_fast""")
								get_tf_activation("""gelu_new""")
								get_tf_activation("""glu""")
								get_tf_activation("""mish""")
								get_tf_activation("""quick_gelu""")
								get_tf_activation("""relu""")
								get_tf_activation("""sigmoid""")
								get_tf_activation("""silu""")
								get_tf_activation("""swish""")
								get_tf_activation("""tanh""")
								with self.assertRaises(_SCREAMING_SNAKE_CASE):
														get_tf_activation("""bogus""")
								with self.assertRaises(_SCREAMING_SNAKE_CASE):
														get_tf_activation(_SCREAMING_SNAKE_CASE)




