Autograd node for 2-D nearest-neighbour interpolation.
Resizes a 4-D tensor of shape (N, C, H_in, W_in) to
(N, C, H_out, W_out) by copying, for each output pixel, the single
nearest input pixel:
(the floor mapping above is the exact rule the forward backend kernel
uses). Because the map is many-to-one, the backward scatter-adds each
output gradient onto its unique source pixel — an input pixel selected by
k output pixels receives the sum of those k gradients.
Attributes
schema_ v1OpSchema"interpolate_nearest_2d", AmpPolicy::KeepInput (pure gather, no arithmetic — input dtype is preserved).H_ in_ , W_ in_intH_ out_ , W_ out_intorig_ shape_Shape(N, C, H_in, W_in) shape for backward reconstruction.Static methods
1Compute the nearest-neighbour resize with autograd wiring.
Parameters
inputTensorImplPtr(N, C, H_in, W_in).H_ outintW_ outintReturns
TensorImplPtrResampled tensor of shape (N, C, H_out, W_out).
Raises
ShapeMismatchinput is not 4-D.Methods
2Backward pass: scatter-adds grad_out onto the source pixels using the same floor coordinate mapping as the forward.
Graph-mode backward. Covers integer upscaling — the case a decoder actually uses — and refuses anything else by name; see the definition.