OpenAI's gelu implementation.
(x)
| 9 | |
| 10 | @torch.jit.script |
| 11 | def gelu_impl(x): |
| 12 | """OpenAI's gelu implementation.""" |
| 13 | return 0.5 * x * (1.0 + torch.tanh(0.7978845608028654 * x * |
| 14 | (1.0 + 0.044715 * x * x))) |
| 15 | |
| 16 | def gelu(x): |
| 17 | return gelu_impl(x) |