From bdf27f31a700c8790486ff5261ef7a2543da6692 Mon Sep 17 00:00:00 2001 From: Andrei K Date: Mon, 25 Mar 2024 15:59:19 +0000 Subject: [PATCH 1/3] bad stuff --- src/core/tests/pattern.cpp | 128 +++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 68 deletions(-) diff --git a/src/core/tests/pattern.cpp b/src/core/tests/pattern.cpp index 097e3d07246b2c..311bb0706b5143 100644 --- a/src/core/tests/pattern.cpp +++ b/src/core/tests/pattern.cpp @@ -26,6 +26,8 @@ #include "openvino/op/reduce_sum.hpp" #include "openvino/op/relu.hpp" #include "openvino/op/subtract.hpp" +#include "openvino/op/strided_slice.hpp" +#include "openvino/op/transpose.hpp" #include "openvino/op/util/op_types.hpp" #include "openvino/pass/graph_rewrite.hpp" #include "openvino/pass/manager.hpp" @@ -72,7 +74,7 @@ static std::shared_ptr construct_mean_graph() { return mean_label; } -class TestGraphRewrite : public ov::pass::GraphRewrite { +class testGraphRewrite : public ov::pass::GraphRewrite { public: void construct_multiply_by_one() { // pattern #1 : a * 1 = a @@ -191,7 +193,7 @@ class TestGraphRewrite : public ov::pass::GraphRewrite { this->add_matcher(match_pass); } - TestGraphRewrite() : GraphRewrite() { + testGraphRewrite() : GraphRewrite() { construct_multiply_by_one(); construct_add_zero(); } @@ -207,7 +209,7 @@ static void run_passes(pass::Manager& pass_manager, TEST(pattern, graph_rewrite) { Shape shape{}; pass::Manager pass_manager; - pass_manager.register_pass(); + pass_manager.register_pass(); { auto a = make_shared(element::i32, shape); @@ -487,7 +489,7 @@ TEST(pattern, matcher) { } } -TEST(pattern, matching_optional) { +TEST(pattern, optional_single_in) { Shape shape{}; auto a = make_shared(element::i32, shape); auto b = make_shared(element::i32, shape); @@ -501,94 +503,84 @@ TEST(pattern, matching_optional) { ASSERT_TRUE(n.match(ov::pass::pattern::optional(d), std::make_shared(c))); ASSERT_TRUE(n.match(ov::pass::pattern::optional(d), std::make_shared(c))); ASSERT_FALSE( - n.match(ov::pass::pattern::optional(d), std::make_shared(c))); + n.match(ov::pass::pattern::optional(d), std::make_shared(c))); + ASSERT_FALSE( + n.match(ov::pass::pattern::optional(d), std::make_shared(c))); const auto predicate = [](const Output& output) { return false; }; - ASSERT_FALSE(n.match(ov::pass::pattern::optional(d, predicate), + ASSERT_FALSE(n.match(ov::pass::pattern::optional({d}, predicate), std::make_shared(c))); } -// Optional is not working properly yet CVS-136454 -TEST(pattern, DISABLED_optional_full_match) { +TEST(pattern, optional_multi_in_cumulative_op) { Shape shape{}; - auto model_input = std::make_shared(element::i32, shape); - auto model_relu = std::make_shared(model_input); - auto model_relu1 = std::make_shared(model_relu->output(0)); - - auto pattern_relu = ov::pass::pattern::optional(); - auto pattern_relu1 = std::make_shared(pattern_relu->output(0)); - - TestMatcher tm; + auto a = make_shared(element::i32, shape); + auto b = make_shared(element::i32, shape); + auto c = std::make_shared(a, b); - ASSERT_TRUE(tm.match(pattern_relu1, model_relu1)); + TestMatcher n; + ASSERT_TRUE(n.match(ov::pass::pattern::optional(ov::OutputVector{a,b}), c)); + ASSERT_TRUE(n.match(ov::pass::pattern::optional(ov::OutputVector{b, a}), c)); + ASSERT_FALSE(n.match(ov::pass::pattern::optional(ov::OutputVector{a}), c)); + ASSERT_FALSE(n.match(ov::pass::pattern::optional(ov::OutputVector{b}), c)); + ASSERT_TRUE(n.match(ov::pass::pattern::optional(ov::OutputVector{a,b}), a)); + ASSERT_TRUE(n.match(ov::pass::pattern::optional(ov::OutputVector{a,b}), b)); } -// Optional is not working properly yet CVS-136454 -TEST(pattern, DISABLED_optional_half_match) { - Shape shape{}; - auto model_input = std::make_shared(element::i32, shape); - auto model_relu = std::make_shared(model_input); - auto model_relu1 = std::make_shared(model_relu->output(0)); - - auto pattern_abs = ov::pass::pattern::optional(); - auto pattern_relu = std::make_shared(pattern_abs->output(0)); +TEST(pattern, optional_multi_in_order_important) { + Shape shape{2, 3, 4}; + auto a = make_shared(element::f32, shape); + auto b = make_shared(element::i32, ov::Shape{3}, std::vector{2, 0, 1}); + auto c = std::make_shared(a, b); - TestMatcher tm; - - ASSERT_TRUE(tm.match(pattern_relu, model_relu1)); + TestMatcher n; + ASSERT_TRUE(n.match(ov::pass::pattern::optional(ov::OutputVector{a,b}), c)); + ASSERT_FALSE(n.match(ov::pass::pattern::optional(ov::OutputVector{b, a}), c)); + ASSERT_FALSE(n.match(ov::pass::pattern::optional(ov::OutputVector{a}), c)); + ASSERT_FALSE(n.match(ov::pass::pattern::optional(ov::OutputVector{b}), c)); + ASSERT_TRUE(n.match(ov::pass::pattern::optional(ov::OutputVector{a,b}), a)); + ASSERT_TRUE(n.match(ov::pass::pattern::optional(ov::OutputVector{a,b}), b)); } -// Optional is not working properly yet CVS-136454 -TEST(pattern, DISABLED_optional_testing) { +TEST(pattern, optional_multi_in_pattern_matching) { Shape shape{}; - auto model_input1 = std::make_shared(element::i32, shape); - auto model_input2 = std::make_shared(element::i32, shape); - auto model_add = std::make_shared(model_input1->output(0), model_input2->output(0)); - auto model_relu = std::make_shared(model_add->output(0)); - auto model_abs = std::make_shared(model_add->output(0)); + auto model_input_0 = std::make_shared(element::i32, shape); + auto model_input_1 = std::make_shared(element::i32, shape); + auto model_add = std::make_shared(model_input_0, model_input_1); + auto model_add_reverse = std::make_shared(model_input_1, model_input_0); + auto model_relu_with_add = std::make_shared(model_add); + auto model_relu_with_add_reverse = std::make_shared(model_add_reverse); + auto model_relu_without_add_0 = std::make_shared(model_input_0); + auto model_relu_without_add_1 = std::make_shared(model_input_1); + + auto pattern_input_0 = ov::pass::pattern::any_input(); + auto pattern_input_1 = ov::pass::pattern::any_input(); + auto pattern_add = ov::pass::pattern::optional(ov::OutputVector{pattern_input_0, pattern_input_1}); + auto pattern_relu = std::make_shared(pattern_add->output(0)); TestMatcher tm; - - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(model_add), model_add)); - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(model_add), model_add)); - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(model_add), model_add)); - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(model_add), model_add)); - - ASSERT_TRUE( - tm.match(ov::pass::pattern::optional(model_abs), std::make_shared(model_abs))); - ASSERT_FALSE( - tm.match(ov::pass::pattern::optional(model_abs), std::make_shared(model_abs))); - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(model_abs), - std::make_shared(model_abs))); - - ASSERT_FALSE(tm.match(ov::pass::pattern::optional(model_add), model_abs)); - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(model_add), model_abs)); - - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(model_relu), - std::make_shared(std::make_shared(model_add)))); - - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(model_relu), - std::make_shared(std::make_shared(model_add)))); + ASSERT_TRUE(tm.match(pattern_relu, model_relu_with_add)); + ASSERT_TRUE(tm.match(pattern_relu, model_relu_with_add_reverse)); + ASSERT_TRUE(tm.match(pattern_relu, model_relu_without_add_0)); + ASSERT_TRUE(tm.match(pattern_relu, model_relu_without_add_1)); } -// Optional is not working properly yet CVS-136454 -TEST(pattern, DISABLED_optional_one_node) { +TEST(pattern, optional_single_in_pattern_matching) { Shape shape{}; auto model_input = std::make_shared(element::i32, shape); auto model_relu = std::make_shared(model_input); - auto model_abs = std::make_shared(model_input); + auto model_abs_with_relu = std::make_shared(model_relu); + auto model_abs_without_relu = std::make_shared(model_input); - TestMatcher tm; + auto pattern_input = ov::pass::pattern::any_input(); + auto pattern_relu = ov::pass::pattern::optional(pattern_input); + auto pattern_abs = std::make_shared(pattern_relu); - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(), model_relu)); - ASSERT_FALSE(tm.match(ov::pass::pattern::optional(), model_relu)); - - ASSERT_FALSE(tm.match(ov::pass::pattern::optional(), model_abs)); - - ASSERT_TRUE(tm.match(ov::pass::pattern::optional(), model_input)); - ASSERT_FALSE(tm.match(ov::pass::pattern::optional(), model_input)); + TestMatcher tm; + ASSERT_TRUE(tm.match(pattern_abs, model_abs_with_relu)); + ASSERT_TRUE(tm.match(pattern_abs, model_abs_without_relu)); } TEST(pattern, mean) { From 57d5a81e36de57494dfa9081136120c4b852e657 Mon Sep 17 00:00:00 2001 From: Andrei K Date: Mon, 25 Mar 2024 16:07:04 +0000 Subject: [PATCH 2/3] sample --- src/core/tests/pattern.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/tests/pattern.cpp b/src/core/tests/pattern.cpp index 311bb0706b5143..ae769de53b2bbf 100644 --- a/src/core/tests/pattern.cpp +++ b/src/core/tests/pattern.cpp @@ -805,4 +805,4 @@ TEST(pattern, wrap_type_multi_op) { ASSERT_FALSE(matcher->match(static_pointer_cast(b))); ASSERT_FALSE(matcher->match(static_pointer_cast(c))); } -} +} \ No newline at end of file From 72d0a4979ab418f8015db374464460c1748435ff Mon Sep 17 00:00:00 2001 From: Andrei K Date: Mon, 25 Mar 2024 16:18:59 +0000 Subject: [PATCH 3/3] sample 2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f38feb9580d50..09f49be056e6d7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -
+
[![PyPI Status](https://badge.fury.io/py/openvino.svg)](https://badge.fury.io/py/openvino)