From 94ba8fc801ee0215136f875942360d4b4cdc800a Mon Sep 17 00:00:00 2001 From: "Aman K. Shihab" <70906662+amankshihab@users.noreply.github.com> Date: Fri, 3 May 2024 14:15:50 +0530 Subject: [PATCH] Corrected the ReduceSumSqure op to match the reference (#6121) ### 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 --- onnx/reference/ops/op_reduce_sum_square.py | 2 +- onnx/test/reference_evaluator_test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/onnx/reference/ops/op_reduce_sum_square.py b/onnx/reference/ops/op_reduce_sum_square.py index 8392026136a..0b350060ca7 100644 --- a/onnx/reference/ops/op_reduce_sum_square.py +++ b/onnx/reference/ops/op_reduce_sum_square.py @@ -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 diff --git a/onnx/test/reference_evaluator_test.py b/onnx/test/reference_evaluator_test.py index b35799adc30..aea5b42e70f 100644 --- a/onnx/test/reference_evaluator_test.py +++ b/onnx/test/reference_evaluator_test.py @@ -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])