Skip to content

Commit

Permalink
Enable UnrollIf tests on CPU
Browse files Browse the repository at this point in the history
- add UnrollIf to check tensor names are not lost if body model is Parameter -> Result

Signed-off-by: Raasz, Pawel <[email protected]>
  • Loading branch information
praasz committed Nov 14, 2024
1 parent 73631e3 commit cc8a3b7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
65 changes: 64 additions & 1 deletion src/common/transformations/tests/control_flow/unroll_if_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
#include "transformations/init_node_info.hpp"
#include "transformations/rt_info/fused_names_attribute.hpp"

using namespace ov;
using namespace testing;

namespace ov {
namespace test {
using op::v0::Constant;
using op::v0::Parameter;
using op::v0::Result;
using op::v1::Add;

std::shared_ptr<ov::Model> get_then_body() {
auto Xt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});
Xt->set_friendly_name("Xt");
Expand Down Expand Up @@ -350,3 +356,60 @@ TEST(TransformationTests, UnrollIfInsideIf) {
auto res = compare_functions(f, f_ref);
ASSERT_TRUE(res.first) << res.second;
}

TEST(TransformationTests, UnrollIfToParameterResultModel) {
constexpr auto et = element::f32;
std::shared_ptr<Model> model, model_ref;

{
const auto a = std::make_shared<Parameter>(et, PartialShape{5, 7});
const auto b = std::make_shared<Parameter>(et, PartialShape{1});
const auto c = std::make_shared<Parameter>(et, PartialShape{5, 7});

const auto then_add = std::make_shared<Add>(a, b);
auto then_result = std::make_shared<Result>(then_add);
auto else_result = std::make_shared<Result>(c);

const auto then_body = std::make_shared<Model>(OutputVector{then_result}, ParameterVector{a, b});
const auto else_body = std::make_shared<Model>(OutputVector{else_result}, ParameterVector{c});

const auto if_input_0 = std::make_shared<Parameter>(et, a->get_output_partial_shape(0));
const auto if_input_1 = std::make_shared<Parameter>(et, b->get_output_partial_shape(0));
const auto condition = Constant::create(element::boolean, {1}, {false});
const auto if_op = std::make_shared<op::v8::If>(condition);
if_op->set_then_body(then_body);
if_op->set_else_body(else_body);
if_op->set_input(if_input_0, a, c);
if_op->set_input(if_input_1, b, nullptr);
const auto if_result = if_op->set_output(then_result, else_result);

const auto results = ResultVector{std::make_shared<Result>(if_result)};
model = std::make_shared<Model>(results, ParameterVector{if_input_0, if_input_1}, "simple_if");
model->input(0).set_names({"Input.0"});
model->input(1).set_names({"Input.1"});
model->output(0).set_names({"Output"});

pass::Manager manager;
manager.register_pass<pass::InitNodeInfo>();
manager.register_pass<pass::UnrollIf>();
manager.run_passes(model);

OV_ASSERT_NO_THROW(check_rt_info(model));
}
{
const auto p = std::make_shared<Parameter>(et, PartialShape{5, 7});
const auto r = std::make_shared<Result>(p);
model_ref = std::make_shared<Model>(ResultVector{r}, ParameterVector{p}, "simple_if");
model_ref->input(0).set_names({"Input.0"});
model_ref->output(0).set_names({"Output"});
}

const auto cmp_result = compare_functions(model, model_ref);
ASSERT_TRUE(cmp_result.first) << cmp_result.second;

EXPECT_THAT(model->input(0).get_names(), UnorderedElementsAre("Input.0", "Output"));
EXPECT_THAT(model->output(0).get_names(), UnorderedElementsAre("Output"));
}

} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ std::vector<std::string> disabledTestPatterns() {
R"(.*InferRequestPreprocessTest.*SetPreProcessToInferRequest.*)",
// Plugin version was changed to ov::Version
R"(.*VersionTest.pluginCurrentVersionIsCorrect.*)",
// Issue: 113703, 114763
R"(.*smoke_If/SimpleIfTest.*Cond=0.*)",
// Issue: 114765
R"(.*smoke_PSROIPoolingAverageLayoutTest/PSROIPoolingLayerCPUTest.*bf16.*)",
R"(.*smoke_PSROIPoolingBilinearLayoutTest/PSROIPoolingLayerCPUTest.*bf16.*)",
Expand Down

0 comments on commit cc8a3b7

Please sign in to comment.