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

[ONNX] Align behavior of ReduceL2-11, 13, 18 with original framework #22741

Merged
merged 38 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8ce144f
Fix display bash code README.md
LucaTamSapienza Jan 30, 2024
8eabde3
Added prompt windows to enhance user interaction README.md
LucaTamSapienza Jan 30, 2024
4568fc6
Update README.md
LucaTamSapienza Jan 30, 2024
1980392
Update README.md
LucaTamSapienza Jan 30, 2024
9c27201
Merge branch 'openvinotoolkit:master' into master
LucaTamSapienza Feb 1, 2024
04afb4b
Merge branch 'openvinotoolkit:master' into master
LucaTamSapienza Feb 7, 2024
5ab3a45
added namespace set_11, 13, 18 for ReduceL2 function
LucaTamSapienza Feb 7, 2024
bdf9cf1
added namespace set_11, 13, 18 for ReduceL2 function for header file
LucaTamSapienza Feb 7, 2024
008dcb5
added unit test based on prototxt file
LucaTamSapienza Feb 7, 2024
876a8ed
registered function in ops_bridge
LucaTamSapienza Feb 7, 2024
a1b708a
added prototxt file for ReduceL2 operation opset 11,13,18
LucaTamSapienza Feb 7, 2024
3b4343a
range for set11,13 is now [-r, r-1], r = rank(data)
LucaTamSapienza Feb 8, 2024
4593701
changed tests
LucaTamSapienza Feb 8, 2024
8128e26
Merge branch 'openvinotoolkit:master' into ReduceL2
LucaTamSapienza Feb 8, 2024
23c4c47
Merge branch 'openvinotoolkit:master' into ReduceL2
LucaTamSapienza Feb 11, 2024
9c51de1
fixed compilation error
LucaTamSapienza Feb 18, 2024
555cbbf
changed reduce.hpp file for set_13
LucaTamSapienza Feb 18, 2024
9effc2e
ordered version from bottom to top
LucaTamSapienza Feb 18, 2024
f610bb6
Merge branch 'master' into ReduceL2
p-wysocki Feb 23, 2024
5461d3c
fix code style
LucaTamSapienza Feb 24, 2024
cd3caba
Merge branch 'openvinotoolkit:master' into ReduceL2
LucaTamSapienza Feb 28, 2024
73e5002
removed useless checks
LucaTamSapienza Feb 28, 2024
eab1747
fixed compilation error
LucaTamSapienza Feb 28, 2024
75df95c
solving merge conflict
LucaTamSapienza Mar 15, 2024
de63f04
changed set_13, set_18 after rebase
LucaTamSapienza Mar 16, 2024
d444803
removed failed ticket due to reeduceL2
LucaTamSapienza Mar 16, 2024
f456af8
added 'rank' input in prototxt file v_18
LucaTamSapienza Mar 16, 2024
42af061
Merge branch 'master' into ReduceL2
LucaTamSapienza Mar 26, 2024
d7517bb
fix code style
LucaTamSapienza Mar 26, 2024
c719c03
removed OnnxBackendNodeModelTest.test_reduce_l2_empty_set_cpu
LucaTamSapienza Mar 26, 2024
21175fd
solving build conflict
LucaTamSapienza Mar 26, 2024
e08e6bf
Merge branch 'master' into ReduceL2
LucaTamSapienza Mar 29, 2024
20c5840
removed opset11 for reducel2
LucaTamSapienza Mar 29, 2024
0817cdd
Update reduce.hpp: code style
gkrivor Apr 2, 2024
b202862
Update reduce.cpp: code style
gkrivor Apr 2, 2024
7e544fc
Merge branch 'master' into ReduceL2
gkrivor Apr 2, 2024
dac55b1
Update ops_bridge.cpp: unused record
gkrivor Apr 2, 2024
3e232e1
Update test_backend.py
gkrivor Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/frontends/onnx/frontend/src/op/reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ ov::OutputVector reduce_sum_square(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceSum>(node, square_node, supported_types_v1)};
}
} // namespace set_1

/*
Opset 11 is skipped because there are no significant difference between opset1 and opset 11.
Found difference is:
Expand All @@ -198,12 +199,18 @@ namespace set_13 {
ov::OutputVector reduce_sum(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceSum>(node, node.get_ov_inputs().at(0), supported_types_v2, false)};
}
ov::OutputVector reduce_l2(const Node& node) {
return {make_ov_reduction_op<v4::ReduceL2>(node, node.get_ov_inputs().at(0), supported_types_v2)};
}
ov::OutputVector reduce_max(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceMax>(node, node.get_ov_inputs().at(0), supported_types_v3)};
}
} // namespace set_13

namespace set_18 {
ov::OutputVector reduce_l2(const Node& node) {
return {make_ov_reduction_op<v4::ReduceL2>(node, node.get_ov_inputs().at(0), supported_types_v2, false)};
}
ov::OutputVector reduce_max(const ov::frontend::onnx::Node& node) {
return {make_ov_reduction_op<v1::ReduceMax>(node, node.get_ov_inputs().at(0), supported_types_v3, false)};
}
Expand Down
7 changes: 7 additions & 0 deletions src/frontends/onnx/frontend/src/op/reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ ov::OutputVector reduce_l1(const ov::frontend::onnx::Node& node);
namespace set_1 {
ov::OutputVector reduce_l2(const ov::frontend::onnx::Node& node);
} // namespace set_1
namespace set_13 {
ov::OutputVector reduce_l2(const ov::frontend::onnx::Node& node);
} // namespace set_13
namespace set_18 {
ov::OutputVector reduce_l2(const ov::frontend::onnx::Node& node);
} // namespace set_18

namespace set_1 {
ov::OutputVector reduce_max(const ov::frontend::onnx::Node& node);
Expand Down Expand Up @@ -64,6 +70,7 @@ ov::OutputVector reduce_sum(const ov::frontend::onnx::Node& node);
namespace set_1 {
ov::OutputVector reduce_sum_square(const ov::frontend::onnx::Node& node);
} // namespace set_1

} // namespace op
} // namespace onnx
} // namespace frontend
Expand Down
3 changes: 3 additions & 0 deletions src/frontends/onnx/frontend/src/ops_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ OperatorsBridge::OperatorsBridge() {
REGISTER_OPERATOR("ReduceLogSumExp", 1, reduce_log_sum_exp);
REGISTER_OPERATOR("ReduceL1", 1, reduce_l1);
REGISTER_OPERATOR("ReduceL2", 1, reduce_l2);
REGISTER_OPERATOR("ReduceL2", 11, reduce_l2);
REGISTER_OPERATOR("ReduceL2", 13, reduce_l2);
REGISTER_OPERATOR("ReduceL2", 18, reduce_l2);
REGISTER_OPERATOR("ReduceMax", 1, reduce_max);
REGISTER_OPERATOR("ReduceMax", 13, reduce_max);
REGISTER_OPERATOR("ReduceMax", 18, reduce_max);
Expand Down
4 changes: 2 additions & 2 deletions src/frontends/onnx/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True):
xfail_issue_99957 = xfail_test(reason="LayerNorm - RuntimeError: While validating node '<Node(Reshape): Mean>'")
xfail_issue_99960 = xfail_test(reason="MVN - Results mismatch")
xfail_issue_99961 = xfail_test(reason="Optional has/get element operators are not supported)'")
xfail_issue_99962 = pytest.mark.skip(reason="ReduceL1/L2 - Unrecognized attribute: axes for operator ReduceL1/L2")
xfail_issue_99968 = xfail_test(reason="ReduceL1/L2 - Results mismatch or unsupported ReduceSum with "
xfail_issue_99962 = pytest.mark.skip(reason="ReduceL1 - Unrecognized attribute: axes for operator ReduceL1")
xfail_issue_99968 = xfail_test(reason="ReduceL1 - Results mismatch or unsupported ReduceSum with "
"dynamic rank by CPU plugin")
xfail_issue_99969 = xfail_test(reason="Resize - Results mismatch / "
"RuntimeError: While validating ONNX node '<Node(Resize): Y>' / "
Expand Down
48 changes: 48 additions & 0 deletions src/frontends/onnx/tests/models/reduce_l2_11.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ir_version: 4
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "A"
output: "B"
op_type: "ReduceL2"
}
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: 11
}
48 changes: 48 additions & 0 deletions src/frontends/onnx/tests/models/reduce_l2_13.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
ir_version: 4
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "A"
output: "B"
op_type: "ReduceL2"
}
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: 13
}
61 changes: 61 additions & 0 deletions src/frontends/onnx/tests/models/reduce_l2_18.prototxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
ir_version: 4
producer_name: "nGraph ONNX Importer"
graph {
node {
input: "A"
output: "B"
op_type: "ReduceL2"
}
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: 6
shape {
dim {
dim_value: 1
}
}
}
}
}
output {
name: "B"
type {
tensor_type {
elem_type: 1
shape {
dim {
dim_value: 1
}
}
}
}
}
}
opset_import {
version: 18
}
48 changes: 48 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,54 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_reduce_l2) {
test_case.run();
}

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

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

// output data shape (1,)
auto expected_output = ov::test::NDArray<float, 4>({{{{12}}}}).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_l2_13) {
auto model = convert_model("reduce_l2_13.onnx");

// input data shape (1, 1, 4, 4)
Inputs inputs{
ov::test::NDArray<float, 4>({{{{4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}, {4, 4, 4, 4}}}}).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_l2_18) {
auto model = convert_model("reduce_l2_18.onnx");

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

// output data shape (1,)
auto expected_output = ov::test::NDArray<float, 4>({{{{20}}}}).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_max) {
auto model = convert_model("reduce_max.onnx");

Expand Down
6 changes: 0 additions & 6 deletions src/frontends/onnx/tests/tests_python/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,6 @@ def expect_fail(test_case_path, xfail): # type: (str) -> None
"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_l2_do_not_keepdims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_do_not_keepdims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_keep_dims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_keep_dims_random_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_negative_axes_keep_dims_example_cpu",
"OnnxBackendNodeModelTest.test_reduce_l2_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",
Expand Down
Loading