Skip to content
class

AvgPoolNdBackward

AvgPoolNdBackward

Python wrappers

Public Python APIs implemented by this engine symbols.

Autograd node for N-dimensional average pooling.

Each output element is the arithmetic mean of a K0×⋯×KN−1K_0 \times \cdots \times K_{N-1} window of the (optionally zero-padded) input. No activations need to be saved — the backward pass is a uniform scatter that distributes each output gradient over the ∏iKi\prod_i K_i input elements of its window.

Attributes

schema_v1OpSchema
Registered op ("avg_pool1d" / "avg_pool2d" / "avg_pool3d", AmpPolicy::KeepInput).
K_int[N]
Pooling window size per axis.
stride_int[N]
Per-axis stride (already resolved from the 0 sentinel).
pad_int[N]
Per-axis zero-padding.

Static methods

1
static

forward

→TensorImplPtr
int forward(const int & x, const int (&)[N] K, const int (&)[N] stride, const int (&)[N] pad, bool ceil_mode, bool count_include_pad)

Forward — emit the mean of each window.

Parameters

xTensorImplPtr
Input of shape (B, C, S_0, ..., S_{N-1}).
Karray<int, N>
Per-axis window size.
stridearray<int, N>
Per-axis stride. stride[i] == 0 defaults to K[i].
padarray<int, N>
Per-axis zero-padding amount.

Returns

TensorImplPtr

Output of shape (B, C, O_0, ..., O_{N-1}) with each Oi=⌊(Si+2pi−Ki)/si+1⌋O_i = \lfloor (S_i + 2 p_i - K_i)/s_i + 1 \rfloor.

Raises

ShapeMismatch
If the input rank disagrees with N + 2 or any computed output extent is non-positive.

Methods

2
fn

apply

→vector<Storage>
int apply(int grad_out)

Backward — distribute grad_out evenly over each pooling window (each contributing element receives 1 / prod(K) of the upstream gradient).

Parameters

grad_outStorage
Upstream gradient shaped like the forward output.

Returns

vector<Storage>

Single-element vector containing dx.

fn

apply_for_graph

int apply_for_graph(const int & grad_out)

Graph-mode backward. Covers the non-overlapping, unpadded window — which is what avg_pool2d(x, k) means — and refuses the rest rather than answering it wrongly; see the definition.