Skip to content

[tmva][sofie] fix SAME_UPPER/SAME_LOWER autopad padding formula#21793

Open
harz05 wants to merge 1 commit intoroot-project:masterfrom
harz05:fix/sofie-same-autopad
Open

[tmva][sofie] fix SAME_UPPER/SAME_LOWER autopad padding formula#21793
harz05 wants to merge 1 commit intoroot-project:masterfrom
harz05:fix/sofie-same-autopad

Conversation

@harz05
Copy link
Copy Markdown
Contributor

@harz05 harz05 commented Apr 4, 2026

Changes:

The SAME_UPPER/SAME_LOWER autopad calculation in ROperator_Conv.hxx and ROperator_Pool.hxx was using kernel/2 as a fixed pad value, ignoring input size and stride entirely. This gave wrong padding for any non-trivial case.

Fixed to use the correct ONNX formula:

output_size = ceil(input_size / stride)
total_pad = max(0, (output_size - 1) * stride + kernel - input_size)

Also fixed the direction: SAME_UPPER should place the extra pad at the end, not the beginning (it was swapped earlier).

Also added regression tests for both ConvWithAutopadSameLower and ConvWithAutopadSameUpper (kernel=3, stride=1 and stride=2 cases). Tests use odd-kernel models where padding is symmetric, since the existing Im2col utility only supports symmetric padding. Even-kernel SAME padding (asymmetric begin/end split) hits a separate pre-existing limitation in Im2col and I'll be adding that as an seperate issue.

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

This PR fixes #21737

@harz05 harz05 requested a review from lmoneta as a code owner April 4, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tmva][sofie] Conv and Pool SAME_UPPER/SAME_LOWER auto-padding computes wrong output shape

2 participants