OpenAI's gelu implementation.
(x)
| 50 | |
| 51 | @torch.jit.script |
| 52 | def gelu_impl(x): |
| 53 | """OpenAI's gelu implementation.""" |
| 54 | return 0.5 * x * (1.0 + torch.tanh(0.7978845608028654 * x * |
| 55 | (1.0 + 0.044715 * x * x))) |
| 56 | def openai_gelu(x): |
| 57 | return gelu_impl(x) |
| 58 |