






'''simple docstring'''

import math

import tensorflow as tf
from packaging import version






def 	_UpperCAmelCase    (  a		:	List[Any]							)			->			Dict:





						"""simple docstring"""
						lowercase_      :   int        =			tf.convert_to_tensor(__UpperCamelCase							)
						lowercase_      :   int        =			0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0							)						,			x.dtype							)							))

						return x * cdf






def 	_UpperCAmelCase    (  a		:	List[str]							)			->			Union[str, Any]:





						"""simple docstring"""
						lowercase_      :   int        =			tf.convert_to_tensor(__UpperCamelCase							)
						lowercase_      :   List[Any]        =			tf.cast(math.pi						,			x.dtype							)
						lowercase_      :   int        =			tf.cast(0.04_47_15						,			x.dtype							)
						lowercase_      :   Optional[int]        =			0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi							) * (x + coeff * tf.pow(__UpperCamelCase						,			3							))							))

						return x * cdf






def 	_UpperCAmelCase    (  a		:	str							)			->			str:





						"""simple docstring"""
						lowercase_      :   Optional[Any]        =			tf.convert_to_tensor(__UpperCamelCase							)

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






def 	_UpperCAmelCase    (  a		:	Any							)			->			Union[str, Any]:





						"""simple docstring"""
						lowercase_      :   str        =			tf.convert_to_tensor(__UpperCamelCase							)
						lowercase_      :   int        =			tf.cast(0.04_47_15						,			x.dtype							)
						lowercase_      :   Optional[int]        =			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    (  a		:	List[str]							)			->			Optional[Any]:





						"""simple docstring"""
						lowercase_      :   Tuple        =			tf.convert_to_tensor(__UpperCamelCase							)
						lowercase_      :   str        =			tf.cast(1.7_02						,			x.dtype							)
						return x * tf.math.sigmoid(coeff * x							)






def 	_UpperCAmelCase    (  a		:	int							)			->			Optional[int]:





						"""simple docstring"""
						return tf.clip_by_value(_gelu(__UpperCamelCase							)						,			-1_0						,			1_0							)






def 	_UpperCAmelCase    (  a		:	Optional[int]						,			a		:	List[str]=-1							)			->			Any:





						"""simple docstring"""
						lowercase_      :   List[Any]        =			tf.split(__UpperCamelCase						,			2						,			axis=__UpperCamelCase							)
						return a * tf.math.sigmoid(__UpperCamelCase							)


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






						def 	_UpperCAmelCase    (  a		:	List[Any]							)			->			Any:





												"""simple docstring"""
												return tf.keras.activations.gelu(__UpperCamelCase						,			approximate=__UpperCamelCase							)

						A:      int  				=				tf.keras.activations.gelu






						A:      Optional[Any]  				=				approximate_gelu_wrap
else:
						A:      List[Any]  				=				_gelu
						A:      Any  				=				_gelu_new


A:      Dict  				=				{
    '''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    (  a		:	Any							)			->			List[Any]:





						"""simple docstring"""






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

import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible






class 							__magic_name__     (	unittest.TestCase				):







	"""simple docstring"""



	def        lowerCamelCase__		(							self       )						->  Optional[Any]:
							lowercase_      :   Tuple        =			[
							    'safety_checker/pytorch_model.bin',
							    'safety_checker/model.safetensors',
							    'vae/diffusion_pytorch_model.bin',
							    'vae/diffusion_pytorch_model.safetensors',
							    'text_encoder/pytorch_model.bin',
							    'text_encoder/model.safetensors',
							    'unet/diffusion_pytorch_model.bin',
							    'unet/diffusion_pytorch_model.safetensors',
							]
							self.assertTrue(is_safetensors_compatible(_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  Dict:
							lowercase_      :   Tuple        =			[
							    'unet/diffusion_pytorch_model.bin',
							    'unet/diffusion_pytorch_model.safetensors',
							]
							self.assertTrue(is_safetensors_compatible(_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  str:
							lowercase_      :   int        =			[
							    'safety_checker/pytorch_model.bin',
							    'safety_checker/model.safetensors',
							    'vae/diffusion_pytorch_model.bin',
							    'vae/diffusion_pytorch_model.safetensors',
							    'text_encoder/pytorch_model.bin',
							    'text_encoder/model.safetensors',
							    'unet/diffusion_pytorch_model.bin',
							    # Removed: 'unet/diffusion_pytorch_model.safetensors',
							]
							self.assertFalse(is_safetensors_compatible(_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  Any:
							lowercase_      :   Dict        =			[
							    'text_encoder/pytorch_model.bin',
							    'text_encoder/model.safetensors',
							]
							self.assertTrue(is_safetensors_compatible(_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  Optional[Any]:
							lowercase_      :   List[Any]        =			[
							    'safety_checker/pytorch_model.bin',
							    'safety_checker/model.safetensors',
							    'vae/diffusion_pytorch_model.bin',
							    'vae/diffusion_pytorch_model.safetensors',
							    'text_encoder/pytorch_model.bin',
							    # Removed: 'text_encoder/model.safetensors',
							    'unet/diffusion_pytorch_model.bin',
							    'unet/diffusion_pytorch_model.safetensors',
							]
							self.assertFalse(is_safetensors_compatible(_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  Optional[int]:
							lowercase_      :   str        =			[
							    'safety_checker/pytorch_model.fp16.bin',
							    'safety_checker/model.fp16.safetensors',
							    'vae/diffusion_pytorch_model.fp16.bin',
							    'vae/diffusion_pytorch_model.fp16.safetensors',
							    'text_encoder/pytorch_model.fp16.bin',
							    'text_encoder/model.fp16.safetensors',
							    'unet/diffusion_pytorch_model.fp16.bin',
							    'unet/diffusion_pytorch_model.fp16.safetensors',
							]
							lowercase_      :   Union[str, Any]        =			'fp16'
							self.assertTrue(is_safetensors_compatible(_lowercase  ,      variant=_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  int:
							lowercase_      :   Optional[int]        =			[
							    'unet/diffusion_pytorch_model.fp16.bin',
							    'unet/diffusion_pytorch_model.fp16.safetensors',
							]
							lowercase_      :   Dict        =			'fp16'
							self.assertTrue(is_safetensors_compatible(_lowercase  ,      variant=_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  int:
							# pass variant but use the non-variant filenames
							lowercase_      :   Optional[int]        =			[
							    'unet/diffusion_pytorch_model.bin',
							    'unet/diffusion_pytorch_model.safetensors',
							]
							lowercase_      :   Dict        =			'fp16'
							self.assertTrue(is_safetensors_compatible(_lowercase  ,      variant=_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  Union[str, Any]:
							lowercase_      :   int        =			[
							    'safety_checker/pytorch_model.fp16.bin',
							    'safety_checker/model.fp16.safetensors',
							    'vae/diffusion_pytorch_model.fp16.bin',
							    'vae/diffusion_pytorch_model.fp16.safetensors',
							    'text_encoder/pytorch_model.fp16.bin',
							    'text_encoder/model.fp16.safetensors',
							    'unet/diffusion_pytorch_model.fp16.bin',
							    # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
							]
							lowercase_      :   Dict        =			'fp16'
							self.assertFalse(is_safetensors_compatible(_lowercase  ,      variant=_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  int:
							lowercase_      :   str        =			[
							    'text_encoder/pytorch_model.fp16.bin',
							    'text_encoder/model.fp16.safetensors',
							]
							lowercase_      :   str        =			'fp16'
							self.assertTrue(is_safetensors_compatible(_lowercase  ,      variant=_lowercase       )       )
	def        lowerCamelCase__		(							self       )						->  List[str]:
							# pass variant but use the non-variant filenames
							lowercase_      :   List[Any]        =			[
							    'text_encoder/pytorch_model.bin',
							    'text_encoder/model.safetensors',
							]
							lowercase_      :   Dict        =			'fp16'
							self.assertTrue(is_safetensors_compatible(_lowercase  ,      variant=_lowercase       )       )







	def        lowerCamelCase__		(							self       )						->  List[str]:
							lowercase_      :   Union[str, Any]        =			[
							    'safety_checker/pytorch_model.fp16.bin',
							    'safety_checker/model.fp16.safetensors',
							    'vae/diffusion_pytorch_model.fp16.bin',
							    'vae/diffusion_pytorch_model.fp16.safetensors',
							    'text_encoder/pytorch_model.fp16.bin',
							    # 'text_encoder/model.fp16.safetensors',
							    'unet/diffusion_pytorch_model.fp16.bin',
							    'unet/diffusion_pytorch_model.fp16.safetensors',
							]
							lowercase_      :   Dict        =			'fp16'
							self.assertFalse(is_safetensors_compatible(_lowercase  ,      variant=_lowercase       )       )
