Skip to content
class

RoundBackward

RoundBackward

Python wrappers

Public Python APIs implemented by this engine symbol.

Autograd node for element-wise round-to-nearest-even: y=round⁡(x)y = \operatorname{round}(x).

Piecewise-constant; derivative is zero almost everywhere and undefined at half-integer boundaries. The node stays in the graph with that zero gradient, as the reference keeps it.

Math

yi=round⁡(xi)y_i = \operatorname{round}(x_i)

Ties round to even ("banker's rounding"), matching IEEE-754.

See Also

FloorBackward, CeilBackward.

Attributes

kSavesInputbool
false — no tensor needs to be saved across the backward pass.
kHasGradientbool
true — kept in the graph with a zero gradient.
schema_v1OpSchema
Op name "round" with AmpPolicy::KeepInput (integer inputs pass through unchanged).

Notes

CPU dispatch routes through backend::IBackend::round; GPU uses MLX's round primitive. Integer dtypes are a no-op.

Static methods

1
static

dispatch

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

Forward — calls IBackend::round to compute y=round⁡(x)y = \operatorname{round}(x) with banker's rounding.

Methods

2
fn

grad_formula

→Storage
int grad_formula(const int & g)

Zero gradient, shaped like the output.

Parameters

gconst Storage&
Incoming upstream gradient (ignored).

Returns

Storage

Zeros shaped like the output.

fn

grad_formula_impl

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

Graph-mode backward — zero, like grad_formula, so the node stays differentiable under create_graph.