Skip to content

Commit

Permalink
[ONNX] Aligned ReduceL1 behavior #20559 (#25909)
Browse files Browse the repository at this point in the history
### Details:
-I've aligned the ReduceL1 operation with opset 11, 13, and 18. created
test models, and added them inside onnx_import.in.cpp.

### Tickets:
 - **#20559

---------

Co-authored-by: Georgy Krivoruchko <[email protected]>
  • Loading branch information
RitikaxShakya and gkrivor authored Aug 9, 2024
1 parent 9c0ae75 commit cb9ee02
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/frontends/onnx/frontend/src/op/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ ov::OutputVector reduce_log_sum_exp(const ov::frontend::onnx::Node& node) {
}

ov::OutputVector reduce_l1(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v4::ReduceL1>(node, node.get_ov_inputs().at(0), supported_types_v1)};
return {make_ov_reduction_op<v4::ReduceL1>(node, node.get_ov_inputs().at(0), supported_types_v2)};
}

ov::OutputVector reduce_l2(const ov::frontend::onnx::Node& node) {
Expand Down Expand Up @@ -309,6 +309,10 @@ ov::OutputVector reduce_sum_square(const ov::frontend::onnx::Node& node) {
return {onnx_reduce_sum_square(node, supported_types_v2, false)};
}

ov::OutputVector reduce_l1(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v4::ReduceL1>(node, node.get_ov_inputs().at(0), supported_types_v2, false)};
}

static bool register_multiple_translators(void) {
ONNX_OP_M("ReduceLogSum", OPSET_SINCE(18), ai_onnx::opset_18::reduce_log_sum);
ONNX_OP_M("ReduceL2", OPSET_SINCE(18), ai_onnx::opset_18::reduce_l2);
Expand All @@ -318,6 +322,7 @@ static bool register_multiple_translators(void) {
ONNX_OP_M("ReduceMin", {18, 19}, ai_onnx::opset_18::reduce_min);
ONNX_OP_M("ReduceProd", OPSET_SINCE(18), ai_onnx::opset_18::reduce_prod);
ONNX_OP_M("ReduceSumSquare", OPSET_SINCE(18), ai_onnx::opset_18::reduce_sum_square);
ONNX_OP_M("ReduceL1", OPSET_SINCE(18), ai_onnx::opset_18::reduce_l1);
return true;
}

Expand Down
48 changes: 48 additions & 0 deletions src/frontends/onnx/tests/models/reduce_l1_18.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "A"
output: "B"
op_type: "ReduceL1"
}
name: "compute_graph"
input {
name: "A"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
output {
name: "B"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
}
}
}
}
}
opset_import {
version: 18
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ir_version: 3
producer_name: "OpenVINO ONNX Frontend"
graph {
node {
input: "A"
input: "axes"
output: "B"
op_type: "ReduceL1"
}
name: "compute_graph"
input {
name: "A"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 4
}
dim {
dim_value: 4
}
}
}
}
}
input {
name: "axes"
type {
tensor_type {
elem_type: 7
shape {
dim {
dim_value: 1
}
}
}
}
}
output {
name: "B"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
dim {
dim_value: 1
}
dim {
dim_value: 4
}
dim {
dim_value: 1
}
}
}
}
}
}
opset_import {
version: 18
}
29 changes: 29 additions & 0 deletions src/frontends/onnx/tests/onnx_import.in.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,35 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_reduce_l1) {
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_reduce_l1_18) {
auto model = convert_model("reduce_l1_18.onnx");

// input data shape (1, 1, 4, 4)
Inputs inputs{
ov::test::NDArray<float, 4>({{{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}}}).get_vector()};

// output data shape (1,)
auto expected_output = ov::test::NDArray<float, 4>({{{{16}}}}).get_vector();

auto test_case = ov::test::TestCase(model, s_device);
test_case.add_multiple_inputs(inputs);
test_case.add_expected_output(expected_output);
test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_reduce_l1_18_axes_as_input) {
auto model = convert_model("reduce_l1_18_axes_as_input.onnx");

auto test_case = ov::test::TestCase(model, s_device);

test_case.add_input<float>(Shape{1, 1, 4, 4}, {2, 1, 4, 2, 3, 1, 3, 2, 4, 2, 4, 2, 2, 2, 1, 4});
test_case.add_input<int64_t>({3});

test_case.add_expected_output(Shape{1, 1, 4, 1}, std::vector<float>{9, 9, 12, 9});

test_case.run();
}

OPENVINO_TEST(${BACKEND_NAME}, onnx_model_reduce_l2) {
auto model = convert_model("reduce_l2.onnx");

Expand Down
12 changes: 0 additions & 12 deletions src/frontends/onnx/tests/tests_python/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
skip_issue_125489,
xfail_issue_125491,
xfail_issue_125492,
xfail_issue_125493,
xfail_issue_122775,
xfail_issue_122776,
skip_misalignment,
Expand Down Expand Up @@ -435,17 +434,10 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
),
(
xfail_issue_99968,
"OnnxBackendNodeModelTest.test_reduce_l1_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_do_not_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_keep_dims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_keep_dims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_negative_axes_keep_dims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_negative_axes_keep_dims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_asc_axes_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_asc_axes_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_desc_axes_cpu",
"OnnxBackendNodeModelTest.test_reduce_log_sum_desc_axes_expanded_cpu",
"OnnxBackendNodeModelTest.test_reduce_l1_do_not_keepdims_example_cpu",
),
(
xfail_issue_99969,
Expand Down Expand Up @@ -630,10 +622,6 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"OnnxBackendNodeModelTest.test_dft_inverse_opset19_cpu",
"OnnxBackendNodeModelTest.test_dft_opset19_cpu",
),
(
xfail_issue_125493,
"OnnxBackendNodeModelTest.test_reduce_l1_empty_set_cpu",
),
(
skip_misalignment,
"OnnxBackendNodeModelTest.test_gelu_default_2_expanded_cpu",
Expand Down

0 comments on commit cb9ee02

Please sign in to comment.