Skip to content
class

ConvNdBackward

ConvNdBackward

Python wrappers

Public Python APIs implemented by this engine symbols.

Autograd node for the N-dimensional cross-correlation.

Explicitly instantiated for N∈{1,2,3}N \in \{1, 2, 3\}. The per-axis hyper- parameters (stride_, pad_, dilation_) are stored as fixed-size C arrays of length N to avoid heap allocation on the forward hot path. groups_ partitions both C_in and C_out into independent filter blocks (groups_ == C_in yields a depthwise convolution).

Backward emits three gradient slots: dx via a transposed-conv against W, dW via an im2col-then-matmul against the saved input, and db via a channel-wise reduction of grad_out.

Attributes

schema_v1OpSchema
Registered op schema ("conv1d" / "conv2d" / "conv3d") with AmpPolicy::Promote — both inputs are cast to the active AMP compute dtype before dispatch.
stride_int[N]
Per-axis stride between successive kernel placements.
pad_int[N]
Per-axis zero-padding amount applied symmetrically to both sides.
dilation_int[N]
Per-axis kernel-element spacing (atrous convolution).
groups_int
Number of input/output channel groups; defaults to 1.

Static methods

1
static

forward

→TensorImplPtr
int forward(const int & x, const int & W, const int & b, const int (&)[N] stride, const int (&)[N] pad, const int (&)[N] dilation, int groups)

Run the forward cross-correlation and attach the backward node.

Parameters

xTensorImplPtr
Input batch of shape (B, C_in, S_0, ..., S_{N-1}).
WTensorImplPtr
Filter bank of shape (C_out, C_in / groups, K_0, ..., K_{N-1}).
bTensorImplPtr
Bias of shape (C_out,); pass an empty tensor for a bias-less convolution.
stridearray<int, N>
Per-axis stride (s_0, ..., s_{N-1}).
padarray<int, N>
Per-axis zero-padding applied to each side.
dilationarray<int, N>
Per-axis kernel-element spacing (atrous convolution).
groupsint
Filter grouping; both C_in and C_out must be divisible by it. groups == C_in yields depthwise convolution.

Returns

TensorImplPtr

Output of shape (B, C_out, O_0, ..., O_{N-1}) where for each spatial axis ii Oi=⌊Si+2pi−di(Ki−1)−1si+1⌋.O_i = \left\lfloor \frac{S_i + 2 p_i - d_i (K_i - 1) - 1}{s_i} + 1 \right\rfloor.

Raises

ShapeMismatch
If the input rank disagrees with N + 2, if C_in / C_out are not divisible by groups, if C_in / groups does not match W's second axis, if b is not 1-D of length C_out, or if the computed output extent is non-positive.
DeviceMismatch
If x, W, b are not all on the same device.

Methods

2
fn

apply

→vector<Storage>
int apply(int grad_out)

Backward — compute gradients [dx, dW, db] for the three saved inputs.

Parameters

grad_outStorage
Upstream gradient with the forward output shape.

Returns

vector<Storage>

Three slots in declaration order: dx (transposed-conv), dW (im2col + matmul), db (channel-wise reduction).

fn

apply_for_graph

int apply_for_graph(const int & grad_out)

Graph-mode backward. Covers the ungrouped, undilated 2-D case — which is every convolution in the model zoo — and refuses the rest by name; see the definition.