OpenAI's gelu implementation.
(x)
| 98 | |
| 99 | @torch.jit.script |
| 100 | def gelu_impl(x): |
| 101 | """OpenAI's gelu implementation.""" |
| 102 | return 0.5 * x * (1.0 + torch.tanh(0.7978845608028654 * x * |
| 103 | (1.0 + 0.044715 * x * x))) |
| 104 | |
| 105 | def gelu(x): |
| 106 | return gelu_impl(x) |