Support Conv2D with stride > 1 via post-conv decimation#271
Open
npow wants to merge 3 commits 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.
Implements genuine stride support in the FFT-based convolution circuit using Option A (post-conv decimation): full-resolution FFT conv followed by an MLE point-expansion hadamard clearing proof that binds the strided output to the full-res output at stride positions. - Add `stride: [usize; 2]` field (serde default [1,1]) to Convolution<T> and ConvCtx<E>; add `new_with_padding_and_stride` constructor - Add shape helpers: conv2d_shape_with_padding_and_stride, padded_conv2d_shape_with_padding_and_stride - Add prover helpers: clear_garbage_strided, compact_strided, new_clearing_tensor_strided, expand_strided_point - Update prove_convolution_step and verify_convolution to expand the MLE evaluation point (free coordinate mapping, no extra sumcheck) and run the hadamard clearing over the full-resolution output tensor - Remove stride==1 restriction from ONNX parser; parse stride from ONNX node attributes with validation (square, power-of-two only) - Fix pad_conv to use the correct strided output formula and pass the original input shape to into_padded_and_ffted - Add 7 new tests: 5 unit tests for helper functions and f32 path, 1 end-to-end prove+verify test (test_prover_strided_conv) - All 153 passing tests continue to pass; 5 pre-existing GPT-2 failures (missing local model file) unchanged Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
The strided output POT-padded spatial dim was computed as (fft_spatial / stride).next_power_of_two(), which gives the wrong answer when padding is non-zero. For a 32x32 input with padding=1 and stride=2 the FFT dim is 64, giving 64/2=32 instead of the correct 16 (valid output = floor((32+2-3)/2)+1 = 16). Compute the correct shape from conv2d_shape_with_padding_and_stride using the tracked unpadded input shape when available.
0fef381 to
ff821fb
Compare
nikkolasg
pushed a commit
that referenced
this pull request
May 31, 2026
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.
Adds stride > 1 support to the Conv2D parser and prover.
Two bugs fixed. First, the parser hard-rejects any stride != 1. Second,
step_infocomputed the compact strided output shape asnext_pow2(fft_spatial / stride), which is wrong when padding is non-zero — for a 32×32 input with padding=1 and stride=2 the FFT dim is 64, so this gave 32 instead of the correct 16. The verifier's challenge point ends up 10 bits wide where the compact output is 8, and the sumcheck fails at round 0.The shape is now derived from
conv2d_shape_with_padding_and_strideon the tracked unpadded input dimensions and then POT-padded.The proof uses post-conv decimation: the full-res FFT conv runs unmodified, then a hadamard clearing proof binds the strided positions.
Convolution<T>andConvCtx<E>get astride: [usize; 2]field with#[serde(default)]so existing serialized proofs deserialize without error.