



import math

import tensorflow as tf
from packaging import version






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							Dict    ):
		SCREAMING_SNAKE_CASE__			=      tf.convert_to_tensor(UpperCamelCase__    )
		SCREAMING_SNAKE_CASE__			=      0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0    )					,   x.dtype    )    ))

		return x * cdf






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							Optional[Any]    ):
		SCREAMING_SNAKE_CASE__			=      tf.convert_to_tensor(UpperCamelCase__    )
		SCREAMING_SNAKE_CASE__			=      tf.cast(math.pi					,   x.dtype    )
		SCREAMING_SNAKE_CASE__			=      tf.cast(0.0_4_4_7_1_5					,   x.dtype    )
		SCREAMING_SNAKE_CASE__			=      0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi    ) * (x + coeff * tf.pow(UpperCamelCase__					,   3    ))    ))

		return x * cdf






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							List[Any]    ):
		SCREAMING_SNAKE_CASE__			=      tf.convert_to_tensor(UpperCamelCase__    )

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






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							Any    ):
		SCREAMING_SNAKE_CASE__			=      tf.convert_to_tensor(UpperCamelCase__    )
		SCREAMING_SNAKE_CASE__			=      tf.cast(0.0_4_4_7_1_5					,   x.dtype    )
		SCREAMING_SNAKE_CASE__			=      tf.cast(0.7_9_7_8_8_4_5_6_0_8					,   x.dtype    )

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






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							Tuple    ):
		SCREAMING_SNAKE_CASE__			=      tf.convert_to_tensor(UpperCamelCase__    )
		SCREAMING_SNAKE_CASE__			=      tf.cast(1.7_0_2					,   x.dtype    )
		return x * tf.math.sigmoid(coeff * x    )






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							List[str]    ):
		return tf.clip_by_value(_gelu(UpperCamelCase__    )					,   -10					,   10    )






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							Union[str, Any]					,   UpperCamelCase__:							List[Any]=-1    ):
		SCREAMING_SNAKE_CASE__	,						SCREAMING_SNAKE_CASE__			=      tf.split(UpperCamelCase__					,   2					,   axis=UpperCamelCase__    )
		return a * tf.math.sigmoid(UpperCamelCase__    )


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






	def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							int    ):
			return tf.keras.activations.gelu(UpperCamelCase__					,   approximate=UpperCamelCase__    )

	_lowerCamelCase   				=			tf.keras.activations.gelu

	_lowerCamelCase   				=			approximate_gelu_wrap
else:
	_lowerCamelCase   				=			_gelu
	_lowerCamelCase   				=			_gelu_new


_lowerCamelCase   				=			{
    """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 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							Optional[int]    ):
		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 inspect
import unittest




class   UpperCamelCase_       (     unittest.TestCase    ):


							def      _snake_case  (							self    :str		)   ->   Union[str, Any]:



									"""simple docstring"""



									try:
											import diffusers  # noqa: F401
									except ImportError:
											assert False


							def      _snake_case  (							self    :Any		)   ->   Any:



									"""simple docstring"""



									import diffusers
									from diffusers.dependency_versions_table import deps

									SCREAMING_SNAKE_CASE__			=      inspect.getmembers(__A							,				inspect.isclass		)

									for cls_name, cls_module in all_classes:
											if "dummy_" in cls_module.__module__:
													for backend in cls_module._backends:
															if backend == "k_diffusion":
																	SCREAMING_SNAKE_CASE__			=      """k-diffusion"""
															elif backend == "invisible_watermark":
																	SCREAMING_SNAKE_CASE__			=      """invisible-watermark"""
															assert backend in deps, f'''{backend} is not in the deps table!'''