

import math

import tensorflow as tf
from packaging import version


def        __lowercase    (  UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							tf.convert_to_tensor(UpperCAmelCase__      )
					__lowerCAmelCase					=							0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0      )		,					x.dtype      )      ))

					return x * cdf


def        __lowercase    (  UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							tf.convert_to_tensor(UpperCAmelCase__      )
					__lowerCAmelCase					=							tf.cast(math.pi		,					x.dtype      )
					__lowerCAmelCase					=							tf.cast(0.044715		,					x.dtype      )
					__lowerCAmelCase					=							0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi      ) * (x + coeff * tf.pow(UpperCAmelCase__		,					3      ))      ))

					return x * cdf


def        __lowercase    (  UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							tf.convert_to_tensor(UpperCAmelCase__      )

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


def        __lowercase    (  UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							tf.convert_to_tensor(UpperCAmelCase__      )
					__lowerCAmelCase					=							tf.cast(0.044715		,					x.dtype      )
					__lowerCAmelCase					=							tf.cast(0.7978845608		,					x.dtype      )

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


def        __lowercase    (  UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							tf.convert_to_tensor(UpperCAmelCase__      )
					__lowerCAmelCase					=							tf.cast(1.702		,					x.dtype      )
					return x * tf.math.sigmoid(coeff * x      )


def        __lowercase    (  UpperCAmelCase__      ):

					"""simple docstring"""






					return tf.clip_by_value(_gelu(UpperCAmelCase__      )		,					-10		,					10      )


def        __lowercase    (  UpperCAmelCase__		,					UpperCAmelCase__=-1      ):

					"""simple docstring"""






					__lowerCAmelCase,	__lowerCAmelCase					=							tf.split(UpperCAmelCase__		,					2		,					axis=UpperCAmelCase__      )
					return a * tf.math.sigmoid(UpperCAmelCase__      )


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


		def        __lowercase    (  UpperCAmelCase__      ):

							"""simple docstring"""






							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        __lowercase    (  UpperCAmelCase__      ):

					"""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()      )}"""      )









from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCamelCase      				=     {
    '''configuration_lilt''': ['''LILT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''LiltConfig'''],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowerCamelCase      				=     [
		    '''LILT_PRETRAINED_MODEL_ARCHIVE_LIST''',
		    '''LiltForQuestionAnswering''',
		    '''LiltForSequenceClassification''',
		    '''LiltForTokenClassification''',
		    '''LiltModel''',
		    '''LiltPreTrainedModel''',
		]

if TYPE_CHECKING:
		from .configuration_lilt import LILT_PRETRAINED_CONFIG_ARCHIVE_MAP, LiltConfig

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_lilt import (
				    LILT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    LiltForQuestionAnswering,
				    LiltForSequenceClassification,
				    LiltForTokenClassification,
				    LiltModel,
				    LiltPreTrainedModel,
				)

else:
		import sys

		lowerCamelCase      				=     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






