From f0d7b8258ab1dd09b5ab4dcc6506754755394467 Mon Sep 17 00:00:00 2001 From: Harsh Chauhan Date: Sat, 28 Mar 2026 21:38:55 +0530 Subject: [PATCH 1/3] fix Conv dynamic shape output formula when stride > 1 --- tmva/sofie/inc/TMVA/ROperator_Conv.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmva/sofie/inc/TMVA/ROperator_Conv.hxx b/tmva/sofie/inc/TMVA/ROperator_Conv.hxx index b4a2bb547c3bd..072922818d505 100644 --- a/tmva/sofie/inc/TMVA/ROperator_Conv.hxx +++ b/tmva/sofie/inc/TMVA/ROperator_Conv.hxx @@ -199,7 +199,7 @@ public: } else { // general case (stride not 1) int64_t v = pad - kernel; std::string outStr = "((" + inputDim.param + "+" + std::to_string(v) + ")/" - + std::to_string(stride) + "1)"; + + std::to_string(stride) + "+1)"; return Dim{ outStr, static_cast(-1)}; } } From 233368b29c24a3b58c532426f955580011d7c4f5 Mon Sep 17 00:00:00 2001 From: Harsh Chauhan Date: Sat, 28 Mar 2026 22:00:39 +0530 Subject: [PATCH 2/3] format fix --- tmva/sofie/inc/TMVA/ROperator_Conv.hxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmva/sofie/inc/TMVA/ROperator_Conv.hxx b/tmva/sofie/inc/TMVA/ROperator_Conv.hxx index 072922818d505..fcd41e427015b 100644 --- a/tmva/sofie/inc/TMVA/ROperator_Conv.hxx +++ b/tmva/sofie/inc/TMVA/ROperator_Conv.hxx @@ -198,8 +198,8 @@ public: } } else { // general case (stride not 1) int64_t v = pad - kernel; - std::string outStr = "((" + inputDim.param + "+" + std::to_string(v) + ")/" - + std::to_string(stride) + "+1)"; + std::string outStr = + "((" + inputDim.param + "+" + std::to_string(v) + ")/" + std::to_string(stride) + "+1)"; return Dim{ outStr, static_cast(-1)}; } } From c5147cd188831062aa95404d06dbed24a3a7fe46 Mon Sep 17 00:00:00 2001 From: Harsh Chauhan Date: Sun, 29 Mar 2026 17:48:29 +0530 Subject: [PATCH 3/3] test: add Conv1d dynamic spatial dim with stride > 1 regression test --- tmva/sofie/test/TestCustomModelsFromONNX.cxx | 23 ++++++++++++++++++ .../input_models/ConvWithDynShapeStride.onnx | Bin 0 -> 187 bytes 2 files changed, 23 insertions(+) create mode 100644 tmva/sofie/test/input_models/ConvWithDynShapeStride.onnx diff --git a/tmva/sofie/test/TestCustomModelsFromONNX.cxx b/tmva/sofie/test/TestCustomModelsFromONNX.cxx index 94993f601a3c4..3c79390afc4d7 100644 --- a/tmva/sofie/test/TestCustomModelsFromONNX.cxx +++ b/tmva/sofie/test/TestCustomModelsFromONNX.cxx @@ -706,6 +706,29 @@ TEST(ONNX, ConvWithStridesNoPadding) } +TEST(ONNX, ConvWithDynShapeStride) +{ + // Conv1d with dynamic spatial dimension W and stride=2. + // Verifies fix for output dimension formula: ((W+pad-kernel)/stride+1) + // was incorrectly generated as ((W+pad-kernel)/stride1) before the fix. + // + // Model: kernel=3, stride=2, pad=0, weight=all-ones, input shape (1,1,W) + // With W=7: output shape (1,1,3), output = [0+1+2, 2+3+4, 4+5+6] = [3, 9, 15] + + std::vector input = {0, 1, 2, 3, 4, 5, 6}; // shape (1,1,7) + std::vector correct_output = {3, 9, 15}; + + // model is dynamic in spatial dim W, use W = 7 + ASSERT_INCLUDE_AND_RUN_SESSION_ARGS(std::vector, "ConvWithDynShapeStride", + "\"ConvWithDynShapeStride_FromONNX.dat\", 7", 7, input); + + EXPECT_EQ(output.size(), correct_output.size()); + for (size_t i = 0; i < output.size(); ++i) { + EXPECT_LE(std::abs(output[i] - correct_output[i]), DEFAULT_TOLERANCE); + } +} + + // Disables test (asymmetric padding not supported) TEST(DISABLED_ONNX, ConvWithAsymmetricPadding) { diff --git a/tmva/sofie/test/input_models/ConvWithDynShapeStride.onnx b/tmva/sofie/test/input_models/ConvWithDynShapeStride.onnx new file mode 100644 index 0000000000000000000000000000000000000000..69864d933ef01ba193a2b4758bfdc2486664cdc2 GIT binary patch literal 187 zcmd;+&sXrX|e9lbu?Wmzon_oRL_N>cG5!kzI?Ii=`kj zrPzVNfdRzj<6R$dGF&S2fY=|T< literal 0 HcmV?d00001