Skip to content
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

Add ReduceMean shape infer to SymbolicShapeInference #22722

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yf711
Copy link
Contributor

@yf711 yf711 commented Nov 5, 2024

Description

Add symbolic shape inference support of ReduceMean op
ReduceMean def: https://onnx.ai/onnx/operators/onnx__ReduceMean.html

Motivation and Context

#22662
This op is not supported by current script

Comment on lines 168 to +169
"ReduceSum": self._infer_ReduceSum,
"ReduceMean": self._infer_ReduceMean,
Copy link
Contributor

@tianleiwu tianleiwu Nov 5, 2024

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."
Copy link
Contributor

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

keep_dims = get_attribute(node, "keepdims", 1)
opset = get_opset(self.out_mp_)

if opset >= 13 and len(node.input) > 1:
Copy link
Contributor

@tianleiwu tianleiwu Nov 5, 2024

Choose a reason for hiding this comment

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

ReduceMean-13 still uses attribute for axes. Maybe just check whether there is two inputs, and not check opset version so that it is more general for other Reduce* op. For example, starting with ReduceSum-13, ReduceMean-18, ReduceMax-18, axes is in input.

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.

2 participants