Skip to content
class

SqrtBackward

SqrtBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

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

Saves the output yy because the backward formula ∂y/∂x=1/(2y)\partial y / \partial x = 1 / (2y) is cheaper and numerically identical to recomputing x\sqrt{x}. Defined for x≥0x \geq 0; negative inputs produce NaN.

Math

\frac{\partial y}{\partial x} = \frac{1}{2\sqrt{x}} = \frac{1}{2y}, \qquad \frac{\partial \mathcal{L}}{\partial x} = \frac{1}{2y}\,\frac{\partial \mathcal{L}}{\partial y}, \quad x \geq 0.$$

Attributes

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

Notes

Dispatch: a correctly rounded root on CPU (vvsqrt for F64, a plain loop for F32 because vvsqrtf is not exact — backend/cpu/Vforce.cpp) / MLX sqrt (GPU). Gradient is unbounded as x→0+x \to 0^+.

Static methods

1
static

dispatch

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

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

Methods

2
fn

grad_formula

int grad_formula(const int & g)

Backward — ∂y/∂x=1/(2y)\partial y/\partial x = 1/(2y), scaled by grad_out.

fn

grad_formula_impl

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

Graph-mode backward: ∂x=g/(2y)\partial x = g / (2y) where y=xy = \sqrt{x} is the saved output; kept inside the autograd graph.