Skip to content

Address MaxUnpool shortcomings msrc116345#28550

Merged
yuslepukhin merged 6 commits into
mainfrom
yuslepukhin/MaxUnpool_msrc_116345
May 21, 2026
Merged

Address MaxUnpool shortcomings msrc116345#28550
yuslepukhin merged 6 commits into
mainfrom
yuslepukhin/MaxUnpool_msrc_116345

Conversation

@yuslepukhin
Copy link
Copy Markdown
Member

@yuslepukhin yuslepukhin commented May 18, 2026

This pull request enhances the robustness of the MaxUnpool operator in ONNX Runtime by adding additional input validation and expanding test coverage for invalid input scenarios. The changes improve error handling for mismatched shapes, invalid dimensions, and other edge cases, ensuring the operator fails gracefully and predictably when given incorrect inputs.

Operator input validation improvements:

  • Added runtime checks in MaxUnpool::Compute to ensure the kernel_shape rank matches the expected pooling dimensions, and that the indices tensor is present and correctly shaped.
  • Added validation to ensure that computed output dimensions are positive, with descriptive error messages if not.
  • Enforced that the output_shape tensor, if provided, must have the same number of elements as the rank of the input tensor.

Test coverage enhancements:

  • Introduced multiple new tests in unpool_op_test.cc to cover invalid input cases, including mismatched indices shapes, rank-0 and rank-2 input tensors, negative indices, and incorrect output_shape element counts. These tests confirm that the operator fails with appropriate error messages in these scenarios.

References
onnx/onnx#7997
#28524

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the CPU MaxUnpool kernel with additional runtime validation (kernel-shape rank, indices presence, positive computed output dims, output_shape element count) and adds several negative tests in unpool_op_test.cc covering invalid indices shape, rank-0 / rank-2 inputs, negative indices, and a wrong-sized output_shape. It is part of a series (msrc116345) tightening operator input validation alongside #28524/#28548.

Changes:

  • Add input-shape/rank/output-shape validation in MaxUnpool::Compute.
  • Reject non-positive computed output dimensions with a descriptive error.
  • Add gtest cases exercising the new failure paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
onnxruntime/core/providers/cpu/nn/Unpool.cc New runtime checks for kernel_shape rank, indices presence, positive output dims, and output_shape element count vs X rank.
onnxruntime/test/providers/cpu/nn/unpool_op_test.cc New failure-path tests; includes a rank-0 test that depends on an unmerged upstream ONNX shape-inference fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread onnxruntime/test/providers/cpu/nn/unpool_op_test.cc Outdated
@yuslepukhin yuslepukhin requested a review from Copilot May 19, 2026 20:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread onnxruntime/test/providers/cpu/nn/unpool_op_test.cc Outdated
Comment thread onnxruntime/test/providers/cpu/nn/unpool_op_test.cc
Comment thread onnxruntime/core/providers/cpu/nn/Unpool.cc Outdated
Comment thread onnxruntime/core/providers/cpu/nn/Unpool.cc
justinchuby pushed a commit to onnx/onnx that referenced this pull request May 19, 2026
This pull request strengthens shape inference and error handling for the
`MaxUnpool` and `ConvTranspose` ONNX operators. It adds stricter input
validation to prevent silent failures or crashes when given invalid
input shapes, and introduces new tests to ensure these cases are
properly handled.

**Shape inference validation improvements:**

* Added a check in `maxUnpoolShapeInference` to ensure the indices input
exists and has at least 2 dimensions, raising a shape inference error
otherwise.
* In `convTransposeShapeInference`, added explicit checks to ensure both
the input tensor and the weight tensor have at least 2 dimensions,
raising clear errors if not.
* Updated logic in `convTransposeShapeInference` to consistently use the
local `weight_shape` variable for shape calculations and checks,
improving code clarity and correctness.
[[1]](diffhunk://#diff-b9e98b88715e8a7e56c0dfa317f21a39582f919c87185f827c4a011ad9010639L1124-R1141)
[[2]](diffhunk://#diff-b9e98b88715e8a7e56c0dfa317f21a39582f919c87185f827c4a011ad9010639L1194-R1206)

**Test coverage enhancements:**

* Added new unit tests to verify that shape inference raises appropriate
errors for invalid input shapes, such as rank-0 or rank-1
indices/weights in `MaxUnpool` and `ConvTranspose`.

**References**

microsoft/onnxruntime#28524
microsoft/onnxruntime#28550

---------

Signed-off-by: Dmitri Smirnov <dmitrism@microsoft.com>
justinchuby
justinchuby previously approved these changes May 19, 2026
@justinchuby justinchuby requested a review from Copilot May 19, 2026 23:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

Comment thread onnxruntime/core/providers/cpu/nn/Unpool.cc Outdated
Comment thread onnxruntime/core/providers/cpu/nn/Unpool.cc Outdated
Comment thread onnxruntime/test/providers/cpu/nn/unpool_op_test.cc
Comment thread onnxruntime/test/providers/cpu/nn/unpool_op_test.cc
Comment thread onnxruntime/test/providers/cpu/nn/unpool_op_test.cc
Comment thread onnxruntime/test/providers/cpu/nn/unpool_op_test.cc
Comment thread onnxruntime/test/providers/cpu/nn/unpool_op_test.cc
Comment thread onnxruntime/test/providers/cpu/nn/unpool_op_test.cc Outdated
@yuslepukhin yuslepukhin merged commit a894893 into main May 21, 2026
88 checks passed
@yuslepukhin yuslepukhin deleted the yuslepukhin/MaxUnpool_msrc_116345 branch May 21, 2026 16:48
tadani3 pushed a commit to tadani3/onnx that referenced this pull request May 26, 2026
This pull request strengthens shape inference and error handling for the
`MaxUnpool` and `ConvTranspose` ONNX operators. It adds stricter input
validation to prevent silent failures or crashes when given invalid
input shapes, and introduces new tests to ensure these cases are
properly handled.

**Shape inference validation improvements:**

* Added a check in `maxUnpoolShapeInference` to ensure the indices input
exists and has at least 2 dimensions, raising a shape inference error
otherwise.
* In `convTransposeShapeInference`, added explicit checks to ensure both
the input tensor and the weight tensor have at least 2 dimensions,
raising clear errors if not.
* Updated logic in `convTransposeShapeInference` to consistently use the
local `weight_shape` variable for shape calculations and checks,
improving code clarity and correctness.
[[1]](diffhunk://#diff-b9e98b88715e8a7e56c0dfa317f21a39582f919c87185f827c4a011ad9010639L1124-R1141)
[[2]](diffhunk://#diff-b9e98b88715e8a7e56c0dfa317f21a39582f919c87185f827c4a011ad9010639L1194-R1206)

**Test coverage enhancements:**

* Added new unit tests to verify that shape inference raises appropriate
errors for invalid input shapes, such as rank-0 or rank-1
indices/weights in `MaxUnpool` and `ConvTranspose`.

**References**

microsoft/onnxruntime#28524
microsoft/onnxruntime#28550

---------

Signed-off-by: Dmitri Smirnov <dmitrism@microsoft.com>
Signed-off-by: Tommaso Adani <tommasoadani@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants