Skip to content
class

MinBackward

MinBackward

Autograd node for the multi-axis reduction minimum y=min⁡i∈axesxiy = \min_{i \in \text{axes}} x_i.

Symmetric to MaxBackward: the gradient flows to positions where xix_i equals the reduced minimum. Ties share gradient equally and the same composed ge/ge equality-mask trick is used.

Math

y=min⁡i∈axesxi,∂L∂xi=1[xi=y]#{j:xj=y}⋅broadcast ⁣(∂L∂y). y = \min_{i \in \text{axes}} x_i, \qquad \frac{\partial \mathcal{L}}{\partial x_i} = \frac{\mathbb{1}[x_i = y]}{\#\{j : x_j = y\}}\cdot \mathrm{broadcast}\!\left(\frac{\partial \mathcal{L}}{\partial y} \right).

Attributes

schema_v1OpSchema
Registered as "min" with AmpPolicy::KeepInput.
kSavesOutputbool
true.

Static methods

1
static

dispatch

int dispatch(backend::IBackend & be, const int & a, const int & in_shape, const int & axes, bool keepdims, Dtype dt)

Forward — reduces a along axes via IBackend::reduce_min.

Methods

2
fn

grad_formula

int grad_formula(const int & grad_out)

Backward — argmin-indicator gradient: routes grad_out only to positions where xix_i equals the reduced min (ties share equally).

fn

scale_graph_grad

int scale_graph_grad(const int & g)

Graph-mode scaling. Without this the base class returns the broadcast gradient unchanged — the sum rule — so create_graph=True silently produced the incoming seed at every position while eager backward was correct.