-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[TRANSFORMATIONS] Fix Optional to match even with no inputs #23471
Changes from all commits
eb18946
7fe3edb
5792f4b
96c4338
0ecb2d9
55f1e5e
e9e9870
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ | |
#include "openvino/op/add.hpp" | ||
#include "openvino/op/broadcast.hpp" | ||
#include "openvino/op/constant.hpp" | ||
#include "openvino/op/cos.hpp" | ||
#include "openvino/op/divide.hpp" | ||
#include "openvino/op/exp.hpp" | ||
#include "openvino/op/multiply.hpp" | ||
#include "openvino/op/parameter.hpp" | ||
#include "openvino/op/reduce_sum.hpp" | ||
|
@@ -508,6 +510,68 @@ TEST(pattern, matching_optional) { | |
std::make_shared<op::v0::Abs>(c))); | ||
} | ||
|
||
TEST(pattern, optional_full_match) { | ||
Shape shape{}; | ||
auto model_input1 = std::make_shared<op::v0::Parameter>(element::i32, shape); | ||
auto model_input2 = std::make_shared<op::v0::Parameter>(element::i32, shape); | ||
auto model_add = std::make_shared<op::v1::Add>(model_input1->output(0), model_input2->output(0)); | ||
auto model_relu = std::make_shared<op::v0::Relu>(model_add->output(0)); | ||
|
||
auto pattern_add = ov::pass::pattern::optional<op::v1::Add>(); | ||
auto pattern_relu = std::make_shared<op::v0::Relu>(pattern_add->output(0)); | ||
|
||
TestMatcher tm; | ||
|
||
ASSERT_TRUE(tm.match(pattern_relu, model_relu)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend to test pattern_map in these tests We can do it in the next PR, not a problem. |
||
} | ||
|
||
TEST(pattern, optional_half_match) { | ||
Shape shape{}; | ||
auto model_input1 = std::make_shared<op::v0::Parameter>(element::i32, shape); | ||
auto model_input2 = std::make_shared<op::v0::Parameter>(element::i32, shape); | ||
auto model_add = std::make_shared<op::v1::Add>(model_input1->output(0), model_input2->output(0)); | ||
auto model_relu = std::make_shared<op::v0::Relu>(model_add->output(0)); | ||
|
||
auto pattern_relu = ov::pass::pattern::optional<op::v0::Relu>(); | ||
auto pattern_relu1 = std::make_shared<op::v0::Relu>(pattern_relu->output(0)); | ||
|
||
TestMatcher tm; | ||
|
||
ASSERT_TRUE(tm.match(pattern_relu1, model_relu)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please check that pattern_map[pattern_relu] is nullptr in this case |
||
} | ||
|
||
TEST(pattern, optional_testing) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in OV we have some operations with "optional" inputs, e.g. Interpolate-11 operation optional class might be used to match Interpolate with different number of inputs: 2 inputs and 3 inputs using 1 instance: could you check if we have such a test? if not could you add it? |
||
Shape shape{}; | ||
auto model_input1 = std::make_shared<op::v0::Parameter>(element::i32, shape); | ||
auto model_input2 = std::make_shared<op::v0::Parameter>(element::i32, shape); | ||
auto model_add = std::make_shared<op::v1::Add>(model_input1->output(0), model_input2->output(0)); | ||
auto model_relu = std::make_shared<op::v0::Relu>(model_add->output(0)); | ||
auto model_abs = std::make_shared<op::v0::Abs>(model_add->output(0)); | ||
|
||
TestMatcher tm; | ||
|
||
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Exp, op::v0::Relu>(model_add), model_add)); | ||
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>(model_add), model_add)); | ||
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Exp>(model_add), model_add)); | ||
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Exp, op::v0::Cos>(model_add), model_add)); | ||
|
||
ASSERT_TRUE( | ||
tm.match(ov::pass::pattern::optional<op::v0::Abs>(model_abs), std::make_shared<op::v0::Abs>(model_abs))); | ||
ASSERT_FALSE( | ||
tm.match(ov::pass::pattern::optional<op::v0::Abs>(model_abs), std::make_shared<op::v0::Relu>(model_abs))); | ||
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Abs, op::v0::Relu>(model_abs), | ||
std::make_shared<op::v0::Relu>(model_abs))); | ||
|
||
ASSERT_FALSE(tm.match(ov::pass::pattern::optional<op::v0::Exp>(model_add), model_abs)); | ||
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Exp, op::v0::Abs>(model_add), model_abs)); | ||
|
||
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Relu>(model_relu), | ||
std::make_shared<op::v0::Relu>(std::make_shared<op::v0::Relu>(model_add)))); | ||
|
||
ASSERT_TRUE(tm.match(ov::pass::pattern::optional<op::v0::Relu>(model_relu), | ||
std::make_shared<op::v0::Relu>(std::make_shared<op::v0::Relu>(model_add)))); | ||
} | ||
|
||
TEST(pattern, mean) { | ||
// construct mean | ||
TestMatcher n; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: ABS -> Abs