roofline.devPublic Beta

GELU Activation

0VERY EASYRankedReport issue

Given vector x‾\underline{x} of length nn, produce vector y‾\underline{y} of length nn such that, with ii indexing over nn,

yi=xi2(1+tanh⁡(2π(xi+0.044715⋅xi3)))y_i = \frac{x_i}{2} \left( 1 + \tanh\left( \sqrt{\tfrac{2}{\pi}} \left( x_i + 0.044715 \cdot x_i^3 \right) \right) \right)

Do not use the exact erf-based GELU. Use the approximate form above.

Input

  • n - the number of elements in the vectors.
  • x - input vector of length nn containing floats −20≤xi≤20-20 \leq x_i \leq 20.

Output

  • y - output vector of length n where each element is the approximate GELU activation applied to the corresponding element of x.
Open on a desktop browser to write and submit code.