Skip to content

Commit

Permalink
Corrected the ReduceSumSqure op to match the reference (#6121)
Browse files Browse the repository at this point in the history
### 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>
  • Loading branch information
amankshihab committed May 3, 2024
1 parent 3bddb4d commit 94ba8fc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion onnx/reference/ops/op_reduce_sum_square.py
Expand Up @@ -21,7 +21,7 @@ def _run(self, data, axes=None, keepdims=None): # type: ignore
class ReduceSumSquare_18(OpRunReduceNumpy):
def _run(self, data, axes=None, keepdims=1, noop_with_empty_axes=0): # type: ignore
if self.is_axes_empty(axes) and noop_with_empty_axes != 0: # type: ignore
return (np.square(data),)
return (data,)

axes = self.handle_axes(axes)
keepdims = keepdims != 0 # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion onnx/test/reference_evaluator_test.py
Expand Up @@ -738,7 +738,7 @@ def test_reduce_sum_square_18_empty_axes_noop(self):
x = np.arange(60).reshape((3, 4, 5)).astype(np.float32)
sess = ReferenceEvaluator(onnx_model)
got = sess.run(None, {"X": x})[0]
assert_allclose(x * x, got)
assert_allclose(x, got)

def test_greater(self):
X = make_tensor_value_info("X", TensorProto.FLOAT, [None, None])
Expand Down

0 comments on commit 94ba8fc

Please sign in to comment.