


'''simple docstring'''





import math

import tensorflow as tf
from packaging import version


def      a	(							SCREAMING_SNAKE_CASE_      :		Union[str, Any]       ):






       """simple docstring"""





       UpperCamelCase    :	List[Any]   	=		tf.convert_to_tensor(SCREAMING_SNAKE_CASE_       )
       UpperCamelCase    :	List[str]   	=		0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0       )							,			x.dtype       )       ))

       return x * cdf


def      a	(							SCREAMING_SNAKE_CASE_      :		Optional[Any]       ):






       """simple docstring"""





       UpperCamelCase    :	List[str]   	=		tf.convert_to_tensor(SCREAMING_SNAKE_CASE_       )
       UpperCamelCase    :	Tuple   	=		tf.cast(math.pi							,			x.dtype       )
       UpperCamelCase    :	int   	=		tf.cast(0.044715							,			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      a	(							SCREAMING_SNAKE_CASE_      :		str       ):






       """simple docstring"""





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

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


def      a	(							SCREAMING_SNAKE_CASE_      :		str       ):






       """simple docstring"""





       UpperCamelCase    :	Optional[Any]   	=		tf.convert_to_tensor(SCREAMING_SNAKE_CASE_       )
       UpperCamelCase    :	Union[str, Any]   	=		tf.cast(0.044715							,			x.dtype       )
       UpperCamelCase    :	Optional[Any]   	=		tf.cast(0.7978845608							,			x.dtype       )

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


def      a	(							SCREAMING_SNAKE_CASE_      :		str       ):






       """simple docstring"""





       UpperCamelCase    :	Tuple   	=		tf.convert_to_tensor(SCREAMING_SNAKE_CASE_       )
       UpperCamelCase    :	str   	=		tf.cast(1.702							,			x.dtype       )
       return x * tf.math.sigmoid(coeff * x       )


def      a	(							SCREAMING_SNAKE_CASE_      :		Dict       ):






       """simple docstring"""





       return tf.clip_by_value(_gelu(SCREAMING_SNAKE_CASE_       )							,			-1_0							,			1_0       )


def      a	(							SCREAMING_SNAKE_CASE_      :		List[str]							,			SCREAMING_SNAKE_CASE_      :		int=-1       ):






       """simple docstring"""





       UpperCamelCase    :	Optional[int]   	=		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      a	(							SCREAMING_SNAKE_CASE_      :		Optional[Any]       ):






         """simple docstring"""





         return tf.keras.activations.gelu(SCREAMING_SNAKE_CASE_							,			approximate=SCREAMING_SNAKE_CASE_       )

  __UpperCAmelCase : str 			=				tf.keras.activations.gelu
  __UpperCAmelCase : str 			=				approximate_gelu_wrap
else:
  __UpperCAmelCase : Union[str, Any] 			=				_gelu
  __UpperCAmelCase : Union[str, Any] 			=				_gelu_new


__UpperCAmelCase : str 			=				{
    "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      a	(							SCREAMING_SNAKE_CASE_      :		Optional[int]       ):






       """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 .imports import is_tqdm_available


if is_tqdm_available():
  from tqdm.auto import tqdm as _tqdm

from ..state import PartialState


def      a	(							SCREAMING_SNAKE_CASE_      :		bool = True							,			*SCREAMING_SNAKE_CASE_      :		List[str]							,			**SCREAMING_SNAKE_CASE_      :		Tuple       ):






       """simple docstring"""





       if not is_tqdm_available():
              raise ImportError('''Accelerate\'s `tqdm` module requires `tqdm` to be installed. Please run `pip install tqdm`.'''       )
       UpperCamelCase    :	int   	=		False
       if main_process_only:
              UpperCamelCase    :	int   	=		PartialState().local_process_index == 0
       return _tqdm(*SCREAMING_SNAKE_CASE_							,			**SCREAMING_SNAKE_CASE_							,			disable=SCREAMING_SNAKE_CASE_       )

