3
Eg @ sf d dl Z d dlZd dlmZ d dlmZmZ ddlmZ eje Z
G dd dejZG dd d ejZ
G d
d dejZG dd
d
ejZG dd dejZG dd dejZG dd dejZG dd dejZej e e e
ej e
dde e e ed$de e ej d
Zdd ZedZedZedZedZed Zed!Zed"Zed#Z dS )% N)version)Tensornn )loggingc @ s e Zd ZdZeedddZdS )NewGELUActivationz
Implementation of the GELU activation function currently in Google BERT repo (identical to OpenAI GPT). Also see
the Gaussian Error Linear Units paper: https://arxiv.org/abs/1606.08415
)inputreturnc C s6 d| dt jtjdtj |dt j|d S )Ng ?g ?g @gHm?g @)torchtanhmathsqrtpipow)selfr r B/usr/local/lib/python3.6/site-packages/transformers/activations.pyforward! s zNewGELUActivation.forwardN)__name__
__module____qualname____doc__r r r r r r r s r c sH e Zd ZdZded fdd
ZeedddZeedd d
Z Z S )GELUActivationa
Original Implementation of the GELU activation function in Google BERT repo when initially created. For
information: OpenAI GPT's GELU is slightly different (and gives slightly different results): 0.5 * x * (1 +
torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 * torch.pow(x, 3)))) This is now written in C in nn.functional
Also see the Gaussian Error Linear Units paper: https://arxiv.org/abs/1606.08415
F)use_gelu_pythonc s<