Skip to content
class

CubeBackward

CubeBackward

Autograd node for the element-wise cube y=x3y = x^3.

Saves the input x so the backward pass can build 3x23x^2 in grad_formula and multiply it against the upstream gradient.

Math

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

Attributes

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

Notes

Dispatch: dedicated Accelerate kernel (CPU) / MLX element-wise cube (GPU).

Static methods

1
static

dispatch

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

Forward — calls IBackend::cube to compute y=x3y = x^3.

Methods

2
fn

grad_formula

int grad_formula(const int & g)

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

fn

grad_formula_impl

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

Graph-mode backward: 3x2⋅g3x^2 \cdot g kept inside the autograd graph.