From a650764254883499a061c6931950ef2ad64368c7 Mon Sep 17 00:00:00 2001 From: locnd182644 Date: Mon, 5 Jan 2026 14:13:31 +0700 Subject: [PATCH 1/2] [Relax][Onnx] Pass output_padding param in ConvTranspose - When implement ConvTranspose op, pass output_padding param --- python/tvm/relax/frontend/onnx/onnx_frontend.py | 1 + src/relax/op/nn/convolution.cc | 2 +- tests/python/relax/test_frontend_onnx.py | 12 +++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/python/tvm/relax/frontend/onnx/onnx_frontend.py b/python/tvm/relax/frontend/onnx/onnx_frontend.py index b41f56bfd42f..2212fa6c68ea 100644 --- a/python/tvm/relax/frontend/onnx/onnx_frontend.py +++ b/python/tvm/relax/frontend/onnx/onnx_frontend.py @@ -1334,6 +1334,7 @@ def _impl_v1(cls, bb, inputs, attr, params): weight=inputs[1], strides=attr.get("strides", 1), padding=attr.get("pads", 0), + output_padding=attr.get("output_padding", 0), dilation=attr.get("dilations", 1), groups=attr.get("group", 1), data_layout=data_layout, diff --git a/src/relax/op/nn/convolution.cc b/src/relax/op/nn/convolution.cc index ca09c0f1cbf5..3fba58ede2be 100644 --- a/src/relax/op/nn/convolution.cc +++ b/src/relax/op/nn/convolution.cc @@ -786,7 +786,7 @@ Expr conv2d_transpose(Expr data, Expr weight, ffi::Array strides, CHECK_GT(groups, 0) << "The number of groups in convolution is expected to be positive. However, " "the given number of groups is " << groups; - CHECK_EQ(output_padding.size(), 2) << "The input output_padding length is expected to be 4. " + CHECK_EQ(output_padding.size(), 2) << "The input output_padding length is expected to be 2. " "However, the given output_padding is " << output_padding; CHECK_EQ(strides.size(), 2) diff --git a/tests/python/relax/test_frontend_onnx.py b/tests/python/relax/test_frontend_onnx.py index 447e1ac99d63..4dcc632eb66c 100644 --- a/tests/python/relax/test_frontend_onnx.py +++ b/tests/python/relax/test_frontend_onnx.py @@ -1171,11 +1171,12 @@ def _verify_conv(input_shape, weight_shape): _verify_conv([3, 4, 32, 32, 32], [2, 4, 3, 3, 3]) # group=2 -@pytest.mark.parametrize("stride", [1, 2]) +@pytest.mark.parametrize("stride", [2]) @pytest.mark.parametrize("dilation", [1]) @pytest.mark.parametrize("bias", [True, False]) @pytest.mark.parametrize("pad", [0, 2]) -def test_conv_transpose(stride: int, dilation: int, pad: int, bias: bool): +@pytest.mark.parametrize("output_pad", [0, 1]) +def test_conv_transpose(stride: int, dilation: int, pad: int, bias: bool, output_pad: int): def _verify_conv_transpose(input_shape, weight_shape): nd = len(weight_shape) - 2 output_shape = [input_shape[0], weight_shape[0]] + [ @@ -1190,6 +1191,7 @@ def _verify_conv_transpose(input_shape, weight_shape): strides=[stride] * nd, dilations=[dilation] * nd, pads=[pad] * nd * 2, + output_padding=[output_pad] * nd, group=input_shape[1] // weight_shape[1], ) graph = helper.make_graph( @@ -1206,9 +1208,9 @@ def _verify_conv_transpose(input_shape, weight_shape): model = helper.make_model(graph, producer_name="conv_transpose_test") check_correctness(model, atol=1e-4) - # ConvTranspose1D - _verify_conv_transpose([3, 4, 32], [4, 4, 3]) - _verify_conv_transpose([3, 4, 32], [4, 2, 3]) # group=2 + # # ConvTranspose1D + # _verify_conv_transpose([3, 4, 32], [4, 4, 3]) + # _verify_conv_transpose([3, 4, 32], [4, 2, 3]) # group=2 # ConvTranspose2D _verify_conv_transpose([3, 4, 32, 32], [4, 4, 3, 3]) _verify_conv_transpose([3, 4, 32, 32], [4, 2, 3, 3]) # group=2 From 0148bc762b8e6835aab2284ebc740cbc083e44f8 Mon Sep 17 00:00:00 2001 From: locnd182644 Date: Mon, 5 Jan 2026 14:53:52 +0700 Subject: [PATCH 2/2] Fix test --- tests/python/relax/test_frontend_onnx.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/python/relax/test_frontend_onnx.py b/tests/python/relax/test_frontend_onnx.py index 4dcc632eb66c..eb4c557e754c 100644 --- a/tests/python/relax/test_frontend_onnx.py +++ b/tests/python/relax/test_frontend_onnx.py @@ -1208,9 +1208,9 @@ def _verify_conv_transpose(input_shape, weight_shape): model = helper.make_model(graph, producer_name="conv_transpose_test") check_correctness(model, atol=1e-4) - # # ConvTranspose1D - # _verify_conv_transpose([3, 4, 32], [4, 4, 3]) - # _verify_conv_transpose([3, 4, 32], [4, 2, 3]) # group=2 + # ConvTranspose1D + _verify_conv_transpose([3, 4, 32], [4, 4, 3]) + _verify_conv_transpose([3, 4, 32], [4, 2, 3]) # group=2 # ConvTranspose2D _verify_conv_transpose([3, 4, 32, 32], [4, 4, 3, 3]) _verify_conv_transpose([3, 4, 32, 32], [4, 2, 3, 3]) # group=2