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

Reference implementation of ONNX Reduce sum square is mismatch with ONNX Spec when noop_with_empty_axes == 1 #6103

Open
RunnerZhong opened this issue Apr 29, 2024 · 5 comments
Labels
bug contributions welcome documentation Issues related to ONNX documentation spec clarification Clarification of the ONNX spec needed

Comments

@RunnerZhong
Copy link

Bug Report

Is the issue related to model conversion?

No

Describe the bug

When noop_with_empty_axes == 1 & axes is empty, in ONNX spec, it will return input tensor directly.
But in reference in onnx, it is mismatch. it returned np.square of the input tensor

image

System information

Reproduction instructions

Expected behavior

return input tensor directly

Notes

@amankshihab
Copy link
Contributor

amankshihab commented May 1, 2024

https://github.com/onnx/onnx/blob/d6f87121ba256ac6cc4d1da0463c300c278339d2/docs/Changelog.md?plain=1#L22221-L22222

The expected behavior is mentioned here as well.
Can I work on this? @justinchuby

@justinchuby
Copy link
Contributor

Absolutely. Contributions are welcome and appreciated

@gramalingam
Copy link
Contributor

This is complicated. Agree that there is a mismatch, but is the bug in the specification or implementation?

My personal interpretation is that this is a bug in the specification, not implementation, for the following reason: the attributes serve to define the set of axes being reduced: specifically, it is a flag to allow the empty list to indicate that all axes must be reduced (or that no axes must be reduced). Now, even if zero axes are reduced, it makes sense to compute the square. ReduceSumSquare is not actually a reduction-op: it is a reduction-op Sum applied to the square of the input.

I think the bug was in reusing the ReduceSum documentation for all ops ... it is correct for basic Reduction ops, but not ReduceSumSquare.

Of course, we can test with other backends/implementations (like onnxruntime, or even pytorch/tensorflow etc. IF they have such an option).

github-merge-queue bot pushed a commit that referenced this issue May 3, 2024
### Description
This PR aligns the op implementation for `ReduceSumSquare18` when `axes`
are not specified and `noop_with_empty_axes != 0` with that of the
reference.

### Motivation and Context
Current implementation of `ReduceSumSquare18` when axes are empty and
`noop_with_empty_axes != 1` squares the input data and then returns it,
when according to the reference it should just return the input data
with no changes.

This addresses issue #6103

Signed-off-by: Aman K Shihab <amanshihab276@gmail.com>
isdanni pushed a commit to isdanni/onnx that referenced this issue May 6, 2024
### Description
This PR aligns the op implementation for `ReduceSumSquare18` when `axes`
are not specified and `noop_with_empty_axes != 0` with that of the
reference.

### Motivation and Context
Current implementation of `ReduceSumSquare18` when axes are empty and
`noop_with_empty_axes != 1` squares the input data and then returns it,
when according to the reference it should just return the input data
with no changes.

This addresses issue onnx#6103

Signed-off-by: Aman K Shihab <amanshihab276@gmail.com>
Signed-off-by: isdanni <leedanni@gmail.com>
isdanni pushed a commit to isdanni/onnx that referenced this issue May 6, 2024
@justinchuby justinchuby added documentation Issues related to ONNX documentation spec clarification Clarification of the ONNX spec needed and removed reference implementation labels May 8, 2024
@justinchuby
Copy link
Contributor

Following the discussion, I think it's reasonable to correct the spec. Out of curiosity, was there any reason you would expect the behavior to be different than the current one @RunnerZhong ?

@RunnerZhong
Copy link
Author

I agree with below idea. So maybe we need to modify the spec of ops like ReduceSumSquare(ReduceLogSum, ReduceLogSumExp).

This is complicated. Agree that there is a mismatch, but is the bug in the specification or implementation?

My personal interpretation is that this is a bug in the specification, not implementation, for the following reason: the attributes serve to define the set of axes being reduced: specifically, it is a flag to allow the empty list to indicate that all axes must be reduced (or that no axes must be reduced). Now, even if zero axes are reduced, it makes sense to compute the square. ReduceSumSquare is not actually a reduction-op: it is a reduction-op Sum applied to the square of the input.

I think the bug was in reusing the ReduceSum documentation for all ops ... it is correct for basic Reduction ops, but not ReduceSumSquare.

Of course, we can test with other backends/implementations (like onnxruntime, or even pytorch/tensorflow etc. IF they have such an option).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug contributions welcome documentation Issues related to ONNX documentation spec clarification Clarification of the ONNX spec needed
Projects
None yet
Development

No branches or pull requests

4 participants