Repository navigation
Fix reduction operator shape inference at opset 18 and later - #32376
Kayvan Zahiri (Kayvan-Zahiri) wants to merge 2 commits into
Conversation
Since opset 18 the reduction operators take axes as an input rather than an attribute. _onnx_infer_single_node forwards initializers only for Unsqueeze, so the seven operators without a dedicated handler reach onnx shape inference with no axes value and come back with no output shape at all. _infer_ReduceSum also treats an empty axes tensor as "reduce nothing". The spec reduces every axis unless noop_with_empty_axes is set. ReduceMean routes to the same handler at opset 18, so both were affected.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟡 Changes recommended
Opset-18 ReduceProd remains unhandled and can still lose its output shape.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes symbolic shape inference for reduction operators using axes inputs.
Changes:
- Forwards reduction axes initializers to ONNX shape inference.
- Handles empty axes according to
noop_with_empty_axes. - Adds opset-18 regression tests.
File summaries
| File | Description |
|---|---|
onnxruntime/python/tools/symbolic_shape_infer.py |
Updates reduction shape inference behavior. |
onnxruntime/test/python/onnxruntime_test_python_symbolic_shape_infer.py |
Adds axes-input and empty-axes tests. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| "ReduceLogSumExp", | ||
| "ReduceMax", | ||
| "ReduceMin", | ||
| "ReduceSumSquare", |
ReduceProd has a dispatched handler, but that handler only computes sympy data for the legacy axes attribute and never sets the output shape. Since _onnx_infer_single_node runs before the dispatcher, ReduceProd needs the axes initializer forwarded like the operators without a handler.
|
Correct, and I verified it before changing anything. Fixed in the latest commit. The reason it applies even though Confirmed on the branch before the change:
The suite goes from 11 failed / 31 passed to 2 failed / 31 passed with 10 subtests passing. |
Two shape inference defects for reduction operators at opset 18 and later, where axes
became an input rather than an attribute.
Seven operators lose their output shape entirely.
_onnx_infer_single_nodeforwardsinitializers into its temp graph only for
Unsqueeze, soReduceL1,ReduceL2,ReduceLogSum,ReduceLogSumExp,ReduceMax,ReduceMinandReduceSumSquarereachonnx.shape_inferencewith no axes value and come back with nothing.ReduceSum,ReduceMeanandReduceProdescape because they have dedicated handlers.ReduceSumignoresnoop_with_empty_axes. An empty axes tensor is notNone, sothe per-axis loop matches nothing and the input shape is copied through. The spec reduces
every axis unless
noop_with_empty_axes=1.ReduceMeanroutes to the same handler atopset 18.
noop_with_empty_axes=1still passes the shape through unchanged, and an explicitnon-empty axes list is unaffected. Both covered in the added tests.
onnxruntime_test_python_symbolic_shape_infer.pygoes from 10 failed / 31 passed to2 failed / 31 passed with 9 subtests passing. The two remaining failures are the
pre-existing
TestSymbolicShapeInferenceForSlicestep tests, unrelated and failing on main.