





"""simple docstring"""


import math

import tensorflow as tf
from packaging import version

def      UpperCamelCase							(SCREAMING_SNAKE_CASE     ):
						UpperCamelCase				:		int				   =			tf.convert_to_tensor(SCREAMING_SNAKE_CASE     )
						UpperCamelCase				:		Any				   =			0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0     )							,     x.dtype     )     ))

						return x * cdf

def      UpperCamelCase							(SCREAMING_SNAKE_CASE     ):
						UpperCamelCase				:		int				   =			tf.convert_to_tensor(SCREAMING_SNAKE_CASE     )
						UpperCamelCase				:		str				   =			tf.cast(math.pi							,     x.dtype     )
						UpperCamelCase				:		List[Any]				   =			tf.cast(0.04_47_15							,     x.dtype     )
						UpperCamelCase				:		List[str]				   =			0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi     ) * (x + coeff * tf.pow(SCREAMING_SNAKE_CASE							,     3     ))     ))

						return x * cdf

def      UpperCamelCase							(SCREAMING_SNAKE_CASE     ):
						UpperCamelCase				:		Union[str, Any]				   =			tf.convert_to_tensor(SCREAMING_SNAKE_CASE     )

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

def      UpperCamelCase							(SCREAMING_SNAKE_CASE     ):
						UpperCamelCase				:		List[Any]				   =			tf.convert_to_tensor(SCREAMING_SNAKE_CASE     )
						UpperCamelCase				:		List[str]				   =			tf.cast(0.04_47_15							,     x.dtype     )
						UpperCamelCase				:		Dict				   =			tf.cast(0.79_78_84_56_08							,     x.dtype     )

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

def      UpperCamelCase							(SCREAMING_SNAKE_CASE     ):
						UpperCamelCase				:		List[str]				   =			tf.convert_to_tensor(SCREAMING_SNAKE_CASE     )
						UpperCamelCase				:		Tuple				   =			tf.cast(1.7_02							,     x.dtype     )
						return x * tf.math.sigmoid(coeff * x     )

def      UpperCamelCase							(SCREAMING_SNAKE_CASE     ):
						return tf.clip_by_value(_gelu(SCREAMING_SNAKE_CASE     )							,     -10							,     10     )

def      UpperCamelCase							(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE=-1     ):
						UpperCamelCase   ,						UpperCamelCase				:		List[str]				   =			tf.split(SCREAMING_SNAKE_CASE							,     2							,     axis=SCREAMING_SNAKE_CASE     )
						return a * tf.math.sigmoid(SCREAMING_SNAKE_CASE     )


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

		def      UpperCamelCase							(SCREAMING_SNAKE_CASE     ):
								return tf.keras.activations.gelu(SCREAMING_SNAKE_CASE							,     approximate=SCREAMING_SNAKE_CASE     )

		__magic_name__       :					List[str]						=			tf.keras.activations.gelu
		__magic_name__       :					int						=			approximate_gelu_wrap
else:
		__magic_name__       :					Optional[Any]						=			_gelu
		__magic_name__       :					Optional[Any]						=			_gelu_new


__magic_name__       :					Optional[Any]						=			{
    """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							(SCREAMING_SNAKE_CASE     ):
						if activation_string in ACTaFN:
												return ACTaFN[activation_string]
						else:
												raise KeyError(f"""function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()     )}"""     )










"""simple docstring"""


from ...utils import is_torch_available, is_transformers_available


if is_transformers_available() and is_torch_available():
		from .pipeline_vq_diffusion import LearnedClassifierFreeSamplingEmbeddings, VQDiffusionPipeline



