diff --git a/cgmanifests/submodules/cgmanifest.json b/cgmanifests/submodules/cgmanifest.json index f4f7e248ef..626bacd17d 100644 --- a/cgmanifests/submodules/cgmanifest.json +++ b/cgmanifests/submodules/cgmanifest.json @@ -222,7 +222,7 @@ "component": { "type": "git", "git": { - "commitHash": "bc7a70b46f4ae88383a4ca49c477fd859715620c", + "commitHash": "174de7d086a768cba29374a56a7461eff87cfdb3", "repositoryUrl": "https://github.com/onnx/onnx" }, "comments": "git submodule at cmake/external/onnx" diff --git a/cmake/external/onnx b/cmake/external/onnx index bc7a70b46f..174de7d086 160000 --- a/cmake/external/onnx +++ b/cmake/external/onnx @@ -1 +1 @@ -Subproject commit bc7a70b46f4ae88383a4ca49c477fd859715620c +Subproject commit 174de7d086a768cba29374a56a7461eff87cfdb3 diff --git a/onnxruntime/core/providers/common.h b/onnxruntime/core/providers/common.h index 628c29654c..890182ae9a 100644 --- a/onnxruntime/core/providers/common.h +++ b/onnxruntime/core/providers/common.h @@ -88,6 +88,9 @@ inline Status ComputePad(const int64_t in_dim, return Status(common::ONNXRUNTIME, common::INVALID_ARGUMENT, "Dilation not supported for AutoPadType::SAME_UPPER or AutoPadType::SAME_LOWER."); + // The ONNX spec says if `auto_pad` attribute is set, pad until the `legacy_target_size` + // is `ceil (in_dim / stride)`. The following line of code is essentially just that and + // is retained as is int64_t legacy_target_size = (in_dim + stride - 1) / stride; int64_t pad_needed = (legacy_target_size - 1) * stride + kernel - in_dim; // make sure padding is symmetric diff --git a/onnxruntime/core/providers/cpu/nn/conv_transpose_attributes.h b/onnxruntime/core/providers/cpu/nn/conv_transpose_attributes.h index 5d6c0243d5..07a36ccccc 100644 --- a/onnxruntime/core/providers/cpu/nn/conv_transpose_attributes.h +++ b/onnxruntime/core/providers/cpu/nn/conv_transpose_attributes.h @@ -210,9 +210,10 @@ struct ConvTransposeAttributes : public ConvAttributes { // Compute padding if the auto_pad attribute is SAME_UPPER/SAME_LOWER if (pad_type == AutoPadType::SAME_UPPER || pad_type == AutoPadType::SAME_LOWER) { - // total pad + // The ONNX spec says if `auto_pad` attribute is set, pad until the `out_size` + // is `in_size * stride` auto total_pad = ComputeTotalPad(in_size, stride, adj, - kernel, dilation, in_size); + kernel, dilation, /*out_size = */ in_size * stride); DistributePadding(pad_type, total_pad, *pad_head, *pad_tail); } diff --git a/onnxruntime/test/providers/cpu/nn/conv_op_test.cc b/onnxruntime/test/providers/cpu/nn/conv_op_test.cc index f2b0259876..4dc9f831bf 100644 --- a/onnxruntime/test/providers/cpu/nn/conv_op_test.cc +++ b/onnxruntime/test/providers/cpu/nn/conv_op_test.cc @@ -678,5 +678,40 @@ TEST(ConvTest, Conv1D_asymmetric_padding) { TestConvOp(attrs, {X, W, B}, {X_shape, W_shape, B_shape}, expected_vals, Y_shape, true); } +TEST(ConvTest, Conv_AutoPad_with_non_default_strides) { + ConvOpAndTestAttributes attrs = { + "SAME_LOWER", // auto_pad + vector{1, 1}, // dilations + 1, // group + vector{3, 3}, // kernel_shape + vector{}, // pads + vector{2, 2}, // strides + {} // excluded EPs + }; + + vector X = {0.0f, 1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, + 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, + 15.0f, 16.0f, 17.0f, 18.0f, + 19.0f, 20.0f, 21.0, 22.0f, 23.0f, 24.0f}; + vector X_shape = {1, 1, 5, 5}; + + vector W = {1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f}; + vector W_shape = {1, 1, 3, 3}; + + auto expected_vals = {12.0f, 27.0f, 24.0f, + 63.0f, 108.0f, 81.0f, + 72.0f, 117.0f, 84.0f}; + vector Y_shape = {1, 1, 3, 3}; + + // Test with weight as initializer + TestConvOp(attrs, {X, W}, {X_shape, W_shape}, expected_vals, Y_shape); + + // Test with weight as initializer + TestConvOp(attrs, {X, W}, {X_shape, W_shape}, expected_vals, Y_shape, true); +} + } // namespace test } // namespace onnxruntime diff --git a/onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc b/onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc index 2e9a305523..42da30ab4c 100644 --- a/onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc +++ b/onnxruntime/test/providers/cpu/nn/conv_transpose_op_test.cc @@ -803,5 +803,50 @@ TEST(ConvTransposeTest, ConvTranspose_1D_AutoPad_SameLower) { OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); } +TEST(ConvTransposeTest, ConvTranspose_AutoPad_with_non_default_strides) { + ConvTransposeOpAttributes attrs = { + vector{3, 3}, // kernel_shape + {}, // output_padding + {}, // output_shape + {}, // pads + vector{2, 2}, // strides + vector{1, 1}, // dilations + 1, // group + "SAME_LOWER" // auto_pad + }; + + vector X = {0.0f, 1.0f, 2.0f, + 3.0f, 4.0f, 5.0f, + 6.0f, 7.0f, 8.0f}; + vector X_shape = {1, 1, 3, 3}; + + vector W = {1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f}; + vector W_shape = {1, 2, 3, 3}; + + auto expected_vals = {0.0f, 0.0f, 1.0f, 1.0f, 3.0f, 2.0f, + 0.0f, 0.0f, 1.0f, 1.0f, 3.0f, 2.0f, + 3.0f, 3.0f, 8.0f, 5.0f, 12.0f, 7.0f, + 3.0f, 3.0f, 7.0f, 4.0f, 9.0f, 5.0f, + 9.0f, 9.0f, 20.0f, 11.0f, 24.0f, 13.0f, + 6.0f, 6.0f, 13.0f, 7.0f, 15.0f, 8.0f, + + 0.0f, 0.0f, 1.0f, 1.0f, 3.0f, 2.0f, + 0.0f, 0.0f, 1.0f, 1.0f, 3.0f, 2.0f, + 3.0f, 3.0f, 8.0f, 5.0f, 12.0f, 7.0f, + 3.0f, 3.0f, 7.0f, 4.0f, 9.0f, 5.0f, + 9.0f, 9.0f, 20.0f, 11.0f, 24.0f, 13.0f, + 6.0f, 6.0f, 13.0f, 7.0f, 15.0f, 8.0f}; + vector Y_shape = {1, 2, 6, 6}; + + TestConvTransposeOp(attrs, {X, W}, {X_shape, W_shape}, expected_vals, Y_shape, + OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); +} + } // namespace test } // namespace onnxruntime diff --git a/tools/ci_build/github/linux/docker/scripts/manylinux/requirements.txt b/tools/ci_build/github/linux/docker/scripts/manylinux/requirements.txt index cd636f4daf..b144b18473 100644 --- a/tools/ci_build/github/linux/docker/scripts/manylinux/requirements.txt +++ b/tools/ci_build/github/linux/docker/scripts/manylinux/requirements.txt @@ -3,7 +3,7 @@ mypy pytest setuptools>=41.4.0 wheel -git+http://github.com/onnx/onnx.git@bc7a70b46f4ae88383a4ca49c477fd859715620c#egg=onnx +git+http://github.com/onnx/onnx.git@174de7d086a768cba29374a56a7461eff87cfdb3#egg=onnx protobuf sympy==1.1.1 flake8 diff --git a/tools/ci_build/github/linux/docker/scripts/requirements.txt b/tools/ci_build/github/linux/docker/scripts/requirements.txt index 5d53114abb..7fcb54d3a5 100644 --- a/tools/ci_build/github/linux/docker/scripts/requirements.txt +++ b/tools/ci_build/github/linux/docker/scripts/requirements.txt @@ -4,7 +4,7 @@ mypy pytest setuptools>=41.4.0 wheel -git+http://github.com/onnx/onnx.git@bc7a70b46f4ae88383a4ca49c477fd859715620c#egg=onnx +git+http://github.com/onnx/onnx.git@174de7d086a768cba29374a56a7461eff87cfdb3#egg=onnx argparse sympy==1.1.1 flake8