Skip to content

Support Conv2D with stride > 1 via post-conv decimation#271

Open
npow wants to merge 3 commits into
Lagrange-Labs:masterfrom
npow:feature/strided-conv-support
Open

Support Conv2D with stride > 1 via post-conv decimation#271
npow wants to merge 3 commits into
Lagrange-Labs:masterfrom
npow:feature/strided-conv-support

Conversation

@npow

@npow npow commented May 25, 2026

Copy link
Copy Markdown

Adds stride > 1 support to the Conv2D parser and prover.

Two bugs fixed. First, the parser hard-rejects any stride != 1. Second, step_info computed the compact strided output shape as next_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_stride on 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> and ConvCtx<E> get a stride: [usize; 2] field with #[serde(default)] so existing serialized proofs deserialize without error.

npow and others added 2 commits May 25, 2026 20:39
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>
@npow npow changed the title feat: ZK-sound strided convolution via post-conv decimation Support Conv2D with stride > 1 via post-conv decimation May 25, 2026
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.
@npow npow force-pushed the feature/strided-conv-support branch from 0fef381 to ff821fb Compare May 26, 2026 05:13
nikkolasg pushed a commit that referenced this pull request May 31, 2026
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