Symbolic review leftovers (#21388)

* Correct include pragmas in symbolic transformations

* Allow for more Reshapes to be optimized via symbolic Reshape Optimization
This commit is contained in:
Evgenya Nugmanova 2023-12-01 15:50:47 +04:00 committed by GitHub
parent ed0ce165ce
commit 055e3d274f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 162 additions and 67 deletions

View File

@ -4,8 +4,8 @@
#pragma once
#include <openvino/pass/graph_rewrite.hpp>
#include <transformations_visibility.hpp>
#include "openvino/pass/graph_rewrite.hpp"
#include "transformations_visibility.hpp"
namespace ov {
namespace pass {

View File

@ -3,9 +3,9 @@
//
#pragma once
#include <openvino/pass/graph_rewrite.hpp>
#include <openvino/pass/pass.hpp>
#include <transformations_visibility.hpp>
#include "openvino/pass/graph_rewrite.hpp"
#include "openvino/pass/pass.hpp"
#include "transformations_visibility.hpp"
namespace ov {
namespace pass {

View File

@ -4,8 +4,8 @@
#pragma once
#include <openvino/pass/graph_rewrite.hpp>
#include <transformations_visibility.hpp>
#include "openvino/pass/graph_rewrite.hpp"
#include "transformations_visibility.hpp"
namespace ov {
namespace pass {

View File

@ -4,8 +4,8 @@
#pragma once
#include <openvino/pass/graph_rewrite.hpp>
#include <transformations_visibility.hpp>
#include "openvino/pass/graph_rewrite.hpp"
#include "transformations_visibility.hpp"
namespace ov {
namespace pass {

View File

@ -4,11 +4,10 @@
#include "transformations/symbolic_transformations/chained_maximum.hpp"
#include <openvino/op/maximum.hpp>
#include <openvino/pass/pattern/op/wrap_type.hpp>
#include "itt.hpp"
#include "openvino/core/dimension_tracker.hpp"
#include "openvino/op/maximum.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "transformations/symbolic_transformations/utils.hpp"
using namespace ov::symbol::util;

View File

@ -4,20 +4,19 @@
#include "transformations/symbolic_transformations/label_optimization.hpp"
#include <openvino/core/bound_evaluation_util.hpp>
#include <openvino/core/dimension_tracker.hpp>
#include <openvino/op/add.hpp>
#include <openvino/op/concat.hpp>
#include <openvino/op/convert.hpp>
#include <openvino/op/gather.hpp>
#include <openvino/op/reshape.hpp>
#include <openvino/op/shape_of.hpp>
#include <openvino/op/squeeze.hpp>
#include <openvino/op/util/symbolic_info.hpp>
#include "itt.hpp"
#include "openvino/core/bound_evaluation_util.hpp"
#include "openvino/core/dimension_tracker.hpp"
#include "openvino/core/rt_info.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/convert.hpp"
#include "openvino/op/gather.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/squeeze.hpp"
#include "openvino/op/util/multi_subgraph_base.hpp"
#include "openvino/op/util/symbolic_info.hpp"
namespace {
void update_label(const ov::EqTable& table, ov::label_t& label) {

View File

@ -4,15 +4,14 @@
#include "transformations/symbolic_transformations/nop_broadcast.hpp"
#include <openvino/core/dimension_tracker.hpp>
#include <openvino/op/broadcast.hpp>
#include <openvino/op/maximum.hpp>
#include <openvino/op/shape_of.hpp>
#include <openvino/pass/pattern/op/wrap_type.hpp>
#include "compare.hpp"
#include "itt.hpp"
#include "openvino/core/dimension_tracker.hpp"
#include "openvino/op/broadcast.hpp"
#include "openvino/op/maximum.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/pass/pattern/op/or.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "transformations/symbolic_transformations/utils.hpp"
#include "transformations/utils/utils.hpp"

View File

@ -4,11 +4,10 @@
#include "transformations/symbolic_transformations/reshape_optimizations.hpp"
#include <openvino/core/dimension_tracker.hpp>
#include <openvino/pass/pattern/op/wrap_type.hpp>
#include "compare.hpp"
#include "itt.hpp"
#include "openvino/core/dimension_tracker.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
#include "transformations/symbolic_transformations/utils.hpp"
#include "transformations/utils/utils.hpp"
@ -30,22 +29,26 @@ ov::pass::ReshapeOptimizations::ReshapeOptimizations() {
if (!reshape)
return false;
const auto& in_shape = reshape->get_input_partial_shape(0);
const auto& in_rank = in_shape.size();
const auto& out_shape = reshape->get_output_partial_shape(0);
const auto& out_rank = out_shape.size();
if (in_shape.size() > out_shape.size()) {
std::vector<int64_t> output_pattern(out_shape.size(), -1);
for (size_t i = 0; i < out_shape.size(); ++i)
if (dims_are_equal(in_shape[i], out_shape[i]))
std::vector<int64_t> output_pattern(out_rank, -1);
for (size_t i = 0; i < out_rank; ++i) {
if (out_shape[i].is_static())
output_pattern[i] = out_shape[i].get_length();
else if (i >= in_rank)
break;
else if (dims_are_equal(in_shape[i], out_shape[i]))
output_pattern[i] = 0;
if (std::count(output_pattern.begin(), output_pattern.end(), -1) == 1) {
auto new_pattern =
ov::op::v0::Constant::create(element::i64, Shape{output_pattern.size()}, output_pattern);
}
if (std::count(output_pattern.begin(), output_pattern.end(), -1) <= 1) {
auto new_pattern = ov::op::v0::Constant::create(element::i64, Shape{output_pattern.size()}, output_pattern);
ov::copy_runtime_info(reshape->get_input_node_shared_ptr(1), new_pattern);
reshape->set_special_zero(true);
reshape->input(1).replace_source_output(new_pattern->output(0));
return true;
}
}
return false;
};

View File

@ -6,14 +6,13 @@
#include <gtest/gtest.h>
#include <openvino/core/model.hpp>
#include <openvino/op/broadcast.hpp>
#include <openvino/op/maximum.hpp>
#include <openvino/op/parameter.hpp>
#include <openvino/op/shape_of.hpp>
#include "common_test_utils/ov_test_utils.hpp"
#include "openvino/core/dimension_tracker.hpp"
#include "openvino/core/model.hpp"
#include "openvino/op/broadcast.hpp"
#include "openvino/op/maximum.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/op/shape_of.hpp"
#include "transformations/symbolic_transformations/symbolic_optimizations.hpp"
using namespace ov;

View File

@ -13,7 +13,6 @@
#include "openvino/op/gather.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/util/symbolic_info.hpp"
#include "openvino/pass/manager.hpp"
#include "transformations/symbolic_transformations/symbolic_optimizations.hpp"
#include "transformations/symbolic_transformations/utils.hpp"

View File

@ -6,15 +6,14 @@
#include <gtest/gtest.h>
#include <openvino/core/model.hpp>
#include <openvino/op/broadcast.hpp>
#include <openvino/op/maximum.hpp>
#include <openvino/op/parameter.hpp>
#include <openvino/op/relu.hpp>
#include <openvino/op/shape_of.hpp>
#include "common_test_utils/ov_test_utils.hpp"
#include "openvino/core/dimension_tracker.hpp"
#include "openvino/core/model.hpp"
#include "openvino/op/broadcast.hpp"
#include "openvino/op/maximum.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/op/relu.hpp"
#include "openvino/op/shape_of.hpp"
using namespace ov;
using namespace ov::op;

View File

@ -6,16 +6,16 @@
#include <gtest/gtest.h>
#include <openvino/core/model.hpp>
#include <openvino/op/concat.hpp>
#include <openvino/op/gather.hpp>
#include <openvino/op/multiply.hpp>
#include <openvino/op/parameter.hpp>
#include <openvino/op/reshape.hpp>
#include <openvino/op/shape_of.hpp>
#include "common_test_utils/ov_test_utils.hpp"
#include "openvino/core/dimension_tracker.hpp"
#include "openvino/core/model.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/divide.hpp"
#include "openvino/op/gather.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/op/reshape.hpp"
#include "openvino/op/shape_of.hpp"
using namespace ov;
using namespace ov::op;
@ -30,6 +30,7 @@ void label_shape(ov::PartialShape& shape) {
} // namespace
TEST_F(TransformationTestsF, FlattenOptimization) {
// [A, B, C, D] -> [A, B, C*D]
{
auto shape = PartialShape::dynamic(4);
label_shape(shape); // we label shape with consecutive labels: 42, 43, 44, 45
@ -65,3 +66,100 @@ TEST_F(TransformationTestsF, FlattenOptimization) {
model_ref = make_shared<Model>(NodeVector{reshape}, ParameterVector{data});
}
}
TEST_F(TransformationTestsF, LastDimSplitStaticLast) {
// [A, B, C, D] -> [A, B, C, D/8, 8]
{
auto shape = PartialShape::dynamic(4);
label_shape(shape); // we label shape with consecutive labels: 42, 43, 44, 45
auto data = make_shared<v0::Parameter>(element::f32, shape);
auto shape_of = make_shared<v3::ShapeOf>(data);
auto indices = ov::op::v0::Constant::create(element::i64, {3}, {0, 1, 2});
auto axis = ov::op::v0::Constant::create(element::i64, {}, {0});
auto as_is_dims = make_shared<v1::Gather>(shape_of, indices, axis);
auto splited_dim = ov::op::v0::Constant::create(element::i64, {2}, {-1, 8});
auto pattern = make_shared<v0::Concat>(OutputVector{as_is_dims, splited_dim}, 0);
auto reshape = make_shared<v1::Reshape>(data, pattern, false);
model = make_shared<Model>(NodeVector{reshape}, ParameterVector{data});
manager.register_pass<pass::ReshapeOptimizations>();
}
{
auto shape = PartialShape::dynamic(4);
label_shape(shape); // we label shape with consecutive labels: 42, 43, 44, 45
auto data = make_shared<v0::Parameter>(element::f32, shape);
auto pattern = ov::op::v0::Constant::create(element::i64, {5}, {0, 0, 0, -1, 8});
auto reshape = make_shared<v1::Reshape>(data, pattern, true);
model_ref = make_shared<Model>(NodeVector{reshape}, ParameterVector{data});
}
}
TEST_F(TransformationTestsF, LastDimSplitDymanicLast) {
// [A, B, C, D] -> [A, B, C, 8, D/8]
{
auto shape = PartialShape::dynamic(4);
label_shape(shape); // we label shape with consecutive labels: 42, 43, 44, 45
auto data = make_shared<v0::Parameter>(element::f32, shape);
auto shape_of = make_shared<v3::ShapeOf>(data);
auto indices = ov::op::v0::Constant::create(element::i64, {3}, {0, 1, 2});
auto axis = ov::op::v0::Constant::create(element::i64, {}, {0});
auto as_is_dims = make_shared<v1::Gather>(shape_of, indices, axis);
auto splited_dim = ov::op::v0::Constant::create(element::i64, {2}, {8, -1});
auto pattern = make_shared<v0::Concat>(OutputVector{as_is_dims, splited_dim}, 0);
auto reshape = make_shared<v1::Reshape>(data, pattern, false);
model = make_shared<Model>(NodeVector{reshape}, ParameterVector{data});
manager.register_pass<pass::ReshapeOptimizations>();
}
{
auto shape = PartialShape::dynamic(4);
label_shape(shape); // we label shape with consecutive labels: 42, 43, 44, 45
auto data = make_shared<v0::Parameter>(element::f32, shape);
auto pattern = ov::op::v0::Constant::create(element::i64, {5}, {0, 0, 0, 8, -1});
auto reshape = make_shared<v1::Reshape>(data, pattern, true);
model_ref = make_shared<Model>(NodeVector{reshape}, ParameterVector{data});
}
}
TEST_F(TransformationTestsF, NegativeTest) {
// [A, B, C, D] -> [A, B, C, D/2, D/3, 6]
{
auto shape = PartialShape::dynamic(4);
label_shape(shape); // we label shape with consecutive labels: 42, 43, 44, 45
auto data = make_shared<v0::Parameter>(element::f32, shape);
auto shape_of = make_shared<v3::ShapeOf>(data);
auto indices = ov::op::v0::Constant::create(element::i64, {3}, {0, 1, 2});
auto axis = ov::op::v0::Constant::create(element::i64, {}, {0});
auto as_is_dims = make_shared<v1::Gather>(shape_of, indices, axis);
auto D = make_shared<v1::Gather>(shape_of, ov::op::v0::Constant::create(element::i64, {1}, {3}), axis);
auto D_2 = make_shared<v1::Divide>(D, ov::op::v0::Constant::create(element::i64, {}, {2}));
auto D_3 = make_shared<v1::Divide>(D, ov::op::v0::Constant::create(element::i64, {}, {3}));
auto six = ov::op::v0::Constant::create(element::i64, {1}, {6});
auto pattern = make_shared<v0::Concat>(OutputVector{as_is_dims, D_2, D_3, six}, 0);
auto reshape = make_shared<v1::Reshape>(data, pattern, false);
model = make_shared<Model>(NodeVector{reshape}, ParameterVector{data});
manager.register_pass<pass::ReshapeOptimizations>();
}
}