-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SymbolicShapeInference] Support 10 Reduce* ops #22722
base: main
Are you sure you want to change the base?
Conversation
"ReduceSum": self._infer_ReduceSum, | ||
"ReduceMean": self._infer_ReduceMean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReduceSum
and ReduceMean
could use same shape infer function.
Also applies to ReduceMin
, ReduceMax
, ReduceProd
etc.
vi = self.known_vi_[node.output[0]] | ||
|
||
if axes is None: | ||
assert keep_dims == 1, "ReduceMean Op: Cannot infer shape when axes is unknown and keepdims is not 1." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opset 18 add an attribute noop_with_empty_axes
, shall we handle it here.
https://onnx.ai/onnx/operators/onnx__ReduceMean.html#reducemean-18
@@ -1567,46 +1575,58 @@ | |||
) | |||
) | |||
|
|||
def _infer_ReduceSum(self, node): # noqa: N802 | |||
# This func takes care of Reduce*** ops, |
Check warning
Code scanning / lintrunner
RUFF/W291 Warning
See https://docs.astral.sh/ruff/rules/trailing-whitespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can commit the suggested changes from lintrunner.
|
||
def _infer_ReduceSum(self, node): # noqa: N802 | ||
# This func takes care of Reduce*** ops, | ||
# including ReduceSum, ReduceMean, ReduceMin, ReduceMax, ReduceProd, etc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def _infer_ReduceSum(self, node): # noqa: N802 | |
# This func takes care of Reduce*** ops, | |
# including ReduceSum, ReduceMean, ReduceMin, ReduceMax, ReduceProd, etc | |
# This func takes care of Reduce*** ops, | |
# including ReduceSum, ReduceMean, ReduceMin, ReduceMax, ReduceProd, etc |
assert input_shape, f"{node.op_type} Op: Reduction over an empty set of values yields undefined" | ||
|
||
axes = [handle_negative_axis(a, len(input_shape)) for a in axes] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert input_shape, f"{node.op_type} Op: Reduction over an empty set of values yields undefined" | |
axes = [handle_negative_axis(a, len(input_shape)) for a in axes] | |
assert input_shape, f"{node.op_type} Op: Reduction over an empty set of values yields undefined" | |
axes = [handle_negative_axis(a, len(input_shape)) for a in axes] |
keep_dims = get_attribute(node, "keepdims", 1) | ||
if get_opset(self.out_mp_) >= 13 and len(node.input) > 1: | ||
# ReduceSum changes axes to input[1] in opset 13 | ||
opset = get_opset(self.out_mp_) |
Check warning
Code scanning / lintrunner
RUFF/F841 Warning
See https://docs.astral.sh/ruff/rules/unused-variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can commit the suggested changes from lintrunner.
|
||
if axes is None or (isinstance(axes, list) and len(axes) == 0): | ||
# No reduction, output shape is the same as input shape |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if axes is None or (isinstance(axes, list) and len(axes) == 0): | |
# No reduction, output shape is the same as input shape | |
if axes is None or (isinstance(axes, list) and len(axes) == 0): | |
# No reduction, output shape is the same as input shape |
|
||
vi = self.known_vi_[node.output[0]] | ||
|
||
if axes is None or (isinstance(axes, list) and len(axes) == 0): |
Check warning
Code scanning / lintrunner
RUFF/W291 Warning
See https://docs.astral.sh/ruff/rules/trailing-whitespace
LGTM. Please use "lintrunner -a" to format the script. |
Description
Extend existing Reduce_Sum func to all 10 Reduce-series ops
i.e ReduceMean def: https://onnx.ai/onnx/operators/onnx__ReduceMean.html
Motivation and Context
#22662
This ReduceMean op is not supported by current script