fn

rsqrt

Tensor
rsqrt(input: Tensor)
source

Element-wise reciprocal square root.

Computes 1/x1/\sqrt{x} for each entry. x must be strictly positive.

Parameters

inputTensor
Input tensor.

Returns

Tensor

Element-wise result with the same shape as input.

Notes

Mathematical definition:

outi=1inputi,inputi>0\text{out}_i = \frac{1}{\sqrt{\text{input}_i}}, \quad \text{input}_i > 0

Gradient: 1/(2x3/2)-1 / (2 x^{3/2}). Heavily used inside layer / RMS normalization.

Examples

>>> import lucid
>>> x = lucid.tensor([1.0, 2.0, 3.0])
>>> lucid.rsqrt(x)
Tensor([...])