Skip to content
class

SquareBackward

SquareBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for the element-wise square y=x2y = x^2.

Saves the input x so the backward pass can scale the upstream gradient by 2x2x.

Math

\frac{\partial y}{\partial x} = 2x, \qquad \frac{\partial \mathcal{L}}{\partial x} = 2x\,\frac{\partial \mathcal{L}}{\partial y}.$$

Attributes

schema_v1OpSchema
Registered as "square" with AmpPolicy::Promote.

Notes

Dispatch: Accelerate vDSP_vsq (CPU) / MLX square (GPU).

Static methods

1
static

dispatch

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

Forward — calls IBackend::square to compute y=x2y = x^2.

Methods

2
fn

grad_formula

int grad_formula(const int & g)

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

fn

grad_formula_impl

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

Graph-mode backward: ∂x=2x⋅g\partial x = 2x \cdot g kept inside the autograd graph.