






import math

import tensorflow as tf
from packaging import version

def        UpperCAmelCase__		(						lowerCamelCase_       :       Tuple				):
			__a						:  Any									=     tf.convert_to_tensor(lowerCamelCase_				)
			__a						:  Any									=     0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0				)   ,  x.dtype				)				))

			return x * cdf

def        UpperCAmelCase__		(						lowerCamelCase_       :       Union[str, Any]				):
			__a						:  Optional[Any]									=     tf.convert_to_tensor(lowerCamelCase_				)
			__a						:  Union[str, Any]									=     tf.cast(math.pi   ,  x.dtype				)
			__a						:  str									=     tf.cast(0.044715   ,  x.dtype				)
			__a						:  int									=     0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi				) * (x + coeff * tf.pow(lowerCamelCase_   ,  3				))				))

			return x * cdf

def        UpperCAmelCase__		(						lowerCamelCase_       :       Tuple				):
			__a						:  Union[str, Any]									=     tf.convert_to_tensor(lowerCamelCase_				)

			return x * tf.tanh(tf.math.softplus(lowerCamelCase_				)				)

def        UpperCAmelCase__		(						lowerCamelCase_       :       Union[str, Any]				):
			__a						:  List[str]									=     tf.convert_to_tensor(lowerCamelCase_				)
			__a						:  int									=     tf.cast(0.044715   ,  x.dtype				)
			__a						:  List[Any]									=     tf.cast(0.7978845608   ,  x.dtype				)

			return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)				))

def        UpperCAmelCase__		(						lowerCamelCase_       :       Optional[Any]				):
			__a						:  Dict									=     tf.convert_to_tensor(lowerCamelCase_				)
			__a						:  int									=     tf.cast(1.702   ,  x.dtype				)
			return x * tf.math.sigmoid(coeff * x				)

def        UpperCAmelCase__		(						lowerCamelCase_       :       List[Any]				):
			return tf.clip_by_value(_gelu(lowerCamelCase_				)   ,  -1_0   ,  1_0				)

def        UpperCAmelCase__		(						lowerCamelCase_       :       Dict   ,  lowerCamelCase_       :       List[Any]=-1				):
			__a						,					__a						:  Optional[Any]									=     tf.split(lowerCamelCase_   ,  2   ,  axis=lowerCamelCase_				)
			return a * tf.math.sigmoid(lowerCamelCase_				)


if version.parse(tf.version.VERSION) >= version.parse('''2.4'''):

							def        UpperCAmelCase__		(						lowerCamelCase_       :       int				):
										return tf.keras.activations.gelu(lowerCamelCase_   ,  approximate=lowerCamelCase_				)

							SCREAMING_SNAKE_CASE__				     =			tf.keras.activations.gelu
							SCREAMING_SNAKE_CASE__				     =			approximate_gelu_wrap
else:
							SCREAMING_SNAKE_CASE__				     =			_gelu
							SCREAMING_SNAKE_CASE__				     =			_gelu_new


SCREAMING_SNAKE_CASE__				     =			{
    '''gelu''': gelu,
    '''gelu_10''': gelu_aa,
    '''gelu_fast''': gelu_fast,
    '''gelu_new''': gelu_new,
    '''glu''': glu,
    '''mish''': mish,
    '''quick_gelu''': quick_gelu,
    '''relu''': tf.keras.activations.relu,
    '''sigmoid''': tf.keras.activations.sigmoid,
    '''silu''': tf.keras.activations.swish,
    '''swish''': tf.keras.activations.swish,
    '''tanh''': tf.keras.activations.tanh,
}

def        UpperCAmelCase__		(						lowerCamelCase_       :       str				):
			if activation_string in ACTaFN:
						return ACTaFN[activation_string]
			else:
						raise KeyError(f'''function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()				)}'''				)












import copy
import random

from transformers import CLIPTokenizer

class 							__SCREAMING_SNAKE_CASE       (  _a							):






							def __init__(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														super().__init__(*__lowerCAmelCase	,			**__lowerCAmelCase	)
														UpperCamelCase__					  =      {}






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														UpperCamelCase__					  =      super().add_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
														if num_added_tokens == 0:
																					raise ValueError(
																					    f"""The tokenizer already contains the token {placeholder_token}. Please pass a different"""
																					    """ `placeholder_token` that is not already in the tokenizer."""	)






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=1	,			**__lowerCAmelCase	):
														UpperCamelCase__					  =      []
														if num_vec_per_token == 1:
																					self.try_adding_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
																					output.append(__lowerCAmelCase	)
														else:
																					UpperCamelCase__					  =      []
																					for i in range(__lowerCAmelCase	):
																												UpperCamelCase__					  =      placeholder_token + f"""_{i}"""
																												self.try_adding_tokens(__lowerCAmelCase	,			*__lowerCAmelCase	,			**__lowerCAmelCase	)
																												output.append(__lowerCAmelCase	)
        # handle cases where there is a new placeholder token that contains the current placeholder token but is larger
														for token in self.token_map:
																					if token in placeholder_token:
																												raise ValueError(
																												    f"""The tokenizer already has placeholder token {token} that can get confused with"""
																												    f""" {placeholder_token}keep placeholder tokens independent"""	)
														UpperCamelCase__					  =      output






							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	):
														if isinstance(__lowerCAmelCase	,			__lowerCAmelCase	):
																					UpperCamelCase__					  =      []
																					for i in range(len(__lowerCAmelCase	)	):
																												output.append(self.replace_placeholder_tokens_in_text(text[i]	,			vector_shuffle=__lowerCAmelCase	)	)
																					return output
														for placeholder_token in self.token_map:
																					if placeholder_token in text:
																												UpperCamelCase__					  =      self.token_map[placeholder_token]
																												UpperCamelCase__					  =      tokens[: 1 + int(len(__lowerCAmelCase	) * prop_tokens_to_load	)]
																												if vector_shuffle:
																																			UpperCamelCase__					  =      copy.copy(__lowerCAmelCase	)
																																			random.shuffle(__lowerCAmelCase	)
																												UpperCamelCase__					  =      text.replace(__lowerCAmelCase	,			""" """.join(__lowerCAmelCase	)	)
														return text






							def __call__(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	,			**__lowerCAmelCase	):
														return super().__call__(
														    self.replace_placeholder_tokens_in_text(
														        __lowerCAmelCase	,			vector_shuffle=__lowerCAmelCase	,			prop_tokens_to_load=__lowerCAmelCase	)	,			*__lowerCAmelCase	,			**__lowerCAmelCase	,			)







							def 					_lowerCamelCase		(    self	,			__lowerCAmelCase	,			*__lowerCAmelCase	,			__lowerCAmelCase=False	,			__lowerCAmelCase=1.0	,			**__lowerCAmelCase	):
														return super().encode(
														    self.replace_placeholder_tokens_in_text(
														        __lowerCAmelCase	,			vector_shuffle=__lowerCAmelCase	,			prop_tokens_to_load=__lowerCAmelCase	)	,			*__lowerCAmelCase	,			**__lowerCAmelCase	,			)




