---
title: "ClikaRT::ops::gelu"
sidebar_label: "gelu"
description: "Gaussian error linear unit. \\[ \\mathrm{gelu}(x) = x\\,\\Phi(x) = \\tfrac{x}{2}\\Bigl(1 + \\mathrm{erf}\\bigl(x/\\sqrt{2}\\bigr)\\Bigr) \\] approximate = GeluMode::Tanh selects the cheaper tanh form used by many…"
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## gelu() {#gelu}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`gelu`**([`Tensor`](../Tensor.md) `input`, [`GeluMode`](./index.md#GeluMode) `approximate` `=` [`GeluMode::None`](./index.md#GeluMode))

</div>

Gaussian error linear unit.

$$
\mathrm{gelu}(x) = x\,\Phi(x) = \tfrac{x}{2}\Bigl(1 + \mathrm{erf}\bigl(x/\sqrt{2}\bigr)\Bigr)
$$

`approximate = `[`GeluMode::Tanh`](./index.md#GeluMode) selects the cheaper tanh form used by many transformer checkpoints; [`GeluMode::None`](./index.md#GeluMode) is the exact erf form.

**Parameters**

- `input`: the input tensor.
- `approximate`: the GELU variant. Default [`GeluMode::None`](./index.md#GeluMode) (exact).

**Throws**

- `ClikaRT::Error`: when the input's dtype is not served for this operation (the machine-readable reason rides `code_name()`).

**Returns:** a new tensor, same shape and dtype as `input`.

```cpp
auto y = ClikaRT::ops::gelu(x, ClikaRT::ops::GeluMode::Tanh);
```

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 779

</div>
