From d3e93c12b244a48ff6860070b1e6aa1fb92d4f49 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Apr 2026 15:00:33 +0000 Subject: [PATCH 1/8] Initial plan From 273524295e6f8c40eac53064f7f9bf1851ed9e56 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Apr 2026 15:48:50 +0000 Subject: [PATCH 2/8] Add shape consistency validation in MaxpoolWithMask::Compute Agent-Logs-Url: https://github.com/microsoft/onnxruntime/sessions/3ff41f92-9af2-46fc-9d9f-029cd4f52233 Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com> --- .../contrib_ops/cpu/maxpool_with_mask.h | 12 +++-- .../test/contrib_ops/maxpool_mask_test.cc | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h index 7210a9a7c6859..04df44a0e8957 100644 --- a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h +++ b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h @@ -200,10 +200,14 @@ class MaxpoolWithMask : public OpKernel, public PoolBase { const TensorShape& x_shape = X->Shape(); const TensorShape& m_shape = M->Shape(); ORT_RETURN_IF_NOT(x_shape.NumDimensions() >= 3, "Input dimension cannot be less than 3."); - - // TODO: fix this checker later - // ONNXRUNTIME_RETURN_IF_NOT((x_shape[2] == m_shape[2]) && (x_shape[3] == m_shape[3]), " Input shape and mask shape - // mismatch: ", x_shape, " vs ", m_shape); + ORT_RETURN_IF_NOT(m_shape.NumDimensions() == x_shape.NumDimensions(), + "Mask and input must have the same number of dimensions. Got mask dims: ", + m_shape.NumDimensions(), " input dims: ", x_shape.NumDimensions()); + for (size_t i = 2; i < x_shape.NumDimensions(); ++i) { + ORT_RETURN_IF_NOT(m_shape[i] == x_shape[i], + "Mask and input spatial dimensions mismatch at dimension ", i, + ": mask=", m_shape[i], " input=", x_shape[i]); + } TensorShapeVector pads = pool_attrs_.pads; TensorShapeVector kernel_shape = pool_attrs_.kernel_shape; diff --git a/onnxruntime/test/contrib_ops/maxpool_mask_test.cc b/onnxruntime/test/contrib_ops/maxpool_mask_test.cc index 7ff1c9919fcad..7b6c04e9a296c 100644 --- a/onnxruntime/test/contrib_ops/maxpool_mask_test.cc +++ b/onnxruntime/test/contrib_ops/maxpool_mask_test.cc @@ -80,5 +80,57 @@ TEST(ContribOpTest, MaxPoolWithMask) { test.Run(); } +TEST(ContribOpTest, MaxPoolWithMask_SpatialDimMismatch) { + OpTester test("MaxpoolWithMask", 1, onnxruntime::kMSDomain); + + test.AddAttribute("auto_pad", ""); + test.AddAttribute("strides", std::vector{1, 1}); + test.AddAttribute("pads", std::vector{0, 0, 0, 0}); + test.AddAttribute("kernel_shape", std::vector{8, 8}); + + // Input X has shape {1, 1, 8, 8} + std::vector x_dims = {1, 1, 8, 8}; + std::vector x_vals(64, 1.0f); + + // Mask M has wrong spatial dimensions: {1, 1, 4, 8} instead of {1, 1, 8, 8} + std::vector m_dims = {1, 1, 4, 8}; + std::vector m_vals(32, 1); + + std::vector expected_dims = {1, 1, 1, 1}; + std::vector expected_vals = {1.0f}; + + test.AddInput("X", x_dims, x_vals); + test.AddInput("M", m_dims, m_vals); + test.AddOutput("Y", expected_dims, expected_vals); + test.Run(BaseTester::ExpectResult::kExpectFailure, + "Mask and input spatial dimensions mismatch at dimension 2"); +} + +TEST(ContribOpTest, MaxPoolWithMask_DimCountMismatch) { + OpTester test("MaxpoolWithMask", 1, onnxruntime::kMSDomain); + + test.AddAttribute("auto_pad", ""); + test.AddAttribute("strides", std::vector{1, 1}); + test.AddAttribute("pads", std::vector{0, 0, 0, 0}); + test.AddAttribute("kernel_shape", std::vector{8, 8}); + + // Input X has shape {1, 1, 8, 8} (4D) + std::vector x_dims = {1, 1, 8, 8}; + std::vector x_vals(64, 1.0f); + + // Mask M has wrong number of dimensions: {1, 1, 8} (3D) instead of 4D + std::vector m_dims = {1, 1, 8}; + std::vector m_vals(8, 1); + + std::vector expected_dims = {1, 1, 1, 1}; + std::vector expected_vals = {1.0f}; + + test.AddInput("X", x_dims, x_vals); + test.AddInput("M", m_dims, m_vals); + test.AddOutput("Y", expected_dims, expected_vals); + test.Run(BaseTester::ExpectResult::kExpectFailure, + "Mask and input must have the same number of dimensions"); +} + } // namespace test } // namespace onnxruntime From b050564f2e413b5c62c15db94a1d8cbee034a651 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 24 Apr 2026 15:50:25 +0000 Subject: [PATCH 3/8] Clarify placeholder output comments in failure test cases Agent-Logs-Url: https://github.com/microsoft/onnxruntime/sessions/3ff41f92-9af2-46fc-9d9f-029cd4f52233 Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com> --- onnxruntime/test/contrib_ops/maxpool_mask_test.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/onnxruntime/test/contrib_ops/maxpool_mask_test.cc b/onnxruntime/test/contrib_ops/maxpool_mask_test.cc index 7b6c04e9a296c..60f1a7f5a248d 100644 --- a/onnxruntime/test/contrib_ops/maxpool_mask_test.cc +++ b/onnxruntime/test/contrib_ops/maxpool_mask_test.cc @@ -96,6 +96,7 @@ TEST(ContribOpTest, MaxPoolWithMask_SpatialDimMismatch) { std::vector m_dims = {1, 1, 4, 8}; std::vector m_vals(32, 1); + // Placeholder output shape and values (not validated since we expect failure) std::vector expected_dims = {1, 1, 1, 1}; std::vector expected_vals = {1.0f}; @@ -122,6 +123,7 @@ TEST(ContribOpTest, MaxPoolWithMask_DimCountMismatch) { std::vector m_dims = {1, 1, 8}; std::vector m_vals(8, 1); + // Placeholder output shape and values (not validated since we expect failure) std::vector expected_dims = {1, 1, 1, 1}; std::vector expected_vals = {1.0f}; From 8e3bc56d4ce33971a9c322e6f5193d79034ccec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Tue, 5 May 2026 17:51:06 +0200 Subject: [PATCH 4/8] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- onnxruntime/contrib_ops/cpu/maxpool_with_mask.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h index 04df44a0e8957..b1494800a096d 100644 --- a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h +++ b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h @@ -203,6 +203,11 @@ class MaxpoolWithMask : public OpKernel, public PoolBase { ORT_RETURN_IF_NOT(m_shape.NumDimensions() == x_shape.NumDimensions(), "Mask and input must have the same number of dimensions. Got mask dims: ", m_shape.NumDimensions(), " input dims: ", x_shape.NumDimensions()); + const bool input_has_nonzero_channels = x_shape[0] > 0 && x_shape[1] > 0; + ORT_RETURN_IF_NOT(!input_has_nonzero_channels || (m_shape[0] > 0 && m_shape[1] > 0), + "Mask N and C dimensions must be greater than 0 when input N and C are greater than 0. " + "Got mask N=", m_shape[0], " C=", m_shape[1], + " input N=", x_shape[0], " C=", x_shape[1]); for (size_t i = 2; i < x_shape.NumDimensions(); ++i) { ORT_RETURN_IF_NOT(m_shape[i] == x_shape[i], "Mask and input spatial dimensions mismatch at dimension ", i, From 4bc602245837a0240651c1c943185b03752646a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Tue, 5 May 2026 17:55:55 +0200 Subject: [PATCH 5/8] Update onnxruntime/contrib_ops/cpu/maxpool_with_mask.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- onnxruntime/contrib_ops/cpu/maxpool_with_mask.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h index b1494800a096d..5e74538208f43 100644 --- a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h +++ b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h @@ -206,7 +206,8 @@ class MaxpoolWithMask : public OpKernel, public PoolBase { const bool input_has_nonzero_channels = x_shape[0] > 0 && x_shape[1] > 0; ORT_RETURN_IF_NOT(!input_has_nonzero_channels || (m_shape[0] > 0 && m_shape[1] > 0), "Mask N and C dimensions must be greater than 0 when input N and C are greater than 0. " - "Got mask N=", m_shape[0], " C=", m_shape[1], + "Got mask N=", + m_shape[0], " C=", m_shape[1], " input N=", x_shape[0], " C=", x_shape[1]); for (size_t i = 2; i < x_shape.NumDimensions(); ++i) { ORT_RETURN_IF_NOT(m_shape[i] == x_shape[i], From 94b343115d7876efce171a0f15bf48016572b3e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Wed, 13 May 2026 10:27:14 +0200 Subject: [PATCH 6/8] add comment --- onnxruntime/contrib_ops/cpu/maxpool_with_mask.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h index 5e74538208f43..cd613067e75ac 100644 --- a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h +++ b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h @@ -204,6 +204,8 @@ class MaxpoolWithMask : public OpKernel, public PoolBase { "Mask and input must have the same number of dimensions. Got mask dims: ", m_shape.NumDimensions(), " input dims: ", x_shape.NumDimensions()); const bool input_has_nonzero_channels = x_shape[0] > 0 && x_shape[1] > 0; + // Mask N and C dimensions may differ from input (broadcasting via modulo). + // Only require them to be nonzero to prevent division-by-zero in total_mask_channels. ORT_RETURN_IF_NOT(!input_has_nonzero_channels || (m_shape[0] > 0 && m_shape[1] > 0), "Mask N and C dimensions must be greater than 0 when input N and C are greater than 0. " "Got mask N=", From 03ea614a25f09e0773315307a91895e432ce9cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Wed, 13 May 2026 10:52:29 +0200 Subject: [PATCH 7/8] Update onnxruntime/contrib_ops/cpu/maxpool_with_mask.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- onnxruntime/contrib_ops/cpu/maxpool_with_mask.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h index cd613067e75ac..7dfb2770a6979 100644 --- a/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h +++ b/onnxruntime/contrib_ops/cpu/maxpool_with_mask.h @@ -205,7 +205,7 @@ class MaxpoolWithMask : public OpKernel, public PoolBase { m_shape.NumDimensions(), " input dims: ", x_shape.NumDimensions()); const bool input_has_nonzero_channels = x_shape[0] > 0 && x_shape[1] > 0; // Mask N and C dimensions may differ from input (broadcasting via modulo). - // Only require them to be nonzero to prevent division-by-zero in total_mask_channels. + // Only require them to be nonzero to prevent division-by-zero in total_mask_channels. ORT_RETURN_IF_NOT(!input_has_nonzero_channels || (m_shape[0] > 0 && m_shape[1] > 0), "Mask N and C dimensions must be greater than 0 when input N and C are greater than 0. " "Got mask N=", From 1f73169802d58bdb2a3ad21d6f75a326067f5bfb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 09:06:08 +0000 Subject: [PATCH 8/8] Add test for mask N/C nonzero validation path in MaxpoolWithMask Agent-Logs-Url: https://github.com/microsoft/onnxruntime/sessions/9e152742-abd5-4f85-a3dc-dc7073befa07 Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com> --- .../test/contrib_ops/maxpool_mask_test.cc | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/onnxruntime/test/contrib_ops/maxpool_mask_test.cc b/onnxruntime/test/contrib_ops/maxpool_mask_test.cc index 60f1a7f5a248d..ed65700ccd336 100644 --- a/onnxruntime/test/contrib_ops/maxpool_mask_test.cc +++ b/onnxruntime/test/contrib_ops/maxpool_mask_test.cc @@ -134,5 +134,32 @@ TEST(ContribOpTest, MaxPoolWithMask_DimCountMismatch) { "Mask and input must have the same number of dimensions"); } +TEST(ContribOpTest, MaxPoolWithMask_MaskEmptyBatchDim) { + OpTester test("MaxpoolWithMask", 1, onnxruntime::kMSDomain); + + test.AddAttribute("auto_pad", ""); + test.AddAttribute("strides", std::vector{1, 1}); + test.AddAttribute("pads", std::vector{0, 0, 0, 0}); + test.AddAttribute("kernel_shape", std::vector{8, 8}); + + // Input X has shape {1, 1, 8, 8} (non-empty) + std::vector x_dims = {1, 1, 8, 8}; + std::vector x_vals(64, 1.0f); + + // Mask M has N=0: should trigger the nonzero N/C guard + std::vector m_dims = {0, 1, 8, 8}; + std::vector m_vals; // 0 elements + + // Placeholder output shape and values (not validated since we expect failure) + std::vector expected_dims = {1, 1, 1, 1}; + std::vector expected_vals = {1.0f}; + + test.AddInput("X", x_dims, x_vals); + test.AddInput("M", m_dims, m_vals); + test.AddOutput("Y", expected_dims, expected_vals); + test.Run(BaseTester::ExpectResult::kExpectFailure, + "Mask N and C dimensions must be greater than 0"); +} + } // namespace test } // namespace onnxruntime