IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

gelu

def gelu[dtype: DType, simd_width: SIMDSize, accum: DType = get_accum_type[dtype]()](x: SIMD[dtype, simd_width]) -> SIMD[dtype, simd_width]

Compute the exact GELU activation using the equation 0.5βˆ—xβˆ—(1+erf(x/sqrt(2)))0.5 * x * (1 + erf(x / sqrt(2))).

Constraints:

Type must be a floating point Dtype.

Parameters:

  • ​dtype (DType): DType used for the computation.
  • ​simd_width (SIMDSize): SIMD width used for the computation.
  • ​accum (DType): Higher-precision accumulation dtype used internally; defaults to get_accum_type[dtype]().

Args:

Returns:

SIMD[dtype, simd_width]: The result of the exact GELU operation.