Skip to content

fix: correct conv/pool padding, reshape 0/-1, reject unsupported ops at load - #3

Merged
asjad2401 merged 2 commits into
mainfrom
fix/padding-reshape-unsupported-ops
Oct 5, 2026
Merged

asjad2401 merged 2 commits into
mainfrom
fix/padding-reshape-unsupported-ops

Conversation

@asjad2401

Copy link
Copy Markdown
Owner

Summary

Fixes several cases where the interpreter silently produced wrong output shapes/values or panicked.

  • Asymmetric padding (Conv2d, MaxPool2d, AveragePool2d): pads were averaged per axis ((top+bottom)/2), giving wrong output shapes. Uneven pads are now applied to the input explicitly — zeros for conv, -inf for max pool, and a padded ones-mask normalization for avg pool with count_include_pad=0 so padding never counts toward the average.
  • auto_pad: SAME_UPPER / SAME_LOWER / VALID were ignored (treated as no padding). Pads are now computed from the input shape per the ONNX spec. Common in TF-exported models.
  • ceil_mode: was hard-coded to false in pooling; now passed through.
  • Reshape: a target shape containing both 0 and -1 (e.g. [0, -1]) panicked with divide-by-zero. Shape is now read from onnx-ir's parsed config, which also covers the opset < 5 shape attribute.
  • Unsupported ops: load_onnx now raises RuntimeError: unsupported ONNX op(s): ... instead of skipping them with a warning and failing (or misbehaving) at inference time.

Shared padding logic lives in the new src/interpreter/ops/padding.rs.

Testing

New tests/test_ops.py builds single-node models on the fly and compares against ONNX Runtime (15 cases: conv padding modes, pooling, reshape, load error). Added to CI.

  • Against the previous code: 11/15 fail (wrong shapes, divide-by-zero panic, no load error).
  • With this change: 15/15 pass, max abs diff < 1e-6.
  • Existing test_bridge.py and compare_ort.py still pass; cargo fmt --check and clippy -D warnings clean.

Known limitation

AveragePool dilation is still ignored — Burn's avg_pool2d doesn't take a dilation parameter (unchanged from before).

🤖 Generated with Claude Code

…at load

- Resolve real per-side pads (incl. auto_pad SAME_UPPER/SAME_LOWER/VALID)
  instead of averaging asymmetric pads; uneven pads are applied to the
  input explicitly (zeros for conv, -inf for max pool, mask-normalized
  for avg pool with count_include_pad=0).
- Pass ceil_mode through to pooling.
- Reshape: read shape from parsed config (supports opset<5 attribute) and
  fix divide-by-zero when the target shape contains both 0 and -1.
- load_onnx now errors listing unsupported ops instead of skipping them
  at inference time.
- Add tests/test_ops.py comparing edge cases against ONNX Runtime; run in CI.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Latest onnx writes IR 14 while latest onnxruntime reads up to 13, which
broke compare_ort.py. Also drop the main-only pull_request filter so
stacked PRs are checked.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@asjad2401
asjad2401 merged commit a696654 into main Oct 5, 2026
4 checks passed
@asjad2401
asjad2401 deleted the fix/padding-reshape-unsupported-ops branch October 5, 2026 14:27
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