From aac04013881d359d9ab43d7bc19c74649713523d Mon Sep 17 00:00:00 2001 From: Tikhonov Ivan Date: Fri, 21 Feb 2025 18:20:50 +0400 Subject: [PATCH] Revert "Add transformation pipeline to PrePostProcessing (#28852)" This reverts commit 5d0027354f1077146f99dafb9f8b7deb150e20b8. --- .../tests/test_graph/test_preprocess.py | 20 ++- .../rt_info/dequantization_node.hpp | 2 - .../moc_transformations.cpp | 11 +- .../rt_info/dequantization_node.cpp | 4 - .../preprocessing_fusion_tests.cpp | 132 ++++++++++-------- src/core/src/pass/constant_folding.cpp | 4 +- src/core/src/preprocess/pre_post_process.cpp | 105 -------------- src/core/tests/preprocess.cpp | 78 ----------- 8 files changed, 86 insertions(+), 270 deletions(-) diff --git a/src/bindings/python/tests/test_graph/test_preprocess.py b/src/bindings/python/tests/test_graph/test_preprocess.py index 1074c60b973552..cb0cc32b3fc03a 100644 --- a/src/bindings/python/tests/test_graph/test_preprocess.py +++ b/src/bindings/python/tests/test_graph/test_preprocess.py @@ -72,8 +72,7 @@ def test_graph_preprocess_scale_vector(): assert list(model.get_output_shape(0)) == [2, 2] assert model.get_output_element_type(0) == Type.f32 assert "Constant" in model_operators - # Div will be converted to Mul in the transformations - assert "Multiply" in model_operators + assert "Divide" in model_operators def test_graph_preprocess_mean_scale_convert(): @@ -96,13 +95,12 @@ def custom_preprocess(output: Output): model = ppp.build() model_operators = [op.get_name().split("_")[0] for op in model.get_ops()] - # Div will be converted to Mul in the transformations expected_ops = [ "Parameter", "Convert", "Constant", "Subtract", - "Multiply", + "Divide", "Result", "Abs", ] @@ -139,13 +137,12 @@ def custom_preprocess(output: Output): model = ppp.build() model_operators = [op.get_name().split("_")[0] for op in model.get_ops()] - # Div will be converted to Mul in the transformations expected_ops = [ "Parameter", "Convert", "Constant", "Subtract", - "Multiply", + "Divide", "Result", "Abs", ] @@ -407,7 +404,7 @@ def test_graph_preprocess_steps(algorithm, color_format1, color_format2, is_fail "Gather", "Interpolate", ] - assert len(model_operators) == 12 + assert len(model_operators) == 15 assert model.get_output_size() == 1 assert list(model.get_output_shape(0)) == [1, 3, 3, 3] assert model.get_output_element_type(0) == Type.f32 @@ -459,9 +456,10 @@ def test_graph_preprocess_postprocess_layout(): "Constant", "Result", "Gather", + "Range", "Transpose", ] - assert len(model_operators) == 11 + assert len(model_operators) == 14 assert model.get_output_size() == 1 assert list(model.get_output_shape(0)) == [1, 1, 3, 3] assert model.get_output_element_type(0) == Type.f32 @@ -488,8 +486,9 @@ def test_graph_preprocess_reverse_channels(): "Constant", "Result", "Gather", + "Range", ] - assert len(model_operators) == 7 + assert len(model_operators) == 10 assert model.get_output_size() == 1 assert list(model.get_output_shape(0)) == [1, 2, 2, 2] assert model.get_output_element_type(0) == Type.f32 @@ -629,7 +628,6 @@ def custom_preprocess(output: Output): model = ppp.build() model_operators = [op.get_name().split("_")[0] for op in model.get_ops()] - # Div will be converted to Mul in the transformations expected_ops = [ "Parameter", "Constant", @@ -638,7 +636,7 @@ def custom_preprocess(output: Output): "Convert", "Abs", "Add", - "Multiply", + "Divide", ] assert len(model_operators) == 13 assert model.get_output_size() == 1 diff --git a/src/common/transformations/include/transformations/rt_info/dequantization_node.hpp b/src/common/transformations/include/transformations/rt_info/dequantization_node.hpp index a2b9e854e81458..50be44aba3d33c 100644 --- a/src/common/transformations/include/transformations/rt_info/dequantization_node.hpp +++ b/src/common/transformations/include/transformations/rt_info/dequantization_node.hpp @@ -14,8 +14,6 @@ TRANSFORMATIONS_API void mark_as_dequantization_node(const std::shared_ptr TRANSFORMATIONS_API bool is_dequantization_node(const std::shared_ptr& node); -TRANSFORMATIONS_API void unmark_dequantization_node(const std::shared_ptr& node); - /** * @ingroup ov_runtime_attr_api * @brief DequantizationNode class represents runtime info attribute that marks operation diff --git a/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp b/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp index 2ea7f9a02dcffe..01a9f4169e7a70 100644 --- a/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/moc_transformations.cpp @@ -131,15 +131,8 @@ bool ov::pass::MOCTransformations::run_on_model(const std::shared_ptr using namespace ov::pass; REGISTER_PASS(manager, InitNodeInfo) if (m_low_precision_enabled) { - manager.register_pass(element::TypeVector{ov::element::i8, - ov::element::u8, - ov::element::i4, - ov::element::u4, - ov::element::nf4, - ov::element::f4e2m1, - ov::element::f8e4m3, - ov::element::f8e5m2, - ov::element::f8e8m0}); + manager.register_pass( + element::TypeVector{ov::element::i8, ov::element::u8, ov::element::i4, ov::element::u4}); } if (!m_use_shapes) { manager.register_pass(); diff --git a/src/common/transformations/src/transformations/rt_info/dequantization_node.cpp b/src/common/transformations/src/transformations/rt_info/dequantization_node.cpp index 4e3ef2b3cd93ed..91ebe224fcc576 100644 --- a/src/common/transformations/src/transformations/rt_info/dequantization_node.cpp +++ b/src/common/transformations/src/transformations/rt_info/dequantization_node.cpp @@ -9,10 +9,6 @@ void ov::mark_as_dequantization_node(const std::shared_ptr& node) { rt_info[DequantizationNode::get_type_info_static()] = DequantizationNode(); } -void ov::unmark_dequantization_node(const std::shared_ptr& node) { - node->get_rt_info().erase(DequantizationNode::get_type_info_static()); -} - bool ov::is_dequantization_node(const std::shared_ptr& node) { const auto& rt_info = node->get_rt_info(); return rt_info.find(DequantizationNode::get_type_info_static()) != rt_info.end(); diff --git a/src/common/transformations/tests/common_optimizations/preprocessing_fusion_tests.cpp b/src/common/transformations/tests/common_optimizations/preprocessing_fusion_tests.cpp index df9f3cf0cbc2ac..55cc23b730d7dd 100644 --- a/src/common/transformations/tests/common_optimizations/preprocessing_fusion_tests.cpp +++ b/src/common/transformations/tests/common_optimizations/preprocessing_fusion_tests.cpp @@ -10,7 +10,6 @@ #include "common_test_utils/ov_test_utils.hpp" #include "openvino/core/model.hpp" #include "openvino/core/preprocess/pre_post_process.hpp" -#include "openvino/core/validation_util.hpp" #include "openvino/opsets/opset12.hpp" #include "openvino/opsets/opset8.hpp" #include "openvino/pass/constant_folding.hpp" @@ -68,7 +67,7 @@ std::shared_ptr create_group_conv_with_gather(Output inp Constant::create(element::i64, Shape{order.size()}, order), Constant::create(element::i64, Shape{1}, {0})); return std::make_shared(input, - ov::util::get_constant_from_source(gather), + gather, ov::Strides{1, 1}, ov::CoordinateDiff{0, 0}, ov::CoordinateDiff{0, 0}, @@ -82,7 +81,7 @@ std::shared_ptr create_conv_with_gather(Output input, Constant::create(element::i64, Shape{order.size()}, order), Constant::create(element::i64, Shape{1}, {1})); return std::make_shared(input, - ov::util::get_constant_from_source(gather), + gather, ov::Strides{1, 1}, ov::CoordinateDiff{0, 0}, ov::CoordinateDiff{0, 0}, @@ -133,8 +132,9 @@ TEST_F(TransformationTestsF, RICFusionSimple) { auto conv = create_conv(relu, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { @@ -173,8 +173,9 @@ TEST_F(TransformationTestsF, RICFusionHard) { model = std::make_shared(NodeVector{conv, conv2}, ParameterVector{input, input2}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({-1, -1, -1, -1}); @@ -231,8 +232,9 @@ TEST_F(TransformationTestsF, RICFusionHardNegativePad12) { model = std::make_shared(NodeVector{conv, conv2}, ParameterVector{input, input2}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({-1, -1, -1, -1}); @@ -273,8 +275,9 @@ TEST_F(TransformationTestsF, RICFusionDynamic) { auto conv = create_conv(relu, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { @@ -295,14 +298,15 @@ TEST_F(TransformationTestsF, RICFusionEltwise1) { auto conv = create_conv(add, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({1, 3, 64, 64}); auto gather = create_gather(Constant::create(element::f32, Shape{3, 1, 1}, {0.1, 0.2, 0.3}), {2, 1, 0}, 0); - auto add = std::make_shared(input, ov::util::get_constant_from_source(gather)); + auto add = std::make_shared(input, gather); auto conv = create_conv_with_gather(add, {6, 3, 3, 3}, {2, 1, 0}); model_ref = std::make_shared(NodeVector{conv}, ParameterVector{input}); } @@ -319,8 +323,9 @@ TEST_F(TransformationTestsF, RICFusionEltwise2) { auto conv = create_conv(add, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { @@ -342,8 +347,9 @@ TEST_F(TransformationTestsF, RICFusionEltwise3) { auto conv = create_conv(add, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { @@ -365,14 +371,15 @@ TEST_F(TransformationTestsF, RICFusionEltwise4) { auto conv = create_conv(add, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({1, 3, 64, 64}); auto gather = create_gather(create_weights({3, 1, 1}), {2, 1, 0}, 0); - auto add = std::make_shared(ov::util::get_constant_from_source(gather), input); + auto add = std::make_shared(gather, input); auto conv = create_conv_with_gather(add, {6, 3, 3, 3}, {2, 1, 0}); model_ref = std::make_shared(NodeVector{conv}, ParameterVector{input}); } @@ -389,14 +396,15 @@ TEST_F(TransformationTestsF, RICFusionEltwise5) { auto conv = create_conv(add, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({1, 3, 64, 64}); auto gather = create_gather(create_weights({1, 3, 1, 1}), {2, 1, 0}, 1); - auto add = std::make_shared(ov::util::get_constant_from_source(gather), input); + auto add = std::make_shared(gather, input); auto conv = create_conv_with_gather(add, {6, 3, 3, 3}, {2, 1, 0}); model_ref = std::make_shared(NodeVector{conv}, ParameterVector{input}); } @@ -414,8 +422,9 @@ TEST_F(TransformationTestsF, RICFusionEltwiseNegative) { auto conv = create_conv(add, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input, input2}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } } @@ -427,8 +436,9 @@ TEST_F(TransformationTestsF, RICFusionEltwiseTwoRIC) { auto conv = create_conv(add, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input, input2}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}, {1, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({1, 3, 64, 64}); @@ -450,8 +460,9 @@ TEST_F(TransformationTestsF, RICFusionEltwiseNegative3) { auto shapeof = std::make_shared(add); model = std::make_shared(NodeVector{shapeof}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } } @@ -463,8 +474,9 @@ TEST_F(TransformationTestsF, RICFusionGroupConv) { auto conv = create_conv(relu, {3, 6, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({1, 3, 64, 64}); @@ -489,8 +501,9 @@ TEST_F(TransformationTestsF, RICFusionGroupConvNegative) { auto conv = create_conv(relu, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } } @@ -502,14 +515,15 @@ TEST_F(TransformationTestsF, RICFusionTranspose) { auto conv = create_conv(transpose, {6, 3, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NHWC"}}); + + manager.register_pass(); } { auto input = create_param({1, 64, 64, 3}); auto gather = create_gather(create_weights({3}), {2, 1, 0}, 0); - auto add = std::make_shared(input, ov::util::get_constant_from_source(gather)); + auto add = std::make_shared(input, gather); auto transpose = std::make_shared(add, Constant::create(element::i64, Shape{4}, {0, 3, 1, 2})); auto conv = create_conv_with_gather(transpose, {6, 3, 3, 3}, {2, 1, 0}); model_ref = std::make_shared(NodeVector{conv}, ParameterVector{input}); @@ -527,15 +541,15 @@ TEST_F(TransformationTestsF, RICFusionFQOnTheWay) { auto conv = create_conv(fq, create_fq(create_weights({6, 3, 3, 3}))); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({1, 3, 64, 64}); auto fq = create_fq(input); - auto weights = ov::util::get_constant_from_source(create_gather(create_weights({6, 3, 3, 3}), {2, 1, 0}, 1)); - auto conv = create_conv(fq, create_fq(weights)); + auto conv = create_conv(fq, create_fq(create_gather(create_weights({6, 3, 3, 3}), {2, 1, 0}, 1))); model_ref = std::make_shared(NodeVector{conv}, ParameterVector{input}); } @@ -559,21 +573,21 @@ TEST_F(TransformationTestsF, RICFusionFQOnTheWay2) { auto conv = create_conv(fq, fq_weights); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({1, 3, 64, 64}); auto fq = create_fq(input); auto weights_const = create_weights({6, 3, 3, 3}); - auto fq_weights = std::make_shared( - ov::util::get_constant_from_source(create_gather(weights_const, {2, 1, 0}, 1)), - ov::util::get_constant_from_source(create_gather(create_weights({1, 3, 1, 1}), {2, 1, 0}, 1)), - create_weights({1, 1, 1}), - create_weights({1}), - ov::util::get_constant_from_source(create_gather(create_weights({3, 1, 1}), {2, 1, 0}, 0)), - 255); + auto fq_weights = std::make_shared(create_gather(weights_const, {2, 1, 0}, 1), + create_gather(create_weights({1, 3, 1, 1}), {2, 1, 0}, 1), + create_weights({1, 1, 1}), + create_weights({1}), + create_gather(create_weights({3, 1, 1}), {2, 1, 0}, 0), + 255); auto conv = create_conv(fq, fq_weights); model_ref = std::make_shared(NodeVector{conv}, ParameterVector{input}); @@ -599,21 +613,21 @@ TEST_F(TransformationTestsF, RICFusionFQOnTheWay3) { auto conv = create_conv(gconv, {6, 3, 1, 1}); model = std::make_shared(NodeVector{conv}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto input = create_param({1, 3, 64, 64}); auto fq = create_fq(input); auto weights_const = create_weights({3, 1, 1, 3, 3}); - auto fq_weights = std::make_shared( - ov::util::get_constant_from_source(create_gather(weights_const, {2, 1, 0}, 0)), - ov::util::get_constant_from_source(create_gather(create_weights({3, 1, 1, 1, 1}), {2, 1, 0}, 0)), - create_weights({1, 1, 1}), - create_weights({1}), - create_weights({1}), - 255); + auto fq_weights = std::make_shared(create_gather(weights_const, {2, 1, 0}, 0), + create_gather(create_weights({3, 1, 1, 1, 1}), {2, 1, 0}, 0), + create_weights({1, 1, 1}), + create_weights({1}), + create_weights({1}), + 255); auto gconv = create_group_conv(fq, fq_weights); auto conv = create_conv_with_gather(gconv, {6, 3, 1, 1}, {2, 1, 0}); @@ -632,8 +646,9 @@ TEST_F(TransformationTestsF, RICFusionShapeOf) { auto shape_of = std::make_shared(relu); model = std::make_shared(NodeVector{shape_of}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { @@ -874,9 +889,9 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiply) { CoordinateDiff{0, 0}, Strides{1, 1}); model = std::make_shared(conv, ParameterVector{parameter}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); } + manager.register_pass(); { auto parameter = std::make_shared(element::f32, Shape{1, 3, 14, 14}); std::shared_ptr activations = @@ -897,7 +912,7 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiply) { std::shared_ptr weights = opset8::Constant::create(element::i8, Shape{4, 3, 1, 1}, {-2}); { auto scale = opset8::Constant::create(element::f32, Shape{}, {0.2}); - auto gather = ov::util::get_constant_from_source(create_gather(weights, {2, 1, 0}, 1)); + auto gather = create_gather(weights, {2, 1, 0}, 1); auto convert = std::make_shared(gather, element::f32); auto multiply = std::make_shared(convert, scale); weights = multiply; @@ -932,16 +947,16 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiplyGroupConv) { auto relu = std::make_shared(group_conv); auto conv = create_conv(relu, {6, 9, 3, 3}); model = std::make_shared(NodeVector{conv}, ParameterVector{data}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); } + manager.register_pass(); { auto data = std::make_shared(element::f32, data_shape); std::shared_ptr weights = opset8::Constant::create(element::f32, Shape{3, 3, 1, 4, 4}, {-2}); auto gather = create_gather(weights, {2, 1, 0}, 1); auto convert = std::make_shared(gather, element::f32); auto scale = opset8::Constant::create(element::f32, Shape{}, {0.2}); - auto multiply = ov::util::get_constant_from_source(std::make_shared(convert, scale)); + auto multiply = std::make_shared(convert, scale); auto group_conv = std::make_shared(data, multiply, @@ -952,7 +967,7 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiplyGroupConv) { op::PadType::EXPLICIT); auto relu = std::make_shared(group_conv); std::shared_ptr weights2 = opset8::Constant::create(element::f32, Shape{6, 9, 3, 3}, {-2}); - auto gather2 = ov::util::get_constant_from_source(create_gather(weights2, {6, 7, 8, 3, 4, 5, 0, 1, 2}, 1)); + auto gather2 = create_gather(weights2, {6, 7, 8, 3, 4, 5, 0, 1, 2}, 1); auto conv = std::make_shared(relu, gather2, ov::Strides{1, 1}, @@ -997,9 +1012,9 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiplyNegative1) { CoordinateDiff{0, 0}, Strides{1, 1}); model = std::make_shared(conv, ParameterVector{parameter}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); } + manager.register_pass(); { auto parameter = std::make_shared(element::f32, Shape{1, 3, 14, 14}); std::shared_ptr activations = @@ -1019,7 +1034,7 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiplyNegative1) { std::shared_ptr weights = opset8::Constant::create(element::i8, Shape{4, 3, 1, 1}, {-2}); { - auto gather = ov::util::get_constant_from_source(create_gather(weights, {2, 1, 0}, 1)); + auto gather = create_gather(weights, {2, 1, 0}, 1); auto convert = std::make_shared(gather, element::f32); auto scale = opset8::Constant::create(element::f32, Shape{1, 1, 1, 1}, {0.2}); auto multiply = std::make_shared(convert, scale); @@ -1070,9 +1085,9 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiplyNegativeBroadcast) { CoordinateDiff{0, 0}, Strides{1, 1}); model = std::make_shared(conv, ParameterVector{parameter}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); } + manager.register_pass(); { auto parameter = std::make_shared(element::f32, Shape{1, 3, 14, 14}); std::shared_ptr activations = @@ -1092,10 +1107,10 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiplyNegativeBroadcast) { std::shared_ptr weights = opset8::Constant::create(element::i8, Shape{3, 1, 1}, {-2}); { - auto gather = ov::util::get_constant_from_source(create_gather(weights, {2, 1, 0}, 0)); + auto gather = create_gather(weights, {2, 1, 0}, 0); auto convert = std::make_shared(gather, element::f32); auto scale = opset8::Constant::create(element::f32, Shape{4, 3, 1, 1}, {0.2}); - auto gather2 = ov::util::get_constant_from_source(create_gather(scale, {2, 1, 0}, 1)); + auto gather2 = create_gather(scale, {2, 1, 0}, 1); auto multiply = std::make_shared(convert, gather2); weights = multiply; } @@ -1169,16 +1184,16 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiplyNonScalarFQInput) { CoordinateDiff{0, 0}, Strides{1, 1}); model = std::make_shared(conv, ParameterVector{parameter}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); } + manager.register_pass(); { auto parameter = std::make_shared(element::f32, Shape{1, 3, 14, 14}); auto gather = create_gather(std::make_shared(element::f32, Shape{1, 3, 14, 14}), {2, 1, 0}, 1); std::shared_ptr activations = std::make_shared(parameter, - ov::util::get_constant_from_source(gather), + gather, opset8::Constant::create(element::f32, Shape{}, {20}), opset8::Constant::create(element::f32, Shape{}, {0}), opset8::Constant::create(element::f32, Shape{}, {254}), @@ -1194,7 +1209,7 @@ TEST_F(TransformationTestsF, RICFusionConvertMultiplyNonScalarFQInput) { std::shared_ptr weights = opset8::Constant::create(element::i8, Shape{4, 3, 1, 1}, {-2}); { auto scale = opset8::Constant::create(element::f32, Shape{}, {0.2}); - auto gather = ov::util::get_constant_from_source(create_gather(weights, {2, 1, 0}, 1)); + gather = create_gather(weights, {2, 1, 0}, 1); auto convert = std::make_shared(gather, element::f32); auto multiply = std::make_shared(convert, scale); weights = multiply; @@ -1255,8 +1270,9 @@ TEST_F(TransformationTestsF, RICFusionTwoConvolutions) { auto conv1 = create_conv(input, create_weights({3, 3, 1, 1})); auto conv2 = create_conv(conv1, create_weights({3, 3, 1, 1})); model = std::make_shared(NodeVector{conv2}, ParameterVector{input}); - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto conv1_with_gather = create_conv_with_gather(input, create_weights({3, 3, 1, 1}), {2, 1, 0}); @@ -1273,9 +1289,9 @@ TEST_F(TransformationTestsF, RICFusionTwoConvolutionsTheSameWeights) { auto conv1 = create_conv(input, weights); auto conv2 = create_conv(conv1, weights); model = std::make_shared(NodeVector{conv2}, ParameterVector{input}); - - // ReverseInputChannelsFusion is expected to be applied inside PrePostProcessing apply_reverse_input_channels(model, {{0, "NCHW"}}); + + manager.register_pass(); } { auto conv1_with_gather = create_conv_with_gather(input, weights, {2, 1, 0}); diff --git a/src/core/src/pass/constant_folding.cpp b/src/core/src/pass/constant_folding.cpp index 467898e9f6cc5a..ae8d74e737ccf0 100644 --- a/src/core/src/pass/constant_folding.cpp +++ b/src/core/src/pass/constant_folding.cpp @@ -14,8 +14,6 @@ #include "openvino/op/util/read_value_base.hpp" #include "openvino/op/util/shape_of_base.hpp" #include "openvino/op/util/sub_graph_base.hpp" -#include "transformations/rt_info/decompression.hpp" -#include "transformations/rt_info/dequantization_node.hpp" /** * \brief Check if \ref ov::Output can be folded base on `can_be_folded` attribute. @@ -53,7 +51,7 @@ const auto friendly_name_from = [](const ov::Node& node, const size_t output_cou static bool restore_original_input_precision(const std::shared_ptr& node) { bool restored = false; - if (ov::is_type(node) && !is_decompression(node) && !is_dequantization_node(node)) { + if (ov::is_type(node)) { auto input = node->input(0); ov::util::remove_original_input_precision_attribute(input); return restored; diff --git a/src/core/src/preprocess/pre_post_process.cpp b/src/core/src/preprocess/pre_post_process.cpp index 32c22eae779968..a74eb8bc5ad835 100644 --- a/src/core/src/preprocess/pre_post_process.cpp +++ b/src/core/src/preprocess/pre_post_process.cpp @@ -6,102 +6,9 @@ #include "color_utils.hpp" #include "function_guard.hpp" -#include "itt.hpp" #include "layout_utils.hpp" #include "openvino/core/model.hpp" -#include "openvino/pass/constant_folding.hpp" -#include "openvino/pass/manager.hpp" -#include "openvino/pass/pattern/op/true.hpp" #include "preprocess_impls.hpp" -#include "transformations/common_optimizations/convolution_to_group_convolution_fusion.hpp" -#include "transformations/common_optimizations/disable_random_uniform_constant_folding.hpp" -#include "transformations/common_optimizations/disable_shapeof_constant_folding.hpp" -#include "transformations/common_optimizations/mul_conv_fusion.hpp" -#include "transformations/common_optimizations/ric_fusion.hpp" -#include "transformations/fp16_compression/mark_decompression_convert_constant_folding.hpp" -#include "transformations/low_precision/mark_dequantization_subgraph.hpp" -#include "transformations/op_conversions/convert_divide.hpp" -#include "transformations/rt_info/dequantization_node.hpp" -#include "transformations/utils/utils.hpp" - -namespace { - -struct RTInfoCache { - template - void traverse(const std::shared_ptr& model, Func&& func) { - for (const auto& op : model->get_ordered_ops()) { - func(op); - if (const auto& multi_subgraph_op = ov::as_type_ptr(op)) { - for (const auto& sub_graph : multi_subgraph_op->get_functions()) { - if (sub_graph) - traverse(sub_graph, func); - } - } - } - } - - void store(const std::shared_ptr& model) { - traverse(model, [this](const std::shared_ptr& op) { - m_rt_info_cache[op.get()] = op->get_rt_info(); - }); - } - - void restore(const std::shared_ptr& model) { - traverse(model, [this](const std::shared_ptr& op) { - auto it = m_rt_info_cache.find(op.get()); - if (it != m_rt_info_cache.end()) { - op->get_rt_info() = it->second; - } else { - ov::pass::enable_constant_folding(op); - ov::unmark_dequantization_node(op); - ov::unmark_as_decompression(op); - } - }); - } - - std::unordered_map m_rt_info_cache; -}; - -void transformation_pipeline(std::shared_ptr& model) { - using namespace ov; - using namespace ov::pass; - using namespace ov::element; - - // 0. Store RT info to not affect plugin compilation - RTInfoCache rt_info_cache; - rt_info_cache.store(model); - - Manager manager("pre_post_processing"); - manager.set_per_pass_validation(false); - - // 1. Set "disable_const_folding" attribute - REGISTER_PASS(manager, MarkDequantization, TypeVector{i8, u8, i4, u4, nf4, f4e2m1, f8e4m3, f8e5m2, f8e8m0}); - REGISTER_PASS(manager, DisableShapeOfConstantFolding, false); - REGISTER_PASS(manager, DisableRandomUniformConstantFolding) - // Mark quantized and f16/bf16 compressed constants to prevent CF for them, - // so that not extra memory is used for intermediate decompressed constants. - REGISTER_PASS(manager, MarkCompressedFloatConstants); - REGISTER_PASS(manager, DisableDecompressionConvertConstantFolding); - - // 2. Fusion transformations: - REGISTER_PASS(manager, ConvertDivideWithConstant) - auto multiply_fusions = manager.register_pass(); - ADD_MATCHER(multiply_fusions, MultiplyConvolutionFusion) - ADD_MATCHER(multiply_fusions, MultiplyGroupConvolutionFusion) - ADD_MATCHER(multiply_fusions, MultiplyConvolutionBackpropDataFusion) - ADD_MATCHER(multiply_fusions, MultiplyGroupConvolutionBackpropDataFusion) - multiply_fusions->set_name("ov::pass::MultiplyFusions"); - REGISTER_PASS(manager, ReverseInputChannelsFusion) - - // 3. CF call due to detected perf degradations - REGISTER_PASS(manager, ConstantFolding) - manager.run_passes(model); - - // 4. Restore old RT info to not affect plugin compilation - rt_info_cache.restore(model); -} - -} // namespace namespace ov { namespace preprocess { @@ -294,18 +201,6 @@ std::shared_ptr PrePostProcessor::build() { function->remove_result(*function->get_results().begin()); function->add_results(results); - // After switching from ModelOptimizer to OVC, the order of - // applying PrePostProcessing and MOCTransformations has changed: - // - // MO path : [fw model conversion -> PrePostProcessing -> MOC] -> nncf - // OVC path: [fw model conversion -> MOC] -> PrePostProcessing -> nncf - // - // Since nncf is applied to a not fully optimized model, extra FQ ops might appear, - // which can affect both accuracy and performance. - // PrePostProcessing is not part of OVC, so we have to insert an additional - // Transformation calls inside PrePostProcessing. - transformation_pipeline(function); - guard.reset(); return function; } diff --git a/src/core/tests/preprocess.cpp b/src/core/tests/preprocess.cpp index 3c70e9386a89a6..fe6fa1e91a4589 100644 --- a/src/core/tests/preprocess.cpp +++ b/src/core/tests/preprocess.cpp @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "common_test_utils/ov_test_utils.hpp" #include "common_test_utils/test_assertions.hpp" #include "common_test_utils/test_tools.hpp" #include "gtest/gtest.h" @@ -38,24 +37,6 @@ static std::shared_ptr create_trivial(element::Type type, const PartialSh return std::make_shared(ResultVector{res}, ParameterVector{data1}); } -static std::shared_ptr create_conv(element::Type in_type, const PartialShape& shape, element::Type weight_type) { - auto data1 = std::make_shared(in_type, shape); - data1->set_friendly_name("input1"); - data1->get_output_tensor(0).set_names({"tensor_input1"}); - - std::shared_ptr weights = std::make_shared(weight_type, ov::Shape{1, 3, 3, 3}, 1); - if (weight_type == element::f16) { - // decompression subgraph - weights = std::make_shared(weights, element::f32); - } - auto conv = - std::make_shared(data1, weights, Strides{}, CoordinateDiff{}, CoordinateDiff{}, Strides{}); - auto res = std::make_shared(conv); - res->set_friendly_name("Result1"); - res->get_output_tensor(0).set_names({"tensor_output1"}); - return std::make_shared(ResultVector{res}, ParameterVector{data1}); -} - template static std::shared_ptr create_n_inputs(element::Type type, const PartialShape& shape) { ResultVector res; @@ -2445,62 +2426,3 @@ TEST(pre_post_process, dump_error) { auto dump = stream.str(); EXPECT_TRUE(dump.find("Error occurred:") != std::string::npos) << dump; } - -TEST_F(TransformationTestsF, preprocessing_mul_conv_fusion) { - auto in_shape = Shape{1, 3, 32, 32}; - auto in_type = element::f32; - auto weight_type = element::f32; - { - auto f = create_conv(in_type, in_shape, weight_type); - auto p = PrePostProcessor(f); - - p.input().tensor().set_layout(Layout("NCHW")); - p.input().preprocess().reverse_channels(); - p.input().preprocess().scale(255.); - model = p.build(); - } - - { - // we expect that MultiplyConvolutionFusion will be applied - auto input = std::make_shared(in_type, in_shape); - - auto weights = op::v0::Constant::create(element::f32, ov::Shape({1, 3, 3, 3}), {0.003922f}); - auto conv = std::make_shared(input, - weights, - Strides{}, - CoordinateDiff{}, - CoordinateDiff{}, - Strides{}); - auto res = std::make_shared(conv); - model_ref = std::make_shared(ResultVector{res}, ParameterVector{input}); - } -} - -TEST_F(TransformationTestsF, preprocessing_conv_decompression) { - auto in_shape = Shape{1, 3, 32, 32}; - auto in_type = element::f32; - auto weight_type = element::f16; - { - auto f = create_conv(in_type, in_shape, weight_type); - auto p = PrePostProcessor(f); - - p.input().tensor().set_layout(Layout("NCHW")); - p.input().preprocess().reverse_channels(); - p.input().preprocess().scale(255.); - model = p.build(); - } - - { - // we expect that MultiplyConvolutionFusion will be applied - auto input = std::make_shared(in_type, in_shape); - - auto weights = op::v0::Constant::create(weight_type, ov::Shape({1, 3, 3, 3}), {1.f}); - auto convert = std::make_shared(weights, element::f32); - auto B = op::v0::Constant::create(in_type, ov::Shape({1}), {0.003922f}); - auto mul = std::make_shared(convert, B); - auto conv = - std::make_shared(input, mul, Strides{}, CoordinateDiff{}, CoordinateDiff{}, Strides{}); - auto res = std::make_shared(conv); - model_ref = std::make_shared(ResultVector{res}, ParameterVector{input}); - } -}