Skip to content

Support Conv2D with non-zero spatial padding#269

Open
npow wants to merge 1 commit into
Lagrange-Labs:masterfrom
npow:feature/conv-padding-support
Open

Support Conv2D with non-zero spatial padding#269
npow wants to merge 1 commit into
Lagrange-Labs:masterfrom
npow:feature/conv-padding-support

Conversation

@npow

@npow npow commented May 25, 2026

Copy link
Copy Markdown

The ONNX parser rejects any Conv2D with padding != [0,0], so the standard "same conv" pattern (kernel=3, padding=1) used by ResNet, VGG and most CNNs won't load.

Zero-pads the input before the existing valid-conv circuit. Padding values are public zeros so no new constraint is needed; only output_shape has to account for the larger effective input. Convolution<T> and ConvCtx<E> get an input_padding: [usize; 2] field with #[serde(default)] so old serialized proofs still deserialize.

Previously any Conv2D with padding != [0,0] was rejected at parse time.
Adds end-to-end support for symmetric spatial zero-padding (ONNX same-conv
convention: kernel=3, pad=1 per side). parser/onnx.rs now parses and
validates symmetric pads and returns [pad_h, pad_w] to load_conv instead
of erroring. Convolution<T> gains input_padding field and new_with_padding
constructor. Tensor<T> gains zero_pad_spatial and crop_to helpers.
pad_conv in padding.rs computes effective shapes accounting for spatial
padding before FFT sizing. Adds two new tests for padded convolution.

Also fixes three pre-existing clippy lints: mem::replace -> mem::take in
prover.rs, redundant / 1 in shape arithmetic, redundant as-usize casts in
onnx.rs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant