Skip to content
class

CubeRootBackward

CubeRootBackward

Autograd node for element-wise cube root: y=x3=x1/3y = \sqrt[3]{x} = x^{1/3}.

Unlike sqrt, cube root is real-valued for all real inputs — negative arguments produce negative outputs and the operation is monotone increasing. The backward formula divides by 3y23 y^{2}, which is the only undefined point (at x=y=0x = y = 0).

Math

Forward

yi=xi3=sgn⁡(xi) ∣xi∣1/3y_i = \sqrt[3]{x_i} = \operatorname{sgn}(x_i)\, |x_i|^{1/3}

Backward

\frac{\partial L}{\partial y_i}$$ **See Also** `cube_root_op`.

Attributes

kSavesInputbool
false — the input is not needed for the backward pass.
kSavesOutputbool
true — the forward output yy is saved so the backward pass can compute 1/(3y2)1 / (3 y^{2}) without re-invoking the cube-root kernel.
schema_v1OpSchema
Op name "cube_root" with AmpPolicy::ForceFP32 because the cube root is numerically unreliable in half precision (loss of accuracy near zero and for very large magnitudes).

Notes

CPU dispatch uses Apple Accelerate's vvcbrtf (vector cube root in float32); GPU dispatch routes through MLX's power primitive applied with exponent 1/31/3. The gradient diverges at x=0x = 0 — callers should guard against zero inputs if they intend to backpropagate.

Static methods

1
static

dispatch

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

Forward — calls IBackend::cube_root to compute y=x3y = \sqrt[3]{x}.

Methods

2
fn

grad_formula

→Storage
int grad_formula(const int & g)

Computes ∂L/∂x=g/(3y2)\partial L/\partial x = g / (3 y^{2}) from the saved output yy — squaring yy is cheaper than recomputing x32\sqrt[3]{x}^{2}.

Parameters

gconst Storage&
Upstream gradient ∂L/∂y\partial L/\partial y.

Returns

Storage

Gradient with respect to x. Undefined at slots where the saved output is zero (division by zero); callers must avoid differentiating through x=0x = 0.

fn

grad_formula_impl

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

Graph-mode backward: g/(3y2)g / (3y^2) from the tracked output.