From 9f8e886067b3566dde967c436c5cfb4d707868d0 Mon Sep 17 00:00:00 2001 From: "Kim, Eddy" Date: Fri, 31 Jan 2025 16:29:35 +0900 Subject: [PATCH 1/2] restore to use ConcatTransformation of LPT --- .../activations_scaling.hpp | 24 ----- .../activations_scaling.cpp | 87 ------------------- .../src/plugin/transformations_pipeline.cpp | 2 - 3 files changed, 113 deletions(-) diff --git a/src/common/transformations/include/transformations/common_optimizations/activations_scaling.hpp b/src/common/transformations/include/transformations/common_optimizations/activations_scaling.hpp index d8c96a1df542af..2c0ebf6b007a4e 100644 --- a/src/common/transformations/include/transformations/common_optimizations/activations_scaling.hpp +++ b/src/common/transformations/include/transformations/common_optimizations/activations_scaling.hpp @@ -18,7 +18,6 @@ namespace activations_scaling { class TRANSFORMATIONS_API ScaleDownSingleLayer; class TRANSFORMATIONS_API EliminateScalarMul; -class TRANSFORMATIONS_API MulConcatTransformation; class TRANSFORMATIONS_API MulShareTransformation; class TRANSFORMATIONS_API MoveDownScalarMul; @@ -56,29 +55,6 @@ class ov::pass::activations_scaling::EliminateScalarMul : public ov::pass::Match EliminateScalarMul(); }; -// input_a const_a input_b const_b input_c const_c -// \ / \ / \ / -// Multiply_a Multiply_b Multiply_c -// \ | / -// \ | / -// ---------- Concat ------------ -// ==> -// (const_a (const_b (const_c -// input_a /const_c) input_b /const_c) input_c /const_c) -// \ / \ / \ / -// Multiply_a Multiply_b Multiply_c -// \ | / -// \ | / -// ---------- Concat ------------ -// | const_c -// | / -// Multiply -class ov::pass::activations_scaling::MulConcatTransformation : public ov::pass::MatcherPass { -public: - OPENVINO_MATCHER_PASS_RTTI("MulConcatTransformation", "0"); - MulConcatTransformation(); -}; - // input input // / \ | // Norm Mul ==> Mul (expect to be fused into the input layer) diff --git a/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp b/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp index 7fd1a5a237fa3b..b9e8acaf34dd2d 100644 --- a/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp +++ b/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp @@ -10,7 +10,6 @@ #include "low_precision/network_helper.hpp" #include "openvino/core/rt_info.hpp" #include "openvino/op/add.hpp" -#include "openvino/op/concat.hpp" #include "openvino/op/constant.hpp" #include "openvino/op/convert.hpp" #include "openvino/op/convolution.hpp" @@ -212,92 +211,6 @@ ov::pass::activations_scaling::EliminateScalarMul::EliminateScalarMul() { this->register_matcher(m, callback); } -ov::pass::activations_scaling::MulConcatTransformation::MulConcatTransformation() { - MATCHER_SCOPE(MulConcatTransformation); - - auto concat_m = wrap_type(); - - ov::matcher_pass_callback callback = [=](pattern::Matcher& m) { - const auto& pattern_map = m.get_pattern_value_map(); - - OPENVINO_ASSERT(pattern_map.count(concat_m), "Not found any Concat layer"); - - auto concat = pattern_map.at(concat_m).get_node_shared_ptr(); - - if (transformation_callback(concat)) { - return false; - } - - // check if all inputs are Multiply with scalar operand - ov::Output last_dep_const = {}; - ov::element::Type last_dep_const_type = ov::element::undefined; - for (auto& input : concat->inputs()) { - auto dep_node = ov::as_type_ptr(input.get_source_output().get_node_shared_ptr()); - if (!dep_node) { - return false; - } - auto dep_const0 = - ov::as_type_ptr(dep_node->input(0).get_source_output().get_node_shared_ptr()); - auto dep_const1 = - ov::as_type_ptr(dep_node->input(1).get_source_output().get_node_shared_ptr()); - if (!dep_const0 && !dep_const1) { - return false; - } - last_dep_const = - dep_const0 ? dep_node->input(0).get_source_output() : dep_node->input(1).get_source_output(); - if (!is_scalar_node(last_dep_const)) - return false; - if (last_dep_const_type != ov::element::undefined && - last_dep_const_type != last_dep_const.get_element_type()) - return false; - last_dep_const_type = last_dep_const.get_element_type(); - } - - auto target_inputs = concat->get_output_target_inputs(0); - - for (auto& input : concat->inputs()) { - auto dep_node = input.get_source_output().get_node_shared_ptr(); - auto dep_input0 = dep_node->input(0).get_source_output().get_node(); - size_t const_index = ov::is_type(dep_input0) ? 0 : 1; - size_t activation_index = ov::is_type(dep_input0) ? 1 : 0; - - auto dep_type = dep_node->get_output_element_type(0); - auto new_mul = std::make_shared>( - std::vector{dep_type, dep_type}, - std::vector{dep_type}, - ov::op::TemporaryReplaceOutputType(dep_node->input(activation_index).get_source_output(), dep_type) - .get(), - ov::op::TemporaryReplaceOutputType( - ov::op::util::eltwise_fold(dep_node->input(const_index).get_source_output(), - last_dep_const), - dep_type) - .get()); - new_mul->set_friendly_name(dep_node->get_friendly_name() + "_c"); - ov::copy_runtime_info(dep_node, new_mul); - - input.replace_source_output(new_mul); - } - - auto concat_type = concat->get_output_element_type(0); - auto new_mul = std::make_shared>( - std::vector{concat_type, concat_type}, - std::vector{concat_type}, - ov::op::TemporaryReplaceOutputType(concat->output(0), concat_type).get(), - ov::op::TemporaryReplaceOutputType(last_dep_const, concat_type).get()); - new_mul->set_friendly_name(concat->get_friendly_name() + "_c"); - ov::copy_runtime_info(concat, new_mul); - - for (auto& in : target_inputs) { - in.replace_source_output(new_mul); - } - - return true; - }; - - auto m = std::make_shared(concat_m, "MulConcatTransformation"); - this->register_matcher(m, callback); -} - ov::pass::activations_scaling::MulShareTransformation::MulShareTransformation() { MATCHER_SCOPE(MulShareTransformation); diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp index f036afc0cd59ad..260b807392c40e 100644 --- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp +++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp @@ -942,7 +942,6 @@ void TransformationsPipeline::apply(std::shared_ptr func) { pass_config->disable(); pass_config->disable(); pass_config->disable(); - pass_config->disable(); pass_config->set_callback( [](const std::shared_ptr &node) -> bool { @@ -961,7 +960,6 @@ void TransformationsPipeline::apply(std::shared_ptr func) { auto params = LayerTransformation::Params(false, infer_precision, {infer_precision}, true, true); auto lpt_pass = manager.register_pass(supportedPrecisions, perTensorQuantization, params); lpt_pass->add_main(); - lpt_pass->add_main(); lpt_pass->add_main(); // Move up remained scalar-multiply layers From 68271596552bfeed8d1bcfdc42a866137a4b68ca Mon Sep 17 00:00:00 2001 From: "Kim, Eddy" Date: Fri, 31 Jan 2025 16:48:56 +0900 Subject: [PATCH 2/2] removed unnecessary unit test --- .../activations_scaling_test.cpp | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp b/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp index a8797b588c31cf..4264c4e3620fb8 100644 --- a/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp +++ b/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp @@ -12,7 +12,6 @@ #include "common_test_utils/graph_comparator.hpp" #include "common_test_utils/ov_test_utils.hpp" #include "openvino/op/add.hpp" -#include "openvino/op/concat.hpp" #include "openvino/op/constant.hpp" #include "openvino/op/convolution.hpp" #include "openvino/op/group_normalization.hpp" @@ -98,38 +97,6 @@ TEST_F(TransformationTestsF, EliminateScalarMulTest) { } } -TEST_F(TransformationTestsF, ConcatTransformationTest) { - { - auto input0 = std::make_shared(ov::element::f16, ov::PartialShape{6, 12, 10, 24}); - auto scale_const0 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10}); - auto mul0 = std::make_shared(input0, scale_const0); - auto input1 = std::make_shared(ov::element::f16, ov::PartialShape{6, 12, 10, 24}); - auto scale_const1 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10}); - auto mul1 = std::make_shared(input1, scale_const1); - auto concat = std::make_shared(OutputVector{mul0, mul1}, 0); - auto convert = std::make_shared(concat, ov::element::f32); - auto result = std::make_shared(convert); - - model = std::make_shared(ov::ResultVector{result}, ov::ParameterVector{input0, input1}); - manager.register_pass(); - } - { - auto input0 = std::make_shared(ov::element::f16, ov::PartialShape{6, 12, 10, 24}); - auto scale_const0 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {1}); - auto mul0 = std::make_shared(input0, scale_const0); - auto input1 = std::make_shared(ov::element::f16, ov::PartialShape{6, 12, 10, 24}); - auto scale_const1 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {1}); - auto mul1 = std::make_shared(input1, scale_const1); - auto concat = std::make_shared(OutputVector{mul0, mul1}, 0); - auto new_scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10}); - auto new_mul = std::make_shared(concat, new_scale_const); - auto convert = std::make_shared(new_mul, ov::element::f32); - auto result = std::make_shared(convert); - - model_ref = std::make_shared(ov::ResultVector{result}, ov::ParameterVector{input0, input1}); - } -} - TEST_F(TransformationTestsF, MoveDownScalarMulTest) { { auto input0 = std::make_shared(ov::element::f16, ov::PartialShape{6, 12, 10, 24});