Support Conv2D with non-zero spatial padding#269
Open
npow wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ONNX parser rejects any
Conv2Dwithpadding != [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_shapehas to account for the larger effective input.Convolution<T>andConvCtx<E>get aninput_padding: [usize; 2]field with#[serde(default)]so old serialized proofs still deserialize.