Validate empty reduction axes - #32156
Open
Akshay Sonawane (apsonawane) wants to merge 2 commits into
Open
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 18, 2026 17:08
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 18, 2026 17:10
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Improves CPU reduction handling for empty tensors and optional axes.
Changes:
- Validates axes tensors as one-dimensional.
- Handles omitted or empty axes before empty-set reduction.
- Adds edge-case tests and avoids zero-byte copies.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
onnxruntime/core/providers/cpu/reduction/reduction_ops.cc |
Updates empty-set validation and reduction flow. |
onnxruntime/test/providers/cpu/reduction/reduction_ops_test.cc |
Adds empty-axes and optional-axes tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+891
to
+892
| const auto axes_data = axes_tensor->DataAsSpan<int64_t>(); | ||
| input_axes.assign(axes_data.begin(), axes_data.end()); |
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 improves the handling and validation of empty set reductions in the ONNX Runtime CPU reduction operators. It enforces stricter checks for the axes input, prevents unnecessary memory operations, and adds comprehensive tests to verify correct behavior for various edge cases.
Validation and Error Handling Improvements:
axestensor input must be a 1D vector and only processes it if it is present, improving robustness and error messages for invalid input shapes.Logic and Flow Adjustments:
Testing Enhancements:
axesinput is missing (should reduce all dimensions).axestensor must be a vector, with expected error messages for invalid cases.noop_with_empty_axesattribute, both when axes are omitted and when an empty axes tensor is provided.