[BugFix][Relax][ONNX] Honor auto_pad in ConvTranspose converter#19450
Merged
Conversation
The ConvTranspose ONNX converter ignored the `auto_pad` attribute and fell back to `pads=0`, producing wrong output shapes for models that rely on SAME_UPPER / SAME_LOWER / VALID. Spec-conform pads are now derived from `input_shape`, `strides`, `kernel_shape`, `dilations`, and `output_padding` per the ONNX ConvTranspose semantics. Adds `test_conv_transpose_auto_pad` covering the three modes across 1D/2D/3D inputs.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for the auto_pad attribute in the ConvTranspose operator within the ONNX frontend, covering SAME_UPPER, SAME_LOWER, and VALID modes, and includes new test cases. Feedback suggests simplifying the padding calculation to avoid dependencies on input spatial dimensions, which prevents potential TypeErrors when handling symbolic shapes in Relax.
…to_pad Addresses review feedback: the auto_pad SAME_* total_padding formula simplifies to a value that depends only on kernel_shape, dilations, strides, and output_padding once the target output size of `input_size * stride` is substituted in. This keeps the converter usable when spatial dimensions are symbolic (`tir.Var`), where the previous `int(s)` would have raised TypeError.
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.
Motivation
The
ConvTransposeONNX → Relax converter silently drops theauto_padattribute.Convhas dedicated handling (onnx_frontend.pylines 1383-1404), butConvTransposepassespadsstraight through, defaulting to 0 when the attribute is absent. Models that rely onauto_pad=SAME_UPPER/SAME_LOWER/VALIDtherefore produce the wrong output shape after import.Minimal repro (against onnxruntime):
Fix
Compute
padsfrom the ONNX spec equation before delegating to the Relax conv-transpose op:then split begin/end by
SAME_UPPERvsSAME_LOWER.VALIDbecomespads=0;NOTSETkeeps the user-suppliedpads. We deliberately do not reuse Conv'sautopad()helper because it pads the input data, whereas ConvTranspose subtracts pads from the output.The
output_shapeattribute (which, when set, also overridespadsper spec) remains unsupported; leaving that as a follow-up.Test plan