

'''simple docstring'''







import math

import tensorflow as tf
from packaging import version
def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			Dict:
       A_						=      tf.convert_to_tensor(UpperCAmelCase__				)
       A_						=      0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0				),       x.dtype				)				))

       return x * cdf
def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			Tuple:
       A_						=      tf.convert_to_tensor(UpperCAmelCase__				)
       A_						=      tf.cast(math.pi,       x.dtype				)
       A_						=      tf.cast(0.044_715,       x.dtype				)
       A_						=      0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi				) * (x + coeff * tf.pow(UpperCAmelCase__,       3				))				))

       return x * cdf
def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			List[Any]:
       A_						=      tf.convert_to_tensor(UpperCAmelCase__				)

       return x * tf.tanh(tf.math.softplus(UpperCAmelCase__				)				)
def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			List[Any]:
       A_						=      tf.convert_to_tensor(UpperCAmelCase__				)
       A_						=      tf.cast(0.044_715,       x.dtype				)
       A_						=      tf.cast(0.7_978_845_608,       x.dtype				)

       return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)				))
def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			Dict:
       A_						=      tf.convert_to_tensor(UpperCAmelCase__				)
       A_						=      tf.cast(1.702,       x.dtype				)
       return x * tf.math.sigmoid(coeff * x				)
def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			Optional[Any]:
       return tf.clip_by_value(_gelu(UpperCAmelCase__				),       -10,       10				)
def       UpperCAmelCase__    (      UpperCAmelCase__,       UpperCAmelCase__=-1				)			->			Optional[int]:
       A_					,			A_						=      tf.split(UpperCAmelCase__,       2,       axis=UpperCAmelCase__				)
       return a * tf.math.sigmoid(UpperCAmelCase__				)


if version.parse(tf.version.VERSION) >= version.parse('''2.4'''):
      def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			Tuple:
             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       UpperCAmelCase__    (      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()				)}'''				)



'''simple docstring'''







def       UpperCAmelCase__    (      UpperCAmelCase__				)			->			int:
       assert (
           isinstance(UpperCAmelCase__,       UpperCAmelCase__				) and number_of_steps > 0
       ), F'''number_of_steps needs to be positive integer, your input {number_of_steps}'''
       if number_of_steps == 1:
              return 1
       A_					,			A_						=      1, 1
       for _ in range(number_of_steps - 1				):
              A_					,			A_						=      current + previous, current
       return current


if __name__ == "__main__":
      import doctest

      doctest.testmod()
