Skip to content
class

RsqrtBackward

RsqrtBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for the element-wise reciprocal square root y=1/xy = 1/\sqrt{x}.

Saves the output yy so the backward pass can form y3y^3 without re-evaluating rsqrt. Defined for x>0x > 0.

Math

\frac{\partial y}{\partial x} = -\tfrac{1}{2}\,x^{-3/2} = -\tfrac{1}{2}\,y^3, \qquad \frac{\partial \mathcal{L}}{\partial x} = -\tfrac{1}{2}\,y^3\,\frac{\partial \mathcal{L}}{\partial y}, \quad x > 0.$$

Attributes

schema_v1OpSchema
Registered as "rsqrt" with AmpPolicy::Promote.
kSavesInputbool
false.
kSavesOutputbool
true — saved tensor is y=1/xy = 1/\sqrt{x}.

Notes

Dispatch: on CPU, the correctly rounded root and then the correctly rounded reciprocal of it, which is how the reference computes it. On GPU, MLX rsqrt.

Static methods

1
static

dispatch

int dispatch(backend::IBackend & be, const int & a, const int & shape, Dtype dt)

Forward — calls IBackend::rsqrt to compute y=1/xy = 1/\sqrt{x}.

Methods

2
fn

grad_formula

int grad_formula(const int & g)

Backward — ∂y/∂x=−12 y3\partial y/\partial x = -\tfrac{1}{2}\,y^3, scaled by grad_out.

fn

grad_formula_impl

int grad_formula_impl(const int & g, const int &, const int & out)

Graph-mode backward: the same derivative built from composable ops, so the gradient itself stays differentiable.