Address MaxUnpool shortcomings msrc116345#28550
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
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
previously approved these changes
May 19, 2026
justinchuby
approved these changes
May 21, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request enhances the robustness of the
MaxUnpooloperator 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:
MaxUnpool::Computeto ensure thekernel_shaperank matches the expected pooling dimensions, and that the indices tensor is present and correctly shaped.output_shapetensor, if provided, must have the same number of elements as the rank of the input tensor.Test coverage enhancements:
unpool_op_test.ccto cover invalid input cases, including mismatched indices shapes, rank-0 and rank-2 input tensors, negative indices, and incorrectoutput_shapeelement counts. These tests confirm that the operator fails with appropriate error messages in these scenarios.References
onnx/onnx#7997
#28524