CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
activations_tf.cpython-310.pyc50 linesDownload Raw Back to __pycache__
1o

2.�Yiy�
@s3ddlZddlZddlmZzddlZWneefy/ddlZeej	�j4dkr-ed��Ynwdd�Zdd�Z
d	d5�Zdd�Zd
d�Zdd�Zddd�Zeejj�ed�krbdd�ZejjZeZneZe
Zeeeeeeeejjejjejjejjejjd�Zdd�ZdS)�N)�parse�z�Your currently installed version of Keras is Keras 3, but this is not yet supported in Transformers. Please install the backwards-compatible tf-keras package with `pip install tf-keras`.c6Cs:t�|�}ddtj�|t�t�d�|j��}||S)a~7    Gaussian Error Linear Unit. Original Implementation of the gelu activation function in Google Bert repo when8    initially created. For information: OpenAI GPT's gelu is slightly different (and gives slightly different results):9    0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) Also see10    https://huggingface.co/papers/1606.0841511    ��?��?�@)�tf�convert_to_tensor�math�erf�cast�sqrt�dtype)�x�cdf�r��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\transformers/activations_tf.py�_gelu"s12(rcCs`t�|�}t�tj|j�}t�d|j�}ddt�t�d|�||t�|d��}||S)z�13    Gaussian Error Linear Unit. This is a smoother version of the GELU. Original paper: https://huggingface.co/papers/1606.084114 15    Args:16        x: float Tensor to perform activation17 18    Returns:19        `x` with the GELU activation applied.20    ��Hm��?rrr�)	rrrr	�pir
�tanhr�pow)rr�coeffrrrr�	_gelu_new/s2122 230rcCs t�|�}|t�tj�|��S)N)rrrr	Zsoftplus�rrrr�mishAs24rcCsPt�|�}t�d|j�}t�d|j�}d|dt�||d|||�S)Nrg���3E��?rr)rrrr
r)rZcoeff1Zcoeff2rrr�	gelu_fastGs25*rcCs,t�|�}t�d|j�}|tj�||�S)Ng�Zd;�?)rrrr
r	�sigmoid)rrrrr�26quick_geluOs27rcCst�t|�dd�S)a�28    Clip the range of possible GeLU outputs between [-10, 10]. This is especially useful for quantization purpose, as29    it allows mapping 2 negatives values in the GeLU spectrum. For more information on this trick, please refer to30    https://huggingface.co/papers/2004.0960231 32    Gaussian Error Linear Unit. Original Implementation of the gelu activation function in Google Bert repo when33    initially created. For information: OpenAI GPT's gelu is slightly different (and gives slightly different results):34    0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) Also see35    https://huggingface.co/papers/1606.08415 :param x: :return:36    i�����37)rZ
clip_by_valuerrrrr�gelu_10Usr �����cCs$tj|d|d�\}}|tj�|�S)a�38    Gated Linear Unit. Implementation as defined in the original paper (see https://huggingface.co/papers/1612.08083), where39    the input `x` is split in two halves across a dimension (`axis`), A and B, returning A * sigmoid(B).40 41    Args:42        `x`: float Tensor to perform activation43        `axis`: dimension across which `x` be split in half44 45    Returns:46        `x` with the GLU activation applied (with its size halved across the dimension `axis`).47    r)�axis)r�splitr	r)rr"�a�brrr�glucsr&z2.4cCstjj|dd�S)NT)Zapproximate)�keras�activations�gelurrrr�approximate_gelu_wrapusr*)r)r r�gelu_newr&rr�relurZsilu�swishrcCs,|tvrt|Std|�dtt�������)Nz	function z not found in ACT2FN mapping )�ACT2FN�KeyError�list�keys)Zactivation_stringrrr�get_tf_activation�sr2)r!)r	Z48tensorflowrZpackaging.versionrZtf_kerasr'�ModuleNotFoundError�ImportError�__version__�major�49ValueErrorrrrrrr r&�version�VERSIONr*r(r)r+r,rr-rr.r2rrrr�<module>sP���
50�
Aluode/PerceptionLabPortable · CoolFace