Skip to content
class

SignBackward

SignBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for the element-wise sign function y=sign(x)∈{−1,0,+1}y = \mathrm{sign}(x) \in \{-1, 0, +1\}.

Because sign is piecewise constant its derivative vanishes almost everywhere; the node therefore carries no gradient information. kHasGradient = false tells UnaryKernel::forward to skip the autograd wiring entirely, and grad_formula returns an empty CpuStorage only as a defensive zero-sentinel if it is ever invoked manually.

Math

\frac{\partial y}{\partial x} = 0 \text{ almost everywhere}.$$

Attributes

schema_v1OpSchema
Registered as "sign" with AmpPolicy::KeepInput — integer dtypes pass through unmodified.
kSavesInputbool
false.
kHasGradientbool
false — no autograd edge is created.

Notes

Dispatch: Accelerate sign kernel (CPU) / MLX sign (GPU).

Static methods

1
static

dispatch

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

Forward — calls IBackend::sign to compute y=sign(x)∈{−1,0,+1}y = \mathrm{sign}(x) \in \{-1, 0, +1\}.

Methods

2
fn

grad_formula

int grad_formula(const int & g)

Backward — ∂y/∂x=0\partial y/\partial x = 0 almost everywhere: a zero gradient, kept in the graph as the reference framework keeps it.

fn

grad_formula_impl

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

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