OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
Remove using namespace ov::op and ov::pass::pattern directives to fix UNITY build conflicts (#33134)
Evgeny Kotov7859e2613fd4
diff --git a/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp b/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cppindex 12c0c74c636..72bd0f02e5c 100644--- a/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/activations_scaling.cpp@@ -32,6 +32,14 @@#include "transformations/common_optimizations/lin_op_sequence_fusion.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v6 = ov::op::v6;+namespace v12 = ov::op::v12;++namespace ov::pass {+namespace {const auto is_scalar_node = [](const ov::Output<ov::Node>& output) -> bool {const auto shape = output.get_partial_shape();@@ -41,23 +49,18 @@ const auto is_scalar_node = [](const ov::Output<ov::Node>& output) -> bool {};const auto is_non_const_node = [](const ov::Output<ov::Node>& output) -> bool {- return !ov::is_type<ov::op::v0::Constant>(output.get_node());+ return !ov::is_type<v0::Constant>(output.get_node());};} // namespace-using namespace ov::pass::activations_scaling;-using namespace ov::pass::pattern;-using ov::pass::pattern::op::Or;--ov::pass::activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(float scale_factor,- ov::element::Type scaled_prec) {+activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(float scale_factor, ov::element::Type scaled_prec) {MATCHER_SCOPE(ScaleDownSingleLayer);- auto activation_m = any_input();- auto weights_m = any_input();- auto convolution_m = wrap_type<ov::op::v1::Convolution>({activation_m, weights_m});- auto matmul_m = wrap_type<ov::op::v0::MatMul>({activation_m, weights_m});- auto scaled_op_m = std::make_shared<Or>(OutputVector{convolution_m, matmul_m});+ auto activation_m = pattern::any_input();+ auto weights_m = pattern::any_input();+ auto convolution_m = pattern::wrap_type<v1::Convolution>({activation_m, weights_m});+ auto matmul_m = pattern::wrap_type<v0::MatMul>({activation_m, weights_m});+ auto scaled_op_m = std::make_shared<pattern::op::Or>(OutputVector{convolution_m, matmul_m});ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -69,16 +72,16 @@ ov::pass::activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(floatconst size_t input_idx) {const std::vector<float> scale_down_value = {1.f / scale_factor};- auto scale_down_layer = std::make_shared<ov::op::v1::Multiply>(- node->input(input_idx).get_source_output(),- std::make_shared<ov::op::v0::Constant>(node->input(input_idx).get_element_type(),- ov::Shape(),- scale_down_value));+ auto scale_down_layer =+ std::make_shared<v1::Multiply>(node->input(input_idx).get_source_output(),+ std::make_shared<v0::Constant>(node->input(input_idx).get_element_type(),+ ov::Shape(),+ scale_down_value));scale_down_layer->set_friendly_name(node->get_friendly_name() + "_scale_down");ov::copy_runtime_info(node, scale_down_layer);if (scale_down_layer->output(0).get_element_type() != scaled_prec) {- auto convert_prec = std::make_shared<ov::op::v0::Convert>(scale_down_layer->output(0), scaled_prec);+ auto convert_prec = std::make_shared<v0::Convert>(scale_down_layer->output(0), scaled_prec);node->input(input_idx).replace_source_output(convert_prec->output(0));} else {node->input(input_idx).replace_source_output(scale_down_layer->output(0));@@ -100,9 +103,9 @@ ov::pass::activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(float// in the case of decompressed_to_f32 nodes, no need to apply activations scalingstd::shared_ptr<ov::Node> output_of_scaled_op = scaled_op;auto child_node = scaled_op->get_output_target_inputs(0).begin()->get_node();- if (scaled_op->get_output_target_inputs(0).size() == 1 && ov::is_type<ov::op::v0::Convert>(child_node) &&+ if (scaled_op->get_output_target_inputs(0).size() == 1 && ov::is_type<v0::Convert>(child_node) &&ov::fp16_compression_is_disabled(child_node->shared_from_this()) &&- ov::pass::constant_folding_is_disabled(child_node->shared_from_this())) {+ constant_folding_is_disabled(child_node->shared_from_this())) {return false;}@@ -112,8 +115,7 @@ ov::pass::activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(float// adding a scale_down layer before the target nodeinsert_scale_down_layer(scaled_op, 0);if (scaled_op->input(1).get_element_type() != scaled_prec) {- auto convert_prec1 =- std::make_shared<ov::op::v0::Convert>(scaled_op->input(1).get_source_output(), scaled_prec);+ auto convert_prec1 = std::make_shared<v0::Convert>(scaled_op->input(1).get_source_output(), scaled_prec);scaled_op->input(1).replace_source_output(convert_prec1->output(0));}@@ -126,7 +128,7 @@ ov::pass::activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(floatbool has_bias = false;size_t bias_index = 1;{- if (scaled_op->get_output_target_inputs(0).size() == 1 && ov::is_type<ov::op::v1::Add>(child_node)) {+ if (scaled_op->get_output_target_inputs(0).size() == 1 && ov::is_type<v1::Add>(child_node)) {bias_index = (child_node->get_input_node_shared_ptr(0) == scaled_op) ? 1 : 0;const auto& bias_pshape = child_node->get_input_partial_shape(bias_index);if (bias_pshape.is_static()) {@@ -147,23 +149,22 @@ ov::pass::activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(floatinsert_scale_down_layer(add, bias_index);add->revalidate_and_infer_types();if (add->output(0).get_element_type() != output_prec) {- output_of_scaled_op = std::make_shared<ov::op::v0::Convert>(add->output(0), output_prec);+ output_of_scaled_op = std::make_shared<v0::Convert>(add->output(0), output_prec);} else {output_of_scaled_op = add;}} else {target_inputs = output_of_scaled_op->get_output_target_inputs(0);if (output_of_scaled_op->output(0).get_element_type() != output_prec) {- output_of_scaled_op =- std::make_shared<ov::op::v0::Convert>(output_of_scaled_op->output(0), output_prec);+ output_of_scaled_op = std::make_shared<v0::Convert>(output_of_scaled_op->output(0), output_prec);}}- auto scale_up = register_new_node<ov::op::v1::Multiply>(+ auto scale_up = register_new_node<v1::Multiply>(output_of_scaled_op->output(0),- std::make_shared<ov::op::v0::Constant>(output_of_scaled_op->output(0).get_element_type(),- ov::Shape(),- scale_up_value));+ std::make_shared<v0::Constant>(output_of_scaled_op->output(0).get_element_type(),+ ov::Shape(),+ scale_up_value));scale_up->set_friendly_name(scaled_op->get_friendly_name() + "_scale_up");ov::copy_runtime_info(scaled_op, scale_up);for (auto& in : target_inputs) {@@ -173,22 +174,23 @@ ov::pass::activations_scaling::ScaleDownSingleLayer::ScaleDownSingleLayer(floatreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(scaled_op_m, "ScaleDownSingleLayer");+ auto m = std::make_shared<pattern::Matcher>(scaled_op_m, "ScaleDownSingleLayer");this->register_matcher(m, callback);}-ov::pass::activations_scaling::EliminateScalarMul::EliminateScalarMul() {+activations_scaling::EliminateScalarMul::EliminateScalarMul() {MATCHER_SCOPE(EliminateScalarMul);- auto activation_m = any_input(is_non_const_node);- auto convert_m = ov::pass::pattern::optional<ov::op::v0::Convert>(activation_m);- auto scale_const_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(is_scalar_node);- auto mul_m = wrap_type<ov::op::v1::Multiply>({convert_m, scale_const_m});- auto mvn_m = wrap_type<ov::op::v6::MVN>({mul_m, any_input()});- auto rms_m = wrap_type<ov::op::internal::RMS>({mul_m, any_input()});- auto group_norm_m = wrap_type<ov::op::v12::GroupNormalization>({mul_m, any_input(), any_input()});- auto shape_of_m = wrap_type<ov::op::v3::ShapeOf>({mul_m});- auto norm_m = std::make_shared<Or>(OutputVector{mvn_m, rms_m, group_norm_m, shape_of_m});+ auto activation_m = pattern::any_input(is_non_const_node);+ auto convert_m = pattern::optional<v0::Convert>(activation_m);+ auto scale_const_m = pattern::wrap_type<v0::Constant>(is_scalar_node);+ auto mul_m = pattern::wrap_type<v1::Multiply>({convert_m, scale_const_m});+ auto mvn_m = pattern::wrap_type<v6::MVN>({mul_m, pattern::any_input()});+ auto rms_m = pattern::wrap_type<ov::op::internal::RMS>({mul_m, pattern::any_input()});+ auto group_norm_m =+ pattern::wrap_type<v12::GroupNormalization>({mul_m, pattern::any_input(), pattern::any_input()});+ auto shape_of_m = pattern::wrap_type<v3::ShapeOf>({mul_m});+ auto norm_m = std::make_shared<pattern::op::Or>(OutputVector{mvn_m, rms_m, group_norm_m, shape_of_m});ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -197,7 +199,7 @@ ov::pass::activations_scaling::EliminateScalarMul::EliminateScalarMul() {return false;}- auto scale_const = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(scale_const_m).get_node_shared_ptr());+ auto scale_const = ov::as_type_ptr<v0::Constant>(pattern_map.at(scale_const_m).get_node_shared_ptr());if (pattern_map.count(shape_of_m) == 0 && scale_const->cast_vector<float>()[0] < 1.f)return false;@@ -214,12 +216,12 @@ ov::pass::activations_scaling::EliminateScalarMul::EliminateScalarMul() {rms->set_epsilon(eps / scale_const_val / scale_const_val);} else if (pattern_map.count(group_norm_m)) {auto group_norm =- ov::as_type_ptr<ov::op::v12::GroupNormalization>(pattern_map.at(group_norm_m).get_node_shared_ptr());+ ov::as_type_ptr<v12::GroupNormalization>(pattern_map.at(group_norm_m).get_node_shared_ptr());auto eps = group_norm->get_epsilon();double scale_const_val = scale_const->cast_vector<double>()[0];group_norm->set_epsilon(eps / scale_const_val / scale_const_val);} else if (pattern_map.count(mvn_m)) {- auto mvn = ov::as_type_ptr<ov::op::v6::MVN>(pattern_map.at(mvn_m).get_node_shared_ptr());+ auto mvn = ov::as_type_ptr<v6::MVN>(pattern_map.at(mvn_m).get_node_shared_ptr());auto eps_mode = mvn->get_eps_mode();auto eps = mvn->get_eps();float scale_const_val = scale_const->cast_vector<float>()[0];@@ -233,18 +235,19 @@ ov::pass::activations_scaling::EliminateScalarMul::EliminateScalarMul() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(norm_m, "EliminateScalarMul");+ auto m = std::make_shared<pattern::Matcher>(norm_m, "EliminateScalarMul");this->register_matcher(m, callback);}-ov::pass::activations_scaling::MulShareTransformation::MulShareTransformation() {+activations_scaling::MulShareTransformation::MulShareTransformation() {MATCHER_SCOPE(MulShareTransformation);- auto mvn_m = wrap_type<ov::op::v6::MVN>({any_input(), any_input()});- auto rms_m = wrap_type<ov::op::internal::RMS>({any_input(), any_input()});- auto group_norm_m = wrap_type<ov::op::v12::GroupNormalization>({any_input(), any_input(), any_input()});- auto shape_of_m = wrap_type<ov::op::v3::ShapeOf>({any_input()});- auto norm_m = std::make_shared<Or>(OutputVector{mvn_m, rms_m, group_norm_m, shape_of_m});+ auto mvn_m = pattern::wrap_type<v6::MVN>({pattern::any_input(), pattern::any_input()});+ auto rms_m = pattern::wrap_type<ov::op::internal::RMS>({pattern::any_input(), pattern::any_input()});+ auto group_norm_m =+ pattern::wrap_type<v12::GroupNormalization>({pattern::any_input(), pattern::any_input(), pattern::any_input()});+ auto shape_of_m = pattern::wrap_type<v3::ShapeOf>({pattern::any_input()});+ auto norm_m = std::make_shared<pattern::op::Or>(OutputVector{mvn_m, rms_m, group_norm_m, shape_of_m});ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -263,7 +266,7 @@ ov::pass::activations_scaling::MulShareTransformation::MulShareTransformation()if (child == norm->input(0))continue;- if (ov::is_type<ov::op::v1::Multiply>(child.get_node())) {+ if (ov::is_type<v1::Multiply>(child.get_node())) {ov::Output<ov::Node> const_input;for (auto input : child.get_node()->input_values()) {if (input == parent_output)@@ -274,7 +277,7 @@ ov::pass::activations_scaling::MulShareTransformation::MulShareTransformation()if (is_scalar_node(const_input) && !is_non_const_node(const_input)) {norm->input(0).replace_source_output(child.get_node()->output(0));- auto scale_const = ov::as_type_ptr<ov::op::v0::Constant>(const_input.get_node_shared_ptr());+ auto scale_const = ov::as_type_ptr<v0::Constant>(const_input.get_node_shared_ptr());if (pattern_map.count(rms_m)) {auto rms = ov::as_type_ptr<ov::op::internal::RMS>(pattern_map.at(rms_m).get_node_shared_ptr());@@ -282,13 +285,13 @@ ov::pass::activations_scaling::MulShareTransformation::MulShareTransformation()double scale_const_val = scale_const->cast_vector<double>()[0];rms->set_epsilon(eps * scale_const_val * scale_const_val);} else if (pattern_map.count(group_norm_m)) {- auto group_norm = ov::as_type_ptr<ov::op::v12::GroupNormalization>(+ auto group_norm = ov::as_type_ptr<v12::GroupNormalization>(pattern_map.at(group_norm_m).get_node_shared_ptr());auto eps = group_norm->get_epsilon();double scale_const_val = scale_const->cast_vector<double>()[0];group_norm->set_epsilon(eps * scale_const_val * scale_const_val);} else if (pattern_map.count(mvn_m)) {- auto mvn = ov::as_type_ptr<ov::op::v6::MVN>(pattern_map.at(mvn_m).get_node_shared_ptr());+ auto mvn = ov::as_type_ptr<v6::MVN>(pattern_map.at(mvn_m).get_node_shared_ptr());auto eps_mode = mvn->get_eps_mode();auto eps = mvn->get_eps();float scale_const_val = scale_const->cast_vector<float>()[0];@@ -307,18 +310,18 @@ ov::pass::activations_scaling::MulShareTransformation::MulShareTransformation()return false;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(norm_m, "ScalarMulShareTransformation");+ auto m = std::make_shared<pattern::Matcher>(norm_m, "ScalarMulShareTransformation");this->register_matcher(m, callback);}-ov::pass::activations_scaling::MoveDownScalarMul::MoveDownScalarMul() {+activations_scaling::MoveDownScalarMul::MoveDownScalarMul() {MATCHER_SCOPE(MoveDownScalarMul);- auto activation_b_m = any_input(is_non_const_node);- auto mul_const_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(is_scalar_node);- auto mul_b_m = wrap_type<ov::op::v1::Multiply>({activation_b_m, mul_const_m});- auto activation_a_m = any_input(is_non_const_node);- auto mul_a_m = wrap_type<ov::op::v1::Multiply>({activation_a_m, mul_b_m});+ auto activation_b_m = pattern::any_input(is_non_const_node);+ auto mul_const_m = pattern::wrap_type<v0::Constant>(is_scalar_node);+ auto mul_b_m = pattern::wrap_type<v1::Multiply>({activation_b_m, mul_const_m});+ auto activation_a_m = pattern::any_input(is_non_const_node);+ auto mul_a_m = pattern::wrap_type<v1::Multiply>({activation_a_m, mul_b_m});ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -331,7 +334,7 @@ ov::pass::activations_scaling::MoveDownScalarMul::MoveDownScalarMul() {auto mul_b = pattern_map.at(mul_b_m).get_node_shared_ptr();auto output_type = mul_a->get_output_element_type(0);- auto new_mul_a = std::make_shared<ov::op::TypeRelaxed<ov::op::v1::Multiply>>(+ auto new_mul_a = std::make_shared<ov::op::TypeRelaxed<v1::Multiply>>(std::vector<element::Type>{output_type, output_type},std::vector<element::Type>{output_type},ov::op::TemporaryReplaceOutputType(pattern_map.at(activation_a_m), output_type).get(),@@ -339,7 +342,7 @@ ov::pass::activations_scaling::MoveDownScalarMul::MoveDownScalarMul() {new_mul_a->set_friendly_name(mul_a->get_friendly_name() + "_mm");ov::copy_runtime_info(mul_a, new_mul_a);- auto new_mul_b = std::make_shared<ov::op::TypeRelaxed<ov::op::v1::Multiply>>(+ auto new_mul_b = std::make_shared<ov::op::TypeRelaxed<v1::Multiply>>(std::vector<element::Type>{output_type, output_type},std::vector<element::Type>{output_type},ov::op::TemporaryReplaceOutputType(new_mul_a->output(0), output_type).get(),@@ -352,6 +355,8 @@ ov::pass::activations_scaling::MoveDownScalarMul::MoveDownScalarMul() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_a_m, "MoveDownScalarMul");+ auto m = std::make_shared<pattern::Matcher>(mul_a_m, "MoveDownScalarMul");this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/adaptive_pool_to_reduce.cpp b/src/common/transformations/src/transformations/common_optimizations/adaptive_pool_to_reduce.cppindex 35ca7176eef..e89e72e14af 100644--- a/src/common/transformations/src/transformations/common_optimizations/adaptive_pool_to_reduce.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/adaptive_pool_to_reduce.cpp@@ -17,9 +17,13 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::op;+namespace ov::pass {-ov::pass::AdaptivePoolToReduce::AdaptivePoolToReduce() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;++AdaptivePoolToReduce::AdaptivePoolToReduce() {MATCHER_SCOPE(AdaptivePoolToReduce);auto data_pattern = pattern::any_input();auto out_spatial_shape = pattern::wrap_type<v0::Constant>();@@ -58,6 +62,8 @@ ov::pass::AdaptivePoolToReduce::AdaptivePoolToReduce() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(a_pool, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(a_pool, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/add_fake_quantize_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/add_fake_quantize_fusion.cppindex 45b25f3f29a..0846ab5ef1c 100644--- a/src/common/transformations/src/transformations/common_optimizations/add_fake_quantize_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/add_fake_quantize_fusion.cpp@@ -23,34 +23,35 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {++AddFakeQuantizeFusion::AddFakeQuantizeFusion() {MATCHER_SCOPE(AddFakeQuantizeFusion);- auto input_pattern = pass::pattern::any_input();- auto const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Add>({input_pattern, const_pattern}, pattern::consumers_count(1));- auto fq_pattern = ov::pass::pattern::wrap_type<ov::op::v0::FakeQuantize>({add_pattern,- pass::pattern::any_input(),- pass::pattern::any_input(),- pass::pattern::any_input(),- pass::pattern::any_input()});+ auto input_pattern = pattern::any_input();+ auto const_pattern = pattern::wrap_type<v0::Constant>();+ auto add_pattern = pattern::wrap_type<v1::Add>({input_pattern, const_pattern}, pattern::consumers_count(1));+ auto fq_pattern = pattern::wrap_type<v0::FakeQuantize>(+ {add_pattern, pattern::any_input(), pattern::any_input(), pattern::any_input(), pattern::any_input()});matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_value_map = m.get_pattern_value_map();const auto& input = pattern_value_map.at(input_pattern);const auto& type = input.get_element_type();if (type.bitwidth() < element::f32.bitwidth())return false;- auto fq = ov::as_type_ptr<ov::op::v0::FakeQuantize>(pattern_value_map.at(fq_pattern).get_node_shared_ptr());+ auto fq = ov::as_type_ptr<v0::FakeQuantize>(pattern_value_map.at(fq_pattern).get_node_shared_ptr());if (!fq)return false;const auto& add_node = pattern_value_map.at(add_pattern).get_node_shared_ptr();- auto add_const =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_value_map.at(const_pattern).get_node_shared_ptr());+ auto add_const = ov::as_type_ptr<v0::Constant>(pattern_value_map.at(const_pattern).get_node_shared_ptr());if (!add_const)return false;auto const_shape = add_const->get_shape();- if (!ov::op::util::check_for_broadcast(input.get_partial_shape(), const_shape)) {+ if (!op_util::check_for_broadcast(input.get_partial_shape(), const_shape)) {// We can't eliminate Add if Constant input broadcasts another input shape because// when we reconnect input from Add to FQ won't broadcast given input, so it will result// in shape collision.@@ -63,9 +64,9 @@ ov::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() {if (!is_single_value) {float v;- is_single_value = ov::op::util::get_single_value(add_const, v);+ is_single_value = op_util::get_single_value(add_const, v);if (is_single_value) {- new_const = std::make_shared<ov::op::v0::Constant>(add_const->get_element_type(), Shape{1}, v);+ new_const = std::make_shared<v0::Constant>(add_const->get_element_type(), Shape{1}, v);}}@@ -78,9 +79,9 @@ ov::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() {if (diff > 0) {// Reshape constants like (C, 1, 1) to (1, C, 1, 1)const_shape.insert(const_shape.begin(), diff, 1);- new_const = std::make_shared<ov::op::v1::Reshape>(+ new_const = std::make_shared<v1::Reshape>(new_const,- ov::op::v0::Constant::create(element::u64, Shape{const_shape.size()}, const_shape),+ v0::Constant::create(element::u64, Shape{const_shape.size()}, const_shape),false);}@@ -96,11 +97,9 @@ ov::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() {bool add_parent_is_conv_or_mm =std::any_of(add_inputs.begin(), add_inputs.end(), [](const Output<Node>& node) -> bool {auto node_ptr = node.get_node();- return is_type<ov::op::v1::Convolution>(node_ptr) ||- is_type<ov::op::v1::GroupConvolution>(node_ptr) ||- is_type<ov::op::v1::ConvolutionBackpropData>(node_ptr) ||- is_type<ov::op::v1::GroupConvolutionBackpropData>(node_ptr) ||- is_type<ov::op::v0::MatMul>(node_ptr);+ return is_type<v1::Convolution>(node_ptr) || is_type<v1::GroupConvolution>(node_ptr) ||+ is_type<v1::ConvolutionBackpropData>(node_ptr) ||+ is_type<v1::GroupConvolutionBackpropData>(node_ptr) || is_type<v0::MatMul>(node_ptr);});if (add_parent_is_conv_or_mm)return false;@@ -108,17 +107,17 @@ ov::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() {// Concat LPT transformation supports per tensor quantization onlybool fq_user_is_concat =std::any_of(fq_users.begin(), fq_users.end(), [](const std::shared_ptr<Node> node_ptr) -> bool {- return is_type<ov::op::v0::Concat>(node_ptr);+ return is_type<v0::Concat>(node_ptr);});if (fq_user_is_concat)return false;}- auto input_low_sub = std::make_shared<ov::op::v1::Subtract>(fq->input_value(1), new_const);+ auto input_low_sub = std::make_shared<v1::Subtract>(fq->input_value(1), new_const);std::shared_ptr<Node> new_input_low = ov::util::get_constant_from_source(input_low_sub);if (!new_input_low)new_input_low = input_low_sub;- auto input_high_sub = std::make_shared<ov::op::v1::Subtract>(fq->input_value(2), new_const);+ auto input_high_sub = std::make_shared<v1::Subtract>(fq->input_value(2), new_const);std::shared_ptr<Node> new_input_high = ov::util::get_constant_from_source(input_high_sub);if (!new_input_high)new_input_high = input_high_sub;@@ -133,6 +132,8 @@ ov::pass::AddFakeQuantizeFusion::AddFakeQuantizeFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(fq_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(fq_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp b/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cppindex 7e9de6b9ffd..4e914f6aa3e 100644--- a/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/align_eltwise_input_ranks.cpp@@ -14,17 +14,22 @@#include "openvino/op/util/binary_elementwise_logical.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::AlignEltwiseInputRanks::AlignEltwiseInputRanks() {- auto eltwise_pattern = pattern::wrap_type<ov::op::v0::SquaredDifference,- ov::op::util::BinaryElementwiseComparison,- ov::op::util::BinaryElementwiseLogical,- ov::op::util::BinaryElementwiseArithmetic,- ov::op::v0::FakeQuantize>(pattern::has_static_rank());+namespace ov::pass {++namespace v0 = ov::op::v0;+namespace op_util = ov::op::util;++AlignEltwiseInputRanks::AlignEltwiseInputRanks() {+ auto eltwise_pattern = pattern::wrap_type<v0::SquaredDifference,+ op_util::BinaryElementwiseComparison,+ op_util::BinaryElementwiseLogical,+ op_util::BinaryElementwiseArithmetic,+ v0::FakeQuantize>(pattern::has_static_rank());matcher_pass_callback callback = [=](pattern::Matcher& m) {auto node = m.get_match_root();- auto fq = as_type<ov::op::v0::FakeQuantize>(node.get());+ auto fq = as_type<v0::FakeQuantize>(node.get());if (fq) {if (fq->get_auto_broadcast() != ov::op::AutoBroadcastType::NUMPY) {return false;@@ -40,7 +45,7 @@ ov::pass::AlignEltwiseInputRanks::AlignEltwiseInputRanks() {if (ov::is_type<ov::op::v1::Multiply>(node)) {auto inputs = node->input_values();if (std::any_of(inputs.begin(), inputs.end(), [](const Output<Node>& input) -> bool {- return ov::is_type<ov::op::v0::NormalizeL2>(input.get_node());+ return ov::is_type<v0::NormalizeL2>(input.get_node());}))return false;}@@ -48,7 +53,7 @@ ov::pass::AlignEltwiseInputRanks::AlignEltwiseInputRanks() {const auto rank = static_cast<int64_t>(node->get_output_partial_shape(0).size());for (size_t i = 0; i < node->get_input_size(); i++) {- auto const_node = as_type<ov::op::v0::Constant>(node->get_input_node_ptr(i));+ auto const_node = as_type<v0::Constant>(node->get_input_node_ptr(i));if (const_node == nullptr)continue;const auto& const_shape = const_node->get_shape();@@ -56,7 +61,7 @@ ov::pass::AlignEltwiseInputRanks::AlignEltwiseInputRanks() {if (diff > 0) {Shape new_shape = const_shape;new_shape.insert(new_shape.begin(), diff, 1);- auto new_const = std::make_shared<ov::op::v0::Constant>(*const_node, new_shape);+ auto new_const = std::make_shared<v0::Constant>(*const_node, new_shape);copy_runtime_info(node->get_input_node_shared_ptr(i), new_const);node->input(i).replace_source_output(new_const);}@@ -68,3 +73,5 @@ ov::pass::AlignEltwiseInputRanks::AlignEltwiseInputRanks() {auto m = std::make_shared<pattern::Matcher>(eltwise_pattern, "AlignEltwiseInputRanks");this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/augru_cell_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/augru_cell_fusion.cppindex 9d13e58c041..1fc3d7da7eb 100644--- a/src/common/transformations/src/transformations/common_optimizations/augru_cell_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/augru_cell_fusion.cpp@@ -25,9 +25,12 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "ov_ops/augru_cell.hpp"-using namespace std;-using namespace ov::element;-using namespace ov::pass::pattern;+namespace ov::pass {++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace {// The 1st input to the Add op is automatically broadcasted// from 1d to 2d tensor, but to be compatible with what@@ -37,8 +40,7 @@ static std::shared_ptr<ov::Node> get_bias_add(const std::shared_ptr<ov::Node>& bauto input_source_1_ps = bias_add->input_value(1).get_partial_shape();if (input_source_1_ps.is_static() && input_source_1_ps.rank().get_length() == 1) {auto unsqueeze =- rg.make<ov::op::v0::Unsqueeze>(bias_add->input_value(1),- ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {0}));+ rg.make<v0::Unsqueeze>(bias_add->input_value(1), v0::Constant::create(ov::element::i32, ov::Shape{}, {0}));bias_add->input(1).replace_source_output(unsqueeze);}@@ -54,11 +56,10 @@ static std::shared_ptr<ov::Node> get_bias_add(const std::shared_ptr<ov::Node>& b// compatible with the code of the transformation.static std::shared_ptr<ov::Node> get_weights_matmul(const std::shared_ptr<ov::Node>& mat_mul,ov::pass::NodeRegistry& rg) {- if (auto matmul = ov::as_type_ptr<ov::op::v0::MatMul>(mat_mul)) {+ if (auto matmul = ov::as_type_ptr<v0::MatMul>(mat_mul)) {if (!matmul->get_transpose_b()) {- auto transpose =- rg.make<ov::op::v1::Transpose>(matmul->input_value(1),- ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0}));+ auto transpose = rg.make<v1::Transpose>(matmul->input_value(1),+ v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0}));matmul->input(1).replace_source_output(transpose);}}@@ -66,7 +67,9 @@ static std::shared_ptr<ov::Node> get_weights_matmul(const std::shared_ptr<ov::Noreturn mat_mul;}-ov::pass::AUGRUCellFusion::AUGRUCellFusion() {+} // namespace++AUGRUCellFusion::AUGRUCellFusion() {MATCHER_SCOPE(AUGRUCellFusion);// we can't determine hidden_size or input_size in this case@@ -75,27 +78,28 @@ ov::pass::AUGRUCellFusion::AUGRUCellFusion() {return !(p_shape.rank().is_dynamic() || p_shape[1].is_dynamic());};- auto concat_1 = wrap_type<ov::op::v0::Concat>({any_input(is_first_dim_static), any_input(is_first_dim_static)});- auto matmul_1 = wrap_type<ov::op::v0::MatMul>({concat_1, any_input(is_first_dim_static)});- auto add_1 = wrap_type<ov::op::v1::Add>({matmul_1, any_input()});+ auto concat_1 = pattern::wrap_type<v0::Concat>(+ {pattern::any_input(is_first_dim_static), pattern::any_input(is_first_dim_static)});+ auto matmul_1 = pattern::wrap_type<v0::MatMul>({concat_1, pattern::any_input(is_first_dim_static)});+ auto add_1 = pattern::wrap_type<v1::Add>({matmul_1, pattern::any_input()});// only Sigmoid is supported in the current version of AUGRUCell- auto sigmoid = wrap_type<ov::op::v0::Sigmoid>({add_1});- auto split = wrap_type<ov::op::v1::Split>({sigmoid, any_input()});- auto multiply = wrap_type<ov::op::v1::Multiply>({split, any_input()});+ auto sigmoid = pattern::wrap_type<v0::Sigmoid>({add_1});+ auto split = pattern::wrap_type<v1::Split>({sigmoid, pattern::any_input()});+ auto multiply = pattern::wrap_type<v1::Multiply>({split, pattern::any_input()});- auto concat_2 = wrap_type<ov::op::v0::Concat>({any_input(), multiply});- auto matmul_2 = wrap_type<ov::op::v0::MatMul>({concat_2, any_input(is_first_dim_static)});- auto add_2 = wrap_type<ov::op::v1::Add>({matmul_2, any_input()});+ auto concat_2 = pattern::wrap_type<v0::Concat>({pattern::any_input(), multiply});+ auto matmul_2 = pattern::wrap_type<v0::MatMul>({concat_2, pattern::any_input(is_first_dim_static)});+ auto add_2 = pattern::wrap_type<v1::Add>({matmul_2, pattern::any_input()});// only Tanh is supported in the current version of AUGRUCell- auto tanh = wrap_type<ov::op::v0::Tanh>({add_2});+ auto tanh = pattern::wrap_type<v0::Tanh>({add_2});- auto subtract_1 = wrap_type<ov::op::v1::Subtract>({any_input(), any_input()});- auto multiply_2 = wrap_type<ov::op::v1::Multiply>({subtract_1, split});- auto subtract_2 = wrap_type<ov::op::v1::Subtract>({any_input(), multiply_2});- auto multiply_3 = wrap_type<ov::op::v1::Multiply>({subtract_2, tanh});+ auto subtract_1 = pattern::wrap_type<v1::Subtract>({pattern::any_input(), pattern::any_input()});+ auto multiply_2 = pattern::wrap_type<v1::Multiply>({subtract_1, split});+ auto subtract_2 = pattern::wrap_type<v1::Subtract>({pattern::any_input(), multiply_2});+ auto multiply_3 = pattern::wrap_type<v1::Multiply>({subtract_2, tanh});- auto multiply_4 = wrap_type<ov::op::v1::Multiply>({multiply_2, any_input()});- auto add_3 = wrap_type<ov::op::v1::Add>({multiply_4, multiply_3});+ auto multiply_4 = pattern::wrap_type<v1::Multiply>({multiply_2, pattern::any_input()});+ auto add_3 = pattern::wrap_type<v1::Add>({multiply_4, multiply_3});matcher_pass_callback callback = [=](pattern::Matcher& m) {NodeRegistry rg;@@ -110,35 +114,34 @@ ov::pass::AUGRUCellFusion::AUGRUCellFusion() {auto hidden_size = h_pshape[1].get_length();auto input_size = x_pshape[1].get_length();- auto axis_0 = rg.make<ov::op::v0::Constant>(i64, Shape{}, 0);- auto axis_1 = rg.make<ov::op::v0::Constant>(i64, Shape{}, 1);+ auto axis_0 = rg.make<v0::Constant>(element::i64, Shape{}, 0);+ auto axis_1 = rg.make<v0::Constant>(element::i64, Shape{}, 1);auto A = pattern_map.at(subtract_1)->input_value(1);// biases are requiredauto bias_add_1 = get_bias_add(pattern_map.at(add_1), rg);- auto split_bias_r_z = rg.make<ov::op::v1::Split>(bias_add_1->input_value(1), axis_1, 2);+ auto split_bias_r_z = rg.make<v1::Split>(bias_add_1->input_value(1), axis_1, 2);auto bias_add_2 = get_bias_add(pattern_map.at(add_2), rg);- auto B = rg.make<ov::op::v0::Concat>(+ auto B = rg.make<v0::Concat>(OutputVector{split_bias_r_z->output(1), split_bias_r_z->output(0), bias_add_2->input_value(1)},1);auto WRrz = get_weights_matmul(pattern_map.at(matmul_1), rg)->input_value(1);auto WRh = get_weights_matmul(pattern_map.at(matmul_2), rg)->input_value(1);- auto split_lenghts = rg.make<ov::op::v0::Constant>(i64, Shape{2}, vector<int64_t>{input_size, hidden_size});- auto split_WRrz = rg.make<ov::op::v1::VariadicSplit>(WRrz, axis_1, split_lenghts);- auto split_W_r_z = rg.make<ov::op::v1::Split>(split_WRrz->output(0), axis_0, 2);- auto split_R_r_z = rg.make<ov::op::v1::Split>(split_WRrz->output(1), axis_0, 2);- auto split_WRh = rg.make<ov::op::v1::VariadicSplit>(WRh, axis_1, split_lenghts);- auto Wzrh = rg.make<ov::op::v0::Concat>(- OutputVector{split_W_r_z->output(1), split_W_r_z->output(0), split_WRh->output(0)},- 0);- auto Rzrh = rg.make<ov::op::v0::Concat>(- OutputVector{split_R_r_z->output(1), split_R_r_z->output(0), split_WRh->output(1)},- 0);-- auto squeeze_B = rg.make<ov::op::v0::Squeeze>(B, axis_0);+ auto split_lenghts =+ rg.make<v0::Constant>(element::i64, Shape{2}, std::vector<int64_t>{input_size, hidden_size});+ auto split_WRrz = rg.make<v1::VariadicSplit>(WRrz, axis_1, split_lenghts);+ auto split_W_r_z = rg.make<v1::Split>(split_WRrz->output(0), axis_0, 2);+ auto split_R_r_z = rg.make<v1::Split>(split_WRrz->output(1), axis_0, 2);+ auto split_WRh = rg.make<v1::VariadicSplit>(WRh, axis_1, split_lenghts);+ auto Wzrh =+ rg.make<v0::Concat>(OutputVector{split_W_r_z->output(1), split_W_r_z->output(0), split_WRh->output(0)}, 0);+ auto Rzrh =+ rg.make<v0::Concat>(OutputVector{split_R_r_z->output(1), split_R_r_z->output(0), split_WRh->output(1)}, 0);++ auto squeeze_B = rg.make<v0::Squeeze>(B, axis_0);auto cell =rg.make<ov::op::internal::AUGRUCell>(X, H, Wzrh, Rzrh, squeeze_B, A, H.get_partial_shape()[1].get_length());@@ -148,6 +151,8 @@ ov::pass::AUGRUCellFusion::AUGRUCellFusion() {return true;};- auto m = make_shared<Matcher>(add_3, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(add_3, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/batch_to_space_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/batch_to_space_fusion.cppindex 60894352b20..f86d28bf7c9 100644--- a/src/common/transformations/src/transformations/common_optimizations/batch_to_space_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/batch_to_space_fusion.cpp@@ -20,28 +20,29 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::BatchToSpaceFusion::BatchToSpaceFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++BatchToSpaceFusion::BatchToSpaceFusion() {MATCHER_SCOPE(BatchToSpaceFusion);auto data_pattern = pattern::any_input(pattern::has_static_shape());auto reshape_before_pattern =- pattern::wrap_type<ov::op::v1::Reshape>({data_pattern, pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(4));+ pattern::wrap_type<v1::Reshape>({data_pattern, pattern::wrap_type<v0::Constant>()}, pattern::rank_equals(4));auto trans_before_pattern =- pattern::wrap_type<ov::op::v1::Transpose>({data_pattern, pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(4));+ pattern::wrap_type<v1::Transpose>({data_pattern, pattern::wrap_type<v0::Constant>()}, pattern::rank_equals(4));auto reshape_or_transpose_before_pattern =std::make_shared<pattern::op::Or>(OutputVector{reshape_before_pattern, trans_before_pattern});- auto depth_to_space_pattern = pattern::wrap_type<ov::op::v0::DepthToSpace>({reshape_or_transpose_before_pattern});- auto starts_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto ends_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto slice_pattern = pattern::wrap_type<ov::op::v1::StridedSlice>(- {depth_to_space_pattern, starts_pattern, ends_pattern, pattern::wrap_type<ov::op::v0::Constant>()});+ auto depth_to_space_pattern = pattern::wrap_type<v0::DepthToSpace>({reshape_or_transpose_before_pattern});+ auto starts_pattern = pattern::wrap_type<v0::Constant>();+ auto ends_pattern = pattern::wrap_type<v0::Constant>();+ auto slice_pattern = pattern::wrap_type<v1::StridedSlice>(+ {depth_to_space_pattern, starts_pattern, ends_pattern, pattern::wrap_type<v0::Constant>()});auto reshape_after_pattern =- pattern::wrap_type<ov::op::v1::Reshape>({slice_pattern, pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(4));+ pattern::wrap_type<v1::Reshape>({slice_pattern, pattern::wrap_type<v0::Constant>()}, pattern::rank_equals(4));auto trans_after_pattern =- pattern::wrap_type<ov::op::v1::Transpose>({slice_pattern, pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(4));+ pattern::wrap_type<v1::Transpose>({slice_pattern, pattern::wrap_type<v0::Constant>()}, pattern::rank_equals(4));auto reshape_or_transpose_after_pattern =std::make_shared<pattern::op::Or>(OutputVector{reshape_after_pattern, trans_after_pattern});@@ -79,21 +80,21 @@ ov::pass::BatchToSpaceFusion::BatchToSpaceFusion() {return false;auto depth_to_space =- ov::as_type_ptr<ov::op::v0::DepthToSpace>(pattern_map.at(depth_to_space_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v0::DepthToSpace>(pattern_map.at(depth_to_space_pattern).get_node_shared_ptr());if (!depth_to_space)return false;- if (depth_to_space->get_mode() != ov::op::v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST)+ if (depth_to_space->get_mode() != v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST)return false;const auto& dts_shape = depth_to_space->get_shape();if (dts_shape.size() != 4)return false;auto block_size = static_cast<int64_t>(depth_to_space->get_block_size());auto block_shape =- ov::op::v0::Constant::create(element::i64, Shape{4}, std::vector<int64_t>{1, 1, block_size, block_size});- auto starts = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(starts_pattern).get_node_shared_ptr());+ v0::Constant::create(element::i64, Shape{4}, std::vector<int64_t>{1, 1, block_size, block_size});+ auto starts = ov::as_type_ptr<v0::Constant>(pattern_map.at(starts_pattern).get_node_shared_ptr());if (!starts)return false;- auto ends = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(ends_pattern).get_node_shared_ptr());+ auto ends = ov::as_type_ptr<v0::Constant>(pattern_map.at(ends_pattern).get_node_shared_ptr());if (!ends)return false;auto starts_value = starts->cast_vector<int64_t>();@@ -112,12 +113,10 @@ ov::pass::BatchToSpaceFusion::BatchToSpaceFusion() {ends_value[i] = dts_shape[i] - ends_value[i];}}- auto crops_begin = ov::op::v0::Constant::create(element::i64, Shape{4}, starts_value);- auto crops_end = ov::op::v0::Constant::create(element::i64, Shape{4}, ends_value);- auto batch_to_space = register_new_node<ov::op::v1::BatchToSpace>(pattern_map.at(data_pattern),- block_shape,- crops_begin,- crops_end);+ auto crops_begin = v0::Constant::create(element::i64, Shape{4}, starts_value);+ auto crops_end = v0::Constant::create(element::i64, Shape{4}, ends_value);+ auto batch_to_space =+ register_new_node<v1::BatchToSpace>(pattern_map.at(data_pattern), block_shape, crops_begin, crops_end);batch_to_space->set_friendly_name(reshape_or_trans_after->get_friendly_name());copy_runtime_info({reshape_or_trans_before,@@ -130,6 +129,8 @@ ov::pass::BatchToSpaceFusion::BatchToSpaceFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reshape_or_transpose_after_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(reshape_or_transpose_after_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/binarize_weights.cpp b/src/common/transformations/src/transformations/common_optimizations/binarize_weights.cppindex 00fa156c980..54475d3b273 100644--- a/src/common/transformations/src/transformations/common_optimizations/binarize_weights.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/binarize_weights.cpp@@ -19,6 +19,13 @@using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++namespace {+static float quantize(float f, float input_low, float input_high, float output_low, float output_high) {if (f <= input_low)return output_low;@@ -57,35 +64,36 @@ static std::vector<float> quantize_weights(const Shape& weights_shape,return out;}-pass::BinarizeWeights::BinarizeWeights() {+} // namespace++BinarizeWeights::BinarizeWeights() {MATCHER_SCOPE(BinarizeWeights);- auto activations_fq_pattern =- pattern::wrap_type<ov::op::v0::FakeQuantize>({pattern::any_input(),- pattern::wrap_type<ov::op::v0::Constant>(),- pattern::wrap_type<ov::op::v0::Constant>(),- pattern::wrap_type<ov::op::v0::Constant>(),- pattern::wrap_type<ov::op::v0::Constant>()},- pattern::consumers_count(1));- auto weights_fq_pattern = pattern::wrap_type<ov::op::v0::FakeQuantize>({pattern::wrap_type<ov::op::v0::Constant>(),- pattern::wrap_type<ov::op::v0::Constant>(),- pattern::wrap_type<ov::op::v0::Constant>(),- pattern::wrap_type<ov::op::v0::Constant>(),- pattern::wrap_type<ov::op::v0::Constant>()},- pattern::consumers_count(1));- auto conv_pattern = pattern::wrap_type<ov::op::v1::Convolution>({activations_fq_pattern, weights_fq_pattern});+ auto activations_fq_pattern = pattern::wrap_type<v0::FakeQuantize>({pattern::any_input(),+ pattern::wrap_type<v0::Constant>(),+ pattern::wrap_type<v0::Constant>(),+ pattern::wrap_type<v0::Constant>(),+ pattern::wrap_type<v0::Constant>()},+ pattern::consumers_count(1));+ auto weights_fq_pattern = pattern::wrap_type<v0::FakeQuantize>({pattern::wrap_type<v0::Constant>(),+ pattern::wrap_type<v0::Constant>(),+ pattern::wrap_type<v0::Constant>(),+ pattern::wrap_type<v0::Constant>(),+ pattern::wrap_type<v0::Constant>()},+ pattern::consumers_count(1));+ auto conv_pattern = pattern::wrap_type<v1::Convolution>({activations_fq_pattern, weights_fq_pattern});matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto conv = ov::as_type_ptr<ov::op::v1::Convolution>(m.get_match_root());+ auto conv = ov::as_type_ptr<v1::Convolution>(m.get_match_root());if (!conv)return false;- auto activations_fq = ov::as_type_ptr<ov::op::v0::FakeQuantize>(conv->input_value(0).get_node_shared_ptr());+ auto activations_fq = ov::as_type_ptr<v0::FakeQuantize>(conv->input_value(0).get_node_shared_ptr());if (!activations_fq || activations_fq->get_levels() != 2)return false;- auto weights_fq = ov::as_type_ptr<ov::op::v0::FakeQuantize>(conv->input_value(1).get_node_shared_ptr());+ auto weights_fq = ov::as_type_ptr<v0::FakeQuantize>(conv->input_value(1).get_node_shared_ptr());if (!weights_fq || weights_fq->get_levels() != 2)return false;- auto weights_const = ov::as_type_ptr<ov::op::v0::Constant>(weights_fq->input_value(0).get_node_shared_ptr());+ auto weights_const = ov::as_type_ptr<v0::Constant>(weights_fq->input_value(0).get_node_shared_ptr());if (!weights_const)return false;@@ -101,9 +109,9 @@ pass::BinarizeWeights::BinarizeWeights() {};auto activations_output_low_const =- ov::as_type_ptr<ov::op::v0::Constant>(activations_fq->input_value(3).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(activations_fq->input_value(3).get_node_shared_ptr());auto activations_output_high_const =- ov::as_type_ptr<ov::op::v0::Constant>(activations_fq->input_value(4).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(activations_fq->input_value(4).get_node_shared_ptr());if (!activations_output_low_const || !activations_output_high_const)return false;@@ -117,16 +125,13 @@ pass::BinarizeWeights::BinarizeWeights() {if (!(act_out_low_high_are_opposite || act_out_low_is_zero))return false;- auto weights_input_low_const =- ov::as_type_ptr<ov::op::v0::Constant>(weights_fq->input_value(1).get_node_shared_ptr());- auto weights_input_high_const =- ov::as_type_ptr<ov::op::v0::Constant>(weights_fq->input_value(2).get_node_shared_ptr());+ auto weights_input_low_const = ov::as_type_ptr<v0::Constant>(weights_fq->input_value(1).get_node_shared_ptr());+ auto weights_input_high_const = ov::as_type_ptr<v0::Constant>(weights_fq->input_value(2).get_node_shared_ptr());if (!weights_input_low_const || !weights_input_high_const)return false;- auto weights_output_low_const =- ov::as_type_ptr<ov::op::v0::Constant>(weights_fq->input_value(3).get_node_shared_ptr());+ auto weights_output_low_const = ov::as_type_ptr<v0::Constant>(weights_fq->input_value(3).get_node_shared_ptr());auto weights_output_high_const =- ov::as_type_ptr<ov::op::v0::Constant>(weights_fq->input_value(4).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(weights_fq->input_value(4).get_node_shared_ptr());if (!weights_output_low_const || !weights_output_high_const)return false;@@ -155,13 +160,11 @@ pass::BinarizeWeights::BinarizeWeights() {const std::shared_ptr<Node>& weights_norm_factor = weights_output_high_const;// Create new FQ on activations with new output low/high- auto output_low_normalized = ov::op::v0::Constant::create(element::f32,- activations_output_low_const->get_shape(),- activations_output_low);+ auto output_low_normalized =+ v0::Constant::create(element::f32, activations_output_low_const->get_shape(), activations_output_low);output_low_normalized->set_friendly_name(activations_output_low_const->get_friendly_name());- auto output_high_normalized = ov::op::v0::Constant::create(element::f32,- activations_output_high_const->get_shape(),- activations_output_high);+ auto output_high_normalized =+ v0::Constant::create(element::f32, activations_output_high_const->get_shape(), activations_output_high);output_high_normalized->set_friendly_name(activations_output_high_const->get_friendly_name());auto new_activations_fq = activations_fq->clone_with_new_inputs({activations_fq->input_value(0),activations_fq->input_value(1),@@ -183,7 +186,7 @@ pass::BinarizeWeights::BinarizeWeights() {weights_output_low,weights_output_high);auto quantized_weights_const =- ov::op::v0::Constant::create(element::f32, weights_const->get_shape(), quantized_weights);+ v0::Constant::create(element::f32, weights_const->get_shape(), quantized_weights);quantized_weights_const->set_friendly_name(weights_const->get_friendly_name());auto new_conv = conv->clone_with_new_inputs({new_activations_fq, quantized_weights_const});@@ -191,14 +194,14 @@ pass::BinarizeWeights::BinarizeWeights() {for (size_t i = 2; i < weights_const->get_shape().size(); i++)norm_factor_shape.push_back(1);auto norm_factor_shape_const =- ov::op::v0::Constant::create(element::i64, Shape{norm_factor_shape.size()}, norm_factor_shape);+ v0::Constant::create(element::i64, Shape{norm_factor_shape.size()}, norm_factor_shape);auto activations_norm_factor_reshaped =- std::make_shared<ov::op::v1::Reshape>(activations_norm_factor, norm_factor_shape_const, false);- auto mul = std::make_shared<ov::op::v1::Multiply>(new_conv, activations_norm_factor_reshaped);+ std::make_shared<v1::Reshape>(activations_norm_factor, norm_factor_shape_const, false);+ auto mul = std::make_shared<v1::Multiply>(new_conv, activations_norm_factor_reshaped);auto weights_norm_factor_reshaped =- std::make_shared<ov::op::v1::Reshape>(weights_norm_factor, norm_factor_shape_const, false);- auto mul2 = std::make_shared<ov::op::v1::Multiply>(mul, weights_norm_factor_reshaped);+ std::make_shared<v1::Reshape>(weights_norm_factor, norm_factor_shape_const, false);+ auto mul2 = std::make_shared<v1::Multiply>(mul, weights_norm_factor_reshaped);copy_runtime_info({activations_fq, weights_fq, conv},@@ -211,3 +214,5 @@ pass::BinarizeWeights::BinarizeWeights() {auto m = std::make_shared<pattern::Matcher>(conv_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cppindex 9e692eddc37..c40c6d80f2e 100644--- a/src/common/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/broadcast_elementwise_fusion.cpp@@ -11,12 +11,17 @@#include "openvino/op/util/binary_elementwise_arithmetic.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+namespace v3 = ov::op::v3;+namespace op_util = ov::op::util;++namespace ov::pass {+namespace {bool can_eliminate_broadcast(const ov::Output<ov::Node>& eltwise,const ov::Output<ov::Node>& eltwise_input,const ov::Output<ov::Node>& broadcast) {- auto b = ov::as_type_ptr<ov::op::util::BinaryElementwiseArithmetic>(eltwise.get_node_shared_ptr());+ auto b = ov::as_type_ptr<op_util::BinaryElementwiseArithmetic>(eltwise.get_node_shared_ptr());if (!b || b->get_autob() == ov::op::AutoBroadcastType::NONE) {return false;}@@ -25,7 +30,7 @@ bool can_eliminate_broadcast(const ov::Output<ov::Node>& eltwise,// to Broadcast operation as a output shape target. In this case we can eliminate// Broadcast since eltwise_input will broadcast another eltwise input automatically.auto broadcast_input = broadcast.get_node()->get_input_node_shared_ptr(1);- if ((ov::is_type<ov::op::v3::ShapeOf>(broadcast_input) || ov::is_type<ov::op::v0::ShapeOf>(broadcast_input)) &&+ if ((ov::is_type<v3::ShapeOf>(broadcast_input) || ov::is_type<ov::op::v0::ShapeOf>(broadcast_input)) &&broadcast_input->input_value(0) == eltwise_input) {return true;}@@ -69,15 +74,15 @@ bool can_eliminate_broadcast(const ov::Output<ov::Node>& eltwise,} // namespace-ov::pass::BroadcastElementwiseFusion::BroadcastElementwiseFusion() {+BroadcastElementwiseFusion::BroadcastElementwiseFusion() {MATCHER_SCOPE(BroadcastElementwiseFusion);auto broadcast_input = pattern::any_input();auto broadcast =- pattern::wrap_type<ov::op::v3::Broadcast>({broadcast_input, pattern::any_input()}, pattern::consumers_count(1));+ pattern::wrap_type<v3::Broadcast>({broadcast_input, pattern::any_input()}, pattern::consumers_count(1));auto eltwise_input = pattern::any_input();- auto eltwise = pattern::wrap_type<ov::op::util::BinaryElementwiseArithmetic>({eltwise_input, broadcast});+ auto eltwise = pattern::wrap_type<op_util::BinaryElementwiseArithmetic>({eltwise_input, broadcast});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {auto& pattern_value = m.get_pattern_value_map();const auto& m_eltwise_input = pattern_value.at(eltwise_input);@@ -96,6 +101,8 @@ ov::pass::BroadcastElementwiseFusion::BroadcastElementwiseFusion() {return false;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(eltwise, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(eltwise, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/broadcast_transition.cpp b/src/common/transformations/src/transformations/common_optimizations/broadcast_transition.cppindex 9fa9df883d0..fd432ee1abf 100644--- a/src/common/transformations/src/transformations/common_optimizations/broadcast_transition.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/broadcast_transition.cpp@@ -19,23 +19,29 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::BroadcastTransition::BroadcastTransition() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace op_util = ov::op::util;++namespace ov::pass {++BroadcastTransition::BroadcastTransition() {MATCHER_SCOPE(BroadcastTransition);- auto bcast_m =- pass::pattern::wrap_type<ov::op::v1::Broadcast, ov::op::v3::Broadcast>(pass::pattern::consumers_count(1));- auto eltwise_input_m = pass::pattern::any_input(pass::pattern::has_static_rank());- auto eltwise_1 = pass::pattern::wrap_type<ov::op::util::BinaryElementwiseArithmetic>({eltwise_input_m, bcast_m});- auto eltwise_2 = pass::pattern::wrap_type<ov::op::util::BinaryElementwiseArithmetic>({bcast_m, eltwise_input_m});- auto eltwise_m = std::make_shared<pass::pattern::op::Or>(OutputVector{eltwise_1, eltwise_2});+ auto bcast_m = pattern::wrap_type<v1::Broadcast, v3::Broadcast>(pattern::consumers_count(1));+ auto eltwise_input_m = pattern::any_input(pattern::has_static_rank());+ auto eltwise_1 = pattern::wrap_type<op_util::BinaryElementwiseArithmetic>({eltwise_input_m, bcast_m});+ auto eltwise_2 = pattern::wrap_type<op_util::BinaryElementwiseArithmetic>({bcast_m, eltwise_input_m});+ auto eltwise_m = std::make_shared<pattern::op::Or>(OutputVector{eltwise_1, eltwise_2});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();- const auto eltwise = ov::as_type_ptr<ov::op::util::BinaryElementwiseArithmetic>(m.get_match_root());+ const auto eltwise = ov::as_type_ptr<op_util::BinaryElementwiseArithmetic>(m.get_match_root());if (eltwise->get_autob().m_type != ov::op::AutoBroadcastType::NUMPY) {return false;}- const auto bcast = ov::as_type_ptr<ov::op::util::BroadcastBase>(pattern_map.at(bcast_m).get_node_shared_ptr());+ const auto bcast = ov::as_type_ptr<op_util::BroadcastBase>(pattern_map.at(bcast_m).get_node_shared_ptr());if (!bcast || (bcast->get_broadcast_spec().m_type != ov::op::BroadcastType::NUMPY &&bcast->get_broadcast_spec().m_type != ov::op::BroadcastType::BIDIRECTIONAL)) {return false;@@ -55,11 +61,11 @@ ov::pass::BroadcastTransition::BroadcastTransition() {std::shared_ptr<ov::Node> data_shape_path;if (target_shape_et == ov::element::i32 || target_shape_et == ov::element::i64) {- data_shape_path = ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(new_eltwise, target_shape_et);+ data_shape_path = op_util::make_try_fold<v3::ShapeOf>(new_eltwise, target_shape_et);ov::copy_runtime_info(eltwise, data_shape_path);} else {- auto shapeof = ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(new_eltwise);- data_shape_path = ov::op::util::make_try_fold<ov::op::v0::Convert>(shapeof, target_shape_et);+ auto shapeof = op_util::make_try_fold<v3::ShapeOf>(new_eltwise);+ data_shape_path = op_util::make_try_fold<v0::Convert>(shapeof, target_shape_et);ov::copy_runtime_info(eltwise, {shapeof, data_shape_path});}@@ -67,8 +73,8 @@ ov::pass::BroadcastTransition::BroadcastTransition() {const size_t input_rank = new_eltwise->get_output_partial_shape(0).size();if (input_rank != target_shape_rank) {auto align_rank = [&](const ov::Output<ov::Node>& out, const size_t count) {- const auto constant = ov::op::v0::Constant::create(target_shape_et, {count}, {1});- const auto res = ov::op::util::make_try_fold<ov::op::v0::Concat>(ov::OutputVector{constant, out}, 0);+ const auto constant = v0::Constant::create(target_shape_et, {count}, {1});+ const auto res = op_util::make_try_fold<v0::Concat>(ov::OutputVector{constant, out}, 0);ov::copy_runtime_info(out.get_node_shared_ptr(), {constant, res});return res;};@@ -78,16 +84,18 @@ ov::pass::BroadcastTransition::BroadcastTransition() {target_shape = align_rank(target_shape, input_rank - target_shape_rank);}}- const auto new_target_shape = ov::op::util::make_try_fold<ov::op::v1::Maximum>(data_shape_path, target_shape);+ const auto new_target_shape = op_util::make_try_fold<v1::Maximum>(data_shape_path, target_shape);ov::copy_runtime_info(eltwise, new_target_shape);- const auto new_bcast = std::make_shared<ov::op::v3::Broadcast>(new_eltwise, new_target_shape);+ const auto new_bcast = std::make_shared<v3::Broadcast>(new_eltwise, new_target_shape);new_bcast->set_friendly_name(eltwise->get_friendly_name());ov::copy_runtime_info(eltwise, {new_eltwise, new_bcast});ov::replace_node(eltwise, new_bcast);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(eltwise_m, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(eltwise_m, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/clamp_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/clamp_fusion.cppindex 7c91d34bb3e..9313aefdcff 100644--- a/src/common/transformations/src/transformations/common_optimizations/clamp_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/clamp_fusion.cpp@@ -18,28 +18,31 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ClampFusion::ClampFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++ClampFusion::ClampFusion() {MATCHER_SCOPE(ClampFusion);- auto data_pattern = pass::pattern::any_input();- auto min_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto max_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto max_pattern1 = ov::pass::pattern::wrap_type<ov::op::v1::Maximum>({data_pattern, min_const_pattern},- pattern::consumers_count(1));- auto min_pattern1 = ov::pass::pattern::wrap_type<ov::op::v1::Minimum>({max_pattern1, max_const_pattern});- auto min_pattern2 = ov::pass::pattern::wrap_type<ov::op::v1::Minimum>({data_pattern, max_const_pattern});- auto max_pattern2 = ov::pass::pattern::wrap_type<ov::op::v1::Maximum>({min_pattern2, min_const_pattern},- pattern::consumers_count(1));- auto root = std::make_shared<ov::pass::pattern::op::Or>(ov::OutputVector{min_pattern1, max_pattern2});+ auto data_pattern = pattern::any_input();+ auto min_const_pattern = pattern::wrap_type<v0::Constant>();+ auto max_const_pattern = pattern::wrap_type<v0::Constant>();+ auto max_pattern1 = pattern::wrap_type<v1::Maximum>({data_pattern, min_const_pattern}, pattern::consumers_count(1));+ auto min_pattern1 = pattern::wrap_type<v1::Minimum>({max_pattern1, max_const_pattern});+ auto min_pattern2 = pattern::wrap_type<v1::Minimum>({data_pattern, max_const_pattern});+ auto max_pattern2 = pattern::wrap_type<v1::Maximum>({min_pattern2, min_const_pattern}, pattern::consumers_count(1));+ auto root = std::make_shared<pattern::op::Or>(ov::OutputVector{min_pattern1, max_pattern2});ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto pattern_map = m.get_pattern_value_map();auto data = pattern_map.at(data_pattern);- auto min_const = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(min_const_pattern).get_node_shared_ptr());+ auto min_const = ov::as_type_ptr<v0::Constant>(pattern_map.at(min_const_pattern).get_node_shared_ptr());if (!min_const)return false;if (shape_size(min_const->get_shape()) != 1)return false;- auto max_const = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(max_const_pattern).get_node_shared_ptr());+ auto max_const = ov::as_type_ptr<v0::Constant>(pattern_map.at(max_const_pattern).get_node_shared_ptr());if (!max_const)return false;if (shape_size(max_const->get_shape()) != 1)@@ -50,7 +53,7 @@ ov::pass::ClampFusion::ClampFusion() {if (min_value > max_value)return false;- auto clamp = register_new_node<ov::op::v0::Clamp>(data, min_value, max_value);+ auto clamp = register_new_node<v0::Clamp>(data, min_value, max_value);std::shared_ptr<ov::Node> root_node;NodeVector nodes;@@ -72,6 +75,8 @@ ov::pass::ClampFusion::ClampFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(root, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(root, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/compress_float_constants.cpp b/src/common/transformations/src/transformations/common_optimizations/compress_float_constants.cppindex 080098a0ed5..2b9ecfec3ef 100644--- a/src/common/transformations/src/transformations/common_optimizations/compress_float_constants.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/compress_float_constants.cpp@@ -25,16 +25,22 @@#include "transformations/rt_info/disable_fp16_compression.hpp"#include "transformations/rt_info/old_api_map_element_type_attribute.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+namespace {+template <ov::element::Type_t PREC_FROM>-std::shared_ptr<ov::Node> change_constant_precision_to_fp16(std::shared_ptr<ov::op::v0::Constant>& constant,+std::shared_ptr<ov::Node> change_constant_precision_to_fp16(std::shared_ptr<v0::Constant>& constant,bool postponed = false) {using src_type = typename ov::element_type_traits<PREC_FROM>::value_type;const auto* src_data = constant->get_data_ptr<src_type>();const auto size = ov::shape_size(constant->get_shape());- auto new_constant = std::make_shared<ov::op::v0::Constant>(ov::element::f16, constant->get_shape());+ auto new_constant = std::make_shared<v0::Constant>(ov::element::f16, constant->get_shape());auto* dst_data = const_cast<ov::float16*>(reinterpret_cast<const ov::float16*>(new_constant->get_data_ptr()));if (!dst_data || !size)return nullptr;@@ -73,12 +79,10 @@ std::shared_ptr<ov::Node> change_constant_precision_to_fp16(std::shared_ptr<ov::}}-using namespace ov::pass;-class DetectFakeQuantizeOrFakeConvert : public MatcherPass {public:DetectFakeQuantizeOrFakeConvert() {- auto root = pattern::wrap_type<ov::op::v0::FakeQuantize, ov::op::v13::FakeConvert>();+ auto root = pattern::wrap_type<v0::FakeQuantize, ov::op::v13::FakeConvert>();ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {return true;@@ -92,20 +96,19 @@ public:class DetectCompressedWeights : public MatcherPass {public:DetectCompressedWeights() {- auto weights = pattern::wrap_type<ov::op::v0::Constant>(pattern::type_matches_any({ov::element::i4,- ov::element::u4,- ov::element::i8,- ov::element::u8,- ov::element::nf4,- ov::element::f8e4m3,- ov::element::f8e5m2}));- auto convert = pattern::wrap_type<ov::op::v0::Convert>({weights});- auto zero_point_const = pattern::wrap_type<ov::op::v0::Constant>();- auto zero_point = pattern::optional<ov::op::v0::Convert>(zero_point_const);- auto subtract = pattern::wrap_type<ov::op::v1::Subtract>({convert, zero_point});+ auto weights = pattern::wrap_type<v0::Constant>(pattern::type_matches_any({ov::element::i4,+ ov::element::u4,+ ov::element::i8,+ ov::element::u8,+ ov::element::nf4,+ ov::element::f8e4m3,+ ov::element::f8e5m2}));+ auto convert = pattern::wrap_type<v0::Convert>({weights});+ auto zero_point_const = pattern::wrap_type<v0::Constant>();+ auto zero_point = pattern::optional<v0::Convert>(zero_point_const);+ auto subtract = pattern::wrap_type<v1::Subtract>({convert, zero_point});auto subtract_or_convert = std::make_shared<pattern::op::Or>(ov::OutputVector{convert, subtract});- auto multiply =- pattern::wrap_type<ov::op::v1::Multiply>({subtract_or_convert, pattern::wrap_type<ov::op::v0::Constant>()});+ auto multiply = pattern::wrap_type<v1::Multiply>({subtract_or_convert, pattern::wrap_type<v0::Constant>()});ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {return true;@@ -115,9 +118,10 @@ public:register_matcher(m, callback);}};+} // namespace-bool ov::pass::is_model_optimized(const std::shared_ptr<ov::Model>& model) {+bool is_model_optimized(const std::shared_ptr<ov::Model>& model) {Manager manager;auto detect_optimized_model = manager.register_pass<GraphRewrite>();detect_optimized_model->add_matcher<DetectFakeQuantizeOrFakeConvert>();@@ -125,7 +129,7 @@ bool ov::pass::is_model_optimized(const std::shared_ptr<ov::Model>& model) {return manager.run_passes(model);}-void ov::pass::compress_model_to_f16(const std::shared_ptr<Model>& model, bool postponed) {+void compress_model_to_f16(const std::shared_ptr<Model>& model, bool postponed) {if (!is_model_optimized(model)) {Manager manager;manager.register_pass<MarkPrecisionSensitiveConstants>();@@ -134,15 +138,15 @@ void ov::pass::compress_model_to_f16(const std::shared_ptr<Model>& model, bool p}}-ov::pass::CompressFloatConstantsImpl::CompressFloatConstantsImpl(bool postponed) {+CompressFloatConstantsImpl::CompressFloatConstantsImpl(bool postponed) {MATCHER_SCOPE(CompressFloatConstantsImpl);- auto const_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto const_pattern = pattern::wrap_type<v0::Constant>();ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& const_node_pattern = pattern_map.at(const_pattern);- auto const_node = ov::as_type_ptr<ov::op::v0::Constant>(const_node_pattern.get_node_shared_ptr());+ auto const_node = ov::as_type_ptr<v0::Constant>(const_node_pattern.get_node_shared_ptr());if (!const_node)return false;@@ -178,8 +182,7 @@ ov::pass::CompressFloatConstantsImpl::CompressFloatConstantsImpl(bool postponed)new_const = const_node;} else {const auto* src_data = const_node->get_data_ptr<float>();- auto compressed_const =- std::make_shared<ov::op::v0::Constant>(ov::element::f16, const_node->get_shape());+ auto compressed_const = std::make_shared<v0::Constant>(ov::element::f16, const_node->get_shape());auto* dst_data =const_cast<ov::float16*>(reinterpret_cast<const ov::float16*>(compressed_const->get_data_ptr()));OPENVINO_ASSERT(dst_data);@@ -212,12 +215,11 @@ ov::pass::CompressFloatConstantsImpl::CompressFloatConstantsImpl(bool postponed)if (is_fp16_compression_postponed(postponed_constant_node->get_rt_info())) {// Convert was already added after postponed_constant_node. Get it and just update rt infoauto next_node = postponed_constant_node->get_output_target_inputs(0).begin()->get_node();- OPENVINO_ASSERT(ov::as_type<ov::op::v0::Convert>(next_node));+ OPENVINO_ASSERT(ov::as_type<v0::Convert>(next_node));ov::copy_runtime_info(const_node, next_node->shared_from_this());} else {auto postponed_constant_target_inputs = postponed_constant_node->get_output_target_inputs(0);- auto convert =- std::make_shared<ov::op::v0::Convert>(postponed_constant_node, const_node->get_element_type());+ auto convert = std::make_shared<v0::Convert>(postponed_constant_node, const_node->get_element_type());convert->set_friendly_name(postponed_constant_node->get_friendly_name());ov::mark_as_decompression(convert);@@ -232,7 +234,7 @@ ov::pass::CompressFloatConstantsImpl::CompressFloatConstantsImpl(bool postponed)}}} else {- auto convert = std::make_shared<ov::op::v0::Convert>(new_const, const_node->get_element_type());+ auto convert = std::make_shared<v0::Convert>(new_const, const_node->get_element_type());convert->set_friendly_name(const_node->get_friendly_name());new_const->set_friendly_name(const_node->get_friendly_name() + "_compressed");@@ -255,3 +257,5 @@ ov::pass::CompressFloatConstantsImpl::CompressFloatConstantsImpl(bool postponed)auto m = std::make_shared<pattern::Matcher>(const_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/concat_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/concat_fusion.cppindex 43038e5d259..950361ca984 100644--- a/src/common/transformations/src/transformations/common_optimizations/concat_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/concat_fusion.cpp@@ -14,9 +14,11 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::op;+namespace v0 = ov::op::v0;-ov::pass::ConcatFusion::ConcatFusion() {+namespace ov::pass {++ConcatFusion::ConcatFusion() {MATCHER_SCOPE(ConcatFusion);auto has_same_axis_concat_input = [](const Output<Node>& output) {const auto& concat = ov::as_type_ptr<v0::Concat>(output.get_node_shared_ptr());@@ -56,6 +58,8 @@ ov::pass::ConcatFusion::ConcatFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(concat_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(concat_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/concat_reduce_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/concat_reduce_fusion.cppindex c80787c70ba..f958bc047e1 100644--- a/src/common/transformations/src/transformations/common_optimizations/concat_reduce_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/concat_reduce_fusion.cpp@@ -24,26 +24,34 @@#include "transformations/common_optimizations/nop_elimination.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {+namespace {+enum class ReduceType { NONE, MAX, MIN };ReduceType get_reduce_type(const std::shared_ptr<ov::Node>& reduce_node) {- if (ov::is_type<ov::op::v1::ReduceMax>(reduce_node)) {+ if (ov::is_type<v1::ReduceMax>(reduce_node)) {return ReduceType::MAX;- } else if (ov::is_type<ov::op::v1::ReduceMin>(reduce_node)) {+ } else if (ov::is_type<v1::ReduceMin>(reduce_node)) {return ReduceType::MIN;} else {return ReduceType::NONE;}}+} // namespace-ov::pass::PullSqueezeThroughEltwise::PullSqueezeThroughEltwise() {+PullSqueezeThroughEltwise::PullSqueezeThroughEltwise() {MATCHER_SCOPE(PullSqueezeThroughEltwise);- auto eltwise_pattern = pattern::wrap_type<ov::op::util::BinaryElementwiseArithmetic>();+ auto eltwise_pattern = pattern::wrap_type<op_util::BinaryElementwiseArithmetic>();- auto squeeze_axes_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto squeeze_pattern = pattern::wrap_type<ov::op::v0::Squeeze>({eltwise_pattern, squeeze_axes_pattern});+ auto squeeze_axes_pattern = pattern::wrap_type<v0::Constant>();+ auto squeeze_pattern = pattern::wrap_type<v0::Squeeze>({eltwise_pattern, squeeze_axes_pattern});matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_map();@@ -54,8 +62,8 @@ ov::pass::PullSqueezeThroughEltwise::PullSqueezeThroughEltwise() {for (size_t input_index = 0; input_index < eltwise_inputs_size; ++input_index) {const auto input_node = eltwise->get_input_node_shared_ptr(input_index);// check that we will able to fuse propagated squeeze in NopElimination pass- if (!is_type<ov::op::v0::Constant>(input_node) && !is_type<ov::op::v0::Unsqueeze>(input_node) &&- !is_type<ov::op::v1::Reshape>(input_node)) {+ if (!is_type<v0::Constant>(input_node) && !is_type<v0::Unsqueeze>(input_node) &&+ !is_type<v1::Reshape>(input_node)) {return false;}}@@ -63,16 +71,16 @@ ov::pass::PullSqueezeThroughEltwise::PullSqueezeThroughEltwise() {ov::OutputVector eltwise_inputs;for (size_t input_index = 0; input_index < eltwise_inputs_size; ++input_index) {const auto eltwise_input = eltwise->input_value(input_index);- const auto new_input_node = ov::op::util::clone_try_fold(squeeze, {eltwise_input, squeeze->input_value(1)});+ const auto new_input_node = op_util::clone_try_fold(squeeze, {eltwise_input, squeeze->input_value(1)});- if (!is_type<ov::op::v0::Constant>(new_input_node))- register_new_node(as_type_ptr<ov::op::v0::Squeeze>(new_input_node));+ if (!is_type<v0::Constant>(new_input_node))+ register_new_node(as_type_ptr<v0::Squeeze>(new_input_node));ov::copy_runtime_info(squeeze, new_input_node);eltwise_inputs.push_back(new_input_node);}- const auto new_eltwise = ov::op::util::clone_try_fold(eltwise, eltwise_inputs);+ const auto new_eltwise = op_util::clone_try_fold(eltwise, eltwise_inputs);new_eltwise->set_friendly_name(squeeze->get_friendly_name());ov::copy_runtime_info({eltwise, squeeze}, new_eltwise);ov::replace_node(squeeze, new_eltwise);@@ -83,21 +91,19 @@ ov::pass::PullSqueezeThroughEltwise::PullSqueezeThroughEltwise() {this->register_matcher(m, callback);}-ov::pass::ReplaceConcatReduceByMinOrMax::ReplaceConcatReduceByMinOrMax() {+ReplaceConcatReduceByMinOrMax::ReplaceConcatReduceByMinOrMax() {MATCHER_SCOPE(ReplaceConcatReduceByMinOrMax);- auto concat_pattern =- ov::pass::pattern::wrap_type<ov::op::v0::Concat>({pattern::any_input(), pattern::any_input()});- auto reduce_axes_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto reduce_pattern = ov::pass::pattern::wrap_type<ov::op::v1::ReduceMin, ov::op::v1::ReduceMax>(- {concat_pattern, reduce_axes_pattern});+ auto concat_pattern = pattern::wrap_type<v0::Concat>({pattern::any_input(), pattern::any_input()});+ auto reduce_axes_pattern = pattern::wrap_type<v0::Constant>();+ auto reduce_pattern = pattern::wrap_type<v1::ReduceMin, v1::ReduceMax>({concat_pattern, reduce_axes_pattern});ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();- auto concat = as_type_ptr<ov::op::v0::Concat>(pattern_map.at(concat_pattern).get_node_shared_ptr());- auto reduce = as_type_ptr<ov::op::util::ArithmeticReductionKeepDims>(- pattern_map.at(reduce_pattern).get_node_shared_ptr());+ auto concat = as_type_ptr<v0::Concat>(pattern_map.at(concat_pattern).get_node_shared_ptr());+ auto reduce =+ as_type_ptr<op_util::ArithmeticReductionKeepDims>(pattern_map.at(reduce_pattern).get_node_shared_ptr());if (!reduce || !concat)return false;@@ -110,10 +116,10 @@ ov::pass::ReplaceConcatReduceByMinOrMax::ReplaceConcatReduceByMinOrMax() {std::shared_ptr<ov::Node> result_node;switch (reduce_type) {case ReduceType::MAX:- result_node = register_new_node<ov::op::v1::Maximum>(concat->input_value(0), concat->input_value(1));+ result_node = register_new_node<v1::Maximum>(concat->input_value(0), concat->input_value(1));break;case ReduceType::MIN:- result_node = register_new_node<ov::op::v1::Minimum>(concat->input_value(0), concat->input_value(1));+ result_node = register_new_node<v1::Minimum>(concat->input_value(0), concat->input_value(1));break;default:return false;@@ -122,9 +128,8 @@ ov::pass::ReplaceConcatReduceByMinOrMax::ReplaceConcatReduceByMinOrMax() {copy_runtime_info({concat, reduce}, result_node);if (!reduce->get_keep_dims()) {- const auto squeeze_axis_node =- ov::op::v0::Constant::create(ov::element::i64, {}, {*reduction_axes.begin()});- result_node = register_new_node<ov::op::v0::Squeeze>(result_node, squeeze_axis_node);+ const auto squeeze_axis_node = v0::Constant::create(ov::element::i64, {}, {*reduction_axes.begin()});+ result_node = register_new_node<v0::Squeeze>(result_node, squeeze_axis_node);copy_runtime_info({concat, reduce}, result_node);}@@ -133,12 +138,14 @@ ov::pass::ReplaceConcatReduceByMinOrMax::ReplaceConcatReduceByMinOrMax() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reduce_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(reduce_pattern, matcher_name);register_matcher(m, callback);}-ov::pass::ConcatReduceFusion::ConcatReduceFusion() {+ConcatReduceFusion::ConcatReduceFusion() {ADD_MATCHER_FOR_THIS(ReplaceConcatReduceByMinOrMax)ADD_MATCHER_FOR_THIS(PullSqueezeThroughEltwise)ADD_MATCHER_FOR_THIS(EliminateSqueeze)}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/concat_to_broadcast.cpp b/src/common/transformations/src/transformations/common_optimizations/concat_to_broadcast.cppindex 9e65cf4f150..717850df47b 100644--- a/src/common/transformations/src/transformations/common_optimizations/concat_to_broadcast.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/concat_to_broadcast.cpp@@ -13,7 +13,13 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-static bool use_broadcast(const std::shared_ptr<ov::op::v0::Concat>& concat) {+namespace v0 = ov::op::v0;++namespace ov::pass {++namespace {++static bool use_broadcast(const std::shared_ptr<v0::Concat>& concat) {const auto& output = concat->output(0);const auto& input = concat->input(0);const auto& input_concat_dim = input.get_partial_shape()[concat->get_axis()];@@ -21,10 +27,12 @@ static bool use_broadcast(const std::shared_ptr<ov::op::v0::Concat>& concat) {return input_concat_dim.is_static() && input_concat_dim.get_length() == 1 && output.get_partial_shape().is_static();}-ov::pass::ConcatToBroadcast::ConcatToBroadcast() {+} // namespace++ConcatToBroadcast::ConcatToBroadcast() {MATCHER_SCOPE(ConcatToBroadcast);- auto concat_label = pattern::wrap_type<ov::op::v0::Concat>([](const Output<Node>& value) {+ auto concat_label = pattern::wrap_type<v0::Concat>([](const Output<Node>& value) {auto node = value.get_node_shared_ptr();if (node->output(0).get_partial_shape().rank().is_dynamic()) {return false;@@ -46,7 +54,7 @@ ov::pass::ConcatToBroadcast::ConcatToBroadcast() {const auto& pattern_map = m.get_pattern_value_map();auto root_node = pattern_map.at(concat_label).get_node_shared_ptr();- auto concat = ov::as_type_ptr<ov::op::v0::Concat>(root_node);+ auto concat = ov::as_type_ptr<v0::Concat>(root_node);if (!concat) {return false;}@@ -59,9 +67,9 @@ ov::pass::ConcatToBroadcast::ConcatToBroadcast() {std::shared_ptr<Node> replacement;if (use_broadcast(concat)) {- auto target_shape = std::make_shared<ov::op::v0::Constant>(ov::element::i32,- Shape{concat->output(0).get_shape().size()},- concat->output(0).get_shape());+ auto target_shape = std::make_shared<v0::Constant>(ov::element::i32,+ Shape{concat->output(0).get_shape().size()},+ concat->output(0).get_shape());replacement = std::make_shared<ov::op::v3::Broadcast>(input, target_shape);} else {return false;@@ -73,8 +81,8 @@ ov::pass::ConcatToBroadcast::ConcatToBroadcast() {repeat_num_vec[concat->get_concatenation_axis()] = concat->get_input_size();auto repeat_num =- std::make_shared<ov::op::v0::Constant>(ov::element::i32, Shape{repeat_num_vec.size()}, repeat_num_vec);- replacement = std::make_shared<ov::op::v0::Tile>(input, repeat_num);+ std::make_shared<v0::Constant>(ov::element::i32, Shape{repeat_num_vec.size()}, repeat_num_vec);+ replacement = std::make_shared<v0::Tile>(input, repeat_num);}*/@@ -89,3 +97,5 @@ ov::pass::ConcatToBroadcast::ConcatToBroadcast() {auto m = std::make_shared<pattern::Matcher>(concat_label, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp b/src/common/transformations/src/transformations/common_optimizations/constants_reduce.cppindex ed7be504683..470cbc09269 100644--- a/src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/constants_reduce.cpp@@ -8,6 +8,7 @@#include "openvino/op/constant.hpp"#include "openvino/util/log.hpp"+namespace v0 = ov::op::v0;#define LARGE_TENSOR_BYTE_SIZE 64namespace ov::pass {@@ -18,7 +19,7 @@ struct KeyHash {std::size_t operator()(const BlobCacheKey& key) const {std::size_t hash = 0;- auto node = ov::as_type_ptr<ov::op::v0::Constant>(key);+ auto node = ov::as_type_ptr<v0::Constant>(key);auto type = node->get_output_element_type(0);auto shape = node->get_shape();@@ -42,8 +43,8 @@ struct KeyHash {struct KeyEqual {bool operator()(const BlobCacheKey& lhs, const BlobCacheKey& rhs) const {- auto lhs_node = ov::as_type_ptr<ov::op::v0::Constant>(lhs);- auto rhs_node = ov::as_type_ptr<ov::op::v0::Constant>(rhs);+ auto lhs_node = ov::as_type_ptr<v0::Constant>(lhs);+ auto rhs_node = ov::as_type_ptr<v0::Constant>(rhs);auto lhs_type = lhs_node->get_output_element_type(0);auto rhs_type = rhs_node->get_output_element_type(0);@@ -84,10 +85,10 @@ bool ConstantsReduce::run_on_model(const std::shared_ptr<ov::Model>& m) {unsigned int copies = 0;for (auto& op : ops) {- if (!ov::is_type<ov::op::v0::Constant>(op))+ if (!ov::is_type<v0::Constant>(op))continue;- auto const_node = ov::as_type_ptr<ov::op::v0::Constant>(op);+ auto const_node = ov::as_type_ptr<v0::Constant>(op);// Limit size of node reading to avoid reading large tensorsif (const_node->get_byte_size() > LARGE_TENSOR_BYTE_SIZE)diff --git a/src/common/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/conv_mul_fusion.cppindex 2511a74072e..8d02db35e61 100644--- a/src/common/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/conv_mul_fusion.cpp@@ -16,13 +16,19 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ConvolutionMultiplyFusion::ConvolutionMultiplyFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {++ConvolutionMultiplyFusion::ConvolutionMultiplyFusion() {MATCHER_SCOPE(ConvolutionMultiplyFusion);auto input = pattern::any_input();- auto weights = pass::pattern::any_input(pattern::has_static_dim(0) /* has OIYX layout */);- auto conv = pattern::wrap_type<ov::op::v1::Convolution>({input, weights}, pattern::consumers_count(1));- auto mul_const = pattern::wrap_type<ov::op::v0::Constant>(pattern::has_static_shape());- auto mul = pattern::wrap_type<ov::op::v1::Multiply>({conv, mul_const});+ auto weights = pattern::any_input(ov::pass::pattern::has_static_dim(0) /* has OIYX layout */);+ auto conv = pattern::wrap_type<v1::Convolution>({input, weights}, pattern::consumers_count(1));+ auto mul_const = pattern::wrap_type<v0::Constant>(pattern::has_static_shape());+ auto mul = pattern::wrap_type<v1::Multiply>({conv, mul_const});matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();@@ -47,7 +53,7 @@ ov::pass::ConvolutionMultiplyFusion::ConvolutionMultiplyFusion() {auto expected_shape = Shape(weights_rank, 1);expected_shape[1] = channel_dim;- if (!ov::op::util::check_for_broadcast(expected_shape, const_shape)) {+ if (!op_util::check_for_broadcast(expected_shape, const_shape)) {return false;}@@ -58,14 +64,14 @@ ov::pass::ConvolutionMultiplyFusion::ConvolutionMultiplyFusion() {if (!is_scalar_multiplier) {auto final_const_shape = Shape(weights_rank, 1);final_const_shape[0] = channel_dim;- final_const = std::make_shared<ov::op::v1::Reshape>(+ final_const = std::make_shared<v1::Reshape>(m_const,- ov::op::v0::Constant::create(element::i64, Shape{final_const_shape.size()}, final_const_shape),+ v0::Constant::create(element::i64, Shape{final_const_shape.size()}, final_const_shape),true);}// Multiply convolution weights with aligned Constant values- auto weights_multiply = std::make_shared<ov::op::v1::Multiply>(m_weights, final_const);+ auto weights_multiply = std::make_shared<v1::Multiply>(m_weights, final_const);// Replace Convolution->Multiply with Convolution with new inputsauto new_conv = m_conv->clone_with_new_inputs({m_input, weights_multiply});@@ -79,13 +85,13 @@ ov::pass::ConvolutionMultiplyFusion::ConvolutionMultiplyFusion() {register_matcher(m, callback);}-ov::pass::GroupConvolutionMultiplyFusion::GroupConvolutionMultiplyFusion() {+GroupConvolutionMultiplyFusion::GroupConvolutionMultiplyFusion() {MATCHER_SCOPE(GroupConvolutionMultiplyFusion);auto input = pattern::any_input();- auto weights = pass::pattern::any_input(pattern::has_static_dims({0, 1}) /* has GOIYX layout */);- auto conv = pattern::wrap_type<ov::op::v1::GroupConvolution>({input, weights}, pattern::consumers_count(1));- auto mul_const = pattern::wrap_type<ov::op::v0::Constant>(); // pattern::has_static_shape());- auto mul = pattern::wrap_type<ov::op::v1::Multiply>({conv, mul_const});+ auto weights = pattern::any_input(ov::pass::pattern::has_static_dims({0, 1}) /* has GOIYX layout */);+ auto conv = pattern::wrap_type<v1::GroupConvolution>({input, weights}, pattern::consumers_count(1));+ auto mul_const = pattern::wrap_type<v0::Constant>(); // has_static_shape());+ auto mul = pattern::wrap_type<v1::Multiply>({conv, mul_const});matcher_pass_callback callback = [conv, input, weights, mul, mul_const](pattern::Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();@@ -111,11 +117,11 @@ ov::pass::GroupConvolutionMultiplyFusion::GroupConvolutionMultiplyFusion() {auto expected_shape = Shape(weights_rank - 1, 1);expected_shape[1] = G * O;- if (!ov::op::util::check_for_broadcast(expected_shape, const_shape)) {+ if (!op_util::check_for_broadcast(expected_shape, const_shape)) {return false;}- auto reshape = ov::as_type_ptr<ov::op::v1::Reshape>(m_weights.get_node_shared_ptr());+ auto reshape = ov::as_type_ptr<v1::Reshape>(m_weights.get_node_shared_ptr());bool are_weights_reshaped = reshape != nullptr;if (are_weights_reshaped) {m_weights = reshape->input_value(0);@@ -141,14 +147,14 @@ ov::pass::GroupConvolutionMultiplyFusion::GroupConvolutionMultiplyFusion() {final_const_shape[0] = G;final_const_shape[1] = O;}- final_const = std::make_shared<ov::op::v1::Reshape>(+ final_const = std::make_shared<v1::Reshape>(m_const,- ov::op::v0::Constant::create(element::i64, Shape{final_const_shape.size()}, final_const_shape),+ v0::Constant::create(element::i64, Shape{final_const_shape.size()}, final_const_shape),true);}// Multiply convolution weights with aligned Constant values- auto new_weights = std::make_shared<ov::op::v1::Multiply>(m_weights, final_const);+ auto new_weights = std::make_shared<v1::Multiply>(m_weights, final_const);if (are_weights_reshaped) {reshape->input(0).replace_source_output(new_weights);} else {@@ -165,17 +171,16 @@ ov::pass::GroupConvolutionMultiplyFusion::GroupConvolutionMultiplyFusion() {register_matcher(m, callback);}-ov::pass::ConvolutionBackpropDataMultiplyFusion::ConvolutionBackpropDataMultiplyFusion() {+ConvolutionBackpropDataMultiplyFusion::ConvolutionBackpropDataMultiplyFusion() {MATCHER_SCOPE(ConvolutionBackpropDataMultiplyFusion);auto input = pattern::any_input();- auto weights = pass::pattern::any_input(pattern::has_static_dim(1) /* has IOYX layout */);- auto conv_2_inputs =- pattern::wrap_type<ov::op::v1::ConvolutionBackpropData>({input, weights}, pattern::consumers_count(1));- auto conv_3_inputs = pattern::wrap_type<ov::op::v1::ConvolutionBackpropData>({input, weights, pattern::any_input()},- pattern::consumers_count(1));+ auto weights = pattern::any_input(ov::pass::pattern::has_static_dim(1) /* has IOYX layout */);+ auto conv_2_inputs = pattern::wrap_type<v1::ConvolutionBackpropData>({input, weights}, pattern::consumers_count(1));+ auto conv_3_inputs = pattern::wrap_type<v1::ConvolutionBackpropData>({input, weights, pattern::any_input()},+ pattern::consumers_count(1));auto conv = std::make_shared<pattern::op::Or>(OutputVector{conv_2_inputs, conv_3_inputs});- auto mul_const = pattern::wrap_type<ov::op::v0::Constant>(pattern::has_static_shape());- auto mul = pattern::wrap_type<ov::op::v1::Multiply>({conv, mul_const});+ auto mul_const = pattern::wrap_type<v0::Constant>(pattern::has_static_shape());+ auto mul = pattern::wrap_type<v1::Multiply>({conv, mul_const});matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();@@ -199,7 +204,7 @@ ov::pass::ConvolutionBackpropDataMultiplyFusion::ConvolutionBackpropDataMultiplyauto expected_shape = Shape(weights_rank, 1);expected_shape[1] = channel_dim;- if (!ov::op::util::check_for_broadcast(expected_shape, const_shape)) {+ if (!op_util::check_for_broadcast(expected_shape, const_shape)) {return false;}@@ -210,14 +215,14 @@ ov::pass::ConvolutionBackpropDataMultiplyFusion::ConvolutionBackpropDataMultiplyif (!is_scalar_multiplier) {auto final_const_shape = Shape(weights_rank - 1, 1);final_const_shape[0] = channel_dim;- final_const = std::make_shared<ov::op::v1::Reshape>(+ final_const = std::make_shared<v1::Reshape>(m_const,- ov::op::v0::Constant::create(element::i64, Shape{final_const_shape.size()}, final_const_shape),+ v0::Constant::create(element::i64, Shape{final_const_shape.size()}, final_const_shape),true);}// Multiply convolution weights with aligned Constant values- auto weights_multiply = std::make_shared<ov::op::v1::Multiply>(m_weights, final_const);+ auto weights_multiply = std::make_shared<v1::Multiply>(m_weights, final_const);// Replace Convolution->Multiply with Convolution with new inputsstd::shared_ptr<Node> new_conv;@@ -240,18 +245,17 @@ ov::pass::ConvolutionBackpropDataMultiplyFusion::ConvolutionBackpropDataMultiplyregister_matcher(m, callback);}-ov::pass::GroupConvolutionBackpropDataMultiplyFusion::GroupConvolutionBackpropDataMultiplyFusion() {+GroupConvolutionBackpropDataMultiplyFusion::GroupConvolutionBackpropDataMultiplyFusion() {MATCHER_SCOPE(GroupConvolutionBackpropDataMultiplyFusion);auto input = pattern::any_input();- auto weights = pass::pattern::any_input(pattern::has_static_dims({0, 2}) /* has GIOYX layout */);+ auto weights = pattern::any_input(ov::pass::pattern::has_static_dims({0, 2}) /* has GIOYX layout */);auto conv_2_inputs =- pattern::wrap_type<ov::op::v1::GroupConvolutionBackpropData>({input, weights}, pattern::consumers_count(1));- auto conv_3_inputs =- pattern::wrap_type<ov::op::v1::GroupConvolutionBackpropData>({input, weights, pattern::any_input()},- pattern::consumers_count(1));+ pattern::wrap_type<v1::GroupConvolutionBackpropData>({input, weights}, pattern::consumers_count(1));+ auto conv_3_inputs = pattern::wrap_type<v1::GroupConvolutionBackpropData>({input, weights, pattern::any_input()},+ pattern::consumers_count(1));auto conv = std::make_shared<pattern::op::Or>(OutputVector{conv_2_inputs, conv_3_inputs});- auto mul_const = pattern::wrap_type<ov::op::v0::Constant>(pattern::has_static_shape());- auto mul = pattern::wrap_type<ov::op::v1::Multiply>({conv, mul_const});+ auto mul_const = pattern::wrap_type<v0::Constant>(pattern::has_static_shape());+ auto mul = pattern::wrap_type<v1::Multiply>({conv, mul_const});matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();@@ -276,7 +280,7 @@ ov::pass::GroupConvolutionBackpropDataMultiplyFusion::GroupConvolutionBackpropDaauto expected_shape = Shape(weights_rank - 1, 1);expected_shape[1] = G * O;- if (!ov::op::util::check_for_broadcast(expected_shape, const_shape)) {+ if (!op_util::check_for_broadcast(expected_shape, const_shape)) {return false;}@@ -288,14 +292,14 @@ ov::pass::GroupConvolutionBackpropDataMultiplyFusion::GroupConvolutionBackpropDaauto final_const_shape = Shape(weights_rank, 1);final_const_shape[0] = G;final_const_shape[2] = O;- final_const = std::make_shared<ov::op::v1::Reshape>(+ final_const = std::make_shared<v1::Reshape>(m_const,- ov::op::v0::Constant::create(element::i64, Shape{final_const_shape.size()}, final_const_shape),+ v0::Constant::create(element::i64, Shape{final_const_shape.size()}, final_const_shape),true);}// Multiply convolution weights with aligned Constant values- auto weights_multiply = std::make_shared<ov::op::v1::Multiply>(m_weights, final_const);+ auto weights_multiply = std::make_shared<v1::Multiply>(m_weights, final_const);// Replace Convolution->Multiply with Convolution with new inputsstd::shared_ptr<Node> new_conv;@@ -317,3 +321,5 @@ ov::pass::GroupConvolutionBackpropDataMultiplyFusion::GroupConvolutionBackpropDaauto m = std::make_shared<pattern::Matcher>(mul, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/conv_to_binary_conv.cpp b/src/common/transformations/src/transformations/common_optimizations/conv_to_binary_conv.cppindex 7ce531ace20..1c3a7a52a4f 100644--- a/src/common/transformations/src/transformations/common_optimizations/conv_to_binary_conv.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/conv_to_binary_conv.cpp@@ -21,6 +21,13 @@#include "openvino/op/reshape.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++namespace {+static std::vector<uint8_t> binarize_weights(const std::vector<float>& weights) {std::vector<uint8_t> out;size_t bits_per_byte = 8;@@ -36,27 +43,27 @@ static std::vector<uint8_t> binarize_weights(const std::vector<float>& weights)return out;}-ov::pass::ConvToBinaryConv::ConvToBinaryConv() {+} // namespace++ConvToBinaryConv::ConvToBinaryConv() {MATCHER_SCOPE(ConvToBinaryConv);- auto fq_pattern =- ov::pass::pattern::wrap_type<ov::op::v0::FakeQuantize>({pattern::any_input(),- pattern::any_input(),- pattern::any_input(),- ov::pass::pattern::wrap_type<ov::op::v0::Constant>(),- ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},- pattern::consumers_count(1));- auto conv_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Convolution>(- {fq_pattern, ov::pass::pattern::wrap_type<ov::op::v0::Constant>()});+ auto fq_pattern = pattern::wrap_type<v0::FakeQuantize>({pattern::any_input(),+ pattern::any_input(),+ pattern::any_input(),+ pattern::wrap_type<v0::Constant>(),+ pattern::wrap_type<v0::Constant>()},+ ov::pass::pattern::consumers_count(1));+ auto conv_pattern = pattern::wrap_type<v1::Convolution>({fq_pattern, pattern::wrap_type<v0::Constant>()});ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto conv = ov::as_type_ptr<ov::op::v1::Convolution>(m.get_match_root());+ auto conv = ov::as_type_ptr<v1::Convolution>(m.get_match_root());if (!conv)return false;- auto fq = ov::as_type_ptr<ov::op::v0::FakeQuantize>(conv->input_value(0).get_node_shared_ptr());+ auto fq = ov::as_type_ptr<v0::FakeQuantize>(conv->input_value(0).get_node_shared_ptr());if (!fq || fq->get_levels() != 2)return false;- auto output_low_constant = ov::as_type_ptr<ov::op::v0::Constant>(fq->input_value(3).get_node_shared_ptr());+ auto output_low_constant = ov::as_type_ptr<v0::Constant>(fq->input_value(3).get_node_shared_ptr());if (!output_low_constant)return false;auto output_low = output_low_constant->cast_vector<float>();@@ -66,7 +73,7 @@ ov::pass::ConvToBinaryConv::ConvToBinaryConv() {bool output_low_is_minus_one = std::all_of(output_low.begin(), output_low.end(), [](float f) -> bool {return f == -1.0f;});- auto output_high_constant = ov::as_type_ptr<ov::op::v0::Constant>(fq->input_value(4).get_node_shared_ptr());+ auto output_high_constant = ov::as_type_ptr<v0::Constant>(fq->input_value(4).get_node_shared_ptr());if (!output_high_constant)return false;auto output_high = output_high_constant->cast_vector<float>();@@ -77,7 +84,7 @@ ov::pass::ConvToBinaryConv::ConvToBinaryConv() {if (!(output_high_is_one && (output_low_is_zero || output_low_is_minus_one)))return false;- auto weights_constant = ov::as_type_ptr<ov::op::v0::Constant>(conv->input_value(1).get_node_shared_ptr());+ auto weights_constant = ov::as_type_ptr<v0::Constant>(conv->input_value(1).get_node_shared_ptr());if (!weights_constant)return false;@@ -89,19 +96,19 @@ ov::pass::ConvToBinaryConv::ConvToBinaryConv() {auto bin_weights = binarize_weights(weights);auto bin_weights_constant =- std::make_shared<ov::op::v0::Constant>(element::u1, weights_constant->get_shape(), bin_weights.data());+ std::make_shared<v0::Constant>(element::u1, weights_constant->get_shape(), bin_weights.data());if (output_low_is_zero && output_high_is_one) {- auto new_conv = std::make_shared<ov::op::v1::BinaryConvolution>(- conv->input_value(0),- bin_weights_constant,- conv->get_strides(),- conv->get_pads_begin(),- conv->get_pads_end(),- conv->get_dilations(),- ov::op::v1::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT,- -1.f,- conv->get_auto_pad());+ auto new_conv =+ std::make_shared<v1::BinaryConvolution>(conv->input_value(0),+ bin_weights_constant,+ conv->get_strides(),+ conv->get_pads_begin(),+ conv->get_pads_end(),+ conv->get_dilations(),+ v1::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT,+ -1.f,+ conv->get_auto_pad());new_conv->set_friendly_name(conv->get_friendly_name());std::vector<int64_t> axes;std::vector<int64_t> weights_reduced_shape = {-1};@@ -111,34 +118,33 @@ ov::pass::ConvToBinaryConv::ConvToBinaryConv() {for (size_t i = 2; i < weights_constant->get_shape().size(); i++) {weights_reduced_shape.push_back(1);}- auto weights_reduced = std::make_shared<ov::op::v1::ReduceSum>(- ov::op::v0::Constant::create(element::f32, weights_constant->get_shape(), weights),- ov::op::v0::Constant::create(element::i64, Shape{axes.size()}, axes),+ auto weights_reduced = std::make_shared<v1::ReduceSum>(+ v0::Constant::create(element::f32, weights_constant->get_shape(), weights),+ v0::Constant::create(element::i64, Shape{axes.size()}, axes),false);- std::shared_ptr<Node> weights_reduced_reshaped = std::make_shared<ov::op::v1::Reshape>(+ std::shared_ptr<Node> weights_reduced_reshaped = std::make_shared<v1::Reshape>(weights_reduced,- ov::op::v0::Constant::create(element::i64, Shape{weights_reduced_shape.size()}, weights_reduced_shape),+ v0::Constant::create(element::i64, Shape{weights_reduced_shape.size()}, weights_reduced_shape),false);weights_reduced_reshaped = ov::util::get_constant_from_source(weights_reduced_reshaped);- auto add = std::make_shared<ov::op::v1::Add>(new_conv, weights_reduced_reshaped);- auto mul =- std::make_shared<ov::op::v1::Multiply>(add, ov::op::v0::Constant::create(element::f32, Shape{}, {0.5}));+ auto add = std::make_shared<v1::Add>(new_conv, weights_reduced_reshaped);+ auto mul = std::make_shared<v1::Multiply>(add, v0::Constant::create(element::f32, Shape{}, {0.5}));copy_runtime_info(conv, {new_conv, add, mul});replace_node(conv, mul);return true;}- auto new_conv = std::make_shared<ov::op::v1::BinaryConvolution>(- conv->input_value(0),- bin_weights_constant,- conv->get_strides(),- conv->get_pads_begin(),- conv->get_pads_end(),- conv->get_dilations(),- ov::op::v1::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT,- 0.f,- conv->get_auto_pad());+ auto new_conv =+ std::make_shared<v1::BinaryConvolution>(conv->input_value(0),+ bin_weights_constant,+ conv->get_strides(),+ conv->get_pads_begin(),+ conv->get_pads_end(),+ conv->get_dilations(),+ v1::BinaryConvolution::BinaryConvolutionMode::XNOR_POPCOUNT,+ 0.f,+ conv->get_auto_pad());new_conv->set_friendly_name(conv->get_friendly_name());copy_runtime_info(conv, new_conv);@@ -147,6 +153,8 @@ ov::pass::ConvToBinaryConv::ConvToBinaryConv() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(conv_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(conv_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp b/src/common/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cppindex 176ecfd14d9..d352657afa1 100644--- a/src/common/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/convert_nms_gather_path_to_unsigned.cpp@@ -27,14 +27,19 @@using namespace std;-namespace ov {-namespace pass {-class InitNMSPath : public pass::MatcherPass {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;++namespace ov::pass {++class InitNMSPath : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("InitNMSPath");InitNMSPath() {MATCHER_SCOPE(InitNMSPath);- auto nms_pattern = pattern::wrap_type<ov::op::v1::NonMaxSuppression,+ auto nms_pattern = pattern::wrap_type<v1::NonMaxSuppression,ov::op::v3::NonMaxSuppression,ov::op::v5::NonMaxSuppression,ov::op::v9::NonMaxSuppression>();@@ -49,22 +54,23 @@ public:register_matcher(m, callback);}};-class PropagateNMSPath : public pass::MatcherPass {++class PropagateNMSPath : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("PropagateNMSPath");PropagateNMSPath() {MATCHER_SCOPE(PropagateNMSPath);- auto node_pattern = pattern::wrap_type<ov::op::v0::Squeeze,- ov::op::v0::Unsqueeze,- ov::op::v1::Reshape,- ov::op::util::BroadcastBase,- ov::op::v1::StridedSlice,- ov::op::v8::Slice,- ov::op::v1::VariadicSplit,- ov::op::util::GatherBase,- ov::op::v0::Concat,- ov::op::v0::Convert,- ov::op::v8::If>();+ auto node_pattern = pattern::wrap_type<v0::Squeeze,+ v0::Unsqueeze,+ v1::Reshape,+ op_util::BroadcastBase,+ v1::StridedSlice,+ v8::Slice,+ v1::VariadicSplit,+ op_util::GatherBase,+ v0::Concat,+ v0::Convert,+ v8::If>();matcher_pass_callback callback = [=](pattern::Matcher& m) {auto propagate_path = [](const ov::OutputVector& input_nodes, ov::Node* target_node) {if (any_of(input_nodes.begin(), input_nodes.end(), [](const Output<Node>& output) {@@ -73,7 +79,7 @@ public:ov::set_nms_selected_indices(target_node);}};- auto handle_params = [&propagate_path](std::shared_ptr<ov::op::util::MultiSubGraphOp> node,+ auto handle_params = [&propagate_path](std::shared_ptr<op_util::MultiSubGraphOp> node,std::shared_ptr<ov::Model> body,int body_index) {const auto& params = body->get_parameters();@@ -83,7 +89,7 @@ public:propagate_path({input_node}, param.get());}};- auto handle_results = [&propagate_path](std::shared_ptr<ov::op::util::MultiSubGraphOp> node,+ auto handle_results = [&propagate_path](std::shared_ptr<op_util::MultiSubGraphOp> node,std::shared_ptr<ov::Model> body,int body_index) {const auto& results = body->get_results();@@ -96,13 +102,13 @@ public:};auto node = m.get_match_root();- if (auto multi_subgraph_op = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(node)) {+ if (auto multi_subgraph_op = ov::as_type_ptr<op_util::MultiSubGraphOp>(node)) {const auto& models = multi_subgraph_op->get_functions();for (size_t body_idx = 0; body_idx < models.size(); ++body_idx) {handle_params(multi_subgraph_op, models[body_idx], static_cast<int>(body_idx));ov::pass::Manager manager("PropagateNMSPath");- manager.register_pass<ov::pass::PropagateNMSPath>();+ manager.register_pass<PropagateNMSPath>();manager.run_passes(models[body_idx]);handle_results(multi_subgraph_op, models[body_idx], static_cast<int>(body_idx));}@@ -116,12 +122,13 @@ public:register_matcher(m, callback);}};-class UpdateConvertGather : public pass::MatcherPass {++class UpdateConvertGather : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("UpdateConvertGather");UpdateConvertGather() {MATCHER_SCOPE(UpdateConvertGather);- auto node_pattern = pattern::wrap_type<ov::op::util::GatherBase>();+ auto node_pattern = pattern::wrap_type<op_util::GatherBase>();matcher_pass_callback callback = [=](pattern::Matcher& m) {auto gather = m.get_match_root();auto indices = gather->input_value(1);@@ -129,12 +136,12 @@ public:return false;gather->get_rt_info()["dontReverseIndices"] = true;auto out_type = (indices.get_element_type() == element::i64 ? element::u64 : element::u32);- auto existing_convert = ov::as_type_ptr<ov::op::v0::Convert>(indices.get_node_shared_ptr());+ auto existing_convert = ov::as_type_ptr<v0::Convert>(indices.get_node_shared_ptr());if (existing_convert && indices.get_target_inputs().size() == 1) {existing_convert->set_convert_element_type(out_type);existing_convert->validate_and_infer_types();} else {- auto new_convert_to_unsigned = make_shared<ov::op::v0::Convert>(indices, out_type);+ auto new_convert_to_unsigned = make_shared<v0::Convert>(indices, out_type);gather->input(1).replace_source_output(new_convert_to_unsigned);copy_runtime_info(gather, new_convert_to_unsigned);}@@ -144,11 +151,11 @@ public:register_matcher(m, callback);}};-} // namespace pass-} // namespace ov-ov::pass::ConvertNmsGatherPathToUnsigned::ConvertNmsGatherPathToUnsigned() {+ConvertNmsGatherPathToUnsigned::ConvertNmsGatherPathToUnsigned() {ADD_MATCHER_FOR_THIS(InitNMSPath)ADD_MATCHER_FOR_THIS(PropagateNMSPath)ADD_MATCHER_FOR_THIS(UpdateConvertGather)}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp b/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cppindex 65b8da6beda..2a75c1385c3 100644--- a/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/convert_pagedattn_inputs.cpp@@ -17,9 +17,12 @@#include "transformations/utils/utils.hpp"using namespace ov::pass;-using namespace ov::op;-ov::pass::ConvertPagedAttnInputs::ConvertPagedAttnInputs(const KVCacheConfig& config, UpdateShapeFunc func)+namespace v0 = ov::op::v0;++namespace ov::pass {++ConvertPagedAttnInputs::ConvertPagedAttnInputs(const KVCacheConfig& config, UpdateShapeFunc func): m_config(config),m_update_shape_func(std::move(func)) {MATCHER_SCOPE(ConvertPagedAttnInputs);@@ -153,10 +156,12 @@ ov::pass::ConvertPagedAttnInputs::ConvertPagedAttnInputs(const KVCacheConfig& cothis->register_matcher(m, callback);}-void ov::pass::ConvertPagedAttnInputs::setKVCacheConfig(const KVCacheConfig& config) {+void ConvertPagedAttnInputs::setKVCacheConfig(const KVCacheConfig& config) {m_config = config;}-const ov::pass::ConvertPagedAttnInputs::KVCacheConfig& ov::pass::ConvertPagedAttnInputs::getKVCacheConfig() const {+const ConvertPagedAttnInputs::KVCacheConfig& ConvertPagedAttnInputs::getKVCacheConfig() const {return m_config;}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/convert_quantize_dequantize.cpp b/src/common/transformations/src/transformations/common_optimizations/convert_quantize_dequantize.cppindex d228ddb0fec..69ecf93d5fb 100644--- a/src/common/transformations/src/transformations/common_optimizations/convert_quantize_dequantize.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/convert_quantize_dequantize.cpp@@ -20,6 +20,12 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {+// ConvertQuantizeDequantize converts Quantize/Dequantize pair to a single FakeQuantize.// Since Quantize is decomposed to FakeQuantize and Dequantize is decomposed to Subtract->Multiply,// the full pattern to match is presented on the left hand side of the graph below.@@ -63,39 +69,36 @@// v//-ov::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize(- const ov::element::TypeVector& supported_low_precisions,- const ov::element::TypeVector& supported_original_precisions,- const bool ignore_consumers_count_check) {+ConvertQuantizeDequantize::ConvertQuantizeDequantize(const ov::element::TypeVector& supported_low_precisions,+ const ov::element::TypeVector& supported_original_precisions,+ const bool ignore_consumers_count_check) {MATCHER_SCOPE(ConvertQuantizeDequantize);-- using namespace ov::pass::pattern;- using namespace ov::op;-- auto data_pattern = any_input(type_matches_any(supported_original_precisions));- auto input_low_pattern = any_input();- auto input_high_pattern = any_input();- auto output_low_pattern = wrap_type<v0::Constant>();- auto output_high_pattern = wrap_type<v0::Constant>();- auto fq_pattern = wrap_type<v0::FakeQuantize>(+ auto data_pattern = pattern::any_input(pattern::type_matches_any(supported_original_precisions));+ auto input_low_pattern = pattern::any_input();+ auto input_high_pattern = pattern::any_input();+ auto output_low_pattern = pattern::wrap_type<v0::Constant>();+ auto output_high_pattern = pattern::wrap_type<v0::Constant>();+ auto fq_pattern = pattern::wrap_type<v0::FakeQuantize>({data_pattern, input_low_pattern, input_high_pattern, output_low_pattern, output_high_pattern});ov::pass::pattern::op::Predicate convert1_predicate =- ignore_consumers_count_check ? type_matches_any(supported_low_precisions)- : type_matches_any(supported_low_precisions) && consumers_count(1);- auto convert1_pattern = wrap_type<v0::Convert>({fq_pattern}, convert1_predicate);+ ignore_consumers_count_check+ ? pattern::type_matches_any(supported_low_precisions)+ : pattern::type_matches_any(supported_low_precisions) && pattern::consumers_count(1);+ auto convert1_pattern = pattern::wrap_type<v0::Convert>({fq_pattern}, convert1_predicate);ov::pass::pattern::op::Predicate convert2_predicate =- ignore_consumers_count_check ? type_matches_any(supported_original_precisions)- : type_matches_any(supported_original_precisions) && consumers_count(1);- auto convert2_pattern = wrap_type<v0::Convert>({convert1_pattern}, convert2_predicate);+ ignore_consumers_count_check+ ? pattern::type_matches_any(supported_original_precisions)+ : pattern::type_matches_any(supported_original_precisions) && pattern::consumers_count(1);+ auto convert2_pattern = pattern::wrap_type<v0::Convert>({convert1_pattern}, convert2_predicate);- auto zero_point_pattern = any_input();+ auto zero_point_pattern = pattern::any_input();ov::pass::pattern::op::Predicate sub_predicate =- ignore_consumers_count_check ? ov::pass::pattern::op::Predicate() : consumers_count(1);- auto sub_pattern = optional<v1::Subtract>({convert2_pattern, zero_point_pattern}, sub_predicate);- auto scale_pattern = any_input();- auto mul_pattern = wrap_type<v1::Multiply>({sub_pattern, scale_pattern});+ ignore_consumers_count_check ? ov::pass::pattern::op::Predicate() : pattern::consumers_count(1);+ auto sub_pattern = pattern::optional<v1::Subtract>({convert2_pattern, zero_point_pattern}, sub_predicate);+ auto scale_pattern = pattern::any_input();+ auto mul_pattern = pattern::wrap_type<v1::Multiply>({sub_pattern, scale_pattern});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto pattern_map = m.get_pattern_value_map();if (transformation_callback(m.get_match_root())) {@@ -105,15 +108,13 @@ ov::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize(auto data = pattern_map.at(data_pattern);auto input_low = pattern_map.at(input_low_pattern);auto input_high = pattern_map.at(input_high_pattern);- auto output_low =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(output_low_pattern).get_node_shared_ptr());+ auto output_low = ov::as_type_ptr<v0::Constant>(pattern_map.at(output_low_pattern).get_node_shared_ptr());if (!output_low)return false;- auto output_high =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(output_high_pattern).get_node_shared_ptr());+ auto output_high = ov::as_type_ptr<v0::Constant>(pattern_map.at(output_high_pattern).get_node_shared_ptr());if (!output_high)return false;- auto fq = ov::as_type_ptr<ov::op::v0::FakeQuantize>(pattern_map.at(fq_pattern).get_node_shared_ptr());+ auto fq = ov::as_type_ptr<v0::FakeQuantize>(pattern_map.at(fq_pattern).get_node_shared_ptr());if (!fq)return false;auto scale = pattern_map.at(scale_pattern);@@ -127,10 +128,10 @@ ov::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize(return false;float out_low_val;- if (!ov::op::util::get_single_value(output_low, out_low_val))+ if (!op_util::get_single_value(output_low, out_low_val))return false;float out_high_val;- if (!ov::op::util::get_single_value(output_high, out_high_val))+ if (!op_util::get_single_value(output_high, out_high_val))return false;#define PRECISION_LIMITS_FOR(type) \@@ -158,11 +159,11 @@ ov::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize(std::shared_ptr<Node> new_out_low = output_low, new_out_high = output_high;if (has_zero_point) {const auto& zero_point = pattern_map.at(zero_point_pattern);- new_out_low = std::make_shared<ov::op::v1::Subtract>(new_out_low, zero_point);- new_out_high = std::make_shared<ov::op::v1::Subtract>(new_out_high, zero_point);+ new_out_low = std::make_shared<v1::Subtract>(new_out_low, zero_point);+ new_out_high = std::make_shared<v1::Subtract>(new_out_high, zero_point);}- new_out_low = std::make_shared<ov::op::v1::Multiply>(new_out_low, scale);- new_out_high = std::make_shared<ov::op::v1::Multiply>(new_out_high, scale);+ new_out_low = std::make_shared<v1::Multiply>(new_out_low, scale);+ new_out_high = std::make_shared<v1::Multiply>(new_out_high, scale);// check if new_out_low/high shapes are broadcastable to FQ's inputauto data_shape = data.get_partial_shape();@@ -183,7 +184,7 @@ ov::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize(new_out_high = const_out_high;auto new_fq =- std::make_shared<ov::op::v0::FakeQuantize>(data, input_low, input_high, new_out_low, new_out_high, levels);+ std::make_shared<v0::FakeQuantize>(data, input_low, input_high, new_out_low, new_out_high, levels);new_fq->set_friendly_name(mul->get_friendly_name());copy_runtime_info({fq, convert1.get_node_shared_ptr(), convert2.get_node_shared_ptr()}, new_fq);@@ -192,6 +193,8 @@ ov::pass::ConvertQuantizeDequantize::ConvertQuantizeDequantize(return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(mul_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp b/src/common/transformations/src/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.cppindex 5ad3f5654ed..f8a1a353476 100644--- a/src/common/transformations/src/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp@@ -14,36 +14,40 @@#include "openvino/reference/autobroadcast_binop.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ConvertU4WeightsZeroPointToScalar::ConvertU4WeightsZeroPointToScalar() {+namespace v0 = ov::op::v0;++namespace ov::pass {++ConvertU4WeightsZeroPointToScalar::ConvertU4WeightsZeroPointToScalar() {MATCHER_SCOPE(ConvertU4WeightsZeroPointToScalar);- auto weights_m = pattern::wrap_type<ov::op::v0::Constant>(pattern::type_matches(ov::element::u4));- auto convert_m = pattern::wrap_type<ov::op::v0::Convert>({weights_m}, pattern::consumers_count(1));+ auto weights_m = pattern::wrap_type<v0::Constant>(pattern::type_matches(ov::element::u4));+ auto convert_m = pattern::wrap_type<v0::Convert>({weights_m}, pattern::consumers_count(1));auto float_zp_predicate = [](ov::Output<ov::Node> output) -> bool {- return pattern::type_matches_any({ov::element::f32, ov::element::f16})(output) &&+ return ov::pass::pattern::type_matches_any({ov::element::f32, ov::element::f16})(output) &&pattern::consumers_count(1)(output);};- auto float_zero_point_m = pattern::wrap_type<ov::op::v0::Constant>(float_zp_predicate);+ auto float_zero_point_m = pattern::wrap_type<v0::Constant>(float_zp_predicate);auto u4_zp_predicate = [](ov::Output<ov::Node> output) -> bool {return pattern::type_matches(ov::element::u4)(output) && pattern::consumers_count(1)(output);};- auto u4_zero_point_m = pattern::wrap_type<ov::op::v0::Constant>(u4_zp_predicate);- auto zero_point_convert_m = pattern::wrap_type<ov::op::v0::Convert>({u4_zero_point_m}, float_zp_predicate);+ auto u4_zero_point_m = pattern::wrap_type<v0::Constant>(u4_zp_predicate);+ auto zero_point_convert_m = pattern::wrap_type<v0::Convert>({u4_zero_point_m}, float_zp_predicate);auto zero_point_m = std::make_shared<pattern::op::Or>(OutputVector{float_zero_point_m, zero_point_convert_m});auto subtract_m = pattern::wrap_type<ov::op::v1::Subtract>({convert_m, zero_point_m});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {auto& pattern_map = m.get_pattern_value_map();- auto weights = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(weights_m).get_node_shared_ptr());- std::shared_ptr<ov::op::v0::Constant> zero_point;+ auto weights = ov::as_type_ptr<v0::Constant>(pattern_map.at(weights_m).get_node_shared_ptr());+ std::shared_ptr<v0::Constant> zero_point;if (pattern_map.count(float_zero_point_m)) {const auto& float_zp = pattern_map.at(float_zero_point_m);- zero_point = ov::as_type_ptr<ov::op::v0::Constant>(float_zp.get_node_shared_ptr());+ zero_point = ov::as_type_ptr<v0::Constant>(float_zp.get_node_shared_ptr());} else {const auto& u4_zp = pattern_map.at(u4_zero_point_m);- zero_point = ov::as_type_ptr<ov::op::v0::Constant>(u4_zp.get_node_shared_ptr());+ zero_point = ov::as_type_ptr<v0::Constant>(u4_zp.get_node_shared_ptr());}if (!weights || !zero_point)return false;@@ -66,10 +70,12 @@ ov::pass::ConvertU4WeightsZeroPointToScalar::ConvertU4WeightsZeroPointToScalar()float zp_value;if (!ov::op::util::get_single_value(zero_point, zp_value))return false;- const auto new_zp = ov::op::v0::Constant::create(zero_point->get_element_type(), {}, {zp_value});+ const auto new_zp = v0::Constant::create(zero_point->get_element_type(), {}, {zp_value});return ov::replace_node_update_name(zero_point, new_zp);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(subtract_m, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(subtract_m, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/convolution_to_group_convolution.cpp b/src/common/transformations/src/transformations/common_optimizations/convolution_to_group_convolution.cppindex 409779a3633..58f62de2af9 100644--- a/src/common/transformations/src/transformations/common_optimizations/convolution_to_group_convolution.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/convolution_to_group_convolution.cpp@@ -17,8 +17,12 @@#include "transformations/common_optimizations/convolution_to_group_convolution_fusion.hpp"#include "transformations/utils/utils.hpp"-static bool compare_convolutions(const ov::op::v1::Convolution* conv1, ov::Node* node) {- const auto conv2 = ov::as_type<ov::op::v1::Convolution>(node);+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+static bool compare_convolutions(const v1::Convolution* conv1, ov::Node* node) {+ const auto conv2 = ov::as_type<v1::Convolution>(node);if (!conv2)return false;return conv1->get_strides() == conv2->get_strides() && conv1->get_pads_begin() == conv2->get_pads_begin() &&@@ -27,7 +31,7 @@ static bool compare_convolutions(const ov::op::v1::Convolution* conv1, ov::Node*}static int64_t get_split_axis(const std::shared_ptr<ov::Node>& split) {- const auto axis = ov::as_type<ov::op::v0::Constant>(split->get_input_node_ptr(1));+ const auto axis = ov::as_type<v0::Constant>(split->get_input_node_ptr(1));if (!axis)return -1;auto axis_value = axis->cast_vector<int64_t>()[0];@@ -41,8 +45,8 @@ static int64_t get_split_axis(const std::shared_ptr<ov::Node>& split) {return axis_value;}-static std::shared_ptr<ov::op::v0::Concat> create_new_weights(ov::pass::NodeRegistry& node_registry,- const std::shared_ptr<ov::Node>& concat) {+static std::shared_ptr<v0::Concat> create_new_weights(ov::pass::NodeRegistry& node_registry,+ const std::shared_ptr<ov::Node>& concat) {const auto concat_input = concat->get_input_node_ptr(0);if (concat_input->get_input_partial_shape(1).is_dynamic())return nullptr;@@ -63,17 +67,17 @@ static std::shared_ptr<ov::op::v0::Concat> create_new_weights(ov::pass::NodeRegiconst auto& shape = weights->get_output_partial_shape(0);if (shape.is_dynamic() || weights->get_output_shape(0) != weights_shape)return nullptr;- if (auto constant = ov::as_type_ptr<ov::op::v0::Constant>(weights)) {- weights_to_concat.push_back(node_registry.make<ov::op::v0::Constant>(*constant, new_shape));+ if (auto constant = ov::as_type_ptr<v0::Constant>(weights)) {+ weights_to_concat.push_back(node_registry.make<v0::Constant>(*constant, new_shape));} else {- weights_to_concat.push_back(node_registry.make<ov::op::v0::Unsqueeze>(- weights_output,- ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {0})));+ weights_to_concat.push_back(+ node_registry.make<v0::Unsqueeze>(weights_output,+ v0::Constant::create(ov::element::i32, ov::Shape{}, {0})));}weights_to_concat.back().get_node()->set_friendly_name(weights->get_friendly_name());}- return node_registry.make<ov::op::v0::Concat>(weights_to_concat, 0);+ return node_registry.make<v0::Concat>(weights_to_concat, 0);}ov::pass::ConvolutionToGroupConvolutionFusion::ConvolutionToGroupConvolutionFusion() {@@ -85,12 +89,12 @@ ov::pass::ConvolutionToGroupConvolutionFusion::ConvolutionToGroupConvolutionFusiif (num_inputs == 0)return false;- const auto first_conv = as_type<ov::op::v1::Convolution>(concat->get_input_node_ptr(0));+ const auto first_conv = as_type<v1::Convolution>(concat->get_input_node_ptr(0));if (!first_conv)return false;const auto split = first_conv->get_input_node_ptr(0);- if (!is_type<ov::op::v1::Split>(split) && !is_type<ov::op::v1::VariadicSplit>(split))+ if (!is_type<v1::Split>(split) && !is_type<v1::VariadicSplit>(split))return false;// go through Concat inputs and check@@ -105,19 +109,19 @@ ov::pass::ConvolutionToGroupConvolutionFusion::ConvolutionToGroupConvolutionFusi}return true;};- auto concat_label = pattern::wrap_type<ov::op::v0::Concat>(has_conv_inputs);+ auto concat_label = ov::pass::pattern::wrap_type<v0::Concat>(has_conv_inputs);- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_value_map = m.get_pattern_value_map();const auto& concat = pattern_value_map.at(concat_label).get_node_shared_ptr();- const auto first_conv = as_type_ptr<ov::op::v1::Convolution>(concat->get_input_node_shared_ptr(0));+ const auto first_conv = as_type_ptr<v1::Convolution>(concat->get_input_node_shared_ptr(0));if (!first_conv)return false;const auto split = first_conv->get_input_node_shared_ptr(0);- const bool is_split = is_type<ov::op::v1::Split>(split);- const bool is_variadic_split = is_type<ov::op::v1::VariadicSplit>(split);+ const bool is_split = is_type<v1::Split>(split);+ const bool is_variadic_split = is_type<v1::VariadicSplit>(split);if (!is_split && !is_variadic_split)return false;@@ -126,7 +130,7 @@ ov::pass::ConvolutionToGroupConvolutionFusion::ConvolutionToGroupConvolutionFusiif (is_variadic_split) {// split_lengths in VariadicSplit must have the same values- if (auto split_lengths = as_type<ov::op::v0::Constant>(split->get_input_node_ptr(1))) {+ if (auto split_lengths = as_type<v0::Constant>(split->get_input_node_ptr(1))) {const auto split_lengths_values = split_lengths->cast_vector<int>();const auto first_length = split_lengths_values[0];if (!std::all_of(split_lengths_values.begin() + 1,@@ -145,13 +149,13 @@ ov::pass::ConvolutionToGroupConvolutionFusion::ConvolutionToGroupConvolutionFusiif (!weights)return false;- const auto conv = node_registry.make<ov::op::v1::GroupConvolution>(split->input_value(0),- weights,- first_conv->get_strides(),- first_conv->get_pads_begin(),- first_conv->get_pads_end(),- first_conv->get_dilations(),- first_conv->get_auto_pad());+ const auto conv = node_registry.make<v1::GroupConvolution>(split->input_value(0),+ weights,+ first_conv->get_strides(),+ first_conv->get_pads_begin(),+ first_conv->get_pads_end(),+ first_conv->get_dilations(),+ first_conv->get_auto_pad());conv->set_friendly_name(concat->get_friendly_name());register_new_node(conv);@@ -171,6 +175,6 @@ ov::pass::ConvolutionToGroupConvolutionFusion::ConvolutionToGroupConvolutionFusireturn true;};- auto m = std::make_shared<pattern::Matcher>(concat_label, matcher_name);+ auto m = std::make_shared<Matcher>(concat_label, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cppindex 4e5b09fd270..b8a9923d631 100644--- a/src/common/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/depth_to_space_fusion.cpp@@ -17,6 +17,12 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {+namespace {bool check_block_first(const ov::PartialShape& shape_input,const ov::PartialShape& shape_reshape_before,@@ -41,7 +47,7 @@ bool check_block_first(const ov::PartialShape& shape_input,for (int i = 2; i < input_rank.get_length(); ++i)expected_shape.push_back(shape_input[i]);- if (!ov::op::util::shapes_equal_except_dynamic_expected_batch(expected_shape, shape_reshape_before)) {+ if (!op_util::shapes_equal_except_dynamic_expected_batch(expected_shape, shape_reshape_before)) {return false;}@@ -62,7 +68,7 @@ bool check_block_first(const ov::PartialShape& shape_input,for (int i = 2; i < input_rank.get_length(); ++i)expected_shape.push_back(shape_input[i] * possible_block_size);- if (!ov::op::util::shapes_equal_except_dynamic_expected_batch(expected_shape, shape_reshape_after)) {+ if (!op_util::shapes_equal_except_dynamic_expected_batch(expected_shape, shape_reshape_after)) {return false;}@@ -90,7 +96,7 @@ bool check_depth_first(const ov::PartialShape& shape_input,for (int i = 2; i < input_rank.get_length(); ++i)expected_shape.push_back(shape_input[i]);- if (!ov::op::util::shapes_equal_except_dynamic_expected_batch(expected_shape, shape_reshape_before)) {+ if (!op_util::shapes_equal_except_dynamic_expected_batch(expected_shape, shape_reshape_before)) {return false;}@@ -110,7 +116,7 @@ bool check_depth_first(const ov::PartialShape& shape_input,for (int i = 2; i < input_rank.get_length(); ++i)expected_shape.push_back(shape_input[i] * possible_block_size);- if (!ov::op::util::shapes_equal_except_dynamic_expected_batch(expected_shape, shape_reshape_after)) {+ if (!op_util::shapes_equal_except_dynamic_expected_batch(expected_shape, shape_reshape_after)) {return false;}@@ -119,30 +125,28 @@ bool check_depth_first(const ov::PartialShape& shape_input,} // namespace-ov::pass::DepthToSpaceFusion::DepthToSpaceFusion() {+DepthToSpaceFusion::DepthToSpaceFusion() {MATCHER_SCOPE(DepthToSpaceFusion);- auto input0 = pass::pattern::any_input(pattern::rank_equals(4));- auto input1 = pass::pattern::any_input();- auto input2 = pass::pattern::any_input();- auto input3 = pass::pattern::any_input();- auto reshape_before =- ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({input0, input1}, pattern::consumers_count(1));- auto permute =- ov::pass::pattern::wrap_type<ov::op::v1::Transpose>({reshape_before, input2}, pattern::consumers_count(1));- auto reshape_after = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({permute, input3});+ auto input0 = pattern::any_input(pattern::rank_equals(4));+ auto input1 = pattern::any_input();+ auto input2 = pattern::any_input();+ auto input3 = pattern::any_input();+ auto reshape_before = pattern::wrap_type<v1::Reshape>({input0, input1}, pattern::consumers_count(1));+ auto permute = pattern::wrap_type<v1::Transpose>({reshape_before, input2}, pattern::consumers_count(1));+ auto reshape_after = pattern::wrap_type<v1::Reshape>({permute, input3});ov::matcher_pass_callback callback = [](pattern::Matcher& m) {- auto reshape_after = ov::as_type_ptr<ov::op::v1::Reshape>(m.get_match_root());+ auto reshape_after = ov::as_type_ptr<v1::Reshape>(m.get_match_root());if (!reshape_after) {return false;}- auto permute = ov::as_type_ptr<ov::op::v1::Transpose>(reshape_after->get_input_node_shared_ptr(0));+ auto permute = ov::as_type_ptr<v1::Transpose>(reshape_after->get_input_node_shared_ptr(0));if (!permute) {return false;}- auto reshape_before = ov::as_type_ptr<ov::op::v1::Reshape>(permute->get_input_node_shared_ptr(0));+ auto reshape_before = ov::as_type_ptr<v1::Reshape>(permute->get_input_node_shared_ptr(0));if (!reshape_before) {return false;}@@ -173,34 +177,35 @@ ov::pass::DepthToSpaceFusion::DepthToSpaceFusion() {}ov::AxisVector permutation;- if (auto input_const = ov::as_type_ptr<ov::op::v0::Constant>(permute->get_input_node_shared_ptr(1))) {+ if (auto input_const = ov::as_type_ptr<v0::Constant>(permute->get_input_node_shared_ptr(1))) {permutation = input_const->get_axis_vector_val();} else {return false;}- ov::op::v0::DepthToSpace::DepthToSpaceMode mode;+ v0::DepthToSpace::DepthToSpaceMode mode;size_t block_size;if (check_depth_first(p_shape_input, p_shape_reshape_before, permutation, p_shape_reshape_after, block_size)) {- mode = ov::op::v0::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST;+ mode = v0::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST;} else if (check_block_first(p_shape_input,p_shape_reshape_before,permutation,p_shape_reshape_after,block_size)) {- mode = ov::op::v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST;+ mode = v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST;} else {return false;}- auto depth_to_space =- std::make_shared<ov::op::v0::DepthToSpace>(reshape_before->input_value(0), mode, block_size);+ auto depth_to_space = std::make_shared<v0::DepthToSpace>(reshape_before->input_value(0), mode, block_size);depth_to_space->set_friendly_name(reshape_after->get_friendly_name());ov::copy_runtime_info({reshape_before, permute, reshape_after}, depth_to_space);ov::replace_node(reshape_after, depth_to_space);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reshape_after, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(reshape_after, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/dilated_convolution_converter.cpp b/src/common/transformations/src/transformations/common_optimizations/dilated_convolution_converter.cppindex df2518702ae..e5e28671ce5 100644--- a/src/common/transformations/src/transformations/common_optimizations/dilated_convolution_converter.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/dilated_convolution_converter.cpp@@ -19,42 +19,44 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+// Replace the following graph SpaceToBatch -> Convolution(GroupConvolution) -> BatchToSpace with single// Convolution(GroupConvolution) node-ov::pass::DilatedConvolutionConverter::DilatedConvolutionConverter() {+DilatedConvolutionConverter::DilatedConvolutionConverter() {MATCHER_SCOPE(DilatedConvolutionConverter);auto data_pattern = pattern::any_input();- auto block_shape_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto pads_begin_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto pads_end_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto space_to_batch_pattern = pattern::wrap_type<ov::op::v1::SpaceToBatch>(- {data_pattern, block_shape_pattern, pads_begin_pattern, pads_end_pattern});- auto conv_p = pattern::wrap_type<ov::op::v1::Convolution>({space_to_batch_pattern, pattern::any_input()});- auto gconv_p = pattern::wrap_type<ov::op::v1::GroupConvolution>({space_to_batch_pattern, pattern::any_input()});+ auto block_shape_pattern = pattern::wrap_type<v0::Constant>();+ auto pads_begin_pattern = pattern::wrap_type<v0::Constant>();+ auto pads_end_pattern = pattern::wrap_type<v0::Constant>();+ auto space_to_batch_pattern =+ pattern::wrap_type<v1::SpaceToBatch>({data_pattern, block_shape_pattern, pads_begin_pattern, pads_end_pattern});+ auto conv_p = pattern::wrap_type<v1::Convolution>({space_to_batch_pattern, pattern::any_input()});+ auto gconv_p = pattern::wrap_type<v1::GroupConvolution>({space_to_batch_pattern, pattern::any_input()});auto conv_pattern = std::make_shared<pattern::op::Or>(OutputVector{conv_p, gconv_p});- auto crops_begin_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto crops_end_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto batch_to_space_pattern = pattern::wrap_type<ov::op::v1::BatchToSpace>(+ auto crops_begin_pattern = pattern::wrap_type<v0::Constant>();+ auto crops_end_pattern = pattern::wrap_type<v0::Constant>();+ auto batch_to_space_pattern = pattern::wrap_type<v1::BatchToSpace>({conv_pattern, pattern::any_input(), crops_begin_pattern, crops_end_pattern});matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();- auto block_shape =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(block_shape_pattern).get_node_shared_ptr());+ auto block_shape = ov::as_type_ptr<v0::Constant>(pattern_map.at(block_shape_pattern).get_node_shared_ptr());if (!block_shape)return false;- auto pads_begin =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(pads_begin_pattern).get_node_shared_ptr());+ auto pads_begin = ov::as_type_ptr<v0::Constant>(pattern_map.at(pads_begin_pattern).get_node_shared_ptr());if (!pads_begin)return false;- auto pads_end = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(pads_end_pattern).get_node_shared_ptr());+ auto pads_end = ov::as_type_ptr<v0::Constant>(pattern_map.at(pads_end_pattern).get_node_shared_ptr());if (!pads_end)return false;- auto crops_begin =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(crops_begin_pattern).get_node_shared_ptr());+ auto crops_begin = ov::as_type_ptr<v0::Constant>(pattern_map.at(crops_begin_pattern).get_node_shared_ptr());if (!crops_begin)return false;- auto crops_end = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(crops_end_pattern).get_node_shared_ptr());+ auto crops_end = ov::as_type_ptr<v0::Constant>(pattern_map.at(crops_end_pattern).get_node_shared_ptr());if (!crops_end)return false;@@ -65,14 +67,14 @@ ov::pass::DilatedConvolutionConverter::DilatedConvolutionConverter() {std::shared_ptr<ov::Node> conv_node;if (pattern_map.count(conv_p)) {conv_node = pattern_map.at(conv_p).get_node_shared_ptr();- auto conv = ov::as_type_ptr<ov::op::v1::Convolution>(conv_node);+ auto conv = ov::as_type_ptr<v1::Convolution>(conv_node);if (!conv)return false;dilations = conv->get_dilations();strides = conv->get_strides();} else if (pattern_map.count(gconv_p)) {conv_node = pattern_map.at(gconv_p).get_node_shared_ptr();- auto conv = ov::as_type_ptr<ov::op::v1::GroupConvolution>(conv_node);+ auto conv = ov::as_type_ptr<v1::GroupConvolution>(conv_node);if (!conv)return false;dilations = conv->get_dilations();@@ -103,21 +105,21 @@ ov::pass::DilatedConvolutionConverter::DilatedConvolutionConverter() {}std::shared_ptr<ov::Node> new_conv;if (pattern_map.count(gconv_p)) {- new_conv = register_new_node<ov::op::v1::GroupConvolution>(pattern_map.at(data_pattern),- conv_node->input_value(1),- strides,- new_pads_begin,- new_pads_end,- dilations,- ov::op::PadType::EXPLICIT);+ new_conv = register_new_node<v1::GroupConvolution>(pattern_map.at(data_pattern),+ conv_node->input_value(1),+ strides,+ new_pads_begin,+ new_pads_end,+ dilations,+ ov::op::PadType::EXPLICIT);} else {- new_conv = register_new_node<ov::op::v1::Convolution>(pattern_map.at(data_pattern),- conv_node->input_value(1),- strides,- new_pads_begin,- new_pads_end,- dilations,- ov::op::PadType::EXPLICIT);+ new_conv = register_new_node<v1::Convolution>(pattern_map.at(data_pattern),+ conv_node->input_value(1),+ strides,+ new_pads_begin,+ new_pads_end,+ dilations,+ ov::op::PadType::EXPLICIT);}auto batch_to_space = pattern_map.at(batch_to_space_pattern).get_node_shared_ptr();@@ -138,3 +140,5 @@ ov::pass::DilatedConvolutionConverter::DilatedConvolutionConverter() {auto m = std::make_shared<pattern::Matcher>(batch_to_space_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/dimension_tracking.cpp b/src/common/transformations/src/transformations/common_optimizations/dimension_tracking.cppindex 75173e677e3..1f513dbc7ac 100644--- a/src/common/transformations/src/transformations/common_optimizations/dimension_tracking.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/dimension_tracking.cpp@@ -20,6 +20,9 @@#include "openvino/op/result.hpp"#include "openvino/op/shape_of.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;void ov::batch_util::mark_with_unique_dimension_symbols(const std::shared_ptr<ov::Model>& m) {for (auto& parameter : m->get_parameters()) {ov::PartialShape new_shape = ov::PartialShape::dynamic(parameter->get_partial_shape().rank());@@ -30,7 +33,7 @@ void ov::batch_util::mark_with_unique_dimension_symbols(const std::shared_ptr<ovm->validate_nodes_and_infer_types();}-void ov::batch_util::mark_batch(const std::shared_ptr<ov::op::v0::Parameter>& parameter,+void ov::batch_util::mark_batch(const std::shared_ptr<v0::Parameter>& parameter,P2Btype& map,const std::unordered_set<std::shared_ptr<Symbol>>& batches) {auto& shape = parameter->get_partial_shape();@@ -62,7 +65,7 @@ void ov::batch_util::mark_batch(const std::shared_ptr<ov::op::v0::Parameter>& paparameter->validate_and_infer_types();}-void ov::batch_util::mark_layout_independent_batch(const std::shared_ptr<ov::op::v0::Parameter>& parameter,+void ov::batch_util::mark_layout_independent_batch(const std::shared_ptr<v0::Parameter>& parameter,const std::shared_ptr<ov::Node>& result,P2Btype& map) {TensorSymbol p_symbols, r_symbols;@@ -82,7 +85,7 @@ void ov::batch_util::mark_layout_independent_batch(const std::shared_ptr<ov::op:mark_no_batch(parameter, map);}-void ov::batch_util::mark_no_batch(const std::shared_ptr<ov::op::v0::Parameter>& parameter, P2Btype& map) {+void ov::batch_util::mark_no_batch(const std::shared_ptr<v0::Parameter>& parameter, P2Btype& map) {if (map.count(parameter))map.erase(parameter);auto& shape = parameter->get_partial_shape();@@ -94,12 +97,12 @@ void ov::batch_util::mark_no_batch(const std::shared_ptr<ov::op::v0::Parameter>&P2Btype ov::batch_util::find_batch(const std::shared_ptr<ov::Model>& f) {std::unordered_map<ov::Node::type_info_t, std::pair<size_t, size_t>> type_input_port_batch_index = {- {ov::op::v1::Convolution::get_type_info_static(), {0, 0}},- {ov::op::v1::GroupConvolution::get_type_info_static(), {0, 0}},- {ov::op::v1::ConvolutionBackpropData::get_type_info_static(), {0, 0}},- {ov::op::v1::GroupConvolutionBackpropData::get_type_info_static(), {0, 0}},- {ov::op::v1::DeformableConvolution::get_type_info_static(), {0, 0}},- {ov::op::v0::MatMul::get_type_info_static(), {0, 0}}, // transpose_a situation+ {v1::Convolution::get_type_info_static(), {0, 0}},+ {v1::GroupConvolution::get_type_info_static(), {0, 0}},+ {v1::ConvolutionBackpropData::get_type_info_static(), {0, 0}},+ {v1::GroupConvolutionBackpropData::get_type_info_static(), {0, 0}},+ {v1::DeformableConvolution::get_type_info_static(), {0, 0}},+ {v0::MatMul::get_type_info_static(), {0, 0}}, // transpose_a situation};P2Btype parameter_to_batch_symbols;@@ -142,15 +145,14 @@ P2Btype ov::batch_util::find_batch(const std::shared_ptr<ov::Model>& f) {continue; // symbol propagation stopped}- if (ov::is_type<ov::op::v0::Result>(curr_node))+ if (ov::is_type<v0::Result>(curr_node))layout_independent_results.push_back(curr_node);for (const auto& output : curr_node->outputs()) {// we do not need to walk through shape-of sub-graphsfor (const auto& t_input : output.get_target_inputs()) {- if (ov::is_type<ov::op::v1::ConvertLike>(t_input.get_node()) ||- ov::is_type<ov::op::v0::ShapeOf>(t_input.get_node()) ||- ov::is_type<ov::op::v3::ShapeOf>(t_input.get_node()))+ if (ov::is_type<v1::ConvertLike>(t_input.get_node()) ||+ ov::is_type<v0::ShapeOf>(t_input.get_node()) || ov::is_type<v3::ShapeOf>(t_input.get_node()))continue;nodes.push_back(t_input.get_node());}@@ -167,7 +169,7 @@ P2Btype ov::batch_util::find_batch(const std::shared_ptr<ov::Model>& f) {void ov::batch_util::restore_original_dimensions(const std::shared_ptr<ov::Model>& model,- const std::map<std::shared_ptr<ov::op::v0::Parameter>, ov::PartialShape>& parameter_to_shape,+ const std::map<std::shared_ptr<v0::Parameter>, ov::PartialShape>& parameter_to_shape,bool leave_batch_dynamic,bool clear_symbols) {for (const auto& item : parameter_to_shape) {@@ -186,7 +188,7 @@ void ov::batch_util::restore_original_dimensions(}item.first->set_partial_shape(original_shape);}- std::unordered_map<std::shared_ptr<ov::op::v0::Result>, ov::PartialShape> output_to_shape;+ std::unordered_map<std::shared_ptr<v0::Result>, ov::PartialShape> output_to_shape;if (!clear_symbols) {for (const auto& result : model->get_results())output_to_shape[result] = result->get_output_partial_shape(0);@@ -236,8 +238,8 @@ bool ov::batch_util::check_batch_tracks_through_all_the_nodes(const std::shared_name_stays = true;all_outputs_has_batch &= name_stays; // && others_are_static;}- if (any_input_has_batch && !all_outputs_has_batch && !ov::is_type<ov::op::v3::ShapeOf>(node) &&- !ov::is_type<ov::op::v0::ShapeOf>(node) && !ov::is_type<ov::op::v1::ConvertLike>(node)) {+ if (any_input_has_batch && !all_outputs_has_batch && !ov::is_type<v3::ShapeOf>(node) &&+ !ov::is_type<v0::ShapeOf>(node) && !ov::is_type<v1::ConvertLike>(node)) {failed_to_propagate_batch = true;node->validate_and_infer_types();}@@ -257,11 +259,11 @@ bool ov::batch_util::detach_detection_output(const std::shared_ptr<ov::Model>& fResultVector new_outputs, outputs_to_delete;for (auto& result_node : f->get_results()) {auto do_node = result_node->input_value(0).get_node_shared_ptr();- if (ov::is_type<ov::op::v0::Convert>(do_node)) // cases with do->convert->result+ if (ov::is_type<v0::Convert>(do_node)) // cases with do->convert->resultdo_node = do_node->get_input_node_shared_ptr(0);- if (ov::is_type<ov::op::v0::DetectionOutput>(do_node) || ov::is_type<ov::op::v8::DetectionOutput>(do_node)) {+ if (ov::is_type<v0::DetectionOutput>(do_node) || ov::is_type<ov::op::v8::DetectionOutput>(do_node)) {for (auto& new_result_src : do_node->input_values()) {- auto new_result = std::make_shared<ov::op::v0::Result>(new_result_src);+ auto new_result = std::make_shared<v0::Result>(new_result_src);ov::copy_runtime_info(result_node, new_result);new_outputs.push_back(new_result);}@@ -276,10 +278,10 @@ bool ov::batch_util::detach_detection_output(const std::shared_ptr<ov::Model>& fnamespace {-std::map<std::shared_ptr<ov::op::v0::Parameter>, ov::PartialShape> collect_original_input_shapes(+std::map<std::shared_ptr<v0::Parameter>, ov::PartialShape> collect_original_input_shapes(const std::shared_ptr<ov::Model>& m) {const auto& parameters = m->get_parameters();- std::map<std::shared_ptr<ov::op::v0::Parameter>, ov::PartialShape> parameter_to_shape;+ std::map<std::shared_ptr<v0::Parameter>, ov::PartialShape> parameter_to_shape;for (const auto& parameter : parameters) {auto shape = parameter->get_partial_shape();if (shape.rank().is_dynamic())diff --git a/src/common/transformations/src/transformations/common_optimizations/disable_random_uniform_constant_folding.cpp b/src/common/transformations/src/transformations/common_optimizations/disable_random_uniform_constant_folding.cppindex 341ed44f1c1..c0888ea9eac 100644--- a/src/common/transformations/src/transformations/common_optimizations/disable_random_uniform_constant_folding.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/disable_random_uniform_constant_folding.cpp@@ -10,7 +10,9 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/rt_info/disable_constant_folding.hpp"-ov::pass::DisableRandomUniformConstantFolding::DisableRandomUniformConstantFolding() {+namespace ov::pass {++DisableRandomUniformConstantFolding::DisableRandomUniformConstantFolding() {auto random_uniform = pattern::wrap_type<ov::op::v8::RandomUniform>();ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {@@ -18,6 +20,8 @@ ov::pass::DisableRandomUniformConstantFolding::DisableRandomUniformConstantFoldireturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(random_uniform, "DisableRandomUniformConstantFolding");+ auto m = std::make_shared<pattern::Matcher>(random_uniform, "DisableRandomUniformConstantFolding");this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/disable_shapeof_constant_folding.cpp b/src/common/transformations/src/transformations/common_optimizations/disable_shapeof_constant_folding.cppindex cc48041e0f1..dc3b9e07e02 100644--- a/src/common/transformations/src/transformations/common_optimizations/disable_shapeof_constant_folding.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/disable_shapeof_constant_folding.cpp@@ -10,7 +10,9 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/rt_info/disable_constant_folding.hpp"-ov::pass::DisableShapeOfConstantFolding::DisableShapeOfConstantFolding(bool check_shape) {+namespace ov::pass {++DisableShapeOfConstantFolding::DisableShapeOfConstantFolding(bool check_shape) {auto shape_of = pattern::wrap_type<ov::op::v0::ShapeOf, ov::op::v3::ShapeOf>([=](const Output<Node>& output) {const auto& shape = output.get_partial_shape();if (!check_shape)@@ -23,6 +25,8 @@ ov::pass::DisableShapeOfConstantFolding::DisableShapeOfConstantFolding(bool checreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(shape_of, "DisableShapeOfConstantFolding");+ auto m = std::make_shared<pattern::Matcher>(shape_of, "DisableShapeOfConstantFolding");this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/divide_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/divide_fusion.cppindex 5526d01b6db..7e3bc5ab812 100644--- a/src/common/transformations/src/transformations/common_optimizations/divide_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/divide_fusion.cpp@@ -16,13 +16,18 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::DivideFusion::DivideFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++DivideFusion::DivideFusion() {MATCHER_SCOPE(DivideFusion);auto p_pow_input = pattern::any_input();- auto p_pow_const = pattern::wrap_type<ov::op::v0::Constant>();- auto p_pow = pattern::wrap_type<ov::op::v1::Power>({p_pow_input, p_pow_const});+ auto p_pow_const = pattern::wrap_type<v0::Constant>();+ auto p_pow = pattern::wrap_type<v1::Power>({p_pow_input, p_pow_const});auto p_mul_input = pattern::any_input();- auto p_mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({p_mul_input, p_pow});+ auto p_mul = pattern::wrap_type<v1::Multiply>({p_mul_input, p_pow});matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();@@ -32,18 +37,20 @@ ov::pass::DivideFusion::DivideFusion() {const auto& pow = pattern_to_output.at(p_pow).get_node_shared_ptr();const auto& minus_one = pattern_to_output.at(p_pow_const).get_node_shared_ptr();- auto minus_one_const = ov::as_type_ptr<ov::op::v0::Constant>(minus_one);+ auto minus_one_const = ov::as_type_ptr<v0::Constant>(minus_one);if (!minus_one_const || !ov::op::util::has_constant_value<float>(minus_one_const, -1.)) {return false;}- auto div = register_new_node<ov::op::v1::Divide>(minuend_input, subtrahend_input);+ auto div = register_new_node<v1::Divide>(minuend_input, subtrahend_input);div->set_friendly_name(mul->get_friendly_name());copy_runtime_info({mul, pow}, div);replace_node(mul, div);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(p_mul, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(p_mul, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/dropout_with_random_uniform_replacer.cpp b/src/common/transformations/src/transformations/common_optimizations/dropout_with_random_uniform_replacer.cppindex 10108fe6be3..743a0202bd6 100644--- a/src/common/transformations/src/transformations/common_optimizations/dropout_with_random_uniform_replacer.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/dropout_with_random_uniform_replacer.cpp@@ -20,41 +20,46 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::DropoutWithRandomUniformReplacer::DropoutWithRandomUniformReplacer() {+namespace v0 = ov::op::v0;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;++namespace ov::pass {++DropoutWithRandomUniformReplacer::DropoutWithRandomUniformReplacer() {MATCHER_SCOPE(DropoutWithRandomUniformReplacer);- const auto shape_pattern = pass::pattern::any_input();- const auto ru_min_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- const auto ru_max_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- const auto random_uniform_pattern = ov::pass::pattern::wrap_type<ov::op::v8::RandomUniform>(- {shape_pattern, ru_min_const_pattern, ru_max_const_pattern},- pattern::consumers_count(1));+ const auto shape_pattern = pattern::any_input();+ const auto ru_min_const_pattern = pattern::wrap_type<v0::Constant>();+ const auto ru_max_const_pattern = pattern::wrap_type<v0::Constant>();+ const auto random_uniform_pattern =+ pattern::wrap_type<v8::RandomUniform>({shape_pattern, ru_min_const_pattern, ru_max_const_pattern},+ pattern::consumers_count(1));- const auto optional_convert = pattern::optional<ov::op::v0::Convert>(random_uniform_pattern);- const auto add_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();+ const auto optional_convert = pattern::optional<v0::Convert>(random_uniform_pattern);+ const auto add_const_pattern = pattern::wrap_type<v0::Constant>();- const auto add_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Add>({optional_convert, add_const_pattern});+ const auto add_pattern = pattern::wrap_type<ov::op::v1::Add>({optional_convert, add_const_pattern});- const auto floor_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Floor>({add_pattern});+ const auto floor_pattern = pattern::wrap_type<v0::Floor>({add_pattern});ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto random_uniform = pattern_map.at(random_uniform_pattern);const auto shape_of = pattern_map.at(shape_pattern);- const auto ru = ov::as_type_ptr<ov::op::v8::RandomUniform>(random_uniform.get_node_shared_ptr());+ const auto ru = ov::as_type_ptr<v8::RandomUniform>(random_uniform.get_node_shared_ptr());if (!ru)return false;if (!ru->get_out_type().is_real())return false;auto min_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(ru_min_const_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_map.at(ru_min_const_pattern).get_node_shared_ptr());auto max_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(ru_max_const_pattern).get_node_shared_ptr());- auto add_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(add_const_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_map.at(ru_max_const_pattern).get_node_shared_ptr());+ auto add_const_value = ov::as_type_ptr<v0::Constant>(pattern_map.at(add_const_pattern).get_node_shared_ptr());- bool valid_constant_values = ov::op::util::has_constant_value<double>(min_const_value, 0.0) &&- ov::op::util::has_constant_value<double>(max_const_value, 1.0);+ bool valid_constant_values = op_util::has_constant_value<double>(min_const_value, 0.0) &&+ op_util::has_constant_value<double>(max_const_value, 1.0);if (!valid_constant_values)return false;@@ -69,7 +74,7 @@ ov::pass::DropoutWithRandomUniformReplacer::DropoutWithRandomUniformReplacer() {if (add_const_vector[0] - std::round(add_const_vector[0]) != 0.0)return false;- const auto broadcast_const = ov::op::v0::Constant::create(ru->get_out_type(), Shape{}, {0.5});+ const auto broadcast_const = v0::Constant::create(ru->get_out_type(), Shape{}, {0.5});const auto broadcast = std::make_shared<ov::op::v3::Broadcast>(broadcast_const, shape_of);broadcast->set_friendly_name(ru->get_friendly_name());@@ -79,6 +84,8 @@ ov::pass::DropoutWithRandomUniformReplacer::DropoutWithRandomUniformReplacer() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(floor_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(floor_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/eliminate_duplicate_ti_inputs.cpp b/src/common/transformations/src/transformations/common_optimizations/eliminate_duplicate_ti_inputs.cppindex 13bb48dbe1f..e68c88d20f3 100644--- a/src/common/transformations/src/transformations/common_optimizations/eliminate_duplicate_ti_inputs.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/eliminate_duplicate_ti_inputs.cpp@@ -13,33 +13,36 @@#include "openvino/op/tensor_iterator.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-using namespace ov::op::util;+namespace v0 = ov::op::v0;+namespace op_util = ov::op::util;-ov::pass::EliminateDuplicateTIInputs::EliminateDuplicateTIInputs() {+namespace ov::pass {++EliminateDuplicateTIInputs::EliminateDuplicateTIInputs() {MATCHER_SCOPE(EliminateDuplicateTIInputs);- auto ti = pattern::wrap_type<ov::op::v0::TensorIterator>();+ auto ti = pattern::wrap_type<v0::TensorIterator>();ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto ti = ov::as_type_ptr<ov::op::v0::TensorIterator>(m.get_match_root());+ auto ti = ov::as_type_ptr<v0::TensorIterator>(m.get_match_root());if (ti == nullptr) {return false;}- std::vector<std::shared_ptr<SubGraphOp::InputDescription>> should_stay;- std::map<std::shared_ptr<SubGraphOp::InputDescription>,- std::vector<std::shared_ptr<SubGraphOp::InputDescription>>>+ std::vector<std::shared_ptr<op_util::SubGraphOp::InputDescription>> should_stay;+ std::map<std::shared_ptr<op_util::SubGraphOp::InputDescription>,+ std::vector<std::shared_ptr<op_util::SubGraphOp::InputDescription>>>need_to_eliminate;auto input_descs = ti->get_input_descriptions();for (auto& key : input_descs) {- auto is_equal = [&](const std::shared_ptr<SubGraphOp::InputDescription>& input) -> bool {+ auto is_equal = [&](const std::shared_ptr<op_util::SubGraphOp::InputDescription>& input) -> bool {if (ti->input_value(input->m_input_index) == ti->input_value(key->m_input_index)) {- auto invariant_l = ov::as_type_ptr<SubGraphOp::InvariantInputDescription>(input);- auto invariant_r = ov::as_type_ptr<SubGraphOp::InvariantInputDescription>(key);+ auto invariant_l = ov::as_type_ptr<op_util::SubGraphOp::InvariantInputDescription>(input);+ auto invariant_r = ov::as_type_ptr<op_util::SubGraphOp::InvariantInputDescription>(key);if (invariant_l && invariant_r) {return true;}- auto slice_l = ov::as_type_ptr<SubGraphOp::SliceInputDescription>(input);- auto slice_r = ov::as_type_ptr<SubGraphOp::SliceInputDescription>(key);+ auto slice_l = ov::as_type_ptr<op_util::SubGraphOp::SliceInputDescription>(input);+ auto slice_r = ov::as_type_ptr<op_util::SubGraphOp::SliceInputDescription>(key);if (slice_l && slice_r) {return slice_l->m_axis == slice_r->m_axis && slice_l->m_start == slice_r->m_start &&@@ -47,8 +50,8 @@ ov::pass::EliminateDuplicateTIInputs::EliminateDuplicateTIInputs() {slice_l->m_stride == slice_r->m_stride;}- auto merged_l = ov::as_type_ptr<SubGraphOp::MergedInputDescription>(input);- auto merged_r = ov::as_type_ptr<SubGraphOp::MergedInputDescription>(key);+ auto merged_l = ov::as_type_ptr<op_util::SubGraphOp::MergedInputDescription>(input);+ auto merged_r = ov::as_type_ptr<op_util::SubGraphOp::MergedInputDescription>(key);if (merged_l && merged_r) {return merged_l->m_body_value_index == merged_r->m_body_value_index;@@ -79,7 +82,7 @@ ov::pass::EliminateDuplicateTIInputs::EliminateDuplicateTIInputs() {}// Create new TI- auto new_ti = std::make_shared<ov::op::v0::TensorIterator>();+ auto new_ti = std::make_shared<v0::TensorIterator>();new_ti->set_output_descriptions(0, ti->get_output_descriptions());ov::ParameterVector new_params;for (const auto& remain : should_stay) {@@ -92,12 +95,12 @@ ov::pass::EliminateDuplicateTIInputs::EliminateDuplicateTIInputs() {for (const auto& remain : should_stay) {auto par = body->get_parameters()[remain->m_body_parameter_index];auto in = ti->input_value(remain->m_input_index);- if (auto invariant = ov::as_type_ptr<SubGraphOp::InvariantInputDescription>(remain)) {+ if (auto invariant = ov::as_type_ptr<op_util::SubGraphOp::InvariantInputDescription>(remain)) {new_ti->set_invariant_input(par, in);- } else if (auto merged = ov::as_type_ptr<SubGraphOp::MergedInputDescription>(remain)) {+ } else if (auto merged = ov::as_type_ptr<op_util::SubGraphOp::MergedInputDescription>(remain)) {auto results = body->get_results();new_ti->set_merged_input(par, in, results[merged->m_body_value_index]);- } else if (auto slice = ov::as_type_ptr<SubGraphOp::SliceInputDescription>(remain)) {+ } else if (auto slice = ov::as_type_ptr<op_util::SubGraphOp::SliceInputDescription>(remain)) {new_ti->set_sliced_input(par,in,slice->m_start,@@ -117,3 +120,5 @@ ov::pass::EliminateDuplicateTIInputs::EliminateDuplicateTIInputs() {auto m = std::make_shared<pattern::Matcher>(ti, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/eliminate_loop_inputs_outputs.cpp b/src/common/transformations/src/transformations/common_optimizations/eliminate_loop_inputs_outputs.cppindex cab3c5d2cd4..91a69bb6e2a 100644--- a/src/common/transformations/src/transformations/common_optimizations/eliminate_loop_inputs_outputs.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/eliminate_loop_inputs_outputs.cpp@@ -15,25 +15,23 @@#include "openvino/op/tensor_iterator.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-using namespace std;-using namespace ov;-using namespace ov::op;-using namespace ov::op::util;-using namespace ov::element;-using namespace ov::pass::pattern;--using InvariantD = MultiSubGraphOp::InvariantInputDescription;-using SlicedD = MultiSubGraphOp::SliceInputDescription;-using MergedD = MultiSubGraphOp::MergedInputDescription;-using OutputD = MultiSubGraphOp::BodyOutputDescription;-using ConcatD = MultiSubGraphOp::ConcatOutputDescription;+namespace ov::pass {++namespace v0 = ov::op::v0;+namespace v5 = ov::op::v5;+namespace op_util = ov::op::util;++using InvariantD = op_util::MultiSubGraphOp::InvariantInputDescription;+using SlicedD = op_util::MultiSubGraphOp::SliceInputDescription;+using MergedD = op_util::MultiSubGraphOp::MergedInputDescription;+using OutputD = op_util::MultiSubGraphOp::BodyOutputDescription;+using ConcatD = op_util::MultiSubGraphOp::ConcatOutputDescription;using ResultPtr = std::shared_ptr<v0::Result>;-using OutputDescPtr = MultiSubGraphOp::OutputDescription::Ptr;+using OutputDescPtr = op_util::MultiSubGraphOp::OutputDescription::Ptr;using OutputDescMap = std::unordered_map<ResultPtr, OutputDescPtr>;-using InputDescPtr = MultiSubGraphOp::InputDescription::Ptr;+using InputDescPtr = op_util::MultiSubGraphOp::InputDescription::Ptr;using BodyResultIdxMap = std::unordered_map<ResultPtr, uint64_t>;-namespace {std::unordered_set<uint64_t> remove_results(const std::shared_ptr<v0::Parameter>& param,const InputDescPtr& input_desc,@@ -86,10 +84,10 @@ std::unordered_set<uint64_t> remove_results(const std::shared_ptr<v0::Parameter>}} // namespace-ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {+EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {MATCHER_SCOPE(EliminateLoopInputsOutputs);- auto subgraph_label = wrap_type<v5::Loop, v0::TensorIterator>();+ auto subgraph_label = pattern::wrap_type<v5::Loop, v0::TensorIterator>();matcher_pass_callback callback = [=](pattern::Matcher& m) {// delete useless Parameter and Result nodes in isolated graph (Parameter->Result)@@ -100,7 +98,8 @@ ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {const auto& pattern_to_output = m.get_pattern_value_map();- auto subgraph = as_type_ptr<SubGraphOp>(pattern_to_output.at(subgraph_label).get_node_shared_ptr());+ auto subgraph =+ ov::as_type_ptr<op_util::SubGraphOp>(pattern_to_output.at(subgraph_label).get_node_shared_ptr());if (!subgraph) {return false;}@@ -108,15 +107,15 @@ ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {const auto& body_params = body_model->get_parameters();const auto& body_results = body_model->get_results();- std::shared_ptr<SubGraphOp> new_node;+ std::shared_ptr<op_util::SubGraphOp> new_node;const auto& subgraph_in_values = subgraph->input_values();int64_t body_condition_output_idx = -1;int64_t current_iteration_input_idx = -1;- if (auto loop = as_type_ptr<v5::Loop>(subgraph)) {+ if (auto loop = ov::as_type_ptr<v5::Loop>(subgraph)) {const auto& trip_count = subgraph_in_values[0];const auto& exec_cond = subgraph_in_values[1];- auto new_loop = make_shared<v5::Loop>(trip_count, exec_cond);+ auto new_loop = std::make_shared<v5::Loop>(trip_count, exec_cond);new_loop->set_special_body_ports(loop->get_special_body_ports());new_node = new_loop;// condition Result node index may be shifted due to removing@@ -125,7 +124,7 @@ ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {body_condition_output_idx = loop->get_special_body_ports().body_condition_output_idx;current_iteration_input_idx = loop->get_special_body_ports().current_iteration_input_idx;} else {- new_node = make_shared<v0::TensorIterator>();+ new_node = std::make_shared<v0::TensorIterator>();}new_node->set_function(body_model);@@ -201,7 +200,7 @@ ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {}// move input description for unremoved node- if (const auto merged_input_desc = as_type_ptr<MergedD>(input_description)) {+ if (const auto merged_input_desc = ov::as_type_ptr<MergedD>(input_description)) {if (cur_remove_result_inds.size() > 0) {// at least one Result node is going to be removed// no back edge after removing so use invariant input@@ -214,11 +213,11 @@ ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {new_node->set_merged_input(body_param, init_value, body_res);});}- } else if (const auto invariant_input_desc = as_type_ptr<InvariantD>(input_description)) {+ } else if (const auto invariant_input_desc = ov::as_type_ptr<InvariantD>(input_description)) {process_inputs_outputs.emplace_back([=, &new_node]() {new_node->set_invariant_input(body_param, init_value);});- } else if (const auto sliced_input_desc = as_type_ptr<SlicedD>(input_description)) {+ } else if (const auto sliced_input_desc = ov::as_type_ptr<SlicedD>(input_description)) {process_inputs_outputs.emplace_back([=, &new_node]() {new_node->set_sliced_input(body_param,init_value,@@ -249,11 +248,11 @@ ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {continue;}- if (const auto body_output_desc = as_type_ptr<OutputD>(output_description)) {+ if (const auto body_output_desc = ov::as_type_ptr<OutputD>(output_description)) {process_inputs_outputs.emplace_back([=, &idx_to_new_output]() {idx_to_new_output[out_idx] = new_node->get_iter_value(body_result, body_output_desc->m_iteration);});- } else if (const auto concat_output_desc = as_type_ptr<ConcatD>(output_description)) {+ } else if (const auto concat_output_desc = ov::as_type_ptr<ConcatD>(output_description)) {process_inputs_outputs.emplace_back([=, &idx_to_new_output]() {idx_to_new_output[out_idx] = new_node->get_concatenated_slices(body_result,concat_output_desc->m_start,@@ -269,7 +268,7 @@ ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {}}- if (auto loop = as_type_ptr<v5::Loop>(new_node)) {+ if (auto loop = ov::as_type_ptr<v5::Loop>(new_node)) {// update of body condition index is required due to body graph clean-upauto special_body_ports = loop->get_special_body_ports();if (special_body_ports.body_condition_output_idx >= 0) {@@ -282,10 +281,10 @@ ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {loop->set_special_body_ports(special_body_ports);}- for_each(delete_inputs_outputs.begin(), delete_inputs_outputs.end(), [](function<void()>& f) {+ std::for_each(delete_inputs_outputs.begin(), delete_inputs_outputs.end(), [](std::function<void()>& f) {f();});- for_each(process_inputs_outputs.begin(), process_inputs_outputs.end(), [](function<void()>& f) {+ std::for_each(process_inputs_outputs.begin(), process_inputs_outputs.end(), [](std::function<void()>& f) {f();});@@ -298,6 +297,8 @@ ov::pass::EliminateLoopInputsOutputs::EliminateLoopInputsOutputs() {return true;};- auto m = make_shared<Matcher>(subgraph_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(subgraph_label, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp b/src/common/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cppindex e3dfc7700b5..d50e605133b 100644--- a/src/common/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/eliminate_unsqueeze_gather.cpp@@ -20,10 +20,16 @@#include "transformations/utils/utils.hpp"using namespace ov;-using namespace ov::op;-using namespace ov::op::util;-using namespace ov::pass::pattern;+using ov::pass::pattern::any_input;+using ov::pass::pattern::consumers_count;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::rank_equals;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;ov::pass::EliminateUnsqueezeGather::EliminateUnsqueezeGather() {MATCHER_SCOPE(EliminateUnsqueezeGather);// Remove Unsqueeze + Gather pair, if Gather gathers data by `1` dimension that was previously added by Unsqueeze@@ -32,7 +38,7 @@ ov::pass::EliminateUnsqueezeGather::EliminateUnsqueezeGather() {const auto unsqueeze = wrap_type<v0::Unsqueeze>({unsqueezeInput, unsqueezeAxis}, consumers_count(1));const auto gatherIndices = v0::Constant::create(element::i64, Shape{}, {0});const auto gatherAxis = any_input();- const auto gather = wrap_type<GatherBase>({unsqueeze, gatherIndices, gatherAxis});+ const auto gather = wrap_type<op_util::GatherBase>({unsqueeze, gatherIndices, gatherAxis});ov::matcher_pass_callback callback = [=](Matcher& m) {auto& patternValue = m.get_pattern_value_map();@@ -77,20 +83,21 @@ inline bool scalar_with_one_consumer(const Output<Node>& out) {ov::pass::EliminateGatherUnsqueeze::EliminateGatherUnsqueeze() {MATCHER_SCOPE(EliminateGatherUnsqueeze);- const auto gather_label = wrap_type<GatherBase>(scalar_with_one_consumer);- const auto be_label = wrap_type<BinaryElementwiseArithmetic, BinaryElementwiseComparison, BinaryElementwiseLogical>(- {gather_label, any_input()},- scalar_with_one_consumer);- const auto or_label = std::make_shared<pattern::op::Or>(OutputVector{gather_label, be_label});+ const auto gather_label = wrap_type<op_util::GatherBase>(scalar_with_one_consumer);+ const auto be_label =+ wrap_type<op_util::BinaryElementwiseArithmetic,+ op_util::BinaryElementwiseComparison,+ op_util::BinaryElementwiseLogical>({gather_label, any_input()}, scalar_with_one_consumer);+ const auto or_label = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{gather_label, be_label});const auto unsqueeze_label = wrap_type<v0::Unsqueeze, v1::Reshape>({or_label, any_input()}, rank_equals(1));ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto pattern_nodes = m.get_pattern_map();auto& gather = pattern_nodes.at(gather_label);auto& unsqueeze = pattern_nodes.at(unsqueeze_label);- const auto& indices = ov::op::util::make_try_fold<v1::Reshape>(gather->input_value(1),- v0::Constant::create(element::i32, {1}, {1}),- false);+ const auto& indices = op_util::make_try_fold<v1::Reshape>(gather->input_value(1),+ v0::Constant::create(element::i32, {1}, {1}),+ false);register_new_node(indices);gather->input(1).replace_source_output(indices->output(0));copy_runtime_info({unsqueeze, gather}, {indices, gather});diff --git a/src/common/transformations/src/transformations/common_optimizations/enable_shapeof_constant_folding.cpp b/src/common/transformations/src/transformations/common_optimizations/enable_shapeof_constant_folding.cppindex 5a8e8b7b2b6..a881b245be9 100644--- a/src/common/transformations/src/transformations/common_optimizations/enable_shapeof_constant_folding.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/enable_shapeof_constant_folding.cpp@@ -8,7 +8,9 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/rt_info/disable_constant_folding.hpp"-ov::pass::EnableShapeOfConstantFolding::EnableShapeOfConstantFolding(bool check_shape) {+namespace ov::pass {++EnableShapeOfConstantFolding::EnableShapeOfConstantFolding(bool check_shape) {auto shape_of = pattern::wrap_type<ov::op::util::ShapeOfBase>([=](const Output<Node>& output) {const auto& shape = output.get_partial_shape();if (!check_shape)@@ -24,3 +26,5 @@ ov::pass::EnableShapeOfConstantFolding::EnableShapeOfConstantFolding(bool check_auto m = std::make_shared<pattern::Matcher>(shape_of, "EnableShapeOfConstantFolding");this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/fold_subgraph_empty_inputs.cpp b/src/common/transformations/src/transformations/common_optimizations/fold_subgraph_empty_inputs.cppindex 16d9472887b..cc73a8de99d 100644--- a/src/common/transformations/src/transformations/common_optimizations/fold_subgraph_empty_inputs.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/fold_subgraph_empty_inputs.cpp@@ -15,11 +15,16 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::FoldSubgraphEmptyInputs::FoldSubgraphEmptyInputs() {+namespace v0 = ov::op::v0;+namespace op_util = ov::op::util;++namespace ov::pass {++FoldSubgraphEmptyInputs::FoldSubgraphEmptyInputs() {MATCHER_SCOPE(FoldSubgraphEmptyInputs);- auto multi_subgraph_op_pattern = pattern::wrap_type<ov::op::util::MultiSubGraphOp>();+ auto multi_subgraph_op_pattern = pattern::wrap_type<op_util::MultiSubGraphOp>();ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto multi_subgraph_op = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(m.get_match_root());+ auto multi_subgraph_op = ov::as_type_ptr<op_util::MultiSubGraphOp>(m.get_match_root());if (multi_subgraph_op == nullptr) {return false;}@@ -35,7 +40,7 @@ ov::pass::FoldSubgraphEmptyInputs::FoldSubgraphEmptyInputs() {std::back_inserter(empty_inputs),[](const Output<Node>& input) {// skip constants- if (ov::as_type_ptr<ov::op::v0::Constant>(input.get_node_shared_ptr())) {+ if (ov::as_type_ptr<v0::Constant>(input.get_node_shared_ptr())) {return false;}// skip non-static shapes@@ -51,7 +56,7 @@ ov::pass::FoldSubgraphEmptyInputs::FoldSubgraphEmptyInputs() {if (empty_inputs.size()) {for (const auto& input : empty_inputs) {const ov::Output<ov::Node> const_empty_replacement =- std::make_shared<ov::op::v0::Constant>(input.get_element_type(), input.get_shape());+ std::make_shared<v0::Constant>(input.get_element_type(), input.get_shape());std::replace(std::begin(multi_subgraph_op_inputs),std::end(multi_subgraph_op_inputs),input,@@ -67,15 +72,17 @@ ov::pass::FoldSubgraphEmptyInputs::FoldSubgraphEmptyInputs() {this->register_matcher(m, callback);}-void ov::pass::disable_fold_subgraph_empty_inputs(const std::shared_ptr<ov::Node>& node) {+void disable_fold_subgraph_empty_inputs(const std::shared_ptr<ov::Node>& node) {node->get_rt_info().emplace(DisableFoldSubgraphEmptyInputs::get_type_info_static(),DisableFoldSubgraphEmptyInputs{});}-void ov::pass::enable_fold_subgraph_empty_inputs(const std::shared_ptr<ov::Node>& node) {+void enable_fold_subgraph_empty_inputs(const std::shared_ptr<ov::Node>& node) {node->get_rt_info().erase(DisableFoldSubgraphEmptyInputs::get_type_info_static());}-bool ov::pass::fold_subgraph_empty_inputs_is_disabled(const std::shared_ptr<ov::Node>& node) {+bool fold_subgraph_empty_inputs_is_disabled(const std::shared_ptr<ov::Node>& node) {return node->get_rt_info().count(DisableFoldSubgraphEmptyInputs::get_type_info_static());}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/fq_mul_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/fq_mul_fusion.cppindex b58dd18992d..2d667028768 100644--- a/src/common/transformations/src/transformations/common_optimizations/fq_mul_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/fq_mul_fusion.cpp@@ -20,6 +20,13 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::consumers_count;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;// This transformation multiplies the "output_low" and "output_high" inputs of the FQ operation// by the constant value that before transormation is used to multiply the output of FQ.// Both output_low and output_high are multiplied by the value represented as C (a constant) below.@@ -43,19 +50,18 @@ov::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() {MATCHER_SCOPE(FakeQuantizeMulFusion);- const auto data_p = pass::pattern::any_input();- const auto fq_output_low_p = pass::pattern::any_input();- const auto fq_output_high_p = pass::pattern::any_input();+ const auto data_p = any_input();+ const auto fq_output_low_p = any_input();+ const auto fq_output_high_p = any_input();- const auto fq_node_p = ov::pass::pattern::wrap_type<ov::op::v0::FakeQuantize>(- {data_p, pass::pattern::any_input(), pass::pattern::any_input(), fq_output_low_p, fq_output_high_p},- pattern::consumers_count(1));+ const auto fq_node_p =+ wrap_type<v0::FakeQuantize>({data_p, any_input(), any_input(), fq_output_low_p, fq_output_high_p},+ consumers_count(1));- const auto mul_constant_p = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- const auto mul_node_p =- ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({fq_node_p, mul_constant_p}, pattern::consumers_count(1));+ const auto mul_constant_p = wrap_type<v0::Constant>();+ const auto mul_node_p = wrap_type<v1::Multiply>({fq_node_p, mul_constant_p}, consumers_count(1));- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& data = pattern_map.at(data_p);@@ -69,13 +75,13 @@ ov::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() {if (!is_single_value) {float v;- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(mul_constant);+ auto constant = ov::as_type_ptr<v0::Constant>(mul_constant);if (constant) {is_single_value = ov::op::util::get_single_value(constant, v);if (is_single_value) {mul_constant_shape = Shape{1};mul_constant =- std::make_shared<ov::op::v0::Constant>(mul_constant->get_element_type(), mul_constant_shape, v);+ std::make_shared<v0::Constant>(mul_constant->get_element_type(), mul_constant_shape, v);}}}@@ -85,7 +91,7 @@ ov::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() {// Convolution and GroupConvolution LP transformations require output low/high to have the same valuesbool fq_output_is_conv =std::any_of(fq_outputs.begin(), fq_outputs.end(), [](const std::shared_ptr<Node>& node) -> bool {- return is_type<ov::op::v1::Convolution>(node) || is_type<ov::op::v1::GroupConvolution>(node);+ return is_type<v1::Convolution>(node) || is_type<v1::GroupConvolution>(node);});if (fq_output_is_conv) {return false;@@ -98,15 +104,15 @@ ov::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() {auto diff = rank - mul_constant_shape.size();if (diff > 0) {mul_constant_shape.insert(mul_constant_shape.begin(), diff, 1);- mul_constant = std::make_shared<ov::op::v1::Reshape>(+ mul_constant = std::make_shared<v1::Reshape>(mul_constant,- ov::op::v0::Constant::create(element::i64, Shape{mul_constant_shape.size()}, mul_constant_shape),+ v0::Constant::create(element::i64, Shape{mul_constant_shape.size()}, mul_constant_shape),false);}}auto get_adjusted_output_range = [&](const Output<Node>& node) -> std::shared_ptr<Node> {- auto ret = std::make_shared<ov::op::v1::Multiply>(node, mul_constant);+ auto ret = std::make_shared<v1::Multiply>(node, mul_constant);copy_runtime_info(node.get_node_shared_ptr(), ret);auto constant = ov::util::get_constant_from_source(ret);if (constant)@@ -120,7 +126,7 @@ ov::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() {get_adjusted_output_range(original_output_low),get_adjusted_output_range(original_output_high)});bool fq_on_weights =- is_type<ov::op::v0::Constant>(data.get_node()) || ov::util::get_constant_from_source(data) != nullptr;+ is_type<v0::Constant>(data.get_node()) || ov::util::get_constant_from_source(data) != nullptr;if (!fq_on_weights && transformation_callback(new_fq_node))return false;@@ -131,7 +137,7 @@ ov::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() {// will lead to shape inconsistency in remaining graph. This check must be// removed in future when FQ will have correct validate_and_infer function// for cases with NUMPY broadcast.- auto fq_casted = ov::as_type_ptr<ov::op::v0::FakeQuantize>(new_fq_node);+ auto fq_casted = ov::as_type_ptr<v0::FakeQuantize>(new_fq_node);if (!fq_casted) {return false;}@@ -153,6 +159,6 @@ ov::pass::FakeQuantizeMulFusion::FakeQuantizeMulFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_node_p, matcher_name);+ auto m = std::make_shared<Matcher>(mul_node_p, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/fq_reshape_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/fq_reshape_fusion.cppindex 7f65f9966ba..8f8c0cfccbd 100644--- a/src/common/transformations/src/transformations/common_optimizations/fq_reshape_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/fq_reshape_fusion.cpp@@ -19,29 +19,33 @@#include "openvino/pass/pattern/op/optional.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::FakeQuantizeReshapeFusion::FakeQuantizeReshapeFusion() {+namespace ov::pass {++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++FakeQuantizeReshapeFusion::FakeQuantizeReshapeFusion() {MATCHER_SCOPE(FakeQuantizeReshapeFusion);// for weights only- const auto data_p = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(pattern::has_static_shape());- const auto convert_p = ov::pass::pattern::optional<ov::op::v0::Convert>(data_p, pattern::consumers_count(1));- const auto fq_node_p =- ov::pass::pattern::wrap_type<ov::op::v0::FakeQuantize>({convert_p,- pattern::any_input(pattern::has_static_shape()),- pattern::any_input(pattern::has_static_shape()),- pattern::any_input(pattern::has_static_shape()),- pattern::any_input(pattern::has_static_shape())},- pattern::consumers_count(1));- const auto reshape_node_p = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>(- {fq_node_p, ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},+ const auto data_p = pattern::wrap_type<v0::Constant>(pattern::has_static_shape());+ const auto convert_p = pattern::optional<v0::Convert>(data_p, pattern::consumers_count(1));+ const auto fq_node_p = pattern::wrap_type<v0::FakeQuantize>({convert_p,+ pattern::any_input(pattern::has_static_shape()),+ pattern::any_input(pattern::has_static_shape()),+ pattern::any_input(pattern::has_static_shape()),+ pattern::any_input(pattern::has_static_shape())},+ pattern::consumers_count(1));+ const auto reshape_node_p = pattern::wrap_type<v1::Reshape>(+ {fq_node_p, pattern::wrap_type<v0::Constant>()},[](const Output<Node>& output) {// WA: check that all Reshape node consumers are not GroupConvolution operationsconst auto& target_inputs = output.get_target_inputs();return std::all_of(target_inputs.begin(), target_inputs.end(), [](const Input<Node>& input) {- return input.get_node()->get_type_info() != ov::op::v1::GroupConvolution::get_type_info_static();+ return input.get_node()->get_type_info() != v1::GroupConvolution::get_type_info_static();});});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& fq_node = pattern_map.at(fq_node_p).get_node_shared_ptr();const auto& reshape_node = pattern_map.at(reshape_node_p).get_node_shared_ptr();@@ -72,7 +76,7 @@ ov::pass::FakeQuantizeReshapeFusion::FakeQuantizeReshapeFusion() {} else {auto reshaped_input = reshape_node->clone_with_new_inputs({limit_input,- ov::op::v0::Constant::create(element::i64, {new_limit_shape.size()}, new_limit_shape)});+ v0::Constant::create(element::i64, {new_limit_shape.size()}, new_limit_shape)});if (auto constant = ov::util::get_constant_from_source(reshaped_input)) {reshaped_input = constant;}@@ -108,6 +112,8 @@ ov::pass::FakeQuantizeReshapeFusion::FakeQuantizeReshapeFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reshape_node_p, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(reshape_node_p, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/fuse_moe_experts.cpp b/src/common/transformations/src/transformations/common_optimizations/fuse_moe_experts.cppindex 1be11283e60..7179c98fdb0 100644--- a/src/common/transformations/src/transformations/common_optimizations/fuse_moe_experts.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/fuse_moe_experts.cpp@@ -49,11 +49,15 @@#include "transformations/rt_info/decompression.hpp"#include "transformations/utils/utils.hpp"-namespace ov {-namespace pass {+namespace ov::pass {-using namespace ov::pass;-using ov::pass::pattern::wrap_type, ov::pass::pattern::PatternValueMap;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v8 = ov::op::v8;+namespace v12 = ov::op::v12;+namespace op_util = ov::op::util;namespace {@@ -62,7 +66,7 @@ namespace {// This pattern matches Slice operations like: Slice(input, [0,0], [1,INT_MAX], [1,1], [0,1])// index_add__Slice_2 = makeOP<opset8::Slice>({index_add__ScatterElementsUpdate_5, {0,0}, {1,INT_MAX}, {1,1}, {0,1}});bool is_slice_to_end(const std::shared_ptr<Node>& node) {- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node);+ auto constant = ov::as_type_ptr<v0::Constant>(node);if (!constant || !constant->get_element_type().is_integral_number()) {return false;}@@ -87,7 +91,7 @@ bool is_slice_to_end(const std::shared_ptr<Node>& node) {}// Pattern matching for individual expert computation block with SwiGLU activation-std::shared_ptr<pattern::op::Block> mlp3_no_bias_swiglu_block(+std::shared_ptr<ov::pass::pattern::op::Block> mlp3_no_bias_swiglu_block(const Output<Node>& permute_Transpose, // Transpose -> OneHot -> TopK -> Softmax -> MatMul -> Hidden Statesconst Output<Node>& unsqueeze_Unsqueeze, // Unsqueeze -> Reshape -> Hidden Statesconst Output<Node>&@@ -95,86 +99,87 @@ std::shared_ptr<pattern::op::Block> mlp3_no_bias_swiglu_block(const Output<Node>& index_Reshape // Reshape -> Divide -> TopK -> Softmax -> MatMul -> Hidden States) {auto index_add__ScatterElementsUpdate_2 = pattern::any_input();- auto shape_const = wrap_type<ov::op::v0::Constant>();- auto expert_id = wrap_type<ov::op::v0::Constant>();- auto slice_end_const = wrap_type<ov::op::v0::Constant>();- auto select_Gather_1 = wrap_type<ov::op::v8::Gather>(- {permute_Transpose, expert_id, wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"))},+ auto shape_const = pattern::wrap_type<v0::Constant>();+ auto expert_id = pattern::wrap_type<v0::Constant>();+ auto slice_end_const = pattern::wrap_type<v0::Constant>();+ auto select_Gather_1 = pattern::wrap_type<v8::Gather>(+ {permute_Transpose, expert_id, pattern::wrap_type<v0::Constant>(pattern::value_matches("0"))},{{"batch_dims", 0}});- auto squeeze_Squeeze_1 =- wrap_type<ov::op::v0::Squeeze>({select_Gather_1, wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"))});+ auto squeeze_Squeeze_1 = pattern::wrap_type<v0::Squeeze>(+ {select_Gather_1, pattern::wrap_type<v0::Constant>(pattern::value_matches("0"))});// NonZero output_type relaxed to accept both i32 and i64- auto ListUnpack_NonZero_1 = wrap_type<ov::op::v3::NonZero>({squeeze_Squeeze_1});- auto ListUnpack_Split_1 = wrap_type<ov::op::v1::Split>(- {ListUnpack_NonZero_1, wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"))},+ auto ListUnpack_NonZero_1 = pattern::wrap_type<v3::NonZero>({squeeze_Squeeze_1});+ auto ListUnpack_Split_1 = pattern::wrap_type<v1::Split>(+ {ListUnpack_NonZero_1, pattern::wrap_type<v0::Constant>(pattern::value_matches("0"))},{{"num_splits", 2}});ListUnpack_Split_1->set_output_size(2);- auto ListUnpack_Squeeze_0_1 = wrap_type<ov::op::v0::Squeeze>(- {ListUnpack_Split_1->output(1), wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"))});+ auto ListUnpack_Squeeze_0_1 = pattern::wrap_type<v0::Squeeze>(+ {ListUnpack_Split_1->output(1), pattern::wrap_type<v0::Constant>(pattern::value_matches("0"))});// Convert is optional - pattern matches both with and without type conversion- auto index_add__Convert_1 = wrap_type<ov::op::v0::Convert>({ListUnpack_Squeeze_0_1}) | ListUnpack_Squeeze_0_1;- auto index_add__Reshape_1 = wrap_type<ov::op::v1::Reshape>(- {index_add__Convert_1, wrap_type<ov::op::v0::Constant>(pattern::value_matches("-1, 1"))},+ auto index_add__Convert_1 = pattern::wrap_type<v0::Convert>({ListUnpack_Squeeze_0_1}) | ListUnpack_Squeeze_0_1;+ auto index_add__Reshape_1 = pattern::wrap_type<v1::Reshape>(+ {index_add__Convert_1, pattern::wrap_type<v0::Constant>(pattern::value_matches("-1, 1"))},{{"special_zero", false}});auto index_add__Slice_1 =- wrap_type<ov::op::v8::Slice>({index_add__ScatterElementsUpdate_2,- wrap_type<ov::op::v0::Constant>(pattern::value_matches("0, 0")),- slice_end_const,- wrap_type<ov::op::v0::Constant>(pattern::value_matches("1, 1")),- wrap_type<ov::op::v0::Constant>(pattern::value_matches("0, 1"))});- auto index_add__ShapeOf_14 = wrap_type<ov::op::v3::ShapeOf>({index_add__Slice_1}, {{"output_type", "i32"}});+ pattern::wrap_type<v8::Slice>({index_add__ScatterElementsUpdate_2,+ pattern::wrap_type<v0::Constant>(pattern::value_matches("0, 0")),+ slice_end_const,+ pattern::wrap_type<v0::Constant>(pattern::value_matches("1, 1")),+ pattern::wrap_type<v0::Constant>(pattern::value_matches("0, 1"))});+ auto index_add__ShapeOf_14 = pattern::wrap_type<v3::ShapeOf>({index_add__Slice_1}, {{"output_type", "i32"}});auto index_add__Broadcast_16 =- wrap_type<ov::op::v3::Broadcast>({index_add__Reshape_1, index_add__ShapeOf_14}, {{"mode", "bidirectional"}});+ pattern::wrap_type<v3::Broadcast>({index_add__Reshape_1, index_add__ShapeOf_14}, {{"mode", "bidirectional"}});auto unsqueeze_Unsqueeze_reshape =- wrap_type<ov::op::v1::Reshape>({unsqueeze_Unsqueeze, pattern::any_input()}, {{"special_zero", false}});- auto index_Gather_2 = wrap_type<ov::op::v8::Gather>({unsqueeze_Unsqueeze_reshape,- index_add__Convert_1,- wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"))},- {{"batch_dims", 0}});+ pattern::wrap_type<v1::Reshape>({unsqueeze_Unsqueeze, pattern::any_input()}, {{"special_zero", false}});+ auto index_Gather_2 =+ pattern::wrap_type<v8::Gather>({unsqueeze_Unsqueeze_reshape,+ index_add__Convert_1,+ pattern::wrap_type<v0::Constant>(pattern::value_matches("0"))},+ {{"batch_dims", 0}});auto reshape_Reshape_1_0 =- wrap_type<ov::op::v1::Reshape>({index_Gather_2, pattern::any_input()}, {{"special_zero", true}});+ pattern::wrap_type<v1::Reshape>({index_Gather_2, pattern::any_input()}, {{"special_zero", true}});auto reshape_Reshape_1_1 =- wrap_type<ov::op::v1::Reshape>({reshape_Reshape_1_0, pattern::any_input()}, {{"special_zero", true}});+ pattern::wrap_type<v1::Reshape>({reshape_Reshape_1_0, pattern::any_input()}, {{"special_zero", true}});auto reshape_Reshape_1_2 =- wrap_type<ov::op::v1::Reshape>({reshape_Reshape_1_1, pattern::any_input()}, {{"special_zero", true}});+ pattern::wrap_type<v1::Reshape>({reshape_Reshape_1_1, pattern::any_input()}, {{"special_zero", true}});auto reshape_Reshape_1 =- wrap_type<ov::op::v1::Reshape>({reshape_Reshape_1_2, shape_const}, {{"special_zero", true}});+ pattern::wrap_type<v1::Reshape>({reshape_Reshape_1_2, shape_const}, {{"special_zero", true}});auto gate_proj_weight = pattern::any_input(pattern::rank_equals(2));- auto linear_MatMul_gate = wrap_type<ov::op::v0::MatMul>({reshape_Reshape_1, gate_proj_weight},- {{"transpose_a", false}, {"transpose_b", true}});- auto silu_Swish = wrap_type<ov::op::v4::Swish>({linear_MatMul_gate});+ auto linear_MatMul_gate = pattern::wrap_type<v0::MatMul>({reshape_Reshape_1, gate_proj_weight},+ {{"transpose_a", false}, {"transpose_b", true}});+ auto silu_Swish = pattern::wrap_type<v4::Swish>({linear_MatMul_gate});auto up_proj_weight = pattern::any_input(pattern::rank_equals(2));- auto linear_MatMul_up = wrap_type<ov::op::v0::MatMul>({reshape_Reshape_1, up_proj_weight},- {{"transpose_a", false}, {"transpose_b", true}});- auto mul_Multiply = wrap_type<ov::op::v1::Multiply>({silu_Swish, linear_MatMul_up}, {{"auto_broadcast", "numpy"}});+ auto linear_MatMul_up = pattern::wrap_type<v0::MatMul>({reshape_Reshape_1, up_proj_weight},+ {{"transpose_a", false}, {"transpose_b", true}});+ auto mul_Multiply = pattern::wrap_type<v1::Multiply>({silu_Swish, linear_MatMul_up}, {{"auto_broadcast", "numpy"}});auto down_proj_weight = pattern::any_input(pattern::rank_equals(2));- auto linear_MatMul_down = wrap_type<ov::op::v0::MatMul>({mul_Multiply, down_proj_weight},- {{"transpose_a", false}, {"transpose_b", true}});- auto ListUnpack_Squeeze_1 = wrap_type<ov::op::v0::Squeeze>(- {ListUnpack_Split_1->output(0), wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"))});+ auto linear_MatMul_down = pattern::wrap_type<v0::MatMul>({mul_Multiply, down_proj_weight},+ {{"transpose_a", false}, {"transpose_b", true}});+ auto ListUnpack_Squeeze_1 = pattern::wrap_type<v0::Squeeze>(+ {ListUnpack_Split_1->output(0), pattern::wrap_type<v0::Constant>(pattern::value_matches("0"))});// Convert is optional - pattern matches both with and without type conversion- auto index_Convert_4 = wrap_type<ov::op::v0::Convert>({ListUnpack_Squeeze_1}) | ListUnpack_Squeeze_1;+ auto index_Convert_4 = pattern::wrap_type<v0::Convert>({ListUnpack_Squeeze_1}) | ListUnpack_Squeeze_1;auto index_Multiply_1 =- wrap_type<ov::op::v1::Multiply>({index_add__Convert_1, index_Split_out_1}, {{"auto_broadcast", "numpy"}});- auto index_Add_1 = wrap_type<ov::op::v1::Add>({index_Convert_4, index_Multiply_1}, {{"auto_broadcast", "numpy"}});- auto index_Gather_3 = wrap_type<ov::op::v8::Gather>(- {index_Reshape, index_Add_1, wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"))},+ pattern::wrap_type<v1::Multiply>({index_add__Convert_1, index_Split_out_1}, {{"auto_broadcast", "numpy"}});+ auto index_Add_1 = pattern::wrap_type<v1::Add>({index_Convert_4, index_Multiply_1}, {{"auto_broadcast", "numpy"}});+ auto index_Gather_3 = pattern::wrap_type<v8::Gather>(+ {index_Reshape, index_Add_1, pattern::wrap_type<v0::Constant>(pattern::value_matches("0"))},{{"batch_dims", 0}});- auto index_Reshape_8_1 = wrap_type<ov::op::v1::Reshape>(- {index_Gather_3, wrap_type<ov::op::v0::Constant>(pattern::value_matches("0, 1"))},+ auto index_Reshape_8_1 = pattern::wrap_type<v1::Reshape>(+ {index_Gather_3, pattern::wrap_type<v0::Constant>(pattern::value_matches("0, 1"))},{{"special_zero", true}});auto mul_Multiply_2 =- wrap_type<ov::op::v1::Multiply>({linear_MatMul_down, index_Reshape_8_1}, {{"auto_broadcast", "numpy"}});+ pattern::wrap_type<v1::Multiply>({linear_MatMul_down, index_Reshape_8_1}, {{"auto_broadcast", "numpy"}});auto index_add__Broadcast_17 =- wrap_type<ov::op::v3::Broadcast>({mul_Multiply_2, index_add__ShapeOf_14}, {{"mode", "bidirectional"}});+ pattern::wrap_type<v3::Broadcast>({mul_Multiply_2, index_add__ShapeOf_14}, {{"mode", "bidirectional"}});auto index_add__ScatterElementsUpdate_5 =- wrap_type<ov::op::v12::ScatterElementsUpdate>({index_add__ScatterElementsUpdate_2,- index_add__Broadcast_16,- index_add__Broadcast_17,- wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"))},- {{"reduction", "sum"}, {"use_init_val", true}});- auto block = std::make_shared<pattern::op::Block>(+ pattern::wrap_type<v12::ScatterElementsUpdate>({index_add__ScatterElementsUpdate_2,+ index_add__Broadcast_16,+ index_add__Broadcast_17,+ pattern::wrap_type<v0::Constant>(pattern::value_matches("0"))},+ {{"reduction", "sum"}, {"use_init_val", true}});+ auto block = std::make_shared<ov::pass::pattern::op::Block>(ov::OutputVector{permute_Transpose, unsqueeze_Unsqueeze, index_Split_out_1, index_Reshape},ov::OutputVector{index_add__ScatterElementsUpdate_5},"expert_block");@@ -190,39 +195,40 @@ std::shared_ptr<pattern::op::Block> mlp3_no_bias_swiglu_block(// Helper function to create commonly used axis constantsstruct AxisPatterns {- std::shared_ptr<Node> axis0 = wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"));- std::shared_ptr<Node> axis1 = wrap_type<ov::op::v0::Constant>(pattern::value_matches("1"));- std::shared_ptr<Node> axis2 = wrap_type<ov::op::v0::Constant>(pattern::value_matches("2"));+ std::shared_ptr<Node> axis0 = pattern::wrap_type<v0::Constant>(pattern::value_matches("0"));+ std::shared_ptr<Node> axis1 = pattern::wrap_type<v0::Constant>(pattern::value_matches("1"));+ std::shared_ptr<Node> axis2 = pattern::wrap_type<v0::Constant>(pattern::value_matches("2"));};// Helper function to extract a dimension from a tensor shape// Returns ShapeOf -> Gather(axis_index) -> Unsqueeze as a dimension vectorstd::shared_ptr<Node> extract_shape_dim(const Output<Node>& input, size_t axis_index) {- auto shape_of = std::make_shared<ov::op::v3::ShapeOf>(input, element::i64);- auto axis_scalar = ov::op::v0::Constant::create(element::i64, Shape{}, {static_cast<int64_t>(axis_index)});- auto axis0_scalar = ov::op::v0::Constant::create(element::i64, Shape{}, {0});- auto dim_scalar = std::make_shared<ov::op::v8::Gather>(shape_of, axis_scalar, axis0_scalar);- auto axis0_vector = ov::op::v0::Constant::create(element::i64, Shape{1}, {0});- return std::make_shared<ov::op::v0::Unsqueeze>(dim_scalar, axis0_vector);+ auto shape_of = std::make_shared<v3::ShapeOf>(input, element::i64);+ auto axis_scalar = v0::Constant::create(element::i64, Shape{}, {static_cast<int64_t>(axis_index)});+ auto axis0_scalar = v0::Constant::create(element::i64, Shape{}, {0});+ auto dim_scalar = std::make_shared<v8::Gather>(shape_of, axis_scalar, axis0_scalar);+ auto axis0_vector = v0::Constant::create(element::i64, Shape{1}, {0});+ return std::make_shared<v0::Unsqueeze>(dim_scalar, axis0_vector);}// Helper function to create router pattern (Softmax -> TopK -> OneHot -> Transpose)// This pattern identifies the expert selection logic from router logitsstd::pair<std::shared_ptr<Node>, std::shared_ptr<Node>> create_router_pattern() {auto linear_MatMul = pattern::any_input();- auto expert_num = wrap_type<ov::op::v0::Constant>();- auto num_topk = wrap_type<ov::op::v0::Constant>();- auto one_hot_on = wrap_type<ov::op::v0::Constant>(pattern::value_matches("1"));- auto one_hot_off = wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"));- auto transpose_perm = wrap_type<ov::op::v0::Constant>(pattern::value_matches("2, 1, 0"));-- auto softmax = wrap_type<ov::op::v8::Softmax>({linear_MatMul}, {{"axis", 1}});- auto topk = wrap_type<ov::op::v11::TopK>(+ auto expert_num = pattern::wrap_type<v0::Constant>();+ auto num_topk = pattern::wrap_type<v0::Constant>();+ auto one_hot_on = pattern::wrap_type<v0::Constant>(pattern::value_matches("1"));+ auto one_hot_off = pattern::wrap_type<v0::Constant>(pattern::value_matches("0"));+ auto transpose_perm = pattern::wrap_type<v0::Constant>(pattern::value_matches("2, 1, 0"));++ auto softmax = pattern::wrap_type<v8::Softmax>({linear_MatMul}, {{"axis", 1}});+ auto topk = pattern::wrap_type<ov::op::v11::TopK>({softmax, num_topk},{{"axis", -1}, {"mode", "max"}, {"sort", "value"}, {"index_element_type", "i64"}, {"stable", false}});topk->set_output_size(2);- auto one_hot = wrap_type<ov::op::v1::OneHot>({topk->output(1), expert_num, one_hot_on, one_hot_off}, {{"axis", 2}});- auto permute = wrap_type<ov::op::v1::Transpose>({one_hot, transpose_perm});+ auto one_hot =+ pattern::wrap_type<v1::OneHot>({topk->output(1), expert_num, one_hot_on, one_hot_off}, {{"axis", 2}});+ auto permute = pattern::wrap_type<v1::Transpose>({one_hot, transpose_perm});return {topk, permute};}@@ -232,15 +238,15 @@ std::pair<std::shared_ptr<Node>, std::shared_ptr<Node>> create_router_pattern()std::shared_ptr<Node> create_expert_indexing_pattern(const std::shared_ptr<Node>& permute_transpose,const AxisPatterns& axes) {auto select_gather =- wrap_type<ov::op::v8::Gather>({permute_transpose, axes.axis0, axes.axis0}, {{"batch_dims", 0}});- auto squeeze = wrap_type<ov::op::v0::Squeeze>({select_gather, axes.axis0});+ pattern::wrap_type<v8::Gather>({permute_transpose, axes.axis0, axes.axis0}, {{"batch_dims", 0}});+ auto squeeze = pattern::wrap_type<v0::Squeeze>({select_gather, axes.axis0});// NonZero output_type relaxed to accept both i32 and i64- auto non_zero = wrap_type<ov::op::v3::NonZero>({squeeze});- auto split = wrap_type<ov::op::v1::Split>({non_zero, axes.axis0}, {{"num_splits", 2}});+ auto non_zero = pattern::wrap_type<v3::NonZero>({squeeze});+ auto split = pattern::wrap_type<v1::Split>({non_zero, axes.axis0}, {{"num_splits", 2}});split->set_output_size(2);- auto squeeze_indices = wrap_type<ov::op::v0::Squeeze>({split->output(1), axes.axis0});+ auto squeeze_indices = pattern::wrap_type<v0::Squeeze>({split->output(1), axes.axis0});// Convert is optional - pattern matches both with and without type conversion- auto convert = wrap_type<ov::op::v0::Convert>({squeeze_indices}) | squeeze_indices;+ auto convert = pattern::wrap_type<v0::Convert>({squeeze_indices}) | squeeze_indices;return convert;}@@ -249,15 +255,15 @@ std::shared_ptr<Node> create_expert_indexing_pattern(const std::shared_ptr<Node>std::tuple<std::shared_ptr<Node>, std::shared_ptr<Node>> create_routing_weights_pattern(const std::shared_ptr<Node>& topk,const AxisPatterns& axes) {- auto reduce_neg1 = wrap_type<ov::op::v0::Constant>(pattern::value_matches("-1"));- auto sum_reduce = wrap_type<ov::op::v1::ReduceSum>({topk->output(0), reduce_neg1}, {{"keep_dims", true}});- auto normalized = wrap_type<ov::op::v1::Divide>({topk->output(0), sum_reduce},- {{"auto_broadcast", "numpy"}, {"m_pythondiv", true}});- auto unsqueeze = wrap_type<ov::op::v0::Unsqueeze>({normalized, axes.axis2});- auto shape_of = wrap_type<ov::op::v3::ShapeOf>({unsqueeze}, {{"output_type", "i32"}});- auto split = wrap_type<ov::op::v1::Split>({shape_of, axes.axis0}, {{"num_splits", 3}});+ auto reduce_neg1 = pattern::wrap_type<v0::Constant>(pattern::value_matches("-1"));+ auto sum_reduce = pattern::wrap_type<v1::ReduceSum>({topk->output(0), reduce_neg1}, {{"keep_dims", true}});+ auto normalized = pattern::wrap_type<v1::Divide>({topk->output(0), sum_reduce},+ {{"auto_broadcast", "numpy"}, {"m_pythondiv", true}});+ auto unsqueeze = pattern::wrap_type<v0::Unsqueeze>({normalized, axes.axis2});+ auto shape_of = pattern::wrap_type<v3::ShapeOf>({unsqueeze}, {{"output_type", "i32"}});+ auto split = pattern::wrap_type<v1::Split>({shape_of, axes.axis0}, {{"num_splits", 3}});split->set_output_size(3);- auto reshape = wrap_type<ov::op::v1::Reshape>({unsqueeze, pattern::any_input()}, {{"special_zero", true}});+ auto reshape = pattern::wrap_type<v1::Reshape>({unsqueeze, pattern::any_input()}, {{"special_zero", true}});return {split, reshape};}@@ -278,10 +284,10 @@ ov::pass::FuseMOEExperts::FuseMOEExperts() : MultiMatcher("FuseMOEExperts") {// Prepare additional patterns for expert computationauto view_Reshape = pattern::any_input();- auto slice_end = wrap_type<ov::op::v0::Constant>(); // Used in callback for slice validation+ auto slice_end = pattern::wrap_type<v0::Constant>(); // Used in callback for slice validation// Pattern for hidden states preparation- auto unsqueeze_Unsqueeze = wrap_type<ov::op::v0::Unsqueeze>({view_Reshape, axes.axis0});+ auto unsqueeze_Unsqueeze = pattern::wrap_type<v0::Unsqueeze>({view_Reshape, axes.axis0});// Create routing weights patternauto routing_result = create_routing_weights_pattern(topk_TopK, axes);@@ -294,11 +300,12 @@ ov::pass::FuseMOEExperts::FuseMOEExperts() : MultiMatcher("FuseMOEExperts") {// Match the final reshape and residual add after all expert computationsauto original_shape = pattern::any_input();- auto last_reshape = wrap_type<ov::op::v1::Reshape>({expert_scatter, original_shape}, {{"special_zero", false}});+ auto last_reshape = pattern::wrap_type<v1::Reshape>({expert_scatter, original_shape}, {{"special_zero", false}});auto residual_input = pattern::any_input();- auto last_add = wrap_type<ov::op::v1::Add>({residual_input, last_reshape}, {{"auto_broadcast", "numpy"}});+ auto last_add = pattern::wrap_type<v1::Add>({residual_input, last_reshape}, {{"auto_broadcast", "numpy"}});- auto callback = [=](const std::unordered_map<std::shared_ptr<Node>, std::vector<PatternValueMap>>& matches) {+ auto callback = [=](const std::unordered_map<std::shared_ptr<Node>, std::vector<pattern::PatternValueMap>>&+ matches) {auto num_last_add = matches.at(last_add).size();// Collect expert data from all matched patterns@@ -313,7 +320,7 @@ ov::pass::FuseMOEExperts::FuseMOEExperts() : MultiMatcher("FuseMOEExperts") {auto up_proj_node = expert_scatter->get_anchor("up_proj_weight", pm).value().get_node_shared_ptr();auto down_proj_node = expert_scatter->get_anchor("down_proj_weight", pm).value().get_node_shared_ptr();auto expert_id_node = expert_scatter->get_anchor("expert_id", pm).value().get_node_shared_ptr();- auto expert_id_const = ov::as_type_ptr<ov::op::v0::Constant>(expert_id_node);+ auto expert_id_const = ov::as_type_ptr<v0::Constant>(expert_id_node);auto permute_node = expert_scatter->get_anchor("permute_Transpose", pm).value().get_node_shared_ptr();auto expert_id_values = expert_id_const->cast_vector<int64_t>();all_experts.push_back({gate_proj_node,@@ -330,10 +337,10 @@ ov::pass::FuseMOEExperts::FuseMOEExperts() : MultiMatcher("FuseMOEExperts") {}// Create shared constants (used across all MoE layers)- auto const_0 = ov::op::v0::Constant::create(element::i64, Shape{1}, {0});- auto const_1 = ov::op::v0::Constant::create(element::i64, Shape{1}, {1});- auto const_minus_1 = ov::op::v0::Constant::create(element::i64, Shape{1}, {-1});- auto transpose_perm = ov::op::v0::Constant::create(element::i64, Shape{2}, {1, 0});+ auto const_0 = v0::Constant::create(element::i64, Shape{1}, {0});+ auto const_1 = v0::Constant::create(element::i64, Shape{1}, {1});+ auto const_minus_1 = v0::Constant::create(element::i64, Shape{1}, {-1});+ auto transpose_perm = v0::Constant::create(element::i64, Shape{2}, {1, 0});// Process each MoE layer separatelyfor (size_t moe_idx = 0; moe_idx < num_last_add; moe_idx++) {@@ -368,10 +375,10 @@ ov::pass::FuseMOEExperts::FuseMOEExperts() : MultiMatcher("FuseMOEExperts") {// Detect if weights have decompression pattern and extract original compressed weightsauto get_original_weight_and_decompress_info =[](const std::shared_ptr<Node>& weight) -> std::pair<std::shared_ptr<Node>, bool> {- if (auto convert_op = ov::as_type_ptr<ov::op::v0::Convert>(weight)) {+ if (auto convert_op = ov::as_type_ptr<v0::Convert>(weight)) {if (ov::is_decompression(convert_op)) {auto convert_input = convert_op->get_input_node_shared_ptr(0);- if (ov::as_type_ptr<ov::op::v0::Constant>(convert_input)) {+ if (ov::as_type_ptr<v0::Constant>(convert_input)) {return {convert_input, true};}}@@ -394,12 +401,12 @@ ov::pass::FuseMOEExperts::FuseMOEExperts() : MultiMatcher("FuseMOEExperts") {target_type = weight->get_output_element_type(0);}- inputs.emplace_back(ov::op::util::make_try_fold<ov::op::v0::Unsqueeze>(original_weight, const_0));+ inputs.emplace_back(op_util::make_try_fold<v0::Unsqueeze>(original_weight, const_0));}- auto fused = std::make_shared<ov::op::v0::Concat>(inputs, 0);+ auto fused = std::make_shared<v0::Concat>(inputs, 0);if (std::all_of(inputs.begin(), inputs.end(), [](const auto& input) {- return ov::op::util::is_constant(input.get_node());+ return op_util::is_constant(input.get_node());})) {// postponed_constant attribute is needed to perform constant folding on serialization stepfused->get_rt_info()["postponed_constant"] = true;@@ -407,7 +414,7 @@ ov::pass::FuseMOEExperts::FuseMOEExperts() : MultiMatcher("FuseMOEExperts") {ov::pass::disable_constant_folding(fused);}if (needs_decompress) {- auto convert = std::make_shared<ov::op::v0::Convert>(fused, target_type);+ auto convert = std::make_shared<v0::Convert>(fused, target_type);ov::mark_as_decompression(convert);return convert->output(0);}@@ -440,68 +447,62 @@ ov::pass::FuseMOEExperts::FuseMOEExperts() : MultiMatcher("FuseMOEExperts") {auto topk_indices_output = topk->output(1);auto batch_dim = extract_shape_dim(topk_indices_output, 0);- auto num_experts_const =- ov::op::v0::Constant::create(element::i64, Shape{}, {static_cast<int64_t>(num_experts)});- auto num_experts_dim = std::make_shared<ov::op::v0::Unsqueeze>(num_experts_const, const_0);+ auto num_experts_const = v0::Constant::create(element::i64, Shape{}, {static_cast<int64_t>(num_experts)});+ auto num_experts_dim = std::make_shared<v0::Unsqueeze>(num_experts_const, const_0);// Tile and reshape input to prepare for batched expert computation- auto tile_shape =- ov::op::v0::Constant::create(element::i64,- Shape{2},- {static_cast<int64_t>(num_experts), static_cast<int64_t>(1)});+ auto tile_shape = v0::Constant::create(element::i64,+ Shape{2},+ {static_cast<int64_t>(num_experts), static_cast<int64_t>(1)});- auto view_reshape_shape = std::make_shared<ov::op::v0::Concat>(OutputVector{const_minus_1, hidden_dim}, 0);- auto view_reshape = std::make_shared<ov::op::v1::Reshape>(view_reshape_node, view_reshape_shape, false);- auto repeated_input = std::make_shared<ov::op::v0::Tile>(view_reshape, tile_shape);+ auto view_reshape_shape = std::make_shared<v0::Concat>(OutputVector{const_minus_1, hidden_dim}, 0);+ auto view_reshape = std::make_shared<v1::Reshape>(view_reshape_node, view_reshape_shape, false);+ auto repeated_input = std::make_shared<v0::Tile>(view_reshape, tile_shape);- auto batched_shape =- std::make_shared<ov::op::v0::Concat>(OutputVector{num_experts_dim, batch_dim, hidden_dim}, 0);- auto batched_input = std::make_shared<ov::op::v1::Reshape>(repeated_input, batched_shape, false);+ auto batched_shape = std::make_shared<v0::Concat>(OutputVector{num_experts_dim, batch_dim, hidden_dim}, 0);+ auto batched_input = std::make_shared<v1::Reshape>(repeated_input, batched_shape, false);// Execute three-GEMM SwiGLU pattern: gate_proj, up_proj, and down_proj- auto gate_bmm = std::make_shared<ov::op::v0::MatMul>(batched_input, fused_gate_weights, false, true);- auto gate_swish = std::make_shared<ov::op::v4::Swish>(gate_bmm);+ auto gate_bmm = std::make_shared<v0::MatMul>(batched_input, fused_gate_weights, false, true);+ auto gate_swish = std::make_shared<v4::Swish>(gate_bmm);- auto up_bmm = std::make_shared<ov::op::v0::MatMul>(batched_input, fused_up_weights, false, true);- auto swiglu_mul = std::make_shared<ov::op::v1::Multiply>(gate_swish, up_bmm);+ auto up_bmm = std::make_shared<v0::MatMul>(batched_input, fused_up_weights, false, true);+ auto swiglu_mul = std::make_shared<v1::Multiply>(gate_swish, up_bmm);- auto down_bmm = std::make_shared<ov::op::v0::MatMul>(swiglu_mul, fused_down_weights, false, true);+ auto down_bmm = std::make_shared<v0::MatMul>(swiglu_mul, fused_down_weights, false, true);- auto minus_one_vec = ov::op::v0::Constant::create(element::i64, Shape{1}, {-1});- auto expert_output_shape = std::make_shared<ov::op::v0::Concat>(- OutputVector{num_experts_dim, batch_dim, minus_one_vec, hidden_dim},- 0);- auto expert_outputs = std::make_shared<ov::op::v1::Reshape>(down_bmm, expert_output_shape, false);+ auto minus_one_vec = v0::Constant::create(element::i64, Shape{1}, {-1});+ auto expert_output_shape =+ std::make_shared<v0::Concat>(OutputVector{num_experts_dim, batch_dim, minus_one_vec, hidden_dim}, 0);+ auto expert_outputs = std::make_shared<v1::Reshape>(down_bmm, expert_output_shape, false);// Build routing weights tensor from TopK outputsauto topk_values = topk->output(0);auto sum_reduce =- std::make_shared<ov::op::v1::ReduceSum>(topk_values,- ov::op::v0::Constant::create(element::i64, Shape{1}, {-1}),- true);- auto normalized_topk = std::make_shared<ov::op::v1::Divide>(topk_values, sum_reduce);-- auto scatter_shape = std::make_shared<ov::op::v0::Concat>(OutputVector{batch_dim, num_experts_dim}, 0);- auto zeros_scalar = ov::op::v0::Constant::create(normalized_topk->get_element_type(), Shape{}, {0});- auto zeros_tensor = std::make_shared<ov::op::v3::Broadcast>(zeros_scalar, scatter_shape);-- auto scatter = std::make_shared<ov::op::v12::ScatterElementsUpdate>(zeros_tensor,- topk_indices_output,- normalized_topk,- const_1);- auto router_transpose = std::make_shared<ov::op::v1::Transpose>(scatter, transpose_perm);+ std::make_shared<v1::ReduceSum>(topk_values, v0::Constant::create(element::i64, Shape{1}, {-1}), true);+ auto normalized_topk = std::make_shared<v1::Divide>(topk_values, sum_reduce);++ auto scatter_shape = std::make_shared<v0::Concat>(OutputVector{batch_dim, num_experts_dim}, 0);+ auto zeros_scalar = v0::Constant::create(normalized_topk->get_element_type(), Shape{}, {0});+ auto zeros_tensor = std::make_shared<v3::Broadcast>(zeros_scalar, scatter_shape);++ auto scatter = std::make_shared<v12::ScatterElementsUpdate>(zeros_tensor,+ topk_indices_output,+ normalized_topk,+ const_1);+ auto router_transpose = std::make_shared<v1::Transpose>(scatter, transpose_perm);auto router_shape =- std::make_shared<ov::op::v0::Concat>(OutputVector{num_experts_dim, batch_dim, minus_one_vec}, 0);- auto router_reshape = std::make_shared<ov::op::v1::Reshape>(router_transpose, router_shape, true);- auto routing_weights = std::make_shared<ov::op::v0::Unsqueeze>(router_reshape, const_minus_1);+ std::make_shared<v0::Concat>(OutputVector{num_experts_dim, batch_dim, minus_one_vec}, 0);+ auto router_reshape = std::make_shared<v1::Reshape>(router_transpose, router_shape, true);+ auto routing_weights = std::make_shared<v0::Unsqueeze>(router_reshape, const_minus_1);// Apply routing weights and reduce across expert dimension- auto weighted_outputs = std::make_shared<ov::op::v1::Multiply>(expert_outputs, routing_weights);- auto final_output = std::make_shared<ov::op::v1::ReduceSum>(weighted_outputs, const_0, false);+ auto weighted_outputs = std::make_shared<v1::Multiply>(expert_outputs, routing_weights);+ auto final_output = std::make_shared<v1::ReduceSum>(weighted_outputs, const_0, false);// Reshape back to original shape and add residual connection- auto final_reshape = std::make_shared<ov::op::v1::Reshape>(final_output, original_shape_node, false);- auto final_add = std::make_shared<ov::op::v1::Add>(residual_input_node, final_reshape);+ auto final_reshape = std::make_shared<v1::Reshape>(final_output, original_shape_node, false);+ auto final_add = std::make_shared<v1::Add>(residual_input_node, final_reshape);if (last_reshape_node && !last_reshape_node->get_friendly_name().empty()) {final_reshape->set_friendly_name(last_reshape_node->get_friendly_name());@@ -531,5 +532,4 @@ bool ov::pass::FuseMOE::run_on_model(const std::shared_ptr<ov::Model>& model) {return false;}-} // namespace pass-} // namespace ov+} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/fuse_rotary_positional_embeddings.cpp b/src/common/transformations/src/transformations/common_optimizations/fuse_rotary_positional_embeddings.cppindex dbecf11685d..308447526d0 100644--- a/src/common/transformations/src/transformations/common_optimizations/fuse_rotary_positional_embeddings.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/fuse_rotary_positional_embeddings.cpp@@ -47,12 +47,17 @@#include "transformations/symbolic_transformations/symbolic_optimizations.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::pass;-using namespace ov::op;+namespace ov::pass {-ov::pass::RoPEFusion::RoPEFusion(bool support_2d_rope) : m_support_2d_rope(support_2d_rope) {}+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;-bool ov::pass::RoPEFusion::run_on_model(const std::shared_ptr<ov::Model>& model) {+RoPEFusion::RoPEFusion(bool support_2d_rope) : m_support_2d_rope(support_2d_rope) {}++bool RoPEFusion::run_on_model(const std::shared_ptr<ov::Model>& model) {RUN_ON_MODEL_SCOPE(RoPEFusion);ov::pass::SymbolicOptimizations symbolic_optimizations(false, get_pass_config());@@ -85,10 +90,10 @@ static std::shared_ptr<ov::Node> gen_chatglm_const() {auto pred = value_matches("-1, head_cnt, 1, ndims/2, 1") || value_matches("1, -1, head_cnt, ndims/2, 1") ||value_matches("0, 0, 0, ndims/2, 1") || value_matches("-1, batch, head_cnt, ndims/2, 1");- return wrap_type<v0::Constant>(pred);+ return pattern::wrap_type<v0::Constant>(pred);}-ov::pass::RoPEFusionFlux::RoPEFusionFlux(bool num_heads_transposed) {+RoPEFusionFlux::RoPEFusionFlux(bool num_heads_transposed) {MATCHER_SCOPE(RoPEFusionFlux);// x[?,24,?,128 | [?,?,24,128]]// x1 = reshape(x, [?,24,?,64,2] | [?,?,24,64,2])@@ -124,7 +129,7 @@ ov::pass::RoPEFusionFlux::RoPEFusionFlux(bool num_heads_transposed) {auto result = pattern::wrap_type<opset1::Add>({y1, y2}, {{"auto_broadcast", "numpy"}});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();@@ -166,12 +171,11 @@ ov::pass::RoPEFusionFlux::RoPEFusionFlux(bool num_heads_transposed) {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(result, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(result, matcher_name);this->register_matcher(m, callback);}-ov::pass::RoPEFusionGPTNEOX::RoPEFusionGPTNEOX(int rank) {- using namespace ov::op::util;+RoPEFusionGPTNEOX::RoPEFusionGPTNEOX(int rank) {MATCHER_SCOPE(RoPEFusionGPTNEOX);// rope pattern matching triggers a little design flaw:@@ -193,9 +197,9 @@ ov::pass::RoPEFusionGPTNEOX::RoPEFusionGPTNEOX(int rank) {auto int32_max = std::numeric_limits<std::int32_t>::max();- auto x2 = NewGenSlice(x, "half_ndims", int32_max, 1, rank - 1);+ auto x2 = op_util::NewGenSlice(x, "half_ndims", int32_max, 1, rank - 1);auto x2neg = pattern::wrap_type<v1::Multiply>({x2 | varsplit->output(1), -1.0f}, {{"auto_broadcast", "numpy"}});- auto x1 = NewGenSlice(x, 0, "half_ndims", 1, rank - 1);+ auto x1 = op_util::NewGenSlice(x, 0, "half_ndims", 1, rank - 1);auto x_rotate_half = pattern::wrap_type<v0::Concat>({x2neg, x1 | varsplit->output(0)}, {{"axis", -1}});auto mul_cos = pattern::wrap_type<v1::Multiply>({x_or_cos1, x_or_cos2}, {{"auto_broadcast", "numpy"}});@@ -203,7 +207,7 @@ ov::pass::RoPEFusionGPTNEOX::RoPEFusionGPTNEOX(int rank) {auto result = pattern::wrap_type<v1::Add>({mul_cos, mul_sin}, {{"auto_broadcast", "numpy"}});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();@@ -238,7 +242,7 @@ ov::pass::RoPEFusionGPTNEOX::RoPEFusionGPTNEOX(int rank) {new_args.push_back(v_cos);new_args.push_back(pattern_map.at(t_sin));auto old_node = root;- auto new_node = std::make_shared<internal::RoPE>(new_args, config);+ auto new_node = std::make_shared<ov::op::internal::RoPE>(new_args, config);new_node->set_friendly_name(old_node->get_friendly_name());ov::copy_runtime_info({pattern_map.at(x2neg).get_node_shared_ptr(),pattern_map.at(x_rotate_half).get_node_shared_ptr(),@@ -253,12 +257,11 @@ ov::pass::RoPEFusionGPTNEOX::RoPEFusionGPTNEOX(int rank) {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(result, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(result, matcher_name);this->register_matcher(m, callback);}-ov::pass::RoPEFusionCosSinPreprocess::RoPEFusionCosSinPreprocess() {- using namespace ov::op::util;+RoPEFusionCosSinPreprocess::RoPEFusionCosSinPreprocess() {MATCHER_SCOPE(RoPEFusionCosSinPreprocess);auto cos_const = pattern::wrap_type<v0::Constant>(pattern::type_matches(element::f32));@@ -270,8 +273,8 @@ ov::pass::RoPEFusionCosSinPreprocess::RoPEFusionCosSinPreprocess() {auto prepare_cos_sin_gptneox = [&](std::shared_ptr<Node> const_tab) {auto slice = pattern::wrap_type<v8::Slice>({const_tab, {0}, node_batch_size, {1}, {0}});- auto strided_slice = NewGenStridedSlice(const_tab, {0}, node_batch_size, {1}, 0);- return pattern::wrap_type<v6::GatherElements>({strided_slice | slice, gather_positions}, {{"axis", 2}});+ auto strided_slice = op_util::NewGenStridedSlice(const_tab, {0}, node_batch_size, {1}, 0);+ return pattern::wrap_type<ov::op::v6::GatherElements>({strided_slice | slice, gather_positions}, {{"axis", 2}});};auto seq_len = pattern::any_input(pattern::type_matches(element::i32) && pattern::shape_matches("[1]"));@@ -280,14 +283,14 @@ ov::pass::RoPEFusionCosSinPreprocess::RoPEFusionCosSinPreprocess() {auto prepare_cos_sin_llama = [&](std::shared_ptr<Node> const_tab) {auto ScatterUpdate = pattern::wrap_type<v3::ScatterUpdate>({{0, 0, 0}, 2, seq_len, 0});auto slice_Slice = pattern::wrap_type<v8::Slice>({const_tab, {0}, seq_len, {1}, {2}});- auto slice_StridedSlice = NewGenStridedSlice(const_tab, {0, 0, 0}, ScatterUpdate, {1, 1, 1}, 2);+ auto slice_StridedSlice = op_util::NewGenStridedSlice(const_tab, {0, 0, 0}, ScatterUpdate, {1, 1, 1}, 2);auto squeeze = pattern::wrap_type<v1::Reshape>({slice_StridedSlice | slice_Slice, pattern::any_input()},pattern::shape_matches("[?, head_dims]"));auto index_Gather = pattern::wrap_type<v8::Gather>({squeeze, gather_positions_2d, 0}, {{"batch_dims", 0}});// another simplified pattern for gathering at position_idsauto slice_Slice2 = pattern::wrap_type<v8::Slice>({const_tab, {0}, seq_len, {1}, {0}});- auto slice_StridedSlice2 = NewGenStridedSlice(const_tab, {0}, seq_len, {1}, 0);+ auto slice_StridedSlice2 = op_util::NewGenStridedSlice(const_tab, {0}, seq_len, {1}, 0);auto index_Gather2 =pattern::wrap_type<v8::Gather>({slice_Slice2 | slice_StridedSlice2, gather_positions_2d, 0},{{"batch_dims", 0}});@@ -305,7 +308,7 @@ ov::pass::RoPEFusionCosSinPreprocess::RoPEFusionCosSinPreprocess() {auto x = pattern::any_input(pattern::rank_equals(4));auto rope = pattern::wrap_type<ov::op::internal::RoPE>({x, cos_tab, sin_tab});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();auto rope_node = as_type_ptr<ov::op::internal::RoPE>(pattern_map.at(rope).get_node_shared_ptr());@@ -334,28 +337,27 @@ ov::pass::RoPEFusionCosSinPreprocess::RoPEFusionCosSinPreprocess() {register_new_node(rope_node);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(rope, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(rope, matcher_name);this->register_matcher(m, callback);}// only a fraction of head_size is rotary-embedded-ov::pass::RoPEFusionIOSlicing::RoPEFusionIOSlicing() {- using namespace ov::op::util;+RoPEFusionIOSlicing::RoPEFusionIOSlicing() {MATCHER_SCOPE(RoPEFusionIOSlicing);auto int32_max = std::numeric_limits<std::int32_t>::max();auto data = pattern::any_input(pattern::rank_equals(4));- auto varsplit = pattern::wrap_type<ov::op::v1::VariadicSplit>({data, 3, {"ndims", "?"}});+ auto varsplit = pattern::wrap_type<v1::VariadicSplit>({data, 3, {"ndims", "?"}});varsplit->set_output_size(2);- auto x = NewGenSlice(data, 0, "ndims", 1, 3);- auto y = NewGenSlice(data, "ndims", int32_max, 1, 3);+ auto x = op_util::NewGenSlice(data, 0, "ndims", 1, 3);+ auto y = op_util::NewGenSlice(data, "ndims", int32_max, 1, 3);auto x_emb = pattern::wrap_type<ov::op::internal::RoPE>({x | varsplit->output(0), pattern::any_input(), pattern::any_input()}) |pattern::wrap_type<ov::op::internal::RoPE>({x | varsplit->output(0), pattern::any_input(), pattern::any_input(), pattern::any_input()});- auto result = pattern::wrap_type<ov::op::v0::Concat>({x_emb, y | varsplit->output(1)}, {{"axis", -1}});+ auto result = pattern::wrap_type<v0::Concat>({x_emb, y | varsplit->output(1)}, {{"axis", -1}});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();@@ -382,13 +384,12 @@ ov::pass::RoPEFusionIOSlicing::RoPEFusionIOSlicing() {register_new_node(rope_node);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(result, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(result, matcher_name);this->register_matcher(m, callback);}// gptneox-preprocess of input data-ov::pass::RoPEFusionPreprocess::RoPEFusionPreprocess() {- using namespace ov::op::util;+RoPEFusionPreprocess::RoPEFusionPreprocess() {MATCHER_SCOPE(RoPEFusionPreprocess);// Pattern for input to be sliced (for models with combined QKV projection)@@ -397,10 +398,10 @@ ov::pass::RoPEFusionPreprocess::RoPEFusionPreprocess() {auto input_to_trans = pattern::any_input(pattern::rank_equals(4));// Slice input if needed: [B, L, H, S] -> [B, L', H, S]- auto input_slice = NewGenSlice(input_to_slice, {"slice_start"}, {"slice_stop"}, 1, 3);+ auto input_slice = op_util::NewGenSlice(input_to_slice, {"slice_start"}, {"slice_stop"}, 1, 3);// Transpose input if needed: [B, L, H, S] -> [B, H, L, S]- auto x = pattern::wrap_type<ov::op::v1::Transpose>({input_slice | input_to_trans, {0, 2, 1, 3}});+ auto x = pattern::wrap_type<v1::Transpose>({input_slice | input_to_trans, {0, 2, 1, 3}});// RoPE node: supports both 3 and 4 inputsauto result = pattern::wrap_type<ov::op::internal::RoPE>({x, pattern::any_input(), pattern::any_input()}) |@@ -460,8 +461,7 @@ static std::shared_ptr<ov::Node> repeat_interleave_pattern(const ov::Output<ov::return pattern::wrap_type<ov::opset8::Gather>({unsqueeze, const_idx, 3}, {{"batch_dims", 0}});}-ov::pass::RoPEFusionGPTJ::RoPEFusionGPTJ() {- using namespace ov::op::util;+RoPEFusionGPTJ::RoPEFusionGPTJ() {MATCHER_SCOPE(RoPEFusionGPTJ);auto gather_sin_cos = pattern::any_input(pattern::type_matches(ov::element::f32));@@ -471,12 +471,12 @@ ov::pass::RoPEFusionGPTJ::RoPEFusionGPTJ() {auto repeat_interleave_cos = repeat_interleave_pattern(varsplit->output(1));auto view_Reshape = pattern::any_input(pattern::rank_equals(4));- auto slice_Slice_965 = NewGenSlice(view_Reshape, 0, "ndims", 1, 3);+ auto slice_Slice_965 = op_util::NewGenSlice(view_Reshape, 0, "ndims", 1, 3);// view_Reshape : B,L,H,Sauto varsplit_view_Reshape = pattern::wrap_type<opset1::VariadicSplit>({view_Reshape, 3, {"ndims", "end"}});varsplit_view_Reshape->set_output_size(2);// x interleave (-x[:,:,:, 1::2], x[:,:,:, 0::2])- auto slice_Slice_1174 = NewGenSlice(slice_Slice_965 | varsplit_view_Reshape->output(0), 1, INT_MAX, 2, 3);+ auto slice_Slice_1174 = op_util::NewGenSlice(slice_Slice_965 | varsplit_view_Reshape->output(0), 1, INT_MAX, 2, 3);auto neg_Multiply_1177 =pattern::wrap_type<opset1::Multiply>({slice_Slice_1174, -1.0f}, {{"auto_broadcast", "numpy"}});@@ -484,7 +484,7 @@ ov::pass::RoPEFusionGPTJ::RoPEFusionGPTJ() {auto Unsqueeze_28998 = pattern::wrap_type<opset1::Reshape>({neg_Multiply_1177, {"-1", "1", "head_num", "32", "1"}},{{"special_zero", false}});- auto slice_Slice_1168 = NewGenSlice(slice_Slice_965 | varsplit_view_Reshape->output(0), 0, INT_MAX, 2, 3);+ auto slice_Slice_1168 = op_util::NewGenSlice(slice_Slice_965 | varsplit_view_Reshape->output(0), 0, INT_MAX, 2, 3);auto Unsqueeze_65525 = pattern::wrap_type<opset1::Unsqueeze>({slice_Slice_1168, -1});auto Unsqueeze_28999 = pattern::wrap_type<opset1::Reshape>({slice_Slice_1168, {"-1", "1", "head_num", "32", "1"}},{{"special_zero", false}});@@ -493,12 +493,12 @@ ov::pass::RoPEFusionGPTJ::RoPEFusionGPTJ() {{{"axis", -1}});auto ShapeOf_169068 = pattern::wrap_type<opset1::ShapeOf>({stack_1182});- auto flatten_Slice_1194 = NewGenSlice(ShapeOf_169068, 0, 3, 1, 0);+ auto flatten_Slice_1194 = op_util::NewGenSlice(ShapeOf_169068, 0, 3, 1, 0);auto flatten_Concat_1197 = pattern::wrap_type<opset1::Concat>({flatten_Slice_1194, {-1}}, {{"axis", 0}});// If with special zero, no need to use shapeof to get full shapeauto flatten_Reshape_1198 = pattern::wrap_type<opset1::Reshape>({stack_1182, flatten_Concat_1197});auto flatten_Reshape_Zero =- pattern::wrap_type<opset1::Reshape>({stack_1182, ov::pass::pattern::any_input()}, {{"special_zero", true}});+ pattern::wrap_type<opset1::Reshape>({stack_1182, pattern::any_input()}, {{"special_zero", true}});// x*cos [B,L,H,ndims]auto mul_cos = pattern::wrap_type<opset1::Multiply>(@@ -511,11 +511,11 @@ ov::pass::RoPEFusionGPTJ::RoPEFusionGPTJ() {// *cos + *sinauto rotary_emb = pattern::wrap_type<opset1::Add>({mul_cos, mul_sin}, {{"auto_broadcast", "numpy"}});- auto slice_Slice_971 = NewGenSlice(view_Reshape, "ndims", INT_MAX, 1, 3);+ auto slice_Slice_971 = op_util::NewGenSlice(view_Reshape, "ndims", INT_MAX, 1, 3);auto result = pattern::wrap_type<opset1::Concat>({rotary_emb, slice_Slice_971 | varsplit_view_Reshape->output(1)},{{"axis", -1}});- matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();auto symbols = m.get_symbols();@@ -543,9 +543,9 @@ ov::pass::RoPEFusionGPTJ::RoPEFusionGPTJ() {auto root_target_inputs = root->output(0).get_target_inputs();if (root_target_inputs.size() == 1) {auto target_node = root_target_inputs.begin()->get_node()->shared_from_this();- if (auto transpose = ov::as_type_ptr<ov::op::v1::Transpose>(target_node)) {+ if (auto transpose = ov::as_type_ptr<v1::Transpose>(target_node)) {auto axes = transpose->input_value(1).get_node_shared_ptr();- auto axes_const = ov::as_type_ptr<ov::op::v0::Constant>(axes);+ auto axes_const = ov::as_type_ptr<v0::Constant>(axes);if (axes_const && axes_const->cast_vector<int64_t>() == std::vector<int64_t>{0, 2, 1, 3}) {config.output_trans0213 = true;rt_from.push_back(target_node);@@ -577,12 +577,11 @@ ov::pass::RoPEFusionGPTJ::RoPEFusionGPTJ() {}return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(result, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(result, matcher_name);this->register_matcher(m, callback);}-ov::pass::RoPEFusionChatGLM::RoPEFusionChatGLM(const bool support_2d_rope) {- using namespace ov::op::util;+RoPEFusionChatGLM::RoPEFusionChatGLM(const bool support_2d_rope) {MATCHER_SCOPE(RoPEFusionChatGLM);// [seq_length, batch_size, input_size(will be cropped to match hidden state size)]@@ -615,7 +614,7 @@ ov::pass::RoPEFusionChatGLM::RoPEFusionChatGLM(const bool support_2d_rope) {input_key = std::move(cur_key);}- auto slice0 = NewGenSlice(input_key, 0, "ndims", 1, 3);+ auto slice0 = op_util::NewGenSlice(input_key, 0, "ndims", 1, 3);auto var_split0 = pattern::wrap_type<v1::VariadicSplit>({input_key, 3, {"ndims", "end"}});var_split0->set_output_size(2);@@ -650,7 +649,7 @@ ov::pass::RoPEFusionChatGLM::RoPEFusionChatGLM(const bool support_2d_rope) {auto slice1 = pattern::wrap_type<v8::Slice>({cos_sin_cache, {0}, seq_length, {1}, {1}});auto slice2 = pattern::wrap_type<v8::Slice>({cos_sin_cache, {0, 0}, scatter_update0, {1, 1}, {0}});auto ss_stop = pattern::wrap_type<v0::Constant>();- auto strided_slice0 = NewGenStridedSlice(cos_sin_cache, {0, 0}, ss_stop | scatter_update0, {1, 1}, 1);+ auto strided_slice0 = op_util::NewGenStridedSlice(cos_sin_cache, {0, 0}, ss_stop | scatter_update0, {1, 1}, 1);auto concat1 = pattern::wrap_type<v0::Concat>({{-1}, {1}, seq_length, {"ndims/2"}, {2}}, {{"axis", 0}});auto const_target_shape3 =@@ -666,7 +665,7 @@ ov::pass::RoPEFusionChatGLM::RoPEFusionChatGLM(const bool support_2d_rope) {pattern::wrap_type<v0::Constant>(pattern::value_matches("seq_len, batch, 1, ndims/2, 2"));auto slice3 = pattern::wrap_type<v8::Slice>({cos_sin_cache, {0}, seq_length, {1}, {0}});- auto strided_slice1 = NewGenStridedSlice(cos_sin_cache, {0}, seq_length, {1}, 0);+ auto strided_slice1 = op_util::NewGenStridedSlice(cos_sin_cache, {0}, seq_length, {1}, 0);// [seq_length, 1, batch, half_rotary_dims, 2]reshape1 = pattern::wrap_type<v1::Reshape>(@@ -690,8 +689,8 @@ ov::pass::RoPEFusionChatGLM::RoPEFusionChatGLM(const bool support_2d_rope) {auto concat2 = pattern::wrap_type<v0::Concat>({y_even, y_odd}, {{"axis", -1}});- auto shape_of0 = pattern::wrap_type<ov::op::util::ShapeOfBase>({concat2});- auto slice4 = NewGenSlice(shape_of0, 0, 3, 1, 0);+ auto shape_of0 = pattern::wrap_type<op_util::ShapeOfBase>({concat2});+ auto slice4 = op_util::NewGenSlice(shape_of0, 0, 3, 1, 0);auto concat3 = pattern::wrap_type<v0::Concat>({slice4, {-1}}, {{"axis", 0}});std::shared_ptr<ov::Node> const_target_shape6 = nullptr;@@ -710,12 +709,12 @@ ov::pass::RoPEFusionChatGLM::RoPEFusionChatGLM(const bool support_2d_rope) {reshape2 = pattern::wrap_type<v1::Reshape>({concat2, concat3 | const_target_shape6 | const_target_shape7},{{"special_zero", true}});}- auto slice5 = NewGenSlice(input_key, "ndims", INT_MAX, 1, 3);+ auto slice5 = op_util::NewGenSlice(input_key, "ndims", INT_MAX, 1, 3);auto concat4 = pattern::wrap_type<v0::Concat>({reshape2, slice5 | var_split0->output(1)}, {{"axis", -1}});auto result = concat4 | reshape2;- matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();auto symbols = m.get_symbols();@@ -773,16 +772,16 @@ ov::pass::RoPEFusionChatGLM::RoPEFusionChatGLM(const bool support_2d_rope) {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(result, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(result, matcher_name);this->register_matcher(m, callback);}static std::shared_ptr<ov::Node> build_ChatGLMHF_interleave_pattern(std::shared_ptr<ov::Node> cos_or_sin) {- auto transpose = pattern::wrap_type<ov::op::v1::Transpose>({cos_or_sin, pattern::any_input()});- auto reshape = pattern::wrap_type<ov::op::v1::Reshape>({transpose, pattern::any_input()});- auto multiply = pattern::wrap_type<ov::op::v1::Multiply>({reshape, pattern::any_input()});- auto gather_nd = pattern::wrap_type<ov::op::v8::GatherND>({multiply, pattern::any_input()});- auto transpose_1 = pattern::wrap_type<ov::op::v1::Transpose>({gather_nd, pattern::any_input()});+ auto transpose = pattern::wrap_type<v1::Transpose>({cos_or_sin, pattern::any_input()});+ auto reshape = pattern::wrap_type<v1::Reshape>({transpose, pattern::any_input()});+ auto multiply = pattern::wrap_type<v1::Multiply>({reshape, pattern::any_input()});+ auto gather_nd = pattern::wrap_type<v8::GatherND>({multiply, pattern::any_input()});+ auto transpose_1 = pattern::wrap_type<v1::Transpose>({gather_nd, pattern::any_input()});auto const_idx =pattern::wrap_type<ov::opset1::Constant>(pattern::type_matches(ov::element::i32) && const_idx_predicate);@@ -790,8 +789,7 @@ static std::shared_ptr<ov::Node> build_ChatGLMHF_interleave_pattern(std::shared_return transpose_1 | gather;}-ov::pass::RoPEFusionChatGLMHF::RoPEFusionChatGLMHF() {- using namespace ov::op::util;+RoPEFusionChatGLMHF::RoPEFusionChatGLMHF() {MATCHER_SCOPE(RoPEFusionChatGLMHF);auto qk_linear = pattern::any_input(pattern::shape_matches("[?, 1, ?]"));@@ -808,18 +806,18 @@ ov::pass::RoPEFusionChatGLMHF::RoPEFusionChatGLMHF() {auto vsplit_out1 = pattern::wrap_type<op::v1::VariadicSplit>({reshape, 3, pattern::any_input()},pattern::output_index_matches(1) && pattern::shape_matches("[?, head_cnt, 1, ndims]"));- auto slice_1 = NewGenSlice(reshape, 0, "ndims", 1, 3) | vsplit_out0;+ auto slice_1 = op_util::NewGenSlice(reshape, 0, "ndims", 1, 3) | vsplit_out0;auto repeat_interleave_cos = build_ChatGLMHF_interleave_pattern(cos);auto repeat_interleave_sin = build_ChatGLMHF_interleave_pattern(sin);auto multiply = pattern::wrap_type<v1::Multiply>({slice_1, repeat_interleave_cos}, {{"auto_broadcast", "numpy"}});- auto slice_2 = NewGenSlice(slice_1, 1, INT_MAX, 2, 3);+ auto slice_2 = op_util::NewGenSlice(slice_1, 1, INT_MAX, 2, 3);auto neg = pattern::wrap_type<v1::Multiply>({slice_2, -1}, {{"auto_broadcast", "numpy"}});auto unsqueeze_1 = pattern::wrap_type<v1::Reshape>({neg, pattern::any_input()},pattern::shape_matches("[?, head_cnt, 1, ndims/2, 1]"),{{"special_zero", false}});- auto slice_3 = NewGenSlice(slice_1, 0, INT_MAX, 2, 3);+ auto slice_3 = op_util::NewGenSlice(slice_1, 0, INT_MAX, 2, 3);auto unsqueeze_2 = pattern::wrap_type<v1::Reshape>({slice_3, pattern::any_input()},pattern::shape_matches("[?, head_cnt, 1, ndims/2, 1]"),{{"special_zero", false}});@@ -830,10 +828,10 @@ ov::pass::RoPEFusionChatGLMHF::RoPEFusionChatGLMHF() {auto multiply_1 = pattern::wrap_type<v1::Multiply>({flatten, repeat_interleave_sin}, {{"auto_broadcast", "numpy"}});auto add = pattern::wrap_type<v1::Add>({multiply, multiply_1}, {{"auto_broadcast", "numpy"}});- auto slice_5 = NewGenSlice(reshape, "ndims", INT_MAX, 1, 3) | vsplit_out1;+ auto slice_5 = op_util::NewGenSlice(reshape, "ndims", INT_MAX, 1, 3) | vsplit_out1;auto result = pattern::wrap_type<v0::Concat>({add, slice_5}, {{"axis", -1}});- matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();@@ -860,19 +858,18 @@ ov::pass::RoPEFusionChatGLMHF::RoPEFusionChatGLMHF() {new_args.push_back(pattern_map.at(sin));auto old_node = root;- auto new_node = std::make_shared<internal::RoPE>(new_args, config);+ auto new_node = std::make_shared<ov::op::internal::RoPE>(new_args, config);new_node->set_friendly_name(old_node->get_friendly_name());ov::copy_runtime_info({root->get_input_node_shared_ptr(0), root}, new_node);ov::replace_node(old_node, new_node);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(result, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(result, matcher_name);this->register_matcher(m, callback);}-ov::pass::RoPEFusionQwen::RoPEFusionQwen() {- using namespace ov::op::util;+RoPEFusionQwen::RoPEFusionQwen() {MATCHER_SCOPE(RoPEFusionQwen);// rotary_emb_cos & rotary_emb_sin are sliced by present kv-length (past-kv-length + cur_len)@@ -888,13 +885,13 @@ ov::pass::RoPEFusionQwen::RoPEFusionQwen() {auto view_Reshape_424 = pattern::wrap_type<v1::Reshape>({ListUnpack_410_VariadicSplit, pattern::any_input()},pattern::shape_matches("[?, ?, head_cnt, head_size]"),{{"special_zero", true}});- auto slice_Slice_543 = NewGenSlice(view_Reshape_424, 0, "head_size", 1, 3);+ auto slice_Slice_543 = op_util::NewGenSlice(view_Reshape_424, 0, "head_size", 1, 3);- auto ShapeOf_485735 = pattern::wrap_type<ov::op::util::ShapeOfBase>({pattern::any_input()}, {});+ auto ShapeOf_485735 = pattern::wrap_type<op_util::ShapeOfBase>({pattern::any_input()}, {});auto Multiply_567524 = pattern::wrap_type<v1::Multiply>({ShapeOf_485735, -1}, {{"auto_broadcast", "numpy"}});auto Gather_377635 = pattern::wrap_type<v8::Gather>({Multiply_567524, 1, 0}, {{"batch_dims", 0}});- auto ShapeOf_409241 = pattern::wrap_type<ov::op::util::ShapeOfBase>({pattern::any_input()}, {});+ auto ShapeOf_409241 = pattern::wrap_type<op_util::ShapeOfBase>({pattern::any_input()}, {});auto Gather_311651 = pattern::wrap_type<v8::Gather>({ShapeOf_409241, 1, 0}, {{"batch_dims", 0}});auto neg_Multiply = pattern::wrap_type<v1::Multiply>({Gather_311651, -1}, {{"auto_broadcast", "numpy"}});@@ -906,7 +903,8 @@ ov::pass::RoPEFusionQwen::RoPEFusionQwen() {pattern::shape_matches("[?, 1, 1, 128]"),{{"special_zero", false}});- auto slice_StridedSlice_446 = NewGenStridedSlice(rotary_emb_cos, ScatterUpdate_463814, {0, INT_MAX}, {1, 1}, 1);+ auto slice_StridedSlice_446 =+ op_util::NewGenStridedSlice(rotary_emb_cos, ScatterUpdate_463814, {0, INT_MAX}, {1, 1}, 1);auto mul_Multiply_552 = pattern::wrap_type<v1::Multiply>({slice_Slice_543, slice_StridedSlice_446 | slice_Slice_446 | reshape_cos_to_expected_layout},{{"auto_broadcast", "numpy"}});@@ -953,7 +951,8 @@ ov::pass::RoPEFusionQwen::RoPEFusionQwen() {auto cat_Concat_593 = pattern::wrap_type<v0::Concat>({ListUnpack_586_Squeeze_0 | ListUnpack_Squeeze_0_1, ListUnpack_586_Squeeze | ListUnpack_Squeeze_1},{{"axis", -1}});- auto slice_StridedSlice_470 = NewGenStridedSlice(rotary_emb_sin, ScatterUpdate_463814, {0, INT_MAX}, {1, 1}, 1);+ auto slice_StridedSlice_470 =+ op_util::NewGenStridedSlice(rotary_emb_sin, ScatterUpdate_463814, {0, INT_MAX}, {1, 1}, 1);auto slice_Slice_470 = pattern::wrap_type<v8::Slice>({rotary_emb_sin, Gather_377635 | neg_Multiply, INT_MAX, 1, 1});auto gather_sin_by_pos_ids = pattern::wrap_type<v8::Gather>({rotary_emb_sin, position_ids, 1}, {{"batch_dims", 0}});auto reshape_sin_to_expected_layout = pattern::wrap_type<v1::Reshape>({gather_sin_by_pos_ids, pattern::any_input()},@@ -964,7 +963,7 @@ ov::pass::RoPEFusionQwen::RoPEFusionQwen() {{{"auto_broadcast", "numpy"}});auto result = pattern::wrap_type<v1::Add>({mul_Multiply_552, mul_Multiply_594}, {{"auto_broadcast", "numpy"}});- matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();@@ -1020,13 +1019,13 @@ ov::pass::RoPEFusionQwen::RoPEFusionQwen() {rt_from.push_back(pattern_map.at(ListUnpack_586_Squeeze).get_node_shared_ptr());}auto old_node = root;- auto new_node = std::make_shared<internal::RoPE>(new_args, config);+ auto new_node = std::make_shared<ov::op::internal::RoPE>(new_args, config);new_node->set_friendly_name(old_node->get_friendly_name());ov::copy_runtime_info(rt_from, new_node);ov::replace_node(old_node, new_node);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(result, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(result, matcher_name);this->register_matcher(m, callback);}@@ -1035,40 +1034,39 @@ ov::pass::RoPEFusionQwen::RoPEFusionQwen() {here we try to share the preparation subgraphs results of these tables across layers.This is not a generic solution due to difficulty of the algorithm*/-ov::pass::RoPEShareCosSin::RoPEShareCosSin() {+RoPEShareCosSin::RoPEShareCosSin() {MATCHER_SCOPE(RoPEShareCosSin);std::vector<std::shared_ptr<Node>> inputs = {pattern::any_input(), pattern::any_input()};// Broadcast patternauto const_broadcast_axes =- pattern::wrap_type<ov::op::v0::Constant>(pattern::type_matches(element::u8) && pattern::value_matches("{0}"));- auto broadcast = pattern::wrap_type<ov::op::v1::Broadcast>({"{1.000000f}", inputs[0], const_broadcast_axes},- {{"mode", "numpy"}});+ pattern::wrap_type<v0::Constant>(pattern::type_matches(element::u8) && pattern::value_matches("{0}"));+ auto broadcast =+ pattern::wrap_type<v1::Broadcast>({"{1.000000f}", inputs[0], const_broadcast_axes}, {{"mode", "numpy"}});// Multiply pattern (expand broadcast)- auto const_inv_freq = pattern::wrap_type<ov::op::v0::Constant>(); // Pattern for the constant inverse frequency- auto multiply =- pattern::wrap_type<ov::op::v1::Multiply>({const_inv_freq, broadcast}, {{"auto_broadcast", "numpy"}});+ auto const_inv_freq = pattern::wrap_type<v0::Constant>(); // Pattern for the constant inverse frequency+ auto multiply = pattern::wrap_type<v1::Multiply>({const_inv_freq, broadcast}, {{"auto_broadcast", "numpy"}});// MatMul patternauto matmul =- pattern::wrap_type<ov::op::v0::MatMul>({multiply, inputs[1]}, {{"transpose_a", false}, {"transpose_b", false}});+ pattern::wrap_type<v0::MatMul>({multiply, inputs[1]}, {{"transpose_a", false}, {"transpose_b", false}});// Transpose pattern- auto transpose = pattern::wrap_type<ov::op::v1::Transpose>({matmul, {0, 2, 1}});+ auto transpose = pattern::wrap_type<v1::Transpose>({matmul, {0, 2, 1}});// Concat pattern- auto concat = pattern::wrap_type<ov::op::v0::Concat>({transpose, transpose}, {{"axis", -1}});+ auto concat = pattern::wrap_type<v0::Concat>({transpose, transpose}, {{"axis", -1}});// Cosine and Sine patterns- auto cos = pattern::wrap_type<ov::op::v0::Cos>({concat});- auto sin = pattern::wrap_type<ov::op::v0::Sin>({concat});+ auto cos = pattern::wrap_type<v0::Cos>({concat});+ auto sin = pattern::wrap_type<v0::Sin>({concat});// Unsqueeze result pattern (cos or sin)- auto result = pattern::wrap_type<ov::op::v0::Unsqueeze>({cos | sin, {1}});+ auto result = pattern::wrap_type<v0::Unsqueeze>({cos | sin, {1}});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();@@ -1077,7 +1075,7 @@ ov::pass::RoPEShareCosSin::RoPEShareCosSin() {if (it == pattern_map.end()) {return false;}- auto cur_inv_freq = as_type_ptr<ov::op::v0::Constant>(it->second.get_node_shared_ptr());+ auto cur_inv_freq = as_type_ptr<v0::Constant>(it->second.get_node_shared_ptr());if (!cur_inv_freq) {return false;}@@ -1098,7 +1096,7 @@ ov::pass::RoPEShareCosSin::RoPEShareCosSin() {return false;if (cur_inv_freq->get_shape() != m_inv_freq->get_shape())return false;- auto global_inv_freq = ov::as_type_ptr<ov::op::v0::Constant>(m_inv_freq);+ auto global_inv_freq = ov::as_type_ptr<v0::Constant>(m_inv_freq);auto cmp_error =memcmp(cur_inv_freq->get_data_ptr(), global_inv_freq->get_data_ptr(), global_inv_freq->get_byte_size());@@ -1136,8 +1134,7 @@ ov::pass::RoPEShareCosSin::RoPEShareCosSin() {this->register_matcher(m, callback);}-ov::pass::RoPEFusionGPTOSS::RoPEFusionGPTOSS() {- using namespace ov::op::util;+RoPEFusionGPTOSS::RoPEFusionGPTOSS() {MATCHER_SCOPE(RoPEFusionGPTOSS);// gpt-oss style@@ -1168,7 +1165,7 @@ ov::pass::RoPEFusionGPTOSS::RoPEFusionGPTOSS() {auto result = concat_result;- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto root = m.get_match_root();const auto& x_val = pattern_map.at(x);@@ -1188,7 +1185,7 @@ ov::pass::RoPEFusionGPTOSS::RoPEFusionGPTOSS() {new_args.push_back(x_val);new_args.push_back(v_cos);new_args.push_back(pattern_map.at(t_sin));- auto new_node = std::make_shared<internal::RoPE>(new_args, config);+ auto new_node = std::make_shared<ov::op::internal::RoPE>(new_args, config);new_node->set_friendly_name(root->get_friendly_name());ov::copy_runtime_info({pattern_map.at(neg).get_node_shared_ptr(),pattern_map.at(sub_Subtract).get_node_shared_ptr(),@@ -1204,6 +1201,8 @@ ov::pass::RoPEFusionGPTOSS::RoPEFusionGPTOSS() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(result, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(result, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/gelu_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/gelu_fusion.cppindex b0966e58fa9..4be49a0cb54 100644--- a/src/common/transformations/src/transformations/common_optimizations/gelu_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/gelu_fusion.cpp@@ -28,24 +28,29 @@#include "transformations/utils/utils.hpp"using namespace ov;-using namespace ov::op::util;-using namespace ov::pass::pattern::op;+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;+using ov::pass::pattern::op::Or;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;constexpr auto SQRT2 = static_cast<float>(M_SQRT2);constexpr auto SQRT1_2 = static_cast<float>(M_SQRT1_2);constexpr auto SQRT_2_PI = 0.79788456080286535588f; // std::sqrt(M_2_PI)namespace {-Predicate check_value(float ref, float eps = std::numeric_limits<float>::epsilon()) {- return Predicate(+ov::pass::pattern::op::Predicate check_value(float ref, float eps = std::numeric_limits<float>::epsilon()) {+ return ov::pass::pattern::op::Predicate([=](const Output<Node>& output) -> bool {return ov::op::util::has_constant_value<float>(output.get_node_shared_ptr(), ref, eps);},"has_constant_value(" + std::to_string(ref) + ")");}-bool gelu_replacer(ov::pass::pattern::Matcher& m,+bool gelu_replacer(Matcher& m,const std::shared_ptr<ov::Node>& pattern_input_to_gelu,ov::op::GeluApproximationMode mode = ov::op::GeluApproximationMode::ERF) {ov::pass::NodeRegistry rg;@@ -66,30 +71,30 @@ ov::pass::GeluFusionWithErfOne::GeluFusionWithErfOne() {MATCHER_SCOPE(GeluFusionWithErfOne);// Replaces a sub-graph with a Gelu op// Shared by every pattern: (1 + erf(x / sqrt(2)))- auto input = pass::pattern::any_input();- auto div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(SQRT2, 0.001f));- auto div = ov::pass::pattern::wrap_type<ov::op::v1::Divide>({input, div_constant});+ auto input = any_input();+ auto div_constant = wrap_type<v0::Constant>(check_value(SQRT2, 0.001f));+ auto div = wrap_type<v1::Divide>({input, div_constant});// In case of ConvertDivideWithConstant is applied and Div is converted to Mul- auto mul_as_div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(SQRT1_2, 0.001f));- auto mul_as_div = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_as_div_constant});+ auto mul_as_div_constant = wrap_type<v0::Constant>(check_value(SQRT1_2, 0.001f));+ auto mul_as_div = wrap_type<v1::Multiply>({input, mul_as_div_constant});auto erf_input = std::make_shared<Or>(ov::OutputVector{div, mul_as_div});- auto erf = ov::pass::pattern::wrap_type<ov::op::v0::Erf>({erf_input});+ auto erf = wrap_type<v0::Erf>({erf_input});- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(1.0f));- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({add_constant, erf});- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(0.5f));+ auto add_constant = wrap_type<v0::Constant>(check_value(1.0f));+ auto add = wrap_type<v1::Add>({add_constant, erf});+ auto mul_constant = wrap_type<v0::Constant>(check_value(0.5f));// (0.5 * x) * (1 + erf(x / sqrt(2))- auto mul_first = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_constant});- auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({mul_first, add});+ auto mul_first = wrap_type<v1::Multiply>({input, mul_constant});+ auto mul = wrap_type<v1::Multiply>({mul_first, add});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {return gelu_replacer(m, input);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul, matcher_name);+ auto m = std::make_shared<Matcher>(mul, matcher_name);register_matcher(m, callback);}@@ -97,29 +102,29 @@ ov::pass::GeluFusionWithErfTwo::GeluFusionWithErfTwo() {MATCHER_SCOPE(GeluFusionWithErfTwo);// Replaces a sub-graph with a Gelu op// Shared by every pattern: (1 + erf(x / sqrt(2)))- auto input = pass::pattern::any_input();- auto div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(SQRT2, 0.001f));- auto div = ov::pass::pattern::wrap_type<ov::op::v1::Divide>({input, div_constant});+ auto input = any_input();+ auto div_constant = wrap_type<v0::Constant>(check_value(SQRT2, 0.001f));+ auto div = wrap_type<v1::Divide>({input, div_constant});// In case of ConvertDivideWithConstant is applied and Div is converted to Mul- auto mul_as_div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(SQRT1_2, 0.001f));- auto mul_as_div = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_as_div_constant});+ auto mul_as_div_constant = wrap_type<v0::Constant>(check_value(SQRT1_2, 0.001f));+ auto mul_as_div = wrap_type<v1::Multiply>({input, mul_as_div_constant});auto erf_input = std::make_shared<Or>(ov::OutputVector{div, mul_as_div});- auto erf = ov::pass::pattern::wrap_type<ov::op::v0::Erf>({erf_input});- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(1.0f));- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({add_constant, erf});- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(0.5f));+ auto erf = wrap_type<v0::Erf>({erf_input});+ auto add_constant = wrap_type<v0::Constant>(check_value(1.0f));+ auto add = wrap_type<v1::Add>({add_constant, erf});+ auto mul_constant = wrap_type<v0::Constant>(check_value(0.5f));// 0.5 * (x * (1 + erf(x / sqrt(2)))- auto mul_first = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, add});- auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({mul_constant, mul_first});+ auto mul_first = wrap_type<v1::Multiply>({input, add});+ auto mul = wrap_type<v1::Multiply>({mul_constant, mul_first});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {return gelu_replacer(m, input);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul, matcher_name);+ auto m = std::make_shared<Matcher>(mul, matcher_name);register_matcher(m, callback);}@@ -127,48 +132,46 @@ ov::pass::GeluFusionWithErfThree::GeluFusionWithErfThree() {MATCHER_SCOPE(GeluFusionWithErfThree);// Replaces a sub-graph with a Gelu op// Shared by every pattern: (1 + erf(x / sqrt(2)))- auto input = pass::pattern::any_input();- auto div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(SQRT2, 0.001f));- auto div = ov::pass::pattern::wrap_type<ov::op::v1::Divide>({input, div_constant});+ auto input = any_input();+ auto div_constant = wrap_type<v0::Constant>(check_value(SQRT2, 0.001f));+ auto div = wrap_type<v1::Divide>({input, div_constant});// In case of ConvertDivideWithConstant is applied and Div is converted to Mul- auto mul_as_div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(SQRT1_2, 0.001f));- auto mul_as_div = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_as_div_constant});+ auto mul_as_div_constant = wrap_type<v0::Constant>(check_value(SQRT1_2, 0.001f));+ auto mul_as_div = wrap_type<v1::Multiply>({input, mul_as_div_constant});auto erf_input = std::make_shared<Or>(ov::OutputVector{div, mul_as_div});- auto erf = ov::pass::pattern::wrap_type<ov::op::v0::Erf>({erf_input});- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(1.0f));- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({add_constant, erf});- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(0.5f));+ auto erf = wrap_type<v0::Erf>({erf_input});+ auto add_constant = wrap_type<v0::Constant>(check_value(1.0f));+ auto add = wrap_type<v1::Add>({add_constant, erf});+ auto mul_constant = wrap_type<v0::Constant>(check_value(0.5f));// x * (0.5 * (1 + erf(x / sqrt(2)))- auto mul_first = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({add, mul_constant});- auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_first});+ auto mul_first = wrap_type<v1::Multiply>({add, mul_constant});+ auto mul = wrap_type<v1::Multiply>({input, mul_first});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {return gelu_replacer(m, input);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul, matcher_name);+ auto m = std::make_shared<Matcher>(mul, matcher_name);register_matcher(m, callback);}ov::pass::GeluFusionWithErfFour::GeluFusionWithErfFour() {MATCHER_SCOPE(GeluFusionWithErfFour);using namespace ov;- using namespace ov::pass::pattern;-auto input = any_input();- auto mul1_constant = wrap_type<ov::op::v0::Constant>(check_value(SQRT1_2, 0.001f));- auto mul1 = wrap_type<ov::op::v1::Multiply>({input, mul1_constant});- auto erf = wrap_type<ov::op::v0::Erf>({mul1});- auto mul2_constant = wrap_type<ov::op::v0::Constant>(check_value(0.5f));- auto mul2 = wrap_type<ov::op::v1::Multiply>({erf, mul2_constant});- auto add_constant = wrap_type<ov::op::v0::Constant>(check_value(0.5f));- auto add = wrap_type<ov::op::v1::Add>({add_constant, mul2});+ auto mul1_constant = wrap_type<v0::Constant>(check_value(SQRT1_2, 0.001f));+ auto mul1 = wrap_type<v1::Multiply>({input, mul1_constant});+ auto erf = wrap_type<v0::Erf>({mul1});+ auto mul2_constant = wrap_type<v0::Constant>(check_value(0.5f));+ auto mul2 = wrap_type<v1::Multiply>({erf, mul2_constant});+ auto add_constant = wrap_type<v0::Constant>(check_value(0.5f));+ auto add = wrap_type<v1::Add>({add_constant, mul2});// x * (0.5 + 0.5 * erf(x * (1 / sqrt(2))))- auto mul3 = wrap_type<ov::op::v1::Multiply>({input, add});+ auto mul3 = wrap_type<v1::Multiply>({input, add});matcher_pass_callback callback = [=](Matcher& m) {return gelu_replacer(m, input);@@ -180,125 +183,125 @@ ov::pass::GeluFusionWithErfFour::GeluFusionWithErfFour() {ov::pass::GeluFusionWithTanh::GeluFusionWithTanh() {MATCHER_SCOPE(GeluFusionWithTanh);- // Replaces a sub-graph with a Gelu (ov::op::v0::Tanh) op+ // Replaces a sub-graph with a Gelu (v0::Tanh) op// Gaussian Error Linear Unit, TanH based approximation:// x * (0.5 * (1 + tanh([sqrt(2 / pi)] * [x + 0.044715^3]))- auto input = pass::pattern::any_input();- auto pow_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(3.0f));- auto pow = ov::pass::pattern::wrap_type<ov::op::v1::Power>({input, pow_constant});+ auto input = any_input();+ auto pow_constant = wrap_type<v0::Constant>(check_value(3.0f));+ auto pow = wrap_type<v1::Power>({input, pow_constant});- auto mul_0_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(0.044715f, 0.001f));- auto mul_0 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({pow, mul_0_constant});+ auto mul_0_constant = wrap_type<v0::Constant>(check_value(0.044715f, 0.001f));+ auto mul_0 = wrap_type<v1::Multiply>({pow, mul_0_constant});- auto add_0 = ov::pass::pattern::wrap_type<ov::op::v1::Add>({input, mul_0});+ auto add_0 = wrap_type<v1::Add>({input, mul_0});- auto mul_1_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(SQRT_2_PI, 0.01f));- auto mul_1 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({add_0, mul_1_constant});+ auto mul_1_constant = wrap_type<v0::Constant>(check_value(SQRT_2_PI, 0.01f));+ auto mul_1 = wrap_type<v1::Multiply>({add_0, mul_1_constant});- auto tanh = ov::pass::pattern::wrap_type<ov::op::v0::Tanh>({mul_1});+ auto tanh = wrap_type<v0::Tanh>({mul_1});- auto add_1_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(1.0f));- auto add_1 = ov::pass::pattern::wrap_type<ov::op::v1::Add>({tanh, add_1_constant});+ auto add_1_constant = wrap_type<v0::Constant>(check_value(1.0f));+ auto add_1 = wrap_type<v1::Add>({tanh, add_1_constant});- auto mul_2_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(0.5f));+ auto mul_2_constant = wrap_type<v0::Constant>(check_value(0.5f));// x * (0.5 * (1 + tanh))- auto mul_2_1 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({add_1, mul_2_constant});- auto mul_3_1 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_2_1});+ auto mul_2_1 = wrap_type<v1::Multiply>({add_1, mul_2_constant});+ auto mul_3_1 = wrap_type<v1::Multiply>({input, mul_2_1});// (x * 0.5) * (1 + tanh)- auto mul_2_2 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_2_constant});- auto mul_3_2 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({add_1, mul_2_2});+ auto mul_2_2 = wrap_type<v1::Multiply>({input, mul_2_constant});+ auto mul_3_2 = wrap_type<v1::Multiply>({add_1, mul_2_2});- auto mul_3 = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{mul_3_1, mul_3_2});+ auto mul_3 = std::make_shared<Or>(OutputVector{mul_3_1, mul_3_2});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {return gelu_replacer(m, input, ov::op::GeluApproximationMode::TANH);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_3, matcher_name);+ auto m = std::make_shared<Matcher>(mul_3, matcher_name);register_matcher(m, callback);}ov::pass::GeluFusionWithTanhNoPower::GeluFusionWithTanhNoPower() {- // Replaces a sub-graph with a Gelu (ov::op::v0::Tanh) op+ // Replaces a sub-graph with a Gelu (v0::Tanh) op// x * 0.5 * (1 + tanh((x * 0.044715 * x + 1) * x * sqrt(2 / pi)))MATCHER_SCOPE(GeluFusionWithTanhNoPower);- auto input = pattern::any_input();+ auto input = any_input();- auto const1 = pattern::wrap_type<ov::op::v0::Constant>(check_value(0.044715f, 0.001f));- auto mul1 = pattern::wrap_type<ov::op::v1::Multiply>({input, const1});+ auto const1 = wrap_type<v0::Constant>(check_value(0.044715f, 0.001f));+ auto mul1 = wrap_type<v1::Multiply>({input, const1});- auto mul2 = pattern::wrap_type<ov::op::v1::Multiply>({mul1, input});+ auto mul2 = wrap_type<v1::Multiply>({mul1, input});- auto const2 = pattern::wrap_type<ov::op::v0::Constant>(check_value(1.0f));- auto add1 = pattern::wrap_type<ov::op::v1::Add>({const2, mul2});+ auto const2 = wrap_type<v0::Constant>(check_value(1.0f));+ auto add1 = wrap_type<v1::Add>({const2, mul2});- auto const3 = pattern::wrap_type<ov::op::v0::Constant>(check_value(SQRT_2_PI, 0.01f));- auto mul3 = pattern::wrap_type<ov::op::v1::Multiply>({input, const3});+ auto const3 = wrap_type<v0::Constant>(check_value(SQRT_2_PI, 0.01f));+ auto mul3 = wrap_type<v1::Multiply>({input, const3});- auto mul4 = pattern::wrap_type<ov::op::v1::Multiply>({add1, mul3});+ auto mul4 = wrap_type<v1::Multiply>({add1, mul3});- auto tanh = pattern::wrap_type<ov::op::v0::Tanh>({mul4});+ auto tanh = wrap_type<v0::Tanh>({mul4});- auto const4 = pattern::wrap_type<ov::op::v0::Constant>(check_value(1.0f));- auto add2 = pattern::wrap_type<ov::op::v1::Add>({tanh, const4});+ auto const4 = wrap_type<v0::Constant>(check_value(1.0f));+ auto add2 = wrap_type<v1::Add>({tanh, const4});- auto const5 = pattern::wrap_type<ov::op::v0::Constant>(check_value(0.5f));- auto mul5 = pattern::wrap_type<ov::op::v1::Multiply>({input, const5});+ auto const5 = wrap_type<v0::Constant>(check_value(0.5f));+ auto mul5 = wrap_type<v1::Multiply>({input, const5});- auto mul6 = pattern::wrap_type<ov::op::v1::Multiply>({add2, mul5});+ auto mul6 = wrap_type<v1::Multiply>({add2, mul5});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {return gelu_replacer(m, input, ov::op::GeluApproximationMode::TANH);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul6, matcher_name);+ auto m = std::make_shared<Matcher>(mul6, matcher_name);register_matcher(m, callback);}ov::pass::GeluFusionWithTanhNoPower2::GeluFusionWithTanhNoPower2() {MATCHER_SCOPE(GeluFusionWithTanhNoPower2);- // Replaces a sub-graph with a Gelu (ov::op::v0::Tanh) op+ // Replaces a sub-graph with a Gelu (v0::Tanh) op// x * (0.5 * (1 + tanh([sqrt(2 / pi)] * [x + 0.044715 * x * x * x])))- auto input = pass::pattern::any_input();+ auto input = any_input();- auto mul_0 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, input});- auto mul_1 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_0});+ auto mul_0 = wrap_type<v1::Multiply>({input, input});+ auto mul_1 = wrap_type<v1::Multiply>({input, mul_0});- auto mul_2_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(0.044715f, 0.001f));- auto mul_2 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({mul_1, mul_2_constant});+ auto mul_2_constant = wrap_type<v0::Constant>(check_value(0.044715f, 0.001f));+ auto mul_2 = wrap_type<v1::Multiply>({mul_1, mul_2_constant});- auto add_0 = ov::pass::pattern::wrap_type<ov::op::v1::Add>({input, mul_2});+ auto add_0 = wrap_type<v1::Add>({input, mul_2});- auto mul_3_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(SQRT_2_PI, 0.01f));- auto mul_3 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({add_0, mul_3_constant});+ auto mul_3_constant = wrap_type<v0::Constant>(check_value(SQRT_2_PI, 0.01f));+ auto mul_3 = wrap_type<v1::Multiply>({add_0, mul_3_constant});- auto tanh = ov::pass::pattern::wrap_type<ov::op::v0::Tanh>({mul_3});+ auto tanh = wrap_type<v0::Tanh>({mul_3});- auto add_1_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(1.0f));- auto add_1 = ov::pass::pattern::wrap_type<ov::op::v1::Add>({tanh, add_1_constant});+ auto add_1_constant = wrap_type<v0::Constant>(check_value(1.0f));+ auto add_1 = wrap_type<v1::Add>({tanh, add_1_constant});- auto mul_4_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(check_value(0.5f));+ auto mul_4_constant = wrap_type<v0::Constant>(check_value(0.5f));// x * (0.5 * (1 + tanh))- auto mul_4_1 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({add_1, mul_4_constant});- auto mul_5_1 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_4_1});+ auto mul_4_1 = wrap_type<v1::Multiply>({add_1, mul_4_constant});+ auto mul_5_1 = wrap_type<v1::Multiply>({input, mul_4_1});// (x * 0.5) * (1 + tanh)- auto mul_4_2 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_4_constant});- auto mul_5_2 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({add_1, mul_4_2});+ auto mul_4_2 = wrap_type<v1::Multiply>({input, mul_4_constant});+ auto mul_5_2 = wrap_type<v1::Multiply>({add_1, mul_4_2});// 0.5 * (x * (1 + tanh))- auto mul_4_3 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({add_1, input});- auto mul_5_3 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({mul_4_3, mul_4_constant});+ auto mul_4_3 = wrap_type<v1::Multiply>({add_1, input});+ auto mul_5_3 = wrap_type<v1::Multiply>({mul_4_3, mul_4_constant});- auto mul_5 = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{mul_5_1, mul_5_2, mul_5_3});+ auto mul_5 = std::make_shared<Or>(OutputVector{mul_5_1, mul_5_2, mul_5_3});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {return gelu_replacer(m, input, ov::op::GeluApproximationMode::TANH);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_5, matcher_name);+ auto m = std::make_shared<Matcher>(mul_5, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/glu_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/glu_fusion.cppindex 5513a9f8c7a..6fd7e5c23be 100644--- a/src/common/transformations/src/transformations/common_optimizations/glu_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/glu_fusion.cpp@@ -17,13 +17,15 @@#include "ov_ops/glu.hpp"#include "transformations/utils/utils.hpp"-namespace ov {-namespace pass {+namespace ov::pass {-GLUFusion::GLUFusion() {- using namespace ov::pass::pattern;- using ov::pass::pattern::op::Or;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;+namespace v7 = ov::op::v7;+namespace op_util = ov::op::util;+GLUFusion::GLUFusion() {auto last_dim_static = [](const ov::Output<ov::Node>& output) {auto out_ps = output.get_node()->get_output_partial_shape(0);return out_ps.rank().is_static() && out_ps[out_ps.rank().get_length() - 1].is_static() && out_ps.size() <= 5;@@ -31,30 +33,30 @@ GLUFusion::GLUFusion() {// Detect GLU decomposition pattern// GLU(Xw, Xv, beta) = (Xw * (1.0 + exp(-beta * Xw))) * Xv- auto data_m = any_input(last_dim_static);+ auto data_m = pattern::any_input(last_dim_static);// VariadicSplit(X, axis, split_lengths) = Xw, Xv- auto axis_const_m = wrap_type<ov::op::v0::Constant>();- auto split_lengths_const_m = wrap_type<ov::op::v0::Constant>();- auto variadic_split_m = wrap_type<ov::op::v1::VariadicSplit>({data_m, axis_const_m, split_lengths_const_m});+ auto axis_const_m = pattern::wrap_type<v0::Constant>();+ auto split_lengths_const_m = pattern::wrap_type<v0::Constant>();+ auto variadic_split_m = pattern::wrap_type<v1::VariadicSplit>({data_m, axis_const_m, split_lengths_const_m});variadic_split_m->set_output_size(2);// Swish(Xw) = Xw * (1.0 + exp(-beta * Xw))- auto swish_m = wrap_type<ov::op::v4::Swish>({variadic_split_m->output(0)});- auto gelu_m = wrap_type<ov::op::v7::Gelu>({variadic_split_m->output(0)});+ auto swish_m = pattern::wrap_type<v4::Swish>({variadic_split_m->output(0)});+ auto gelu_m = pattern::wrap_type<v7::Gelu>({variadic_split_m->output(0)});// Mul(Xw, Xv) = Swish(Xw) * Xv- auto glu_m = std::make_shared<Or>(OutputVector{swish_m, gelu_m});- auto mul_m = wrap_type<ov::op::v1::Multiply>({glu_m, variadic_split_m->output(1)});+ auto glu_m = std::make_shared<pattern::op::Or>(OutputVector{swish_m, gelu_m});+ auto mul_m = pattern::wrap_type<v1::Multiply>({glu_m, variadic_split_m->output(1)});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();OPENVINO_ASSERT(pattern_map.count(mul_m));OPENVINO_ASSERT(pattern_map.count(swish_m) || pattern_map.count(gelu_m));OPENVINO_ASSERT(pattern_map.count(variadic_split_m));OPENVINO_ASSERT(pattern_map.count(split_lengths_const_m));OPENVINO_ASSERT(pattern_map.count(axis_const_m));- auto mul = ov::as_type_ptr<ov::op::v1::Multiply>(pattern_map.at(mul_m).get_node_shared_ptr());+ auto mul = ov::as_type_ptr<v1::Multiply>(pattern_map.at(mul_m).get_node_shared_ptr());if (!mul || transformation_callback(mul))return false;@@ -64,21 +66,21 @@ GLUFusion::GLUFusion() {ov::op::internal::GLU::GluType glu_type = ov::op::internal::GLU::GluType::Swish;if (isSwiGLU) {- auto swish = ov::as_type_ptr<ov::op::v4::Swish>(pattern_map.at(swish_m).get_node_shared_ptr());+ auto swish = ov::as_type_ptr<v4::Swish>(pattern_map.at(swish_m).get_node_shared_ptr());glu_type = ov::op::internal::GLU::GluType::Swish;split_to_glu_idx = swish->input_value(0).get_index();- size_t split_in_idx = ov::is_type<ov::op::v4::Swish>(mul->get_input_node_shared_ptr(0)) ? 1 : 0;+ size_t split_in_idx = ov::is_type<v4::Swish>(mul->get_input_node_shared_ptr(0)) ? 1 : 0;if (mul->input_value(split_in_idx).get_index() == split_to_glu_idx)return false;} else if (isGeGLU) {- auto gelu = ov::as_type_ptr<ov::op::v7::Gelu>(pattern_map.at(gelu_m).get_node_shared_ptr());+ auto gelu = ov::as_type_ptr<v7::Gelu>(pattern_map.at(gelu_m).get_node_shared_ptr());glu_type = (gelu->get_approximation_mode() == ov::op::GeluApproximationMode::ERF)? ov::op::internal::GLU::GluType::Gelu: ov::op::internal::GLU::GluType::Gelu_Tanh;split_to_glu_idx = gelu->input_value(0).get_index();- size_t split_in_idx = ov::is_type<ov::op::v7::Gelu>(mul->get_input_node_shared_ptr(0)) ? 1 : 0;+ size_t split_in_idx = ov::is_type<v7::Gelu>(mul->get_input_node_shared_ptr(0)) ? 1 : 0;if (mul->input_value(split_in_idx).get_index() == split_to_glu_idx)return false;} else {@@ -86,19 +88,18 @@ GLUFusion::GLUFusion() {}auto variadic_split =- ov::as_type_ptr<ov::op::v1::VariadicSplit>(pattern_map.at(variadic_split_m).get_node_shared_ptr());+ ov::as_type_ptr<v1::VariadicSplit>(pattern_map.at(variadic_split_m).get_node_shared_ptr());auto variadic_split_in_ps = variadic_split->get_input_partial_shape(0);auto last_dim = variadic_split_in_ps.rank().get_length() - 1;- auto axis = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(axis_const_m).get_node_shared_ptr());- bool valid_axis_const_values = ov::op::util::has_constant_value<int64_t>(axis, -1) ||- ov::op::util::has_constant_value<int64_t>(axis, last_dim);+ auto axis = ov::as_type_ptr<v0::Constant>(pattern_map.at(axis_const_m).get_node_shared_ptr());+ bool valid_axis_const_values =+ op_util::has_constant_value<int64_t>(axis, -1) || op_util::has_constant_value<int64_t>(axis, last_dim);if (!valid_axis_const_values)return false;auto axis_value = axis->cast_vector<int64_t>()[0];- auto split_lengths =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(split_lengths_const_m).get_node_shared_ptr());+ auto split_lengths = ov::as_type_ptr<v0::Constant>(pattern_map.at(split_lengths_const_m).get_node_shared_ptr());auto split_lengths_value = split_lengths->cast_vector<int64_t>()[0];// Allow only case that exactly splits in half along the last dimensionauto split_length = variadic_split_in_ps[last_dim].get_length() / 2;@@ -121,9 +122,8 @@ GLUFusion::GLUFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_m, "GLUFusion");+ auto m = std::make_shared<pattern::Matcher>(mul_m, "GLUFusion");this->register_matcher(m, callback);}-} // namespace pass-} // namespace ov+} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/group_normalization_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/group_normalization_fusion.cppindex 16263d78c81..6e736a591c7 100644--- a/src/common/transformations/src/transformations/common_optimizations/group_normalization_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/group_normalization_fusion.cpp@@ -19,9 +19,14 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::pass::pattern;+namespace ov::pass {-ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v6 = ov::op::v6;+namespace v8 = ov::op::v8;++GroupNormalizationFusion::GroupNormalizationFusion() {MATCHER_SCOPE(GroupNormalizationFusion);auto has_real_not_quantized_type = [](const ov::Output<ov::Node>& output) -> bool {@@ -34,36 +39,44 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {return (output_ps.rank().is_static()) && (output_ps.rank().get_length() >= 2);};- auto input_m = any_input(all_of({has_real_not_quantized_type, has_at_least_2d_shape, has_static_dim(1)}));+ auto input_m = pattern::any_input(+ pattern::all_of({has_real_not_quantized_type, has_at_least_2d_shape, pattern::has_static_dim(1)}));- auto pre_mvn_shape_const_m = wrap_type<ov::op::v0::Constant>(all_of({rank_equals(1), has_static_dim(0)}));- auto pre_mvn_reshape_m =- wrap_type<ov::op::v1::Reshape>({input_m, pre_mvn_shape_const_m},- all_of({has_real_not_quantized_type, rank_equals(3), has_static_dim(1)}));+ auto pre_mvn_shape_const_m =+ pattern::wrap_type<v0::Constant>(pattern::all_of({pattern::rank_equals(1), pattern::has_static_dim(0)}));+ auto pre_mvn_reshape_m = pattern::wrap_type<v1::Reshape>(+ {input_m, pre_mvn_shape_const_m},+ pattern::all_of({has_real_not_quantized_type, pattern::rank_equals(3), pattern::has_static_dim(1)}));- auto mvn_reduction_axes_const_m = wrap_type<ov::op::v0::Constant>(all_of({rank_equals(1), has_static_dim(0)}));- auto mvn_m = wrap_type<ov::op::v6::MVN>({pre_mvn_reshape_m, mvn_reduction_axes_const_m});+ auto mvn_reduction_axes_const_m =+ pattern::wrap_type<v0::Constant>(pattern::all_of({pattern::rank_equals(1), pattern::has_static_dim(0)}));+ auto mvn_m = pattern::wrap_type<v6::MVN>({pre_mvn_reshape_m, mvn_reduction_axes_const_m});- auto instance_norm_gamma_m = any_input(all_of({has_real_not_quantized_type, has_static_shape()}));- auto instance_norm_opt_gamma_m = optional<ov::op::v1::Multiply>({mvn_m, instance_norm_gamma_m});+ auto instance_norm_gamma_m =+ pattern::any_input(pattern::all_of({has_real_not_quantized_type, pattern::has_static_shape()}));+ auto instance_norm_opt_gamma_m = pattern::optional<v1::Multiply>({mvn_m, instance_norm_gamma_m});- auto instance_norm_beta_m = any_input(all_of({has_real_not_quantized_type, has_static_shape()}));+ auto instance_norm_beta_m =+ pattern::any_input(pattern::all_of({has_real_not_quantized_type, pattern::has_static_shape()}));auto instance_norm_opt_gamma_opt_beta_m =- optional<ov::op::v1::Add>({instance_norm_opt_gamma_m, instance_norm_beta_m});+ pattern::optional<v1::Add>({instance_norm_opt_gamma_m, instance_norm_beta_m});- auto post_instance_norm_shape_m = any_input(all_of({rank_equals(1), has_static_dim(0)}));- auto post_instance_norm_reshape_m =- wrap_type<ov::op::v1::Reshape>({instance_norm_opt_gamma_opt_beta_m, post_instance_norm_shape_m},- all_of({has_real_not_quantized_type, has_at_least_2d_shape, has_static_dim(1)}));+ auto post_instance_norm_shape_m =+ pattern::any_input(pattern::all_of({pattern::rank_equals(1), pattern::has_static_dim(0)}));+ auto post_instance_norm_reshape_m = pattern::wrap_type<v1::Reshape>(+ {instance_norm_opt_gamma_opt_beta_m, post_instance_norm_shape_m},+ pattern::all_of({has_real_not_quantized_type, has_at_least_2d_shape, pattern::has_static_dim(1)}));- auto group_norm_gamma_m = any_input(all_of({has_real_not_quantized_type, has_static_shape()}));+ auto group_norm_gamma_m =+ pattern::any_input(pattern::all_of({has_real_not_quantized_type, pattern::has_static_shape()}));auto group_norm_gamma_multiply_m =- wrap_type<ov::op::v1::Multiply>({post_instance_norm_reshape_m, group_norm_gamma_m});+ pattern::wrap_type<v1::Multiply>({post_instance_norm_reshape_m, group_norm_gamma_m});- auto group_norm_beta_m = any_input(all_of({has_real_not_quantized_type, has_static_shape()}));- auto group_norm_beta_add_m = wrap_type<ov::op::v1::Add>({group_norm_gamma_multiply_m, group_norm_beta_m});+ auto group_norm_beta_m =+ pattern::any_input(pattern::all_of({has_real_not_quantized_type, pattern::has_static_shape()}));+ auto group_norm_beta_add_m = pattern::wrap_type<v1::Add>({group_norm_gamma_multiply_m, group_norm_beta_m});- ov::matcher_pass_callback callback = [=](Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& input = pattern_map.at(input_m);@@ -80,7 +93,7 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {// but leave batch and channel dimensions untouchedconst auto& pre_mvn_shape = pattern_map.at(pre_mvn_shape_const_m);const auto& pre_mvn_shape_const =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(pre_mvn_shape_const_m).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_map.at(pre_mvn_shape_const_m).get_node_shared_ptr());const auto& pre_mvn_shape_out_ps = pre_mvn_shape.get_shape();if (pre_mvn_shape_out_ps[0] != 3)return false;@@ -118,8 +131,7 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {// we expect to execute normalization over last dimension of MVN inputconst auto& mvn_reduction_axes = pattern_map.at(mvn_reduction_axes_const_m);- const auto& mvn_reduction_axes_const =- ov::as_type_ptr<ov::op::v0::Constant>(mvn_reduction_axes.get_node_shared_ptr());+ const auto& mvn_reduction_axes_const = ov::as_type_ptr<v0::Constant>(mvn_reduction_axes.get_node_shared_ptr());const auto& mvn_reduction_axes_out_shape = mvn_reduction_axes.get_shape();if (mvn_reduction_axes_out_shape[0] != 1)return false;@@ -154,7 +166,7 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {ov::NodeVector nodes;- std::shared_ptr<ov::Node> group_norm_gamma_1d_m = std::make_shared<ov::op::v0::Squeeze>(group_norm_gamma);+ std::shared_ptr<ov::Node> group_norm_gamma_1d_m = std::make_shared<v0::Squeeze>(group_norm_gamma);nodes.push_back(group_norm_gamma_1d_m);const auto& group_norm_gamma_1d_out_ps = group_norm_gamma_1d_m->get_output_partial_shape(0);@@ -162,20 +174,20 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {if (group_norm_gamma_1d_out_ps != expected_param_shape)return false;- std::shared_ptr<ov::Node> group_norm_beta_1d_m = std::make_shared<ov::op::v0::Squeeze>(group_norm_beta);+ std::shared_ptr<ov::Node> group_norm_beta_1d_m = std::make_shared<v0::Squeeze>(group_norm_beta);nodes.push_back(group_norm_beta_1d_m);const auto& group_norm_beta_1d_out_ps = group_norm_beta_1d_m->get_output_partial_shape(0);if (group_norm_beta_1d_out_ps != expected_param_shape)return false;- auto gather_axis_const_m = ov::op::v0::Constant::create(element::i64, Shape{1}, {0});+ auto gather_axis_const_m = v0::Constant::create(element::i64, Shape{1}, {0});nodes.push_back(gather_axis_const_m);auto gather_indices_vals = std::vector<int64_t>();for (auto i = 0; i < num_groups; i++)gather_indices_vals.insert(gather_indices_vals.end(), num_channels / num_groups, i);auto gather_indices_const_m =- ov::op::v0::Constant::create(element::i64, Shape{static_cast<size_t>(num_channels)}, gather_indices_vals);+ v0::Constant::create(element::i64, Shape{static_cast<size_t>(num_channels)}, gather_indices_vals);nodes.push_back(gather_indices_const_m);if (pattern_map.count(instance_norm_beta_m) > 0) {@@ -189,19 +201,17 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {// with group_norm parameters, i.e. 1D vector of shape (num_channels)std::shared_ptr<ov::Node> instance_norm_beta_1d_m = nullptr;if (ov::shape_size(instance_norm_beta.get_shape()) == 1) {- auto shape_1d_const_m = ov::op::v0::Constant::create(element::i64, Shape{1}, {1});+ auto shape_1d_const_m = v0::Constant::create(element::i64, Shape{1}, {1});nodes.push_back(shape_1d_const_m);- instance_norm_beta_1d_m =- std::make_shared<ov::op::v1::Reshape>(instance_norm_beta, shape_1d_const_m, true);+ instance_norm_beta_1d_m = std::make_shared<v1::Reshape>(instance_norm_beta, shape_1d_const_m, true);nodes.push_back(instance_norm_beta_1d_m);} else {- instance_norm_beta_1d_m = std::make_shared<ov::op::v0::Squeeze>(instance_norm_beta);+ instance_norm_beta_1d_m = std::make_shared<v0::Squeeze>(instance_norm_beta);nodes.push_back(instance_norm_beta_1d_m);}- instance_norm_beta_1d_m = std::make_shared<ov::op::v8::Gather>(instance_norm_beta_1d_m,- gather_indices_const_m,- gather_axis_const_m);+ instance_norm_beta_1d_m =+ std::make_shared<v8::Gather>(instance_norm_beta_1d_m, gather_indices_const_m, gather_axis_const_m);nodes.push_back(instance_norm_beta_1d_m);const auto& instance_norm_beta_1d_ps = instance_norm_beta_1d_m->get_output_partial_shape(0);@@ -210,10 +220,9 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {// group_norm_beta = group_norm_gamma * instance_norm_beta + group_norm_betaauto group_norm_beta_corr_multiply_m =- std::make_shared<ov::op::v1::Multiply>(group_norm_gamma_1d_m, instance_norm_beta_1d_m);+ std::make_shared<v1::Multiply>(group_norm_gamma_1d_m, instance_norm_beta_1d_m);nodes.push_back(group_norm_beta_corr_multiply_m);- group_norm_beta_1d_m =- std::make_shared<ov::op::v1::Add>(group_norm_beta_corr_multiply_m, group_norm_beta_1d_m);+ group_norm_beta_1d_m = std::make_shared<v1::Add>(group_norm_beta_corr_multiply_m, group_norm_beta_1d_m);nodes.push_back(group_norm_beta_1d_m);}@@ -228,19 +237,17 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {// with group_norm parameters, i.e. 1D vector of shape (num_channels)std::shared_ptr<ov::Node> instance_norm_gamma_1d_m = nullptr;if (ov::shape_size(instance_norm_gamma.get_shape()) == 1) {- auto shape_1d_const_m = ov::op::v0::Constant::create(element::i64, Shape{1}, {1});+ auto shape_1d_const_m = v0::Constant::create(element::i64, Shape{1}, {1});nodes.push_back(shape_1d_const_m);- instance_norm_gamma_1d_m =- std::make_shared<ov::op::v1::Reshape>(instance_norm_gamma, shape_1d_const_m, true);+ instance_norm_gamma_1d_m = std::make_shared<v1::Reshape>(instance_norm_gamma, shape_1d_const_m, true);nodes.push_back(instance_norm_gamma_1d_m);} else {- instance_norm_gamma_1d_m = std::make_shared<ov::op::v0::Squeeze>(instance_norm_gamma);+ instance_norm_gamma_1d_m = std::make_shared<v0::Squeeze>(instance_norm_gamma);nodes.push_back(instance_norm_gamma_1d_m);}- instance_norm_gamma_1d_m = std::make_shared<ov::op::v8::Gather>(instance_norm_gamma_1d_m,- gather_indices_const_m,- gather_axis_const_m);+ instance_norm_gamma_1d_m =+ std::make_shared<v8::Gather>(instance_norm_gamma_1d_m, gather_indices_const_m, gather_axis_const_m);nodes.push_back(instance_norm_gamma_1d_m);const auto& instance_norm_gamma_1d_ps = instance_norm_gamma_1d_m->get_output_partial_shape(0);@@ -248,14 +255,13 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {return false;// group_norm_gamma *= instance_norm_gamma- group_norm_gamma_1d_m =- std::make_shared<ov::op::v1::Multiply>(group_norm_gamma_1d_m, instance_norm_gamma_1d_m);+ group_norm_gamma_1d_m = std::make_shared<v1::Multiply>(group_norm_gamma_1d_m, instance_norm_gamma_1d_m);nodes.push_back(group_norm_gamma_1d_m);}// we need to cast mvn to MVN layer type in order to read actual epsilon valueconst auto& mvn_out = pattern_map.at(mvn_m);- const auto& mvn = ov::as_type_ptr<ov::op::v6::MVN>(mvn_out.get_node_shared_ptr());+ const auto& mvn = ov::as_type_ptr<v6::MVN>(mvn_out.get_node_shared_ptr());const auto& epsilon = mvn->get_eps();// reuse original friendly names for gamma and beta inputs@@ -277,6 +283,8 @@ ov::pass::GroupNormalizationFusion::GroupNormalizationFusion() {return true;};- auto m = std::make_shared<Matcher>(group_norm_beta_add_m, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(group_norm_beta_add_m, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/gru_cell_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/gru_cell_fusion.cppindex 25a813f8fd7..ef0dfb5e274 100644--- a/src/common/transformations/src/transformations/common_optimizations/gru_cell_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/gru_cell_fusion.cpp@@ -26,10 +26,10 @@#include "openvino/pass/pattern/op/or.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-using namespace std;-using namespace ov::element;-using namespace ov::pass;-using namespace ov::pass::pattern;+namespace ov::pass {++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;namespace {@@ -48,38 +48,35 @@ namespace {** \return Tuple of {Wzrh, Rzrh}*/-tuple<ov::Output<ov::Node>, ov::Output<ov::Node>> process_weights(NodeRegistry& rg,- bool is_zr_format,- const ov::Output<ov::Node>& WR,- const ov::Output<ov::Node>& WRh,- int64_t input_size,- int64_t hidden_size,- const shared_ptr<ov::op::v0::Constant>& axis_0,- const shared_ptr<ov::op::v0::Constant>& axis_1) {- using namespace ov;- auto split_lenghts = rg.make<ov::op::v0::Constant>(i64, Shape{2}, vector<int64_t>{input_size, hidden_size});- auto split_WRh = rg.make<ov::op::v1::VariadicSplit>(WRh, axis_1, split_lenghts);+std::tuple<ov::Output<ov::Node>, ov::Output<ov::Node>> process_weights(NodeRegistry& rg,+ bool is_zr_format,+ const ov::Output<ov::Node>& WR,+ const ov::Output<ov::Node>& WRh,+ int64_t input_size,+ int64_t hidden_size,+ const std::shared_ptr<v0::Constant>& axis_0,+ const std::shared_ptr<v0::Constant>& axis_1) {+ auto split_lenghts = rg.make<v0::Constant>(element::i64, Shape{2}, std::vector<int64_t>{input_size, hidden_size});+ auto split_WRh = rg.make<v1::VariadicSplit>(WRh, axis_1, split_lenghts);if (is_zr_format) {- auto split_WRzr = rg.make<ov::op::v1::VariadicSplit>(WR, axis_1, split_lenghts);- auto Wzrh = rg.make<ov::op::v0::Concat>(ov::OutputVector{split_WRzr->output(0), split_WRh->output(0)}, 0);- auto Rzrh = rg.make<ov::op::v0::Concat>(ov::OutputVector{split_WRzr->output(1), split_WRh->output(1)}, 0);+ auto split_WRzr = rg.make<v1::VariadicSplit>(WR, axis_1, split_lenghts);+ auto Wzrh = rg.make<v0::Concat>(ov::OutputVector{split_WRzr->output(0), split_WRh->output(0)}, 0);+ auto Rzrh = rg.make<v0::Concat>(ov::OutputVector{split_WRzr->output(1), split_WRh->output(1)}, 0);return {Wzrh, Rzrh};} else {- auto split_WRrz = rg.make<ov::op::v1::VariadicSplit>(WR, axis_1, split_lenghts);- auto split_W_r_z = rg.make<ov::op::v1::Split>(split_WRrz->output(0), axis_0, 2);- auto split_R_r_z = rg.make<ov::op::v1::Split>(split_WRrz->output(1), axis_0, 2);- auto Wzrh = rg.make<ov::op::v0::Concat>(- OutputVector{split_W_r_z->output(1), split_W_r_z->output(0), split_WRh->output(0)},- 0);- auto Rzrh = rg.make<ov::op::v0::Concat>(- OutputVector{split_R_r_z->output(1), split_R_r_z->output(0), split_WRh->output(1)},- 0);+ auto split_WRrz = rg.make<v1::VariadicSplit>(WR, axis_1, split_lenghts);+ auto split_W_r_z = rg.make<v1::Split>(split_WRrz->output(0), axis_0, 2);+ auto split_R_r_z = rg.make<v1::Split>(split_WRrz->output(1), axis_0, 2);+ auto Wzrh =+ rg.make<v0::Concat>(OutputVector{split_W_r_z->output(1), split_W_r_z->output(0), split_WRh->output(0)}, 0);+ auto Rzrh =+ rg.make<v0::Concat>(OutputVector{split_R_r_z->output(1), split_R_r_z->output(0), split_WRh->output(1)}, 0);return {Wzrh, Rzrh};}}} // namespace-ov::pass::GRUCellFusion::GRUCellFusion() {+GRUCellFusion::GRUCellFusion() {MATCHER_SCOPE(GRUCellFusion);// we can't determine hidden_size or input_size in this case@@ -88,24 +85,25 @@ ov::pass::GRUCellFusion::GRUCellFusion() {return !(p_shape.rank().is_dynamic() || p_shape[1].is_dynamic());};- auto concat_1 = wrap_type<ov::op::v0::Concat>({any_input(is_first_dim_static), any_input(is_first_dim_static)});- auto matmul_1 = wrap_type<ov::op::v0::MatMul>({concat_1, any_input(is_first_dim_static)});- auto add_1 = wrap_type<ov::op::v1::Add>({matmul_1, any_input()});- auto optional_bias_add_1 = make_shared<pattern::op::Or>(OutputVector{matmul_1, add_1});- auto activation_1 = wrap_type<ov::op::v0::Relu, ov::op::v0::Tanh, ov::op::v0::Sigmoid>({optional_bias_add_1});- auto split = wrap_type<ov::op::v1::Split>({activation_1, any_input()});-- auto multiply_1 = wrap_type<ov::op::v1::Multiply>({split, any_input()});- auto concat_2 = wrap_type<ov::op::v0::Concat>({any_input(), multiply_1});- auto matmul_2 = wrap_type<ov::op::v0::MatMul>({concat_2, any_input(is_first_dim_static)});- auto add_2 = wrap_type<ov::op::v1::Add>({matmul_2, any_input()});- auto optional_bias_add_2 = make_shared<pattern::op::Or>(OutputVector{matmul_2, add_2});- auto activation_2 = wrap_type<ov::op::v0::Relu, ov::op::v0::Tanh, ov::op::v0::Sigmoid>({optional_bias_add_2});-- auto subtract = wrap_type<ov::op::v1::Subtract>({any_input(), split});- auto multiply_2 = wrap_type<ov::op::v1::Multiply>({subtract, activation_2});- auto multiply_3 = wrap_type<ov::op::v1::Multiply>({split, any_input()});- auto add = wrap_type<ov::op::v1::Add>({multiply_2, multiply_3});+ auto concat_1 = pattern::wrap_type<v0::Concat>(+ {pattern::any_input(is_first_dim_static), pattern::any_input(is_first_dim_static)});+ auto matmul_1 = pattern::wrap_type<v0::MatMul>({concat_1, pattern::any_input(is_first_dim_static)});+ auto add_1 = pattern::wrap_type<v1::Add>({matmul_1, pattern::any_input()});+ auto optional_bias_add_1 = std::make_shared<pattern::op::Or>(OutputVector{matmul_1, add_1});+ auto activation_1 = pattern::wrap_type<v0::Relu, v0::Tanh, v0::Sigmoid>({optional_bias_add_1});+ auto split = pattern::wrap_type<v1::Split>({activation_1, pattern::any_input()});++ auto multiply_1 = pattern::wrap_type<v1::Multiply>({split, pattern::any_input()});+ auto concat_2 = pattern::wrap_type<v0::Concat>({pattern::any_input(), multiply_1});+ auto matmul_2 = pattern::wrap_type<v0::MatMul>({concat_2, pattern::any_input(is_first_dim_static)});+ auto add_2 = pattern::wrap_type<v1::Add>({matmul_2, pattern::any_input()});+ auto optional_bias_add_2 = std::make_shared<pattern::op::Or>(OutputVector{matmul_2, add_2});+ auto activation_2 = pattern::wrap_type<v0::Relu, v0::Tanh, v0::Sigmoid>({optional_bias_add_2});++ auto subtract = pattern::wrap_type<v1::Subtract>({pattern::any_input(), split});+ auto multiply_2 = pattern::wrap_type<v1::Multiply>({subtract, activation_2});+ auto multiply_3 = pattern::wrap_type<v1::Multiply>({split, pattern::any_input()});+ auto add = pattern::wrap_type<v1::Add>({multiply_2, multiply_3});matcher_pass_callback callback = [=](pattern::Matcher& m) {NodeRegistry rg;@@ -120,8 +118,8 @@ ov::pass::GRUCellFusion::GRUCellFusion() {auto hidden_size = h_pshape[1].get_length();auto input_size = x_pshape[1].get_length();- auto axis_0 = rg.make<ov::op::v0::Constant>(i64, Shape{}, 0);- auto axis_1 = rg.make<ov::op::v0::Constant>(i64, Shape{}, 1);+ auto axis_0 = rg.make<v0::Constant>(element::i64, Shape{}, 0);+ auto axis_1 = rg.make<v0::Constant>(element::i64, Shape{}, 1);// we assume this WR can have zr or rz formatauto WR = pattern_map.at(matmul_1)->input_value(1);@@ -139,14 +137,14 @@ ov::pass::GRUCellFusion::GRUCellFusion() {if (pattern_map.find(add_1) != pattern_map.end()) {B = pattern_map[add_1]->input_value(1);} else {- B = rg.make<ov::op::v0::Constant>(WR.get_element_type(), Shape{1, static_cast<size_t>(2 * hidden_size)}, 0);+ B = rg.make<v0::Constant>(WR.get_element_type(), Shape{1, static_cast<size_t>(2 * hidden_size)}, 0);}Output<Node> Bh;if (pattern_map.find(add_2) != pattern_map.end()) {Bh = pattern_map[add_2]->input_value(1);} else {- Bh = rg.make<ov::op::v0::Constant>(WRh.get_element_type(), Shape{1, static_cast<size_t>(hidden_size)}, 0);+ Bh = rg.make<v0::Constant>(WRh.get_element_type(), Shape{1, static_cast<size_t>(hidden_size)}, 0);}// perform additional check for applicability of the transformation@@ -160,26 +158,26 @@ ov::pass::GRUCellFusion::GRUCellFusion() {Output<Node> Wzrh, Rzrh, Bzrh;if (cnt_of_consumers_of_zero_out == 1 && cnt_of_consumers_of_first_out == 2) {- tie(Wzrh, Rzrh) = process_weights(rg, false, WR, WRh, input_size, hidden_size, axis_0, axis_1);- auto split_B_r_z = rg.make<ov::op::v1::Split>(B, axis_1, 2);- Bzrh = rg.make<ov::op::v0::Concat>(OutputVector{split_B_r_z->output(1), split_B_r_z->output(0), Bh}, 1);+ std::tie(Wzrh, Rzrh) = process_weights(rg, false, WR, WRh, input_size, hidden_size, axis_0, axis_1);+ auto split_B_r_z = rg.make<v1::Split>(B, axis_1, 2);+ Bzrh = rg.make<v0::Concat>(OutputVector{split_B_r_z->output(1), split_B_r_z->output(0), Bh}, 1);} else if (cnt_of_consumers_of_zero_out == 2 && cnt_of_consumers_of_first_out == 1) {- tie(Wzrh, Rzrh) = process_weights(rg, true, WR, WRh, input_size, hidden_size, axis_0, axis_1);- Bzrh = rg.make<ov::op::v0::Concat>(OutputVector{B, Bh}, 1);+ std::tie(Wzrh, Rzrh) = process_weights(rg, true, WR, WRh, input_size, hidden_size, axis_0, axis_1);+ Bzrh = rg.make<v0::Concat>(OutputVector{B, Bh}, 1);} else {// we can't detect the weights formatreturn false;}- auto squeeze_B = rg.make<ov::op::v0::Squeeze>(Bzrh, axis_0);+ auto squeeze_B = rg.make<v0::Squeeze>(Bzrh, axis_0);std::string act_name_1 = pattern_map.at(activation_1)->get_type_name();std::string act_name_2 = pattern_map.at(activation_2)->get_type_name();auto to_lower = [](unsigned char c) {return std::tolower(c);};- transform(act_name_1.begin(), act_name_1.end(), act_name_1.begin(), to_lower);- transform(act_name_2.begin(), act_name_2.end(), act_name_2.begin(), to_lower);+ std::transform(act_name_1.begin(), act_name_1.end(), act_name_1.begin(), to_lower);+ std::transform(act_name_2.begin(), act_name_2.end(), act_name_2.begin(), to_lower);auto cell = rg.make<ov::op::v3::GRUCell>(X,H,@@ -187,7 +185,7 @@ ov::pass::GRUCellFusion::GRUCellFusion() {Rzrh,squeeze_B,hidden_size,- vector<std::string>{act_name_1, act_name_2});+ std::vector<std::string>{act_name_1, act_name_2});cell->set_friendly_name(m.get_match_root()->get_friendly_name());copy_runtime_info(m.get_matched_nodes(), rg.get());@@ -195,6 +193,8 @@ ov::pass::GRUCellFusion::GRUCellFusion() {return true;};- auto m = make_shared<Matcher>(add, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(add, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cppindex 916ea7e2d81..29454002829 100644--- a/src/common/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/hsigmoid_fusion.cpp@@ -21,38 +21,42 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::HSigmoidFusionWithReluDiv::HSigmoidFusionWithReluDiv() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v5 = ov::op::v5;+namespace op_util = ov::op::util;++namespace ov::pass {++HSigmoidFusionWithReluDiv::HSigmoidFusionWithReluDiv() {MATCHER_SCOPE(HSigmoidFusionWithReluDiv);// Replaces a sub-graph ((min(Relu(x + 3), 6)) / 6 with a HSigmoid op.- auto input = pass::pattern::any_input();- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({input, add_constant});- auto relu = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({add});- auto min_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto min = ov::pass::pattern::wrap_type<ov::op::v1::Minimum>({relu, min_constant});- auto div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto div = ov::pass::pattern::wrap_type<ov::op::v1::Divide>({min, div_constant});-- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto add_constant = pattern::wrap_type<v0::Constant>();+ auto add = pattern::wrap_type<v1::Add>({input, add_constant});+ auto relu = pattern::wrap_type<v0::Relu>({add});+ auto min_constant = pattern::wrap_type<v0::Constant>();+ auto min = pattern::wrap_type<v1::Minimum>({relu, min_constant});+ auto div_constant = pattern::wrap_type<v0::Constant>();+ auto div = pattern::wrap_type<v1::Divide>({min, div_constant});++ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto x_output = pattern_to_output.at(input);- auto add_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- auto min_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());- auto div_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());+ auto add_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ auto min_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());+ auto div_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());- bool valid_constant_values = ov::op::util::has_constant_value<float>(add_const_value, 3.0) &&- ov::op::util::has_constant_value<float>(min_const_value, 6.0) &&- ov::op::util::has_constant_value<float>(div_const_value, 6.0);+ bool valid_constant_values = op_util::has_constant_value<float>(add_const_value, 3.0) &&+ op_util::has_constant_value<float>(min_const_value, 6.0) &&+ op_util::has_constant_value<float>(div_const_value, 6.0);if (!valid_constant_values) {return false;}- auto hsigmoid = register_new_node<ov::op::v5::HSigmoid>(x_output);+ auto hsigmoid = register_new_node<v5::HSigmoid>(x_output);hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info(@@ -67,42 +71,39 @@ ov::pass::HSigmoidFusionWithReluDiv::HSigmoidFusionWithReluDiv() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(div, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(div, matcher_name);register_matcher(m, callback);}-ov::pass::HSigmoidFusionWithReluMul::HSigmoidFusionWithReluMul() {+HSigmoidFusionWithReluMul::HSigmoidFusionWithReluMul() {MATCHER_SCOPE(HSigmoidFusionWithReluMul);// Replaces a sub-graph ((min(Relu(x + 3), 6)) * const(1/6) with a HSigmoid op.- auto input = pass::pattern::any_input();- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({input, add_constant});- auto relu = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({add});- auto min_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto min = ov::pass::pattern::wrap_type<ov::op::v1::Minimum>({relu, min_constant});- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul_second = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({min, mul_constant});-- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto add_constant = pattern::wrap_type<v0::Constant>();+ auto add = pattern::wrap_type<v1::Add>({input, add_constant});+ auto relu = pattern::wrap_type<v0::Relu>({add});+ auto min_constant = pattern::wrap_type<v0::Constant>();+ auto min = pattern::wrap_type<v1::Minimum>({relu, min_constant});+ auto mul_constant = pattern::wrap_type<v0::Constant>();+ auto mul_second = pattern::wrap_type<v1::Multiply>({min, mul_constant});++ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto x_output = pattern_to_output.at(input);- auto add_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- auto min_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());- auto mul_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());+ auto add_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ auto min_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());+ auto mul_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());- bool valid_constant_values = ov::op::util::has_constant_value<float>(add_const_value, 3.0f) &&- ov::op::util::has_constant_value<float>(min_const_value, 6.0f) &&- ov::op::util::has_constant_value<float>(mul_const_value, (1.0f / 6.0f), 0.0001f);+ bool valid_constant_values = op_util::has_constant_value<float>(add_const_value, 3.0f) &&+ op_util::has_constant_value<float>(min_const_value, 6.0f) &&+ op_util::has_constant_value<float>(mul_const_value, (1.0f / 6.0f), 0.0001f);if (!valid_constant_values) {return false;}- auto hsigmoid = register_new_node<ov::op::v5::HSigmoid>(x_output);+ auto hsigmoid = register_new_node<v5::HSigmoid>(x_output);hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(),@@ -114,47 +115,43 @@ ov::pass::HSigmoidFusionWithReluMul::HSigmoidFusionWithReluMul() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_second, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(mul_second, matcher_name);register_matcher(m, callback);}-ov::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() {+HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() {MATCHER_SCOPE(HSigmoidFusionWithoutRelu);// Replaces a sub-graph (min(max(x + 3, 0), 6) / 6) with a HSigmoid op.- auto input = pass::pattern::any_input();- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({input, add_constant});- auto max_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto max = ov::pass::pattern::wrap_type<ov::op::v1::Maximum>({add, max_constant});- auto min_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto min = ov::pass::pattern::wrap_type<ov::op::v1::Minimum>({max, min_constant});- auto div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto div = ov::pass::pattern::wrap_type<ov::op::v1::Divide>({min, div_constant});- auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, div});-- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto add_constant = pattern::wrap_type<v0::Constant>();+ auto add = pattern::wrap_type<v1::Add>({input, add_constant});+ auto max_constant = pattern::wrap_type<v0::Constant>();+ auto max = pattern::wrap_type<v1::Maximum>({add, max_constant});+ auto min_constant = pattern::wrap_type<v0::Constant>();+ auto min = pattern::wrap_type<v1::Minimum>({max, min_constant});+ auto div_constant = pattern::wrap_type<v0::Constant>();+ auto div = pattern::wrap_type<v1::Divide>({min, div_constant});+ auto mul = pattern::wrap_type<v1::Multiply>({input, div});++ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto x_output = pattern_to_output.at(input);- auto add_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- auto max_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(max_constant).get_node_shared_ptr());- auto min_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());- auto div_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());+ auto add_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ auto max_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(max_constant).get_node_shared_ptr());+ auto min_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());+ auto div_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());- bool valid_constant_values = ov::op::util::has_constant_value<float>(add_const_value, 3.0f) &&- ov::op::util::has_constant_value<float>(max_const_value, 0.0f) &&- ov::op::util::has_constant_value<float>(min_const_value, 6.0f) &&- ov::op::util::has_constant_value<float>(div_const_value, 6.0f);+ bool valid_constant_values = op_util::has_constant_value<float>(add_const_value, 3.0f) &&+ op_util::has_constant_value<float>(max_const_value, 0.0f) &&+ op_util::has_constant_value<float>(min_const_value, 6.0f) &&+ op_util::has_constant_value<float>(div_const_value, 6.0f);if (!valid_constant_values) {return false;}- auto hsigmoid = register_new_node<ov::op::v5::HSigmoid>(x_output);+ auto hsigmoid = register_new_node<v5::HSigmoid>(x_output);hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(),@@ -166,41 +163,39 @@ ov::pass::HSigmoidFusionWithoutRelu::HSigmoidFusionWithoutRelu() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(div, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(div, matcher_name);register_matcher(m, callback);}-ov::pass::HSigmoidFusionWithClampMul::HSigmoidFusionWithClampMul() {+HSigmoidFusionWithClampMul::HSigmoidFusionWithClampMul() {MATCHER_SCOPE(HSigmoidFusionWithClampMul);// Replaces a sub-graph (Clamp(x + 3, 0, 6) * const(1/6)) with a HSigmoid op.- auto input = pass::pattern::any_input();- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({input, add_constant});- auto clamp = ov::pass::pattern::wrap_type<ov::op::v0::Clamp>({add});- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul_first = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({clamp, mul_constant});-- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto add_constant = pattern::wrap_type<v0::Constant>();+ auto add = pattern::wrap_type<v1::Add>({input, add_constant});+ auto clamp = pattern::wrap_type<v0::Clamp>({add});+ auto mul_constant = pattern::wrap_type<v0::Constant>();+ auto mul_first = pattern::wrap_type<v1::Multiply>({clamp, mul_constant});++ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto x_output = pattern_to_output.at(input);- auto add_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- auto mul_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());+ auto add_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ auto mul_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());- bool valid_constant_values = ov::op::util::has_constant_value(add_const_value, 3.0) &&- ov::op::util::has_constant_value(mul_const_value, (1.0 / 6.0), 0.0001);+ bool valid_constant_values = op_util::has_constant_value(add_const_value, 3.0) &&+ op_util::has_constant_value(mul_const_value, (1.0 / 6.0), 0.0001);if (!valid_constant_values) {return false;}- auto clamp_node = ov::as_type_ptr<ov::op::v0::Clamp>(pattern_to_output.at(clamp).get_node_shared_ptr());+ auto clamp_node = ov::as_type_ptr<v0::Clamp>(pattern_to_output.at(clamp).get_node_shared_ptr());if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6)return false;- auto hsigmoid = register_new_node<ov::op::v5::HSigmoid>(x_output);+ auto hsigmoid = register_new_node<v5::HSigmoid>(x_output);hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(),@@ -211,41 +206,39 @@ ov::pass::HSigmoidFusionWithClampMul::HSigmoidFusionWithClampMul() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_first, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(mul_first, matcher_name);register_matcher(m, callback);}-ov::pass::HSigmoidFusionWithClampDiv::HSigmoidFusionWithClampDiv() {+HSigmoidFusionWithClampDiv::HSigmoidFusionWithClampDiv() {MATCHER_SCOPE(HSigmoidFusionWithClampDiv);// Replaces a sub-graph (Clamp(x + 3, 0, 6) / 6) with a HSigmoid op.- auto input = pass::pattern::any_input();- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({input, add_constant});- auto clamp = ov::pass::pattern::wrap_type<ov::op::v0::Clamp>({add});- auto div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto div = ov::pass::pattern::wrap_type<ov::op::v1::Divide>({clamp, div_constant});-- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto add_constant = pattern::wrap_type<v0::Constant>();+ auto add = pattern::wrap_type<v1::Add>({input, add_constant});+ auto clamp = pattern::wrap_type<v0::Clamp>({add});+ auto div_constant = pattern::wrap_type<v0::Constant>();+ auto div = pattern::wrap_type<v1::Divide>({clamp, div_constant});++ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto x_output = pattern_to_output.at(input);- auto add_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- auto div_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());+ auto add_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ auto div_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());- bool valid_constant_values = ov::op::util::has_constant_value(add_const_value, 3.0) &&- ov::op::util::has_constant_value(div_const_value, 6.0);+ bool valid_constant_values =+ op_util::has_constant_value(add_const_value, 3.0) && op_util::has_constant_value(div_const_value, 6.0);if (!valid_constant_values) {return false;}- auto clamp_node = ov::as_type_ptr<ov::op::v0::Clamp>(pattern_to_output.at(clamp).get_node_shared_ptr());+ auto clamp_node = ov::as_type_ptr<v0::Clamp>(pattern_to_output.at(clamp).get_node_shared_ptr());if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6)return false;- auto hsigmoid = register_new_node<ov::op::v5::HSigmoid>(x_output);+ auto hsigmoid = register_new_node<v5::HSigmoid>(x_output);hsigmoid->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(),@@ -256,6 +249,8 @@ ov::pass::HSigmoidFusionWithClampDiv::HSigmoidFusionWithClampDiv() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(div, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(div, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/hswish_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/hswish_fusion.cppindex d7f12d5bb2f..dc679c66c98 100644--- a/src/common/transformations/src/transformations/common_optimizations/hswish_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/hswish_fusion.cpp@@ -21,39 +21,43 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::HSwishFusionWithReluDiv::HSwishFusionWithReluDiv() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;+namespace op_util = ov::op::util;++namespace ov::pass {++HSwishFusionWithReluDiv::HSwishFusionWithReluDiv() {MATCHER_SCOPE(HSwishFusionWithReluDiv);// Replaces a sub-graph (x * (min(Relu(x + 3), 6)) / 6 with a HSwish op.- auto input = pass::pattern::any_input();- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add = std::make_shared<ov::op::v1::Add>(input, add_constant);- auto relu = std::make_shared<ov::op::v0::Relu>(add);- auto min_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto min = std::make_shared<ov::op::v1::Minimum>(relu, min_constant);- auto mul = std::make_shared<ov::op::v1::Multiply>(input, min);- auto div_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto div = std::make_shared<ov::op::v1::Divide>(mul, div_constant);-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto add_constant = pattern::wrap_type<v0::Constant>();+ auto add = std::make_shared<v1::Add>(input, add_constant);+ auto relu = std::make_shared<v0::Relu>(add);+ auto min_constant = pattern::wrap_type<v0::Constant>();+ auto min = std::make_shared<v1::Minimum>(relu, min_constant);+ auto mul = std::make_shared<v1::Multiply>(input, min);+ auto div_constant = pattern::wrap_type<v0::Constant>();+ auto div = std::make_shared<v1::Divide>(mul, div_constant);++ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto x_output = pattern_to_output.at(input);- auto add_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- auto min_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());- auto div_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());+ auto add_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ auto min_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());+ auto div_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(div_constant).get_node_shared_ptr());- bool valid_constant_values = ov::op::util::has_constant_value<float>(add_const_value, 3.0) &&- ov::op::util::has_constant_value<float>(min_const_value, 6.0) &&- ov::op::util::has_constant_value<float>(div_const_value, 6.0);+ bool valid_constant_values = op_util::has_constant_value<float>(add_const_value, 3.0) &&+ op_util::has_constant_value<float>(min_const_value, 6.0) &&+ op_util::has_constant_value<float>(div_const_value, 6.0);if (!valid_constant_values) {return false;}- auto hswish = std::make_shared<ov::op::v4::HSwish>(x_output);+ auto hswish = std::make_shared<v4::HSwish>(x_output);hswish->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info(@@ -72,43 +76,40 @@ ov::pass::HSwishFusionWithReluDiv::HSwishFusionWithReluDiv() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(div, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(div, matcher_name);register_matcher(m, callback);}-ov::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() {+HSwishFusionWithReluMul::HSwishFusionWithReluMul() {MATCHER_SCOPE(HSwishFusionWithReluMul);// Replaces a sub-graph (x * (min(Relu(x + 3), 6)) * const(1/6) with a HSwish op.- auto input = pass::pattern::any_input();- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add = std::make_shared<ov::op::v1::Add>(input, add_constant);- auto relu = std::make_shared<ov::op::v0::Relu>(add);- auto min_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto min = std::make_shared<ov::op::v1::Minimum>(relu, min_constant);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(input, min);- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul_second = std::make_shared<ov::op::v1::Multiply>(mul_first, mul_constant);-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto add_constant = pattern::wrap_type<v0::Constant>();+ auto add = std::make_shared<v1::Add>(input, add_constant);+ auto relu = std::make_shared<v0::Relu>(add);+ auto min_constant = pattern::wrap_type<v0::Constant>();+ auto min = std::make_shared<v1::Minimum>(relu, min_constant);+ auto mul_first = std::make_shared<v1::Multiply>(input, min);+ auto mul_constant = pattern::wrap_type<v0::Constant>();+ auto mul_second = std::make_shared<v1::Multiply>(mul_first, mul_constant);++ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto x_output = pattern_to_output.at(input);- auto add_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- auto min_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());- auto mul_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());+ auto add_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ auto min_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(min_constant).get_node_shared_ptr());+ auto mul_const_value = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(mul_constant).get_node_shared_ptr());- bool valid_constant_values = ov::op::util::has_constant_value<float>(add_const_value, 3.0f) &&- ov::op::util::has_constant_value<float>(min_const_value, 6.0f) &&- ov::op::util::has_constant_value<float>(mul_const_value, (1.0f / 6.0f), 0.0001f);+ bool valid_constant_values = op_util::has_constant_value<float>(add_const_value, 3.0f) &&+ op_util::has_constant_value<float>(min_const_value, 6.0f) &&+ op_util::has_constant_value<float>(mul_const_value, (1.0f / 6.0f), 0.0001f);if (!valid_constant_values) {return false;}- auto hswish = std::make_shared<ov::op::v4::HSwish>(x_output);+ auto hswish = std::make_shared<v4::HSwish>(x_output);hswish->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({pattern_to_output.at(add_constant).get_node_shared_ptr(),@@ -124,60 +125,59 @@ ov::pass::HSwishFusionWithReluMul::HSwishFusionWithReluMul() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_second, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(mul_second, matcher_name);register_matcher(m, callback);}-ov::pass::HSwishFusionWithHSigmoid::HSwishFusionWithHSigmoid() {+HSwishFusionWithHSigmoid::HSwishFusionWithHSigmoid() {MATCHER_SCOPE(HSwishFusionWithHSigmoid);// Replaces a sub-graph x * HSigmoid(x) with a HSwish op.auto input = pattern::any_input();auto hsigmoid_pattern = pattern::wrap_type<ov::op::v5::HSigmoid>({input}, pattern::consumers_count(1));- auto mul_pattern = pattern::wrap_type<ov::op::v1::Multiply>({input, hsigmoid_pattern});+ auto mul_pattern = pattern::wrap_type<v1::Multiply>({input, hsigmoid_pattern});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto hsigmoid = pattern_to_output.at(hsigmoid_pattern).get_node_shared_ptr();auto mul = pattern_to_output.at(mul_pattern).get_node_shared_ptr();- auto hswish = std::make_shared<ov::op::v4::HSwish>(pattern_to_output.at(input));+ auto hswish = std::make_shared<v4::HSwish>(pattern_to_output.at(input));hswish->set_friendly_name(mul->get_friendly_name());ov::copy_runtime_info({hsigmoid, mul}, hswish);ov::replace_node(mul, hswish);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(mul_pattern, matcher_name);register_matcher(m, callback);}-ov::pass::HSwishFusionWithClamp::HSwishFusionWithClamp() {+HSwishFusionWithClamp::HSwishFusionWithClamp() {MATCHER_SCOPE(HSwishFusionWithClampMul);// Replaces a sub-graph (Clamp(x + 3, 0, 6) * x) with a HSwish * 6.- const auto input = pass::pattern::any_input();- const auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- const auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({input, add_constant});- const auto clamp = ov::pass::pattern::wrap_type<ov::op::v0::Clamp>({add});- const auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({clamp, input});+ const auto input = pattern::any_input();+ const auto add_constant = pattern::wrap_type<v0::Constant>();+ const auto add = pattern::wrap_type<v1::Add>({input, add_constant});+ const auto clamp = pattern::wrap_type<v0::Clamp>({add});+ const auto mul = pattern::wrap_type<v1::Multiply>({clamp, input});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();const auto x_output = pattern_to_output.at(input);const auto add_const_value =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- if (!ov::op::util::has_constant_value(add_const_value, 3.0)) {+ ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ if (!op_util::has_constant_value(add_const_value, 3.0)) {return false;}- const auto clamp_node = ov::as_type_ptr<ov::op::v0::Clamp>(pattern_to_output.at(clamp).get_node_shared_ptr());+ const auto clamp_node = ov::as_type_ptr<v0::Clamp>(pattern_to_output.at(clamp).get_node_shared_ptr());if (!clamp_node || clamp_node->get_min() != 0 || clamp_node->get_max() != 6)return false;- auto hswish = std::make_shared<ov::op::v4::HSwish>(x_output);- auto new_mul_const = std::make_shared<ov::op::v0::Constant>(add_const_value->get_element_type(),- Shape{},- std::vector<float>{6.0});- auto new_mul = std::make_shared<ov::op::v1::Multiply>(hswish, new_mul_const);+ auto hswish = std::make_shared<v4::HSwish>(x_output);+ auto new_mul_const =+ std::make_shared<v0::Constant>(add_const_value->get_element_type(), Shape{}, std::vector<float>{6.0});+ auto new_mul = std::make_shared<v1::Multiply>(hswish, new_mul_const);new_mul->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({pattern_to_output.at(add).get_node_shared_ptr(),@@ -188,6 +188,8 @@ ov::pass::HSwishFusionWithClamp::HSwishFusionWithClamp() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(mul, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/interpolate_sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/interpolate_sequence_fusion.cppindex d91fb351c58..bf1447570ef 100644--- a/src/common/transformations/src/transformations/common_optimizations/interpolate_sequence_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/interpolate_sequence_fusion.cpp@@ -25,6 +25,14 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v8 = ov::op::v8;++namespace ov::pass {+namespace {using namespace ov;@@ -37,22 +45,22 @@ bool compatible_axes(const std::vector<int64_t>& fst_axes_vector, const std::vecreturn true;}-bool shape_calculation_mode_can_use_constant_inputs(const std::shared_ptr<ov::op::v4::Interpolate>& interpolate) {+bool shape_calculation_mode_can_use_constant_inputs(const std::shared_ptr<v4::Interpolate>& interpolate) {const auto& attrs = interpolate->get_attrs();- if (attrs.shape_calculation_mode == ov::op::v4::Interpolate::ShapeCalcMode::SIZES) {- return ov::as_type_ptr<ov::op::v0::Constant>(interpolate->input_value(1).get_node_shared_ptr()) != nullptr;+ if (attrs.shape_calculation_mode == v4::Interpolate::ShapeCalcMode::SIZES) {+ return ov::as_type_ptr<v0::Constant>(interpolate->input_value(1).get_node_shared_ptr()) != nullptr;}- return ov::as_type_ptr<ov::op::v0::Constant>(interpolate->input_value(2).get_node_shared_ptr()) != nullptr;+ return ov::as_type_ptr<v0::Constant>(interpolate->input_value(2).get_node_shared_ptr()) != nullptr;}-bool is_candidate_for_fusion(const std::shared_ptr<ov::op::v4::Interpolate>& interpolate) {+bool is_candidate_for_fusion(const std::shared_ptr<v4::Interpolate>& interpolate) {return (interpolate->get_input_partial_shape(0).rank().is_static()) &&(interpolate->inputs().size() != 4 ||- ov::as_type_ptr<ov::op::v0::Constant>(interpolate->input_value(3).get_node_shared_ptr())) &&+ ov::as_type_ptr<v0::Constant>(interpolate->input_value(3).get_node_shared_ptr())) &&shape_calculation_mode_can_use_constant_inputs(interpolate);}-std::vector<int64_t> get_interpolated_axes(const std::shared_ptr<ov::op::v4::Interpolate>& interpolate) {+std::vector<int64_t> get_interpolated_axes(const std::shared_ptr<v4::Interpolate>& interpolate) {if (interpolate->inputs().size() != 4) {const auto input_rank = interpolate->get_input_partial_shape(0).rank().get_length();@@ -61,12 +69,10 @@ std::vector<int64_t> get_interpolated_axes(const std::shared_ptr<ov::op::v4::Intreturn default_value;}- return ov::as_type_ptr<ov::op::v0::Constant>(interpolate->input_value(3).get_node_shared_ptr())- ->cast_vector<int64_t>();+ return ov::as_type_ptr<v0::Constant>(interpolate->input_value(3).get_node_shared_ptr())->cast_vector<int64_t>();}-bool can_be_fused(const std::shared_ptr<ov::op::v4::Interpolate>& fst,- const std::shared_ptr<ov::op::v4::Interpolate>& snd) {+bool can_be_fused(const std::shared_ptr<v4::Interpolate>& fst, const std::shared_ptr<v4::Interpolate>& snd) {// The first Interpolate (fst) must have only one consumer.for (const auto& output : fst->outputs()) {for (const auto& consumer : output.get_target_inputs()) {@@ -83,13 +89,13 @@ bool can_be_fused(const std::shared_ptr<ov::op::v4::Interpolate>& fst,return compatible_axes(fst_axes, snd_axes);}-ov::NodeVector subgraph_for_sizes_calculation_mode(const std::shared_ptr<ov::op::v4::Interpolate>& fst,- const std::shared_ptr<ov::op::v4::Interpolate>& snd,- pass::MatcherPass* matcherPass) {+ov::NodeVector subgraph_for_sizes_calculation_mode(const std::shared_ptr<v4::Interpolate>& fst,+ const std::shared_ptr<v4::Interpolate>& snd,+ MatcherPass* matcherPass) {const auto fst_axes = get_interpolated_axes(fst);const auto snd_axes = get_interpolated_axes(snd);- const auto fst_sizes_node = ov::as_type_ptr<ov::op::v0::Constant>(fst->input_value(1).get_node_shared_ptr());- const auto snd_sizes_node = ov::as_type_ptr<ov::op::v0::Constant>(snd->input_value(1).get_node_shared_ptr());+ const auto fst_sizes_node = ov::as_type_ptr<v0::Constant>(fst->input_value(1).get_node_shared_ptr());+ const auto snd_sizes_node = ov::as_type_ptr<v0::Constant>(snd->input_value(1).get_node_shared_ptr());if (!fst_sizes_node || !snd_sizes_node)return {};@@ -114,18 +120,18 @@ ov::NodeVector subgraph_for_sizes_calculation_mode(const std::shared_ptr<ov::op:new_sizes.emplace_back(as.second);}- auto new_sizes_node = ov::op::v0::Constant::create(element::i64, {new_sizes.size()}, new_sizes);- auto new_axes_node = ov::op::v0::Constant::create(element::i64, {new_axes.size()}, new_axes);- auto new_sizes_cast = std::make_shared<ov::op::v0::Convert>(new_sizes_node, element::f32);- auto shape_node = std::make_shared<ov::op::v3::ShapeOf>(fst->input_value(0));+ auto new_sizes_node = v0::Constant::create(element::i64, {new_sizes.size()}, new_sizes);+ auto new_axes_node = v0::Constant::create(element::i64, {new_axes.size()}, new_axes);+ auto new_sizes_cast = std::make_shared<v0::Convert>(new_sizes_node, element::f32);+ auto shape_node = std::make_shared<v3::ShapeOf>(fst->input_value(0));- auto gather_axis_node = ov::op::v0::Constant::create(element::i64, {1}, std::vector<int64_t>{0});- auto gather_node = std::make_shared<ov::op::v8::Gather>(shape_node, new_axes_node, gather_axis_node);- auto cast_shape_to_float = std::make_shared<ov::op::v0::Convert>(gather_node, element::f32);+ auto gather_axis_node = v0::Constant::create(element::i64, {1}, std::vector<int64_t>{0});+ auto gather_node = std::make_shared<v8::Gather>(shape_node, new_axes_node, gather_axis_node);+ auto cast_shape_to_float = std::make_shared<v0::Convert>(gather_node, element::f32);- auto div_node = std::make_shared<ov::op::v1::Divide>(new_sizes_cast, cast_shape_to_float);+ auto div_node = std::make_shared<v1::Divide>(new_sizes_cast, cast_shape_to_float);- const auto new_interpolate = ov::as_type_ptr<ov::op::v4::Interpolate>(+ const auto new_interpolate = ov::as_type_ptr<v4::Interpolate>(fst->clone_with_new_inputs({fst->input_value(0), new_sizes_node, div_node, new_axes_node}));matcherPass->register_new_node(new_interpolate);@@ -140,13 +146,13 @@ ov::NodeVector subgraph_for_sizes_calculation_mode(const std::shared_ptr<ov::op:new_interpolate};}-ov::NodeVector subgraph_for_scales_calculation_mode(const std::shared_ptr<ov::op::v4::Interpolate>& fst,- const std::shared_ptr<ov::op::v4::Interpolate>& snd,- pass::MatcherPass* matcherPass) {+ov::NodeVector subgraph_for_scales_calculation_mode(const std::shared_ptr<v4::Interpolate>& fst,+ const std::shared_ptr<v4::Interpolate>& snd,+ MatcherPass* matcherPass) {const auto fst_axes = get_interpolated_axes(fst);const auto snd_axes = get_interpolated_axes(snd);- const auto fst_scales_node = ov::as_type_ptr<ov::op::v0::Constant>(fst->input_value(2).get_node_shared_ptr());- const auto snd_scales_node = ov::as_type_ptr<ov::op::v0::Constant>(snd->input_value(2).get_node_shared_ptr());+ const auto fst_scales_node = ov::as_type_ptr<v0::Constant>(fst->input_value(2).get_node_shared_ptr());+ const auto snd_scales_node = ov::as_type_ptr<v0::Constant>(snd->input_value(2).get_node_shared_ptr());if (!fst_scales_node || !snd_scales_node)return {};@@ -171,21 +177,21 @@ ov::NodeVector subgraph_for_scales_calculation_mode(const std::shared_ptr<ov::opnew_scales.emplace_back(as.second);}- auto new_scales_node = ov::op::v0::Constant::create(element::f32, {new_scales.size()}, new_scales);- auto new_axes_node = ov::op::v0::Constant::create(element::i64, {new_axes.size()}, new_axes);- auto shape_node = std::make_shared<ov::op::v3::ShapeOf>(fst->input_value(0));+ auto new_scales_node = v0::Constant::create(element::f32, {new_scales.size()}, new_scales);+ auto new_axes_node = v0::Constant::create(element::i64, {new_axes.size()}, new_axes);+ auto shape_node = std::make_shared<v3::ShapeOf>(fst->input_value(0));- auto gather_axis_node = ov::op::v0::Constant::create(element::i64, {1}, std::vector<int64_t>{0});- auto gather_node = std::make_shared<ov::op::v8::Gather>(shape_node, new_axes_node, gather_axis_node);- auto cast_shape_to_float = std::make_shared<ov::op::v0::Convert>(gather_node, element::f32);+ auto gather_axis_node = v0::Constant::create(element::i64, {1}, std::vector<int64_t>{0});+ auto gather_node = std::make_shared<v8::Gather>(shape_node, new_axes_node, gather_axis_node);+ auto cast_shape_to_float = std::make_shared<v0::Convert>(gather_node, element::f32);- auto mul_node = std::make_shared<ov::op::v1::Multiply>(cast_shape_to_float, new_scales_node);- auto eps_node = ov::op::v0::Constant::create(element::f32, {}, std::vector<float>{1.0e-5f});- auto add_node = std::make_shared<ov::op::v1::Multiply>(mul_node, eps_node);- auto floor_node = std::make_shared<ov::op::v0::Floor>(add_node);- auto cast_mul_result_to_int = std::make_shared<ov::op::v0::Convert>(floor_node, element::i64);+ auto mul_node = std::make_shared<v1::Multiply>(cast_shape_to_float, new_scales_node);+ auto eps_node = v0::Constant::create(element::f32, {}, std::vector<float>{1.0e-5f});+ auto add_node = std::make_shared<v1::Multiply>(mul_node, eps_node);+ auto floor_node = std::make_shared<v0::Floor>(add_node);+ auto cast_mul_result_to_int = std::make_shared<v0::Convert>(floor_node, element::i64);- const auto new_interpolate = ov::as_type_ptr<ov::op::v4::Interpolate>(+ const auto new_interpolate = ov::as_type_ptr<v4::Interpolate>(fst->clone_with_new_inputs({fst->input_value(0), cast_mul_result_to_int, new_scales_node, new_axes_node}));matcherPass->register_new_node(new_interpolate);@@ -204,16 +210,15 @@ ov::NodeVector subgraph_for_scales_calculation_mode(const std::shared_ptr<ov::op}} // namespace-ov::pass::InterpolateSequenceFusion::InterpolateSequenceFusion() {+InterpolateSequenceFusion::InterpolateSequenceFusion() {MATCHER_SCOPE(InterpolateSequenceFusion);- auto interpolate_pattern = ov::pass::pattern::wrap_type<ov::op::v4::Interpolate>();- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {- auto snd_interpolate = ov::as_type_ptr<ov::op::v4::Interpolate>(m.get_match_root());+ auto interpolate_pattern = pattern::wrap_type<v4::Interpolate>();+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ auto snd_interpolate = ov::as_type_ptr<v4::Interpolate>(m.get_match_root());if (!snd_interpolate)return false;- auto fst_interpolate =- ov::as_type_ptr<ov::op::v4::Interpolate>(snd_interpolate->input_value(0).get_node_shared_ptr());+ auto fst_interpolate = ov::as_type_ptr<v4::Interpolate>(snd_interpolate->input_value(0).get_node_shared_ptr());if (!fst_interpolate)return false;@@ -221,7 +226,7 @@ ov::pass::InterpolateSequenceFusion::InterpolateSequenceFusion() {return false;NodeVector new_subgraph;- if (fst_interpolate->get_attrs().shape_calculation_mode == ov::op::v4::Interpolate::ShapeCalcMode::SIZES) {+ if (fst_interpolate->get_attrs().shape_calculation_mode == v4::Interpolate::ShapeCalcMode::SIZES) {new_subgraph = subgraph_for_sizes_calculation_mode(fst_interpolate, snd_interpolate, this);} else {new_subgraph = subgraph_for_scales_calculation_mode(fst_interpolate, snd_interpolate, this);@@ -237,6 +242,8 @@ ov::pass::InterpolateSequenceFusion::InterpolateSequenceFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(interpolate_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(interpolate_pattern, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cppindex 3261216cfcf..6010511a715 100644--- a/src/common/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/leaky_relu_fusion.cpp@@ -16,13 +16,18 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::LeakyReluFusion::LeakyReluFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++LeakyReluFusion::LeakyReluFusion() {MATCHER_SCOPE(LeakyReluFusion);- auto data_pattern = pass::pattern::any_input();- auto alpha_pattern = pass::pattern::wrap_type<ov::op::v0::Constant>();+ auto data_pattern = pattern::any_input();+ auto alpha_pattern = pattern::wrap_type<v0::Constant>();auto multiply_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({data_pattern, alpha_pattern}, pattern::consumers_count(1));- auto max_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Maximum>({data_pattern, multiply_pattern});+ pattern::wrap_type<v1::Multiply>({data_pattern, alpha_pattern}, pattern::consumers_count(1));+ auto max_pattern = pattern::wrap_type<v1::Maximum>({data_pattern, multiply_pattern});ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -31,7 +36,7 @@ ov::pass::LeakyReluFusion::LeakyReluFusion() {if (shape_size(original_alpha_pattern.get_shape()) != 1)return false;- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(original_alpha_pattern.get_node_shared_ptr());+ auto constant = ov::as_type_ptr<v0::Constant>(original_alpha_pattern.get_node_shared_ptr());if (!constant)return false;@@ -42,7 +47,7 @@ ov::pass::LeakyReluFusion::LeakyReluFusion() {if (value > 1.0f)return false;- auto leaky_relu = register_new_node<ov::op::v0::PRelu>(pattern_map.at(data_pattern), original_alpha_pattern);+ auto leaky_relu = register_new_node<v0::PRelu>(pattern_map.at(data_pattern), original_alpha_pattern);auto maximum = pattern_map.at(max_pattern);leaky_relu->set_friendly_name(maximum.get_node()->get_friendly_name());@@ -53,6 +58,8 @@ ov::pass::LeakyReluFusion::LeakyReluFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(max_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(max_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/lin_op_sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/lin_op_sequence_fusion.cppindex 73544ca7b34..1b2331aee81 100644--- a/src/common/transformations/src/transformations/common_optimizations/lin_op_sequence_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/lin_op_sequence_fusion.cpp@@ -18,23 +18,29 @@using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {+namespace {const auto is_eltwise_supported_type = [](const Output<Node>& output) -> bool {- const auto is_single_output = pass::pattern::consumers_count(1);+ const auto is_single_output = pattern::consumers_count(1);return is_single_output(output) && output.get_node()->has_evaluate();};} // namespace-ov::pass::AddMultiplyFusion::AddMultiplyFusion() {+AddMultiplyFusion::AddMultiplyFusion() {MATCHER_SCOPE(AddMultiplyFusion);// Create Add->Multiply pattern where Add has exactly one consumer- auto m_data = pass::pattern::any_input();- auto m_add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto m_add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({m_data, m_add_constant}, pattern::consumers_count(1));- auto m_mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto m_mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({m_add, m_mul_constant});+ auto m_data = pattern::any_input();+ auto m_add_constant = pattern::wrap_type<v0::Constant>();+ auto m_add = pattern::wrap_type<v1::Add>({m_data, m_add_constant}, pattern::consumers_count(1));+ auto m_mul_constant = pattern::wrap_type<v0::Constant>();+ auto m_mul = pattern::wrap_type<v1::Multiply>({m_add, m_mul_constant});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) -> bool {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) -> bool {auto& label_to_output = m.get_pattern_value_map();auto mul = label_to_output[m_mul].get_node_shared_ptr();@@ -56,11 +62,11 @@ ov::pass::AddMultiplyFusion::AddMultiplyFusion() {// Replace Add->Multiply with Multiply->Add// As new Multiply can be fused with operation above it we add this Multiply// to the list of operations that will be used in additional matching.- auto new_mul = register_new_node<ov::op::v1::Multiply>(input, mul_const);+ auto new_mul = register_new_node<v1::Multiply>(input, mul_const);// Add two constants using opset3::Add constant folding and create new Add operation- auto new_const = ov::op::util::make_try_fold<ov::op::v1::Multiply>(add_const, mul_const);- auto new_add = std::make_shared<ov::op::v1::Add>(new_mul, new_const);+ auto new_const = op_util::make_try_fold<v1::Multiply>(add_const, mul_const);+ auto new_add = std::make_shared<v1::Add>(new_mul, new_const);copy_runtime_info({add, mul}, {new_mul, new_add, new_const});new_add->set_friendly_name(mul->get_friendly_name());@@ -68,20 +74,20 @@ ov::pass::AddMultiplyFusion::AddMultiplyFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(m_mul, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(m_mul, matcher_name);this->register_matcher(m, callback);}-ov::pass::AddAddFusion::AddAddFusion() {+AddAddFusion::AddAddFusion() {MATCHER_SCOPE(AddAddFusion);// Create Add->Add pattern where first Add has exactly one consumer- auto m_data = pass::pattern::any_input();- auto m_add1_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto m_add1 = ov::pass::pattern::wrap_type<ov::op::v1::Add>({m_data, m_add1_constant}, pattern::consumers_count(1));- auto m_add2_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto m_add2 = ov::pass::pattern::wrap_type<ov::op::v1::Add>({m_add1, m_add2_constant});+ auto m_data = pattern::any_input();+ auto m_add1_constant = pattern::wrap_type<v0::Constant>();+ auto m_add1 = pattern::wrap_type<v1::Add>({m_data, m_add1_constant}, pattern::consumers_count(1));+ auto m_add2_constant = pattern::wrap_type<v0::Constant>();+ auto m_add2 = pattern::wrap_type<v1::Add>({m_add1, m_add2_constant});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) -> bool {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) -> bool {auto& label_to_output = m.get_pattern_value_map();auto add1 = label_to_output[m_add1].get_node_shared_ptr();@@ -93,8 +99,8 @@ ov::pass::AddAddFusion::AddAddFusion() {// Replace Add->Add with single Add// Add operation will be added to the list of ops requested for pattern matching- auto new_const = ov::op::util::make_try_fold<ov::op::v1::Add>(add1_const, add2_const);- auto new_add = register_new_node<ov::op::v1::Add>(input, new_const);+ auto new_const = op_util::make_try_fold<v1::Add>(add1_const, add2_const);+ auto new_add = register_new_node<v1::Add>(input, new_const);copy_runtime_info({add1, add2}, {new_add, new_const});new_add->set_friendly_name(add2->get_friendly_name());@@ -102,21 +108,20 @@ ov::pass::AddAddFusion::AddAddFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(m_add2, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(m_add2, matcher_name);this->register_matcher(m, callback);}-ov::pass::MultiplyMultiplyFusion::MultiplyMultiplyFusion() {+MultiplyMultiplyFusion::MultiplyMultiplyFusion() {MATCHER_SCOPE(MultiplyMultiplyFusion);// Create Multiply->Multiply pattern where first Multiply has exactly one consumer- auto m_data = pass::pattern::any_input();- auto m_mul1_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto m_mul1 =- ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({m_data, m_mul1_constant}, is_eltwise_supported_type);- auto m_mul2_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto m_mul2 = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({m_mul1, m_mul2_constant});-- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) -> bool {+ auto m_data = pattern::any_input();+ auto m_mul1_constant = pattern::wrap_type<v0::Constant>();+ auto m_mul1 = pattern::wrap_type<v1::Multiply>({m_data, m_mul1_constant}, is_eltwise_supported_type);+ auto m_mul2_constant = pattern::wrap_type<v0::Constant>();+ auto m_mul2 = pattern::wrap_type<v1::Multiply>({m_mul1, m_mul2_constant});++ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) -> bool {auto& label_to_output = m.get_pattern_value_map();auto mul1 = label_to_output[m_mul1].get_node_shared_ptr();@@ -128,8 +133,8 @@ ov::pass::MultiplyMultiplyFusion::MultiplyMultiplyFusion() {// Replace Multiply->Multiply with single Multiply// Multiply operation will be added to the list of ops requested for pattern matching- auto new_const = ov::op::util::make_try_fold<ov::op::v1::Multiply>(mul1_const, mul2_const);- auto new_mul = register_new_node<ov::op::v1::Multiply>(input, new_const);+ auto new_const = op_util::make_try_fold<v1::Multiply>(mul1_const, mul2_const);+ auto new_mul = register_new_node<v1::Multiply>(input, new_const);copy_runtime_info({mul1, mul2}, {new_mul, new_const});new_mul->set_friendly_name(mul2->get_friendly_name());@@ -137,6 +142,8 @@ ov::pass::MultiplyMultiplyFusion::MultiplyMultiplyFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(m_mul2, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(m_mul2, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/lora_subgraph_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/lora_subgraph_fusion.cppindex 596ae95d7a8..4a473c6ee69 100644--- a/src/common/transformations/src/transformations/common_optimizations/lora_subgraph_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/lora_subgraph_fusion.cpp@@ -21,31 +21,37 @@#include "ov_ops/lora_subgraph.hpp"#include "transformations/utils/utils.hpp"-ov::pass::LoraSubgraphFusion::LoraSubgraphFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {++LoraSubgraphFusion::LoraSubgraphFusion() {MATCHER_SCOPE(LoraSubgraphFusion);- using namespace pass::pattern;- auto lora_input_m = any_input();- auto transpose_const1_m = wrap_type<ov::op::v0::Constant>(consumers_count(1));- auto transpose1_m = optional<ov::op::v1::Transpose>({lora_input_m, transpose_const1_m}, consumers_count(1));+ auto lora_input_m = pattern::any_input();+ auto transpose_const1_m = pattern::wrap_type<v0::Constant>(pattern::consumers_count(1));+ auto transpose1_m =+ pattern::optional<v1::Transpose>({lora_input_m, transpose_const1_m}, pattern::consumers_count(1));- auto read_value1_m = wrap_type<ov::op::util::ReadValueBase>();- auto convert1_m = optional<ov::op::v0::Convert>(read_value1_m, consumers_count(1));- auto matmul1_m = wrap_type<ov::op::v0::MatMul>({transpose1_m, convert1_m}, consumers_count(1));+ auto read_value1_m = pattern::wrap_type<op_util::ReadValueBase>();+ auto convert1_m = pattern::optional<v0::Convert>(read_value1_m, pattern::consumers_count(1));+ auto matmul1_m = pattern::wrap_type<v0::MatMul>({transpose1_m, convert1_m}, pattern::consumers_count(1));- auto read_value2_m = wrap_type<ov::op::util::ReadValueBase>();- auto convert2_m = optional<ov::op::v0::Convert>(read_value2_m, consumers_count(1));- auto multiply_m = wrap_type<ov::op::v1::Multiply>({matmul1_m, convert2_m}, consumers_count(1));+ auto read_value2_m = pattern::wrap_type<op_util::ReadValueBase>();+ auto convert2_m = pattern::optional<v0::Convert>(read_value2_m, pattern::consumers_count(1));+ auto multiply_m = pattern::wrap_type<v1::Multiply>({matmul1_m, convert2_m}, pattern::consumers_count(1));- auto read_value3_m = wrap_type<ov::op::util::ReadValueBase>();- auto convert3_m = optional<ov::op::v0::Convert>(read_value3_m, consumers_count(1));- auto matmul2_m = wrap_type<ov::op::v0::MatMul>({multiply_m, convert3_m}, consumers_count(1));+ auto read_value3_m = pattern::wrap_type<op_util::ReadValueBase>();+ auto convert3_m = pattern::optional<v0::Convert>(read_value3_m, pattern::consumers_count(1));+ auto matmul2_m = pattern::wrap_type<v0::MatMul>({multiply_m, convert3_m}, pattern::consumers_count(1));- auto transpose_const2_m = wrap_type<ov::op::v0::Constant>(consumers_count(1));- auto transpose2_m = optional<ov::op::v1::Transpose>({matmul2_m, transpose_const2_m}, consumers_count(1));- auto main_flow_m = wrap_type<ov::op::v0::MatMul, ov::op::v1::Convolution>({lora_input_m, any_input()});- auto add_m = wrap_type<ov::op::v1::Add>({transpose2_m, main_flow_m});+ auto transpose_const2_m = pattern::wrap_type<v0::Constant>(pattern::consumers_count(1));+ auto transpose2_m = pattern::optional<v1::Transpose>({matmul2_m, transpose_const2_m}, pattern::consumers_count(1));+ auto main_flow_m = pattern::wrap_type<v0::MatMul, v1::Convolution>({lora_input_m, pattern::any_input()});+ auto add_m = pattern::wrap_type<v1::Add>({transpose2_m, main_flow_m});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& lora_input = pattern_map.at(lora_input_m);const auto& matmul1 = pattern_map.at(matmul1_m);@@ -95,7 +101,7 @@ ov::pass::LoraSubgraphFusion::LoraSubgraphFusion() {ov::ParameterVector subgraph_parameters;subgraph_parameters.reserve(internal_inputs.size());for (auto& in : internal_inputs) {- auto new_parameter = std::make_shared<ov::op::v0::Parameter>(in.get_element_type(), in.get_partial_shape());+ auto new_parameter = std::make_shared<v0::Parameter>(in.get_element_type(), in.get_partial_shape());subgraph_parameters.push_back(new_parameter);in.replace_source_output(new_parameter);}@@ -114,6 +120,8 @@ ov::pass::LoraSubgraphFusion::LoraSubgraphFusion() {return true;};- auto m = std::make_shared<Matcher>(add_m, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(add_m, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/lstm_cell_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/lstm_cell_fusion.cppindex a8bcbbdd389..6a4a105ead0 100644--- a/src/common/transformations/src/transformations/common_optimizations/lstm_cell_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/lstm_cell_fusion.cpp@@ -26,6 +26,15 @@using namespace ov;using namespace ov::pass;+using ov::pass::pattern::any_input;+using ov::pass::pattern::has_static_shape;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::rank_equals;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;namespace {static std::string get_activation_name(const std::shared_ptr<ov::Node>& node) {std::string name = node->get_type_name();@@ -41,21 +50,21 @@ void generate_gate_pattern(const std::shared_ptr<ov::Node>& x,std::shared_ptr<ov::Node>& bi,std::shared_ptr<ov::Node>& x_by_wi,std::shared_ptr<ov::Node>& h_by_ri) {- wi = pattern::any_input([](const Output<Node>& output) {- return pattern::has_static_shape()(output) && pattern::rank_equals(2)(output);+ wi = any_input([](const Output<Node>& output) {+ return has_static_shape()(output) && rank_equals(2)(output);});- ri = pattern::any_input([](const Output<Node>& output) {- return pattern::has_static_shape()(output) && pattern::rank_equals(2)(output);+ ri = any_input([](const Output<Node>& output) {+ return has_static_shape()(output) && rank_equals(2)(output);});- bi = pattern::any_input([](const Output<Node>& output) {- return pattern::has_static_shape()(output) && pattern::rank_equals(1)(output);+ bi = any_input([](const Output<Node>& output) {+ return has_static_shape()(output) && rank_equals(1)(output);});- x_by_wi = pattern::wrap_type<ov::op::v0::MatMul>({x, wi});- auto x_by_wi_biased = pattern::wrap_type<ov::op::v1::Add>({x_by_wi, bi});- h_by_ri = pattern::wrap_type<ov::op::v0::MatMul>({h, ri});- it = pattern::wrap_type<ov::op::v1::Add>({x_by_wi_biased, h_by_ri});- it = pattern::wrap_type<ov::op::v0::Relu, ov::op::v0::Sigmoid, ov::op::v0::Tanh>({it});+ x_by_wi = wrap_type<v0::MatMul>({x, wi});+ auto x_by_wi_biased = wrap_type<v1::Add>({x_by_wi, bi});+ h_by_ri = wrap_type<v0::MatMul>({h, ri});+ it = wrap_type<v1::Add>({x_by_wi_biased, h_by_ri});+ it = wrap_type<v0::Relu, v0::Sigmoid, v0::Tanh>({it});}bool check_weights_format(const ov::Output<ov::Node>& w,@@ -82,7 +91,7 @@ bool check_weights_format(const ov::Output<ov::Node>& w,}// check transpose attributes for MatMul operations- if (const auto& matmul = ov::as_type_ptr<ov::op::v0::MatMul>(pattern_map.at(x_by_w_label).get_node_shared_ptr())) {+ if (const auto& matmul = ov::as_type_ptr<v0::MatMul>(pattern_map.at(x_by_w_label).get_node_shared_ptr())) {if (matmul->get_transpose_a() || matmul->get_transpose_b()) {return false;}@@ -90,7 +99,7 @@ bool check_weights_format(const ov::Output<ov::Node>& w,return false;}- if (const auto& matmul = ov::as_type_ptr<ov::op::v0::MatMul>(pattern_map.at(h_by_r_label).get_node_shared_ptr())) {+ if (const auto& matmul = ov::as_type_ptr<v0::MatMul>(pattern_map.at(h_by_r_label).get_node_shared_ptr())) {if (matmul->get_transpose_a() || matmul->get_transpose_b()) {return false;}@@ -109,13 +118,13 @@ ov::Output<ov::Node> prepare_weight_fico(const ov::Output<ov::Node>& f,// at this point input weights are of shape [input_size, hidden_size]// before concatenation it needs to transpose them// to get a shape equal to [hidden_size, input_size]- auto transpose_order = rg.make<ov::op::v0::Constant>(element::i32, ov::Shape{2}, std::vector<int32_t>{1, 0});- auto f_tr = rg.make<ov::op::v1::Transpose>(f, transpose_order);- auto i_tr = rg.make<ov::op::v1::Transpose>(i, transpose_order);- auto c_tr = rg.make<ov::op::v1::Transpose>(c, transpose_order);- auto o_tr = rg.make<ov::op::v1::Transpose>(o, transpose_order);+ auto transpose_order = rg.make<v0::Constant>(element::i32, ov::Shape{2}, std::vector<int32_t>{1, 0});+ auto f_tr = rg.make<v1::Transpose>(f, transpose_order);+ auto i_tr = rg.make<v1::Transpose>(i, transpose_order);+ auto c_tr = rg.make<v1::Transpose>(c, transpose_order);+ auto o_tr = rg.make<v1::Transpose>(o, transpose_order);- ov::Output<ov::Node> w = rg.make<ov::op::v0::Concat>(ov::OutputVector{f_tr, i_tr, c_tr, o_tr}, 0);+ ov::Output<ov::Node> w = rg.make<v0::Concat>(ov::OutputVector{f_tr, i_tr, c_tr, o_tr}, 0);if (const auto& constant = ov::util::constantfold_subgraph(w)) {w = constant;}@@ -211,31 +220,31 @@ ov::Output<ov::Node> prepare_weight_fico(const ov::Output<ov::Node>& f,ov::pass::LSTMCellFusionWithJointWeights::LSTMCellFusionWithJointWeights() {MATCHER_SCOPE(LSTMCellFusionWithJointWeights);- auto x_label = pattern::any_input(pattern::rank_equals(2));- auto h_label = pattern::any_input(pattern::rank_equals(2));- auto concat_label = pattern::wrap_type<ov::op::v0::Concat>({x_label, h_label});- auto weights_label = pattern::any_input([](const Output<Node>& output) {- return pattern::has_static_shape()(output) && pattern::rank_equals(2)(output);+ auto x_label = any_input(rank_equals(2));+ auto h_label = any_input(rank_equals(2));+ auto concat_label = wrap_type<v0::Concat>({x_label, h_label});+ auto weights_label = any_input([](const Output<Node>& output) {+ return has_static_shape()(output) && rank_equals(2)(output);});- auto matmul_label = pattern::wrap_type<ov::op::v0::MatMul>({concat_label, weights_label});- auto bias_label = pattern::any_input(pattern::has_static_shape());- auto bias_add_label = pattern::wrap_type<ov::op::v1::Add>({matmul_label, bias_label});- auto axis_label = pattern::wrap_type<ov::op::v0::Constant>();- auto split_label = pattern::wrap_type<ov::op::v1::Split>({bias_add_label, axis_label});- auto it_label = pattern::wrap_type<ov::op::v0::Relu, ov::op::v0::Sigmoid, ov::op::v0::Tanh>({split_label});- auto ct_label = pattern::wrap_type<ov::op::v0::Relu, ov::op::v0::Sigmoid, ov::op::v0::Tanh>({split_label});- auto ft_additional_bias_label = pattern::wrap_type<ov::op::v0::Constant>();- auto add_label = pattern::wrap_type<ov::op::v1::Add>({split_label, ft_additional_bias_label});- auto ft_label = pattern::wrap_type<ov::op::v0::Relu, ov::op::v0::Sigmoid, ov::op::v0::Tanh>({add_label});- auto ot_label = pattern::wrap_type<ov::op::v0::Relu, ov::op::v0::Sigmoid, ov::op::v0::Tanh>({split_label});- auto mul_label = pattern::wrap_type<ov::op::v1::Multiply>({it_label, ct_label});- auto c_label = pattern::any_input();- auto mul1_label = pattern::wrap_type<ov::op::v1::Multiply>({ft_label, c_label});- auto Co_label = pattern::wrap_type<ov::op::v1::Add>({mul_label, mul1_label});- auto Co_activation_label = pattern::wrap_type<ov::op::v0::Relu, ov::op::v0::Sigmoid, ov::op::v0::Tanh>({Co_label});- auto Ho_label = pattern::wrap_type<ov::op::v1::Multiply>({Co_activation_label, ot_label});-- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ auto matmul_label = wrap_type<v0::MatMul>({concat_label, weights_label});+ auto bias_label = any_input(has_static_shape());+ auto bias_add_label = wrap_type<v1::Add>({matmul_label, bias_label});+ auto axis_label = wrap_type<v0::Constant>();+ auto split_label = wrap_type<v1::Split>({bias_add_label, axis_label});+ auto it_label = wrap_type<v0::Relu, v0::Sigmoid, v0::Tanh>({split_label});+ auto ct_label = wrap_type<v0::Relu, v0::Sigmoid, v0::Tanh>({split_label});+ auto ft_additional_bias_label = wrap_type<v0::Constant>();+ auto add_label = wrap_type<v1::Add>({split_label, ft_additional_bias_label});+ auto ft_label = wrap_type<v0::Relu, v0::Sigmoid, v0::Tanh>({add_label});+ auto ot_label = wrap_type<v0::Relu, v0::Sigmoid, v0::Tanh>({split_label});+ auto mul_label = wrap_type<v1::Multiply>({it_label, ct_label});+ auto c_label = any_input();+ auto mul1_label = wrap_type<v1::Multiply>({ft_label, c_label});+ auto Co_label = wrap_type<v1::Add>({mul_label, mul1_label});+ auto Co_activation_label = wrap_type<v0::Relu, v0::Sigmoid, v0::Tanh>({Co_label});+ auto Ho_label = wrap_type<v1::Multiply>({Co_activation_label, ot_label});++ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& X = pattern_map.at(x_label);@@ -246,7 +255,7 @@ ov::pass::LSTMCellFusionWithJointWeights::LSTMCellFusionWithJointWeights() {const auto& ft_additional_bias = pattern_map.at(ft_additional_bias_label);auto Ho = pattern_map.at(Ho_label);auto Co = pattern_map.at(Co_label);- const auto matmul = ov::as_type_ptr<ov::op::v0::MatMul>(pattern_map.at(matmul_label).get_node_shared_ptr());+ const auto matmul = ov::as_type_ptr<v0::MatMul>(pattern_map.at(matmul_label).get_node_shared_ptr());if (!matmul)return false;if (matmul->get_transpose_a())@@ -297,7 +306,7 @@ ov::pass::LSTMCellFusionWithJointWeights::LSTMCellFusionWithJointWeights() {if (!C_shape[1].compatible(hidden_size))return false;- const auto split_axis = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(axis_label).get_node_shared_ptr());+ const auto split_axis = ov::as_type_ptr<v0::Constant>(pattern_map.at(axis_label).get_node_shared_ptr());int64_t split_axis_value = split_axis->cast_vector<int64_t>()[0];if (split_axis_value != 1 && split_axis_value != -1)return false;@@ -338,7 +347,7 @@ ov::pass::LSTMCellFusionWithJointWeights::LSTMCellFusionWithJointWeights() {std::string h_activation_name = get_activation_name(Co_activation);if (!weights_transposed) {- WR = std::make_shared<ov::op::v1::Transpose>(WR, ov::op::v0::Constant::create(element::i32, Shape{0}, {}));+ WR = std::make_shared<v1::Transpose>(WR, v0::Constant::create(element::i32, Shape{0}, {}));}// Split WR to W, R and convert to the layout that OpenVino supports//@@ -369,14 +378,14 @@ ov::pass::LSTMCellFusionWithJointWeights::LSTMCellFusionWithJointWeights() {// o | | o | |// +-------+ +---+//- auto zero_axis = ov::op::v0::Constant::create(element::i32, Shape{}, {0});- auto WR_split = std::make_shared<ov::op::v1::Split>(WR, zero_axis, 4);- auto WR_fico = std::make_shared<ov::op::v0::Concat>(+ auto zero_axis = v0::Constant::create(element::i32, Shape{}, {0});+ auto WR_split = std::make_shared<v1::Split>(WR, zero_axis, 4);+ auto WR_fico = std::make_shared<v0::Concat>(OutputVector{WR_split->output(2), WR_split->output(0), WR_split->output(1), WR_split->output(3)},0);- auto vsplit_axis = ov::op::v0::Constant::create(element::i32, Shape{}, {1});- auto split_lengths = ov::op::v0::Constant::create(element::i32, Shape{2}, {input_size, hidden_size});- auto vsplit = std::make_shared<ov::op::v1::VariadicSplit>(WR_fico, vsplit_axis, split_lengths);+ auto vsplit_axis = v0::Constant::create(element::i32, Shape{}, {1});+ auto split_lengths = v0::Constant::create(element::i32, Shape{2}, {input_size, hidden_size});+ auto vsplit = std::make_shared<v1::VariadicSplit>(WR_fico, vsplit_axis, split_lengths);Output<Node> W = vsplit->output(0);if (auto constant = ov::util::constantfold_subgraph(W))W = constant;@@ -385,20 +394,19 @@ ov::pass::LSTMCellFusionWithJointWeights::LSTMCellFusionWithJointWeights() {R = constant;if (B_shape.size() > 1)- B = std::make_shared<ov::op::v0::Squeeze>(B, zero_axis);+ B = std::make_shared<v0::Squeeze>(B, zero_axis);// Convert B layout from icfo to fico- auto B_split = std::make_shared<ov::op::v1::Split>(B, zero_axis, 4);- auto B_f = std::make_shared<ov::op::v1::Add>(B_split->output(2),- std::make_shared<ov::op::v0::Squeeze>(ft_additional_bias));+ auto B_split = std::make_shared<v1::Split>(B, zero_axis, 4);+ auto B_f = std::make_shared<v1::Add>(B_split->output(2), std::make_shared<v0::Squeeze>(ft_additional_bias));- Output<Node> B_fico = std::make_shared<ov::op::v0::Concat>(- OutputVector{B_f, B_split->output(0), B_split->output(1), B_split->output(3)},- 0);+ Output<Node> B_fico =+ std::make_shared<v0::Concat>(OutputVector{B_f, B_split->output(0), B_split->output(1), B_split->output(3)},+ 0);if (auto constant = ov::util::constantfold_subgraph(B_fico))B_fico = constant;- auto lstm_cell = std::make_shared<ov::op::v4::LSTMCell>(+ auto lstm_cell = std::make_shared<v4::LSTMCell>(X,H,C,@@ -443,7 +451,7 @@ ov::pass::LSTMCellFusionWithJointWeights::LSTMCellFusionWithJointWeights() {return true;};- auto m = std::make_shared<pattern::Matcher>(Ho_label, matcher_name);+ auto m = std::make_shared<Matcher>(Ho_label, matcher_name);this->register_matcher(m, callback);}@@ -533,9 +541,9 @@ ov::pass::LSTMCellFusionWithJointWeights::LSTMCellFusionWithJointWeights() {ov::pass::LSTMCellFusionWithSplitWeights::LSTMCellFusionWithSplitWeights() {MATCHER_SCOPE(LSTMCellFusionWithSplitWeights);- auto x_label = pattern::any_input(pattern::rank_equals(2));- auto h_label = pattern::any_input(pattern::rank_equals(2));- auto c_label = pattern::any_input(pattern::rank_equals(2));+ auto x_label = any_input(rank_equals(2));+ auto h_label = any_input(rank_equals(2));+ auto c_label = any_input(rank_equals(2));// it expects a pattern with split weights (input, recurrent and bias) for each gatestd::shared_ptr<Node> it_label, wi_label, ri_label, bi_label, x_by_wi_label, h_by_ri_label;@@ -547,14 +555,14 @@ ov::pass::LSTMCellFusionWithSplitWeights::LSTMCellFusionWithSplitWeights() {std::shared_ptr<Node> c1t_label, wc_label, rc_label, bc_label, x_by_wc_label, h_by_rc_label;generate_gate_pattern(x_label, h_label, c1t_label, wc_label, rc_label, bc_label, x_by_wc_label, h_by_rc_label);- auto it_mul_c1t_label = pattern::wrap_type<ov::op::v1::Multiply>({it_label, c1t_label});- auto ft_mul_c_label = pattern::wrap_type<ov::op::v1::Multiply>({ft_label, c_label});- auto ct_label = pattern::wrap_type<ov::op::v1::Add>({ft_mul_c_label, it_mul_c1t_label});+ auto it_mul_c1t_label = wrap_type<v1::Multiply>({it_label, c1t_label});+ auto ft_mul_c_label = wrap_type<v1::Multiply>({ft_label, c_label});+ auto ct_label = wrap_type<v1::Add>({ft_mul_c_label, it_mul_c1t_label});- auto ct_activated_label = pattern::wrap_type<ov::op::v0::Relu, ov::op::v0::Sigmoid, ov::op::v0::Tanh>({ct_label});- auto ht_label = pattern::wrap_type<ov::op::v1::Multiply>({ct_activated_label, ot_label});+ auto ct_activated_label = wrap_type<v0::Relu, v0::Sigmoid, v0::Tanh>({ct_label});+ auto ht_label = wrap_type<v1::Multiply>({ct_activated_label, ot_label});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {NodeRegistry rg;const auto& pattern_map = m.get_pattern_value_map();@@ -617,19 +625,19 @@ ov::pass::LSTMCellFusionWithSplitWeights::LSTMCellFusionWithSplitWeights() {ov::Output<ov::Node> W = prepare_weight_fico(wf, wi, wc, wo, rg);ov::Output<ov::Node> R = prepare_weight_fico(rf, ri, rc, ro, rg);- ov::Output<ov::Node> B = rg.make<ov::op::v0::Concat>(ov::OutputVector{bf, bi, bc, bo}, 0);+ ov::Output<ov::Node> B = rg.make<v0::Concat>(ov::OutputVector{bf, bi, bc, bo}, 0);if (const auto& constant = ov::util::constantfold_subgraph(B))B = constant;- auto lstm_cell = rg.make<ov::op::v4::LSTMCell>(- x,- h,- c,- W,- R,- B,- static_cast<size_t>(hidden_size),- std::vector<std::string>{f_activation_name, g_activation_name, h_activation_name});+ auto lstm_cell =+ rg.make<v4::LSTMCell>(x,+ h,+ c,+ W,+ R,+ B,+ static_cast<size_t>(hidden_size),+ std::vector<std::string>{f_activation_name, g_activation_name, h_activation_name});if (transformation_callback(lstm_cell)) {return false;@@ -645,6 +653,6 @@ ov::pass::LSTMCellFusionWithSplitWeights::LSTMCellFusionWithSplitWeights() {return true;};- auto m = std::make_shared<pattern::Matcher>(ht_label, matcher_name);+ auto m = std::make_shared<Matcher>(ht_label, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_shapeof_subgraphs.cpp b/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_shapeof_subgraphs.cppindex a1664a8d9ae..ca8abe3f17d 100644--- a/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_shapeof_subgraphs.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/mark_precision_sensitive_shapeof_subgraphs.cpp@@ -20,6 +20,7 @@using namespace std;+namespace op_util = ov::op::util;ov::pass::MarkPrecisionSensitiveShapeOfSubgraphs::MarkPrecisionSensitiveShapeOfSubgraphs() {m_markup_func = [](Node* node) {ov::disable_fp16_compression(node->shared_from_this());@@ -65,9 +66,9 @@ bool ov::pass::MarkPrecisionSensitiveShapeOfSubgraphs::run_on_model(const shared// visit_shape_path shouldn't depend on "visited" nodes because we can approach Divide// earlier from some non precision sensitive path. So we use dedicated "precision_sensitive_visited"// set for precision sensitive nodes, so they can be visited twice and finally marked-up.- ov::op::util::visit_shape_path(input.get_source_output().get_node(),- precision_sensitive_visited,- m_markup_func);+ op_util::visit_shape_path(input.get_source_output().get_node(),+ precision_sensitive_visited,+ m_markup_func);}}@@ -77,7 +78,7 @@ bool ov::pass::MarkPrecisionSensitiveShapeOfSubgraphs::run_on_model(const sharedif (visited.count(input_node))continue;- if (auto sub_graph_node = ov::as_type<ov::op::util::MultiSubGraphOp>(input_node)) {+ if (auto sub_graph_node = ov::as_type<op_util::MultiSubGraphOp>(input_node)) {size_t sub_graphs_num = sub_graph_node->get_internal_subgraphs_size();for (size_t sub_graph_ind = 0; sub_graph_ind < sub_graphs_num; ++sub_graph_ind) {auto sub_graph = sub_graph_node->get_function(static_cast<int>(sub_graph_ind));diff --git a/src/common/transformations/src/transformations/common_optimizations/mark_rope_input_to_keep_in_mixed_precision.cpp b/src/common/transformations/src/transformations/common_optimizations/mark_rope_input_to_keep_in_mixed_precision.cppindex 6b0116d139f..ff818965e12 100644--- a/src/common/transformations/src/transformations/common_optimizations/mark_rope_input_to_keep_in_mixed_precision.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/mark_rope_input_to_keep_in_mixed_precision.cpp@@ -15,14 +15,18 @@#include "transformations/rt_info/disable_fp16_compression.hpp"#include "transformations/utils/utils.hpp"-ov::pass::MarkRopeInputsToKeepInMixedPrecision::MarkRopeInputsToKeepInMixedPrecision() {+namespace v0 = ov::op::v0;+namespace op_util = ov::op::util;++namespace ov::pass {++MarkRopeInputsToKeepInMixedPrecision::MarkRopeInputsToKeepInMixedPrecision() {MATCHER_SCOPE(MarkRopeInputsToKeepInMixedPrecision);- using namespace ov::pass::pattern;- auto cos_tab = any_input();- auto sin_tab = any_input();- auto rope = wrap_type<ov::op::internal::RoPE>({any_input(), cos_tab, sin_tab});+ auto cos_tab = pattern::any_input();+ auto sin_tab = pattern::any_input();+ auto rope = pattern::wrap_type<ov::op::internal::RoPE>({pattern::any_input(), cos_tab, sin_tab});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto cos_input_node = pattern_map.at(cos_tab).get_node();auto sin_input_node = pattern_map.at(sin_tab).get_node();@@ -34,18 +38,20 @@ ov::pass::MarkRopeInputsToKeepInMixedPrecision::MarkRopeInputsToKeepInMixedPreci// The inputs of cos_sin table generation are position_ids and a ShapeOf [batch, input_length]// The parent of ShapeOf may change when IR changes so skip it to avoid unknown precision problemauto skip_node_predicate = [](ov::Node* node) -> bool {- return ov::is_type<ov::op::v0::Constant>(node) || ov::is_type<ov::op::v0::Parameter>(node) ||- ov::is_type<ov::op::util::ShapeOfBase>(node);+ return ov::is_type<v0::Constant>(node) || ov::is_type<v0::Parameter>(node) ||+ ov::is_type<op_util::ShapeOfBase>(node);};if (!visited.count(cos_input_node)) {- ov::op::util::visit_path(cos_input_node, visited, visit_func, skip_node_predicate);+ op_util::visit_path(cos_input_node, visited, visit_func, skip_node_predicate);}if (!visited.count(sin_input_node)) {- ov::op::util::visit_path(sin_input_node, visited, visit_func, skip_node_predicate);+ op_util::visit_path(sin_input_node, visited, visit_func, skip_node_predicate);}return false;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(rope, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(rope, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/matmul_const_transposes_extraction.cpp b/src/common/transformations/src/transformations/common_optimizations/matmul_const_transposes_extraction.cppindex 01b3a1a938f..51ecf9959e1 100644--- a/src/common/transformations/src/transformations/common_optimizations/matmul_const_transposes_extraction.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/matmul_const_transposes_extraction.cpp@@ -12,19 +12,22 @@#include "openvino/op/transpose.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;ov::pass::MatMulConstTransposesExtraction::MatMulConstTransposesExtraction() {- auto data_pattern = pattern::any_input();- auto weights_pattern =- pattern::wrap_type<ov::op::v0::Constant, ov::op::v0::FakeQuantize>([](Output<Node> node) -> bool {- const auto& pshape = node.get_partial_shape();- const auto& rank = pshape.rank();- return rank.is_static() && rank.get_length() >= 2 &&- std::count(pshape.begin(), pshape.end(), 1) >= rank.get_length() - 2;- });- auto matmul_pattern = pattern::wrap_type<ov::op::v0::MatMul>({data_pattern, weights_pattern});- matcher_pass_callback callback = [=](pattern::Matcher& m) {+ auto data_pattern = ov::pass::pattern::any_input();+ auto weights_pattern = wrap_type<v0::Constant, v0::FakeQuantize>([](Output<Node> node) -> bool {+ const auto& pshape = node.get_partial_shape();+ const auto& rank = pshape.rank();+ return rank.is_static() && rank.get_length() >= 2 &&+ std::count(pshape.begin(), pshape.end(), 1) >= rank.get_length() - 2;+ });+ auto matmul_pattern = wrap_type<v0::MatMul>({data_pattern, weights_pattern});+ matcher_pass_callback callback = [=](Matcher& m) {auto node = m.get_match_root();- auto matmul = as_type<ov::op::v0::MatMul>(node.get());+ auto matmul = as_type<v0::MatMul>(node.get());if (!matmul || matmul->get_transpose_b())return false;@@ -36,17 +39,17 @@ ov::pass::MatMulConstTransposesExtraction::MatMulConstTransposesExtraction() {std::reverse(transpose_order.end() - 2, transpose_order.end());std::shared_ptr<Node> transpose = std::make_shared<ov::op::v1::Transpose>(weights,- ov::op::v0::Constant::create(element::i32, {transpose_order.size()}, transpose_order));- auto new_matmul = std::make_shared<ov::op::v0::MatMul>(pattern_value_map.at(data_pattern),- transpose,- matmul->get_transpose_a(),- true);+ v0::Constant::create(element::i32, {transpose_order.size()}, transpose_order));+ auto new_matmul = std::make_shared<v0::MatMul>(pattern_value_map.at(data_pattern),+ transpose,+ matmul->get_transpose_a(),+ true);new_matmul->set_friendly_name(matmul->get_friendly_name());copy_runtime_info(node, {transpose, new_matmul});replace_node(node, new_matmul);return true;};- auto m = std::make_shared<pattern::Matcher>(matmul_pattern, "MatMulConstTransposesExtraction");+ auto m = std::make_shared<Matcher>(matmul_pattern, "MatMulConstTransposesExtraction");this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/matmul_experts_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/matmul_experts_fusion.cppindex 6825aeb7d2c..c8459f9b72b 100644--- a/src/common/transformations/src/transformations/common_optimizations/matmul_experts_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/matmul_experts_fusion.cpp@@ -26,50 +26,57 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::pass;-ov::pass::FuseVectorizedMOE2GEMM::FuseVectorizedMOE2GEMM() {+namespace ov::pass {++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;+namespace v8 = ov::op::v8;+namespace v12 = ov::op::v12;++FuseVectorizedMOE2GEMM::FuseVectorizedMOE2GEMM() {MATCHER_SCOPE(FuseVectorizedMOE2GEMM);- auto experts_input = pattern::wrap_type<ov::op::v1::Reshape>({pattern::any_input(), pattern::any_input()});- auto tile = pattern::wrap_type<ov::op::v0::Tile>({experts_input, pattern::any_input()});- auto after_tile_reshape = pattern::wrap_type<ov::op::v1::Reshape>({tile, pattern::any_input()});- auto gate_up_matmul = pattern::wrap_type<ov::op::v0::MatMul>({after_tile_reshape, pattern::any_input()},- {{"transpose_a", false}, {"transpose_b", true}});- auto gate_up_add = pattern::wrap_type<ov::op::v1::Add>({gate_up_matmul, pattern::any_input()});+ auto experts_input = pattern::wrap_type<v1::Reshape>({pattern::any_input(), pattern::any_input()});+ auto tile = pattern::wrap_type<v0::Tile>({experts_input, pattern::any_input()});+ auto after_tile_reshape = pattern::wrap_type<v1::Reshape>({tile, pattern::any_input()});+ auto gate_up_matmul = pattern::wrap_type<v0::MatMul>({after_tile_reshape, pattern::any_input()},+ {{"transpose_a", false}, {"transpose_b", true}});+ auto gate_up_add = pattern::wrap_type<v1::Add>({gate_up_matmul, pattern::any_input()});// Branch 1: Slice_1 -> Clamp -> Add_1- auto slice1 = pattern::wrap_type<ov::op::v8::Slice>(+ auto slice1 = pattern::wrap_type<v8::Slice>({gate_up_add, pattern::any_input(), pattern::any_input(), pattern::any_input(), pattern::any_input()});- auto clamp = pattern::wrap_type<ov::op::v0::Clamp>({slice1});- auto add1 = pattern::wrap_type<ov::op::v1::Add>({clamp, pattern::wrap_const()});+ auto clamp = pattern::wrap_type<v0::Clamp>({slice1});+ auto add1 = pattern::wrap_type<v1::Add>({clamp, ov::pass::pattern::wrap_const()});// Branch 2: Slice_2 -> Minimum_1 -> Swish- auto slice2 = pattern::wrap_type<ov::op::v8::Slice>(+ auto slice2 = pattern::wrap_type<v8::Slice>({gate_up_add, pattern::any_input(), pattern::any_input(), pattern::any_input(), pattern::any_input()});- auto minimum1 = pattern::wrap_type<ov::op::v1::Minimum>({slice2, pattern::wrap_const()});- auto swish_beta = pattern::wrap_const();- auto swish = pattern::wrap_type<ov::op::v4::Swish>({minimum1, swish_beta});+ auto minimum1 = pattern::wrap_type<v1::Minimum>({slice2, ov::pass::pattern::wrap_const()});+ auto swish_beta = ov::pass::pattern::wrap_const();+ auto swish = pattern::wrap_type<v4::Swish>({minimum1, swish_beta});// Join: Multiply_2- auto multiply2 = pattern::wrap_type<ov::op::v1::Multiply>({add1, swish});+ auto multiply2 = pattern::wrap_type<v1::Multiply>({add1, swish});// Down projection- auto down_proj_matmul = pattern::wrap_type<ov::op::v0::MatMul>({multiply2, pattern::any_input()},- {{"transpose_a", false}, {"transpose_b", true}});- auto down_proj_add = pattern::wrap_type<ov::op::v1::Add>({down_proj_matmul, pattern::wrap_const()});- auto end_reshape = pattern::wrap_type<ov::op::v1::Reshape>({down_proj_add, pattern::any_input()});+ auto down_proj_matmul = pattern::wrap_type<v0::MatMul>({multiply2, pattern::any_input()},+ {{"transpose_a", false}, {"transpose_b", true}});+ auto down_proj_add = pattern::wrap_type<v1::Add>({down_proj_matmul, ov::pass::pattern::wrap_const()});+ auto end_reshape = pattern::wrap_type<v1::Reshape>({down_proj_add, pattern::any_input()});// Routing weights/maskauto router_topk_indices = pattern::any_input();- auto scatter_elements_update = pattern::wrap_type<ov::op::v12::ScatterElementsUpdate>(+ auto scatter_elements_update = pattern::wrap_type<v12::ScatterElementsUpdate>({pattern::any_input(), router_topk_indices, pattern::any_input(), pattern::any_input()});- auto router_transpose = pattern::wrap_type<ov::op::v1::Transpose>({scatter_elements_update, pattern::any_input()});- auto router_reshape = pattern::wrap_type<ov::op::v1::Reshape>({router_transpose, pattern::any_input()});- auto unsqueeze_routing_weights = pattern::wrap_type<ov::op::v0::Unsqueeze>({router_reshape, pattern::any_input()});+ auto router_transpose = pattern::wrap_type<v1::Transpose>({scatter_elements_update, pattern::any_input()});+ auto router_reshape = pattern::wrap_type<v1::Reshape>({router_transpose, pattern::any_input()});+ auto unsqueeze_routing_weights = pattern::wrap_type<v0::Unsqueeze>({router_reshape, pattern::any_input()});- auto mul3 = pattern::wrap_type<ov::op::v1::Multiply>({end_reshape, unsqueeze_routing_weights});- auto reduce_sum = pattern::wrap_type<ov::op::v1::ReduceSum>({mul3, pattern::any_input()}, {{"keep_dims", false}});+ auto mul3 = pattern::wrap_type<v1::Multiply>({end_reshape, unsqueeze_routing_weights});+ auto reduce_sum = pattern::wrap_type<v1::ReduceSum>({mul3, pattern::any_input()}, {{"keep_dims", false}});auto moe_pattern = reduce_sum;matcher_pass_callback callback = [=](pattern::Matcher& m) {@@ -99,12 +106,12 @@ ov::pass::FuseVectorizedMOE2GEMM::FuseVectorizedMOE2GEMM() {ov::op::internal::MOE::Config config;// Extract expert_beta from Swish beta attribute- auto swish_beta_const = ov::as_type_ptr<ov::op::v0::Constant>(pm.at(swish_beta).get_node_shared_ptr());+ auto swish_beta_const = ov::as_type_ptr<v0::Constant>(pm.at(swish_beta).get_node_shared_ptr());auto swish_beta_const_val = swish_beta_const->cast_vector<float>()[0];config.expert_beta = swish_beta_const_val;// Extract expert_alpha from Clamp max attribute- if (auto clamp_op = ov::as_type_ptr<ov::op::v0::Clamp>(pm.at(clamp).get_node_shared_ptr())) {+ if (auto clamp_op = ov::as_type_ptr<v0::Clamp>(pm.at(clamp).get_node_shared_ptr())) {config.expert_alpha = static_cast<float>(clamp_op->get_max());}@@ -124,38 +131,38 @@ ov::pass::FuseVectorizedMOE2GEMM::FuseVectorizedMOE2GEMM() {this->register_matcher(matcher, callback);}-ov::pass::FuseVectorizedMOE3GEMM::FuseVectorizedMOE3GEMM() {+FuseVectorizedMOE3GEMM::FuseVectorizedMOE3GEMM() {MATCHER_SCOPE(FuseVectorizedMOE3GEMM);- auto experts_input = pattern::wrap_type<ov::op::v1::Reshape>({pattern::any_input(), pattern::any_input()});- auto tile = pattern::wrap_type<ov::op::v0::Tile>({experts_input, pattern::any_input()});- auto after_tile_reshape = pattern::wrap_type<ov::op::v1::Reshape>({tile, pattern::any_input()});+ auto experts_input = pattern::wrap_type<v1::Reshape>({pattern::any_input(), pattern::any_input()});+ auto tile = pattern::wrap_type<v0::Tile>({experts_input, pattern::any_input()});+ auto after_tile_reshape = pattern::wrap_type<v1::Reshape>({tile, pattern::any_input()});// First GEMM (activation gate)- auto gate_matmul = pattern::wrap_type<ov::op::v0::MatMul>({after_tile_reshape, pattern::any_input()},- {{"transpose_a", false}, {"transpose_b", true}});- auto swish = pattern::wrap_type<ov::op::v4::Swish>({gate_matmul});+ auto gate_matmul = pattern::wrap_type<v0::MatMul>({after_tile_reshape, pattern::any_input()},+ {{"transpose_a", false}, {"transpose_b", true}});+ auto swish = pattern::wrap_type<v4::Swish>({gate_matmul});// Second GEMM (up_projection)- auto up_matmul = pattern::wrap_type<ov::op::v0::MatMul>({after_tile_reshape, pattern::any_input()},- {{"transpose_a", false}, {"transpose_b", true}});+ auto up_matmul = pattern::wrap_type<v0::MatMul>({after_tile_reshape, pattern::any_input()},+ {{"transpose_a", false}, {"transpose_b", true}});// Join: Multiply (SwiGLU)- auto swiglu = pattern::wrap_type<ov::op::v1::Multiply>({swish, up_matmul});+ auto swiglu = pattern::wrap_type<v1::Multiply>({swish, up_matmul});// Third GEMM (down_projection)- auto down_matmul = pattern::wrap_type<ov::op::v0::MatMul>({swiglu, pattern::any_input()},- {{"transpose_a", false}, {"transpose_b", true}});- auto end_reshape = pattern::wrap_type<ov::op::v1::Reshape>({down_matmul, pattern::any_input()});+ auto down_matmul =+ pattern::wrap_type<v0::MatMul>({swiglu, pattern::any_input()}, {{"transpose_a", false}, {"transpose_b", true}});+ auto end_reshape = pattern::wrap_type<v1::Reshape>({down_matmul, pattern::any_input()});// Routing weights/maskauto router_topk_indices = pattern::any_input();- auto scatter_elements_update = pattern::wrap_type<ov::op::v12::ScatterElementsUpdate>(+ auto scatter_elements_update = pattern::wrap_type<v12::ScatterElementsUpdate>({pattern::any_input(), router_topk_indices, pattern::any_input(), pattern::any_input()});- auto router_transpose = pattern::wrap_type<ov::op::v1::Transpose>({scatter_elements_update, pattern::any_input()});- auto router_reshape = pattern::wrap_type<ov::op::v1::Reshape>({router_transpose, pattern::any_input()});- auto unsqueeze_routing_weights = pattern::wrap_type<ov::op::v0::Unsqueeze>({router_reshape, pattern::any_input()});+ auto router_transpose = pattern::wrap_type<v1::Transpose>({scatter_elements_update, pattern::any_input()});+ auto router_reshape = pattern::wrap_type<v1::Reshape>({router_transpose, pattern::any_input()});+ auto unsqueeze_routing_weights = pattern::wrap_type<v0::Unsqueeze>({router_reshape, pattern::any_input()});- auto mul3 = pattern::wrap_type<ov::op::v1::Multiply>({end_reshape, unsqueeze_routing_weights});- auto reduce_sum = pattern::wrap_type<ov::op::v1::ReduceSum>({mul3, pattern::any_input()}, {{"keep_dims", false}});+ auto mul3 = pattern::wrap_type<v1::Multiply>({end_reshape, unsqueeze_routing_weights});+ auto reduce_sum = pattern::wrap_type<v1::ReduceSum>({mul3, pattern::any_input()}, {{"keep_dims", false}});auto moe_pattern = reduce_sum;matcher_pass_callback callback = [=](pattern::Matcher& m) {@@ -184,10 +191,9 @@ ov::pass::FuseVectorizedMOE3GEMM::FuseVectorizedMOE3GEMM() {ov::op::internal::MOE::Config config;config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;// Extract expert_beta if Swish has beta input provided- if (auto swish_op = ov::as_type_ptr<ov::op::v4::Swish>(pm.at(swish).get_node_shared_ptr())) {+ if (auto swish_op = ov::as_type_ptr<v4::Swish>(pm.at(swish).get_node_shared_ptr())) {if (swish_op->get_input_size() > 1) {- if (auto swish_beta_const =- ov::as_type_ptr<ov::op::v0::Constant>(swish_op->get_input_node_shared_ptr(1))) {+ if (auto swish_beta_const = ov::as_type_ptr<v0::Constant>(swish_op->get_input_node_shared_ptr(1))) {config.expert_beta = swish_beta_const->cast_vector<float>()[0];}}@@ -205,3 +211,5 @@ ov::pass::FuseVectorizedMOE3GEMM::FuseVectorizedMOE3GEMM() {auto matcher = std::make_shared<pattern::Matcher>(moe_pattern, matcher_name);this->register_matcher(matcher, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/matmul_multiply_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/matmul_multiply_fusion.cppindex 08d1fd129d0..2a63a7e07c6 100644--- a/src/common/transformations/src/transformations/common_optimizations/matmul_multiply_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/matmul_multiply_fusion.cpp@@ -17,9 +17,15 @@using namespace ov;+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;static std::shared_ptr<Node> fuse_const_to_weights(const std::shared_ptr<Node>& matmul,const Output<Node>& weights,- std::shared_ptr<ov::op::v0::Constant> mul_const) {+ std::shared_ptr<v0::Constant> mul_const) {auto const_shape = mul_const->get_shape();auto const_rank = static_cast<int64_t>(const_shape.size());const auto& weights_shape = weights.get_partial_shape();@@ -27,7 +33,7 @@ static std::shared_ptr<Node> fuse_const_to_weights(const std::shared_ptr<Node>&// Fuse if const is a scalarif (ov::is_scalar(const_shape)) {- return std::make_shared<ov::op::v1::Multiply>(weights, mul_const);+ return std::make_shared<v1::Multiply>(weights, mul_const);}// Disallow consts that have rank greater than weights' rank when MatMul has dynamic rank.@@ -49,11 +55,11 @@ static std::shared_ptr<Node> fuse_const_to_weights(const std::shared_ptr<Node>&// If weights is not a constant node - disallow Multiply constant// that extends weights rank. This is LPT requirement in case where// weights are meant to be quantized.- if (const_rank > weights_rank && !ov::is_type<ov::op::v0::Constant>(weights.get_node())) {+ if (const_rank > weights_rank && !ov::is_type<v0::Constant>(weights.get_node())) {return nullptr;}- auto matmul_casted = ov::as_type_ptr<ov::op::v0::MatMul>(matmul);+ auto matmul_casted = ov::as_type_ptr<v0::MatMul>(matmul);if (!matmul_casted) {return nullptr;}@@ -123,17 +129,16 @@ static std::shared_ptr<Node> fuse_const_to_weights(const std::shared_ptr<Node>&// Scalars were fused before, it suffices to check for 1D shape hereif (const_rank == 1) {const_shape.insert(const_shape.begin(), 1);- new_const = std::make_shared<ov::op::v1::Reshape>(+ new_const = std::make_shared<v1::Reshape>(mul_const,- ov::op::v0::Constant::create(element::u64, Shape{const_shape.size()}, const_shape),+ v0::Constant::create(element::u64, Shape{const_shape.size()}, const_shape),false);}std::vector<int64_t> perm(const_shape.size());std::iota(perm.begin(), perm.end(), 0);std::swap(*(perm.end() - 1), *(perm.end() - 2));- auto transpose = std::make_shared<ov::op::v1::Transpose>(- new_const,- ov::op::v0::Constant::create(element::i64, Shape{perm.size()}, perm));+ auto transpose =+ std::make_shared<v1::Transpose>(new_const, v0::Constant::create(element::i64, Shape{perm.size()}, perm));return ov::util::get_constant_from_source(transpose);};@@ -142,25 +147,25 @@ static std::shared_ptr<Node> fuse_const_to_weights(const std::shared_ptr<Node>&auto transpose = transpose_const(mul_const);if (!transpose)return nullptr;- return std::make_shared<ov::op::v1::Multiply>(weights, transpose);+ return std::make_shared<v1::Multiply>(weights, transpose);}- return std::make_shared<ov::op::v1::Multiply>(weights, mul_const);+ return std::make_shared<v1::Multiply>(weights, mul_const);}pass::MatMulMultiplyFusion::MatMulMultiplyFusion() {MATCHER_SCOPE(MatMulMultiplyFusion);- auto input_pattern = pattern::any_input();- auto weights_pattern = pattern::any_input(pattern::has_static_rank());- auto mul_const_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto input_pattern = any_input();+ auto weights_pattern = any_input(ov::pass::pattern::has_static_rank());+ auto mul_const_pattern = wrap_type<v0::Constant>();auto matmul_pattern =- pattern::wrap_type<ov::op::v0::MatMul>({input_pattern, weights_pattern}, pattern::consumers_count(1));- auto mul_pattern = pattern::wrap_type<ov::op::v1::Multiply>({matmul_pattern, mul_const_pattern});+ wrap_type<v0::MatMul>({input_pattern, weights_pattern}, ov::pass::pattern::consumers_count(1));+ auto mul_pattern = wrap_type<v1::Multiply>({matmul_pattern, mul_const_pattern});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& weights = pattern_map.at(weights_pattern);auto mul = pattern_map.at(mul_pattern).get_node_shared_ptr();- auto mul_const = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(mul_const_pattern).get_node_shared_ptr());+ auto mul_const = ov::as_type_ptr<v0::Constant>(pattern_map.at(mul_const_pattern).get_node_shared_ptr());if (!mul_const)return false;auto matmul = pattern_map.at(matmul_pattern).get_node_shared_ptr();@@ -171,7 +176,7 @@ pass::MatMulMultiplyFusion::MatMulMultiplyFusion() {// Constantfold new weights, only if old weights is a constant node.// To make sure that subgraphs with e.g. FakeQuantize don't get constant folded here.- if (ov::is_type<ov::op::v0::Constant>(weights.get_node())) {+ if (ov::is_type<v0::Constant>(weights.get_node())) {if (auto constant = ov::util::get_constant_from_source(new_weights)) {new_weights = constant;}@@ -188,6 +193,6 @@ pass::MatMulMultiplyFusion::MatMulMultiplyFusion() {return true;};- auto m = std::make_shared<pattern::Matcher>(mul_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(mul_pattern, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/mish_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/mish_fusion.cppindex 01ffff7caf7..36a39e0b733 100644--- a/src/common/transformations/src/transformations/common_optimizations/mish_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/mish_fusion.cpp@@ -19,16 +19,20 @@#include "openvino/op/tanh.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::MishFusion::MishFusion() {MATCHER_SCOPE(MishFusion);- auto input = pass::pattern::any_input();- auto exp = std::make_shared<ov::op::v0::Exp>(input);- auto add = std::make_shared<ov::op::v1::Add>(exp, ov::pass::pattern::wrap_type<ov::op::v0::Constant>());- auto log = std::make_shared<ov::op::v0::Log>(add);- auto tanh = std::make_shared<ov::op::v0::Tanh>(log);- auto mul = std::make_shared<ov::op::v1::Multiply>(input, tanh);-- ov::matcher_pass_callback matcher_pass_callback = [=](ov::pass::pattern::Matcher& m) {+ auto input = ov::pass::pattern::any_input();+ auto exp = std::make_shared<v0::Exp>(input);+ auto add = std::make_shared<v1::Add>(exp, ov::pass::pattern::wrap_type<v0::Constant>());+ auto log = std::make_shared<v0::Log>(add);+ auto tanh = std::make_shared<v0::Tanh>(log);+ auto mul = std::make_shared<v1::Multiply>(input, tanh);++ ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto exp_input = pattern_to_output.at(input);@@ -45,6 +49,6 @@ ov::pass::MishFusion::MishFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul, matcher_name);+ auto m = std::make_shared<Matcher>(mul, matcher_name);register_matcher(m, matcher_pass_callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/moe_transpose_weights.cpp b/src/common/transformations/src/transformations/common_optimizations/moe_transpose_weights.cppindex d703e11327f..f1eb45e91df 100644--- a/src/common/transformations/src/transformations/common_optimizations/moe_transpose_weights.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/moe_transpose_weights.cpp@@ -31,62 +31,67 @@using namespace ov::pass;+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;ov::pass::VectorizedMOE2GEMMTransposeWeights::VectorizedMOE2GEMMTransposeWeights() {MATCHER_SCOPE(VectorizedMOE2GEMMTransposeWeights);- auto experts_input = pattern::wrap_type<ov::op::v1::Reshape>({pattern::any_input(), pattern::any_input()});- auto tile = pattern::wrap_type<ov::op::v0::Tile>({experts_input, pattern::any_input()});- auto after_tile_reshape = pattern::wrap_type<ov::op::v1::Reshape>({tile, pattern::any_input()});- auto gate_up_matmul = pattern::wrap_type<ov::op::v0::MatMul>({after_tile_reshape, pattern::any_input()},- {{"transpose_a", false}, {"transpose_b", false}});- auto gate_up_add = pattern::wrap_type<ov::op::v1::Add>({gate_up_matmul, pattern::any_input()});-- auto slice1 = pattern::wrap_type<ov::op::v8::Slice>(- {gate_up_add, pattern::any_input(), pattern::any_input(), pattern::any_input(), pattern::any_input()});- auto clamp = pattern::wrap_type<ov::op::v0::Clamp>({slice1});- auto add1 = pattern::wrap_type<ov::op::v1::Add>({clamp, pattern::wrap_const()});-- auto slice2 = pattern::wrap_type<ov::op::v8::Slice>(- {gate_up_add, pattern::any_input(), pattern::any_input(), pattern::any_input(), pattern::any_input()});- auto minimum1 = pattern::wrap_type<ov::op::v1::Minimum>({slice2, pattern::wrap_const()});- auto swish_beta = pattern::wrap_const();- auto swish = pattern::wrap_type<ov::op::v4::Swish>({minimum1, swish_beta});-- auto multiply2 = pattern::wrap_type<ov::op::v1::Multiply>({add1, swish});-- auto down_proj_matmul = pattern::wrap_type<ov::op::v0::MatMul>({multiply2, pattern::any_input()},- {{"transpose_a", false}, {"transpose_b", false}});- auto down_proj_add = pattern::wrap_type<ov::op::v1::Add>({down_proj_matmul, pattern::wrap_const()});- auto end_reshape = pattern::wrap_type<ov::op::v1::Reshape>({down_proj_add, pattern::any_input()});-- auto router_topk_indices = pattern::any_input();- auto scatter_elements_update = pattern::wrap_type<ov::op::v12::ScatterElementsUpdate>(- {pattern::any_input(), router_topk_indices, pattern::any_input(), pattern::any_input()});-- auto router_transpose = pattern::wrap_type<ov::op::v1::Transpose>({scatter_elements_update, pattern::any_input()});- auto router_reshape = pattern::wrap_type<ov::op::v1::Reshape>({router_transpose, pattern::any_input()});- auto unsqueeze_routing_weights = pattern::wrap_type<ov::op::v0::Unsqueeze>({router_reshape, pattern::any_input()});-- auto mul3 = pattern::wrap_type<ov::op::v1::Multiply>({end_reshape, unsqueeze_routing_weights});- auto reduce_sum = pattern::wrap_type<ov::op::v1::ReduceSum>({mul3, pattern::any_input()}, {{"keep_dims", false}});+ auto experts_input = wrap_type<v1::Reshape>({any_input(), any_input()});+ auto tile = wrap_type<v0::Tile>({experts_input, any_input()});+ auto after_tile_reshape = wrap_type<v1::Reshape>({tile, any_input()});+ auto gate_up_matmul =+ wrap_type<v0::MatMul>({after_tile_reshape, any_input()}, {{"transpose_a", false}, {"transpose_b", false}});+ auto gate_up_add = wrap_type<v1::Add>({gate_up_matmul, any_input()});++ auto slice1 = wrap_type<v8::Slice>({gate_up_add, any_input(), any_input(), any_input(), any_input()});+ auto clamp = wrap_type<v0::Clamp>({slice1});+ auto add1 = wrap_type<v1::Add>({clamp, ov::pass::pattern::wrap_const()});++ auto slice2 = wrap_type<v8::Slice>({gate_up_add, any_input(), any_input(), any_input(), any_input()});+ auto minimum1 = wrap_type<v1::Minimum>({slice2, ov::pass::pattern::wrap_const()});+ auto swish_beta = ov::pass::pattern::wrap_const();+ auto swish = wrap_type<ov::op::v4::Swish>({minimum1, swish_beta});++ auto multiply2 = wrap_type<v1::Multiply>({add1, swish});++ auto down_proj_matmul =+ wrap_type<v0::MatMul>({multiply2, any_input()}, {{"transpose_a", false}, {"transpose_b", false}});+ auto down_proj_add = wrap_type<v1::Add>({down_proj_matmul, ov::pass::pattern::wrap_const()});+ auto end_reshape = wrap_type<v1::Reshape>({down_proj_add, any_input()});++ auto router_topk_indices = any_input();+ auto scatter_elements_update =+ wrap_type<ov::op::v12::ScatterElementsUpdate>({any_input(), router_topk_indices, any_input(), any_input()});++ auto router_transpose = wrap_type<v1::Transpose>({scatter_elements_update, any_input()});+ auto router_reshape = wrap_type<v1::Reshape>({router_transpose, any_input()});+ auto unsqueeze_routing_weights = wrap_type<v0::Unsqueeze>({router_reshape, any_input()});++ auto mul3 = wrap_type<v1::Multiply>({end_reshape, unsqueeze_routing_weights});+ auto reduce_sum = wrap_type<v1::ReduceSum>({mul3, any_input()}, {{"keep_dims", false}});auto moe_pattern = reduce_sum;- matcher_pass_callback callback = [=](pattern::Matcher& m) {+ matcher_pass_callback callback = [=](Matcher& m) {auto& pm = m.get_pattern_value_map();if (transformation_callback(m.get_match_root())) {return false;}- auto gate_matmul = ov::as_type_ptr<ov::op::v0::MatMul>(pm.at(gate_up_matmul).get_node_shared_ptr());- auto down_matmul = ov::as_type_ptr<ov::op::v0::MatMul>(pm.at(down_proj_matmul).get_node_shared_ptr());+ auto gate_matmul = ov::as_type_ptr<v0::MatMul>(pm.at(gate_up_matmul).get_node_shared_ptr());+ auto down_matmul = ov::as_type_ptr<v0::MatMul>(pm.at(down_proj_matmul).get_node_shared_ptr());if (!gate_matmul || !down_matmul)return false;- auto insert_transpose = [&](const std::shared_ptr<ov::op::v0::MatMul>& matmul) -> bool {+ auto insert_transpose = [&](const std::shared_ptr<v0::MatMul>& matmul) -> bool {auto weight_output = matmul->input_value(1);auto transpose_input = weight_output;- std::shared_ptr<ov::op::v0::Convert> decompress_convert;+ std::shared_ptr<v0::Convert> decompress_convert;- if (auto convert = ov::as_type_ptr<ov::op::v0::Convert>(weight_output.get_node_shared_ptr())) {+ if (auto convert = ov::as_type_ptr<v0::Convert>(weight_output.get_node_shared_ptr())) {if (ov::is_decompression(convert) && convert->output(0).get_target_inputs().size() == 1) {decompress_convert = convert;transpose_input = convert->input_value(0);@@ -102,11 +107,10 @@ ov::pass::VectorizedMOE2GEMMTransposeWeights::VectorizedMOE2GEMMTransposeWeightsstd::iota(transpose_order.begin(), transpose_order.end(), 0);std::reverse(transpose_order.end() - 2, transpose_order.end());- auto order_const =- ov::op::v0::Constant::create(ov::element::i64, {transpose_order.size()}, transpose_order);- auto transpose = std::make_shared<ov::op::v1::Transpose>(transpose_input, order_const);+ auto order_const = v0::Constant::create(ov::element::i64, {transpose_order.size()}, transpose_order);+ auto transpose = std::make_shared<v1::Transpose>(transpose_input, order_const);- if (ov::is_type<ov::op::v0::Constant>(transpose_input.get_node_shared_ptr())) {+ if (ov::is_type<v0::Constant>(transpose_input.get_node_shared_ptr())) {transpose->get_rt_info()["postponed_constant"] = true;ov::pass::disable_constant_folding(transpose);}@@ -143,6 +147,6 @@ ov::pass::VectorizedMOE2GEMMTransposeWeights::VectorizedMOE2GEMMTransposeWeightsreturn true;};- auto matcher = std::make_shared<pattern::Matcher>(moe_pattern, matcher_name);+ auto matcher = std::make_shared<Matcher>(moe_pattern, matcher_name);this->register_matcher(matcher, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/move_eltwise_up_data_movement.cpp b/src/common/transformations/src/transformations/common_optimizations/move_eltwise_up_data_movement.cppindex 1e59857a3b8..503c551cec4 100644--- a/src/common/transformations/src/transformations/common_optimizations/move_eltwise_up_data_movement.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/move_eltwise_up_data_movement.cpp@@ -29,6 +29,13 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v7 = ov::op::v7;+namespace op_util = ov::op::util;namespace {bool is_data_movement_operation(const std::shared_ptr<ov::Node>& node,const std::vector<ov::DiscreteTypeInfo>& allowed_data_movement_ops) {@@ -48,19 +55,19 @@ bool is_scalar_like(const std::shared_ptr<ov::Node>& node) {std::vector<ov::DiscreteTypeInfo> ov::pass::MoveEltwiseUpThroughDataMov::get_default_allowed_ops() {return {- ov::op::v0::Squeeze::get_type_info_static(),- ov::op::v0::Unsqueeze::get_type_info_static(),- ov::op::v1::Reshape::get_type_info_static(),- ov::op::v1::Transpose::get_type_info_static(),- ov::op::v0::ShuffleChannels::get_type_info_static(),- ov::op::v7::Roll::get_type_info_static(),- ov::op::v0::ReverseSequence::get_type_info_static(),- ov::op::v0::DepthToSpace::get_type_info_static(),- ov::op::v1::BatchToSpace::get_type_info_static(),- ov::op::v1::Broadcast::get_type_info_static(),+ v0::Squeeze::get_type_info_static(),+ v0::Unsqueeze::get_type_info_static(),+ v1::Reshape::get_type_info_static(),+ v1::Transpose::get_type_info_static(),+ v0::ShuffleChannels::get_type_info_static(),+ v7::Roll::get_type_info_static(),+ v0::ReverseSequence::get_type_info_static(),+ v0::DepthToSpace::get_type_info_static(),+ v1::BatchToSpace::get_type_info_static(),+ v1::Broadcast::get_type_info_static(),ov::op::v3::Broadcast::get_type_info_static(),- ov::op::v1::Gather::get_type_info_static(),- ov::op::v7::Gather::get_type_info_static(),+ v1::Gather::get_type_info_static(),+ v7::Gather::get_type_info_static(),ov::op::v8::Gather::get_type_info_static(),};}@@ -68,11 +75,11 @@ std::vector<ov::DiscreteTypeInfo> ov::pass::MoveEltwiseUpThroughDataMov::get_defov::pass::MoveEltwiseUpThroughDataMovScalar::MoveEltwiseUpThroughDataMovScalar(std::vector<DiscreteTypeInfo> allowed_data_movement_ops) {MATCHER_SCOPE(MoveEltwiseUpThroughDataMovScalar);- auto eltwise_pattern = ov::pass::pattern::wrap_type<ov::op::util::UnaryElementwiseArithmetic,- ov::op::util::BinaryElementwiseArithmetic,- ov::op::v0::FakeQuantize>(ov::pass::pattern::has_static_rank());+ auto eltwise_pattern =+ wrap_type<op_util::UnaryElementwiseArithmetic, op_util::BinaryElementwiseArithmetic, v0::FakeQuantize>(+ ov::pass::pattern::has_static_rank());- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto eltwise = pattern_map.at(eltwise_pattern).get_node_shared_ptr();@@ -138,7 +145,7 @@ ov::pass::MoveEltwiseUpThroughDataMovScalar::MoveEltwiseUpThroughDataMovScalar(return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(eltwise_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(eltwise_pattern, matcher_name);register_matcher(m, callback);}@@ -168,7 +175,7 @@ ov::pass::MoveEltwiseUpThroughDataMovPerChannel::MoveEltwiseUpThroughDataMovPerCif (node->get_output_partial_shape(0).rank().is_dynamic())return false;- const size_t const_idx = ov::is_type<ov::op::v0::Constant>(node->get_input_node_ptr(0)) ? 0 : 1;+ const size_t const_idx = ov::is_type<v0::Constant>(node->get_input_node_ptr(0)) ? 0 : 1;const size_t data_flow_idx = (const_idx + 1) % 2;if (node->get_input_partial_shape(data_flow_idx).size() < node->get_input_partial_shape(const_idx).size())@@ -177,15 +184,12 @@ ov::pass::MoveEltwiseUpThroughDataMovPerChannel::MoveEltwiseUpThroughDataMovPerCreturn true;};- auto eltw_data_flow_in =- ov::pass::pattern::wrap_type<ov::op::v1::Reshape, ov::op::v0::Squeeze, ov::op::v0::Unsqueeze>(- pattern::consumers_count(1));- auto eltw_const_in = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(const_predicate);+ auto eltw_data_flow_in = wrap_type<v1::Reshape, v0::Squeeze, v0::Unsqueeze>(ov::pass::pattern::consumers_count(1));+ auto eltw_const_in = wrap_type<v0::Constant>(const_predicate);auto eltwise_pattern =- ov::pass::pattern::wrap_type<ov::op::util::BinaryElementwiseArithmetic>({eltw_data_flow_in, eltw_const_in},- eltw_predicate);+ wrap_type<op_util::BinaryElementwiseArithmetic>({eltw_data_flow_in, eltw_const_in}, eltw_predicate);- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto eltwise = pattern_map.at(eltwise_pattern).get_node_shared_ptr();@@ -193,7 +197,7 @@ ov::pass::MoveEltwiseUpThroughDataMovPerChannel::MoveEltwiseUpThroughDataMovPerCreturn false;}- const size_t const_idx = ov::is_type<ov::op::v0::Constant>(eltwise->get_input_node_ptr(0)) ? 0 : 1;+ const size_t const_idx = ov::is_type<v0::Constant>(eltwise->get_input_node_ptr(0)) ? 0 : 1;const size_t data_flow_idx = (const_idx + 1) % 2;auto const_shape = eltwise->get_input_shape(const_idx);@@ -218,8 +222,8 @@ ov::pass::MoveEltwiseUpThroughDataMovPerChannel::MoveEltwiseUpThroughDataMovPerCauto new_shape = ov::Shape(parent->get_input_partial_shape(0).size(), 1);new_shape[channel_idx] = const_shape[channel_idx];- auto old_const = ov::as_type_ptr<ov::op::v0::Constant>(eltwise->get_input_node_shared_ptr(const_idx));- auto new_const = std::make_shared<ov::op::v0::Constant>(*old_const, new_shape);+ auto old_const = ov::as_type_ptr<v0::Constant>(eltwise->get_input_node_shared_ptr(const_idx));+ auto new_const = std::make_shared<v0::Constant>(*old_const, new_shape);ov::replace_node_update_name(old_const, new_const);ov::replace_output_update_name(eltwise->output(0), eltwise->input_value(data_flow_idx));@@ -238,6 +242,6 @@ ov::pass::MoveEltwiseUpThroughDataMovPerChannel::MoveEltwiseUpThroughDataMovPerCreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(eltwise_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(eltwise_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/mul_conv_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/mul_conv_fusion.cppindex 13cad550396..df31605a3f6 100644--- a/src/common/transformations/src/transformations/common_optimizations/mul_conv_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/mul_conv_fusion.cpp@@ -20,21 +20,29 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::consumers_count;+using ov::pass::pattern::has_static_shape;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;ov::pass::MultiplyConvolutionFusion::MultiplyConvolutionFusion() {MATCHER_SCOPE(MultiplyConvolutionFusion);- auto input_pattern = pattern::any_input(pattern::has_static_rank());- auto mul_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input_pattern, mul_const_pattern},- pattern::consumers_count(1));- auto weights_pattern = pass::pattern::any_input(pattern::has_static_shape());- auto conv_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Convolution>({mul_pattern, weights_pattern});-- matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {+ auto input_pattern = any_input(ov::pass::pattern::has_static_rank());+ auto mul_const_pattern = wrap_type<v0::Constant>();+ auto mul_pattern = wrap_type<v1::Multiply>({input_pattern, mul_const_pattern}, consumers_count(1));+ auto weights_pattern = any_input(has_static_shape());+ auto conv_pattern = wrap_type<v1::Convolution>({mul_pattern, weights_pattern});++ matcher_pass_callback callback = [=](Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();// Can't fuse Multiply to Convolution if that Multiply is part of dequantization subgraph// since that breaks low precision transformations- if (ov::op::util::is_dequantization_subgraph(pattern_to_output.at(mul_pattern)))+ if (op_util::is_dequantization_subgraph(pattern_to_output.at(mul_pattern)))return false;const auto& weights = pattern_to_output.at(weights_pattern);@@ -48,7 +56,7 @@ ov::pass::MultiplyConvolutionFusion::MultiplyConvolutionFusion() {// Check if constant in multiply broadcasts input's shape.// If this is the case, we cannot perform the transformation as// 'bare' input's shape will not be aligned with weights.- if (ov::op::util::check_for_broadcast(mul_const_shape, input_shape)) {+ if (op_util::check_for_broadcast(mul_const_shape, input_shape)) {return false;}@@ -56,12 +64,12 @@ ov::pass::MultiplyConvolutionFusion::MultiplyConvolutionFusion() {// Also if mul_const's rank matches weights rank and mul_const.shape[0] != 1// then we can't fuse the multiply, since first dimension in mul_const corresponds to// batch size, while first dimension in weights corresponds to output channel count- if (!ov::op::util::check_for_broadcast(weights_shape, mul_const_shape) ||+ if (!op_util::check_for_broadcast(weights_shape, mul_const_shape) ||(weights_shape.size() == mul_const_shape.size() && mul_const_shape[0] != 1)) {return false;}- auto weights_multiply = std::make_shared<ov::op::v1::Multiply>(weights, mul_const);+ auto weights_multiply = std::make_shared<v1::Multiply>(weights, mul_const);std::shared_ptr<Node> new_weights = ov::util::get_constant_from_source(weights_multiply);if (!new_weights)new_weights = weights_multiply;@@ -76,25 +84,24 @@ ov::pass::MultiplyConvolutionFusion::MultiplyConvolutionFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(conv_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(conv_pattern, matcher_name);register_matcher(m, callback);}ov::pass::MultiplyGroupConvolutionFusion::MultiplyGroupConvolutionFusion() {MATCHER_SCOPE(MultiplyGroupConvolutionFusion);- auto input_pattern = pattern::any_input();- auto mul_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input_pattern, mul_const_pattern},- pattern::consumers_count(1));- auto weights_pattern = pass::pattern::any_input(pattern::has_static_shape());- auto conv_pattern = ov::pass::pattern::wrap_type<ov::op::v1::GroupConvolution>({mul_pattern, weights_pattern});-- matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {+ auto input_pattern = any_input();+ auto mul_const_pattern = wrap_type<v0::Constant>();+ auto mul_pattern = wrap_type<v1::Multiply>({input_pattern, mul_const_pattern}, consumers_count(1));+ auto weights_pattern = any_input(has_static_shape());+ auto conv_pattern = wrap_type<v1::GroupConvolution>({mul_pattern, weights_pattern});++ matcher_pass_callback callback = [=](Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();// Can't fuse Multiply to Convolution if that Multiply is part of dequantization subgraph// since that breaks low precision transformations- if (ov::op::util::is_dequantization_subgraph(pattern_to_output.at(mul_pattern)))+ if (op_util::is_dequantization_subgraph(pattern_to_output.at(mul_pattern)))return false;const auto& weights = pattern_to_output.at(weights_pattern);@@ -108,7 +115,7 @@ ov::pass::MultiplyGroupConvolutionFusion::MultiplyGroupConvolutionFusion() {// Check if constant in multiply broadcasts input's shape.// If this is the case, we cannot perform the transformation as// 'bare' input's shape will not be aligned with weights.- if (ov::op::util::check_for_broadcast(mul_const_shape, input_shape)) {+ if (op_util::check_for_broadcast(mul_const_shape, input_shape)) {return false;}@@ -127,16 +134,16 @@ ov::pass::MultiplyGroupConvolutionFusion::MultiplyGroupConvolutionFusion() {// Reshape mul_const from shape (1, C, H, W) to (G, 1, C / G, H, W) to match GroupConvolution weights formatShape new_shape{G, 1, C};std::copy(mul_const_shape.begin() + 2, mul_const_shape.end(), std::back_inserter(new_shape));- if (!ov::op::util::check_for_broadcast(weights_shape, new_shape)) {+ if (!op_util::check_for_broadcast(weights_shape, new_shape)) {return false;}- mul_const = std::make_shared<ov::op::v1::Reshape>(- mul_const,- ov::op::v0::Constant::create(element::u64, Shape{new_shape.size()}, new_shape),- false);+ mul_const =+ std::make_shared<v1::Reshape>(mul_const,+ v0::Constant::create(element::u64, Shape{new_shape.size()}, new_shape),+ false);}- auto weights_multiply = std::make_shared<ov::op::v1::Multiply>(weights, mul_const);+ auto weights_multiply = std::make_shared<v1::Multiply>(weights, mul_const);std::shared_ptr<Node> new_weights = ov::util::get_constant_from_source(weights_multiply);if (!new_weights)new_weights = weights_multiply;@@ -151,26 +158,24 @@ ov::pass::MultiplyGroupConvolutionFusion::MultiplyGroupConvolutionFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(conv_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(conv_pattern, matcher_name);register_matcher(m, callback);}ov::pass::MultiplyConvolutionBackpropDataFusion::MultiplyConvolutionBackpropDataFusion() {MATCHER_SCOPE(MultiplyConvolutionBackpropDataFusion);- auto input_pattern = pattern::any_input();- auto mul_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input_pattern, mul_const_pattern},- pattern::consumers_count(1));- auto weights_pattern = pass::pattern::any_input(pattern::has_static_shape());- auto conv_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::ConvolutionBackpropData>({mul_pattern, weights_pattern});-- matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {+ auto input_pattern = any_input();+ auto mul_const_pattern = wrap_type<v0::Constant>();+ auto mul_pattern = wrap_type<v1::Multiply>({input_pattern, mul_const_pattern}, consumers_count(1));+ auto weights_pattern = any_input(has_static_shape());+ auto conv_pattern = wrap_type<v1::ConvolutionBackpropData>({mul_pattern, weights_pattern});++ matcher_pass_callback callback = [=](Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();// Can't fuse Multiply to Convolution if that Multiply is part of dequantization subgraph// since that breaks low precision transformations- if (ov::op::util::is_dequantization_subgraph(pattern_to_output.at(mul_pattern)))+ if (op_util::is_dequantization_subgraph(pattern_to_output.at(mul_pattern)))return false;const auto& weights = pattern_to_output.at(weights_pattern);@@ -183,7 +188,7 @@ ov::pass::MultiplyConvolutionBackpropDataFusion::MultiplyConvolutionBackpropData// Check if constant in multiply broadcasts input's shape.// If this is the case, we cannot perform the transformation as// 'bare' input's shape will not be aligned with weights.- if (ov::op::util::check_for_broadcast(mul_const_shape, input_shape)) {+ if (op_util::check_for_broadcast(mul_const_shape, input_shape)) {return false;}@@ -204,16 +209,16 @@ ov::pass::MultiplyConvolutionBackpropDataFusion::MultiplyConvolutionBackpropData// Reshape mul_const from shape (1, C, 1, 1) to (C, 1, 1, 1) to match ConvolutionBackpropData weights formatShape new_shape{mul_const_shape[1], 1};new_shape.insert(new_shape.end(), mul_const_shape.size() - 2, 1);- if (!ov::op::util::check_for_broadcast(weights_shape, new_shape)) {+ if (!op_util::check_for_broadcast(weights_shape, new_shape)) {return false;}- mul_const = std::make_shared<ov::op::v1::Reshape>(- mul_const,- ov::op::v0::Constant::create(element::u64, Shape{new_shape.size()}, new_shape),- false);+ mul_const =+ std::make_shared<v1::Reshape>(mul_const,+ v0::Constant::create(element::u64, Shape{new_shape.size()}, new_shape),+ false);}- auto weights_multiply = std::make_shared<ov::op::v1::Multiply>(weights, mul_const);+ auto weights_multiply = std::make_shared<v1::Multiply>(weights, mul_const);std::shared_ptr<Node> new_weights = ov::util::get_constant_from_source(weights_multiply);if (!new_weights)new_weights = weights_multiply;@@ -228,26 +233,24 @@ ov::pass::MultiplyConvolutionBackpropDataFusion::MultiplyConvolutionBackpropDatareturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(conv_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(conv_pattern, matcher_name);register_matcher(m, callback);}ov::pass::MultiplyGroupConvolutionBackpropDataFusion::MultiplyGroupConvolutionBackpropDataFusion() {MATCHER_SCOPE(MultiplyGroupConvolutionBackpropDataFusion);- auto input_pattern = pattern::any_input();- auto mul_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input_pattern, mul_const_pattern},- pattern::consumers_count(1));- auto weights_pattern = pass::pattern::any_input(pattern::has_static_shape());- auto conv_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::GroupConvolutionBackpropData>({mul_pattern, weights_pattern});-- matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {+ auto input_pattern = any_input();+ auto mul_const_pattern = wrap_type<v0::Constant>();+ auto mul_pattern = wrap_type<v1::Multiply>({input_pattern, mul_const_pattern}, consumers_count(1));+ auto weights_pattern = any_input(has_static_shape());+ auto conv_pattern = wrap_type<v1::GroupConvolutionBackpropData>({mul_pattern, weights_pattern});++ matcher_pass_callback callback = [=](Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();// Can't fuse Multiply to Convolution if that Multiply is part of dequantization subgraph// since that breaks low precision transformations- if (ov::op::util::is_dequantization_subgraph(pattern_to_output.at(mul_pattern)))+ if (op_util::is_dequantization_subgraph(pattern_to_output.at(mul_pattern)))return false;const auto& weights = pattern_to_output.at(weights_pattern);@@ -259,7 +262,7 @@ ov::pass::MultiplyGroupConvolutionBackpropDataFusion::MultiplyGroupConvolutionBa// Check if constant in multiply broadcasts input's shape.// If this is the case, we cannot perform the transformation as// 'bare' input's shape will not be aligned with weights.- if (ov::op::util::check_for_broadcast(mul_const_shape, input_shape)) {+ if (op_util::check_for_broadcast(mul_const_shape, input_shape)) {return false;}@@ -283,16 +286,16 @@ ov::pass::MultiplyGroupConvolutionBackpropDataFusion::MultiplyGroupConvolutionBaauto C = mul_const_shape[1] / G;Shape new_shape{G, C, 1};new_shape.insert(new_shape.end(), mul_const_shape.size() - 2, 1);- if (!ov::op::util::check_for_broadcast(weights_shape, new_shape)) {+ if (!op_util::check_for_broadcast(weights_shape, new_shape)) {return false;}- mul_const = std::make_shared<ov::op::v1::Reshape>(- mul_const,- ov::op::v0::Constant::create(element::u64, Shape{new_shape.size()}, new_shape),- false);+ mul_const =+ std::make_shared<v1::Reshape>(mul_const,+ v0::Constant::create(element::u64, Shape{new_shape.size()}, new_shape),+ false);}- auto weights_multiply = std::make_shared<ov::op::v1::Multiply>(weights, mul_const);+ auto weights_multiply = std::make_shared<v1::Multiply>(weights, mul_const);std::shared_ptr<Node> new_weights = ov::util::get_constant_from_source(weights_multiply);if (!new_weights)new_weights = weights_multiply;@@ -307,6 +310,6 @@ ov::pass::MultiplyGroupConvolutionBackpropDataFusion::MultiplyGroupConvolutionBareturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(conv_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(conv_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/mul_fake_quantize_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/mul_fake_quantize_fusion.cppindex a55c574e051..5d7bb8f0413 100644--- a/src/common/transformations/src/transformations/common_optimizations/mul_fake_quantize_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/mul_fake_quantize_fusion.cpp@@ -20,33 +20,34 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;ov::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() {MATCHER_SCOPE(MulFakeQuantizeFusion);- auto input_pattern = pass::pattern::any_input();- auto const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input_pattern, const_pattern}, pattern::consumers_count(1));- auto fq_pattern = ov::pass::pattern::wrap_type<ov::op::v0::FakeQuantize>({mul_pattern,- pass::pattern::any_input(),- pass::pattern::any_input(),- pass::pattern::any_input(),- pass::pattern::any_input()});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ auto input_pattern = any_input();+ auto const_pattern = wrap_type<v0::Constant>();+ auto mul_pattern = wrap_type<v1::Multiply>({input_pattern, const_pattern}, ov::pass::pattern::consumers_count(1));+ auto fq_pattern = wrap_type<v0::FakeQuantize>({mul_pattern, any_input(), any_input(), any_input(), any_input()});+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_value_map = m.get_pattern_value_map();const auto& input = pattern_value_map.at(input_pattern);const auto& type = input.get_element_type();if (type.bitwidth() < element::f32.bitwidth())return false;- auto fq = ov::as_type_ptr<ov::op::v0::FakeQuantize>(pattern_value_map.at(fq_pattern).get_node_shared_ptr());+ auto fq = ov::as_type_ptr<v0::FakeQuantize>(pattern_value_map.at(fq_pattern).get_node_shared_ptr());if (!fq)return false;- auto mul_const =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_value_map.at(const_pattern).get_node_shared_ptr());+ auto mul_const = ov::as_type_ptr<v0::Constant>(pattern_value_map.at(const_pattern).get_node_shared_ptr());if (!mul_const)return false;auto const_shape = mul_const->get_shape();- if (!ov::op::util::check_for_broadcast(input.get_partial_shape(), const_shape)) {+ if (!op_util::check_for_broadcast(input.get_partial_shape(), const_shape)) {// We can't eliminate Multiply if Constant input broadcasts another input shape because// when we reconnect input from Multiply to FQ won't broadcast given input, so it will result// in shape collision.@@ -65,9 +66,9 @@ ov::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() {if (!is_single_value) {float v;- is_single_value = ov::op::util::get_single_value(mul_const, v);+ is_single_value = op_util::get_single_value(mul_const, v);if (is_single_value) {- new_const = std::make_shared<ov::op::v0::Constant>(mul_const->get_element_type(), Shape{1}, v);+ new_const = std::make_shared<v0::Constant>(mul_const->get_element_type(), Shape{1}, v);const_shape = Shape{1};}}@@ -81,9 +82,9 @@ ov::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() {if (diff > 0) {// Reshape constants like (C, 1, 1) to (1, C, 1, 1)const_shape.insert(const_shape.begin(), diff, 1);- new_const = std::make_shared<ov::op::v1::Reshape>(+ new_const = std::make_shared<v1::Reshape>(new_const,- ov::op::v0::Constant::create(element::u64, Shape{const_shape.size()}, const_shape),+ v0::Constant::create(element::u64, Shape{const_shape.size()}, const_shape),false);}@@ -97,17 +98,17 @@ ov::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() {// Concat LPT transformation supports per tensor quantization onlybool fq_user_is_concat =std::any_of(fq_users.begin(), fq_users.end(), [](const std::shared_ptr<Node> node_ptr) -> bool {- return is_type<ov::op::v0::Concat>(node_ptr);+ return is_type<v0::Concat>(node_ptr);});if (fq_user_is_concat)return false;}- auto input_low_div = std::make_shared<ov::op::v1::Divide>(fq->input_value(1), new_const);+ auto input_low_div = std::make_shared<v1::Divide>(fq->input_value(1), new_const);std::shared_ptr<Node> new_input_low = ov::util::get_constant_from_source(input_low_div);if (!new_input_low)new_input_low = input_low_div;- auto input_high_div = std::make_shared<ov::op::v1::Divide>(fq->input_value(2), new_const);+ auto input_high_div = std::make_shared<v1::Divide>(fq->input_value(2), new_const);std::shared_ptr<Node> new_input_high = ov::util::get_constant_from_source(input_high_div);if (!new_input_high)new_input_high = input_high_div;@@ -124,6 +125,6 @@ ov::pass::MulFakeQuantizeFusion::MulFakeQuantizeFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(fq_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(fq_pattern, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/mvn_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/mvn_fusion.cppindex 9db25fa41b3..06fecb5c69b 100644--- a/src/common/transformations/src/transformations/common_optimizations/mvn_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/mvn_fusion.cpp@@ -26,11 +26,20 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;+using ov::pass::pattern::op::Or;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v6 = ov::op::v6;+namespace op_util = ov::op::util;template <class T>std::function<bool(ov::Output<ov::Node>)> value_is_equal_to(const std::vector<T>& ref_values) {return [ref_values](ov::Output<ov::Node> output) -> bool {auto node = output.get_node_shared_ptr();- if (auto const_node = ov::as_type_ptr<ov::op::v0::Constant>(node)) {+ if (auto const_node = ov::as_type_ptr<v0::Constant>(node)) {return const_node->template cast_vector<T>() == ref_values;}return false;@@ -41,89 +50,87 @@ ov::pass::MVNFusionWithoutConstants::MVNFusionWithoutConstants() {MATCHER_SCOPE(MVNFusionWithoutConstants);// Detect MVN decomposition pattern:// (x - ReduceMean(x, axes)) / (Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) + eps)- auto x = pattern::any_input();+ auto x = any_input();// (x - ReduceMean(x, axes))// `------mean1-------'- auto mean1_axes = pattern::wrap_type<ov::op::v0::Constant>();- auto mean1 = pattern::wrap_type<ov::op::v1::ReduceMean>({x, mean1_axes});+ auto mean1_axes = wrap_type<v0::Constant>();+ auto mean1 = wrap_type<v1::ReduceMean>({x, mean1_axes});// (x - ReduceMean(x, axes))// `-sub1------------------'- auto sub1 = pattern::wrap_type<ov::op::v1::Subtract>({x, mean1});+ auto sub1 = wrap_type<v1::Subtract>({x, mean1});// Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2))// `---mean2----------'- auto mean2_axes = pattern::wrap_type<ov::op::v0::Constant>();- auto mean2 = pattern::wrap_type<ov::op::v1::ReduceMean>({x, mean2_axes});+ auto mean2_axes = wrap_type<v0::Constant>();+ auto mean2 = wrap_type<v1::ReduceMean>({x, mean2_axes});// Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2))// `-sub2------------------'- auto sub2 = pattern::wrap_type<ov::op::v1::Subtract>({x, mean2});+ auto sub2 = wrap_type<v1::Subtract>({x, mean2});- const auto reuseSub1OrNot = std::make_shared<pattern::op::Or>(OutputVector{sub1, sub2});- const auto optionalConvert = pattern::optional<ov::op::v0::Convert>(reuseSub1OrNot);+ const auto reuseSub1OrNot = std::make_shared<Or>(OutputVector{sub1, sub2});+ const auto optionalConvert = ov::pass::pattern::optional<v0::Convert>(reuseSub1OrNot);// Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2))// `---------------------power--'- auto const_2 = pattern::wrap_type<ov::op::v0::Constant>(value_is_equal_to<float>({2.0}));- auto power = pattern::wrap_type<ov::op::v1::Power>({optionalConvert, const_2});+ auto const_2 = wrap_type<v0::Constant>(value_is_equal_to<float>({2.0}));+ auto power = wrap_type<v1::Power>({optionalConvert, const_2});// Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2))// `---mean3--------------------------------'- auto mean3_axes = pattern::wrap_type<ov::op::v0::Constant>();- auto mean3 = pattern::wrap_type<ov::op::v1::ReduceMean>({power, mean3_axes});+ auto mean3_axes = wrap_type<v0::Constant>();+ auto mean3 = wrap_type<v1::ReduceMean>({power, mean3_axes});- auto const_0_5 = pattern::wrap_type<ov::op::v0::Constant>(value_is_equal_to<float>({0.5}));- auto eps = pattern::wrap_type<ov::op::v0::Constant>();+ auto const_0_5 = wrap_type<v0::Constant>(value_is_equal_to<float>({0.5}));+ auto eps = wrap_type<v0::Constant>();// ------------------- OUTSIDE_SQRT ----------------------// Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2))// `--Power--------------------------------------'- auto power_sqrt_os = pattern::wrap_type<ov::op::v1::Power>({mean3, const_0_5});- auto sqrt_os = pattern::wrap_type<ov::op::v0::Sqrt>({mean3});- const auto powerOrSqrt_os = std::make_shared<pattern::op::Or>(OutputVector{power_sqrt_os, sqrt_os});+ auto power_sqrt_os = wrap_type<v1::Power>({mean3, const_0_5});+ auto sqrt_os = wrap_type<v0::Sqrt>({mean3});+ const auto powerOrSqrt_os = std::make_shared<Or>(OutputVector{power_sqrt_os, sqrt_os});// Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) + eps// `----------------------------------------------Add---'- auto add_eps_os = pattern::wrap_type<ov::op::v1::Add>({powerOrSqrt_os, eps});+ auto add_eps_os = wrap_type<v1::Add>({powerOrSqrt_os, eps});// ------------------- INSIDE_SQRT ----------------------// (Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps))// `-----------------------------------------------Add---'- auto add_eps_is = pattern::wrap_type<ov::op::v1::Add>({mean3, eps});+ auto add_eps_is = wrap_type<v1::Add>({mean3, eps});// Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2))// `--Power--------------------------------------'- auto power_sqrt_is = pattern::wrap_type<ov::op::v1::Power>({add_eps_is, const_0_5});- auto sqrt_is = pattern::wrap_type<ov::op::v0::Sqrt>({add_eps_is});- const auto powerOrSqrt_is = std::make_shared<pattern::op::Or>(OutputVector{power_sqrt_is, sqrt_is});+ auto power_sqrt_is = wrap_type<v1::Power>({add_eps_is, const_0_5});+ auto sqrt_is = wrap_type<v0::Sqrt>({add_eps_is});+ const auto powerOrSqrt_is = std::make_shared<Or>(OutputVector{power_sqrt_is, sqrt_is});- auto outsideOrInside = std::make_shared<pattern::op::Or>(OutputVector{add_eps_os, powerOrSqrt_is});+ auto outsideOrInside = std::make_shared<Or>(OutputVector{add_eps_os, powerOrSqrt_is});// Final Divide- auto const_neg_1 = pattern::wrap_type<ov::op::v0::Constant>(value_is_equal_to<float>({-1}));- auto power_div = pattern::wrap_type<ov::op::v1::Power>({outsideOrInside, const_neg_1});- auto div = pattern::wrap_type<ov::op::v1::Multiply>({sub1, power_div});+ auto const_neg_1 = wrap_type<v0::Constant>(value_is_equal_to<float>({-1}));+ auto power_div = wrap_type<v1::Power>({outsideOrInside, const_neg_1});+ auto div = wrap_type<v1::Multiply>({sub1, power_div});- auto div_alt = pattern::wrap_type<ov::op::v1::Divide>({sub1, outsideOrInside});- const auto powerMulOrDiv = std::make_shared<pattern::op::Or>(OutputVector{div, div_alt});+ auto div_alt = wrap_type<v1::Divide>({sub1, outsideOrInside});+ const auto powerMulOrDiv = std::make_shared<Or>(OutputVector{div, div_alt});- ov::matcher_pass_callback matcher_pass_callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto exp_input = pattern_to_output.at(x);- auto const_eps_node = ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(eps).get_node_shared_ptr());+ auto const_eps_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(eps).get_node_shared_ptr());float eps_value;- if (!ov::op::util::get_single_value(const_eps_node, eps_value)) {+ if (!op_util::get_single_value(const_eps_node, eps_value)) {return false;}- auto axes_1_node =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(mean1_axes).get_node_shared_ptr());- auto axes_3_node =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(mean3_axes).get_node_shared_ptr());+ auto axes_1_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(mean1_axes).get_node_shared_ptr());+ auto axes_3_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(mean3_axes).get_node_shared_ptr());if (!axes_1_node || !axes_3_node) {return false;@@ -136,8 +143,7 @@ ov::pass::MVNFusionWithoutConstants::MVNFusionWithoutConstants() {return false;}if (pattern_to_output.count(mean2_axes)) {- auto axes_2_node =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(mean2_axes).get_node_shared_ptr());+ auto axes_2_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(mean2_axes).get_node_shared_ptr());if (!axes_2_node) {return false;}@@ -172,7 +178,7 @@ ov::pass::MVNFusionWithoutConstants::MVNFusionWithoutConstants() {} else {return false;}- auto mvn = std::make_shared<ov::op::v6::MVN>(exp_input, axes_1_node, true, eps_value, mode);+ auto mvn = std::make_shared<v6::MVN>(exp_input, axes_1_node, true, eps_value, mode);if (pattern_to_output.count(mean2) && pattern_to_output.count(sub2)) {nodes_to_copy_info.push_back(pattern_to_output.at(mean2).get_node_shared_ptr());@@ -197,7 +203,7 @@ ov::pass::MVNFusionWithoutConstants::MVNFusionWithoutConstants() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(powerMulOrDiv, matcher_name);+ auto m = std::make_shared<Matcher>(powerMulOrDiv, matcher_name);register_matcher(m, matcher_pass_callback);}@@ -205,81 +211,77 @@ ov::pass::MVNFusionWithConstantsInside::MVNFusionWithConstantsInside() {MATCHER_SCOPE(MVNFusionWithConstantsInside);// Detect MVN decomposition pattern:// (x - ReduceMean(x, axes)) * gamma / (Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) + eps) + beta- auto x = pattern::any_input();+ auto x = any_input();// (x - ReduceMean(x, axes))^2// `------mean1-------'- auto mean1_axes = pattern::wrap_type<ov::op::v0::Constant>();- auto mean1 = pattern::wrap_type<ov::op::v1::ReduceMean>({x, mean1_axes});+ auto mean1_axes = wrap_type<v0::Constant>();+ auto mean1 = wrap_type<v1::ReduceMean>({x, mean1_axes});// (x - ReduceMean(x, axes))^2// `-squared_difference------'- auto squared_difference = pattern::wrap_type<ov::op::v0::SquaredDifference>({x, mean1});+ auto squared_difference = wrap_type<v0::SquaredDifference>({x, mean1});// 1 / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps)// `---mean2--------------------------------'- auto mean2_axes = pattern::wrap_type<ov::op::v0::Constant>();- auto mean2 = pattern::wrap_type<ov::op::v1::ReduceMean>({squared_difference, mean2_axes});+ auto mean2_axes = wrap_type<v0::Constant>();+ auto mean2 = wrap_type<v1::ReduceMean>({squared_difference, mean2_axes});// 1 / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps)// `------------------------------------------add--'- auto eps = pattern::wrap_type<ov::op::v0::Constant>();- auto add_eps = pattern::wrap_type<ov::op::v1::Add>({mean2, eps});+ auto eps = wrap_type<v0::Constant>();+ auto add_eps = wrap_type<v1::Add>({mean2, eps});// 1 / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps)// `-power-------------------------------------------------'- auto const_0_5 = pattern::wrap_type<ov::op::v0::Constant>(value_is_equal_to<float>({-0.5}));- auto power = pattern::wrap_type<ov::op::v1::Power>({add_eps, const_0_5});+ auto const_0_5 = wrap_type<v0::Constant>(value_is_equal_to<float>({-0.5}));+ auto power = wrap_type<v1::Power>({add_eps, const_0_5});// gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps)// `---mul1----------------------------------------------------'- auto gamma = pattern::wrap_type<ov::op::v0::Constant>();- auto mul1 = pattern::wrap_type<ov::op::v1::Multiply>({power, gamma});+ auto gamma = wrap_type<v0::Constant>();+ auto mul1 = wrap_type<v1::Multiply>({power, gamma});// x * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps)// `---mul2--------------------------------------------------------'- auto mul2 = pattern::wrap_type<ov::op::v1::Multiply>({x, mul1});+ auto mul2 = wrap_type<v1::Multiply>({x, mul1});// ReduceMean(x, axes) * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) - beta// `-------------------mul3----------------------------------------------------------'- auto mul3 = pattern::wrap_type<ov::op::v1::Multiply>({mul1, mean1});+ auto mul3 = wrap_type<v1::Multiply>({mul1, mean1});// beta - ReduceMean(x, axes) * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps)// `---sub-----------------------------------------------------------------------------------'- auto beta = pattern::wrap_type<ov::op::v0::Constant>();- auto sub = pattern::wrap_type<ov::op::v1::Subtract>({beta, mul3});+ auto beta = wrap_type<v0::Constant>();+ auto sub = wrap_type<v1::Subtract>({beta, mul3});// Final Add// x * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) +// beta - ReduceMean(x, axes) * gamma / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) =// gamma * (x - ReduceMean(x, axes)) / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps) + beta- auto add = pattern::wrap_type<ov::op::v1::Add>({mul2, sub});+ auto add = wrap_type<v1::Add>({mul2, sub});- ov::matcher_pass_callback matcher_pass_callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto x_output = pattern_to_output.at(x);- auto const_0_5_node =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(const_0_5).get_node_shared_ptr());- auto const_gamma_node =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(gamma).get_node_shared_ptr());- auto const_beta_node = ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(beta).get_node_shared_ptr());- auto const_eps_node = ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(eps).get_node_shared_ptr());+ auto const_0_5_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(const_0_5).get_node_shared_ptr());+ auto const_gamma_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(gamma).get_node_shared_ptr());+ auto const_beta_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(beta).get_node_shared_ptr());+ auto const_eps_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(eps).get_node_shared_ptr());if (!const_0_5_node || !const_beta_node || !const_gamma_node || !const_eps_node) {return false;}float eps_value;- bool valid_constant_values = ov::op::util::has_constant_value<float>(const_0_5_node, -0.5) &&- ov::op::util::get_single_value(const_eps_node, eps_value);+ bool valid_constant_values = op_util::has_constant_value<float>(const_0_5_node, -0.5) &&+ op_util::get_single_value(const_eps_node, eps_value);if (!valid_constant_values) {return false;}- auto axes_1_node =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(mean1_axes).get_node_shared_ptr());- auto axes_2_node =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(mean2_axes).get_node_shared_ptr());+ auto axes_1_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(mean1_axes).get_node_shared_ptr());+ auto axes_2_node = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(mean2_axes).get_node_shared_ptr());if (!axes_1_node || !axes_2_node) {return false;}@@ -290,10 +292,9 @@ ov::pass::MVNFusionWithConstantsInside::MVNFusionWithConstantsInside() {return false;}- auto mvn =- std::make_shared<ov::op::v6::MVN>(x_output, axes_1_node, true, eps_value, ov::op::MVNEpsMode::INSIDE_SQRT);- auto mul_gamma = std::make_shared<ov::op::v1::Multiply>(mvn, const_gamma_node);- auto add_beta = std::make_shared<ov::op::v1::Add>(mul_gamma, const_beta_node);+ auto mvn = std::make_shared<v6::MVN>(x_output, axes_1_node, true, eps_value, ov::op::MVNEpsMode::INSIDE_SQRT);+ auto mul_gamma = std::make_shared<v1::Multiply>(mvn, const_gamma_node);+ auto add_beta = std::make_shared<v1::Add>(mul_gamma, const_beta_node);ov::copy_runtime_info({pattern_to_output.at(mean1).get_node_shared_ptr(),pattern_to_output.at(squared_difference).get_node_shared_ptr(),@@ -310,6 +311,6 @@ ov::pass::MVNFusionWithConstantsInside::MVNFusionWithConstantsInside() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(add, matcher_name);+ auto m = std::make_shared<Matcher>(add, matcher_name);register_matcher(m, matcher_pass_callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.cppindex 0ed51f7cbde..0dbfa850a1d 100644--- a/src/common/transformations/src/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/nearest_neighbor_upsampling_fusion.cpp@@ -26,6 +26,12 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;++namespace ov::pass {+namespace {using namespace ov;@@ -52,7 +58,7 @@ std::vector<float> get_scales_from_mul_const_shape(const Shape& s, uint64_t inpureturn scales;}-bool check_concat_1(const std::shared_ptr<ov::op::v0::Concat>& concat, const Shape& shape) {+bool check_concat_1(const std::shared_ptr<v0::Concat>& concat, const Shape& shape) {size_t rank = shape.size();const auto inputs = concat->input_values();@@ -63,17 +69,17 @@ bool check_concat_1(const std::shared_ptr<ov::op::v0::Concat>& concat, const Shastd::vector<int64_t> input_constants(num_of_input_values, 1);for (size_t i = 1; i < num_of_input_values; ++i) {- const auto& current_input = ov::as_type_ptr<ov::op::v0::Unsqueeze>(inputs[i].get_node_shared_ptr());+ const auto& current_input = ov::as_type_ptr<v0::Unsqueeze>(inputs[i].get_node_shared_ptr());if (!current_input)return false;const auto current_input_axis =- ov::as_type_ptr<ov::op::v0::Constant>(current_input->input_value(1).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(current_input->input_value(1).get_node_shared_ptr());if (!current_input_axis || current_input_axis->cast_vector<int64_t>() != std::vector<int64_t>{0})return false;const auto unsqueezed_const =- ov::as_type_ptr<ov::op::v0::Constant>(current_input->input_value(0).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(current_input->input_value(0).get_node_shared_ptr());if (!unsqueezed_const)return false;@@ -103,7 +109,7 @@ bool check_concat_1(const std::shared_ptr<ov::op::v0::Concat>& concat, const Sha//// This function gets a new spatial shape from unsqueezed constants of 'concat_2', that is, the vector with elements// [newD_1, newD_2, ..., newD_{r - 2}].-std::vector<int64_t> get_new_spatial_shape_from_concat_2(const std::shared_ptr<ov::op::v0::Concat>& concat,+std::vector<int64_t> get_new_spatial_shape_from_concat_2(const std::shared_ptr<v0::Concat>& concat,const Shape& input_shape) {size_t rank = input_shape.size();@@ -116,17 +122,17 @@ std::vector<int64_t> get_new_spatial_shape_from_concat_2(const std::shared_ptr<ostd::vector<int64_t> input_constants(num_of_input_values - 1, 0);for (size_t i = 1; i < num_of_input_values; ++i) {- const auto& current_input = ov::as_type_ptr<ov::op::v0::Unsqueeze>(inputs[i].get_node_shared_ptr());+ const auto& current_input = ov::as_type_ptr<v0::Unsqueeze>(inputs[i].get_node_shared_ptr());if (!current_input)return {};const auto current_input_axis =- ov::as_type_ptr<ov::op::v0::Constant>(current_input->input_value(1).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(current_input->input_value(1).get_node_shared_ptr());if (!current_input_axis || current_input_axis->cast_vector<int64_t>() != std::vector<int64_t>{0})return {};const auto unsqueezed_const =- ov::as_type_ptr<ov::op::v0::Constant>(current_input->input_value(0).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(current_input->input_value(0).get_node_shared_ptr());if (!unsqueezed_const)return {};@@ -146,7 +152,7 @@ std::vector<int64_t> get_new_spatial_shape_from_concat_2(const std::shared_ptr<o}} // namespace-ov::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() {+NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() {MATCHER_SCOPE(NearestNeighborUpsamplingFusion);// This transformation looks for Interpolate layer implemented using simple operations, namely ShapeOf,// StridedSlice, Concat, Reshape, Mul, and replaces found pattern with a sequence of Shape, StridedSlice, Const,@@ -173,54 +179,29 @@ ov::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() {// | | | | |// | | | | |// | | | |-------------| |------------| | | |-------------|- // |--------------| | | | | | | Constant | | | |- // | | Constant | | | | | 0|<--| value: H | | | |- // 0|<--| value: new_H | | | | | | |------------| | |- // | | |--------------| | | | | | | | |+ // | | | | | | Constant | | | | |+ // | | 1|<-----| 0|<--| value: H | | 1|<-----| 0|<--| Constant// | | | | | Unsqueeze | |------------| | | | Unsqueeze |- // |------------| | | | | | | Constant | | | |- // | | Constant | | | 1|<-----| 1|<--| value: 0 | | 1|<-----| 1|<--|- // value: 0 | | | | |-------------| |------------| | |- // |-------------| |------------| | | | | | | |- // | |-------------| |------------| | | |-------------| |--------------| | | |- // | | | Constant | | | | | | Constant | | | | |- // 0|<--| value: 1 | | | | 0|<--| value: new_W | | | |- // | | |------------| | | | | |--------------| | | | |- // | | | | | | | | | Unsqueeze |- // |------------| | | | Unsqueeze | |------------| | | | |- // | | Constant | | | | | | Constant | | | 2|<-----| 1|<--|- // value: 0 | | 2|<-----| 1|<--| value: 0 | | | |+ // | value: new_H | | | | | | | | |+ // | |--------------| | | | | 1|<-----| 1|<--| Constant | |+ // | | 1|<-----| 1|<--| Constant | | | | |-------------|+ // | value: 0 | | | |-------------| | value: 0 | | | |// |-------------| |------------| | | |-------------| |------------| | | | | |- // | | | |-------------| |------------| | | |-------------|- // |------------| | | | | | | Constant | | | |- // | | Constant | | | | | 0|<--| value: W | | | |- // 0|<--| value: C | | | | | | |------------| | | |- // | |------------| | | | | | | | | |- // | | | | Unsqueeze | |------------| | | | Unsqueeze |- // |------------| | | | | | | Constant | | | |- // | | Constant | | | 3|<-----| 1|<--| value: 0 | | 3|<-----| 1|<--|- // value: 0 | | | | |-------------| |------------| |------|--------|- // |-------------| |------------| | | | |- // | | | |-------------| |------------| |- // | | | | | | Constant | |- // | | | | 0|<--| value: 1 | |- // | | | | | |------------| |- // | | | | | |- // | | | | Unsqueeze | |------------| |- // | | | | | | Constant | |- // | | 4|<-----| 1|<--| value: 0 | |- // | | | |-------------| |------------| |- // | | | |- // | | | |-------------| |------------| |- // | | | | | | Constant | |- // | | | | 0|<--| value: C | |- // | | | | | |------------| |- // | | | | | |- // | | | | Unsqueeze | |------------| |- // | | | | | | Constant | |- // | | 5|<-----| 1|<--| value: 0 | |- // | |------|--------| |-------------| |------------| |- // | | |+ // | Constant | | | | | | Constant | | | 2|<-----|+ // 0|<--| value: 1 | | 2|<-----| 0|<--| value: new_W | | | |+ // | | |------------| | | | | |--------------| | | | |+ // | | | | Unsqueeze | |------------| | | | |+ // Unsqueeze | |------------| | | | | | Constant | | |+ // 3|<-----| 1|<--| value: 0 | | 3|<-----| 1|<--| value: 0 | | | |+ // |-------------| |------------| |------|--------| |-------------| |------------| | | |+ // |-------------| |------------| | |-------------| |------------| | | | | |+ // | Constant | | | | | Constant | | | 4|<-----|+ // 0|<--| value: W | | | 0|<--| value: C | | | | |+ // | |------------| | | | |------------| | | | | |+ // | | | | | | | Unsqueeze | |------------| |+ // | Unsqueeze | |------------| | | 5|<-----| 1|<--| value: 0 | |+ // | 1|<--| value: 0 | | |------|--------| |-------------| |------------| |+ // |-------------| |------------| | | |// | | |// | |------------| |// | | |@@ -274,30 +255,28 @@ ov::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() {// 4) 'axes' input as a constant with the value [1, 2, ..., r - 2].//// Of course, the replacement shouldn't be done, if all S_i are equal to 1.- auto input = pass::pattern::any_input(pattern::has_static_shape());- auto concat_1 = pattern::wrap_type<ov::op::v0::Concat>();- auto concat_2 = pattern::wrap_type<ov::op::v0::Concat>();- auto reshape_1 = pattern::wrap_type<ov::op::v1::Reshape>({input, concat_1});- auto mul_const = pattern::wrap_type<ov::op::v0::Constant>(pattern::has_static_shape());- auto mul = pattern::wrap_type<ov::op::v1::Multiply>({reshape_1, mul_const});- auto reshape_2 = pattern::wrap_type<ov::op::v1::Reshape>({mul, concat_2});-- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input(pattern::has_static_shape());+ auto concat_1 = pattern::wrap_type<v0::Concat>();+ auto concat_2 = pattern::wrap_type<v0::Concat>();+ auto reshape_1 = pattern::wrap_type<v1::Reshape>({input, concat_1});+ auto mul_const = pattern::wrap_type<v0::Constant>(pattern::has_static_shape());+ auto mul = pattern::wrap_type<v1::Multiply>({reshape_1, mul_const});+ auto reshape_2 = pattern::wrap_type<v1::Reshape>({mul, concat_2});++ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();- const auto reshape_2_node =- ov::as_type_ptr<ov::op::v1::Reshape>(pattern_to_output.at(reshape_2).get_node_shared_ptr());- const auto mul_node = ov::as_type_ptr<ov::op::v1::Multiply>(pattern_to_output.at(mul).get_node_shared_ptr());+ const auto reshape_2_node = ov::as_type_ptr<v1::Reshape>(pattern_to_output.at(reshape_2).get_node_shared_ptr());+ const auto mul_node = ov::as_type_ptr<v1::Multiply>(pattern_to_output.at(mul).get_node_shared_ptr());if (!reshape_2_node || !mul_node)return false;const auto mul_const_node =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(mul_const).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_to_output.at(mul_const).get_node_shared_ptr());if (!mul_const_node)return false;- const auto reshape_1_node =- ov::as_type_ptr<ov::op::v1::Reshape>(pattern_to_output.at(reshape_1).get_node_shared_ptr());+ const auto reshape_1_node = ov::as_type_ptr<v1::Reshape>(pattern_to_output.at(reshape_1).get_node_shared_ptr());if (!reshape_1_node)return false;@@ -317,8 +296,7 @@ ov::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() {return false;}- const auto concat_1_node =- ov::as_type_ptr<ov::op::v0::Concat>(pattern_to_output.at(concat_1).get_node_shared_ptr());+ const auto concat_1_node = ov::as_type_ptr<v0::Concat>(pattern_to_output.at(concat_1).get_node_shared_ptr());if (!concat_1_node)return false;@@ -326,8 +304,7 @@ ov::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() {if (!check_concat_1(concat_1_node, input_shape))return false;- const auto concat_2_node =- ov::as_type_ptr<ov::op::v0::Concat>(pattern_to_output.at(concat_2).get_node_shared_ptr());+ const auto concat_2_node = ov::as_type_ptr<v0::Concat>(pattern_to_output.at(concat_2).get_node_shared_ptr());if (!concat_2_node)return false;@@ -336,9 +313,9 @@ ov::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() {return false;const auto ss_before_concat_1 =- ov::as_type_ptr<ov::op::v1::StridedSlice>(concat_1_node->input_value(0).get_node_shared_ptr());+ ov::as_type_ptr<v1::StridedSlice>(concat_1_node->input_value(0).get_node_shared_ptr());const auto ss_before_concat_2 =- ov::as_type_ptr<ov::op::v1::StridedSlice>(concat_2_node->input_value(0).get_node_shared_ptr());+ ov::as_type_ptr<v1::StridedSlice>(concat_2_node->input_value(0).get_node_shared_ptr());if (!ss_before_concat_1 || !ss_before_concat_2 || ss_before_concat_1.get() != ss_before_concat_2.get())return false;@@ -352,28 +329,27 @@ ov::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() {if (before_shapeof.get_node() != before_reshape_1.get_node())return false;- ov::op::v4::Interpolate::InterpolateAttrs attrs;- attrs.mode = ov::op::v4::Interpolate::InterpolateMode::NEAREST;- attrs.shape_calculation_mode = ov::op::v4::Interpolate::ShapeCalcMode::SCALES;- attrs.nearest_mode = ov::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR;+ v4::Interpolate::InterpolateAttrs attrs;+ attrs.mode = v4::Interpolate::InterpolateMode::NEAREST;+ attrs.shape_calculation_mode = v4::Interpolate::ShapeCalcMode::SCALES;+ attrs.nearest_mode = v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR;attrs.pads_begin = std::vector<size_t>{0};attrs.pads_end = std::vector<size_t>{0};attrs.antialias = false;- attrs.coordinate_transformation_mode = ov::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL;+ attrs.coordinate_transformation_mode = v4::Interpolate::CoordinateTransformMode::HALF_PIXEL;attrs.cube_coeff = -0.75f;const auto& input_node = pattern_to_output.at(input);const auto& type = input_node.get_element_type();- const auto scales_node = ov::op::v0::Constant::create(type, {scales.size()}, scales);- const auto sizes_node =- ov::op::v0::Constant::create(element::i64, {new_spatial_shape.size()}, new_spatial_shape);+ const auto scales_node = v0::Constant::create(type, {scales.size()}, scales);+ const auto sizes_node = v0::Constant::create(element::i64, {new_spatial_shape.size()}, new_spatial_shape);std::vector<int64_t> axes(input_rank - 2);std::iota(axes.begin(), axes.end(), static_cast<int64_t>(1));- const auto axes_node = ov::op::v0::Constant::create(element::i64, {axes.size()}, axes);+ const auto axes_node = v0::Constant::create(element::i64, {axes.size()}, axes);auto interpolate =- register_new_node<ov::op::v4::Interpolate>(before_shapeof, sizes_node, scales_node, axes_node, attrs);+ register_new_node<v4::Interpolate>(before_shapeof, sizes_node, scales_node, axes_node, attrs);interpolate->set_friendly_name(reshape_2_node->get_friendly_name());copy_runtime_info(@@ -384,6 +360,8 @@ ov::pass::NearestNeighborUpsamplingFusion::NearestNeighborUpsamplingFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reshape_2, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(reshape_2, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/nonzero_horizontal_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/nonzero_horizontal_fusion.cppindex 25adf3bd219..1043cca5796 100644--- a/src/common/transformations/src/transformations/common_optimizations/nonzero_horizontal_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/nonzero_horizontal_fusion.cpp@@ -13,20 +13,24 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::NonZeroHorizontalFusion::NonZeroHorizontalFusion() {+namespace v3 = ov::op::v3;++namespace ov::pass {++NonZeroHorizontalFusion::NonZeroHorizontalFusion() {MATCHER_SCOPE(NonZeroHorizontalFusion);- auto input_m = pass::pattern::any_input(ov::pass::pattern::consumers_more_than(1));- auto nonzero_m = pass::pattern::wrap_type<ov::op::v3::NonZero>({input_m});+ auto input_m = pattern::any_input(pattern::consumers_more_than(1));+ auto nonzero_m = pattern::wrap_type<v3::NonZero>({input_m});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();- const auto nonzero = ov::as_type_ptr<ov::op::v3::NonZero>(pattern_map.at(nonzero_m).get_node_shared_ptr());+ const auto nonzero = ov::as_type_ptr<v3::NonZero>(pattern_map.at(nonzero_m).get_node_shared_ptr());const auto out_prc = nonzero->get_output_type();bool status = false;auto replace_if_nodes_match = [&](const ov::Input<ov::Node>& in) {auto in_node = in.get_node();- auto cur_nonzero = ov::as_type<ov::op::v3::NonZero>(in_node);+ auto cur_nonzero = ov::as_type<v3::NonZero>(in_node);if (in_node != nonzero.get() && cur_nonzero && cur_nonzero->get_output_type() == out_prc) {status |= ov::replace_output_update_name(cur_nonzero->output(0), nonzero->output(0));}@@ -37,6 +41,8 @@ ov::pass::NonZeroHorizontalFusion::NonZeroHorizontalFusion() {return status;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(nonzero_m, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(nonzero_m, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp b/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cppindex a450bffcc78..e04656c1e8d 100644--- a/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/nop_elimination.cpp@@ -52,13 +52,20 @@#include "openvino/util/util.hpp"#include "transformations/utils/utils.hpp"-using namespace std;-using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v5 = ov::op::v5;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;+namespace ov::pass {++namespace {//`simplify_gather`, optimizes gather if Gather is gathering the// whole input tensor-static bool simplify_gather(shared_ptr<Node> node) {- if (auto gather = ov::as_type_ptr<ov::op::util::GatherBase>(node)) {+static bool simplify_gather(std::shared_ptr<Node> node) {+ if (auto gather = ov::as_type_ptr<op_util::GatherBase>(node)) {// check if we are gathering the whole inputauto data = gather->input_value(0);auto indices = gather->input_value(1);@@ -69,13 +76,13 @@ static bool simplify_gather(shared_ptr<Node> node) {}auto axis = gather->get_axis();- if (axis == ov::op::v1::Gather::AXIS_NOT_SET_VALUE) {+ if (axis == v1::Gather::AXIS_NOT_SET_VALUE) {OPENVINO_DEBUG("axis value not set");return false;}if (data.get_shape().size() != node->get_shape().size()) {- auto constant_indices = ov::as_type_ptr<ov::op::v0::Constant>(gather->input_value(1).get_node_shared_ptr());+ auto constant_indices = ov::as_type_ptr<v0::Constant>(gather->input_value(1).get_node_shared_ptr());if (!constant_indices)return false;// case_3: if input_shape is (1,3,5,5) and axis = 0, indices = 0, then gather is just a Squeeze@@ -83,7 +90,7 @@ static bool simplify_gather(shared_ptr<Node> node) {const auto const_indices = constant_indices->cast_vector<int64_t>();if (data.get_shape()[axis] == 1 && (constant_indices_size == 0 || constant_indices_size == 1) &&const_indices[0] == 0) {- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(gather->input_value(0), gather->input_value(2));+ auto squeeze = std::make_shared<v0::Squeeze>(gather->input_value(0), gather->input_value(2));squeeze->set_friendly_name(gather->get_friendly_name());ov::copy_runtime_info(gather, squeeze);ov::replace_node(gather, squeeze);@@ -107,13 +114,13 @@ static bool simplify_gather(shared_ptr<Node> node) {// op has Nop// check if the indices is constant- auto constant_indices = ov::as_type_ptr<ov::op::v0::Constant>(gather->input_value(1).get_node_shared_ptr());+ auto constant_indices = ov::as_type_ptr<v0::Constant>(gather->input_value(1).get_node_shared_ptr());if (!constant_indices) {return false;} else {// if ref_inidices == indices, we are capturing the// entire input tensor- vector<int64_t> ref_indices(data.get_shape()[axis], 0);+ std::vector<int64_t> ref_indices(data.get_shape()[axis], 0);iota(ref_indices.begin(), ref_indices.end(), 0);if (ref_indices == constant_indices->cast_vector<int64_t>()) {return replace_output_update_name(gather->output(0), gather->input_value(0));@@ -123,7 +130,7 @@ static bool simplify_gather(shared_ptr<Node> node) {return false;}-static bool eliminate_nop(const shared_ptr<Node>& node) {+static bool eliminate_nop(const std::shared_ptr<Node>& node) {// skip if shapes are dynamicif (node->get_input_partial_shape(0).is_dynamic() || node->get_output_partial_shape(0).is_dynamic()) {return false;@@ -152,7 +159,7 @@ static bool only_first_dim_dynamic(const PartialShape& pshape) {return false;}-static bool eliminate_reshape_v1(const shared_ptr<Node>& node) {+static bool eliminate_reshape_v1(const std::shared_ptr<Node>& node) {auto input = node->input_value(0);if (input.get_partial_shape().rank().is_static() && input.get_partial_shape().rank().same_scheme(1)) {@@ -174,8 +181,8 @@ static bool eliminate_reshape_v1(const shared_ptr<Node>& node) {}// eliminate redundant reshape, squeeze, or unsqueezeauto input_node = input.get_node_shared_ptr();- if (ov::as_type_ptr<ov::op::v0::Squeeze>(input_node) || ov::as_type_ptr<ov::op::v0::Unsqueeze>(input_node) ||- ov::as_type_ptr<ov::op::v1::Reshape>(input_node)) {+ if (ov::as_type_ptr<v0::Squeeze>(input_node) || ov::as_type_ptr<v0::Unsqueeze>(input_node) ||+ ov::as_type_ptr<v1::Reshape>(input_node)) {if (input_node->get_output_target_inputs(0).size() != 1)return false;@@ -186,13 +193,13 @@ static bool eliminate_reshape_v1(const shared_ptr<Node>& node) {input_node->get_input_partial_shape(0) == node->get_output_partial_shape(0)) {return replace_output_update_name(node->output(0), input_node->input_value(0));} else {- vector<int64_t> vi;+ std::vector<int64_t> vi;vi.reserve(shape.size());for (const auto& dim : shape) {vi.push_back(dim.is_dynamic() ? -1 : dim.get_length());}- auto pat = ov::op::v0::Constant::create<int64_t>(element::i64, Shape{shape.size()}, vi);- auto new_reshape = make_shared<ov::op::v1::Reshape>(input.get_node()->input_value(0), pat, false);+ auto pat = v0::Constant::create<int64_t>(element::i64, Shape{shape.size()}, vi);+ auto new_reshape = std::make_shared<v1::Reshape>(input.get_node()->input_value(0), pat, false);new_reshape->set_friendly_name(node->get_friendly_name());copy_runtime_info({input_node, node}, new_reshape);replace_node(node, new_reshape);@@ -216,7 +223,7 @@ static size_t count_unknown_dims(const PartialShape& ps) {return rc;}-static bool replace_squeeze_unsqueeze(const shared_ptr<Node>& node) {+static bool replace_squeeze_unsqueeze(const std::shared_ptr<Node>& node) {auto shape_ps = node->get_output_partial_shape(0);if (shape_ps.rank().get_length() == 0) {return false;@@ -224,7 +231,7 @@ static bool replace_squeeze_unsqueeze(const shared_ptr<Node>& node) {if (count_unknown_dims(shape_ps) > 1) {return false;}- vector<int64_t> target_shape;+ std::vector<int64_t> target_shape;for (auto i = 0; i < shape_ps.rank().get_length(); i++) {if (shape_ps[i].is_dynamic()) {target_shape.emplace_back(-1);@@ -233,15 +240,14 @@ static bool replace_squeeze_unsqueeze(const shared_ptr<Node>& node) {}}- shared_ptr<Node> reshape;+ std::shared_ptr<Node> reshape;auto input = node->input_value(0).get_node_shared_ptr();- auto pat = ov::op::v0::Constant::create<int64_t>(element::i64, Shape{target_shape.size()}, target_shape);+ auto pat = v0::Constant::create<int64_t>(element::i64, Shape{target_shape.size()}, target_shape);- if (ov::is_type<ov::op::v1::Reshape>(input) || ov::is_type<ov::op::v0::Squeeze>(input) ||- ov::is_type<ov::op::v0::Unsqueeze>(input)) {- reshape = make_shared<ov::op::v1::Reshape>(input->input_value(0), pat, false);+ if (ov::is_type<v1::Reshape>(input) || ov::is_type<v0::Squeeze>(input) || ov::is_type<v0::Unsqueeze>(input)) {+ reshape = std::make_shared<v1::Reshape>(input->input_value(0), pat, false);} else {- reshape = make_shared<ov::op::v1::Reshape>(node->input_value(0), pat, false);+ reshape = std::make_shared<v1::Reshape>(node->input_value(0), pat, false);}// skip if reshape is nop@@ -253,8 +259,8 @@ static bool replace_squeeze_unsqueeze(const shared_ptr<Node>& node) {}}-static vector<int64_t> get_unsqueeze_axes(const PartialShape& data_shape, const PartialShape& out_shape) {- vector<int64_t> axes;+static std::vector<int64_t> get_unsqueeze_axes(const PartialShape& data_shape, const PartialShape& out_shape) {+ std::vector<int64_t> axes;int64_t i = 0;for (auto o = 0; o < out_shape.rank().get_length(); o++) {if (i < data_shape.rank().get_length() && data_shape[i].same_scheme(out_shape[o])) {@@ -268,8 +274,8 @@ static vector<int64_t> get_unsqueeze_axes(const PartialShape& data_shape, constreturn axes;}-static vector<int64_t> get_squeeze_axes(const PartialShape& data_shape, const PartialShape& out_shape) {- vector<int64_t> axes;+static std::vector<int64_t> get_squeeze_axes(const PartialShape& data_shape, const PartialShape& out_shape) {+ std::vector<int64_t> axes;int64_t out_i = 0;for (auto i = 0; i < data_shape.rank().get_length(); i++) {if (out_i < out_shape.rank().get_length() && data_shape[i].same_scheme(out_shape[out_i])) {@@ -283,21 +289,21 @@ static vector<int64_t> get_squeeze_axes(const PartialShape& data_shape, const Pareturn axes;}-static bool eliminate_unsqueeze(const shared_ptr<Node>& node) {+static bool eliminate_unsqueeze(const std::shared_ptr<Node>& node) {auto out_shape = node->get_output_partial_shape(0);// try to replace all squeeze/unsqueeze with reshapeif (out_shape.rank().is_static() && out_shape.rank().get_length() != 0 && count_unknown_dims(out_shape) < 2) {return replace_squeeze_unsqueeze(node);}- auto unsqueeze = ov::as_type_ptr<ov::op::v0::Unsqueeze>(node);+ auto unsqueeze = ov::as_type_ptr<v0::Unsqueeze>(node);if (unsqueeze == nullptr)return false;auto input = unsqueeze->input_value(0).get_node_shared_ptr();- auto squeeze = ov::as_type_ptr<ov::op::v0::Squeeze>(input);- auto replace_unsqueeze_only = [&](const vector<int64_t>& axes) {- auto axes_const = ov::op::v0::Constant::create<int64_t>(element::i64, Shape{axes.size()}, axes);- auto new_unsq = make_shared<ov::op::v0::Unsqueeze>(input->input_value(0), axes_const);+ auto squeeze = ov::as_type_ptr<v0::Squeeze>(input);+ auto replace_unsqueeze_only = [&](const std::vector<int64_t>& axes) {+ auto axes_const = v0::Constant::create<int64_t>(element::i64, Shape{axes.size()}, axes);+ auto new_unsq = std::make_shared<v0::Unsqueeze>(input->input_value(0), axes_const);if (unsqueeze->get_output_partial_shape(0).same_scheme(new_unsq->get_output_partial_shape(0))) {return replace_node_update_name(unsqueeze, new_unsq);}@@ -324,8 +330,8 @@ static bool eliminate_unsqueeze(const shared_ptr<Node>& node) {// check if single squeeze can handle thisauto axes = get_squeeze_axes(data_shape, out_shape);if (data_shape.rank().get_length() - static_cast<int64_t>(axes.size()) == out_shape.rank().get_length()) {- auto axes_const = ov::op::v0::Constant::create<int64_t>(element::i64, Shape{axes.size()}, axes);- auto new_sq = make_shared<ov::op::v0::Squeeze>(input->input_value(0), axes_const);+ auto axes_const = v0::Constant::create<int64_t>(element::i64, Shape{axes.size()}, axes);+ auto new_sq = std::make_shared<v0::Squeeze>(input->input_value(0), axes_const);if (unsqueeze->get_output_partial_shape(0).same_scheme(new_sq->get_output_partial_shape(0))) {return replace_node_update_name(unsqueeze, new_sq);}@@ -335,7 +341,7 @@ static bool eliminate_unsqueeze(const shared_ptr<Node>& node) {return false;}// eliminate redundant unsqueeze->unsqueeze- auto unsqueeze_i = ov::as_type_ptr<ov::op::v0::Unsqueeze>(input);+ auto unsqueeze_i = ov::as_type_ptr<v0::Unsqueeze>(input);if (unsqueeze_i) {const auto& data_shape = unsqueeze_i->input_value(0).get_partial_shape();if (data_shape.rank().is_dynamic() || out_shape.rank().is_dynamic()) {@@ -348,47 +354,44 @@ static bool eliminate_unsqueeze(const shared_ptr<Node>& node) {return false;}+} // namespace+#define ECHO(NAME) #NAME#define STR(NAME) ECHO(NAME)-#define SIMPLE_MATCHER_PASS_DEFINITION(NAME, FUNC, ...) \- class NAME : public ov::pass::MatcherPass { \- public: \- OPENVINO_RTTI(STR(NAME), "0", ov::pass::MatcherPass); \- NAME() { \- MATCHER_SCOPE(NAME); \- auto match_node = ov::pass::pattern::wrap_type<__VA_ARGS__>(); \- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) { \- return FUNC(m.get_match_root()); \- }; \- auto m = make_shared<ov::pass::pattern::Matcher>(match_node, matcher_name); \- register_matcher(m, callback); \- } \+#define SIMPLE_MATCHER_PASS_DEFINITION(NAME, FUNC, ...) \+ class NAME : public ov::pass::MatcherPass { \+ public: \+ OPENVINO_RTTI(STR(NAME), "0", ov::pass::MatcherPass); \+ NAME() { \+ MATCHER_SCOPE(NAME); \+ auto match_node = pattern::wrap_type<__VA_ARGS__>(); \+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) { \+ return FUNC(m.get_match_root()); \+ }; \+ auto m = std::make_shared<pattern::Matcher>(match_node, matcher_name); \+ register_matcher(m, callback); \+ } \};-SIMPLE_MATCHER_PASS_DEFINITION(EliminateReshape, eliminate_reshape_v1, ov::op::v1::Reshape);-SIMPLE_MATCHER_PASS_DEFINITION(EliminateBroadcast, eliminate_nop, ov::op::v1::Broadcast, ov::op::v3::Broadcast);-SIMPLE_MATCHER_PASS_DEFINITION(EliminateGather,- simplify_gather,- ov::op::v1::Gather,- ov::op::v7::Gather,- ov::op::v8::Gather);+SIMPLE_MATCHER_PASS_DEFINITION(EliminateReshape, eliminate_reshape_v1, v1::Reshape);+SIMPLE_MATCHER_PASS_DEFINITION(EliminateBroadcast, eliminate_nop, v1::Broadcast, v3::Broadcast);+SIMPLE_MATCHER_PASS_DEFINITION(EliminateGather, simplify_gather, v1::Gather, ov::op::v7::Gather, v8::Gather);-pass::EliminateReduceReshape::EliminateReduceReshape() {+EliminateReduceReshape::EliminateReduceReshape() {MATCHER_SCOPE(EliminateReduceReshape);- using namespace pass::pattern;- auto axes = wrap_type<ov::op::v0::Constant>();- auto reduce_pattern = wrap_type<ov::op::util::ReductionBase>({any_input(), axes});- auto requested_shape_pattern = wrap_type<ov::op::v0::Constant>();+ auto axes = pattern::wrap_type<v0::Constant>();+ auto reduce_pattern = pattern::wrap_type<op_util::ReductionBase>({pattern::any_input(), axes});+ auto requested_shape_pattern = pattern::wrap_type<v0::Constant>();auto reshape_pattern =- wrap_type<ov::op::v1::Reshape>({reduce_pattern, requested_shape_pattern}, consumers_count(1));+ pattern::wrap_type<v1::Reshape>({reduce_pattern, requested_shape_pattern}, pattern::consumers_count(1));- matcher_pass_callback callback = [=](Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {auto pattern_map = m.get_pattern_map();auto reshape_node = m.get_match_root();auto reduce_node = pattern_map.at(reduce_pattern);- auto reshape = ov::as_type_ptr<ov::op::v1::Reshape>(reshape_node);- auto reduce = ov::as_type_ptr<ov::op::util::ReductionBase>(reduce_node);+ auto reshape = ov::as_type_ptr<v1::Reshape>(reshape_node);+ auto reduce = ov::as_type_ptr<op_util::ReductionBase>(reduce_node);if (!reshape || !reduce) {return false;}@@ -399,7 +402,7 @@ pass::EliminateReduceReshape::EliminateReduceReshape() {return false;}- auto requested_shape = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(requested_shape_pattern));+ auto requested_shape = ov::as_type_ptr<v0::Constant>(pattern_map.at(requested_shape_pattern));if (!requested_shape) {return false;}@@ -422,13 +425,13 @@ pass::EliminateReduceReshape::EliminateReduceReshape() {}};- auto m = make_shared<Matcher>(reshape_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(reshape_pattern, matcher_name);this->register_matcher(m, callback);}-pass::EliminatePad::EliminatePad() {+EliminatePad::EliminatePad() {MATCHER_SCOPE(EliminatePad);- auto pad_node_pattern = pattern::wrap_type<ov::op::util::PadBase>();+ auto pad_node_pattern = pattern::wrap_type<op_util::PadBase>();matcher_pass_callback callback = [=](pattern::Matcher& m) {auto pad = m.get_match_root();@@ -457,16 +460,16 @@ pass::EliminatePad::EliminatePad() {return replace_output_update_name(pad->output(0), pad->input_value(0));};- auto m = make_shared<pattern::Matcher>(pad_node_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(pad_node_pattern, matcher_name);this->register_matcher(m, callback);}-pass::EliminateConvert::EliminateConvert() {+EliminateConvert::EliminateConvert() {MATCHER_SCOPE(EliminateConvert);- auto convert_pattern = pattern::wrap_type<ov::op::v0::Convert>();+ auto convert_pattern = pattern::wrap_type<v0::Convert>();matcher_pass_callback callback = [](pattern::Matcher& m) {- auto convert = ov::as_type_ptr<ov::op::v0::Convert>(m.get_match_root());+ auto convert = ov::as_type_ptr<v0::Convert>(m.get_match_root());if (!convert) {return false;}@@ -476,15 +479,15 @@ pass::EliminateConvert::EliminateConvert() {return false;};- auto m = make_shared<pattern::Matcher>(convert_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(convert_pattern, matcher_name);this->register_matcher(m, callback);}-pass::EliminateIdentityConvert::EliminateIdentityConvert() {+EliminateIdentityConvert::EliminateIdentityConvert() {MATCHER_SCOPE(EliminateIdentityConvert);- auto convert_pattern = pattern::wrap_type<ov::op::v0::Convert>();+ auto convert_pattern = pattern::wrap_type<v0::Convert>();auto convert_identity_pattern = pattern::wrap_type<ov::op::v16::Identity>(convert_pattern);- auto convert_identity_convert_pattern = pattern::wrap_type<ov::op::v0::Convert>(convert_identity_pattern);+ auto convert_identity_convert_pattern = pattern::wrap_type<v0::Convert>(convert_identity_pattern);matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_map();@@ -500,14 +503,14 @@ pass::EliminateIdentityConvert::EliminateIdentityConvert() {}return false;};- auto m = make_shared<pattern::Matcher>(convert_identity_convert_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(convert_identity_convert_pattern, matcher_name);this->register_matcher(m, callback);}-pass::EliminateConvertNonZero::EliminateConvertNonZero() {+EliminateConvertNonZero::EliminateConvertNonZero() {MATCHER_SCOPE(EliminateConvertNonZero);- auto convert_pattern = pattern::wrap_type<ov::op::v0::Convert>(pattern::consumers_count(1));- auto non_zero = pattern::wrap_type<ov::op::v3::NonZero>({convert_pattern});+ auto convert_pattern = pattern::wrap_type<v0::Convert>(pattern::consumers_count(1));+ auto non_zero = pattern::wrap_type<v3::NonZero>({convert_pattern});matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_map();@@ -519,13 +522,13 @@ pass::EliminateConvertNonZero::EliminateConvertNonZero() {return true;};- auto m = make_shared<pattern::Matcher>(non_zero, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(non_zero, matcher_name);this->register_matcher(m, callback);}-pass::EliminateConcat::EliminateConcat() {+EliminateConcat::EliminateConcat() {MATCHER_SCOPE(EliminateConcat);- auto convert_pattern = pattern::wrap_type<ov::op::v0::Concat>();+ auto convert_pattern = pattern::wrap_type<v0::Concat>();matcher_pass_callback callback = [](pattern::Matcher& m) {auto concat = m.get_match_root();@@ -535,17 +538,17 @@ pass::EliminateConcat::EliminateConcat() {return false;};- auto m = make_shared<pattern::Matcher>(convert_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(convert_pattern, matcher_name);this->register_matcher(m, callback);}-pass::EliminateConcatStridedSlice::EliminateConcatStridedSlice() {+EliminateConcatStridedSlice::EliminateConcatStridedSlice() {using node_index_info_map = std::vector<std::tuple<std::shared_ptr<Node>, int64_t, int64_t>>;MATCHER_SCOPE(EliminateConcatStridedSlice);- auto pattern_concat = pattern::wrap_type<ov::op::v0::Concat>(ov::pass::pattern::has_static_rank());+ auto pattern_concat = pattern::wrap_type<v0::Concat>(pattern::has_static_rank());matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_map();- const auto concat = ov::as_type_ptr<ov::op::v0::Concat>(pattern_map.at(pattern_concat));+ const auto concat = ov::as_type_ptr<v0::Concat>(pattern_map.at(pattern_concat));if (concat->is_dynamic())return false;@@ -559,8 +562,8 @@ pass::EliminateConcatStridedSlice::EliminateConcatStridedSlice() {node_index_info_map slice_out_index_in_concat;for (const auto& user : concat_users) {- if (ov::is_type<ov::op::v1::StridedSlice>(user)) {- auto strided_slice_node = ov::as_type_ptr<ov::op::v1::StridedSlice>(user);+ if (ov::is_type<v1::StridedSlice>(user)) {+ auto strided_slice_node = ov::as_type_ptr<v1::StridedSlice>(user);if (!strided_slice_node) {return false;}@@ -693,9 +696,9 @@ pass::EliminateConcatStridedSlice::EliminateConcatStridedSlice() {replace_output_update_name(concat, new_concat_node);for (const auto& [slice_node, slice_begin, slice_end] : mismatch_slices) {- if (slice_node->get_users().size() == 1 && ov::is_type<ov::op::v0::Concat>(slice_node->get_users()[0]) &&- ov::as_type_ptr<ov::op::v0::Concat>(slice_node->get_users()[0])->get_axis() == concat_axis) {- auto next_concat = ov::as_type_ptr<ov::op::v0::Concat>(slice_node->get_users()[0]);+ if (slice_node->get_users().size() == 1 && ov::is_type<v0::Concat>(slice_node->get_users()[0]) &&+ ov::as_type_ptr<v0::Concat>(slice_node->get_users()[0])->get_axis() == concat_axis) {+ auto next_concat = ov::as_type_ptr<v0::Concat>(slice_node->get_users()[0]);auto next_concat_inputs = next_concat->input_values();ov::OutputVector new_next_concat_inputs{};for (const auto& t : next_concat_inputs) {@@ -718,14 +721,14 @@ pass::EliminateConcatStridedSlice::EliminateConcatStridedSlice() {auto begin_values = begin_constant_node->cast_vector<int64_t>();begin_values[concat_axis] = slice_begin - new_start_value;new_slice_in_nodes.push_back(- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{begin_values.size()}, begin_values));+ v0::Constant::create(ov::element::i64, ov::Shape{begin_values.size()}, begin_values));auto end_node = slice_node->get_input_node_shared_ptr(2);const auto& end_constant_node = ov::util::get_constant_from_source(end_node);auto end_values = end_constant_node->cast_vector<int64_t>();end_values[concat_axis] = slice_end - new_start_value + 1;new_slice_in_nodes.push_back(- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{end_values.size()}, end_values));+ v0::Constant::create(ov::element::i64, ov::Shape{end_values.size()}, end_values));auto new_slice_node = slice_node->clone_with_new_inputs(ov::as_output_vector(new_slice_in_nodes));replace_output_update_name(slice_node, new_slice_node);}@@ -733,40 +736,40 @@ pass::EliminateConcatStridedSlice::EliminateConcatStridedSlice() {return true;};- auto m = make_shared<pattern::Matcher>(pattern_concat, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(pattern_concat, matcher_name);this->register_matcher(m, callback);}-pass::EliminateSplit::EliminateSplit() {+EliminateSplit::EliminateSplit() {MATCHER_SCOPE(EliminateSplit);- auto convert_pattern = pattern::wrap_type<ov::op::v1::Split>();+ auto convert_pattern = pattern::wrap_type<v1::Split>();matcher_pass_callback callback = [](pattern::Matcher& m) {- auto split = ov::as_type_ptr<ov::op::v1::Split>(m.get_match_root());+ auto split = ov::as_type_ptr<v1::Split>(m.get_match_root());if (!split || split->get_num_splits() != 1) {return false;}return replace_output_update_name(split->output(0), split->input_value(0));};- auto m = make_shared<pattern::Matcher>(convert_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(convert_pattern, matcher_name);this->register_matcher(m, callback);}-pass::EliminateUnsqueeze::EliminateUnsqueeze() {+EliminateUnsqueeze::EliminateUnsqueeze() {MATCHER_SCOPE(EliminateUnsqueeze);- auto unsqueeze_pattern = pattern::wrap_type<ov::op::v0::Unsqueeze>();+ auto unsqueeze_pattern = pattern::wrap_type<v0::Unsqueeze>();- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {return eliminate_unsqueeze(m.get_match_root());};- auto m = make_shared<pattern::Matcher>(unsqueeze_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(unsqueeze_pattern, matcher_name);this->register_matcher(m, callback);}-pass::EliminateSqueeze::EliminateSqueeze() {+EliminateSqueeze::EliminateSqueeze() {MATCHER_SCOPE(EliminateSqueeze);- auto squeeze_pattern = pattern::wrap_type<ov::op::v0::Squeeze>();+ auto squeeze_pattern = pattern::wrap_type<v0::Squeeze>();matcher_pass_callback callback = [](pattern::Matcher& m) {const auto node = m.get_match_root();@@ -776,22 +779,22 @@ pass::EliminateSqueeze::EliminateSqueeze() {return replace_squeeze_unsqueeze(node);}- auto squeeze = ov::as_type_ptr<ov::op::v0::Squeeze>(node);+ auto squeeze = ov::as_type_ptr<v0::Squeeze>(node);if (squeeze == nullptr)return false;auto input = squeeze->input_value(0).get_node_shared_ptr();- auto replace_squeeze_only = [&](const vector<int64_t>& axes) {- auto axes_const = ov::op::v0::Constant::create<int64_t>(element::i64, Shape{axes.size()}, axes);- auto new_sq = make_shared<ov::op::v0::Squeeze>(input->input_value(0), axes_const);+ auto replace_squeeze_only = [&](const std::vector<int64_t>& axes) {+ auto axes_const = v0::Constant::create<int64_t>(element::i64, Shape{axes.size()}, axes);+ auto new_sq = std::make_shared<v0::Squeeze>(input->input_value(0), axes_const);if (squeeze->get_output_partial_shape(0).same_scheme(new_sq->get_output_partial_shape(0))) {return replace_node_update_name(squeeze, new_sq);}return false;};// eliminate redundant unsqueeze->squeeze- if (auto unsqueeze = ov::as_type_ptr<ov::op::v0::Unsqueeze>(input)) {+ if (auto unsqueeze = ov::as_type_ptr<v0::Unsqueeze>(input)) {PartialShape data_shape;- if (ov::op::util::is_parameter(input)) {+ if (op_util::is_parameter(input)) {data_shape = unsqueeze->input(0).get_partial_shape();} else {data_shape = input->input(0).get_partial_shape();@@ -816,8 +819,8 @@ pass::EliminateSqueeze::EliminateSqueeze() {auto axes = get_unsqueeze_axes(data_shape, out_shape);if (data_shape.rank().get_length() + static_cast<int64_t>(axes.size()) ==out_shape.rank().get_length()) {- auto axes_const = ov::op::v0::Constant::create<int64_t>(element::i64, Shape{axes.size()}, axes);- auto new_unsq = make_shared<ov::op::v0::Unsqueeze>(input->input_value(0), axes_const);+ auto axes_const = v0::Constant::create<int64_t>(element::i64, Shape{axes.size()}, axes);+ auto new_unsq = std::make_shared<v0::Unsqueeze>(input->input_value(0), axes_const);if (squeeze->get_output_partial_shape(0).same_scheme(new_unsq->get_output_partial_shape(0))) {replace_output_update_name(squeeze, new_unsq);return true;@@ -827,9 +830,9 @@ pass::EliminateSqueeze::EliminateSqueeze() {return false;}// eliminate redundant squeeze->squeeze- if (auto squeeze_i = ov::as_type_ptr<ov::op::v0::Squeeze>(input)) {+ if (auto squeeze_i = ov::as_type_ptr<v0::Squeeze>(input)) {PartialShape data_shape;- if (ov::op::util::is_parameter(input)) {+ if (op_util::is_parameter(input)) {data_shape = squeeze_i->input(0).get_partial_shape();} else {data_shape = input->input(0).get_partial_shape();@@ -843,11 +846,11 @@ pass::EliminateSqueeze::EliminateSqueeze() {return false;};- auto m = make_shared<pattern::Matcher>(squeeze_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(squeeze_pattern, matcher_name);this->register_matcher(m, callback);}-pass::EliminateIdentity::EliminateIdentity() {+EliminateIdentity::EliminateIdentity() {MATCHER_SCOPE(EliminateIdentity);auto identity_pattern = pattern::wrap_type<ov::op::v16::Identity>();@@ -859,7 +862,7 @@ pass::EliminateIdentity::EliminateIdentity() {return replace_output_update_name(identity->output(0), identity->input_value(0));};- auto m = make_shared<pattern::Matcher>(identity_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(identity_pattern, matcher_name);this->register_matcher(m, callback);}@@ -872,10 +875,10 @@ int64_t make_positive(int64_t value, const Output<Node>& node) {return value;};-bool check_squeeze(const shared_ptr<Node>& node) {- auto squeeze = ov::as_type_ptr<ov::op::v0::Squeeze>(node);+bool check_squeeze(const std::shared_ptr<Node>& node) {+ auto squeeze = ov::as_type_ptr<v0::Squeeze>(node);if (squeeze) {- auto axis = ov::as_type_ptr<ov::op::v0::Constant>(squeeze->input_value(1).get_node_shared_ptr());+ auto axis = ov::as_type_ptr<v0::Constant>(squeeze->input_value(1).get_node_shared_ptr());if (axis) {auto axis_val = axis->cast_vector<int64_t>();if (axis_val.size() == 1 && make_positive(axis_val[0], squeeze->input_value(0)) == 1) {@@ -888,10 +891,10 @@ bool check_squeeze(const shared_ptr<Node>& node) {// Checks that Reshape actually equals to Squeeze op// 0, -1 values in the shape pattern are not allowed.-bool check_reshape(const shared_ptr<Node>& node) {- auto reshape = ov::as_type_ptr<ov::op::v1::Reshape>(node);+bool check_reshape(const std::shared_ptr<Node>& node) {+ auto reshape = ov::as_type_ptr<v1::Reshape>(node);if (reshape) {- auto shape_pattern = ov::as_type_ptr<ov::op::v0::Constant>(reshape->input_value(1).get_node_shared_ptr());+ auto shape_pattern = ov::as_type_ptr<v0::Constant>(reshape->input_value(1).get_node_shared_ptr());if (shape_pattern) {auto pattern_val = shape_pattern->cast_vector<int64_t>();bool is_valid_pattern = find(pattern_val.begin(), pattern_val.end(), 0) == pattern_val.end();@@ -913,10 +916,10 @@ bool check_reshape(const shared_ptr<Node>& node) {return false;}-bool check_axis(const shared_ptr<ov::op::v0::Concat>& concat,- const shared_ptr<Node>& split,+bool check_axis(const std::shared_ptr<v0::Concat>& concat,+ const std::shared_ptr<Node>& split,bool is_special_case = false) {- auto axis = ov::as_type_ptr<ov::op::v0::Constant>(split->input_value(1).get_node_shared_ptr());+ auto axis = ov::as_type_ptr<v0::Constant>(split->input_value(1).get_node_shared_ptr());if (!axis) {return false;}@@ -940,12 +943,12 @@ bool check_axis(const shared_ptr<ov::op::v0::Concat>& concat,}template <class T>-shared_ptr<T> check_all_inputs(const shared_ptr<ov::op::v0::Concat>& concat) {- shared_ptr<T> split;+std::shared_ptr<T> check_all_inputs(const std::shared_ptr<v0::Concat>& concat) {+ std::shared_ptr<T> split;const auto concat_in_values = concat->input_values();size_t idx = 0;for (const auto& in_to_concat : concat_in_values) {- const auto& cast_to_split = dynamic_pointer_cast<T>(in_to_concat.get_node_shared_ptr());+ const auto& cast_to_split = std::dynamic_pointer_cast<T>(in_to_concat.get_node_shared_ptr());// There is a special case with (GRU/RNN/LSTM)Sequence ops://// (LSTM/GRU/RNN)Sequence -- output(0) --> Squeeze (Reshape) ->Split -(H1...Hn-1 outs) -> Concat@@ -962,7 +965,7 @@ shared_ptr<T> check_all_inputs(const shared_ptr<ov::op::v0::Concat>& concat) {if (idx != (concat_in_values.size() - 1) || !split) {return {};}- shared_ptr<Node> in_to_split = split->input_value(0).get_node_shared_ptr();+ std::shared_ptr<Node> in_to_split = split->input_value(0).get_node_shared_ptr();Output<Node> seq_out;if (in_to_split && !in_to_split->inputs().empty()) {seq_out = in_to_split->input_value(0);@@ -972,9 +975,8 @@ shared_ptr<T> check_all_inputs(const shared_ptr<ov::op::v0::Concat>& concat) {auto seq_node = seq_out.get_node_shared_ptr();if (!seq_node || seq_out.get_index() != 0 ||- !(ov::as_type_ptr<ov::op::v5::RNNSequence>(seq_node) ||- ov::as_type_ptr<ov::op::v5::GRUSequence>(seq_node) ||- ov::as_type_ptr<ov::op::v5::LSTMSequence>(seq_node))) {+ !(ov::as_type_ptr<v5::RNNSequence>(seq_node) || ov::as_type_ptr<v5::GRUSequence>(seq_node) ||+ ov::as_type_ptr<v5::LSTMSequence>(seq_node))) {return {};}@@ -1025,16 +1027,16 @@ shared_ptr<T> check_all_inputs(const shared_ptr<ov::op::v0::Concat>& concat) {ov::pass::EliminateSplitConcat::EliminateSplitConcat() {MATCHER_SCOPE(EliminateSplitConcat);- auto pattern_concat = pattern::wrap_type<ov::op::v0::Concat>();+ auto pattern_concat = pattern::wrap_type<v0::Concat>();matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_map();- const auto concat = ov::as_type_ptr<ov::op::v0::Concat>(pattern_map.at(pattern_concat));+ const auto concat = ov::as_type_ptr<v0::Concat>(pattern_map.at(pattern_concat));if (!concat) {return false;}- shared_ptr<Node> split = check_all_inputs<ov::op::v1::Split>(concat);+ std::shared_ptr<Node> split = check_all_inputs<v1::Split>(concat);if (!split) {- split = check_all_inputs<ov::op::v1::VariadicSplit>(concat);+ split = check_all_inputs<v1::VariadicSplit>(concat);}if (!split) {@@ -1044,18 +1046,18 @@ ov::pass::EliminateSplitConcat::EliminateSplitConcat() {return replace_output_update_name(concat->output(0), split->input_value(0));};- auto m = make_shared<pattern::Matcher>(pattern_concat, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(pattern_concat, matcher_name);this->register_matcher(m, callback);}-pass::EliminateTranspose::EliminateTranspose() {+EliminateTranspose::EliminateTranspose() {MATCHER_SCOPE(EliminateTranspose);- auto order = pattern::wrap_type<ov::op::v0::Constant>();- auto transpose_pattern = pattern::wrap_type<ov::op::v1::Transpose>({pattern::any_input(), order});+ auto order = pattern::wrap_type<v0::Constant>();+ auto transpose_pattern = pattern::wrap_type<v1::Transpose>({pattern::any_input(), order});matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_map();- auto order_const = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(order));+ auto order_const = ov::as_type_ptr<v0::Constant>(pattern_map.at(order));if (!order_const) {return false;}@@ -1065,7 +1067,7 @@ pass::EliminateTranspose::EliminateTranspose() {return false;}- vector<int64_t> ref_values(order_values.size());+ std::vector<int64_t> ref_values(order_values.size());iota(ref_values.begin(), ref_values.end(), 0);if (order_values != ref_values) {return false;@@ -1075,20 +1077,19 @@ pass::EliminateTranspose::EliminateTranspose() {return replace_output_update_name(transpose->output(0), transpose->input_value(0));};- auto m = make_shared<pattern::Matcher>(transpose_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_pattern, matcher_name);this->register_matcher(m, callback);}-pass::EliminateEltwise::EliminateEltwise() {+EliminateEltwise::EliminateEltwise() {MATCHER_SCOPE(EliminateEltwise);auto input = pattern::any_input();- auto constant_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto constant_pattern = pattern::wrap_type<v0::Constant>();auto eltwise_pattern =- pattern::wrap_type<ov::op::v1::Add, ov::op::v1::Subtract, ov::op::v1::Multiply, ov::op::v1::Divide>(- {input, constant_pattern});+ pattern::wrap_type<v1::Add, v1::Subtract, v1::Multiply, v1::Divide>({input, constant_pattern});auto subtract_pattern =- pattern::wrap_type<ov::op::v1::Subtract>({input, pattern::wrap_type<ov::op::v0::Convert>({constant_pattern})});- auto root = make_shared<pattern::op::Or>(OutputVector{eltwise_pattern, subtract_pattern});+ pattern::wrap_type<v1::Subtract>({input, pattern::wrap_type<v0::Convert>({constant_pattern})});+ auto root = std::make_shared<pattern::op::Or>(OutputVector{eltwise_pattern, subtract_pattern});matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -1096,22 +1097,20 @@ pass::EliminateEltwise::EliminateEltwise() {const auto& non_const_input = pattern_map.at(input);const auto& constant = pattern_map.at(constant_pattern);- if (!ov::op::util::can_eliminate_eltwise_node(eltwise, constant, non_const_input)) {+ if (!op_util::can_eliminate_eltwise_node(eltwise, constant, non_const_input)) {return false;}return replace_output_update_name(eltwise->output(0), non_const_input);};- auto m = make_shared<pattern::Matcher>(root, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(root, matcher_name);this->register_matcher(m, callback);}-pass::EliminateScatterUpdate::EliminateScatterUpdate() {+EliminateScatterUpdate::EliminateScatterUpdate() {MATCHER_SCOPE(EliminateScatterUpdate);- auto scatter_pattern = pattern::wrap_type<ov::op::v3::ScatterUpdate,- ov::op::v3::ScatterNDUpdate,- ov::op::v15::ScatterNDUpdate,- ov::op::v3::ScatterElementsUpdate>();+ auto scatter_pattern = pattern::+ wrap_type<v3::ScatterUpdate, v3::ScatterNDUpdate, ov::op::v15::ScatterNDUpdate, v3::ScatterElementsUpdate>();matcher_pass_callback callback = [=](pattern::Matcher& m) {auto scatter = m.get_match_root();@@ -1128,22 +1127,21 @@ pass::EliminateScatterUpdate::EliminateScatterUpdate() {}};- auto m = make_shared<pattern::Matcher>(scatter_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(scatter_pattern, matcher_name);this->register_matcher(m, callback);}-ov::pass::EliminateNopBroadcast::EliminateNopBroadcast() {+EliminateNopBroadcast::EliminateNopBroadcast() {MATCHER_SCOPE(EliminateNopBroadcast);- auto root = pattern::wrap_type<ov::op::v1::Broadcast, ov::op::v3::Broadcast, ov::op::v0::Tile>(- [](std::shared_ptr<Node> node) {- auto input_rank = node->get_input_partial_shape(0).rank();- auto output_rank = node->get_output_partial_shape(0).rank();- return input_rank.is_static() && output_rank.is_static() && input_rank == output_rank;- });+ auto root = pattern::wrap_type<v1::Broadcast, v3::Broadcast, v0::Tile>([](std::shared_ptr<Node> node) {+ auto input_rank = node->get_input_partial_shape(0).rank();+ auto output_rank = node->get_output_partial_shape(0).rank();+ return input_rank.is_static() && output_rank.is_static() && input_rank == output_rank;+ });ov::matcher_pass_callback matcher_pass_callback = [](pattern::Matcher& m) {const auto& op = m.get_match_root();- if (ov::op::util::is_constant_and_all_values_equal_int(op->input_value(1), 1))+ if (op_util::is_constant_and_all_values_equal_int(op->input_value(1), 1))return replace_output_update_name(op->output(0), op->input_value(0));return false;};@@ -1152,16 +1150,16 @@ ov::pass::EliminateNopBroadcast::EliminateNopBroadcast() {register_matcher(m, matcher_pass_callback);}-ov::pass::EliminateSliceBeforeGatherElements::EliminateSliceBeforeGatherElements() {+EliminateSliceBeforeGatherElements::EliminateSliceBeforeGatherElements() {MATCHER_SCOPE(EliminateSliceBeforeGatherElements);- auto slice = pattern::wrap_type<ov::op::v8::Slice>();+ auto slice = pattern::wrap_type<v8::Slice>();auto gather = pattern::wrap_type<ov::op::v6::GatherElements>({slice, pattern::any_input()});ov::matcher_pass_callback matcher_pass_callback = [=](pattern::Matcher& m) {const auto& pattern_to_node = m.get_pattern_map();const auto& slice_node = pattern_to_node.at(slice);- bool start_from_zero = ov::op::util::is_constant_and_all_values_equal_int(slice_node->input_value(1), 0);- bool step_is_one = ov::op::util::is_constant_and_all_values_equal_int(slice_node->input_value(3), 1);+ bool start_from_zero = op_util::is_constant_and_all_values_equal_int(slice_node->input_value(1), 0);+ bool step_is_one = op_util::is_constant_and_all_values_equal_int(slice_node->input_value(3), 1);if (!start_from_zero || !step_is_one)return false;const auto& gather_node = pattern_to_node.at(gather);@@ -1172,18 +1170,18 @@ ov::pass::EliminateSliceBeforeGatherElements::EliminateSliceBeforeGatherElementsauto m = std::make_shared<pattern::Matcher>(gather, matcher_name);register_matcher(m, matcher_pass_callback);}-ov::pass::EliminateSlice::EliminateSlice() {+EliminateSlice::EliminateSlice() {MATCHER_SCOPE(EliminateSlice);auto input = pattern::any_input();- auto begin_const = pattern::wrap_type<ov::op::v0::Constant>();- auto end_const = pattern::wrap_type<ov::op::v0::Constant>();- auto step_const = pattern::wrap_type<ov::op::v0::Constant>();+ auto begin_const = pattern::wrap_type<v0::Constant>();+ auto end_const = pattern::wrap_type<v0::Constant>();+ auto step_const = pattern::wrap_type<v0::Constant>();auto axes = pattern::any_input();- auto pattern = pattern::wrap_type<ov::op::v8::Slice>({input, begin_const, end_const, step_const, axes});+ auto ptrn = pattern::wrap_type<v8::Slice>({input, begin_const, end_const, step_const, axes});ov::matcher_pass_callback matcher_pass_callback = [=](pattern::Matcher& m) {- auto slice = ov::as_type_ptr<ov::op::v8::Slice>(m.get_match_root());+ auto slice = ov::as_type_ptr<v8::Slice>(m.get_match_root());if (!slice) {return false;}@@ -1191,9 +1189,9 @@ ov::pass::EliminateSlice::EliminateSlice() {int64_t max_int = slice->input_value(2).get_element_type() == element::i32? std::numeric_limits<int32_t>::max(): std::numeric_limits<int64_t>::max();- bool is_nop = ov::op::util::is_constant_and_all_values_equal_int(slice->input_value(1), 0) &&- ov::op::util::is_constant_and_all_values_equal_int(slice->input_value(2), max_int) &&- ov::op::util::is_constant_and_all_values_equal_int(slice->input_value(3), 1);+ bool is_nop = op_util::is_constant_and_all_values_equal_int(slice->input_value(1), 0) &&+ op_util::is_constant_and_all_values_equal_int(slice->input_value(2), max_int) &&+ op_util::is_constant_and_all_values_equal_int(slice->input_value(3), 1);if (is_nop) {return replace_output_update_name(slice->output(0), slice->input_value(0));@@ -1201,21 +1199,21 @@ ov::pass::EliminateSlice::EliminateSlice() {return false;}};- auto m = std::make_shared<pattern::Matcher>(pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(ptrn, matcher_name);register_matcher(m, matcher_pass_callback);}-ov::pass::EliminateStridedSlice::EliminateStridedSlice() {+EliminateStridedSlice::EliminateStridedSlice() {MATCHER_SCOPE(EliminateStridedSlice);auto input = pattern::any_input();- auto begin_const = pattern::wrap_type<ov::op::v0::Constant>();- auto end_const = pattern::wrap_type<ov::op::v0::Constant>();- auto optional_stride_const = pattern::wrap_type<ov::op::v0::Constant>();- auto pattern = pattern::wrap_type<ov::op::v1::StridedSlice>({input, begin_const, end_const, optional_stride_const});+ auto begin_const = pattern::wrap_type<v0::Constant>();+ auto end_const = pattern::wrap_type<v0::Constant>();+ auto optional_stride_const = pattern::wrap_type<v0::Constant>();+ auto ptrn = pattern::wrap_type<v1::StridedSlice>({input, begin_const, end_const, optional_stride_const});ov::matcher_pass_callback matcher_pass_callback = [=](pattern::Matcher& m) {- auto strided_slice_node = ov::as_type_ptr<ov::op::v1::StridedSlice>(m.get_match_root());+ auto strided_slice_node = ov::as_type_ptr<v1::StridedSlice>(m.get_match_root());if (!strided_slice_node) {return false;}@@ -1237,7 +1235,7 @@ ov::pass::EliminateStridedSlice::EliminateStridedSlice() {}// check that that we will take all valuesif (strided_slice_node->get_input_size() == 4 &&- !ov::op::util::is_constant_and_all_values_equal_int(strided_slice_node->input_value(3), 1)) {+ !op_util::is_constant_and_all_values_equal_int(strided_slice_node->input_value(3), 1)) {return false;}@@ -1289,29 +1287,29 @@ ov::pass::EliminateStridedSlice::EliminateStridedSlice() {}return replace_output_update_name(strided_slice_node->output(0), strided_slice_node->input_value(0));};- auto m = std::make_shared<pattern::Matcher>(pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(ptrn, matcher_name);register_matcher(m, matcher_pass_callback);}-ov::pass::EliminateStridedSliceByShape::EliminateStridedSliceByShape() {+EliminateStridedSliceByShape::EliminateStridedSliceByShape() {MATCHER_SCOPE(EliminateStridedSliceByShape);auto input = pattern::any_input();auto begin = pattern::any_input();auto end = pattern::any_input();- auto optional_stride_const = pattern::wrap_type<ov::op::v0::Constant>();- auto strided_slice = pattern::wrap_type<ov::op::v1::StridedSlice>({input, begin, end, optional_stride_const});+ auto optional_stride_const = pattern::wrap_type<v0::Constant>();+ auto strided_slice = pattern::wrap_type<v1::StridedSlice>({input, begin, end, optional_stride_const});auto axes = pattern::any_input();- auto slice = pattern::wrap_type<ov::op::v8::Slice>({input, begin, end, optional_stride_const, axes});- auto pattern = std::make_shared<pattern::op::Or>(OutputVector{strided_slice, slice});+ auto slice = pattern::wrap_type<v8::Slice>({input, begin, end, optional_stride_const, axes});+ auto ptrn = std::make_shared<pattern::op::Or>(OutputVector{strided_slice, slice});ov::matcher_pass_callback matcher_pass_callback = [=](pattern::Matcher& m) {auto node = m.get_match_root();if (node == nullptr) {return false;}- auto strided_slice_node = ov::as_type_ptr<ov::op::v1::StridedSlice>(node);+ auto strided_slice_node = ov::as_type_ptr<v1::StridedSlice>(node);if (strided_slice_node) {// check that all values of the mask is equal 0auto check_mask = [](const std::vector<int64_t>& mask_to_check) {@@ -1332,8 +1330,7 @@ ov::pass::EliminateStridedSliceByShape::EliminateStridedSliceByShape() {}// check that that we will take all values- if (node->get_input_size() >= 4 &&- !ov::op::util::is_constant_and_all_values_equal_int(node->input_value(3), 1)) {+ if (node->get_input_size() >= 4 && !op_util::is_constant_and_all_values_equal_int(node->input_value(3), 1)) {return false;}@@ -1345,22 +1342,20 @@ ov::pass::EliminateStridedSliceByShape::EliminateStridedSliceByShape() {return false;};- auto m = std::make_shared<pattern::Matcher>(pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(ptrn, matcher_name);register_matcher(m, matcher_pass_callback);}-ov::pass::PrepareShapeOpsForEliminationAroundBE::PrepareShapeOpsForEliminationAroundBE() {+PrepareShapeOpsForEliminationAroundBE::PrepareShapeOpsForEliminationAroundBE() {MATCHER_SCOPE(PrepareShapeOpsForEliminationAroundBE);- auto first_label = pattern::- wrap_type<ov::op::v1::Reshape, ov::op::v0::Squeeze, ov::op::v1::StridedSlice, ov::op::util::GatherBase>(- pattern::rank_equals(0));+ auto first_label =+ pattern::wrap_type<v1::Reshape, v0::Squeeze, v1::StridedSlice, op_util::GatherBase>(pattern::rank_equals(0));auto other_input_label = pattern::any_input(pattern::rank_equals(0));- auto binary_op_label = pattern::wrap_type<ov::op::util::BinaryElementwiseArithmetic,- ov::op::util::BinaryElementwiseComparison,- ov::op::util::BinaryElementwiseLogical>({first_label, other_input_label},- pattern::consumers_count(1));- auto second_label =- pattern::wrap_type<ov::op::v1::Reshape, ov::op::v0::Unsqueeze>({binary_op_label, pattern::any_input()},+ auto binary_op_label = pattern::wrap_type<op_util::BinaryElementwiseArithmetic,+ op_util::BinaryElementwiseComparison,+ op_util::BinaryElementwiseLogical>({first_label, other_input_label},+ pattern::consumers_count(1));+ auto second_label = pattern::wrap_type<v1::Reshape, v0::Unsqueeze>({binary_op_label, pattern::any_input()},pattern::rank_equals(1));ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {@@ -1369,10 +1364,8 @@ ov::pass::PrepareShapeOpsForEliminationAroundBE::PrepareShapeOpsForEliminationArauto second_node = pattern_to_node.at(second_label);auto binary = pattern_to_node.at(binary_op_label);- auto lhs_node =- ov::op::util::clone_try_fold(second_node, {binary->input_value(0), second_node->input_value(1)});- auto rhs_node =- ov::op::util::clone_try_fold(second_node, {binary->input_value(1), second_node->input_value(1)});+ auto lhs_node = op_util::clone_try_fold(second_node, {binary->input_value(0), second_node->input_value(1)});+ auto rhs_node = op_util::clone_try_fold(second_node, {binary->input_value(1), second_node->input_value(1)});register_new_node(lhs_node);register_new_node(rhs_node);@@ -1421,3 +1414,5 @@ ov::pass::NopElimination::NopElimination(bool use_shape_for_elimination) {ADD_MATCHER_FOR_THIS(EliminateGather)}}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cppindex 5ad9c1703bf..e4d308fd705 100644--- a/src/common/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/normalize_l2_fusion.cpp@@ -23,59 +23,62 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::NormalizeL2Fusion::NormalizeL2Fusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {++NormalizeL2Fusion::NormalizeL2Fusion() {MATCHER_SCOPE(NormalizeL2Fusion);- auto input = pass::pattern::any_input();+ auto input = pattern::any_input();- auto exp = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto pow = std::make_shared<ov::op::v1::Power>(input, exp);- auto axes = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto reduce_sum = std::make_shared<ov::op::v1::ReduceSum>(pow, axes);+ auto exp = pattern::wrap_type<v0::Constant>();+ auto pow = std::make_shared<v1::Power>(input, exp);+ auto axes = pattern::wrap_type<v0::Constant>();+ auto reduce_sum = std::make_shared<v1::ReduceSum>(pow, axes);- auto eps_const = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto max = std::make_shared<ov::op::v1::Maximum>(reduce_sum, eps_const);- auto add = std::make_shared<ov::op::v1::Add>(reduce_sum, eps_const);+ auto eps_const = pattern::wrap_type<v0::Constant>();+ auto max = std::make_shared<v1::Maximum>(reduce_sum, eps_const);+ auto add = std::make_shared<v1::Add>(reduce_sum, eps_const);auto max_or_add = std::make_shared<pattern::op::Or>(OutputVector{max, add});// Sqrt can be represented by Sqrt node or as Power node with exponent 0.5- auto sqrt = std::make_shared<ov::op::v0::Sqrt>(max_or_add);- auto exp2 = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto pow_as_sqrt = std::make_shared<ov::op::v1::Power>(max_or_add, exp2);+ auto sqrt = std::make_shared<v0::Sqrt>(max_or_add);+ auto exp2 = pattern::wrap_type<v0::Constant>();+ auto pow_as_sqrt = std::make_shared<v1::Power>(max_or_add, exp2);auto power_or_sqrt = std::make_shared<pattern::op::Or>(OutputVector{sqrt, pow_as_sqrt});// divide(input,sqrt(..)) can be represented as mul(input, power(..., -0.5f))- auto divide = std::make_shared<ov::op::v1::Divide>(input, power_or_sqrt);- auto exp3 = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto reversed_pow_as_sqrt = std::make_shared<ov::op::v1::Power>(max_or_add, exp3);- auto mul = std::make_shared<ov::op::v1::Multiply>(input, reversed_pow_as_sqrt);+ auto divide = std::make_shared<v1::Divide>(input, power_or_sqrt);+ auto exp3 = pattern::wrap_type<v0::Constant>();+ auto reversed_pow_as_sqrt = std::make_shared<v1::Power>(max_or_add, exp3);+ auto mul = std::make_shared<v1::Multiply>(input, reversed_pow_as_sqrt);auto divide_or_mul = std::make_shared<pattern::op::Or>(OutputVector{divide, mul});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();const auto data_input = pattern_to_output.at(input);- const auto exp_input = ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(exp).get_node_shared_ptr());- const auto axes_input = ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(axes).get_node_shared_ptr());- const auto eps_attr =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(eps_const).get_node_shared_ptr());- const auto exp2_input =- pattern_to_output.count(exp2)- ? ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(exp2).get_node_shared_ptr())- : nullptr;- const auto exp3_input =- pattern_to_output.count(exp3)- ? ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(exp3).get_node_shared_ptr())- : nullptr;-- if (exp_input && !ov::op::util::has_constant_value<float>(exp_input, 2.0f)) {+ const auto exp_input = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(exp).get_node_shared_ptr());+ const auto axes_input = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(axes).get_node_shared_ptr());+ const auto eps_attr = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(eps_const).get_node_shared_ptr());+ const auto exp2_input = pattern_to_output.count(exp2)+ ? ov::as_type_ptr<v0::Constant>(pattern_to_output.at(exp2).get_node_shared_ptr())+ : nullptr;+ const auto exp3_input = pattern_to_output.count(exp3)+ ? ov::as_type_ptr<v0::Constant>(pattern_to_output.at(exp3).get_node_shared_ptr())+ : nullptr;++ if (exp_input && !op_util::has_constant_value<float>(exp_input, 2.0f)) {return false;}- if (exp2_input && !ov::op::util::has_constant_value<float>(exp2_input, 0.5f)) {+ if (exp2_input && !op_util::has_constant_value<float>(exp2_input, 0.5f)) {return false;}- if (exp3_input && !ov::op::util::has_constant_value<float>(exp3_input, -0.5f)) {+ if (exp3_input && !op_util::has_constant_value<float>(exp3_input, -0.5f)) {return false;}@@ -96,7 +99,7 @@ ov::pass::NormalizeL2Fusion::NormalizeL2Fusion() {return false;}- auto normalize_l2 = std::make_shared<ov::op::v0::NormalizeL2>(data_input, axes_input, eps_attr_value, mode);+ auto normalize_l2 = std::make_shared<v0::NormalizeL2>(data_input, axes_input, eps_attr_value, mode);if (transformation_callback(normalize_l2)) {return false;}@@ -130,6 +133,8 @@ ov::pass::NormalizeL2Fusion::NormalizeL2Fusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(divide_or_mul, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(divide_or_mul, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp b/src/common/transformations/src/transformations/common_optimizations/optimize_strided_slice.cppindex 368b392a654..01d06563bd5 100644--- a/src/common/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/optimize_strided_slice.cpp@@ -24,23 +24,28 @@#include "transformations/op_conversions/convert_slice_to_strided_slice.hpp"#include "transformations/utils/utils.hpp"-using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;-bool ov::pass::UselessSliceEraser::run_on_model(const std::shared_ptr<ov::Model>& f) {+namespace ov::pass {++bool UselessSliceEraser::run_on_model(const std::shared_ptr<ov::Model>& f) {RUN_ON_FUNCTION_SCOPE(UselessSliceEraser);bool rewritten = false;for (auto& node : f->get_ordered_ops()) {// Recursively apply transformation for sub-graph based operations- rewritten = ov::op::util::process_subgraph(*this, node) || rewritten;+ rewritten = op_util::process_subgraph(*this, node) || rewritten;- bool is_slice = ov::is_type<ov::op::v1::StridedSlice>(node) || ov::is_type<ov::op::v8::Slice>(node);+ bool is_slice = ov::is_type<v1::StridedSlice>(node) || ov::is_type<v8::Slice>(node);if (!is_slice || node->get_output_partial_shape(0).is_dynamic() ||node->get_input_partial_shape(0).is_dynamic())continue;if (node->get_input_shape(0) != node->get_output_shape(0))continue;- auto stridesNode = ov::as_type_ptr<ov::op::v0::Constant>(node->get_input_node_shared_ptr(3));+ auto stridesNode = ov::as_type_ptr<v0::Constant>(node->get_input_node_shared_ptr(3));if (stridesNode) {auto strides = stridesNode->cast_vector<int64_t>();if (!std::any_of(strides.begin(), strides.end(), [](int64_t strd) {@@ -55,7 +60,7 @@ bool ov::pass::UselessSliceEraser::run_on_model(const std::shared_ptr<ov::Model>namespace {-ov::op::util::SlicePlan get_slice_plan(std::shared_ptr<ov::op::v1::StridedSlice> slice) {+op_util::SlicePlan get_slice_plan(std::shared_ptr<v1::StridedSlice> slice) {auto convert_mask_to_axis_set = [](const std::vector<int64_t>& mask) {ov::AxisSet axis_set{};for (size_t i = 0; i < static_cast<size_t>(mask.size()); ++i) {@@ -66,11 +71,11 @@ ov::op::util::SlicePlan get_slice_plan(std::shared_ptr<ov::op::v1::StridedSlice>};auto data = slice->input_value(0).get_node_shared_ptr();- auto begin = ov::as_type_ptr<ov::op::v0::Constant>(slice->input_value(1).get_node_shared_ptr());- auto end = ov::as_type_ptr<ov::op::v0::Constant>(slice->input_value(2).get_node_shared_ptr());- auto strides = ov::as_type_ptr<ov::op::v0::Constant>(slice->input_value(3).get_node_shared_ptr());+ auto begin = ov::as_type_ptr<v0::Constant>(slice->input_value(1).get_node_shared_ptr());+ auto end = ov::as_type_ptr<v0::Constant>(slice->input_value(2).get_node_shared_ptr());+ auto strides = ov::as_type_ptr<v0::Constant>(slice->input_value(3).get_node_shared_ptr());if (!begin || !end || !strides || slice->input(0).get_partial_shape().is_dynamic())- return ov::op::util::SlicePlan();+ return op_util::SlicePlan();auto begin_vec = begin->cast_vector<int64_t>();auto end_vec = end->cast_vector<int64_t>();@@ -78,15 +83,15 @@ ov::op::util::SlicePlan get_slice_plan(std::shared_ptr<ov::op::v1::StridedSlice>const auto begin_mask = convert_mask_to_axis_set(slice->get_begin_mask());const auto end_mask = convert_mask_to_axis_set(slice->get_end_mask());- const auto plan = ov::op::util::make_slice_plan(slice->input(0).get_shape(),- begin_vec,- end_vec,- strides_vec,- begin_mask,- end_mask,- convert_mask_to_axis_set(slice->get_new_axis_mask()),- convert_mask_to_axis_set(slice->get_shrink_axis_mask()),- convert_mask_to_axis_set(slice->get_ellipsis_mask()));+ const auto plan = op_util::make_slice_plan(slice->input(0).get_shape(),+ begin_vec,+ end_vec,+ strides_vec,+ begin_mask,+ end_mask,+ convert_mask_to_axis_set(slice->get_new_axis_mask()),+ convert_mask_to_axis_set(slice->get_shrink_axis_mask()),+ convert_mask_to_axis_set(slice->get_ellipsis_mask()));return plan;}@@ -103,35 +108,35 @@ std::shared_ptr<Node> concat_boundaries(const Output<Node>& lhs, const Output<No? lhs_dtype: rhs_dtype;if (lhs_dtype != common_dtype) {- auto new_lhs = std::make_shared<ov::op::v0::Convert>(_lhs, common_dtype);- _lhs = ov::op::util::try_fold_unary_output(new_lhs);+ auto new_lhs = std::make_shared<v0::Convert>(_lhs, common_dtype);+ _lhs = op_util::try_fold_unary_output(new_lhs);}if (rhs_dtype != common_dtype) {- auto new_rhs = std::make_shared<ov::op::v0::Convert>(_rhs, common_dtype);- _rhs = ov::op::util::try_fold_unary_output(new_rhs);+ auto new_rhs = std::make_shared<v0::Convert>(_rhs, common_dtype);+ _rhs = op_util::try_fold_unary_output(new_rhs);}}- return std::make_shared<ov::op::v0::Concat>(OutputVector{_lhs, _rhs}, 0);+ return std::make_shared<v0::Concat>(OutputVector{_lhs, _rhs}, 0);}} // namespace-bool ov::pass::GroupedStridedSliceOptimizer::run_on_model(const std::shared_ptr<ov::Model>& f) {+bool GroupedStridedSliceOptimizer::run_on_model(const std::shared_ptr<ov::Model>& f) {RUN_ON_FUNCTION_SCOPE(GroupedStridedSliceOptimizer);bool graph_rewritten = false;struct planned_slice {- std::shared_ptr<ov::op::v1::StridedSlice> ptr;- ov::op::util::SlicePlan plan;+ std::shared_ptr<v1::StridedSlice> ptr;+ op_util::SlicePlan plan;};std::map<ov::Output<Node>, std::vector<planned_slice>> source_to_ss_with_plan;for (const auto& node : f->get_ordered_ops()) {// Recursively apply transformation for sub-graph based operations- graph_rewritten = ov::op::util::process_subgraph(*this, node) || graph_rewritten;+ graph_rewritten = op_util::process_subgraph(*this, node) || graph_rewritten;- if (auto ss = ov::as_type_ptr<ov::op::v1::StridedSlice>(node)) {+ if (auto ss = ov::as_type_ptr<v1::StridedSlice>(node)) {auto slice_plan = get_slice_plan(ss);- if (slice_plan == ov::op::util::SlicePlan())+ if (slice_plan == op_util::SlicePlan())continue;source_to_ss_with_plan[ss->input_value(0)].push_back({ss, slice_plan});}@@ -175,7 +180,7 @@ bool ov::pass::GroupedStridedSliceOptimizer::run_on_model(const std::shared_ptr<valid_for_replacement = false;for (auto& target_input : ss_plan.ptr->output(0).get_target_inputs()) {- if (is_type<ov::op::v0::Result>(target_input.get_node())) {+ if (is_type<v0::Result>(target_input.get_node())) {valid_for_replacement = false;break;}@@ -221,14 +226,13 @@ bool ov::pass::GroupedStridedSliceOptimizer::run_on_model(const std::shared_ptr<output_to_size.emplace_back(fake_output, input_shape[axis] - prev_r);}- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {axis});+ auto axis_const = v0::Constant::create(ov::element::i64, ov::Shape{}, {axis});std::vector<int64_t> size_splits;for (const auto& item : output_to_size)size_splits.push_back(item.second);- auto size_splits_const =- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{size_splits.size()}, size_splits);- auto variadic_split = std::make_shared<ov::op::v1::VariadicSplit>(pair.first, axis_const, size_splits_const);+ auto size_splits_const = v0::Constant::create(ov::element::i64, ov::Shape{size_splits.size()}, size_splits);+ auto variadic_split = std::make_shared<v1::VariadicSplit>(pair.first, axis_const, size_splits_const);auto i = 0;NodeVector ops_to_replace;@@ -251,11 +255,11 @@ struct SliceAttrs {};struct SliceWithAttrs {- std::shared_ptr<ov::op::v8::Slice> slice;+ std::shared_ptr<v8::Slice> slice;SliceAttrs attrs;};-bool slice_is_suitable_for_optimization(const std::shared_ptr<ov::op::v8::Slice>& op, SliceAttrs& attrs) {+bool slice_is_suitable_for_optimization(const std::shared_ptr<v8::Slice>& op, SliceAttrs& attrs) {const auto& input_shape = op->get_input_partial_shape(0);const auto& data_rank = input_shape.rank();if (op->get_input_size() != 5 || data_rank.is_dynamic())@@ -263,7 +267,7 @@ bool slice_is_suitable_for_optimization(const std::shared_ptr<ov::op::v8::Slice>const auto rank = data_rank.get_length();auto get_scalar = [](const std::shared_ptr<ov::Node>& node, int64_t& value) -> bool {- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node);+ auto constant = ov::as_type_ptr<v0::Constant>(node);if (!constant)return false;if (shape_size(constant->get_shape()) != 1)@@ -302,7 +306,7 @@ bool slice_is_suitable_for_optimization(const std::shared_ptr<ov::op::v8::Slice>} // namespace-bool ov::pass::GroupedSliceToVSplitOptimization::run_on_model(const std::shared_ptr<ov::Model>& model) {+bool GroupedSliceToVSplitOptimization::run_on_model(const std::shared_ptr<ov::Model>& model) {RUN_ON_FUNCTION_SCOPE(GroupedSliceToVSplitOptimization);bool graph_rewritten = false;@@ -313,9 +317,9 @@ bool ov::pass::GroupedSliceToVSplitOptimization::run_on_model(const std::shared_std::vector<OutputWithAxis> ordered_outputs;for (const auto& node : model->get_ordered_ops()) {// Recursively apply transformation for sub-graph based operations- graph_rewritten = ov::op::util::process_subgraph(*this, node) || graph_rewritten;+ graph_rewritten = op_util::process_subgraph(*this, node) || graph_rewritten;- if (auto op = ov::as_type_ptr<ov::op::v8::Slice>(node)) {+ if (auto op = ov::as_type_ptr<v8::Slice>(node)) {SliceAttrs attributes{};if (slice_is_suitable_for_optimization(op, attributes)) {OutputWithAxis current_output = {op->input_value(0), attributes.axis};@@ -377,9 +381,9 @@ bool ov::pass::GroupedSliceToVSplitOptimization::run_on_model(const std::shared_if (current_sum != dimension)continue;auto split_lengths_const =- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{split_lengths.size()}, split_lengths);- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {axis});- auto variadic_split = std::make_shared<ov::op::v1::VariadicSplit>(output, axis_const, split_lengths_const);+ v0::Constant::create(ov::element::i64, ov::Shape{split_lengths.size()}, split_lengths);+ auto axis_const = v0::Constant::create(ov::element::i64, ov::Shape{}, {axis});+ auto variadic_split = std::make_shared<v1::VariadicSplit>(output, axis_const, split_lengths_const);auto i = 0;for (auto& slice_with_attrs : attributes) {@@ -393,21 +397,17 @@ bool ov::pass::GroupedSliceToVSplitOptimization::run_on_model(const std::shared_return graph_rewritten;}-ov::pass::SliceSequenceToSingleSlice::SliceSequenceToSingleSlice() {+SliceSequenceToSingleSlice::SliceSequenceToSingleSlice() {MATCHER_SCOPE(SliceSequenceToSingleSlice);- using namespace ov::op;- using namespace ov::op::util;- using namespace ov::pass::pattern;-- auto const_axes_1_pattern = wrap_type<v0::Constant>();- auto const_axes_2_pattern = wrap_type<v0::Constant>();- auto slice_1_pattern =- wrap_type<v8::Slice>({any_input(), any_input(), any_input(), any_input(), const_axes_1_pattern},- consumers_count(1));- auto slice_2_pattern =- wrap_type<v8::Slice>({slice_1_pattern, any_input(), any_input(), any_input(), const_axes_2_pattern});-- ov::matcher_pass_callback callback = [=](Matcher& m) {+ auto const_axes_1_pattern = pattern::wrap_type<v0::Constant>();+ auto const_axes_2_pattern = pattern::wrap_type<v0::Constant>();+ auto slice_1_pattern = pattern::wrap_type<v8::Slice>(+ {pattern::any_input(), pattern::any_input(), pattern::any_input(), pattern::any_input(), const_axes_1_pattern},+ pattern::consumers_count(1));+ auto slice_2_pattern = pattern::wrap_type<v8::Slice>(+ {slice_1_pattern, pattern::any_input(), pattern::any_input(), pattern::any_input(), const_axes_2_pattern});++ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_map();auto slice_1 = pattern_to_output.at(slice_1_pattern);auto slice_2 = pattern_to_output.at(slice_2_pattern);@@ -448,26 +448,26 @@ ov::pass::SliceSequenceToSingleSlice::SliceSequenceToSingleSlice() {auto end = concat_boundaries(slice_1->input_value(2), slice_2->input_value(2));auto step = concat_boundaries(slice_1->input_value(3), slice_2->input_value(3));auto axes = concat_boundaries(slice_1->input_value(4), slice_2->input_value(4));- auto one_slice = std::make_shared<ov::op::v8::Slice>(slice_1->input_value(0),- try_fold_unary_output(begin),- try_fold_unary_output(end),- try_fold_unary_output(step),- try_fold_unary_output(axes));+ auto one_slice = std::make_shared<v8::Slice>(slice_1->input_value(0),+ op_util::try_fold_unary_output(begin),+ op_util::try_fold_unary_output(end),+ op_util::try_fold_unary_output(step),+ op_util::try_fold_unary_output(axes));ov::copy_runtime_info({slice_1, slice_2}, {one_slice, begin, end, step, axes});one_slice->set_friendly_name(slice_2->get_friendly_name());ov::replace_node(slice_2, one_slice);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(slice_2_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(slice_2_pattern, matcher_name);register_matcher(m, callback);}-ov::pass::StridedSliceOptimization::StridedSliceOptimization(bool use_shapes) {+StridedSliceOptimization::StridedSliceOptimization(bool use_shapes) {m_use_shapes = use_shapes;}-bool ov::pass::StridedSliceOptimization::run_on_model(const std::shared_ptr<ov::Model>& f) {+bool StridedSliceOptimization::run_on_model(const std::shared_ptr<ov::Model>& f) {RUN_ON_FUNCTION_SCOPE(StridedSliceOptimization);ov::pass::Manager manager("StridedSliceOptimization");manager.set_per_pass_validation(false);@@ -481,3 +481,5 @@ bool ov::pass::StridedSliceOptimization::run_on_model(const std::shared_ptr<ov::manager.register_pass<SliceSequenceToSingleSlice>();return manager.run_passes(f);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cppindex c936301d1e0..d2948398a91 100644--- a/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/pad_fusion.cpp@@ -19,14 +19,19 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;+namespace ov::pass {++namespace {template <typename T>-static bool can_be_fused(const std::shared_ptr<ov::op::util::PadBase>& pad,- const std::shared_ptr<T>& node,- const std::shared_ptr<Node>& pad_value_node,- const std::shared_ptr<ov::op::v0::Constant>& pads_begin,- const std::shared_ptr<ov::op::v0::Constant>& pads_end) {+bool can_be_fused(const std::shared_ptr<op_util::PadBase>& pad,+ const std::shared_ptr<T>& node,+ const std::shared_ptr<Node>& pad_value_node,+ const std::shared_ptr<v0::Constant>& pads_begin,+ const std::shared_ptr<v0::Constant>& pads_end) {if (!pad || pad->get_pad_mode() != ov::op::PadMode::CONSTANT)return false;if (!node)@@ -66,9 +71,9 @@ static bool can_be_fused(const std::shared_ptr<ov::op::util::PadBase>& pad,}template <typename T>-static std::tuple<Shape, Shape> new_pooling_pad_values(const std::shared_ptr<ov::op::v0::Constant>& pads_begin,- const std::shared_ptr<ov::op::v0::Constant>& pads_end,- const std::shared_ptr<T>& node) {+std::tuple<Shape, Shape> new_pooling_pad_values(const std::shared_ptr<v0::Constant>& pads_begin,+ const std::shared_ptr<v0::Constant>& pads_end,+ const std::shared_ptr<T>& node) {auto node_pads_begin = node->get_pads_begin();auto node_pads_end = node->get_pads_end();auto pads_begin_val = pads_begin->cast_vector<size_t>();@@ -92,29 +97,57 @@ static std::tuple<Shape, Shape> new_pooling_pad_values(const std::shared_ptr<ov:return std::make_tuple(node_pads_begin, node_pads_end);}-pass::PadFusionAvgPool::PadFusionAvgPool() {+template <typename T>+std::tuple<CoordinateDiff, CoordinateDiff> new_conv_pad_values(const std::shared_ptr<v0::Constant>& pads_begin,+ const std::shared_ptr<v0::Constant>& pads_end,+ const std::shared_ptr<T>& node) {+ auto node_pads_begin = node->get_pads_begin();+ auto node_pads_end = node->get_pads_end();+ auto pads_begin_val = pads_begin->cast_vector<size_t>();+ auto pads_end_val = pads_end->cast_vector<size_t>();++ std::transform(node_pads_begin.begin(),+ node_pads_begin.end(),+ pads_begin_val.begin() + 2,+ node_pads_begin.begin(),+ [](std::ptrdiff_t a, size_t b) -> std::ptrdiff_t {+ return a + b;+ });+ std::transform(node_pads_end.begin(),+ node_pads_end.end(),+ pads_end_val.begin() + 2,+ node_pads_end.begin(),+ [](std::ptrdiff_t a, size_t b) -> std::ptrdiff_t {+ return a + b;+ });++ return std::make_tuple(node_pads_begin, node_pads_end);+}+} // namespace++PadFusionAvgPool::PadFusionAvgPool() {MATCHER_SCOPE(PadFusionAvgPool);auto data_pattern = pattern::any_input();- auto pads_begin_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto pads_end_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto pads_begin_pattern = pattern::wrap_type<v0::Constant>();+ auto pads_end_pattern = pattern::wrap_type<v0::Constant>();auto pad_value_pattern = pattern::any_input();- auto pad_node_pattern = pattern::wrap_type<ov::op::util::PadBase>(- {data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},- pattern::consumers_count(1));- auto avg_pool_pattern = pattern::wrap_type<ov::op::v1::AvgPool>({pad_node_pattern});+ auto pad_node_pattern =+ pattern::wrap_type<op_util::PadBase>({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},+ pattern::consumers_count(1));+ auto avg_pool_pattern = pattern::wrap_type<v1::AvgPool>({pad_node_pattern});matcher_pass_callback callback = [=](pattern::Matcher& m) {auto pattern_map = m.get_pattern_value_map();auto data = pattern_map[data_pattern];- auto pad = ov::as_type_ptr<ov::op::util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());+ auto pad = ov::as_type_ptr<op_util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr();- auto pads_begin = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());- auto pads_end = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());- auto avg_pool = ov::as_type_ptr<ov::op::v1::AvgPool>(pattern_map[avg_pool_pattern].get_node_shared_ptr());+ auto pads_begin = ov::as_type_ptr<v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());+ auto pads_end = ov::as_type_ptr<v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());+ auto avg_pool = ov::as_type_ptr<v1::AvgPool>(pattern_map[avg_pool_pattern].get_node_shared_ptr());if (!can_be_fused(pad, avg_pool, pad_value, pads_begin, pads_end))return false;- std::shared_ptr<ov::op::v1::AvgPool> new_avg_pool;+ std::shared_ptr<v1::AvgPool> new_avg_pool;if (avg_pool->get_exclude_pad()) {const auto& avg_pads_begin = avg_pool->get_pads_begin();const auto& avg_pads_end = avg_pool->get_pads_end();@@ -129,26 +162,25 @@ pass::PadFusionAvgPool::PadFusionAvgPool() {return false;auto pads_begin_val = pads_begin->cast_vector<size_t>();auto pads_end_val = pads_end->cast_vector<size_t>();- new_avg_pool =- std::make_shared<ov::op::v1::AvgPool>(data,- avg_pool->get_strides(),- Shape{pads_begin_val.begin() + 2, pads_begin_val.end()},- Shape{pads_end_val.begin() + 2, pads_end_val.end()},- avg_pool->get_kernel(),- false,- avg_pool->get_rounding_type(),- ov::op::PadType::EXPLICIT);+ new_avg_pool = std::make_shared<v1::AvgPool>(data,+ avg_pool->get_strides(),+ Shape{pads_begin_val.begin() + 2, pads_begin_val.end()},+ Shape{pads_end_val.begin() + 2, pads_end_val.end()},+ avg_pool->get_kernel(),+ false,+ avg_pool->get_rounding_type(),+ ov::op::PadType::EXPLICIT);} else {Shape new_pads_begin, new_pads_end;std::tie(new_pads_begin, new_pads_end) = new_pooling_pad_values(pads_begin, pads_end, avg_pool);- new_avg_pool = std::make_shared<ov::op::v1::AvgPool>(data,- avg_pool->get_strides(),- new_pads_begin,- new_pads_end,- avg_pool->get_kernel(),- false,- avg_pool->get_rounding_type(),- ov::op::PadType::EXPLICIT);+ new_avg_pool = std::make_shared<v1::AvgPool>(data,+ avg_pool->get_strides(),+ new_pads_begin,+ new_pads_end,+ avg_pool->get_kernel(),+ false,+ avg_pool->get_rounding_type(),+ ov::op::PadType::EXPLICIT);}new_avg_pool->set_friendly_name(avg_pool->get_friendly_name());@@ -162,67 +194,39 @@ pass::PadFusionAvgPool::PadFusionAvgPool() {this->register_matcher(m, callback);}-template <typename T>-static std::tuple<CoordinateDiff, CoordinateDiff> new_conv_pad_values(- const std::shared_ptr<ov::op::v0::Constant>& pads_begin,- const std::shared_ptr<ov::op::v0::Constant>& pads_end,- const std::shared_ptr<T>& node) {- auto node_pads_begin = node->get_pads_begin();- auto node_pads_end = node->get_pads_end();- auto pads_begin_val = pads_begin->cast_vector<size_t>();- auto pads_end_val = pads_end->cast_vector<size_t>();-- std::transform(node_pads_begin.begin(),- node_pads_begin.end(),- pads_begin_val.begin() + 2,- node_pads_begin.begin(),- [](std::ptrdiff_t a, size_t b) -> std::ptrdiff_t {- return a + b;- });- std::transform(node_pads_end.begin(),- node_pads_end.end(),- pads_end_val.begin() + 2,- node_pads_end.begin(),- [](std::ptrdiff_t a, size_t b) -> std::ptrdiff_t {- return a + b;- });-- return std::make_tuple(node_pads_begin, node_pads_end);-}--pass::PadFusionConvolution::PadFusionConvolution() {+PadFusionConvolution::PadFusionConvolution() {MATCHER_SCOPE(PadFusionConvolution);auto data_pattern = pattern::any_input();auto filter_pattern = pattern::any_input();- auto pads_begin_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto pads_end_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto pads_begin_pattern = pattern::wrap_type<v0::Constant>();+ auto pads_end_pattern = pattern::wrap_type<v0::Constant>();auto pad_value_pattern = pattern::any_input();- auto pad_node_pattern = pattern::wrap_type<ov::op::util::PadBase>(- {data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},- pattern::consumers_count(1));- auto conv_pattern = pattern::wrap_type<ov::op::v1::Convolution>({pad_node_pattern, filter_pattern});+ auto pad_node_pattern =+ pattern::wrap_type<op_util::PadBase>({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},+ pattern::consumers_count(1));+ auto conv_pattern = pattern::wrap_type<v1::Convolution>({pad_node_pattern, filter_pattern});matcher_pass_callback callback = [=](pattern::Matcher& m) {auto pattern_map = m.get_pattern_value_map();auto data = pattern_map[data_pattern];auto filter = pattern_map[filter_pattern];- auto pad = ov::as_type_ptr<ov::op::util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());+ auto pad = ov::as_type_ptr<op_util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr();- auto pads_begin = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());- auto pads_end = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());- auto conv = ov::as_type_ptr<ov::op::v1::Convolution>(pattern_map[conv_pattern].get_node_shared_ptr());+ auto pads_begin = ov::as_type_ptr<v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());+ auto pads_end = ov::as_type_ptr<v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());+ auto conv = ov::as_type_ptr<v1::Convolution>(pattern_map[conv_pattern].get_node_shared_ptr());if (!can_be_fused(pad, conv, pad_value, pads_begin, pads_end))return false;CoordinateDiff new_pads_begin, new_pads_end;std::tie(new_pads_begin, new_pads_end) = new_conv_pad_values(pads_begin, pads_end, conv);- auto new_conv = std::make_shared<ov::op::v1::Convolution>(data,- filter,- conv->get_strides(),- new_pads_begin,- new_pads_end,- conv->get_dilations(),- ov::op::PadType::EXPLICIT);+ auto new_conv = std::make_shared<v1::Convolution>(data,+ filter,+ conv->get_strides(),+ new_pads_begin,+ new_pads_end,+ conv->get_dilations(),+ ov::op::PadType::EXPLICIT);new_conv->set_friendly_name(conv->get_friendly_name());copy_runtime_info({pad, conv}, new_conv);@@ -235,28 +239,27 @@ pass::PadFusionConvolution::PadFusionConvolution() {this->register_matcher(m, callback);}-pass::PadFusionConvolutionBackpropData::PadFusionConvolutionBackpropData() {+PadFusionConvolutionBackpropData::PadFusionConvolutionBackpropData() {MATCHER_SCOPE(PadFusionConvolutionBackpropData);auto data_pattern = pattern::any_input();auto filter_pattern = pattern::any_input();- auto pads_begin_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto pads_end_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto pads_begin_pattern = pattern::wrap_type<v0::Constant>();+ auto pads_end_pattern = pattern::wrap_type<v0::Constant>();auto pad_value_pattern = pattern::any_input();- auto pad_node_pattern = pattern::wrap_type<ov::op::util::PadBase>(- {data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},- pattern::consumers_count(1));- auto conv_pattern = pattern::wrap_type<ov::op::v1::ConvolutionBackpropData>({pad_node_pattern, filter_pattern});+ auto pad_node_pattern =+ pattern::wrap_type<op_util::PadBase>({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},+ pattern::consumers_count(1));+ auto conv_pattern = pattern::wrap_type<v1::ConvolutionBackpropData>({pad_node_pattern, filter_pattern});matcher_pass_callback callback = [=](pattern::Matcher& m) {auto pattern_map = m.get_pattern_value_map();auto data = pattern_map[data_pattern];auto filter = pattern_map[filter_pattern];- auto pad = ov::as_type_ptr<ov::op::util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());+ auto pad = ov::as_type_ptr<op_util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr();- auto pads_begin = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());- auto pads_end = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());- auto conv =- ov::as_type_ptr<ov::op::v1::ConvolutionBackpropData>(pattern_map[conv_pattern].get_node_shared_ptr());+ auto pads_begin = ov::as_type_ptr<v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());+ auto pads_end = ov::as_type_ptr<v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());+ auto conv = ov::as_type_ptr<v1::ConvolutionBackpropData>(pattern_map[conv_pattern].get_node_shared_ptr());if (!can_be_fused(pad, conv, pad_value, pads_begin, pads_end))return false;@@ -271,14 +274,14 @@ pass::PadFusionConvolutionBackpropData::PadFusionConvolutionBackpropData() {conv_pads_end[i] -= pads_end_val[i + 2];}- auto new_conv = std::make_shared<ov::op::v1::ConvolutionBackpropData>(data,- filter,- conv->get_strides(),- conv_pads_begin,- conv_pads_end,- conv->get_dilations(),- ov::op::PadType::EXPLICIT,- conv->get_output_padding());+ auto new_conv = std::make_shared<v1::ConvolutionBackpropData>(data,+ filter,+ conv->get_strides(),+ conv_pads_begin,+ conv_pads_end,+ conv->get_dilations(),+ ov::op::PadType::EXPLICIT,+ conv->get_output_padding());new_conv->set_friendly_name(conv->get_friendly_name());copy_runtime_info({pad, conv}, new_conv);@@ -291,39 +294,39 @@ pass::PadFusionConvolutionBackpropData::PadFusionConvolutionBackpropData() {this->register_matcher(m, callback);}-pass::PadFusionGroupConvolution::PadFusionGroupConvolution() {+PadFusionGroupConvolution::PadFusionGroupConvolution() {MATCHER_SCOPE(PadFusionGroupConvolution);auto data_pattern = pattern::any_input();auto filter_pattern = pattern::any_input();- auto pads_begin_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto pads_end_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto pads_begin_pattern = pattern::wrap_type<v0::Constant>();+ auto pads_end_pattern = pattern::wrap_type<v0::Constant>();auto pad_value_pattern = pattern::any_input();- auto pad_node_pattern = pattern::wrap_type<ov::op::util::PadBase>(- {data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},- pattern::consumers_count(1));- auto conv_pattern = pattern::wrap_type<ov::op::v1::GroupConvolution>({pad_node_pattern, filter_pattern});+ auto pad_node_pattern =+ pattern::wrap_type<op_util::PadBase>({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},+ pattern::consumers_count(1));+ auto conv_pattern = pattern::wrap_type<v1::GroupConvolution>({pad_node_pattern, filter_pattern});matcher_pass_callback callback = [=](pattern::Matcher& m) {auto pattern_map = m.get_pattern_value_map();auto data = pattern_map[data_pattern];auto filter = pattern_map[filter_pattern];- auto pad = ov::as_type_ptr<ov::op::util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());+ auto pad = ov::as_type_ptr<op_util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr();- auto pads_begin = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());- auto pads_end = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());- auto conv = ov::as_type_ptr<ov::op::v1::GroupConvolution>(pattern_map[conv_pattern].get_node_shared_ptr());+ auto pads_begin = ov::as_type_ptr<v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());+ auto pads_end = ov::as_type_ptr<v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());+ auto conv = ov::as_type_ptr<v1::GroupConvolution>(pattern_map[conv_pattern].get_node_shared_ptr());if (!can_be_fused(pad, conv, pad_value, pads_begin, pads_end))return false;CoordinateDiff new_pads_begin, new_pads_end;std::tie(new_pads_begin, new_pads_end) = new_conv_pad_values(pads_begin, pads_end, conv);- auto new_conv = std::make_shared<ov::op::v1::GroupConvolution>(data,- filter,- conv->get_strides(),- new_pads_begin,- new_pads_end,- conv->get_dilations(),- ov::op::PadType::EXPLICIT);+ auto new_conv = std::make_shared<v1::GroupConvolution>(data,+ filter,+ conv->get_strides(),+ new_pads_begin,+ new_pads_end,+ conv->get_dilations(),+ ov::op::PadType::EXPLICIT);new_conv->set_friendly_name(conv->get_friendly_name());copy_runtime_info({pad, conv}, new_conv);@@ -336,29 +339,27 @@ pass::PadFusionGroupConvolution::PadFusionGroupConvolution() {this->register_matcher(m, callback);}-pass::PadFusionGroupConvolutionBackpropData::PadFusionGroupConvolutionBackpropData() {+PadFusionGroupConvolutionBackpropData::PadFusionGroupConvolutionBackpropData() {MATCHER_SCOPE(PadFusionGroupConvolutionBackpropData);auto data_pattern = pattern::any_input();auto filter_pattern = pattern::any_input();- auto pads_begin_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto pads_end_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto pads_begin_pattern = pattern::wrap_type<v0::Constant>();+ auto pads_end_pattern = pattern::wrap_type<v0::Constant>();auto pad_value_pattern = pattern::any_input();- auto pad_node_pattern = pattern::wrap_type<ov::op::util::PadBase>(- {data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},- pattern::consumers_count(1));- auto conv_pattern =- pattern::wrap_type<ov::op::v1::GroupConvolutionBackpropData>({pad_node_pattern, filter_pattern});+ auto pad_node_pattern =+ pattern::wrap_type<op_util::PadBase>({data_pattern, pads_begin_pattern, pads_end_pattern, pad_value_pattern},+ pattern::consumers_count(1));+ auto conv_pattern = pattern::wrap_type<v1::GroupConvolutionBackpropData>({pad_node_pattern, filter_pattern});matcher_pass_callback callback = [=](pattern::Matcher& m) {auto pattern_map = m.get_pattern_value_map();auto data = pattern_map[data_pattern];auto filter = pattern_map[filter_pattern];- auto pad = ov::as_type_ptr<ov::op::util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());+ auto pad = ov::as_type_ptr<op_util::PadBase>(pattern_map[pad_node_pattern].get_node_shared_ptr());auto pad_value = pattern_map[pad_value_pattern].get_node_shared_ptr();- auto pads_begin = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());- auto pads_end = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());- auto conv =- ov::as_type_ptr<ov::op::v1::GroupConvolutionBackpropData>(pattern_map[conv_pattern].get_node_shared_ptr());+ auto pads_begin = ov::as_type_ptr<v0::Constant>(pattern_map[pads_begin_pattern].get_node_shared_ptr());+ auto pads_end = ov::as_type_ptr<v0::Constant>(pattern_map[pads_end_pattern].get_node_shared_ptr());+ auto conv = ov::as_type_ptr<v1::GroupConvolutionBackpropData>(pattern_map[conv_pattern].get_node_shared_ptr());if (!can_be_fused(pad, conv, pad_value, pads_begin, pads_end))return false;@@ -373,14 +374,14 @@ pass::PadFusionGroupConvolutionBackpropData::PadFusionGroupConvolutionBackpropDaconv_pads_end[i] -= pads_end_val[i + 2];}- auto new_conv = std::make_shared<ov::op::v1::GroupConvolutionBackpropData>(data,- filter,- conv->get_strides(),- conv_pads_begin,- conv_pads_end,- conv->get_dilations(),- ov::op::PadType::EXPLICIT,- conv->get_output_padding());+ auto new_conv = std::make_shared<v1::GroupConvolutionBackpropData>(data,+ filter,+ conv->get_strides(),+ conv_pads_begin,+ conv_pads_end,+ conv->get_dilations(),+ ov::op::PadType::EXPLICIT,+ conv->get_output_padding());new_conv->set_friendly_name(conv->get_friendly_name());copy_runtime_info({pad, conv}, new_conv);@@ -392,3 +393,5 @@ pass::PadFusionGroupConvolutionBackpropData::PadFusionGroupConvolutionBackpropDaauto m = std::make_shared<pattern::Matcher>(conv_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/prelu_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/prelu_fusion.cppindex 798052c6e57..5b174d7d92e 100644--- a/src/common/transformations/src/transformations/common_optimizations/prelu_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/prelu_fusion.cpp@@ -23,23 +23,29 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::PReluFusionNegativeAdd::PReluFusionNegativeAdd() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {++PReluFusionNegativeAdd::PReluFusionNegativeAdd() {MATCHER_SCOPE(PReluFusionNegativeAdd);- auto input = pass::pattern::any_input();- auto relu_pos = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({input});- auto neg1 = ov::pass::pattern::wrap_type<ov::op::v0::Negative>({input});- auto relu_neg = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({neg1});- auto neg2 = ov::pass::pattern::wrap_type<ov::op::v0::Negative>({relu_neg});- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({neg2, mul_constant});- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({relu_pos, mul});-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto relu_pos = pattern::wrap_type<v0::Relu>({input});+ auto neg1 = pattern::wrap_type<v0::Negative>({input});+ auto relu_neg = pattern::wrap_type<v0::Relu>({neg1});+ auto neg2 = pattern::wrap_type<v0::Negative>({relu_neg});+ auto mul_constant = pattern::wrap_type<v0::Constant>();+ auto mul = pattern::wrap_type<v1::Multiply>({neg2, mul_constant});+ auto add = pattern::wrap_type<v1::Add>({relu_pos, mul});++ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto input_output = pattern_to_output.at(input);auto slope_output = pattern_to_output.at(mul_constant);auto add_node = pattern_to_output.at(add).get_node_shared_ptr();- auto prelu = std::make_shared<ov::op::v0::PRelu>(input_output, slope_output);+ auto prelu = std::make_shared<v0::PRelu>(input_output, slope_output);prelu->set_friendly_name(m.get_match_root()->get_friendly_name());ov::NodeVector copy_from = {pattern_to_output.at(relu_pos).get_node_shared_ptr(),pattern_to_output.at(neg1).get_node_shared_ptr(),@@ -51,26 +57,26 @@ ov::pass::PReluFusionNegativeAdd::PReluFusionNegativeAdd() {ov::replace_node(add_node, prelu);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(add, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(add, matcher_name);register_matcher(m, callback);}-ov::pass::PReluFusionNegativeSub::PReluFusionNegativeSub() {+PReluFusionNegativeSub::PReluFusionNegativeSub() {MATCHER_SCOPE(PReluFusionNegativeSub);- auto input = pass::pattern::any_input();- auto relu_pos = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({input});- auto neg1 = ov::pass::pattern::wrap_type<ov::op::v0::Negative>({input});- auto relu_neg = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({neg1});- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({relu_neg, mul_constant});- auto sub = ov::pass::pattern::wrap_type<ov::op::v1::Subtract>({relu_pos, mul});-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto relu_pos = pattern::wrap_type<v0::Relu>({input});+ auto neg1 = pattern::wrap_type<v0::Negative>({input});+ auto relu_neg = pattern::wrap_type<v0::Relu>({neg1});+ auto mul_constant = pattern::wrap_type<v0::Constant>();+ auto mul = pattern::wrap_type<v1::Multiply>({relu_neg, mul_constant});+ auto sub = pattern::wrap_type<v1::Subtract>({relu_pos, mul});++ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto input_output = pattern_to_output.at(input);auto slope_output = pattern_to_output.at(mul_constant);auto sub_node = pattern_to_output.at(sub).get_node_shared_ptr();- auto prelu = std::make_shared<ov::op::v0::PRelu>(input_output, slope_output);+ auto prelu = std::make_shared<v0::PRelu>(input_output, slope_output);prelu->set_friendly_name(m.get_match_root()->get_friendly_name());ov::NodeVector copy_from = {pattern_to_output.at(relu_pos).get_node_shared_ptr(),pattern_to_output.at(neg1).get_node_shared_ptr(),@@ -81,42 +87,50 @@ ov::pass::PReluFusionNegativeSub::PReluFusionNegativeSub() {ov::replace_node(sub_node, prelu);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(sub, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(sub, matcher_name);register_matcher(m, callback);}-static std::function<bool(ov::Output<ov::Node>)> constant_value(const float target_value) {+} // namespace ov::pass++namespace {++std::function<bool(ov::Output<ov::Node>)> constant_value(const float target_value) {return [=](const ov::Output<ov::Node>& output) -> bool {- auto node = ov::as_type_ptr<ov::op::v0::Constant>(output.get_node_shared_ptr());+ auto node = ov::as_type_ptr<v0::Constant>(output.get_node_shared_ptr());if (!node) {return false;}float value;- if (!ov::op::util::get_single_value(node, value)) {+ if (!op_util::get_single_value(node, value)) {return false;}return value == target_value;};}-ov::pass::PReluFusionMultiplyAdd::PReluFusionMultiplyAdd() {+} // namespace++namespace ov::pass {++PReluFusionMultiplyAdd::PReluFusionMultiplyAdd() {MATCHER_SCOPE(PReluFusionMultiplyAdd);- auto input = pass::pattern::any_input();- auto relu_pos = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({input});- auto mul_neg_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(constant_value(-1.0));- auto mul_neg = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_neg_constant});- auto relu_neg = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({mul_neg});- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({relu_neg, mul_constant});- auto add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({relu_pos, mul});-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto relu_pos = pattern::wrap_type<v0::Relu>({input});+ auto mul_neg_constant = pattern::wrap_type<v0::Constant>(constant_value(-1.0));+ auto mul_neg = pattern::wrap_type<v1::Multiply>({input, mul_neg_constant});+ auto relu_neg = pattern::wrap_type<v0::Relu>({mul_neg});+ auto mul_constant = pattern::wrap_type<v0::Constant>();+ auto mul = pattern::wrap_type<v1::Multiply>({relu_neg, mul_constant});+ auto add = pattern::wrap_type<v1::Add>({relu_pos, mul});++ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto input_output = pattern_to_output.at(input);auto slope_output = pattern_to_output.at(mul_constant);auto add_node = pattern_to_output.at(add).get_node_shared_ptr();- auto negative = ov::op::util::make_try_fold<ov::op::v0::Negative>(slope_output);- auto prelu = std::make_shared<ov::op::v0::PRelu>(input_output, negative);+ auto negative = op_util::make_try_fold<v0::Negative>(slope_output);+ auto prelu = std::make_shared<v0::PRelu>(input_output, negative);prelu->set_friendly_name(m.get_match_root()->get_friendly_name());ov::NodeVector copy_from = {pattern_to_output.at(relu_pos).get_node_shared_ptr(),@@ -128,27 +142,27 @@ ov::pass::PReluFusionMultiplyAdd::PReluFusionMultiplyAdd() {ov::replace_node(add_node, prelu);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(add, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(add, matcher_name);register_matcher(m, callback);}-ov::pass::PReluFusionMultiplySub::PReluFusionMultiplySub() {+PReluFusionMultiplySub::PReluFusionMultiplySub() {MATCHER_SCOPE(PReluFusionMultiplySub);- auto input = pass::pattern::any_input();- auto relu_pos = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({input});- auto mul_neg_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(constant_value(-1.0));- auto mul_neg = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({input, mul_neg_constant});- auto relu_neg = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({mul_neg});- auto mul_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({relu_neg, mul_constant});- auto sub = ov::pass::pattern::wrap_type<ov::op::v1::Subtract>({relu_pos, mul});-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto input = pattern::any_input();+ auto relu_pos = pattern::wrap_type<v0::Relu>({input});+ auto mul_neg_constant = pattern::wrap_type<v0::Constant>(constant_value(-1.0));+ auto mul_neg = pattern::wrap_type<v1::Multiply>({input, mul_neg_constant});+ auto relu_neg = pattern::wrap_type<v0::Relu>({mul_neg});+ auto mul_constant = pattern::wrap_type<v0::Constant>();+ auto mul = pattern::wrap_type<v1::Multiply>({relu_neg, mul_constant});+ auto sub = pattern::wrap_type<v1::Subtract>({relu_pos, mul});++ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto input_output = pattern_to_output.at(input);auto slope_output = pattern_to_output.at(mul_constant);auto sub_node = pattern_to_output.at(sub).get_node_shared_ptr();- auto prelu = std::make_shared<ov::op::v0::PRelu>(input_output, slope_output);+ auto prelu = std::make_shared<v0::PRelu>(input_output, slope_output);prelu->set_friendly_name(m.get_match_root()->get_friendly_name());ov::NodeVector copy_from = {pattern_to_output.at(relu_pos).get_node_shared_ptr(),@@ -160,84 +174,80 @@ ov::pass::PReluFusionMultiplySub::PReluFusionMultiplySub() {ov::replace_node(sub_node, prelu);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(sub, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(sub, matcher_name);register_matcher(m, callback);}-ov::pass::PReluFusionAbsSubMulMulAdd::PReluFusionAbsSubMulMulAdd() {+PReluFusionAbsSubMulMulAdd::PReluFusionAbsSubMulMulAdd() {MATCHER_SCOPE(PReluFusionAbsSubMulMulAdd);- using namespace std;- using namespace ov;-- const auto equals_half = [](const Output<Node>& node) {+ const auto equals_half = [](const ov::Output<ov::Node>& node) {float v;- const auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node.get_node_shared_ptr());- return constant && ov::op::util::get_single_value(constant, v) && v == 0.5f;+ const auto constant = ov::as_type_ptr<v0::Constant>(node.get_node_shared_ptr());+ return constant && op_util::get_single_value(constant, v) && v == 0.5f;};- const auto input = pass::pattern::any_input();- const auto relu = pattern::wrap_type<ov::op::v0::Relu>({input});- const auto abs = pattern::wrap_type<ov::op::v0::Abs>({input});- const auto sub = pattern::wrap_type<ov::op::v1::Subtract>({input, abs});- const auto mul_1_constant = pattern::wrap_type<ov::op::v0::Constant>();- const auto mul_1 = pattern::wrap_type<ov::op::v1::Multiply>({sub, mul_1_constant});- const auto mul_2_constant = pattern::wrap_type<ov::op::v0::Constant>(equals_half);- const auto mul_2 = pattern::wrap_type<ov::op::v1::Multiply>({mul_1, mul_2_constant});- const auto add = pattern::wrap_type<ov::op::v1::Add>({mul_2, relu});-- matcher_pass_callback callback = [=](pattern::Matcher& m) {+ const auto input = pattern::any_input();+ const auto relu = pattern::wrap_type<v0::Relu>({input});+ const auto abs = pattern::wrap_type<v0::Abs>({input});+ const auto sub = pattern::wrap_type<v1::Subtract>({input, abs});+ const auto mul_1_constant = pattern::wrap_type<v0::Constant>();+ const auto mul_1 = pattern::wrap_type<v1::Multiply>({sub, mul_1_constant});+ const auto mul_2_constant = pattern::wrap_type<v0::Constant>(equals_half);+ const auto mul_2 = pattern::wrap_type<v1::Multiply>({mul_1, mul_2_constant});+ const auto add = pattern::wrap_type<v1::Add>({mul_2, relu});++ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();const auto input_output = pattern_to_output.at(input);const auto add_node = pattern_to_output.at(add).get_node_shared_ptr();const auto slope = pattern_to_output.at(mul_1_constant);- const auto prelu = make_shared<ov::op::v0::PRelu>(input_output, slope);+ const auto prelu = std::make_shared<v0::PRelu>(input_output, slope);prelu->set_friendly_name(m.get_match_root()->get_friendly_name());- const OutputVector copy_from = {pattern_to_output.at(relu),- pattern_to_output.at(abs),- pattern_to_output.at(sub),- pattern_to_output.at(mul_1),- pattern_to_output.at(mul_2),- pattern_to_output.at(add)};- copy_runtime_info(as_node_vector(copy_from), prelu);- replace_node(add_node, prelu);+ const ov::OutputVector copy_from = {pattern_to_output.at(relu),+ pattern_to_output.at(abs),+ pattern_to_output.at(sub),+ pattern_to_output.at(mul_1),+ pattern_to_output.at(mul_2),+ pattern_to_output.at(add)};+ ov::copy_runtime_info(ov::as_node_vector(copy_from), prelu);+ ov::replace_node(add_node, prelu);return true;};- auto m = make_shared<pattern::Matcher>(add, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(add, matcher_name);register_matcher(m, callback);}-ov::pass::PReluFusionNegReluMulAdd::PReluFusionNegReluMulAdd() {+PReluFusionNegReluMulAdd::PReluFusionNegReluMulAdd() {MATCHER_SCOPE(PReluFusionNegReluMulAdd);- using namespace std;- using namespace ov;-- const auto input = pass::pattern::any_input();- const auto relu_pos = pattern::wrap_type<ov::op::v0::Relu>({input});- const auto neg1 = pattern::wrap_type<ov::op::v0::Negative>({input});- const auto relu_neg = pattern::wrap_type<ov::op::v0::Relu>({neg1});- const auto mul_constant = pattern::wrap_type<ov::op::v0::Constant>();- const auto mul = pattern::wrap_type<ov::op::v1::Multiply>({relu_neg, mul_constant});- const auto add = pattern::wrap_type<ov::op::v1::Add>({relu_pos, mul});+ const auto input = pattern::any_input();+ const auto relu_pos = pattern::wrap_type<v0::Relu>({input});+ const auto neg1 = pattern::wrap_type<v0::Negative>({input});+ const auto relu_neg = pattern::wrap_type<v0::Relu>({neg1});+ const auto mul_constant = pattern::wrap_type<v0::Constant>();+ const auto mul = pattern::wrap_type<v1::Multiply>({relu_neg, mul_constant});+ const auto add = pattern::wrap_type<v1::Add>({relu_pos, mul});- matcher_pass_callback callback = [=](pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();const auto input_output = pattern_to_output.at(input);const auto add_node = pattern_to_output.at(add).get_node_shared_ptr();- const auto slope = ov::op::util::make_try_fold<ov::op::v0::Negative>(pattern_to_output.at(mul_constant));- const auto prelu = make_shared<ov::op::v0::PRelu>(input_output, slope);+ const auto slope = op_util::make_try_fold<v0::Negative>(pattern_to_output.at(mul_constant));+ const auto prelu = std::make_shared<v0::PRelu>(input_output, slope);prelu->set_friendly_name(m.get_match_root()->get_friendly_name());- NodeVector copy_from = {pattern_to_output.at(relu_pos).get_node_shared_ptr(),- pattern_to_output.at(neg1).get_node_shared_ptr(),- pattern_to_output.at(relu_neg).get_node_shared_ptr(),- pattern_to_output.at(mul).get_node_shared_ptr(),- pattern_to_output.at(add).get_node_shared_ptr()};- copy_runtime_info(copy_from, prelu);- replace_node(add_node, prelu);+ ov::NodeVector copy_from = {pattern_to_output.at(relu_pos).get_node_shared_ptr(),+ pattern_to_output.at(neg1).get_node_shared_ptr(),+ pattern_to_output.at(relu_neg).get_node_shared_ptr(),+ pattern_to_output.at(mul).get_node_shared_ptr(),+ pattern_to_output.at(add).get_node_shared_ptr()};+ ov::copy_runtime_info(copy_from, prelu);+ ov::replace_node(add_node, prelu);return true;};- auto matcher = make_shared<pattern::Matcher>(add, matcher_name);+ auto matcher = std::make_shared<pattern::Matcher>(add, matcher_name);register_matcher(matcher, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/pull_through_reduce.cpp b/src/common/transformations/src/transformations/common_optimizations/pull_through_reduce.cppindex a1bdb5c9815..3cff0083c69 100644--- a/src/common/transformations/src/transformations/common_optimizations/pull_through_reduce.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/pull_through_reduce.cpp@@ -22,6 +22,11 @@#include "sequence_generator.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace op_util = ov::op::util;++namespace ov::pass {+namespace {// Adjust axes of Unsqueeze/Reduce ops after Unsqueeze pulling// For example if we have:@@ -89,13 +94,13 @@ std::vector<int64_t> try_get_unsqueeze_axes_from_reshape(const ov::Shape& target}// Update given reshape_input_shape by inserting "1" dimension on the postion represented by axes_to_insert-std::shared_ptr<ov::op::v0::Constant> update_reshape_target_shape(const ov::Shape& reshape_input_shape,- const std::vector<int64_t>& axes_to_insert) {+std::shared_ptr<v0::Constant> update_reshape_target_shape(const ov::Shape& reshape_input_shape,+ const std::vector<int64_t>& axes_to_insert) {auto result = std::vector<int64_t>(std::begin(reshape_input_shape), std::end(reshape_input_shape));for (const auto& axis : axes_to_insert) {result.insert(std::next(std::begin(result), axis), 1);}- return ov::op::v0::Constant::create(ov::element::i64, ov::Shape{result.size()}, result);+ return v0::Constant::create(ov::element::i64, ov::Shape{result.size()}, result);}// Return true if given inputs have some common elements, otherwise return false.@@ -107,28 +112,23 @@ bool have_same_axes(const std::vector<int64_t>& unsqueeze_axes, const std::vecto}} // namespace-ov::pass::PullUnsqueezeThroughReduce::PullUnsqueezeThroughReduce() {+PullUnsqueezeThroughReduce::PullUnsqueezeThroughReduce() {MATCHER_SCOPE(PullUnsqueezeThroughReduce);const auto input = pattern::any_input(pattern::has_static_rank());- const auto unsqueeze_axes = pattern::wrap_type<ov::op::v0::Constant>();- const auto unsqueeze =- pattern::wrap_type<ov::op::v0::Unsqueeze>({input, unsqueeze_axes}, pattern::consumers_count(1));- const auto reduce_axes = pattern::wrap_type<ov::op::v0::Constant>();- const auto reduce =- pattern::wrap_type<ov::op::util::ArithmeticReductionKeepDims, ov::op::util::LogicalReductionKeepDims>(- {unsqueeze, reduce_axes});+ const auto unsqueeze_axes = pattern::wrap_type<v0::Constant>();+ const auto unsqueeze = pattern::wrap_type<v0::Unsqueeze>({input, unsqueeze_axes}, pattern::consumers_count(1));+ const auto reduce_axes = pattern::wrap_type<v0::Constant>();+ const auto reduce = pattern::wrap_type<op_util::ArithmeticReductionKeepDims, op_util::LogicalReductionKeepDims>(+ {unsqueeze, reduce_axes});matcher_pass_callback callback = [=](pattern::Matcher& m) {auto& pattern_map = m.get_pattern_value_map();const auto input_node = pattern_map.at(input);- const auto reduce_node =- ov::as_type_ptr<ov::op::util::ReductionBase>(pattern_map.at(reduce).get_node_shared_ptr());+ const auto reduce_node = ov::as_type_ptr<op_util::ReductionBase>(pattern_map.at(reduce).get_node_shared_ptr());const auto unsqueeze_node = pattern_map.at(unsqueeze).get_node_shared_ptr();- auto unsqueeze_axes_input =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(unsqueeze_axes).get_node_shared_ptr());- auto reduce_axes_input =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(reduce_axes).get_node_shared_ptr());+ auto unsqueeze_axes_input = ov::as_type_ptr<v0::Constant>(pattern_map.at(unsqueeze_axes).get_node_shared_ptr());+ auto reduce_axes_input = ov::as_type_ptr<v0::Constant>(pattern_map.at(reduce_axes).get_node_shared_ptr());if (!unsqueeze_axes_input || !reduce_axes_input || !reduce_node) {return false;@@ -153,17 +153,17 @@ ov::pass::PullUnsqueezeThroughReduce::PullUnsqueezeThroughReduce() {if (!keep_dims) {const auto unsqueeze_adjusted_axes = adjust_axes(unsqueeze_axes_val, reduce_axes_val);if (unsqueeze_adjusted_axes != unsqueeze_axes_val) {- unsqueeze_axes_input = ov::op::v0::Constant::create(unsqueeze_axes_input->get_element_type(),- unsqueeze_axes_input->get_shape(),- unsqueeze_adjusted_axes);+ unsqueeze_axes_input = v0::Constant::create(unsqueeze_axes_input->get_element_type(),+ unsqueeze_axes_input->get_shape(),+ unsqueeze_adjusted_axes);}}const auto reduce_adjusted_axes = adjust_axes(reduce_axes_val, unsqueeze_axes_val);if (reduce_adjusted_axes != reduce_axes_val) {- reduce_axes_input = ov::op::v0::Constant::create(reduce_axes_input->get_element_type(),- reduce_axes_input->get_shape(),- reduce_adjusted_axes);+ reduce_axes_input = v0::Constant::create(reduce_axes_input->get_element_type(),+ reduce_axes_input->get_shape(),+ reduce_adjusted_axes);}const auto new_reduce_node = reduce_node->clone_with_new_inputs({input_node, reduce_axes_input});@@ -181,23 +181,21 @@ ov::pass::PullUnsqueezeThroughReduce::PullUnsqueezeThroughReduce() {register_matcher(m, callback);}-ov::pass::PullReshapeThroughReduce::PullReshapeThroughReduce() {+PullReshapeThroughReduce::PullReshapeThroughReduce() {MATCHER_SCOPE(PullReshapeThroughReduce);const auto input = pattern::any_input(pattern::has_static_shape());- const auto reshape_target_shape = pattern::wrap_type<ov::op::v0::Constant>();+ const auto reshape_target_shape = pattern::wrap_type<v0::Constant>();const auto reshape =pattern::wrap_type<ov::op::v1::Reshape>({input, reshape_target_shape}, pattern::consumers_count(1));- const auto reduce_axes = pattern::wrap_type<ov::op::v0::Constant>();- const auto reduce =- pattern::wrap_type<ov::op::util::ArithmeticReductionKeepDims, ov::op::util::LogicalReductionKeepDims>(- {reshape, reduce_axes});+ const auto reduce_axes = pattern::wrap_type<v0::Constant>();+ const auto reduce = pattern::wrap_type<op_util::ArithmeticReductionKeepDims, op_util::LogicalReductionKeepDims>(+ {reshape, reduce_axes});matcher_pass_callback callback = [=](pattern::Matcher& m) {auto& pattern_map = m.get_pattern_value_map();const auto input_node = pattern_map.at(input);- const auto reduce_node =- ov::as_type_ptr<ov::op::util::ReductionBase>(pattern_map.at(reduce).get_node_shared_ptr());+ const auto reduce_node = ov::as_type_ptr<op_util::ReductionBase>(pattern_map.at(reduce).get_node_shared_ptr());if (!reduce_node) {return false;}@@ -220,17 +218,16 @@ ov::pass::PullReshapeThroughReduce::PullReshapeThroughReduce() {const auto unsqueeze_adjusted_axes = adjust_axes(unsqueeze_axes, reduce_axes_val);const auto reduce_adjusted_axes = adjust_axes(reduce_axes_val, unsqueeze_axes);- auto reduce_axes_input =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(reduce_axes).get_node_shared_ptr());+ auto reduce_axes_input = ov::as_type_ptr<v0::Constant>(pattern_map.at(reduce_axes).get_node_shared_ptr());if (!reduce_axes_input) {return false;}if (reduce_adjusted_axes != reduce_axes_val) {- reduce_axes_input = ov::op::v0::Constant::create(reduce_axes_input->get_element_type(),- reduce_axes_input->get_shape(),- reduce_adjusted_axes);+ reduce_axes_input = v0::Constant::create(reduce_axes_input->get_element_type(),+ reduce_axes_input->get_shape(),+ reduce_adjusted_axes);}const auto new_reduce_node = reduce_node->clone_with_new_inputs({input_node, reduce_axes_input});@@ -248,3 +245,5 @@ ov::pass::PullReshapeThroughReduce::PullReshapeThroughReduce() {auto m = std::make_shared<pattern::Matcher>(reduce, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/pull_transpose_through_fq.cpp b/src/common/transformations/src/transformations/common_optimizations/pull_transpose_through_fq.cppindex 8fc8d60db0b..3a0120138a8 100644--- a/src/common/transformations/src/transformations/common_optimizations/pull_transpose_through_fq.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/pull_transpose_through_fq.cpp@@ -19,18 +19,23 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::PullTransposeThroughFQUp::PullTransposeThroughFQUp() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++PullTransposeThroughFQUp::PullTransposeThroughFQUp() {MATCHER_SCOPE(PullTransposeThroughFQUp);- const auto weights = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- const auto convert_p = ov::pass::pattern::optional<ov::op::v0::Convert>(weights, pattern::consumers_count(1));- auto m_fq = pattern::wrap_type<ov::op::v0::FakeQuantize>({convert_p,- pattern::any_input(pattern::has_static_shape()),- pattern::any_input(pattern::has_static_shape()),- pattern::any_input(pattern::has_static_shape()),- pattern::any_input(pattern::has_static_shape())},- pattern::consumers_count(1));- auto m_transpose_perm = pattern::wrap_type<ov::op::v0::Constant>();- auto m_transpose = pattern::wrap_type<ov::op::v1::Transpose>({m_fq, m_transpose_perm});+ const auto weights = pattern::wrap_type<v0::Constant>();+ const auto convert_p = pattern::optional<v0::Convert>(weights, pattern::consumers_count(1));+ auto m_fq = pattern::wrap_type<v0::FakeQuantize>({convert_p,+ pattern::any_input(pattern::has_static_shape()),+ pattern::any_input(pattern::has_static_shape()),+ pattern::any_input(pattern::has_static_shape()),+ pattern::any_input(pattern::has_static_shape())},+ pattern::consumers_count(1));+ auto m_transpose_perm = pattern::wrap_type<v0::Constant>();+ auto m_transpose = pattern::wrap_type<v1::Transpose>({m_fq, m_transpose_perm});ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto& pattern_map = m.get_pattern_value_map();@@ -51,12 +56,12 @@ ov::pass::PullTransposeThroughFQUp::PullTransposeThroughFQUp() {unsqueeze_axes.push_back(j);}if (!unsqueeze_axes.empty()) {- fq_input = std::make_shared<ov::op::v0::Unsqueeze>(+ fq_input = std::make_shared<v0::Unsqueeze>(fq_input,- ov::op::v0::Constant::create(element::i64, Shape{unsqueeze_axes.size()}, unsqueeze_axes));+ v0::Constant::create(element::i64, Shape{unsqueeze_axes.size()}, unsqueeze_axes));new_ops.push_back(fq_input.get_node_shared_ptr());}- fq_input = std::make_shared<ov::op::v1::Transpose>(fq_input, transpose->input_value(1));+ fq_input = std::make_shared<v1::Transpose>(fq_input, transpose->input_value(1));if (auto constant = ov::util::get_constant_from_source(fq_input)) {fq_input = constant;}@@ -80,6 +85,8 @@ ov::pass::PullTransposeThroughFQUp::PullTransposeThroughFQUp() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(m_transpose, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(m_transpose, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/push_constant_to_subgraph.cpp b/src/common/transformations/src/transformations/common_optimizations/push_constant_to_subgraph.cppindex 728cbd42b7a..a60b463bc2a 100644--- a/src/common/transformations/src/transformations/common_optimizations/push_constant_to_subgraph.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/push_constant_to_subgraph.cpp@@ -9,12 +9,14 @@#include "openvino/op/constant.hpp"#include "openvino/op/util/multi_subgraph_base.hpp"-using MultiSubGraphOp = ov::op::util::MultiSubGraphOp;+namespace v0 = ov::op::v0;+namespace op_util = ov::op::util;+using MultiSubGraphOp = op_util::MultiSubGraphOp;-static std::shared_ptr<ov::op::v0::Constant> try_constantfold_input(+static std::shared_ptr<v0::Constant> try_constantfold_input(const std::shared_ptr<MultiSubGraphOp>& op,const MultiSubGraphOp::InputDescription::Ptr& input_desc,- std::map<ov::Output<ov::Node>, std::shared_ptr<ov::op::v0::Constant>>& cache) {+ std::map<ov::Output<ov::Node>, std::shared_ptr<v0::Constant>>& cache) {if (!ov::as_type_ptr<MultiSubGraphOp::InvariantInputDescription>(input_desc)) {return nullptr;}@@ -31,9 +33,9 @@ static std::shared_ptr<ov::op::v0::Constant> try_constantfold_input(}static void replace_body_parameter(const std::shared_ptr<ov::Model>& body,- const std::shared_ptr<ov::op::v0::Parameter>& body_param,+ const std::shared_ptr<v0::Parameter>& body_param,size_t body_parameter_index,- const std::shared_ptr<ov::op::v0::Constant>& constant,+ const std::shared_ptr<v0::Constant>& constant,MultiSubGraphOp::MultiSubgraphInputDescriptionVector& descriptions) {body_param->output(0).replace(constant);body->remove_parameter(body_param);@@ -75,13 +77,13 @@ bool ov::pass::PushConstantToSubgraph::run_on_model(const std::shared_ptr<Model>bool result = false;for (const auto& op : model->get_ordered_ops()) {- const auto multi_sub_graph_op = as_type_ptr<ov::op::util::MultiSubGraphOp>(op);+ const auto multi_sub_graph_op = as_type_ptr<op_util::MultiSubGraphOp>(op);if (!multi_sub_graph_op) {continue;}// cache for already constant folded inputs- std::map<ov::Output<ov::Node>, std::shared_ptr<ov::op::v0::Constant>> cache;+ std::map<ov::Output<ov::Node>, std::shared_ptr<v0::Constant>> cache;// bitmask describing which MultiSubGraphOp's input to removestd::vector<bool> remove_inputs_mask(multi_sub_graph_op->get_input_size(), false);int num_subgraphs = static_cast<int>(multi_sub_graph_op->get_internal_subgraphs_size());diff --git a/src/common/transformations/src/transformations/common_optimizations/random_uniform_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/random_uniform_fusion.cppindex d805beb8c5d..e4a8d9360e5 100644--- a/src/common/transformations/src/transformations/common_optimizations/random_uniform_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/random_uniform_fusion.cpp@@ -19,32 +19,37 @@#include "openvino/pass/pattern/op/or.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::RandomUniformFusion::RandomUniformFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;++namespace ov::pass {++RandomUniformFusion::RandomUniformFusion() {MATCHER_SCOPE(RandomUniformFusion);- const auto data_pattern = pass::pattern::any_input();- const auto ru_min_input_pattern = pass::pattern::any_input();- const auto ru_max_input_pattern = pass::pattern::any_input();- const auto random_uniform_pattern = ov::pass::pattern::wrap_type<ov::op::v8::RandomUniform>(- {data_pattern, ru_min_input_pattern, ru_max_input_pattern},- pattern::consumers_count(1));- const auto const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- const auto optional_convert = ov::pass::pattern::optional<ov::op::v0::Convert>(random_uniform_pattern);-- const auto mul_add_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Multiply, ov::op::v1::Add>({optional_convert, const_pattern});+ const auto data_pattern = pattern::any_input();+ const auto ru_min_input_pattern = pattern::any_input();+ const auto ru_max_input_pattern = pattern::any_input();+ const auto random_uniform_pattern =+ pattern::wrap_type<v8::RandomUniform>({data_pattern, ru_min_input_pattern, ru_max_input_pattern},+ pattern::consumers_count(1));+ const auto const_pattern = pattern::wrap_type<v0::Constant>();+ const auto optional_convert = pattern::optional<v0::Convert>(random_uniform_pattern);++ const auto mul_add_pattern = pattern::wrap_type<v1::Multiply, v1::Add>({optional_convert, const_pattern});ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto data = pattern_map.at(data_pattern);const auto random_uniform = pattern_map.at(random_uniform_pattern);const auto constant = pattern_map.at(const_pattern);- const auto ru = ov::as_type_ptr<ov::op::v8::RandomUniform>(random_uniform.get_node_shared_ptr());+ const auto ru = ov::as_type_ptr<v8::RandomUniform>(random_uniform.get_node_shared_ptr());if (!ru)return false;if (!ru->get_out_type().is_real())return false;- const auto old_const = ov::as_type_ptr<ov::op::v0::Constant>(constant.get_node_shared_ptr());+ const auto old_const = ov::as_type_ptr<v0::Constant>(constant.get_node_shared_ptr());if (!old_const)return false;if (!old_const->get_element_type().is_real())@@ -55,7 +60,7 @@ ov::pass::RandomUniformFusion::RandomUniformFusion() {return false;const auto& value = old_const->cast_vector<double>();- auto new_const = ov::op::v0::Constant::create(ru->get_out_type(), Shape{}, value);+ auto new_const = v0::Constant::create(ru->get_out_type(), Shape{}, value);const auto& mul_add = pattern_map.at(mul_add_pattern);const auto mul_add_ptr = std::dynamic_pointer_cast<ov::Node>(mul_add.get_node_shared_ptr());@@ -86,6 +91,8 @@ ov::pass::RandomUniformFusion::RandomUniformFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul_add_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(mul_add_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/reduce_merge.cpp b/src/common/transformations/src/transformations/common_optimizations/reduce_merge.cppindex 6aaa4d955f1..8feecd00941 100644--- a/src/common/transformations/src/transformations/common_optimizations/reduce_merge.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/reduce_merge.cpp@@ -25,9 +25,14 @@#include "openvino/pass/pattern/op/or.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-using namespace ov;-using namespace ov::pass;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;+namespace op_util = ov::op::util;+namespace ov::pass {++namespace {template <typename T>std::shared_ptr<Node> create_pattern() {auto input = pattern::any_input();@@ -75,21 +80,21 @@ bool fuse_reduce_operations(const std::shared_ptr<Node>& node) {const auto reduce_axes_node = reduce_axes_output.get_node_shared_ptr();const auto reduce_axes_rank = reduce_axes_output.get_partial_shape().rank();if (reduce_axes_rank == Dimension(0)) {- const auto unsqueeze_const = ov::op::v0::Constant::create(reduce_axes_node->get_element_type(), {}, {0});- const auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(reduce_axes_output, unsqueeze_const);+ const auto unsqueeze_const = v0::Constant::create(reduce_axes_node->get_element_type(), {}, {0});+ const auto unsqueeze = std::make_shared<v0::Unsqueeze>(reduce_axes_output, unsqueeze_const);reduce->inputs()[1].replace_source_output(unsqueeze);copy_runtime_info(reduce_axes_node, {unsqueeze_const, unsqueeze});}if (!dtype_match) {- const auto cast = std::make_shared<ov::op::v0::Convert>(reduce->input_value(1), ov::element::i64);+ const auto cast = std::make_shared<v0::Convert>(reduce->input_value(1), ov::element::i64);reduce->inputs()[1].replace_source_output(cast);copy_runtime_info(reduce_axes_node, cast);}}std::shared_ptr<Node> axes =- std::make_shared<ov::op::v0::Concat>(OutputVector{top_reduce->input_value(1), bottom_reduce->input_value(1)},- int64_t(0));+ std::make_shared<v0::Concat>(OutputVector{top_reduce->input_value(1), bottom_reduce->input_value(1)},+ int64_t(0));if (auto constant = ov::util::get_constant_from_source(axes)) {axes = constant;}@@ -101,40 +106,43 @@ bool fuse_reduce_operations(const std::shared_ptr<Node>& node) {ov::replace_node(bottom_reduce, new_reduce);return true;}+} // namespace-pass::ReduceMerge::ReduceMerge() {+ReduceMerge::ReduceMerge() {MATCHER_SCOPE(ReduceMerge);- auto reducel1_pattern = create_pattern<ov::op::v4::ReduceL1>();- auto reducel2_pattern = create_pattern<ov::op::v4::ReduceL2>();- auto reduce_log_and_pattern = create_pattern<ov::op::v1::ReduceLogicalAnd>();- auto reduce_log_or_pattern = create_pattern<ov::op::v1::ReduceLogicalOr>();- auto reduce_max_pattern = create_pattern<ov::op::v1::ReduceMax>();- auto reduce_mean_pattern = create_pattern<ov::op::v1::ReduceMean>();- auto reduce_min_pattern = create_pattern<ov::op::v1::ReduceMin>();- auto reduce_prod_pattern = create_pattern<ov::op::v1::ReduceProd>();- auto reduce_sum_pattern = create_pattern<ov::op::v1::ReduceSum>();-- auto pattern = std::make_shared<pattern::op::Or>(OutputVector{reducel1_pattern,- reducel2_pattern,- reduce_log_and_pattern,- reduce_log_or_pattern,- reduce_max_pattern,- reduce_mean_pattern,- reduce_min_pattern,- reduce_prod_pattern,- reduce_sum_pattern});-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto reducel1_pattern = create_pattern<v4::ReduceL1>();+ auto reducel2_pattern = create_pattern<v4::ReduceL2>();+ auto reduce_log_and_pattern = create_pattern<v1::ReduceLogicalAnd>();+ auto reduce_log_or_pattern = create_pattern<v1::ReduceLogicalOr>();+ auto reduce_max_pattern = create_pattern<v1::ReduceMax>();+ auto reduce_mean_pattern = create_pattern<v1::ReduceMean>();+ auto reduce_min_pattern = create_pattern<v1::ReduceMin>();+ auto reduce_prod_pattern = create_pattern<v1::ReduceProd>();+ auto reduce_sum_pattern = create_pattern<v1::ReduceSum>();++ auto pattern_node = std::make_shared<pattern::op::Or>(OutputVector{reducel1_pattern,+ reducel2_pattern,+ reduce_log_and_pattern,+ reduce_log_or_pattern,+ reduce_max_pattern,+ reduce_mean_pattern,+ reduce_min_pattern,+ reduce_prod_pattern,+ reduce_sum_pattern});++ matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto node = m.get_match_root();- if (ov::is_type<ov::op::util::ArithmeticReductionKeepDims>(node)) {- return fuse_reduce_operations<ov::op::util::ArithmeticReductionKeepDims>(node);- } else if (ov::is_type<ov::op::util::LogicalReductionKeepDims>(node)) {- return fuse_reduce_operations<ov::op::util::LogicalReductionKeepDims>(node);+ if (ov::is_type<op_util::ArithmeticReductionKeepDims>(node)) {+ return fuse_reduce_operations<op_util::ArithmeticReductionKeepDims>(node);+ } else if (ov::is_type<op_util::LogicalReductionKeepDims>(node)) {+ return fuse_reduce_operations<op_util::LogicalReductionKeepDims>(node);} else {return false;}};- auto m = std::make_shared<pattern::Matcher>(pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(pattern_node, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/reduce_reshape_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/reduce_reshape_fusion.cppindex c7355f50698..4ee8ab09d6d 100644--- a/src/common/transformations/src/transformations/common_optimizations/reduce_reshape_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/reduce_reshape_fusion.cpp@@ -19,22 +19,24 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ReduceReshapeFusion::ReduceReshapeFusion() {+namespace op_util = ov::op::util;++namespace ov::pass {++ReduceReshapeFusion::ReduceReshapeFusion() {MATCHER_SCOPE(ReduceReshapeFusion);const auto reduce_axes = pattern::wrap_type<ov::op::v0::Constant>();- const auto reduce =- pattern::wrap_type<ov::op::util::ArithmeticReductionKeepDims, ov::op::util::LogicalReductionKeepDims>(- {pattern::any_input(), reduce_axes},- pattern::consumers_count(1));+ const auto reduce = pattern::wrap_type<op_util::ArithmeticReductionKeepDims, op_util::LogicalReductionKeepDims>(+ {pattern::any_input(), reduce_axes},+ pattern::consumers_count(1));const auto reshape =pattern::wrap_type<ov::op::v1::Reshape>({reduce, pattern::any_input()}, pattern::has_static_shape());matcher_pass_callback callback = [=](pattern::Matcher& m) {auto& pattern_map = m.get_pattern_value_map();auto reshape_node = pattern_map.at(reshape).get_node_shared_ptr();- const auto reduce_node =- ov::as_type_ptr<ov::op::util::ReductionBase>(pattern_map.at(reduce).get_node_shared_ptr());+ const auto reduce_node = ov::as_type_ptr<op_util::ReductionBase>(pattern_map.at(reduce).get_node_shared_ptr());if (!reduce_node) {return false;}@@ -59,9 +61,9 @@ ov::pass::ReduceReshapeFusion::ReduceReshapeFusion() {return false;}- if (auto arithmetic_reduce_node = ov::as_type_ptr<ov::op::util::ArithmeticReductionKeepDims>(reduce_node)) {+ if (auto arithmetic_reduce_node = ov::as_type_ptr<op_util::ArithmeticReductionKeepDims>(reduce_node)) {arithmetic_reduce_node->set_keep_dims(true);- } else if (auto logical_reduce_node = ov::as_type_ptr<ov::op::util::LogicalReductionKeepDims>(reduce_node)) {+ } else if (auto logical_reduce_node = ov::as_type_ptr<op_util::LogicalReductionKeepDims>(reduce_node)) {logical_reduce_node->set_keep_dims(true);}reduce_node->validate_and_infer_types();@@ -75,3 +77,5 @@ ov::pass::ReduceReshapeFusion::ReduceReshapeFusion() {auto m = std::make_shared<pattern::Matcher>(reshape, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/relu_fake_quantize_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/relu_fake_quantize_fusion.cppindex 3fd5830742e..eb395c44b5c 100644--- a/src/common/transformations/src/transformations/common_optimizations/relu_fake_quantize_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/relu_fake_quantize_fusion.cpp@@ -16,23 +16,24 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ReluFakeQuantizeFusion::ReluFakeQuantizeFusion() {+namespace v0 = ov::op::v0;++namespace ov::pass {++ReluFakeQuantizeFusion::ReluFakeQuantizeFusion() {MATCHER_SCOPE(ReluFakeQuantizeFusion);- auto data_pattern = pass::pattern::any_input();- auto relu_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Relu>({data_pattern}, pattern::consumers_count(1));- auto input_low_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto fq_pattern = ov::pass::pattern::wrap_type<ov::op::v0::FakeQuantize>({relu_pattern,- input_low_pattern,- pass::pattern::any_input(),- pass::pattern::any_input(),- pass::pattern::any_input()});+ auto data_pattern = pattern::any_input();+ auto relu_pattern = pattern::wrap_type<v0::Relu>({data_pattern}, pattern::consumers_count(1));+ auto input_low_pattern = pattern::wrap_type<v0::Constant>();+ auto fq_pattern = pattern::wrap_type<v0::FakeQuantize>(+ {relu_pattern, input_low_pattern, pattern::any_input(), pattern::any_input(), pattern::any_input()});ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto pattern_map = m.get_pattern_value_map();auto data = pattern_map[data_pattern];auto relu = pattern_map[relu_pattern];auto input_low = pattern_map[input_low_pattern];- auto input_low_const = ov::as_type_ptr<ov::op::v0::Constant>(input_low.get_node_shared_ptr());+ auto input_low_const = ov::as_type_ptr<v0::Constant>(input_low.get_node_shared_ptr());if (!input_low_const)return false;auto input_low_values = input_low_const->cast_vector<float>();@@ -40,16 +41,16 @@ ov::pass::ReluFakeQuantizeFusion::ReluFakeQuantizeFusion() {return f < 0;}))return false;- auto fq = ov::as_type_ptr<ov::op::v0::FakeQuantize>(pattern_map[fq_pattern].get_node_shared_ptr());+ auto fq = ov::as_type_ptr<v0::FakeQuantize>(pattern_map[fq_pattern].get_node_shared_ptr());if (!fq)return false;- auto new_fq = register_new_node<ov::op::v0::FakeQuantize>(data,- fq->input_value(1),- fq->input_value(2),- fq->input_value(3),- fq->input_value(4),- fq->get_levels());+ auto new_fq = register_new_node<v0::FakeQuantize>(data,+ fq->input_value(1),+ fq->input_value(2),+ fq->input_value(3),+ fq->input_value(4),+ fq->get_levels());new_fq->set_friendly_name(fq->get_friendly_name());copy_runtime_info({relu.get_node_shared_ptr(), fq}, new_fq);@@ -58,6 +59,8 @@ ov::pass::ReluFakeQuantizeFusion::ReluFakeQuantizeFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(fq_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(fq_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/remove_concat_zero_dim_input.cpp b/src/common/transformations/src/transformations/common_optimizations/remove_concat_zero_dim_input.cppindex 5a0857dd47b..53a6b650bc1 100644--- a/src/common/transformations/src/transformations/common_optimizations/remove_concat_zero_dim_input.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/remove_concat_zero_dim_input.cpp@@ -15,9 +15,13 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::RemoveConcatZeroDimInput::RemoveConcatZeroDimInput() {+namespace v0 = ov::op::v0;++namespace ov::pass {++RemoveConcatZeroDimInput::RemoveConcatZeroDimInput() {MATCHER_SCOPE(RemoveConcatZeroDimInput);- auto concat_pattern = pattern::wrap_type<ov::op::v0::Concat>();+ auto concat_pattern = pattern::wrap_type<v0::Concat>();ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {auto concat = m.get_match_root();const auto& rt_info = concat->get_rt_info();@@ -51,10 +55,9 @@ ov::pass::RemoveConcatZeroDimInput::RemoveConcatZeroDimInput() {return false;if (concat->get_output_partial_shape(0).is_dynamic())return false;- const auto& empty_constant =- ov::op::v0::Constant::create(concat->get_output_element_type(0),- concat->get_output_partial_shape(0).to_shape(),- {});+ const auto& empty_constant = v0::Constant::create(concat->get_output_element_type(0),+ concat->get_output_partial_shape(0).to_shape(),+ {});copy_runtime_info(concat, empty_constant);concat->output(0).replace(empty_constant);empty_constant->set_friendly_name(concat->get_friendly_name());@@ -68,15 +71,17 @@ ov::pass::RemoveConcatZeroDimInput::RemoveConcatZeroDimInput() {this->register_matcher(m, callback);}-void ov::pass::disable_remove_concat_zerodim_input(const std::shared_ptr<Node>& node) {+void disable_remove_concat_zerodim_input(const std::shared_ptr<Node>& node) {node->get_rt_info().emplace(DisableRemoveConcatZeroDimInput::get_type_info_static(),DisableRemoveConcatZeroDimInput{});}-void ov::pass::enable_remove_concat_zerodim_input(const std::shared_ptr<Node>& node) {+void enable_remove_concat_zerodim_input(const std::shared_ptr<Node>& node) {node->get_rt_info().erase(DisableRemoveConcatZeroDimInput::get_type_info_static());}-bool ov::pass::remove_concat_zerodim_input_is_disabled(const std::shared_ptr<Node>& node) {+bool remove_concat_zerodim_input_is_disabled(const std::shared_ptr<Node>& node) {return node->get_rt_info().count(DisableRemoveConcatZeroDimInput::get_type_info_static());}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/remove_filtering_boxes_by_size.cpp b/src/common/transformations/src/transformations/common_optimizations/remove_filtering_boxes_by_size.cppindex a3d8793b7e7..06501856461 100644--- a/src/common/transformations/src/transformations/common_optimizations/remove_filtering_boxes_by_size.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/remove_filtering_boxes_by_size.cpp@@ -28,97 +28,103 @@#include "openvino/pass/manager.hpp"#include "transformations/common_optimizations/subtract_fusion.hpp"-ov::pass::FuseFilteringBoxesBySize::FuseFilteringBoxesBySize() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;++namespace ov::pass {++FuseFilteringBoxesBySize::FuseFilteringBoxesBySize() {ADD_MATCHER_FOR_THIS(SubtractFusion);ADD_MATCHER_FOR_THIS(RemoveFilteringBoxesBySize);}-ov::pass::RemoveFilteringBoxesBySize::RemoveFilteringBoxesBySize() {+RemoveFilteringBoxesBySize::RemoveFilteringBoxesBySize() {MATCHER_SCOPE(RemoveFilteringBoxesBySize);// variadic splitauto data = std::make_shared<pattern::op::Label>(element::f32, Shape{1000, 4});- auto sizes = ov::op::v0::Constant::create(element::i64, Shape{4}, std::vector<int64_t>({1, 1, 1, 1}));- auto axis = ov::op::v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));- auto split = std::make_shared<ov::op::v1::VariadicSplit>(data, axis, sizes);+ auto sizes = v0::Constant::create(element::i64, Shape{4}, std::vector<int64_t>({1, 1, 1, 1}));+ auto axis = v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));+ auto split = std::make_shared<v1::VariadicSplit>(data, axis, sizes);// sub -> add- auto sub_2_0 = std::make_shared<ov::op::v1::Subtract>(split->output(2), split->output(0));+ auto sub_2_0 = std::make_shared<v1::Subtract>(split->output(2), split->output(0));auto term_1 = std::make_shared<pattern::op::Label>(element::f32, Shape{1});- auto add_1 = std::make_shared<ov::op::v1::Add>(sub_2_0, term_1);+ auto add_1 = std::make_shared<v1::Add>(sub_2_0, term_1);- auto sub_3_1 = std::make_shared<ov::op::v1::Subtract>(split->output(3), split->output(1));+ auto sub_3_1 = std::make_shared<v1::Subtract>(split->output(3), split->output(1));auto term_2 = std::make_shared<pattern::op::Label>(element::f32, Shape{1});- auto add_2 = std::make_shared<ov::op::v1::Add>(sub_3_1, term_2);+ auto add_2 = std::make_shared<v1::Add>(sub_3_1, term_2);// concat- auto concat = std::make_shared<ov::op::v0::Concat>(+ auto concat = std::make_shared<v0::Concat>(ov::OutputVector({split->output(0), split->output(1), add_1->output(0), add_2->output(0)}),1);// second variadic split- auto sizes_1 = ov::op::v0::Constant::create(element::i64, Shape{4}, std::vector<int64_t>({1, 1, 1, 1}));- auto axis_1 = ov::op::v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));- auto split_1 = std::make_shared<ov::op::v1::VariadicSplit>(concat, axis_1, sizes_1);+ auto sizes_1 = v0::Constant::create(element::i64, Shape{4}, std::vector<int64_t>({1, 1, 1, 1}));+ auto axis_1 = v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));+ auto split_1 = std::make_shared<v1::VariadicSplit>(concat, axis_1, sizes_1);// squeeze- auto squeeze_1_axis = ov::op::v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));- auto squeeze_1 = std::make_shared<ov::op::v0::Squeeze>(split_1->output(2), squeeze_1_axis);+ auto squeeze_1_axis = v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));+ auto squeeze_1 = std::make_shared<v0::Squeeze>(split_1->output(2), squeeze_1_axis);- auto squeeze_2_axis = ov::op::v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));- auto squeeze_2 = std::make_shared<ov::op::v0::Squeeze>(split_1->output(3), squeeze_2_axis);+ auto squeeze_2_axis = v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));+ auto squeeze_2 = std::make_shared<v0::Squeeze>(split_1->output(3), squeeze_2_axis);// less- auto less_1_constant = ov::op::v0::Constant::create(element::f32, Shape{1}, std::vector<float>({0}));- auto less_1 = std::make_shared<ov::op::v1::Less>(squeeze_1, less_1_constant);+ auto less_1_constant = v0::Constant::create(element::f32, Shape{1}, std::vector<float>({0}));+ auto less_1 = std::make_shared<v1::Less>(squeeze_1, less_1_constant);- auto less_2_constant = ov::op::v0::Constant::create(element::f32, Shape{1}, std::vector<float>({0}));- auto less_2 = std::make_shared<ov::op::v1::Less>(squeeze_2, less_2_constant);+ auto less_2_constant = v0::Constant::create(element::f32, Shape{1}, std::vector<float>({0}));+ auto less_2 = std::make_shared<v1::Less>(squeeze_2, less_2_constant);// Logical Not- auto not_1 = std::make_shared<ov::op::v1::LogicalNot>(less_1);- auto not_2 = std::make_shared<ov::op::v1::LogicalNot>(less_2);+ auto not_1 = std::make_shared<v1::LogicalNot>(less_1);+ auto not_2 = std::make_shared<v1::LogicalNot>(less_2);// cast- auto cast_11 = std::make_shared<ov::op::v0::Convert>(not_1, ov::element::u8);- auto cast_12 = std::make_shared<ov::op::v0::Convert>(cast_11, ov::element::boolean);+ auto cast_11 = std::make_shared<v0::Convert>(not_1, ov::element::u8);+ auto cast_12 = std::make_shared<v0::Convert>(cast_11, ov::element::boolean);- auto cast_21 = std::make_shared<ov::op::v0::Convert>(not_2, ov::element::u8);- auto cast_22 = std::make_shared<ov::op::v0::Convert>(cast_21, ov::element::boolean);+ auto cast_21 = std::make_shared<v0::Convert>(not_2, ov::element::u8);+ auto cast_22 = std::make_shared<v0::Convert>(cast_21, ov::element::boolean);// logical and- auto and_1 = std::make_shared<ov::op::v1::LogicalAnd>(cast_12, cast_22);+ auto and_1 = std::make_shared<v1::LogicalAnd>(cast_12, cast_22);// cast- auto cast_31 = std::make_shared<ov::op::v0::Convert>(and_1, ov::element::u8);- auto cast_32 = std::make_shared<ov::op::v0::Convert>(cast_31, ov::element::f32);+ auto cast_31 = std::make_shared<v0::Convert>(and_1, ov::element::u8);+ auto cast_32 = std::make_shared<v0::Convert>(cast_31, ov::element::f32);// nonzero- auto non_zero = std::make_shared<ov::op::v3::NonZero>(cast_32);+ auto non_zero = std::make_shared<v3::NonZero>(cast_32);- auto order = ov::op::v0::Constant::create(element::i64, Shape{2}, std::vector<int64_t>({1, 0}));- auto transpose = std::make_shared<ov::op::v1::Transpose>(non_zero, order);+ auto order = v0::Constant::create(element::i64, Shape{2}, std::vector<int64_t>({1, 0}));+ auto transpose = std::make_shared<v1::Transpose>(non_zero, order);- auto squeeze_3_axis = ov::op::v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));- auto squeeze_3 = std::make_shared<ov::op::v0::Squeeze>(transpose, squeeze_3_axis);+ auto squeeze_3_axis = v0::Constant::create(element::i64, Shape{1}, std::vector<int64_t>({1}));+ auto squeeze_3 = std::make_shared<v0::Squeeze>(transpose, squeeze_3_axis);- auto cast = std::make_shared<ov::op::v0::Convert>(squeeze_3, ov::element::i64);+ auto cast = std::make_shared<v0::Convert>(squeeze_3, ov::element::i64);- ov::matcher_pass_callback callback = [data](pattern::Matcher& m) {- auto start = ov::op::v0::Constant::create(element::i64, Shape{}, std::vector<int64_t>({0}));- auto step = ov::op::v0::Constant::create(element::i64, Shape{}, std::vector<int64_t>({1}));+ matcher_pass_callback callback = [data](pattern::Matcher& m) {+ auto start = v0::Constant::create(element::i64, Shape{}, std::vector<int64_t>({0}));+ auto step = v0::Constant::create(element::i64, Shape{}, std::vector<int64_t>({1}));const auto& pattern_map = m.get_pattern_map();auto input = pattern_map.at(data);auto output = m.get_match_root();- auto input_shape = std::make_shared<ov::op::v3::ShapeOf>(input);+ auto input_shape = std::make_shared<v3::ShapeOf>(input);- auto axis = ov::op::v0::Constant::create(element::i64, Shape{}, std::vector<int64_t>({0}));- auto index = ov::op::v0::Constant::create(element::i64, Shape{}, std::vector<int64_t>({0}));- auto stop = std::make_shared<ov::op::v1::Gather>(input_shape, index, axis);+ auto axis = v0::Constant::create(element::i64, Shape{}, std::vector<int64_t>({0}));+ auto index = v0::Constant::create(element::i64, Shape{}, std::vector<int64_t>({0}));+ auto stop = std::make_shared<v1::Gather>(input_shape, index, axis);- auto range = std::make_shared<ov::op::v0::Range>(start, stop, step);+ auto range = std::make_shared<v0::Range>(start, stop, step);range->set_friendly_name(output->get_friendly_name());// TODO: add copy_runtime_info@@ -130,3 +136,5 @@ ov::pass::RemoveFilteringBoxesBySize::RemoveFilteringBoxesBySize() {auto m = std::make_shared<pattern::Matcher>(cast, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp b/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cppindex bb62c971702..3a933e49ee3 100644--- a/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp@@ -16,6 +16,10 @@using namespace ov::op::util;+namespace v0 = ov::op::v0;+namespace v5 = ov::op::v5;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;namespace {/** @brief Value to mark that input idx has been removed (at least one removed so last idx will be always available) */constexpr auto mark_removed = std::numeric_limits<uint64_t>::max();@@ -44,9 +48,9 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const stauto multi_subgraph_op = ov::as_type_ptr<MultiSubGraphOp>(*it);if (!multi_subgraph_op)continue;- auto if_op = ov::as_type_ptr<ov::op::v8::If>(multi_subgraph_op);- auto loop_op = ov::as_type_ptr<ov::op::v5::Loop>(multi_subgraph_op);- auto ti_op = ov::as_type_ptr<ov::op::v0::TensorIterator>(multi_subgraph_op);+ auto if_op = ov::as_type_ptr<v8::If>(multi_subgraph_op);+ auto loop_op = ov::as_type_ptr<v5::Loop>(multi_subgraph_op);+ auto ti_op = ov::as_type_ptr<v0::TensorIterator>(multi_subgraph_op);// Only If, Loop and TensorIterator are supportedif (!if_op && !loop_op && !ti_op)continue;@@ -158,13 +162,13 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const st}if (pass_required) {is_changed = true;- using DescType = ov::op::util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector;+ using DescType = op_util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector;auto update_body_param_desc = [](DescType& descriptors, uint64_t removed_body_idx) {for (auto& desc : descriptors) {desc->m_body_parameter_index = get_updated_idx(desc->m_body_parameter_index, removed_body_idx);}};- auto update_op_inputs_desc = [&subgraphs_size](const std::shared_ptr<ov::op::util::MultiSubGraphOp>& op,+ auto update_op_inputs_desc = [&subgraphs_size](const std::shared_ptr<op_util::MultiSubGraphOp>& op,uint64_t removed_loop_idx) {for (size_t body_idx = 0; body_idx < subgraphs_size; ++body_idx) {auto& descriptors = op->get_input_descriptions(static_cast<int>(body_idx));@@ -186,7 +190,7 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const stauto op_inputs = multi_subgraph_op->input_values();for (size_t body_idx = 0; body_idx < subgraphs_size; ++body_idx) {auto& body_in_descriptors = multi_subgraph_op->get_input_descriptions(static_cast<int>(body_idx));- ov::op::util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector updated_body_in_descriptors;+ op_util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector updated_body_in_descriptors;for (size_t desc_idx = 0; desc_idx < body_in_descriptors.size(); ++desc_idx) {auto& current_body_desc = body_in_descriptors[desc_idx];@@ -223,13 +227,13 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const st// existing opstd::shared_ptr<MultiSubGraphOp> new_op;if (if_op) {- new_op = std::make_shared<ov::op::v8::If>();+ new_op = std::make_shared<v8::If>();} else if (loop_op) {- auto new_loop_op = std::make_shared<ov::op::v5::Loop>();+ auto new_loop_op = std::make_shared<v5::Loop>();new_loop_op->set_special_body_ports(loop_op->get_special_body_ports());new_op = new_loop_op;} else if (ti_op) {- new_op = std::make_shared<ov::op::v0::TensorIterator>();+ new_op = std::make_shared<v0::TensorIterator>();}new_op->set_arguments(multi_subgraph_op->input_values());new_op->set_friendly_name(multi_subgraph_op->get_friendly_name());diff --git a/src/common/transformations/src/transformations/common_optimizations/reshape_prelu.cpp b/src/common/transformations/src/transformations/common_optimizations/reshape_prelu.cppindex 7041e5719f1..e537d58c0e7 100644--- a/src/common/transformations/src/transformations/common_optimizations/reshape_prelu.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/reshape_prelu.cpp@@ -13,13 +13,15 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::pass;+namespace v0 = ov::op::v0;++namespace ov::pass {ReshapePRelu::ReshapePRelu() {MATCHER_SCOPE(ReshapePRelu);auto input_m = pattern::any_input(pattern::has_static_rank());auto slope_m = pattern::any_input(pattern::has_static_rank());- auto prelu_m = pattern::wrap_type<ov::op::v0::PRelu>({input_m, slope_m});+ auto prelu_m = pattern::wrap_type<v0::PRelu>({input_m, slope_m});matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -46,8 +48,7 @@ ReshapePRelu::ReshapePRelu() {std::vector<std::int64_t> target_shape(prelu_rank.get_length(), 1);target_shape[channel_dim_idx] = -1;- const auto target_shape_const =- ov::op::v0::Constant::create(ov::element::i64, {target_shape.size()}, target_shape);+ const auto target_shape_const = v0::Constant::create(ov::element::i64, {target_shape.size()}, target_shape);auto new_slope = ov::op::util::make_try_fold<ov::op::v1::Reshape>(slope, target_shape_const, true);auto new_prelu = prelu->clone_with_new_inputs({input, new_slope});@@ -59,6 +60,8 @@ ReshapePRelu::ReshapePRelu() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(prelu_m, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(prelu_m, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/reshape_sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/reshape_sequence_fusion.cppindex 8fd748a5c83..f5083f0a74a 100644--- a/src/common/transformations/src/transformations/common_optimizations/reshape_sequence_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/reshape_sequence_fusion.cpp@@ -17,9 +17,14 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+namespace {bool has_valid_pattern(const ov::Output<ov::Node>& node_out) {- const auto const_node = ov::as_type_ptr<ov::op::v0::Constant>(node_out.get_node_shared_ptr());+ const auto const_node = ov::as_type_ptr<v0::Constant>(node_out.get_node_shared_ptr());constexpr auto has_special_value = ov::cmp::Less<int64_t>(1);if (!const_node) {// evaluate bounds@@ -29,7 +34,7 @@ bool has_valid_pattern(const ov::Output<ov::Node>& node_out) {if (!lb || !ub) {return false;}- const auto lb_const_node = std::make_shared<ov::op::v0::Constant>(lb);+ const auto lb_const_node = std::make_shared<v0::Constant>(lb);const auto& lb_values = lb_const_node->cast_vector<int64_t>();// The pattern is valid if all lower bound values are higher than zero (not a special number)@@ -38,7 +43,7 @@ bool has_valid_pattern(const ov::Output<ov::Node>& node_out) {if (!lb_has_special_val)return true;- const auto ub_const_node = std::make_shared<ov::op::v0::Constant>(ub);+ const auto ub_const_node = std::make_shared<v0::Constant>(ub);const auto& ub_values = ub_const_node->cast_vector<int64_t>();if (lb_values.size() != ub_values.size())return false;@@ -60,14 +65,13 @@ bool has_valid_pattern(const ov::Output<ov::Node>& node_out) {}} // namespace-ov::pass::ReshapeSequenceFusion::ReshapeSequenceFusion(bool use_shape_for_elimination) {+ReshapeSequenceFusion::ReshapeSequenceFusion(bool use_shape_for_elimination) {MATCHER_SCOPE(ReshapeSequenceFusion);auto reshape_input = pattern::any_input();- auto reshape_a_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto reshape_a =- pattern::wrap_type<ov::op::v1::Reshape>({reshape_input, reshape_a_pattern}, pattern::consumers_count(1));+ auto reshape_a_pattern = pattern::wrap_type<v0::Constant>();+ auto reshape_a = pattern::wrap_type<v1::Reshape>({reshape_input, reshape_a_pattern}, pattern::consumers_count(1));auto reshape_b_pattern = pattern::any_input();- auto reshape_b = pattern::wrap_type<ov::op::v1::Reshape>({reshape_a, reshape_b_pattern});+ auto reshape_b = pattern::wrap_type<v1::Reshape>({reshape_a, reshape_b_pattern});matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -83,7 +87,7 @@ ov::pass::ReshapeSequenceFusion::ReshapeSequenceFusion(bool use_shape_for_elimin// vector of nodes which runtime info must be copiedNodeVector nodes{pattern_map.at(reshape_a).get_node_shared_ptr(), reshape};- while (ov::as_type_ptr<ov::op::v1::Reshape>(input.get_node_shared_ptr())) {+ while (ov::as_type_ptr<v1::Reshape>(input.get_node_shared_ptr())) {auto node = input.get_node_shared_ptr();if (!has_valid_pattern(node->get_input_node_shared_ptr(1)) || input.get_target_inputs().size() != 1) {break;@@ -109,6 +113,8 @@ ov::pass::ReshapeSequenceFusion::ReshapeSequenceFusion(bool use_shape_for_eliminreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reshape_b, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(reshape_b, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp b/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cppindex 6f4b1b15884..6854ae6cde5 100644--- a/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/reverse_shape_and_type_infer.cpp@@ -23,6 +23,10 @@#include "openvino/op/util/unary_elementwise_arithmetic.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;namespace {void set_source_output_type_shape(const ov::Node& node,@@ -93,11 +97,11 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::auto ops = f->get_ordered_ops();for (auto it = ops.rbegin(); it != ops.rend(); ++it) {const auto& op = *it;- is_changed = ov::op::util::process_subgraph(*this, op) || is_changed;+ is_changed = op_util::process_subgraph(*this, op) || is_changed;auto output_shape = op->get_output_partial_shape(0);auto output_type = op->get_output_element_type(0);- if (const auto& param = ov::as_type_ptr<ov::op::v0::Parameter>(op)) {+ if (const auto& param = ov::as_type_ptr<v0::Parameter>(op)) {if (param->get_partial_shape().compatible(output_shape)) {auto shape = param->get_partial_shape();if (PartialShape::merge_into(shape, output_shape)) {@@ -109,7 +113,7 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::param->set_element_type(output_type);is_changed = true;}- } else if (ov::as_type_ptr<ov::op::v1::Convolution>(op)) {+ } else if (ov::as_type_ptr<v1::Convolution>(op)) {is_changed |= inherit_output_rank(op, {0, 1});// Inherit channels from weightsconst auto& weigths_pshape = op->get_input_partial_shape(1);@@ -120,7 +124,7 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::set_source_output_shape(*op, new_shape, 0);}is_changed |= inherit_output_type(op, {0, 1});- } else if (ov::as_type_ptr<ov::op::v1::GroupConvolution>(op)) {+ } else if (ov::as_type_ptr<v1::GroupConvolution>(op)) {is_changed |= inherit_output_rank(op, {0, 1});// Inherit channels from weightsconst auto& weigths_pshape = op->get_input_partial_shape(1);@@ -131,7 +135,7 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::set_source_output_shape(*op, new_shape, 0);}is_changed |= inherit_output_type(op, {0, 1});- } else if (ov::as_type_ptr<ov::op::v1::ConvolutionBackpropData>(op)) {+ } else if (ov::as_type_ptr<v1::ConvolutionBackpropData>(op)) {is_changed |= inherit_output_rank(op, {0, 1});// Inherit channels from weightsconst auto& weigths_pshape = op->get_input_partial_shape(1);@@ -142,7 +146,7 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::set_source_output_shape(*op, new_shape, 0);}is_changed |= inherit_output_type(op, {0, 1});- } else if (ov::as_type_ptr<ov::op::v1::GroupConvolutionBackpropData>(op)) {+ } else if (ov::as_type_ptr<v1::GroupConvolutionBackpropData>(op)) {is_changed |= inherit_output_rank(op, {0, 1});// Inherit channels from weightsconst auto& weigths_pshape = op->get_input_partial_shape(1);@@ -153,10 +157,10 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::set_source_output_shape(*op, new_shape, 0);}is_changed |= inherit_output_type(op, {0, 1});- } else if (ov::as_type_ptr<ov::op::v8::DeformableConvolution>(op)) {+ } else if (ov::as_type_ptr<v8::DeformableConvolution>(op)) {is_changed |= inherit_output_rank(op, {0, 1, 2, 3});is_changed |= inherit_output_type(op, {0, 1, 2, 3});- } else if (ov::as_type_ptr<ov::op::util::PadBase>(op)) {+ } else if (ov::as_type_ptr<op_util::PadBase>(op)) {// Shape of pads_begin and pads_end must match rank of inputif (op->get_input_partial_shape(0).rank().is_dynamic()) {auto pads_begin_shape = op->get_input_partial_shape(1);@@ -170,10 +174,10 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::}}is_changed |= inherit_output_type(op, {0});- } else if (ov::as_type_ptr<ov::op::util::UnaryElementwiseArithmetic>(op)) {+ } else if (ov::as_type_ptr<op_util::UnaryElementwiseArithmetic>(op)) {is_changed |= inherit_output_shape(op, {0});is_changed |= inherit_output_type(op, {0});- } else if (const auto& eltwise = ov::as_type_ptr<ov::op::util::BinaryElementwiseArithmetic>(op)) {+ } else if (const auto& eltwise = ov::as_type_ptr<op_util::BinaryElementwiseArithmetic>(op)) {if (output_shape.rank().is_static()) {auto in0_rank = op->get_input_partial_shape(0).rank();auto in1_rank = op->get_input_partial_shape(1).rank();@@ -192,7 +196,7 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::}}is_changed |= inherit_output_type(op, {0, 1});- } else if (const auto& concat = ov::as_type_ptr<ov::op::v0::Concat>(op)) {+ } else if (const auto& concat = ov::as_type_ptr<v0::Concat>(op)) {std::vector<size_t> input_idxs(op->get_input_size());std::iota(input_idxs.begin(), input_idxs.end(), 0);@@ -214,10 +218,10 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::}}is_changed |= inherit_output_type(op, input_idxs);- } else if (ov::as_type_ptr<ov::op::v8::Slice>(op)) {+ } else if (ov::as_type_ptr<v8::Slice>(op)) {is_changed |= inherit_output_rank(op, {0});is_changed |= inherit_output_type(op, {0});- } else if (ov::as_type_ptr<ov::op::v0::Squeeze>(op)) {+ } else if (ov::as_type_ptr<v0::Squeeze>(op)) {auto in0_pshape = op->get_input_partial_shape(0);auto in0_rank = in0_pshape.rank();if (output_shape.rank().is_static()) {@@ -239,15 +243,15 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::}int64_t num_ones = in1_data.size();if (num_ones == in0_rank.get_length() - output_shape.rank().get_length()) {- auto axes = ov::op::v0::Constant::create(element::i64, Shape{in1_data.size()}, in1_data);- auto new_squeeze = std::make_shared<ov::op::v0::Squeeze>(op->get_input_source_output(0), axes);+ auto axes = v0::Constant::create(element::i64, Shape{in1_data.size()}, in1_data);+ auto new_squeeze = std::make_shared<v0::Squeeze>(op->get_input_source_output(0), axes);op->output(0).replace(new_squeeze->output(0));copy_runtime_info(op, new_squeeze);}}}is_changed |= inherit_output_type(op, {0});- } else if (ov::as_type_ptr<ov::op::v0::Unsqueeze>(op)) {+ } else if (ov::as_type_ptr<v0::Unsqueeze>(op)) {auto in0_rank = op->get_input_partial_shape(0).rank();auto in1_pshape = op->get_input_partial_shape(1);if (output_shape.rank().is_static() && in0_rank.is_dynamic() && in1_pshape.is_static()) {@@ -255,14 +259,14 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::set_source_output_shape(*op, PartialShape::dynamic(output_shape.rank().get_length() - num_dims), 0);}is_changed |= inherit_output_type(op, {0});- } else if (const auto& if_op = ov::as_type_ptr<ov::op::v8::If>(op)) {+ } else if (const auto& if_op = ov::as_type_ptr<v8::If>(op)) {auto then_body = if_op->get_then_body();auto else_body = if_op->get_else_body();// First set types and shapes to Result nodesconst auto& then_body_results = then_body->get_results();const auto& else_body_results = else_body->get_results();- const auto& then_out_desc = if_op->get_output_descriptions(ov::op::v8::If::THEN_BODY_INDEX);- const auto& else_out_desc = if_op->get_output_descriptions(ov::op::v8::If::ELSE_BODY_INDEX);+ const auto& then_out_desc = if_op->get_output_descriptions(v8::If::THEN_BODY_INDEX);+ const auto& else_out_desc = if_op->get_output_descriptions(v8::If::ELSE_BODY_INDEX);for (const auto& out_desc : then_out_desc) {const auto& out_indx = out_desc->m_output_index;@@ -286,8 +290,8 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::is_changed |= run_on_model(else_body);auto then_body_params = then_body->get_parameters();auto else_body_params = else_body->get_parameters();- const auto& then_in_desc = if_op->get_input_descriptions(ov::op::v8::If::THEN_BODY_INDEX);- const auto& else_in_desc = if_op->get_input_descriptions(ov::op::v8::If::ELSE_BODY_INDEX);+ const auto& then_in_desc = if_op->get_input_descriptions(v8::If::THEN_BODY_INDEX);+ const auto& else_in_desc = if_op->get_input_descriptions(v8::If::ELSE_BODY_INDEX);for (const auto& in_desc : then_in_desc) {const auto& in_indx = in_desc->m_input_index;const auto& body_indx = in_desc->m_body_parameter_index;@@ -326,10 +330,10 @@ bool ov::pass::ReverseShapeAndTypeInfer::run_on_model(const std::shared_ptr<ov::set_source_output_shape(*if_op, PartialShape{}, 0);is_changed = true;}- } else if (ov::as_type_ptr<ov::op::v1::ConvertLike>(op)) {+ } else if (ov::as_type_ptr<v1::ConvertLike>(op)) {is_changed |= inherit_output_shape(op, {0});is_changed |= inherit_output_type(op, {1});- } else if (ov::as_type_ptr<ov::op::v1::Transpose>(op)) {+ } else if (ov::as_type_ptr<v1::Transpose>(op)) {auto transpose_order = ov::util::get_constant_from_source(op->input_value(1));if (output_shape.rank().is_static()) {if (transpose_order) {diff --git a/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cppindex 6d8624433ee..8ed57be58e3 100644--- a/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/ric_fusion.cpp@@ -31,13 +31,16 @@#include "openvino/util/log.hpp"#include "transformations/utils/utils.hpp"-namespace ov {-namespace pass {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;+namespace ov::pass {namespace ric_attr {namespace {-std::shared_ptr<ov::op::v0::Constant> create_1d_const(const std::vector<int64_t>& values) {- return ov::op::v0::Constant::create(ov::element::i64, ov::Shape{values.size()}, values);+std::shared_ptr<v0::Constant> create_1d_const(const std::vector<int64_t>& values) {+ return v0::Constant::create(ov::element::i64, ov::Shape{values.size()}, values);}} // namespace@@ -101,8 +104,7 @@ public:order.resize(axis_dim.get_length());std::iota(order.rbegin(), order.rend(), 0);}- auto gather =- std::make_shared<ov::op::v8::Gather>(output, create_1d_const(order), create_1d_const({get_axis()}));+ auto gather = std::make_shared<v8::Gather>(output, create_1d_const(order), create_1d_const({get_axis()}));input.replace_source_output(gather);ov::copy_runtime_info(nodes, gather);}@@ -227,13 +229,13 @@ public:OPENVINO_MATCHER_PASS_RTTI("pass::init::SplitConcat");SplitConcat(NodeVector& nodes_to_fuse) {MATCHER_SCOPE(SplitConcat);- auto split_p = pattern::wrap_type<ov::op::v1::Split>();- auto pattern_root = pattern::wrap_type<ov::op::v0::Concat>({split_p, split_p, split_p});+ auto split_p = pattern::wrap_type<v1::Split>();+ auto pattern_root = pattern::wrap_type<v0::Concat>({split_p, split_p, split_p});auto callback = [=, &nodes_to_fuse](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();- auto concat = ov::as_type_ptr<ov::op::v0::Concat>(pattern_map.at(pattern_root).get_node_shared_ptr());- auto split = ov::as_type_ptr<ov::op::v1::Split>(pattern_map.at(split_p).get_node_shared_ptr());+ auto concat = ov::as_type_ptr<v0::Concat>(pattern_map.at(pattern_root).get_node_shared_ptr());+ auto split = ov::as_type_ptr<v1::Split>(pattern_map.at(split_p).get_node_shared_ptr());if (!concat || !split)return false;@@ -286,8 +288,8 @@ public:MATCHER_SCOPE(Gather);auto input_p = pattern::any_input(pattern::has_static_rank());auto indices_p = pattern::any_input();- auto axis_p = pattern::wrap_type<ov::op::v0::Constant>();- auto pattern_root = pattern::wrap_type<ov::op::v8::Gather>({input_p, indices_p, axis_p});+ auto axis_p = pattern::wrap_type<v0::Constant>();+ auto pattern_root = pattern::wrap_type<v8::Gather>({input_p, indices_p, axis_p});auto callback = [=, &nodes_to_fuse](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -346,7 +348,7 @@ public:OPENVINO_MATCHER_PASS_RTTI("pass::prop::Binary");Binary() {MATCHER_SCOPE(Binary);- auto pattern_root = pattern::wrap_type<ov::op::util::BinaryElementwiseArithmetic, ov::op::v0::FakeQuantize>();+ auto pattern_root = pattern::wrap_type<op_util::BinaryElementwiseArithmetic, v0::FakeQuantize>();auto callback = [=](pattern::Matcher& m) {const auto& root = m.get_match_root();@@ -357,7 +359,7 @@ public:auto output = input.get_source_output();if (ric_attr::has(output)) {attrs.insert({input.get_index(), ric_attr::get(output).propagate()});- } else if (!ov::is_type<ov::op::v0::Constant>(output.get_node())) {+ } else if (!ov::is_type<v0::Constant>(output.get_node())) {// If number of non-constant inputs and without RIC attr is greater than 0 we have to skip// propagation because it is not efficient to have a lot of RIC copies on data path.return false;@@ -433,7 +435,7 @@ public:Convolution() {MATCHER_SCOPE(Convolution);auto input_p = pattern::any_input(ric_attr::has<Output<Node>>);- auto pattern_root = pattern::wrap_type<ov::op::v1::Convolution>(+ auto pattern_root = pattern::wrap_type<v1::Convolution>({input_p, pattern::any_input(pattern::has_static_dim(1 /*output channel*/))});auto callback = [=](pattern::Matcher& m) {auto conv = m.get_match_root();@@ -456,8 +458,8 @@ public:GroupConvolution() {MATCHER_SCOPE(GroupConvolution);auto input_p = pattern::any_input(ric_attr::has<Output<Node>>);- auto pattern_root = pattern::wrap_type<ov::op::v1::GroupConvolution>(- {input_p, pattern::any_input(pattern::has_static_shape())});+ auto pattern_root =+ pattern::wrap_type<v1::GroupConvolution>({input_p, pattern::any_input(pattern::has_static_shape())});auto callback = [=](pattern::Matcher& m) {auto conv = m.get_match_root();@@ -512,7 +514,7 @@ public:OPENVINO_MATCHER_PASS_RTTI("pass::prop::ShapeOf");ShapeOf() {MATCHER_SCOPE(ShapeOf);- auto pattern_root = pattern::wrap_type<ov::op::v0::ShapeOf, ov::op::v3::ShapeOf>();+ auto pattern_root = pattern::wrap_type<v0::ShapeOf, ov::op::v3::ShapeOf>();auto callback = [=](pattern::Matcher& m) {// Skip propagation for ShapeOf path@@ -529,10 +531,8 @@ public:OPENVINO_MATCHER_PASS_RTTI("pass::prop::PassThrough");PassThrough() {MATCHER_SCOPE(PassThrough);- auto pattern_root = pattern::wrap_type<ov::op::util::UnaryElementwiseArithmetic,- ov::op::v0::Convert,- ov::op::util::PadBase,- ov::op::v0::PRelu>();+ auto pattern_root =+ pattern::wrap_type<op_util::UnaryElementwiseArithmetic, v0::Convert, op_util::PadBase, v0::PRelu>();auto callback = [=](pattern::Matcher& m) {auto root = m.get_match_root();@@ -553,15 +553,15 @@ public:Transpose() {MATCHER_SCOPE(Transpose);auto input_p = pattern::any_input(ric_attr::has<Output<Node>>);- auto order_p = pattern::wrap_type<ov::op::v0::Constant>();- auto pattern_root = pattern::wrap_type<ov::op::v1::Transpose>({input_p, order_p});+ auto order_p = pattern::wrap_type<v0::Constant>();+ auto pattern_root = pattern::wrap_type<v1::Transpose>({input_p, order_p});auto callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto input = pattern_map.at(input_p);auto ric = ric_attr::get(input).propagate();- auto order_node = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(order_p).get_node_shared_ptr());+ auto order_node = ov::as_type_ptr<v0::Constant>(pattern_map.at(order_p).get_node_shared_ptr());auto order = order_node->cast_vector<int64_t>();int64_t new_axis = std::find(order.begin(), order.end(), ric.get_axis()) - order.begin();@@ -642,8 +642,8 @@ public:EraseSplitConcat() {MATCHER_SCOPE(EraseSplitConcat);auto input_p = pattern::any_input();- auto split_p = pattern::wrap_type<ov::op::v1::Split>({input_p, pattern::any_input()});- auto pattern_root = pattern::wrap_type<ov::op::v0::Concat>({split_p, split_p, split_p}, need_to_erase_ric);+ auto split_p = pattern::wrap_type<v1::Split>({input_p, pattern::any_input()});+ auto pattern_root = pattern::wrap_type<v0::Concat>({split_p, split_p, split_p}, need_to_erase_ric);auto callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -665,8 +665,7 @@ public:MATCHER_SCOPE(EraseGather);auto input_p = pattern::any_input();auto pattern_root =- pattern::wrap_type<ov::op::v8::Gather>({input_p, pattern::any_input(), pattern::any_input()},- need_to_erase_ric);+ pattern::wrap_type<v8::Gather>({input_p, pattern::any_input(), pattern::any_input()}, need_to_erase_ric);auto callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto output = pattern_map.at(pattern_root);@@ -688,13 +687,13 @@ public:Binary() {MATCHER_SCOPE(Binary);auto fake_quantize_pattern =- pattern::wrap_type<ov::op::v0::FakeQuantize>({pattern::any_input(pattern::has_static_rank()),- pattern::any_input(pattern::has_static_rank()),- pattern::any_input(pattern::has_static_rank()),- pattern::any_input(pattern::has_static_rank()),- pattern::any_input(pattern::has_static_rank())},- pattern::has_static_rank());- auto binary_elementwise_pattern = pattern::wrap_type<ov::op::util::BinaryElementwiseArithmetic>(+ pattern::wrap_type<v0::FakeQuantize>({pattern::any_input(pattern::has_static_rank()),+ pattern::any_input(pattern::has_static_rank()),+ pattern::any_input(pattern::has_static_rank()),+ pattern::any_input(pattern::has_static_rank()),+ pattern::any_input(pattern::has_static_rank())},+ pattern::has_static_rank());+ auto binary_elementwise_pattern = pattern::wrap_type<op_util::BinaryElementwiseArithmetic>({pattern::any_input(pattern::has_static_rank()), pattern::any_input(pattern::has_static_rank())},pattern::has_static_rank());@@ -771,7 +770,7 @@ public:OPENVINO_MATCHER_PASS_RTTI("pass::back_prop::ConvertPassThrough");ConvertPassThrough() {MATCHER_SCOPE(ConvertPassThrough);- auto pattern_root = pattern::wrap_type<ov::op::v0::Convert>(pattern::has_static_rank());+ auto pattern_root = pattern::wrap_type<v0::Convert>(pattern::has_static_rank());auto callback = [=](pattern::Matcher& m) {auto root = m.get_match_root();const auto& output = root->output(0);@@ -823,8 +822,8 @@ public:bool run_on_model(const std::shared_ptr<ov::Model>& model) override {RUN_ON_FUNCTION_SCOPE(Constant);for (const auto& node : model->get_ordered_ops()) {- if ((ov::as_type_ptr<ov::op::util::BinaryElementwiseArithmetic>(node) ||- ov::as_type_ptr<ov::op::v0::FakeQuantize>(node) || ov::as_type_ptr<ov::op::v0::Convert>(node)) &&+ if ((ov::as_type_ptr<op_util::BinaryElementwiseArithmetic>(node) ||+ ov::as_type_ptr<v0::FakeQuantize>(node) || ov::as_type_ptr<v0::Convert>(node)) &&node->get_output_partial_shape(0).rank().is_static()) {continue;}@@ -832,7 +831,7 @@ public:for (const auto& consumer : output.get_target_inputs()) {if (ric_attr::has(consumer)) {auto ric = ric_attr::get(consumer);- if (ov::as_type_ptr<ov::op::v0::Constant>(node)) {+ if (ov::as_type_ptr<v0::Constant>(node)) {ric.set_is_final(true);ric_attr::set(consumer, ric);} else { // Unsupported@@ -904,5 +903,4 @@ bool ov::pass::ReverseInputChannelsFusion::run_on_model(const std::shared_ptr<ovm.run_passes(model);return false;}-} // namespace pass-} // namespace ov+} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/rms_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/rms_fusion.cppindex 8460af0dfea..d14e0cf72a8 100644--- a/src/common/transformations/src/transformations/common_optimizations/rms_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/rms_fusion.cpp@@ -20,83 +20,86 @@#include "ov_ops/rms.hpp"#include "transformations/utils/utils.hpp"-namespace ov {-namespace pass {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;-static std::function<bool(ov::Output<ov::Node>)> constant_value(const float target_value) {+namespace ov::pass {++namespace {+std::function<bool(ov::Output<ov::Node>)> constant_value(const float target_value) {return [=](const ov::Output<ov::Node>& output) -> bool {- auto node = ov::as_type_ptr<ov::op::v0::Constant>(output.get_node_shared_ptr());+ auto node = ov::as_type_ptr<v0::Constant>(output.get_node_shared_ptr());if (!node) {return false;}float value;- if (!ov::op::util::get_single_value(node, value)) {+ if (!op_util::get_single_value(node, value)) {return false;}return value == target_value;};}+} // namespaceRMSFusion::RMSFusion(bool force_tail_convert, bool enable_div_x) {- using namespace ov::pass::pattern;-// Detect RMS decomposition pattern// x * 1/Sqrt(ReduceMean(x^2,axes)+eps) * gamma- auto x = any_input();+ auto x = pattern::any_input();// x^2- auto const_power = wrap_type<ov::op::v0::Constant>(constant_value(2));- auto const_power_convert = pattern::optional<ov::op::v0::Convert>(const_power);- auto power = wrap_type<ov::op::v1::Power>({x, const_power_convert});+ auto const_power = pattern::wrap_type<v0::Constant>(constant_value(2));+ auto const_power_convert = pattern::optional<v0::Convert>(const_power);+ auto power = pattern::wrap_type<v1::Power>({x, const_power_convert});// ReduceMean(x^2,axes)- auto mean_axes = wrap_type<ov::op::v0::Constant>(constant_value(-1));- auto mean = wrap_type<ov::op::v1::ReduceMean>({power, mean_axes});+ auto mean_axes = pattern::wrap_type<v0::Constant>(constant_value(-1));+ auto mean = pattern::wrap_type<v1::ReduceMean>({power, mean_axes});// ReduceMean(x^2,axes)+eps- auto eps = wrap_type<ov::op::v0::Constant>();- auto eps_convert = pattern::optional<ov::op::v0::Convert>(eps);- auto add_eps = wrap_type<ov::op::v1::Add>({mean, eps_convert});+ auto eps = pattern::wrap_type<v0::Constant>();+ auto eps_convert = pattern::optional<v0::Convert>(eps);+ auto add_eps = pattern::wrap_type<v1::Add>({mean, eps_convert});// Sqrt(ReduceMean(x^2,axes)+eps)- auto sqrt = wrap_type<ov::op::v0::Sqrt>({add_eps});+ auto sqrt = pattern::wrap_type<v0::Sqrt>({add_eps});// 1/Sqrt(ReduceMean(x^2,axes)+eps)- auto const_pow = wrap_type<ov::op::v0::Constant>(constant_value(-1));- auto const_pow_convert = pattern::optional<ov::op::v0::Convert>(const_pow);- auto pow = wrap_type<ov::op::v1::Power>({sqrt, const_pow_convert});+ auto const_pow = pattern::wrap_type<v0::Constant>(constant_value(-1));+ auto const_pow_convert = pattern::optional<v0::Convert>(const_pow);+ auto pow = pattern::wrap_type<v1::Power>({sqrt, const_pow_convert});- auto const_div = wrap_type<ov::op::v0::Constant>(constant_value(1));- auto const_div_convert = pattern::optional<ov::op::v0::Convert>(const_div);- auto div = wrap_type<ov::op::v1::Divide>({const_div_convert, sqrt});+ auto const_div = pattern::wrap_type<v0::Constant>(constant_value(1));+ auto const_div_convert = pattern::optional<v0::Convert>(const_div);+ auto div = pattern::wrap_type<v1::Divide>({const_div_convert, sqrt});auto div_or_pow = std::make_shared<pattern::op::Or>(OutputVector{div, pow});// x * 1/Sqrt(ReduceMean(x^2,axes)+eps)- auto mul1 = wrap_type<ov::op::v1::Multiply>({x, div_or_pow});+ auto mul1 = pattern::wrap_type<v1::Multiply>({x, div_or_pow});std::shared_ptr<pattern::op::Or> mul_or_div;// TODO: Check div_x pattern failed in CPU CI Pytorch layer test.if (enable_div_x) {// x / Sqrt(ReduceMean(x^2,axes)+eps)- auto div_x = wrap_type<ov::op::v1::Divide>({x, sqrt});+ auto div_x = pattern::wrap_type<v1::Divide>({x, sqrt});mul_or_div = std::make_shared<pattern::op::Or>(OutputVector{mul1, div_x});} else {mul_or_div = std::make_shared<pattern::op::Or>(OutputVector{mul1});}// x * 1/Sqrt(ReduceMean(x^2,axes)+eps) * gamma- auto gamma = wrap_type<ov::op::v0::Constant>();- auto gamma_convert = pattern::optional<ov::op::v0::Convert>(gamma);+ auto gamma = pattern::wrap_type<v0::Constant>();+ auto gamma_convert = pattern::optional<v0::Convert>(gamma);- auto mul2 = wrap_type<ov::op::v1::Multiply>({gamma_convert, mul_or_div});+ auto mul2 = pattern::wrap_type<v1::Multiply>({gamma_convert, mul_or_div});std::shared_ptr<ov::Node> comp = mul2;if (force_tail_convert) {// compress RMS result- comp = wrap_type<ov::op::v0::Convert>({mul2});+ comp = pattern::wrap_type<v0::Convert>({mul2});}- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto node = m.get_match_root();if (transformation_callback(node)) {@@ -105,9 +108,9 @@ RMSFusion::RMSFusion(bool force_tail_convert, bool enable_div_x) {const auto& x_output = pattern_map.at(x);- auto const_eps_node = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(eps).get_node_shared_ptr());+ auto const_eps_node = ov::as_type_ptr<v0::Constant>(pattern_map.at(eps).get_node_shared_ptr());float eps_value;- if (!ov::op::util::get_single_value(const_eps_node, eps_value)) {+ if (!op_util::get_single_value(const_eps_node, eps_value)) {return false;}@@ -118,7 +121,7 @@ RMSFusion::RMSFusion(bool force_tail_convert, bool enable_div_x) {const auto& mean_node = pattern_map.at(mean).get_node_shared_ptr();const auto& axes = pattern_map.at(mean_axes).get_node_shared_ptr();- auto axes_constant = ov::as_type_ptr<ov::op::v0::Constant>(axes);+ auto axes_constant = ov::as_type_ptr<v0::Constant>(axes);auto axes_val = axes_constant->cast_vector<int64_t>();// allow last dimension onlyif ((axes_val[0] != -1) &&@@ -135,9 +138,8 @@ RMSFusion::RMSFusion(bool force_tail_convert, bool enable_div_x) {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(comp, "RMSFusion");+ auto m = std::make_shared<pattern::Matcher>(comp, "RMSFusion");this->register_matcher(m, callback);}-} // namespace pass-} // namespace ov+} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cppindex 1d16f3e7ba6..031741fa2f1 100644--- a/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/sdpa_fusion.cpp@@ -33,8 +33,18 @@#include "transformations/symbolic_transformations/symbolic_optimizations.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::op;-+using ov::pass::pattern::any_input;+using ov::pass::pattern::consumers_count;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::rank_equals;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v8 = ov::op::v8;+namespace v13 = ov::op::v13;+namespace op_util = ov::op::util;namespace {std::vector<size_t> get_order(const ov::pass::pattern::PatternSymbolValue& any_layout_sym,@@ -89,8 +99,7 @@ ov::pass::pattern::op::Predicate check_layout(const std::string& layout) {};} // namespace-namespace ov {-namespace pass {+namespace ov::pass {bool SDPAFusion::run_on_model(const std::shared_ptr<ov::Model>& model) {RUN_ON_MODEL_SCOPE(SDPAFusion);@@ -104,14 +113,10 @@ bool SDPAFusion::run_on_model(const std::shared_ptr<ov::Model>& model) {SDPAReshapeFusion::SDPAReshapeFusion() {MATCHER_SCOPE(SDPAReshapeFusion);-- using namespace ov::op;- using namespace ov::pass::pattern;-- auto q = any_input(shape_matches("Batches..., S_q, D"));- auto k = any_input(shape_matches("AnyLayout...") && rank_more_than(2));- auto v = any_input(shape_matches("Batches..., S_kv, D") && check_layout("AnyLayout"));- auto mask = any_input(has_static_rank());+ auto q = any_input(ov::pass::pattern::shape_matches("Batches..., S_q, D"));+ auto k = any_input(ov::pass::pattern::shape_matches("AnyLayout...") && ov::pass::pattern::rank_more_than(2));+ auto v = any_input(ov::pass::pattern::shape_matches("Batches..., S_kv, D") && check_layout("AnyLayout"));+ auto mask = any_input(ov::pass::pattern::has_static_rank());// these Reshape/Unsqueeze may already exist in the graphauto unsq_q = wrap_type<v1::Reshape, v0::Unsqueeze>({q, any_input()});@@ -119,15 +124,16 @@ SDPAReshapeFusion::SDPAReshapeFusion() {auto unsq_v = wrap_type<v1::Reshape, v0::Unsqueeze>({v, any_input()});// this Transpose may already exist in the graph- auto opt_original_transpose_k = optional<v1::Transpose>({unsq_k, any_input()});+ auto opt_original_transpose_k = ov::pass::pattern::optional<v1::Transpose>({unsq_k, any_input()});// these Reshape/Unsqueeze may be inserted by SDPAFusionMatcher- auto opt_unsq_q = optional<v1::Reshape, v0::Unsqueeze>({unsq_q, any_input()});- auto opt_unsq_k = optional<v1::Reshape, v0::Unsqueeze>({opt_original_transpose_k, any_input()});- auto opt_unsq_v = optional<v1::Reshape, v0::Unsqueeze>({unsq_v, any_input()});+ auto opt_unsq_q = ov::pass::pattern::optional<v1::Reshape, v0::Unsqueeze>({unsq_q, any_input()});+ auto opt_unsq_k = ov::pass::pattern::optional<v1::Reshape, v0::Unsqueeze>({opt_original_transpose_k, any_input()});+ auto opt_unsq_v = ov::pass::pattern::optional<v1::Reshape, v0::Unsqueeze>({unsq_v, any_input()});// this Transpose may be inserted by SDPAFusionMatcher- auto opt_transpose_k = optional<v1::Transpose>({opt_unsq_k, any_input()}, shape_matches("..., S_kv, D"));+ auto opt_transpose_k = ov::pass::pattern::optional<v1::Transpose>({opt_unsq_k, any_input()},+ ov::pass::pattern::shape_matches("..., S_kv, D"));auto sdpa_pattern = wrap_type<v13::ScaledDotProductAttention>({opt_unsq_q,@@ -137,11 +143,11 @@ SDPAReshapeFusion::SDPAReshapeFusion() {any_input(),});- auto opt_sdpa_reshape = optional<v1::Reshape, v0::Unsqueeze>({sdpa_pattern, any_input()});- auto post_sdpa =- wrap_type<v1::Reshape, v0::Unsqueeze>({opt_sdpa_reshape, any_input()}, shape_matches("Batches..., S_q, D"));+ auto opt_sdpa_reshape = ov::pass::pattern::optional<v1::Reshape, v0::Unsqueeze>({sdpa_pattern, any_input()});+ auto post_sdpa = wrap_type<v1::Reshape, v0::Unsqueeze>({opt_sdpa_reshape, any_input()},+ ov::pass::pattern::shape_matches("Batches..., S_q, D"));- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pm = m.get_pattern_value_map();const auto& q_node = pm.at(q);@@ -150,7 +156,7 @@ SDPAReshapeFusion::SDPAReshapeFusion() {const auto& mask_node = pm.at(mask);auto post_sdpa_node = pm.at(post_sdpa).get_node_shared_ptr();- auto sdpa = ov::as_type_ptr<ov::op::v13::ScaledDotProductAttention>(pm.at(sdpa_pattern).get_node_shared_ptr());+ auto sdpa = ov::as_type_ptr<v13::ScaledDotProductAttention>(pm.at(sdpa_pattern).get_node_shared_ptr());if (!sdpa) {return false;}@@ -185,14 +191,14 @@ SDPAReshapeFusion::SDPAReshapeFusion() {} else {if (!is_ascending_order) {auto transpose_order = v0::Constant::create(ov::element::i64, {order.size()}, order);- k_node = std::make_shared<ov::op::v1::Transpose>(k_node, transpose_order);+ k_node = std::make_shared<v1::Transpose>(k_node, transpose_order);ov::copy_runtime_info(m.get_matched_nodes(), {transpose_order, k_node.get_node_shared_ptr()});}}} else {if (!is_ascending_order) {- auto shape_of_v = ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(v_node);- k_node = std::make_shared<ov::op::v1::Reshape>(k_node, shape_of_v, false);+ auto shape_of_v = op_util::make_try_fold<v3::ShapeOf>(v_node);+ k_node = std::make_shared<v1::Reshape>(k_node, shape_of_v, false);ov::copy_runtime_info(m.get_matched_nodes(), {shape_of_v, k_node.get_node_shared_ptr()});}}@@ -213,7 +219,7 @@ SDPAReshapeFusion::SDPAReshapeFusion() {static std::shared_ptr<ov::Node> get_scale(std::shared_ptr<ov::Node> scale_pattern,element::Type default_scale_type,- ov::pass::pattern::Matcher& matcher) {+ Matcher& matcher) {auto& pm = matcher.get_pattern_value_map();if (pm.count(scale_pattern)) {auto scale_node = pm.at(scale_pattern);@@ -229,9 +235,9 @@ static std::shared_ptr<ov::Node> get_scale(std::shared_ptr<ov::Node> scale_pattereturn nullptr;} else {if (rank.get_length() > 1) {- scale_node = ov::op::util::make_try_fold<v1::Reshape>(scale_node,- v0::Constant::create(ov::element::i64, {1}, {1}),- false);+ scale_node = op_util::make_try_fold<v1::Reshape>(scale_node,+ v0::Constant::create(ov::element::i64, {1}, {1}),+ false);}return scale_node.get_node_shared_ptr();}@@ -244,7 +250,7 @@ static std::shared_ptr<ov::Node> get_mask(std::shared_ptr<ov::Node> mask_patternstd::shared_ptr<ov::Node> opt_mask_add,element::Type default_mask_type,bool mask_present,- ov::pass::pattern::Matcher& matcher) {+ Matcher& matcher) {auto& pm = matcher.get_pattern_value_map();if (mask_present && pm.count(opt_mask_add)) {const auto& qk_out = pm.at(opt_mask_add);@@ -261,7 +267,7 @@ static std::shared_ptr<ov::Node> get_mask(std::shared_ptr<ov::Node> mask_pattern// mask should be broadcastable to qk shape// Create temporary copy for broadcast_merge_into as it modifies the first argumentauto qk_out_ps_temp = qk_out_ps;- if (!ov::PartialShape::broadcast_merge_into(qk_out_ps_temp, mask_input_ps, AutoBroadcastType::NUMPY))+ if (!ov::PartialShape::broadcast_merge_into(qk_out_ps_temp, mask_input_ps, ov::op::AutoBroadcastType::NUMPY))return nullptr;if (mask_input_ps.size() < 2) {@@ -302,7 +308,7 @@ static ov::OutputVector get_qkv(ov::OutputVector qkv,Output<ov::Node> mask_node,element::Type default_mask_type,bool matmul_transposes_k,- ov::pass::pattern::Matcher& matcher) {+ Matcher& matcher) {// 3 is the min supported rank according to the SDPA specint64_t supported_rank = std::max(mask_node.get_partial_shape().rank().get_length(), static_cast<int64_t>(3));for (size_t i = 0; i < qkv.size(); ++i) {@@ -341,10 +347,6 @@ static ov::OutputVector get_qkv(ov::OutputVector qkv,SDPAFusionMatcher::SDPAFusionMatcher() {MATCHER_SCOPE(SDPAFusionMatcher);-- using namespace ov::op;- using namespace ov::pass::pattern;-/** Corner Case: Dynamic Mask and Attention Scores* When the mask and the attention scores (after MatMul) have [..., -1, -1] shapes,@@ -368,17 +370,23 @@ SDPAFusionMatcher::SDPAFusionMatcher() {return true;};- auto q = any_input(shape_matches("..., H, S_q, E") || shape_matches("S_q, E"));- auto k = any_input(shape_matches("..., H, S_kv, E") || shape_matches("S_kv, E"));- auto kT = any_input(shape_matches("..., H, E, S_kv") || shape_matches("E, S_kv"));- auto v = any_input(shape_matches("..., H, S_kv, Ev") || shape_matches("S_kv, Ev"));+ auto q =+ any_input(ov::pass::pattern::shape_matches("..., H, S_q, E") || ov::pass::pattern::shape_matches("S_q, E"));+ auto k =+ any_input(ov::pass::pattern::shape_matches("..., H, S_kv, E") || ov::pass::pattern::shape_matches("S_kv, E"));+ auto kT =+ any_input(ov::pass::pattern::shape_matches("..., H, E, S_kv") || ov::pass::pattern::shape_matches("E, S_kv"));+ auto v =+ any_input(ov::pass::pattern::shape_matches("..., H, S_kv, Ev") || ov::pass::pattern::shape_matches("S_kv, Ev"));auto attn_scale = any_input();- auto opt_k_scale = optional<v1::Multiply>({k, attn_scale});- auto opt_kT_scale = optional<v1::Multiply>({kT, attn_scale});+ auto opt_k_scale = ov::pass::pattern::optional<v1::Multiply>({k, attn_scale});+ auto opt_kT_scale = ov::pass::pattern::optional<v1::Multiply>({kT, attn_scale});- auto qk_pred = (shape_matches("..., H, S_q, S_kv") || shape_matches("S_q, S_kv")) && consumers_count(1);+ auto qk_pred =+ (ov::pass::pattern::shape_matches("..., H, S_q, S_kv") || ov::pass::pattern::shape_matches("S_q, S_kv")) &&+ consumers_count(1);auto qk = wrap_type<v0::MatMul>({q, opt_kT_scale}, qk_pred, {{"transpose_a", false}, {"transpose_b", false}});auto qk_transpose_b =wrap_type<v0::MatMul>({q, opt_k_scale}, qk_pred, {{"transpose_a", false}, {"transpose_b", true}});@@ -386,7 +394,7 @@ SDPAFusionMatcher::SDPAFusionMatcher() {// Optional unsqueeze that is converted to Reshapeauto unsqueeze_axis = wrap_type<v0::Constant>();- auto qk_opt_unsqueeze = optional<v1::Reshape>({qk_alternatives, unsqueeze_axis});+ auto qk_opt_unsqueeze = ov::pass::pattern::optional<v1::Reshape>({qk_alternatives, unsqueeze_axis});auto qk_scaled = wrap_type<v1::Multiply>({qk_opt_unsqueeze, attn_scale});auto qk_opt_scaled = qk_scaled | qk_opt_unsqueeze;@@ -396,18 +404,20 @@ SDPAFusionMatcher::SDPAFusionMatcher() {// 2. Reshape before adding mask// 3. Mask add// 4. Reshape after adding mask- auto mask = any_input(has_static_rank());- auto qk_opt_scaled_pre_mask_opt_reshaped = optional<v1::Reshape>({qk_opt_scaled, any_input()});+ auto mask = any_input(ov::pass::pattern::has_static_rank());+ auto qk_opt_scaled_pre_mask_opt_reshaped = ov::pass::pattern::optional<v1::Reshape>({qk_opt_scaled, any_input()});auto add_pred = consumers_count(1) && corner_case_check;- auto qk_opt_scaled_opt_mask_added = optional<v1::Add>({qk_opt_scaled_pre_mask_opt_reshaped, mask}, add_pred);- auto qk_post_mask_opt_reshaped = optional<v1::Reshape>({qk_opt_scaled_opt_mask_added, any_input()});+ auto qk_opt_scaled_opt_mask_added =+ ov::pass::pattern::optional<v1::Add>({qk_opt_scaled_pre_mask_opt_reshaped, mask}, add_pred);+ auto qk_post_mask_opt_reshaped =+ ov::pass::pattern::optional<v1::Reshape>({qk_opt_scaled_opt_mask_added, any_input()});// Softmax axis can be:// Pattern 1: axis = -1 (last axis)// Pattern 2: axis = rank size - 1 (also means last axis for static rank inputs)auto axis_predicate = ([](const ov::Output<ov::Node>& node) {- auto softmax = std::dynamic_pointer_cast<ov::op::v8::Softmax>(node.get_node_shared_ptr());+ auto softmax = std::dynamic_pointer_cast<v8::Softmax>(node.get_node_shared_ptr());if (!softmax)return false;auto input_rank = node.get_partial_shape().rank();@@ -417,15 +427,16 @@ SDPAFusionMatcher::SDPAFusionMatcher() {return static_cast<size_t>(input_rank.get_length() - 1) == axis;});auto softmax_pred =- consumers_count(1) && axis_predicate && (shape_matches("..., H, S_q, S_kv") || shape_matches("S_q, S_kv"));+ consumers_count(1) && axis_predicate &&+ (ov::pass::pattern::shape_matches("..., H, S_q, S_kv") || ov::pass::pattern::shape_matches("S_q, S_kv"));auto softmax = wrap_type<v8::Softmax>({qk_post_mask_opt_reshaped}, softmax_pred);- auto softmax_opt_reshaped = optional<v1::Reshape>({softmax, any_input()});+ auto softmax_opt_reshaped = ov::pass::pattern::optional<v1::Reshape>({softmax, any_input()});- auto qkv_shape = shape_matches("..., H, S_q, Ev") || shape_matches("S_q, Ev");+ auto qkv_shape = ov::pass::pattern::shape_matches("..., H, S_q, Ev") || ov::pass::pattern::shape_matches("S_q, Ev");auto qkv =wrap_type<v0::MatMul>({softmax_opt_reshaped, v}, qkv_shape, {{"transpose_a", false}, {"transpose_b", false}});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pm = m.get_pattern_value_map();if (transformation_callback(m.get_match_root())) {return false;@@ -472,10 +483,6 @@ SDPAFusionMatcher::SDPAFusionMatcher() {SDPAFusionMatcherSinks::SDPAFusionMatcherSinks() {MATCHER_SCOPE(SDPAFusionMatcherSinks);-- using namespace ov::op;- using namespace ov::pass::pattern;-auto v = any_input(rank_equals(4));auto k = any_input(rank_equals(4));auto q = any_input(rank_equals(4));@@ -484,11 +491,11 @@ SDPAFusionMatcherSinks::SDPAFusionMatcherSinks() {wrap_type<v0::MatMul>({q, k}, consumers_count(1), {{"transpose_a", false}, {"transpose_b", true}});auto attn_scale = any_input();- auto opt_qk_scaled = optional<v1::Multiply>({qk_transpose_b, attn_scale});+ auto opt_qk_scaled = ov::pass::pattern::optional<v1::Multiply>({qk_transpose_b, attn_scale});- auto mask = any_input(has_static_rank());+ auto mask = any_input(ov::pass::pattern::has_static_rank());auto add_pred = consumers_count(1);- auto opt_mask_add = optional<v1::Add>({opt_qk_scaled, mask}, add_pred);+ auto opt_mask_add = ov::pass::pattern::optional<v1::Add>({opt_qk_scaled, mask}, add_pred);auto sinks = any_input();auto sinks_broadcast = wrap_type<v3::Broadcast>({sinks, any_input()});@@ -500,7 +507,7 @@ SDPAFusionMatcherSinks::SDPAFusionMatcherSinks() {// Pattern 1: axis = -1 (last axis)// Pattern 2: axis = rank size - 1 (also means last axis for static rank inputs)auto axis_predicate = ([](const ov::Output<ov::Node>& node) {- auto softmax = ov::as_type_ptr<ov::op::v8::Softmax>(node.get_node_shared_ptr());+ auto softmax = ov::as_type_ptr<v8::Softmax>(node.get_node_shared_ptr());if (!softmax)return false;auto input_rank = node.get_partial_shape().rank();@@ -516,7 +523,7 @@ SDPAFusionMatcherSinks::SDPAFusionMatcherSinks() {wrap_type<v8::Slice>({softmax, any_input(), any_input(), any_input(), any_input()});auto qkv = wrap_type<v0::MatMul>({sinks_slice, v});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pm = m.get_pattern_value_map();if (transformation_callback(m.get_match_root()))return false;@@ -569,5 +576,4 @@ SDPAFusionMatcherSinks::SDPAFusionMatcherSinks() {this->register_matcher(m, callback);}-} // namespace pass-} // namespace ov+} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/sdpa_scale_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/sdpa_scale_fusion.cppindex 1b1c53df644..ead1342a385 100644--- a/src/common/transformations/src/transformations/common_optimizations/sdpa_scale_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/sdpa_scale_fusion.cpp@@ -20,8 +20,11 @@#include "openvino/util/pp.hpp"#include "transformations/symbolic_transformations/symbolic_optimizations.hpp"-namespace ov {-namespace pass {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v13 = ov::op::v13;++namespace ov::pass {bool SDPAScaleFusion::run_on_model(const std::shared_ptr<ov::Model>& model) {RUN_ON_MODEL_SCOPE(SDPAScaleFusion);@@ -35,26 +38,24 @@ bool SDPAScaleFusion::run_on_model(const std::shared_ptr<ov::Model>& model) {}SDPAScaleFusionPass::SDPAScaleFusionPass() {- using namespace ov::pass::pattern;-- auto q = any_input(rank_equals(4));- auto k = any_input(rank_equals(4));- auto v = any_input(rank_equals(4));- auto mask = any_input();- auto sdpa_scale = wrap_const();- auto scale_q = any_input(shape_matches("[]") || shape_matches("[1]"));- auto scale_k = any_input(shape_matches("[]") || shape_matches("[1]"));-- auto scaled_q = optional<ov::op::v1::Multiply>({q, scale_q});- auto scaled_k = optional<ov::op::v1::Multiply>({k, scale_k});- auto sdpa_mask_scale = wrap_type<ov::op::v13::ScaledDotProductAttention>({scaled_q, scaled_k, v, mask, sdpa_scale},- {{"causal", false}});+ auto q = pattern::any_input(pattern::rank_equals(4));+ auto k = pattern::any_input(pattern::rank_equals(4));+ auto v = pattern::any_input(pattern::rank_equals(4));+ auto mask = pattern::any_input();+ auto sdpa_scale = pattern::wrap_const();+ auto scale_q = pattern::any_input(pattern::shape_matches("[]") || pattern::shape_matches("[1]"));+ auto scale_k = pattern::any_input(pattern::shape_matches("[]") || pattern::shape_matches("[1]"));++ auto scaled_q = pattern::optional<v1::Multiply>({q, scale_q});+ auto scaled_k = pattern::optional<v1::Multiply>({k, scale_k});+ auto sdpa_mask_scale = pattern::wrap_type<v13::ScaledDotProductAttention>({scaled_q, scaled_k, v, mask, sdpa_scale},+ {{"causal", false}});auto sdpa_mask =- wrap_type<ov::op::v13::ScaledDotProductAttention>({scaled_q, scaled_k, v, mask}, {{"causal", false}});- auto sdpa_simple = wrap_type<ov::op::v13::ScaledDotProductAttention>({scaled_q, scaled_k, v}, {{"causal", false}});+ pattern::wrap_type<v13::ScaledDotProductAttention>({scaled_q, scaled_k, v, mask}, {{"causal", false}});+ auto sdpa_simple = pattern::wrap_type<v13::ScaledDotProductAttention>({scaled_q, scaled_k, v}, {{"causal", false}});auto sdpa = sdpa_simple | sdpa_mask | sdpa_mask_scale;- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();if (transformation_callback(m.get_match_root())) {return false;@@ -81,8 +82,7 @@ SDPAScaleFusionPass::SDPAScaleFusionPass() {std::shared_ptr<ov::Node> scale_k_node = nullptr;if (pattern_map.find(sdpa_scale) != pattern_map.end()) {- auto prev_scale_node =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(sdpa_scale).get_node_shared_ptr());+ auto prev_scale_node = ov::as_type_ptr<v0::Constant>(pattern_map.at(sdpa_scale).get_node_shared_ptr());prev_scale_value = prev_scale_node->cast_vector<float>()[0];scale_et = prev_scale_node->get_output_element_type(0);} else {@@ -97,8 +97,8 @@ SDPAScaleFusionPass::SDPAScaleFusionPass() {if (has_q_scale) {scale_q_node = pattern_map.at(scale_q).get_node_shared_ptr();if (pattern_map.at(q).get_element_type() == q_input.get_element_type()) {- if (ov::is_type<ov::op::v0::Constant>(scale_q_node)) {- scale_q_value = ov::as_type_ptr<ov::op::v0::Constant>(scale_q_node)->cast_vector<float>()[0];+ if (ov::is_type<v0::Constant>(scale_q_node)) {+ scale_q_value = ov::as_type_ptr<v0::Constant>(scale_q_node)->cast_vector<float>()[0];q_input = pattern_map.at(q);}} else {@@ -108,8 +108,8 @@ SDPAScaleFusionPass::SDPAScaleFusionPass() {if (has_k_scale) {scale_k_node = pattern_map.at(scale_k).get_node_shared_ptr();if (pattern_map.at(k).get_element_type() == k_input.get_element_type()) {- if (ov::is_type<ov::op::v0::Constant>(scale_k_node)) {- scale_k_value = ov::as_type_ptr<ov::op::v0::Constant>(scale_k_node)->cast_vector<float>()[0];+ if (ov::is_type<v0::Constant>(scale_k_node)) {+ scale_k_value = ov::as_type_ptr<v0::Constant>(scale_k_node)->cast_vector<float>()[0];k_input = pattern_map.at(k);}} else {@@ -124,17 +124,17 @@ SDPAScaleFusionPass::SDPAScaleFusionPass() {auto new_scale_val = prev_scale_value * scale_q_value * scale_k_value;// If new scale is 1 and we have non-constant scale node for either Q or K, then we can make it a scale of SDPAif (new_scale_val == 1.0f) {- if (has_q_scale && !ov::is_type<ov::op::v0::Constant>(scale_q_node)) {+ if (has_q_scale && !ov::is_type<v0::Constant>(scale_q_node)) {new_scale_node = pattern_map.at(scale_q);q_input = pattern_map.at(q);- } else if (has_k_scale && !ov::is_type<ov::op::v0::Constant>(scale_k_node)) {+ } else if (has_k_scale && !ov::is_type<v0::Constant>(scale_k_node)) {new_scale_node = pattern_map.at(scale_k);k_input = pattern_map.at(k);} else {- new_scale_node = ov::op::v0::Constant::create(scale_et, ov::Shape{}, std::vector<float>{new_scale_val});+ new_scale_node = v0::Constant::create(scale_et, ov::Shape{}, std::vector<float>{new_scale_val});}} else {- new_scale_node = ov::op::v0::Constant::create(scale_et, ov::Shape{}, std::vector<float>{new_scale_val});+ new_scale_node = v0::Constant::create(scale_et, ov::Shape{}, std::vector<float>{new_scale_val});}OutputVector new_inputs = {q_input, k_input, pattern_map.at(v)};@@ -142,7 +142,7 @@ SDPAScaleFusionPass::SDPAScaleFusionPass() {new_inputs.push_back(pattern_map.at(mask));} else {new_inputs.push_back(- ov::op::v0::Constant::create(new_scale_node.get_element_type(), ov::Shape{}, std::vector<float>{0.0f}));+ v0::Constant::create(new_scale_node.get_element_type(), ov::Shape{}, std::vector<float>{0.0f}));}new_inputs.push_back(new_scale_node);@@ -155,9 +155,8 @@ SDPAScaleFusionPass::SDPAScaleFusionPass() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(sdpa, "SDPAScaleFusionPass");+ auto m = std::make_shared<pattern::Matcher>(sdpa, "SDPAScaleFusionPass");this->register_matcher(m, callback);}-} // namespace pass-} // namespace ov+} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/select_with_one_value_condition.cpp b/src/common/transformations/src/transformations/common_optimizations/select_with_one_value_condition.cppindex 7773ba74575..9e9183ea8a9 100644--- a/src/common/transformations/src/transformations/common_optimizations/select_with_one_value_condition.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/select_with_one_value_condition.cpp@@ -18,28 +18,32 @@using namespace std;using namespace ov;using namespace ov::element;-using namespace ov::op::util;-ov::pass::SelectWithOneValueCondition::SelectWithOneValueCondition() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++SelectWithOneValueCondition::SelectWithOneValueCondition() {MATCHER_SCOPE(SelectWithOneValueCondition);- auto condition = pattern::wrap_type<ov::op::v0::Constant>();+ auto condition = pattern::wrap_type<v0::Constant>();auto then_branch = pattern::any_input();auto else_branch = pattern::any_input();- auto select_pattern = make_shared<ov::op::v1::Select>(condition, then_branch, else_branch);+ auto select_pattern = make_shared<v1::Select>(condition, then_branch, else_branch);matcher_pass_callback callback = [=](pattern::Matcher& m) {- NodeRegistry copy_from;- NodeRegistry copy_to;+ pass::NodeRegistry copy_from;+ pass::NodeRegistry copy_to;auto& pattern_map = m.get_pattern_value_map();auto& select_value = pattern_map.at(select_pattern);- auto select = ov::as_type_ptr<ov::op::v1::Select>(select_value.get_node_shared_ptr());+ auto select = ov::as_type_ptr<v1::Select>(select_value.get_node_shared_ptr());if (!select) {return false;}auto condition_value = pattern_map.at(condition);- auto condition_const = ov::as_type_ptr<ov::op::v0::Constant>(condition_value.get_node_shared_ptr());+ auto condition_const = ov::as_type_ptr<v0::Constant>(condition_value.get_node_shared_ptr());if (!condition_const) {return false;}@@ -74,15 +78,14 @@ ov::pass::SelectWithOneValueCondition::SelectWithOneValueCondition() {return replace_output_update_name(select->output(0), branch_output);} else if (select_shape.is_static()) {// if the shape of the selected branch is not the same, it needs the broadcasting- NodeRegistry copy_to;+ pass::NodeRegistry copy_to;auto select_rank = select_shape.size();vector<int32_t> select_shape_values(select_rank);for (size_t i = 0; i < select_rank; ++i) {select_shape_values[i] = static_cast<int32_t>(select_shape[i].get_length());}- auto target_shape =- copy_to.make<ov::op::v0::Constant>(element::i32, Shape{select_rank}, select_shape_values);+ auto target_shape = copy_to.make<v0::Constant>(element::i32, Shape{select_rank}, select_shape_values);auto broadcast = copy_to.make<ov::op::v3::Broadcast>(branch_output, target_shape);select->output(0).replace(broadcast->output(0));broadcast->set_friendly_name(select->get_friendly_name());@@ -97,3 +100,5 @@ ov::pass::SelectWithOneValueCondition::SelectWithOneValueCondition() {auto m = make_shared<pattern::Matcher>(select_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cppindex db663e6443f..c7bd72a9c4d 100644--- a/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/sequence_fusion.cpp@@ -29,12 +29,18 @@using namespace std;using namespace ov::element;-using namespace ov::op::util;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v5 = ov::op::v5;+namespace op_util = ov::op::util;namespace {bool is_equal_consts(const shared_ptr<ov::Node>& l, const shared_ptr<ov::Node>& r) {- auto l_const = ov::as_type_ptr<ov::op::v0::Constant>(l);- auto r_const = ov::as_type_ptr<ov::op::v0::Constant>(r);+ auto l_const = ov::as_type_ptr<v0::Constant>(l);+ auto r_const = ov::as_type_ptr<v0::Constant>(r);if (l_const && r_const) {auto l_ptr = l_const->get_data_ptr();auto r_ptr = r_const->get_data_ptr();@@ -45,21 +51,21 @@ bool is_equal_consts(const shared_ptr<ov::Node>& l, const shared_ptr<ov::Node>&return false;}-bool check_WRB(const shared_ptr<RNNCellBase>& cell_1, const shared_ptr<RNNCellBase>& cell_2) {+bool check_WRB(const shared_ptr<op_util::RNNCellBase>& cell_1, const shared_ptr<op_util::RNNCellBase>& cell_2) {int64_t idx_W = 2, idx_R = 3, idx_B = 4;auto increase_indexes = [&]() {++idx_B;++idx_R;++idx_W;};- auto lstm_cell_v4_1 = ov::as_type_ptr<ov::op::v4::LSTMCell>(cell_1);- auto lstm_cell_v4_2 = ov::as_type_ptr<ov::op::v4::LSTMCell>(cell_2);+ auto lstm_cell_v4_1 = ov::as_type_ptr<v4::LSTMCell>(cell_1);+ auto lstm_cell_v4_2 = ov::as_type_ptr<v4::LSTMCell>(cell_2);// 2nd input is Cell Stateif (lstm_cell_v4_1 && lstm_cell_v4_2) {increase_indexes();}- auto lstm_cell_v0_1 = ov::as_type_ptr<ov::op::v0::LSTMCell>(cell_1);- auto lstm_cell_v0_2 = ov::as_type_ptr<ov::op::v0::LSTMCell>(cell_2);+ auto lstm_cell_v0_1 = ov::as_type_ptr<v0::LSTMCell>(cell_1);+ auto lstm_cell_v0_2 = ov::as_type_ptr<v0::LSTMCell>(cell_2);if (lstm_cell_v0_1 && lstm_cell_v0_2) {if (lstm_cell_v0_1->get_weights_format() != lstm_cell_v0_2->get_weights_format() ||lstm_cell_v0_1->get_input_forget() != lstm_cell_v0_2->get_input_forget()) {@@ -79,10 +85,10 @@ bool check_WRB(const shared_ptr<RNNCellBase>& cell_1, const shared_ptr<RNNCellBareturn is_equal;}-bool is_equal_cells(const shared_ptr<RNNCellBase>& cell_1, const shared_ptr<RNNCellBase>& cell_2) {+bool is_equal_cells(const shared_ptr<op_util::RNNCellBase>& cell_1, const shared_ptr<op_util::RNNCellBase>& cell_2) {bool is_equal = true;- auto gru_cell_1 = ov::as_type_ptr<ov::op::v3::GRUCell>(cell_1);- auto gru_cell_2 = ov::as_type_ptr<ov::op::v3::GRUCell>(cell_2);+ auto gru_cell_1 = ov::as_type_ptr<v3::GRUCell>(cell_1);+ auto gru_cell_2 = ov::as_type_ptr<v3::GRUCell>(cell_2);if (gru_cell_1 && gru_cell_2) {is_equal = gru_cell_1->get_linear_before_reset() == gru_cell_2->get_linear_before_reset();}@@ -95,45 +101,46 @@ bool is_equal_cells(const shared_ptr<RNNCellBase>& cell_1, const shared_ptr<RNNCreturn is_equal;}-bool check_lstm_cell(const shared_ptr<RNNCellBase>& prev_cell, const shared_ptr<RNNCellBase>& current_cell) {+bool check_lstm_cell(const shared_ptr<op_util::RNNCellBase>& prev_cell,+ const shared_ptr<op_util::RNNCellBase>& current_cell) {// check intermediate C outputs in case of LSTMCell// LSTMCell - C -> LSTMCell- if ((ov::as_type_ptr<ov::op::v4::LSTMCell>(prev_cell) || ov::as_type_ptr<ov::op::v0::LSTMCell>(prev_cell))) {+ if ((ov::as_type_ptr<v4::LSTMCell>(prev_cell) || ov::as_type_ptr<v0::LSTMCell>(prev_cell))) {const auto& target_inputs = prev_cell->get_output_target_inputs(1);bool valid = target_inputs.empty() ||(target_inputs.size() == 1 &&- ov::as_type<RNNCellBase>(target_inputs.begin()->get_node()) == current_cell.get() &&+ ov::as_type<op_util::RNNCellBase>(target_inputs.begin()->get_node()) == current_cell.get() &&target_inputs.begin()->get_index() == 2);- // if intermediate C output is connected to other node, except ov::op::v4::LSTMCell,+ // if intermediate C output is connected to other node, except v4::LSTMCell,// we can't replace cells with sequence. Sequence doesn't provide access to these outputs.return valid;}return true;}-shared_ptr<RNNCellBase> find_cell_chain(ov::pass::NodeRegistry& cp_from,- ov::pass::NodeRegistry& cp_to,- const shared_ptr<RNNCellBase>& current_cell,- ov::OutputVector& x_to_concat,- ov::OutputVector& attention_to_concat,- map<int, ov::Output<ov::Node>>& h_outputs_to_redirect,- int& cells_cnt,- const shared_ptr<ov::Node>& axis_1) {+shared_ptr<op_util::RNNCellBase> find_cell_chain(ov::pass::NodeRegistry& cp_from,+ ov::pass::NodeRegistry& cp_to,+ const shared_ptr<op_util::RNNCellBase>& current_cell,+ ov::OutputVector& x_to_concat,+ ov::OutputVector& attention_to_concat,+ map<int, ov::Output<ov::Node>>& h_outputs_to_redirect,+ int& cells_cnt,+ const shared_ptr<ov::Node>& axis_1) {cells_cnt = 1;- shared_ptr<RNNCellBase> current = current_cell;+ shared_ptr<op_util::RNNCellBase> current = current_cell;while (true) {cp_from.add(current);// check the source node of HiddenState inputauto prev = current->input_value(1).get_node_shared_ptr();- auto prev_cell = ov::as_type_ptr<RNNCellBase>(prev);+ auto prev_cell = ov::as_type_ptr<op_util::RNNCellBase>(prev);auto in_X = current->input(0);- x_to_concat.push_back(cp_to.make<ov::op::v0::Unsqueeze>(in_X.get_source_output(), axis_1));+ x_to_concat.push_back(cp_to.make<v0::Unsqueeze>(in_X.get_source_output(), axis_1));h_outputs_to_redirect[cells_cnt] = current->output(0);if (auto augru = ov::as_type_ptr<ov::op::internal::AUGRUCell>(current)) {- attention_to_concat.push_back(cp_to.make<ov::op::v0::Unsqueeze>(augru->input_value(5), axis_1));+ attention_to_concat.push_back(cp_to.make<v0::Unsqueeze>(augru->input_value(5), axis_1));}if (prev_cell && is_equal_cells(prev_cell, current) && check_lstm_cell(prev_cell, current)) {@@ -150,8 +157,8 @@ shared_ptr<RNNCellBase> find_cell_chain(ov::pass::NodeRegistry& cp_from,}bool create_sequence(ov::pass::NodeRegistry& cp_to,- const shared_ptr<RNNCellBase>& first_cell,- const shared_ptr<RNNCellBase>& last_cell,+ const shared_ptr<op_util::RNNCellBase>& first_cell,+ const shared_ptr<op_util::RNNCellBase>& last_cell,const ov::OutputVector& x_to_concat,const ov::OutputVector& attention_to_concat,const map<int, ov::Output<ov::Node>>& h_outputs_to_redirect,@@ -161,45 +168,44 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to,int64_t idx_W = 2, idx_R = 3, idx_B = 4;// 2nd input is Cell Statebool is_lstm = false;- if (ov::as_type_ptr<ov::op::v4::LSTMCell>(last_cell) || ov::as_type_ptr<ov::op::v0::LSTMCell>(last_cell)) {+ if (ov::as_type_ptr<v4::LSTMCell>(last_cell) || ov::as_type_ptr<v0::LSTMCell>(last_cell)) {is_lstm = true;idx_B++;idx_R++;idx_W++;}- const auto X_in = cp_to.make<ov::op::v0::Concat>(x_to_concat, 1);- const auto Ht_in = cp_to.make<ov::op::v0::Unsqueeze>(first_cell->input_value(1), axis_1);- const auto W_in = cp_to.make<ov::op::v0::Unsqueeze>(first_cell->input_value(idx_W), axis_0);- const auto R_in = cp_to.make<ov::op::v0::Unsqueeze>(first_cell->input_value(idx_R), axis_0);- const auto B_in = cp_to.make<ov::op::v0::Unsqueeze>(first_cell->input_value(idx_B), axis_0);+ const auto X_in = cp_to.make<v0::Concat>(x_to_concat, 1);+ const auto Ht_in = cp_to.make<v0::Unsqueeze>(first_cell->input_value(1), axis_1);+ const auto W_in = cp_to.make<v0::Unsqueeze>(first_cell->input_value(idx_W), axis_0);+ const auto R_in = cp_to.make<v0::Unsqueeze>(first_cell->input_value(idx_R), axis_0);+ const auto B_in = cp_to.make<v0::Unsqueeze>(first_cell->input_value(idx_B), axis_0);- const auto& shape_node = cp_to.add(ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(first_cell->input_value(0)));- const auto& zero = cp_to.make<ov::op::v0::Constant>(i64, ov::Shape{1}, 0);- const auto& batch_dimension = cp_to.add(ov::op::util::make_try_fold<ov::op::v8::Gather>(shape_node, zero, axis_0));- auto seq_lengths_scalar = cp_to.make<ov::op::v0::Constant>(i64, ov::Shape{}, cells_cnt);- auto sequence_lengths_in =- cp_to.add(ov::op::util::make_try_fold<ov::op::v3::Broadcast>(seq_lengths_scalar, batch_dimension));+ const auto& shape_node = cp_to.add(op_util::make_try_fold<v3::ShapeOf>(first_cell->input_value(0)));+ const auto& zero = cp_to.make<v0::Constant>(i64, ov::Shape{1}, 0);+ const auto& batch_dimension = cp_to.add(op_util::make_try_fold<ov::op::v8::Gather>(shape_node, zero, axis_0));+ auto seq_lengths_scalar = cp_to.make<v0::Constant>(i64, ov::Shape{}, cells_cnt);+ auto sequence_lengths_in = cp_to.add(op_util::make_try_fold<v3::Broadcast>(seq_lengths_scalar, batch_dimension));shared_ptr<ov::Node> sequence;ov::OutputVector outputs(1);- if (ov::as_type_ptr<ov::op::v4::LSTMCell>(first_cell)) {- const auto Ct_in = cp_to.make<ov::op::v0::Unsqueeze>(first_cell->input_value(2), axis_1);- sequence = cp_to.make<ov::op::v5::LSTMSequence>(X_in,- Ht_in,- Ct_in,- sequence_lengths_in,- W_in,- R_in,- B_in,- first_cell->get_hidden_size(),- ov::op::RecurrentSequenceDirection::FORWARD,- first_cell->get_activations_alpha(),- first_cell->get_activations_beta(),- first_cell->get_activations(),- first_cell->get_clip());+ if (ov::as_type_ptr<v4::LSTMCell>(first_cell)) {+ const auto Ct_in = cp_to.make<v0::Unsqueeze>(first_cell->input_value(2), axis_1);+ sequence = cp_to.make<v5::LSTMSequence>(X_in,+ Ht_in,+ Ct_in,+ sequence_lengths_in,+ W_in,+ R_in,+ B_in,+ first_cell->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::FORWARD,+ first_cell->get_activations_alpha(),+ first_cell->get_activations_beta(),+ first_cell->get_activations(),+ first_cell->get_clip());outputs.resize(2);- outputs[1] = cp_to.make<ov::op::v0::Squeeze>(sequence->output(2), axis_1);- } else if (auto lstm_cell_v0 = ov::as_type_ptr<ov::op::v0::LSTMCell>(first_cell)) {+ outputs[1] = cp_to.make<v0::Squeeze>(sequence->output(2), axis_1);+ } else if (auto lstm_cell_v0 = ov::as_type_ptr<v0::LSTMCell>(first_cell)) {// input_forget modification is not supportedif (lstm_cell_v0->get_input_forget()) {return false;@@ -207,55 +213,55 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to,auto weights_format = lstm_cell_v0->get_weights_format();ov::Output<ov::Node> W = W_in, R = R_in, B = B_in;if (weights_format != ov::op::LSTMWeightsFormat::FICO) {- W = ov::op::util::convert_lstm_node_format(W_in, convert_lstm_weights_enums(weights_format));- R = ov::op::util::convert_lstm_node_format(R_in, convert_lstm_weights_enums(weights_format));- B = ov::op::util::convert_lstm_node_format(B_in, convert_lstm_weights_enums(weights_format));+ W = op_util::convert_lstm_node_format(W_in, convert_lstm_weights_enums(weights_format));+ R = op_util::convert_lstm_node_format(R_in, convert_lstm_weights_enums(weights_format));+ B = op_util::convert_lstm_node_format(B_in, convert_lstm_weights_enums(weights_format));}- const auto Ct_in = cp_to.make<ov::op::v0::Unsqueeze>(first_cell->input_value(2), axis_1);- sequence = cp_to.make<ov::op::v5::LSTMSequence>(X_in,- Ht_in,- Ct_in,- sequence_lengths_in,- W,- R,- B,- first_cell->get_hidden_size(),- ov::op::RecurrentSequenceDirection::FORWARD,- first_cell->get_activations_alpha(),- first_cell->get_activations_beta(),- first_cell->get_activations(),- first_cell->get_clip());+ const auto Ct_in = cp_to.make<v0::Unsqueeze>(first_cell->input_value(2), axis_1);+ sequence = cp_to.make<v5::LSTMSequence>(X_in,+ Ht_in,+ Ct_in,+ sequence_lengths_in,+ W,+ R,+ B,+ first_cell->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::FORWARD,+ first_cell->get_activations_alpha(),+ first_cell->get_activations_beta(),+ first_cell->get_activations(),+ first_cell->get_clip());outputs.resize(2);- outputs[1] = cp_to.make<ov::op::v0::Squeeze>(sequence->output(2), axis_1);- } else if (auto gru_cell = ov::as_type_ptr<ov::op::v3::GRUCell>(first_cell)) {- sequence = cp_to.make<ov::op::v5::GRUSequence>(X_in,- Ht_in,- sequence_lengths_in,- W_in,- R_in,- B_in,- first_cell->get_hidden_size(),- ov::op::RecurrentSequenceDirection::FORWARD,- first_cell->get_activations(),- first_cell->get_activations_alpha(),- first_cell->get_activations_beta(),- first_cell->get_clip(),- gru_cell->get_linear_before_reset());- } else if (ov::as_type_ptr<ov::op::v0::RNNCell>(first_cell)) {- sequence = cp_to.make<ov::op::v5::RNNSequence>(X_in,- Ht_in,- sequence_lengths_in,- W_in,- R_in,- B_in,- first_cell->get_hidden_size(),- ov::op::RecurrentSequenceDirection::FORWARD,- first_cell->get_activations(),- first_cell->get_activations_alpha(),- first_cell->get_activations_beta(),- first_cell->get_clip());+ outputs[1] = cp_to.make<v0::Squeeze>(sequence->output(2), axis_1);+ } else if (auto gru_cell = ov::as_type_ptr<v3::GRUCell>(first_cell)) {+ sequence = cp_to.make<v5::GRUSequence>(X_in,+ Ht_in,+ sequence_lengths_in,+ W_in,+ R_in,+ B_in,+ first_cell->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::FORWARD,+ first_cell->get_activations(),+ first_cell->get_activations_alpha(),+ first_cell->get_activations_beta(),+ first_cell->get_clip(),+ gru_cell->get_linear_before_reset());+ } else if (ov::as_type_ptr<v0::RNNCell>(first_cell)) {+ sequence = cp_to.make<v5::RNNSequence>(X_in,+ Ht_in,+ sequence_lengths_in,+ W_in,+ R_in,+ B_in,+ first_cell->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::FORWARD,+ first_cell->get_activations(),+ first_cell->get_activations_alpha(),+ first_cell->get_activations_beta(),+ first_cell->get_clip());} else if (ov::as_type_ptr<ov::op::internal::AUGRUCell>(first_cell)) {- const auto A_in = cp_to.make<ov::op::v0::Concat>(attention_to_concat, 1);+ const auto A_in = cp_to.make<v0::Concat>(attention_to_concat, 1);sequence = cp_to.make<ov::op::internal::AUGRUSequence>(X_in,Ht_in,sequence_lengths_in,@@ -270,7 +276,7 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to,}if (!h_outputs_to_redirect.empty()) {- auto squeeze_Y = cp_to.make<ov::op::v0::Squeeze>(sequence->output(0), axis_1);+ auto squeeze_Y = cp_to.make<v0::Squeeze>(sequence->output(0), axis_1);auto split = cp_to.make<ov::op::v1::Split>(squeeze_Y, axis_1, cells_cnt);for (auto it : h_outputs_to_redirect) {@@ -279,7 +285,7 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to,if (it.first == 1) {Hi = sequence->output(1);}- auto squeeze = cp_to.make<ov::op::v0::Squeeze>(Hi, axis_1);+ auto squeeze = cp_to.make<v0::Squeeze>(Hi, axis_1);it.second.replace(squeeze);if (is_lstm) {friendly_name += ":1";@@ -288,7 +294,7 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to,}}if (is_lstm) {- auto squeeze = cp_to.make<ov::op::v0::Squeeze>(sequence->output(2), axis_1);+ auto squeeze = cp_to.make<v0::Squeeze>(sequence->output(2), axis_1);last_cell->output(1).replace(squeeze);squeeze->set_friendly_name(last_cell->get_friendly_name() + ":2");}@@ -300,12 +306,12 @@ bool create_sequence(ov::pass::NodeRegistry& cp_to,ov::pass::SequenceFusion::SequenceFusion() {MATCHER_SCOPE(SequenceFusion);- auto cell = pattern::wrap_type<RNNCellBase>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- NodeRegistry copy_from;- NodeRegistry copy_to;+ auto cell = ov::pass::pattern::wrap_type<op_util::RNNCellBase>();+ matcher_pass_callback callback = [=](Matcher& m) {+ ov::pass::NodeRegistry copy_from;+ ov::pass::NodeRegistry copy_to;auto cell = m.get_match_root();- shared_ptr<RNNCellBase> current_cell = ov::as_type_ptr<RNNCellBase>(cell);+ shared_ptr<op_util::RNNCellBase> current_cell = ov::as_type_ptr<op_util::RNNCellBase>(cell);if (!current_cell) {return false;}@@ -313,7 +319,7 @@ ov::pass::SequenceFusion::SequenceFusion() {// GRUCell -> GRUCell (the last cell) -> OtherNode// GRUCell (hidden_size = 128) -> GRUCell (hs = 128, the last) -> GRUCell (hs = 64)for (const auto& target : cell->get_output_target_inputs(0)) {- auto cell_1 = ov::as_type_ptr<RNNCellBase>(target.get_node()->shared_from_this());+ auto cell_1 = ov::as_type_ptr<op_util::RNNCellBase>(target.get_node()->shared_from_this());if (cell_1 && is_equal_cells(cell_1, current_cell)) {return false;}@@ -322,8 +328,8 @@ ov::pass::SequenceFusion::SequenceFusion() {ov::OutputVector x_to_concat;ov::OutputVector attention_to_concat;map<int, ov::Output<ov::Node>> h_outputs_to_redirect;- auto axis_0 = copy_to.make<ov::op::v0::Constant>(i64, Shape{}, 0);- auto axis_1 = copy_to.make<ov::op::v0::Constant>(i64, Shape{}, 1);+ auto axis_0 = copy_to.make<v0::Constant>(i64, Shape{}, 0);+ auto axis_1 = copy_to.make<v0::Constant>(i64, Shape{}, 1);// detect chain (Cell->Cell->Cell->..)auto first_cell = find_cell_chain(copy_from,@@ -361,6 +367,6 @@ ov::pass::SequenceFusion::SequenceFusion() {return true;};- auto m = make_shared<pattern::Matcher>(cell, matcher_name);+ auto m = make_shared<Matcher>(cell, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/shared_ops_optimization.cpp b/src/common/transformations/src/transformations/common_optimizations/shared_ops_optimization.cppindex 275409f1946..9a56d2f4e4b 100644--- a/src/common/transformations/src/transformations/common_optimizations/shared_ops_optimization.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/shared_ops_optimization.cpp@@ -13,8 +13,9 @@using namespace std;using namespace ov;-using namespace ov::op;+namespace v0 = ov::op::v0;+namespace op_util = ov::op::util;namespace {#define ACCESSOR(type) \void on_adapter(const std::string& name, ValueAccessor<type>& adapter) override { \@@ -62,7 +63,7 @@ bool inputs_from_same_source_or_equal_constants(const std::shared_ptr<Node>& lhsif (input_size != rhs->get_input_size())return false;for (size_t i = 0; i < input_size; ++i) {- if (ov::op::util::input_sources_are_equal(lhs, rhs, i))+ if (op_util::input_sources_are_equal(lhs, rhs, i))continue;auto lhs_constant = as_type<v0::Constant>(lhs->get_input_node_ptr(i));auto rhs_constant = as_type<v0::Constant>(rhs->get_input_node_ptr(i));@@ -127,7 +128,7 @@ bool shared_node_optimization(const shared_ptr<Model>& model) {std::unordered_map<std::shared_ptr<ov::Node>, ov::AnyMap> node_attributes_cache;for (const auto& op : order) {// Recursively apply transformation for sub-graph based operations- if (auto multi_subgraph_op = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(op)) {+ if (auto multi_subgraph_op = ov::as_type_ptr<op_util::MultiSubGraphOp>(op)) {for (const auto& sub_graph : multi_subgraph_op->get_functions()) {if (sub_graph)rewritten = shared_node_optimization(sub_graph) || rewritten;@@ -165,7 +166,7 @@ bool shared_node_optimization(const shared_ptr<Model>& model) {const auto& child_op = shared_nodes[j];// no functionality is implemented to compare bodies of MultiSubGraphOp operations- if (ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(root_op)) {+ if (ov::as_type_ptr<op_util::MultiSubGraphOp>(root_op)) {continue;}@@ -186,13 +187,13 @@ bool shape_of_upgrade(const shared_ptr<Model>& model) {bool rewritten = false;for (const auto& op : model->get_ordered_ops()) {// Recursively apply transformation for sub-graph based operations- if (auto multi_subgraph_op = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(op)) {+ if (auto multi_subgraph_op = ov::as_type_ptr<op_util::MultiSubGraphOp>(op)) {for (const auto& sub_graph : multi_subgraph_op->get_functions()) {if (sub_graph)rewritten = shape_of_upgrade(sub_graph) || rewritten;}} else if (auto v1_shape_of = ov::as_type_ptr<v0::ShapeOf>(op)) {- auto v3_shape_of = std::make_shared<v3::ShapeOf>(v1_shape_of->input_value(0), element::i64);+ auto v3_shape_of = std::make_shared<ov::op::v3::ShapeOf>(v1_shape_of->input_value(0), element::i64);v3_shape_of->set_friendly_name(v1_shape_of->get_friendly_name());ov::replace_output_update_name(v1_shape_of, v3_shape_of);rewritten = true;diff --git a/src/common/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cppindex ec51443ff16..dcdea438977 100644--- a/src/common/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/shuffle_channels_fusion.cpp@@ -17,6 +17,13 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::consumers_count;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;namespace {bool check_shapes(const ov::PartialShape& pshape_input,const ov::PartialShape& pshape_reshape_before,@@ -55,7 +62,7 @@ bool check_shapes(const ov::PartialShape& pshape_input,pshape_input[3]};}- if (!ov::op::util::shapes_equal_except_dynamic_expected_batch(expected_reshape_before, pshape_reshape_before)) {+ if (!op_util::shapes_equal_except_dynamic_expected_batch(expected_reshape_before, pshape_reshape_before)) {return false;}@@ -74,7 +81,7 @@ bool check_shapes(const ov::PartialShape& pshape_input,}// y = reshape(x'', [N, C, H, W])- if (!ov::op::util::shapes_equal_except_dynamic_expected_batch(pshape_input, pshape_reshape_after)) {+ if (!op_util::shapes_equal_except_dynamic_expected_batch(pshape_input, pshape_reshape_after)) {return false;}@@ -85,34 +92,28 @@ bool check_shapes(const ov::PartialShape& pshape_input,ov::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_constants_check) {MATCHER_SCOPE(ShuffleChannelsFusion);- auto input = pass::pattern::any_input(pattern::rank_equals(4));- auto reshape_before_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto transpose_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto reshape_after_const_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();-- auto reshape_before_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({input, reshape_before_const_pattern},- pattern::consumers_count(1));+ auto input = ov::pass::pattern::any_input(ov::pass::pattern::rank_equals(4));+ auto reshape_before_const_pattern = wrap_type<v0::Constant>();+ auto transpose_const_pattern = wrap_type<v0::Constant>();+ auto reshape_after_const_pattern = wrap_type<v0::Constant>();++ auto reshape_before_pattern = wrap_type<v1::Reshape>({input, reshape_before_const_pattern}, consumers_count(1));auto transpose_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Transpose>({reshape_before_pattern, transpose_const_pattern},- pattern::consumers_count(1));- auto reshape_after_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({transpose_pattern, reshape_after_const_pattern});+ wrap_type<v1::Transpose>({reshape_before_pattern, transpose_const_pattern}, consumers_count(1));+ auto reshape_after_pattern = wrap_type<v1::Reshape>({transpose_pattern, reshape_after_const_pattern});- ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto data = pattern_map.at(input);auto reshape_before_constant =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(reshape_before_const_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_map.at(reshape_before_const_pattern).get_node_shared_ptr());auto reshape_before =- ov::as_type_ptr<ov::op::v1::Reshape>(pattern_map.at(reshape_before_pattern).get_node_shared_ptr());- auto transpose =- ov::as_type_ptr<ov::op::v1::Transpose>(pattern_map.at(transpose_pattern).get_node_shared_ptr());- auto reshape_after =- ov::as_type_ptr<ov::op::v1::Reshape>(pattern_map.at(reshape_after_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v1::Reshape>(pattern_map.at(reshape_before_pattern).get_node_shared_ptr());+ auto transpose = ov::as_type_ptr<v1::Transpose>(pattern_map.at(transpose_pattern).get_node_shared_ptr());+ auto reshape_after = ov::as_type_ptr<v1::Reshape>(pattern_map.at(reshape_after_pattern).get_node_shared_ptr());auto reshape_after_constant =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(reshape_after_const_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_map.at(reshape_after_const_pattern).get_node_shared_ptr());if (!reshape_after || !transpose || !reshape_before || !reshape_before_constant || !reshape_after_constant) {return false;}@@ -137,7 +138,7 @@ ov::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_constaauto pshape_reshape_after = reshape_after->get_output_partial_shape(0);auto transpose_constant =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(transpose_const_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_map.at(transpose_const_pattern).get_node_shared_ptr());auto transpose_constant_values = transpose_constant->get_axis_vector_val();if (!check_shapes(pshape_input, pshape_reshape_before, transpose_constant_values, pshape_reshape_after)) {return false;@@ -146,7 +147,7 @@ ov::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_constaint64_t axis = 1ul;int64_t group = pshape_reshape_before[1].get_length();- auto shuffle_shannels = std::make_shared<ov::op::v0::ShuffleChannels>(data, axis, group);+ auto shuffle_shannels = std::make_shared<v0::ShuffleChannels>(data, axis, group);shuffle_shannels->set_friendly_name(reshape_after->get_friendly_name());ov::copy_runtime_info({reshape_before,reshape_before_constant,@@ -159,6 +160,6 @@ ov::pass::ShuffleChannelsFusion::ShuffleChannelsFusion(const bool reshape_constareturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reshape_after_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(reshape_after_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp b/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cppindex 6b276627f34..51299c358b4 100644--- a/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/simplify_shape_of_sub_graph.cpp@@ -30,9 +30,19 @@#include "transformations/utils/utils.hpp"using namespace ov;-using namespace ov::op;-using namespace ov::pass::pattern;+using ov::pass::pattern::any_input;+using ov::pass::pattern::has_static_shape;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::rank_equals;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v7 = ov::op::v7;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;pass::GroupedGatherElimination::GroupedGatherElimination() {MATCHER_SCOPE(GroupedGatherElimination);auto concat_label = wrap_type<v0::Concat>(rank_equals(1));@@ -80,7 +90,7 @@ pass::GroupedGatherElimination::GroupedGatherElimination() {// curr and next are the same type of gather which takes data from the same sourceauto joint_indices =- new_ops.add(ov::op::util::make_try_fold<v0::Concat>(OutputVector{curr_indices, next_indices}, 0));+ new_ops.add(op_util::make_try_fold<v0::Concat>(OutputVector{curr_indices, next_indices}, 0));std::shared_ptr<Node> new_gather;if (is_type<v1::Gather>(curr)) {new_gather = register_new_node<v1::Gather>(curr->input_value(0),@@ -121,7 +131,7 @@ pass::GroupedGatherElimination::GroupedGatherElimination() {pass::GatherNopElimination::GatherNopElimination() {MATCHER_SCOPE(GatherNopElimination);- const auto gather_label = wrap_type<ov::op::util::GatherBase>(+ const auto gather_label = wrap_type<op_util::GatherBase>({any_input(has_static_shape()), wrap_type<v0::Constant>(), wrap_type<v0::Constant>()});matcher_pass_callback callback = [](Matcher& m) {@@ -145,7 +155,7 @@ pass::GatherNopElimination::GatherNopElimination() {pass::AbsSinking::AbsSinking() {MATCHER_SCOPE(AbsSinking);- const auto abs_label = wrap_type<ov::op::v0::Abs>(pattern::rank_equals(1));+ const auto abs_label = wrap_type<v0::Abs>(rank_equals(1));matcher_pass_callback callback = [](Matcher& m) {NodeVector abs_ops = {m.get_match_root()};@@ -154,7 +164,7 @@ pass::AbsSinking::AbsSinking() {if (auto concat = as_type_ptr<v0::Concat>(abs_ops[0]->get_input_node_shared_ptr(0))) {for (const auto& input : concat->inputs()) {- auto new_abs = ov::op::util::make_try_fold<v0::Abs>(input.get_source_output());+ auto new_abs = op_util::make_try_fold<v0::Abs>(input.get_source_output());if (!as_type_ptr<v0::Constant>(new_abs))abs_ops.push_back(new_abs);input.replace_source_output(new_abs);@@ -186,15 +196,15 @@ pass::AbsSinking::AbsSinking() {pass::SimplifyGatherShapeOf::SimplifyGatherShapeOf() {MATCHER_SCOPE(SimplifyGatherShapeOf);- const auto data_pattern = pattern::any_input(pattern::has_static_rank());- const auto indices_pattern = pattern::any_input(pattern::has_static_rank());- const auto axis_pattern = wrap_type<ov::op::v0::Constant>();- const auto gather_pattern = wrap_type<ov::op::util::GatherBase>({data_pattern, indices_pattern, axis_pattern});+ const auto data_pattern = any_input(ov::pass::pattern::has_static_rank());+ const auto indices_pattern = any_input(ov::pass::pattern::has_static_rank());+ const auto axis_pattern = wrap_type<v0::Constant>();+ const auto gather_pattern = wrap_type<op_util::GatherBase>({data_pattern, indices_pattern, axis_pattern});const auto shape_of_pattern = wrap_type<v0::ShapeOf, v3::ShapeOf>({gather_pattern});matcher_pass_callback callback = [](Matcher& m) {auto node = m.get_match_root();- auto gather = as_type_ptr<ov::op::util::GatherBase>(node->input_value(0).get_node_shared_ptr());+ auto gather = as_type_ptr<op_util::GatherBase>(node->input_value(0).get_node_shared_ptr());if (!gather || gather->get_batch_dims() != 0) {return false;}@@ -281,13 +291,13 @@ pass::SimplifySecondInputOfReshape::SimplifySecondInputOfReshape() {auto data = m.get_pattern_value_map().at(input);if (is_type<v0::FakeQuantize>(data.get_node_shared_ptr()) ||- ov::op::util::is_unary_elementwise_arithmetic(data.get_node_shared_ptr())) {+ op_util::is_unary_elementwise_arithmetic(data.get_node_shared_ptr())) {data = data.get_node_shared_ptr()->input_value(0);}auto check_shape_of_gather = [&](const std::shared_ptr<Node>& gather) {auto shape_of = gather->get_input_node_shared_ptr(0);- if (!is_type<ov::op::util::ShapeOfBase>(shape_of)) {+ if (!is_type<op_util::ShapeOfBase>(shape_of)) {return false;}return shape_of->input_value(0) == data;@@ -311,7 +321,7 @@ pass::SimplifySecondInputOfReshape::SimplifySecondInputOfReshape() {// that change the arrangement of dimensions in the reshape patternfor (auto& concat_input : new_concat_inputs) {auto node = concat_input.get_node_shared_ptr();- if (ov::is_type<ov::op::util::GatherBase>(node) &&+ if (ov::is_type<op_util::GatherBase>(node) &&ov::is_type<v0::Constant>(node->get_input_node_shared_ptr(1)) && check_shape_of_gather(node)) {auto indices_constant = as_type_ptr<v0::Constant>(node->get_input_node_shared_ptr(1));bool gather_can_be_fused = true;@@ -348,7 +358,7 @@ pass::SimplifySecondInputOfReshape::SimplifySecondInputOfReshape() {return false;}- const auto new_concat = ov::op::util::make_try_fold<v0::Concat>(new_concat_inputs, concat_axis);+ const auto new_concat = op_util::make_try_fold<v0::Concat>(new_concat_inputs, concat_axis);new_concat->set_friendly_name(concat->get_friendly_name());copy_runtime_info(concat, new_concat);diff --git a/src/common/transformations/src/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.cpp b/src/common/transformations/src/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.cppindex 7099d7260ea..d909fa4346c 100644--- a/src/common/transformations/src/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/skip_gather_before_transpose_and_reshape.cpp@@ -17,22 +17,27 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::SkipGatherBeforeTransposeAndReshape::SkipGatherBeforeTransposeAndReshape() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++SkipGatherBeforeTransposeAndReshape::SkipGatherBeforeTransposeAndReshape() {MATCHER_SCOPE(SkipGatherBeforeTransposeAndReshape);- auto input_m = pass::pattern::any_input(ov::pass::pattern::has_static_dim(0));+ auto input_m = pattern::any_input(pattern::has_static_dim(0));- auto indices_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto axis_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto gather_m = ov::pass::pattern::wrap_type<ov::op::util::GatherBase>({input_m, indices_m, axis_m});+ auto indices_m = pattern::wrap_type<v0::Constant>();+ auto axis_m = pattern::wrap_type<v0::Constant>();+ auto gather_m = pattern::wrap_type<ov::op::util::GatherBase>({input_m, indices_m, axis_m});- auto transpose_const_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto transpose_m = ov::pass::pattern::wrap_type<ov::op::v1::Transpose>({gather_m, transpose_const_m});+ auto transpose_const_m = pattern::wrap_type<v0::Constant>();+ auto transpose_m = pattern::wrap_type<v1::Transpose>({gather_m, transpose_const_m});- auto reshape_const_m = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto reshape_m = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({transpose_m, reshape_const_m});+ auto reshape_const_m = pattern::wrap_type<v0::Constant>();+ auto reshape_m = pattern::wrap_type<v1::Reshape>({transpose_m, reshape_const_m});- ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& input = pattern_map.at(input_m);if (input.get_partial_shape()[0] != 1) {@@ -40,8 +45,8 @@ ov::pass::SkipGatherBeforeTransposeAndReshape::SkipGatherBeforeTransposeAndResha}const auto gather = pattern_map.at(gather_m).get_node_shared_ptr();- const auto indices = as_type_ptr<ov::op::v0::Constant>(pattern_map.at(indices_m).get_node_shared_ptr());- const auto axis = as_type_ptr<ov::op::v0::Constant>(pattern_map.at(axis_m).get_node_shared_ptr());+ const auto indices = as_type_ptr<v0::Constant>(pattern_map.at(indices_m).get_node_shared_ptr());+ const auto axis = as_type_ptr<v0::Constant>(pattern_map.at(axis_m).get_node_shared_ptr());if (!indices || !axis) {return false;}@@ -53,14 +58,12 @@ ov::pass::SkipGatherBeforeTransposeAndReshape::SkipGatherBeforeTransposeAndResha}const auto transpose = pattern_map.at(transpose_m).get_node_shared_ptr();- const auto transpose_const =- as_type_ptr<ov::op::v0::Constant>(pattern_map.at(transpose_const_m).get_node_shared_ptr());+ const auto transpose_const = as_type_ptr<v0::Constant>(pattern_map.at(transpose_const_m).get_node_shared_ptr());if (!transpose_const) {return false;}- const auto reshape_const =- as_type_ptr<ov::op::v0::Constant>(pattern_map.at(reshape_const_m).get_node_shared_ptr());+ const auto reshape_const = as_type_ptr<v0::Constant>(pattern_map.at(reshape_const_m).get_node_shared_ptr());if (!reshape_const) {return false;}@@ -79,9 +82,8 @@ ov::pass::SkipGatherBeforeTransposeAndReshape::SkipGatherBeforeTransposeAndReshanew_transpose_vals.push_back(++elem);}- const auto new_transpose_const = ov::op::v0::Constant::create(transpose_const->get_element_type(),- {new_transpose_vals.size()},- new_transpose_vals);+ const auto new_transpose_const =+ v0::Constant::create(transpose_const->get_element_type(), {new_transpose_vals.size()}, new_transpose_vals);const auto new_transpose = transpose->clone_with_new_inputs({input, new_transpose_const});new_transpose->set_friendly_name(transpose->get_friendly_name());ov::copy_runtime_info({transpose, gather}, new_transpose);@@ -90,6 +92,8 @@ ov::pass::SkipGatherBeforeTransposeAndReshape::SkipGatherBeforeTransposeAndReshareturn false;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reshape_m, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(reshape_m, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/softmax_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/softmax_fusion.cppindex 93f2c5a4a99..c7f0db2fa9e 100644--- a/src/common/transformations/src/transformations/common_optimizations/softmax_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/softmax_fusion.cpp@@ -21,31 +21,34 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::SoftmaxFusion::SoftmaxFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++SoftmaxFusion::SoftmaxFusion() {MATCHER_SCOPE(SoftmaxFusion);- auto data_pattern = pass::pattern::any_input(pass::pattern::has_static_rank());- auto reduce_max_axes_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto reduce_max_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::ReduceMax>({data_pattern, reduce_max_axes_pattern});- auto sub_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Subtract>({data_pattern, reduce_max_pattern});+ auto data_pattern = pattern::any_input(pattern::has_static_rank());+ auto reduce_max_axes_pattern = pattern::wrap_type<v0::Constant>();+ auto reduce_max_pattern = pattern::wrap_type<v1::ReduceMax>({data_pattern, reduce_max_axes_pattern});+ auto sub_pattern = pattern::wrap_type<v1::Subtract>({data_pattern, reduce_max_pattern});auto exp_input = std::make_shared<pattern::op::Or>(OutputVector{sub_pattern, data_pattern});- auto exp_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Exp>({exp_input});+ auto exp_pattern = pattern::wrap_type<v0::Exp>({exp_input});- auto reduce_sum_axes_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto reduce_sum_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::ReduceSum>({exp_pattern, reduce_sum_axes_pattern});- auto div_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Divide>({exp_pattern, reduce_sum_pattern});+ auto reduce_sum_axes_pattern = pattern::wrap_type<v0::Constant>();+ auto reduce_sum_pattern = pattern::wrap_type<v1::ReduceSum>({exp_pattern, reduce_sum_axes_pattern});+ auto div_pattern = pattern::wrap_type<v1::Divide>({exp_pattern, reduce_sum_pattern});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {if (transformation_callback(m.get_match_root()))return false;const auto& pattern_map = m.get_pattern_value_map();auto reduce_sum_axes =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(reduce_sum_axes_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_map.at(reduce_sum_axes_pattern).get_node_shared_ptr());if (!reduce_sum_axes || shape_size(reduce_sum_axes->get_shape()) != 1)return false;int64_t reduce_sum_axis = reduce_sum_axes->cast_vector<int64_t>()[0];@@ -57,7 +60,7 @@ ov::pass::SoftmaxFusion::SoftmaxFusion() {auto exp_input_is_subtract = pattern_map.count(sub_pattern) != 0;if (exp_input_is_subtract) {auto reduce_max_axes =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(reduce_max_axes_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_map.at(reduce_max_axes_pattern).get_node_shared_ptr());if (!reduce_max_axes || shape_size(reduce_max_axes->get_shape()) != 1)return false;int64_t reduce_max_axis = reduce_max_axes->cast_vector<int64_t>()[0];@@ -71,7 +74,7 @@ ov::pass::SoftmaxFusion::SoftmaxFusion() {return false;}- auto softmax = register_new_node<ov::op::v1::Softmax>(pattern_map.at(data_pattern), reduce_sum_axis);+ auto softmax = register_new_node<v1::Softmax>(pattern_map.at(data_pattern), reduce_sum_axis);auto div = pattern_map.at(div_pattern).get_node_shared_ptr();softmax->set_friendly_name(div->get_friendly_name());@@ -90,6 +93,8 @@ ov::pass::SoftmaxFusion::SoftmaxFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(div_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(div_pattern, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/softplus_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/softplus_fusion.cppindex 11d1217df0d..e1baf752bf2 100644--- a/src/common/transformations/src/transformations/common_optimizations/softplus_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/softplus_fusion.cpp@@ -17,21 +17,24 @@#include "openvino/op/softplus.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::SoftPlusFusion::SoftPlusFusion() {+namespace v0 = ov::op::v0;++namespace ov::pass {++SoftPlusFusion::SoftPlusFusion() {MATCHER_SCOPE(SoftPlusFusion);// fuses ln(exp(x) + 1.0) operations into SoftPlus(x)auto input = pattern::any_input();- auto exp = std::make_shared<ov::op::v0::Exp>(input);- auto add_constant =- ov::pass::pattern::wrap_type<ov::op::v0::Constant>(pattern::type_matches_any({element::f32, element::f16}));+ auto exp = std::make_shared<v0::Exp>(input);+ auto add_constant = pattern::wrap_type<v0::Constant>(pattern::type_matches_any({element::f32, element::f16}));auto add = std::make_shared<ov::op::v1::Add>(exp, add_constant);- auto log = std::make_shared<ov::op::v0::Log>(add);+ auto log = std::make_shared<v0::Log>(add);- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto exp_input = pattern_to_output.at(input);- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ auto constant = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());if (!constant)return false;@@ -51,6 +54,8 @@ ov::pass::SoftPlusFusion::SoftPlusFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(log, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(log, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/softplus_to_mish_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/softplus_to_mish_fusion.cppindex 4fd7a9abd31..d33592017ad 100644--- a/src/common/transformations/src/transformations/common_optimizations/softplus_to_mish_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/softplus_to_mish_fusion.cpp@@ -16,18 +16,22 @@#include "openvino/op/tanh.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::SoftPlusToMishFusion::SoftPlusToMishFusion() {+namespace v4 = ov::op::v4;++namespace ov::pass {++SoftPlusToMishFusion::SoftPlusToMishFusion() {MATCHER_SCOPE(SoftPlusToMishFusion);- auto input = pass::pattern::any_input();- auto softplus = ov::pass::pattern::wrap_type<ov::op::v4::SoftPlus>({input}, pattern::consumers_count(1));- auto tanh = ov::pass::pattern::wrap_type<ov::op::v0::Tanh>({softplus}, pattern::consumers_count(1));+ auto input = pattern::any_input();+ auto softplus = pattern::wrap_type<v4::SoftPlus>({input}, pattern::consumers_count(1));+ auto tanh = pattern::wrap_type<ov::op::v0::Tanh>({softplus}, pattern::consumers_count(1));auto mul = std::make_shared<ov::op::v1::Multiply>(input, tanh);- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto exp_input = pattern_to_output.at(input);- auto mish = std::make_shared<ov::op::v4::Mish>(exp_input);+ auto mish = std::make_shared<v4::Mish>(exp_input);mish->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({pattern_to_output.at(mul).get_node_shared_ptr(),@@ -38,6 +42,8 @@ ov::pass::SoftPlusToMishFusion::SoftPlusToMishFusion() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(mul, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/space_to_batch_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/space_to_batch_fusion.cppindex 4b65a347b30..9a0cc5f17ac 100644--- a/src/common/transformations/src/transformations/common_optimizations/space_to_batch_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/space_to_batch_fusion.cpp@@ -20,34 +20,35 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;+using ov::pass::pattern::rank_equals;+using ov::pass::pattern::wrap_type;+using ov::pass::pattern::op::Or;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;ov::pass::SpaceToBatchFusion::SpaceToBatchFusion() {MATCHER_SCOPE(SpaceToBatchFusion);- auto data_pattern = pattern::any_input();- auto reshape_before_pattern =- pattern::wrap_type<ov::op::v1::Reshape>({data_pattern, pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(4));- auto trans_before_pattern =- pattern::wrap_type<ov::op::v1::Transpose>({data_pattern, pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(4));+ auto data_pattern = ov::pass::pattern::any_input();+ auto reshape_before_pattern = wrap_type<v1::Reshape>({data_pattern, wrap_type<v0::Constant>()}, rank_equals(4));+ auto trans_before_pattern = wrap_type<v1::Transpose>({data_pattern, wrap_type<v0::Constant>()}, rank_equals(4));auto reshape_or_transpose_before_pattern =- std::make_shared<pattern::op::Or>(OutputVector{reshape_before_pattern, trans_before_pattern});- auto pads_begin_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto pads_end_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto pad_value = pattern::wrap_type<ov::op::v0::Constant>();- auto pad_pattern = pattern::wrap_type<ov::op::util::PadBase>(+ std::make_shared<Or>(OutputVector{reshape_before_pattern, trans_before_pattern});+ auto pads_begin_pattern = wrap_type<v0::Constant>();+ auto pads_end_pattern = wrap_type<v0::Constant>();+ auto pad_value = wrap_type<v0::Constant>();+ auto pad_pattern = wrap_type<op_util::PadBase>({reshape_or_transpose_before_pattern, pads_begin_pattern, pads_end_pattern, pad_value});- auto space_to_depth_pattern =- pattern::wrap_type<ov::op::v0::SpaceToDepth>({pad_pattern}, pattern::has_static_shape());+ auto space_to_depth_pattern = wrap_type<v0::SpaceToDepth>({pad_pattern}, ov::pass::pattern::has_static_shape());auto reshape_after_pattern =- pattern::wrap_type<ov::op::v1::Reshape>({space_to_depth_pattern, pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(4));+ wrap_type<v1::Reshape>({space_to_depth_pattern, wrap_type<v0::Constant>()}, rank_equals(4));auto trans_after_pattern =- pattern::wrap_type<ov::op::v1::Transpose>({space_to_depth_pattern, pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(4));+ wrap_type<v1::Transpose>({space_to_depth_pattern, wrap_type<v0::Constant>()}, rank_equals(4));auto reshape_or_transpose_after_pattern =- std::make_shared<pattern::op::Or>(OutputVector{reshape_after_pattern, trans_after_pattern});+ std::make_shared<Or>(OutputVector{reshape_after_pattern, trans_after_pattern});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto get_reshape_or_transpose = [&pattern_map](@@ -68,7 +69,7 @@ ov::pass::SpaceToBatchFusion::SpaceToBatchFusion() {};auto pads_are_negative = [](const std::shared_ptr<Node>& pads) -> bool {- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(pads);+ auto constant = ov::as_type_ptr<v0::Constant>(pads);if (!constant)return true;@@ -94,10 +95,10 @@ ov::pass::SpaceToBatchFusion::SpaceToBatchFusion() {if (!check_input_output_shape(reshape_or_trans_after))return false;- auto pad = ov::as_type_ptr<ov::op::util::PadBase>(pattern_map.at(pad_pattern).get_node_shared_ptr());+ auto pad = ov::as_type_ptr<op_util::PadBase>(pattern_map.at(pad_pattern).get_node_shared_ptr());if (!pad || pad->get_pad_mode() != ov::op::PadMode::CONSTANT)return false;- auto pad_value_const = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(pad_value).get_node_shared_ptr());+ auto pad_value_const = ov::as_type_ptr<v0::Constant>(pattern_map.at(pad_value).get_node_shared_ptr());if (!pad_value_const)return false;auto pad_value = pad_value_const->cast_vector<float>();@@ -112,18 +113,16 @@ ov::pass::SpaceToBatchFusion::SpaceToBatchFusion() {return false;auto space_to_depth =- ov::as_type_ptr<ov::op::v0::SpaceToDepth>(pattern_map.at(space_to_depth_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v0::SpaceToDepth>(pattern_map.at(space_to_depth_pattern).get_node_shared_ptr());if (!space_to_depth)return false;- if (space_to_depth->get_mode() != ov::op::v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST)+ if (space_to_depth->get_mode() != v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST)return false;auto block_size = static_cast<int64_t>(space_to_depth->get_block_size());auto block_shape =- ov::op::v0::Constant::create(element::i64, Shape{4}, std::vector<int64_t>{1, 1, block_size, block_size});- auto space_to_batch = register_new_node<ov::op::v1::SpaceToBatch>(pattern_map.at(data_pattern),- block_shape,- pads_begin,- pads_end);+ v0::Constant::create(element::i64, Shape{4}, std::vector<int64_t>{1, 1, block_size, block_size});+ auto space_to_batch =+ register_new_node<v1::SpaceToBatch>(pattern_map.at(data_pattern), block_shape, pads_begin, pads_end);space_to_batch->set_friendly_name(reshape_or_trans_after->get_friendly_name());copy_runtime_info(@@ -139,6 +138,6 @@ ov::pass::SpaceToBatchFusion::SpaceToBatchFusion() {return true;};- auto m = std::make_shared<pattern::Matcher>(reshape_or_transpose_after_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(reshape_or_transpose_after_pattern, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.cppindex 61725d05097..12bb002fb08 100644--- a/src/common/transformations/src/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/split_concat_pair_to_interpolate_fusion.cpp@@ -31,6 +31,11 @@using namespace ov;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;namespace {// This function creates a partition of its argument into groups consisting of adjacent identical elements.// Argument: std::vector<uint64_t> v@@ -56,8 +61,7 @@ std::vector<std::vector<uint64_t>> grouped_vector(const std::vector<uint64_t>& vreturn result;}-std::pair<std::shared_ptr<ov::op::v1::Split>, uint64_t> get_split_before_concat(- const std::shared_ptr<ov::op::v0::Concat>& concat) {+std::pair<std::shared_ptr<v1::Split>, uint64_t> get_split_before_concat(const std::shared_ptr<v0::Concat>& concat) {// This function gets producers of the 'concat' node, checks that the following conditions are fulfilled:// 1) all producers for 'concat' are Split nodes;// 2) 'concat' has only one unique producer ('split');@@ -69,10 +73,10 @@ std::pair<std::shared_ptr<ov::op::v1::Split>, uint64_t> get_split_before_concat(// these conditions is false, this functions returns nullptr.std::vector<uint64_t> idx;- std::shared_ptr<ov::op::v1::Split> split;+ std::shared_ptr<v1::Split> split;for (const auto& input : concat->input_values()) {// If 'concat' has some non-Split producer, then the transformation is not applicable.- auto split_op = ov::as_type_ptr<ov::op::v1::Split>(input.get_node_shared_ptr());+ auto split_op = ov::as_type_ptr<v1::Split>(input.get_node_shared_ptr());if (!split)split = split_op;if (!split_op || split != split_op)@@ -151,14 +155,14 @@ ov::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFusion// by number of output ports of 'split'.//// Detect only concat, because we don't know how many inputs will go into concat.- auto concat_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Concat>();- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {- auto concat = ov::as_type_ptr<ov::op::v0::Concat>(m.get_match_root());+ auto concat_pattern = ov::pass::pattern::wrap_type<v0::Concat>();+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto concat = ov::as_type_ptr<v0::Concat>(m.get_match_root());if (!concat)return false;uint64_t scale_factor;- std::shared_ptr<ov::op::v1::Split> split;+ std::shared_ptr<v1::Split> split;std::tie(split, scale_factor) = get_split_before_concat(concat);// If scale_factor == 1, then output data of Interpolate are equal to input data. Hence, we should not replace// Split->Concat pair with Interpolate.@@ -174,7 +178,7 @@ ov::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFusionif (split_input_rank != 4 && split_input_rank != 5)return false;- auto split_axis_const = ov::as_type_ptr<ov::op::v0::Constant>(split->input_value(1).get_node_shared_ptr());+ auto split_axis_const = ov::as_type_ptr<v0::Constant>(split->input_value(1).get_node_shared_ptr());if (!split_axis_const)return false;@@ -184,33 +188,33 @@ ov::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFusionsplit->get_input_partial_shape(0)[axis].get_length() != static_cast<int64_t>(split->outputs().size()))return false;- ov::op::v4::Interpolate::InterpolateAttrs attrs;+ v4::Interpolate::InterpolateAttrs attrs;- attrs.mode = ov::op::v4::Interpolate::InterpolateMode::NEAREST;- attrs.shape_calculation_mode = ov::op::v4::Interpolate::ShapeCalcMode::SCALES;- attrs.nearest_mode = ov::op::v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR;+ attrs.mode = v4::Interpolate::InterpolateMode::NEAREST;+ attrs.shape_calculation_mode = v4::Interpolate::ShapeCalcMode::SCALES;+ attrs.nearest_mode = v4::Interpolate::NearestMode::ROUND_PREFER_FLOOR;attrs.pads_begin = std::vector<size_t>{0};attrs.pads_end = std::vector<size_t>{0};attrs.antialias = false;- attrs.coordinate_transformation_mode = ov::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL;+ attrs.coordinate_transformation_mode = v4::Interpolate::CoordinateTransformMode::HALF_PIXEL;attrs.cube_coeff = -0.75f;auto scales_node =- ov::op::v0::Constant::create(element::f32, {1}, std::vector<float>{static_cast<float>(scale_factor)});- auto axis_node = ov::op::v0::Constant::create(element::i64, {1}, std::vector<int64_t>{axis});+ v0::Constant::create(element::f32, {1}, std::vector<float>{static_cast<float>(scale_factor)});+ auto axis_node = v0::Constant::create(element::i64, {1}, std::vector<int64_t>{axis});auto shape_node = std::make_shared<ov::op::v3::ShapeOf>(split->input_value(0));- auto sslice_begin = ov::op::v0::Constant::create(element::i64, {1}, std::vector<int64_t>{axis});- auto sslice_end = ov::op::v0::Constant::create(element::i64, {1}, std::vector<int64_t>{axis + 1});+ auto sslice_begin = v0::Constant::create(element::i64, {1}, std::vector<int64_t>{axis});+ auto sslice_end = v0::Constant::create(element::i64, {1}, std::vector<int64_t>{axis + 1});std::vector<int64_t> begin_mask = {0};std::vector<int64_t> end_mask = {0};auto strided_slice_node =- std::make_shared<ov::op::v1::StridedSlice>(shape_node, sslice_begin, sslice_end, begin_mask, end_mask);+ std::make_shared<v1::StridedSlice>(shape_node, sslice_begin, sslice_end, begin_mask, end_mask);- auto cast_shape_to_float = std::make_shared<ov::op::v0::Convert>(strided_slice_node, element::f32);- auto mul_node = std::make_shared<ov::op::v1::Multiply>(cast_shape_to_float, scales_node);- auto floor_node = std::make_shared<ov::op::v0::Floor>(mul_node);- auto cast_mul_result_to_int = std::make_shared<ov::op::v0::Convert>(floor_node, element::i64);+ auto cast_shape_to_float = std::make_shared<v0::Convert>(strided_slice_node, element::f32);+ auto mul_node = std::make_shared<v1::Multiply>(cast_shape_to_float, scales_node);+ auto floor_node = std::make_shared<v0::Floor>(mul_node);+ auto cast_mul_result_to_int = std::make_shared<v0::Convert>(floor_node, element::i64);std::shared_ptr<Node> sizes_node;@@ -223,11 +227,8 @@ ov::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFusionif (!sizes_node)sizes_node = cast_mul_result_to_int;- auto interpolate = register_new_node<ov::op::v4::Interpolate>(split->input_value(0),- sizes_node,- scales_node,- axis_node,- attrs);+ auto interpolate =+ register_new_node<v4::Interpolate>(split->input_value(0), sizes_node, scales_node, axis_node, attrs);interpolate->set_friendly_name(concat->get_friendly_name());copy_runtime_info({split, concat},@@ -247,6 +248,6 @@ ov::pass::SplitConcatPairToInterpolateFusion::SplitConcatPairToInterpolateFusionreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(concat_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(concat_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/split_squeeze_concat_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/split_squeeze_concat_fusion.cppindex e87de81485c..8fa151f70ed 100644--- a/src/common/transformations/src/transformations/common_optimizations/split_squeeze_concat_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/split_squeeze_concat_fusion.cpp@@ -20,36 +20,40 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;static bool is_axis_squeezed_by_node(const std::shared_ptr<ov::Node>& squeeze_node, int64_t axis, bool use_shapes);ov::pass::SplitSqueezeConcatFusion::SplitSqueezeConcatFusion(bool use_shapes) {MATCHER_SCOPE(SplitSqueezeConcatFusion);// Detect only concat, because we don't know how many inputs will go into concat- auto concat_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Concat>();+ auto concat_pattern = ov::pass::pattern::wrap_type<v0::Concat>();- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();- auto concat = ov::as_type_ptr<ov::op::v0::Concat>(pattern_to_output.at(concat_pattern).get_node_shared_ptr());+ auto concat = ov::as_type_ptr<v0::Concat>(pattern_to_output.at(concat_pattern).get_node_shared_ptr());if (!concat)return false;NodeVector nodes_to_delete{concat};- std::shared_ptr<ov::op::v1::Split> split;+ std::shared_ptr<v1::Split> split;int64_t split_axis = 0;for (size_t i = 0; i < concat->get_input_size(); i++) {auto squeeze_node = concat->get_input_node_shared_ptr(i);- if (!ov::is_type<ov::op::v0::Squeeze>(squeeze_node) && !ov::is_type<ov::op::v1::Reshape>(squeeze_node))+ if (!ov::is_type<v0::Squeeze>(squeeze_node) && !ov::is_type<v1::Reshape>(squeeze_node))return false;- auto split_to_check = ov::as_type_ptr<ov::op::v1::Split>(squeeze_node->get_input_node_shared_ptr(0));+ auto split_to_check = ov::as_type_ptr<v1::Split>(squeeze_node->get_input_node_shared_ptr(0));if (!split_to_check)return false;if (i == 0) {nodes_to_delete.push_back(split_to_check);split = split_to_check;- auto split_axis_node = ov::as_type_ptr<ov::op::v0::Constant>(split->get_input_node_shared_ptr(1));+ auto split_axis_node = ov::as_type_ptr<v0::Constant>(split->get_input_node_shared_ptr(1));if (!split_axis_node)return false;auto axis_vec = split_axis_node->cast_vector<int64_t>();@@ -91,11 +95,11 @@ ov::pass::SplitSqueezeConcatFusion::SplitSqueezeConcatFusion(bool use_shapes) {order.erase(order.begin() + split_axis);order.insert(order.begin() + concat_axis, split_axis);- auto transpose_order = ov::op::v0::Constant::create(element::i64, {(size_t)rank.get_length()}, order);- auto transpose = register_new_node<ov::op::v1::Transpose>(input, transpose_order);+ auto transpose_order = v0::Constant::create(element::i64, {(size_t)rank.get_length()}, order);+ auto transpose = register_new_node<v1::Transpose>(input, transpose_order);auto shape_after =- ov::op::v0::Constant::create(element::i64, {(size_t)rank.get_length() - 1}, concat->get_output_shape(0));- auto reshape = std::make_shared<ov::op::v1::Reshape>(transpose, shape_after, false);+ v0::Constant::create(element::i64, {(size_t)rank.get_length() - 1}, concat->get_output_shape(0));+ auto reshape = std::make_shared<v1::Reshape>(transpose, shape_after, false);reshape->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info(nodes_to_delete, {transpose, reshape});@@ -103,7 +107,7 @@ ov::pass::SplitSqueezeConcatFusion::SplitSqueezeConcatFusion(bool use_shapes) {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(concat_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(concat_pattern, matcher_name);register_matcher(m, callback);}@@ -124,7 +128,7 @@ bool is_axis_squeezed_by_node(const std::shared_ptr<ov::Node>& squeeze_node, intif (input_shape[axis].is_dynamic() || input_shape[axis] != 1)return false;- if (ov::is_type<ov::op::v1::Reshape>(squeeze_node)) {+ if (ov::is_type<v1::Reshape>(squeeze_node)) {if (!use_shapes)return false;// clang-format off@@ -156,7 +160,7 @@ bool is_axis_squeezed_by_node(const std::shared_ptr<ov::Node>& squeeze_node, int}} else {// The second Squeeze input has explicit axes- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(squeeze_node->get_input_node_shared_ptr(1));+ auto constant = ov::as_type_ptr<v0::Constant>(squeeze_node->get_input_node_shared_ptr(1));if (!constant)return false;if (ov::shape_size(constant->get_shape()) != 1)diff --git a/src/common/transformations/src/transformations/common_optimizations/strides_optimization.cpp b/src/common/transformations/src/transformations/common_optimizations/strides_optimization.cppindex 169ee6b0a80..152022ed7ea 100644--- a/src/common/transformations/src/transformations/common_optimizations/strides_optimization.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/strides_optimization.cpp@@ -24,6 +24,13 @@using namespace std;using namespace ov;+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;static bool can_propagate_conv_stride(const std::shared_ptr<ov::Node>& conv) {const auto& kernel_shape = conv->input_value(1).get_shape();return std::all_of(kernel_shape.begin() + 2, kernel_shape.end(), [](size_t s) -> bool {@@ -55,24 +62,22 @@ static void insert_pooling(const Output<Node>& first, Input<Node>& second, constconst bool do_reshape = rank.is_static() && static_cast<size_t>(rank.get_length()) < strides.size() + 2;if (do_reshape) {const size_t diff = strides.size() + 2 - static_cast<size_t>(rank.get_length());- const auto ones = rg.make<ov::op::v0::Constant>(element::i64, Shape{diff}, vector<int64_t>(diff, 1));+ const auto ones = rg.make<v0::Constant>(element::i64, Shape{diff}, vector<int64_t>(diff, 1));const auto current_shape = rg.make<ov::op::v3::ShapeOf>(first);- shared_ptr<Node> new_shape = rg.make<ov::op::v0::Concat>(OutputVector{ones, current_shape}, 0);+ shared_ptr<Node> new_shape = rg.make<v0::Concat>(OutputVector{ones, current_shape}, 0);if (const auto constant_new_shape = ov::util::get_constant_from_source(new_shape)) {rg.add(constant_new_shape);new_shape = constant_new_shape;}- first_node = rg.make<ov::op::v1::Reshape>(first_node, new_shape, false);+ first_node = rg.make<v1::Reshape>(first_node, new_shape, false);}- shared_ptr<Node> new_node =- rg.make<ov::op::v1::MaxPool>(first_node, strides, Shape{}, Shape{}, Shape(strides.size(), 1));+ shared_ptr<Node> new_node = rg.make<v1::MaxPool>(first_node, strides, Shape{}, Shape{}, Shape(strides.size(), 1));if (do_reshape) {// squeeze dimensions backconst size_t diff = strides.size() + 2 - static_cast<size_t>(rank.get_length());vector<size_t> axes(diff);iota(axes.begin(), axes.end(), 0);- new_node =- rg.make<ov::op::v0::Squeeze>(new_node, rg.make<ov::op::v0::Constant>(element::u64, Shape{diff}, axes));+ new_node = rg.make<v0::Squeeze>(new_node, rg.make<v0::Constant>(element::u64, Shape{diff}, axes));}if (const auto constant_new_node = ov::util::get_constant_from_source(new_node)) {rg.add(constant_new_node);@@ -92,7 +97,7 @@ static void handle_not_equal_stride_props(std::vector<ov::Input<ov::Node>>& nextreturn s == 1;});if (!are_strides_ones) {- auto conv = ov::as_type<ov::op::v1::Convolution>(op.get_node());+ auto conv = ov::as_type<v1::Convolution>(op.get_node());if (conv) {conv->set_strides(strides);} else {@@ -110,7 +115,7 @@ static void remove_strides_property_from_nodes(std::vector<ov::Input<ov::Node>>&ov::pass::ConvStridesPropagation::ConvStridesPropagation() {MATCHER_SCOPE(ConvStridesPropagation);- auto data = pattern::any_input([](const Output<Node>& node) -> bool {+ auto data = any_input([](const Output<Node>& node) -> bool {const auto& shape = node.get_partial_shape();const auto& rank = shape.rank();if (rank.is_dynamic())@@ -119,17 +124,17 @@ ov::pass::ConvStridesPropagation::ConvStridesPropagation() {return dim.is_static();});});- auto weights = pattern::any_input(pattern::has_static_shape());- auto conv_pattern = pattern::wrap_type<ov::op::v1::Convolution>({data, weights});+ auto weights = any_input(ov::pass::pattern::has_static_shape());+ auto conv_pattern = wrap_type<v1::Convolution>({data, weights});- ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto conv = ov::as_type_ptr<ov::op::v1::Convolution>(m.get_match_root());+ ov::matcher_pass_callback callback = [=](Matcher& m) {+ auto conv = ov::as_type_ptr<v1::Convolution>(m.get_match_root());if (!conv)return false;auto conv_strides = conv->get_strides();Strides strides_ones(conv_strides.size(), 1);- auto next_ops = ov::op::util::get_node_target_inputs(conv);+ auto next_ops = op_util::get_node_target_inputs(conv);bool all_ops_are_valid;Strides strides;std::tie(strides, all_ops_are_valid) = check_next_ops(next_ops);@@ -165,18 +170,17 @@ ov::pass::ConvStridesPropagation::ConvStridesPropagation() {return true;};- auto m = std::make_shared<pattern::Matcher>(conv_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(conv_pattern, matcher_name);this->register_matcher(m, callback);}ov::pass::SupportedNodesStridesPropagation::SupportedNodesStridesPropagation() {MATCHER_SCOPE(SupportedNodesStridesPropagation);- auto root =- pattern::wrap_type<ov::op::util::UnaryElementwiseArithmetic, ov::op::util::BinaryElementwiseArithmetic>();+ auto root = wrap_type<op_util::UnaryElementwiseArithmetic, op_util::BinaryElementwiseArithmetic>();- ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {auto node = m.get_match_root();- auto next_ops = ov::op::util::get_node_target_inputs(node);+ auto next_ops = op_util::get_node_target_inputs(node);bool all_ops_are_valid;Strides strides;std::tie(strides, all_ops_are_valid) = check_next_ops(next_ops);@@ -194,24 +198,24 @@ ov::pass::SupportedNodesStridesPropagation::SupportedNodesStridesPropagation() {return true;};- auto m = std::make_shared<pattern::Matcher>(root, matcher_name);+ auto m = std::make_shared<Matcher>(root, matcher_name);this->register_matcher(m, callback);}ov::pass::UnsupportedNodesStridesPropagation::UnsupportedNodesStridesPropagation() {MATCHER_SCOPE(UnsupportedNodesStridesPropagation);- auto root = pattern::any_input();+ auto root = any_input();- ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {auto node = m.get_match_root();- auto next_ops = ov::op::util::get_node_target_inputs(node);+ auto next_ops = op_util::get_node_target_inputs(node);handle_not_equal_stride_props(next_ops);remove_strides_property_from_nodes(next_ops);return true;};- auto m = std::make_shared<pattern::Matcher>(root, matcher_name);+ auto m = std::make_shared<Matcher>(root, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/subtract_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/subtract_fusion.cppindex 90010429fcb..3a65bcb9d97 100644--- a/src/common/transformations/src/transformations/common_optimizations/subtract_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/subtract_fusion.cpp@@ -18,19 +18,24 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::SubtractFusion::SubtractFusion() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++SubtractFusion::SubtractFusion() {MATCHER_SCOPE(SubtractFusion);auto p_input = pattern::any_input();- auto p_mul_const = pattern::wrap_type<ov::op::v0::Constant>();- auto p_mul = pattern::wrap_type<ov::op::v1::Multiply>({p_input, p_mul_const});+ auto p_mul_const = pattern::wrap_type<v0::Constant>();+ auto p_mul = pattern::wrap_type<v1::Multiply>({p_input, p_mul_const});- auto p_neg = pattern::wrap_type<ov::op::v0::Negative>({p_input});+ auto p_neg = pattern::wrap_type<v0::Negative>({p_input});auto p_mul_or_neg = std::make_shared<pattern::op::Or>(OutputVector({p_mul, p_neg}));auto p_add_input = pattern::any_input();- auto p_add = ov::pass::pattern::wrap_type<ov::op::v1::Add>({p_add_input, p_mul_or_neg});+ auto p_add = pattern::wrap_type<v1::Add>({p_add_input, p_mul_or_neg});matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();@@ -43,7 +48,7 @@ ov::pass::SubtractFusion::SubtractFusion() {if (pattern_to_output.count(p_mul_const)) {auto minus_one_const =- ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(p_mul_const).get_node_shared_ptr());+ ov::as_type_ptr<v0::Constant>(pattern_to_output.at(p_mul_const).get_node_shared_ptr());if (!ov::op::util::has_constant_value<float>(minus_one_const, -1.)) {return false;}@@ -52,13 +57,15 @@ ov::pass::SubtractFusion::SubtractFusion() {nodes_to_replace.emplace_back(pattern_to_output.at(p_neg).get_node_shared_ptr());}- auto sub = register_new_node<ov::op::v1::Subtract>(minuend_input, subtrahend_input);+ auto sub = register_new_node<v1::Subtract>(minuend_input, subtrahend_input);sub->set_friendly_name(add->get_friendly_name());copy_runtime_info(nodes_to_replace, sub);replace_node(add, sub);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(p_add, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(p_add, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/swish_fusion.cpp b/src/common/transformations/src/transformations/common_optimizations/swish_fusion.cppindex 5fa7c6c6dab..5569786e97a 100644--- a/src/common/transformations/src/transformations/common_optimizations/swish_fusion.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/swish_fusion.cpp@@ -20,9 +20,17 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;+namespace op_util = ov::op::util;namespace {-bool check_beta_value(const std::shared_ptr<ov::op::v0::Constant>& constant) {+bool check_beta_value(const std::shared_ptr<v0::Constant>& constant) {// check that the constant for beta contains only one distinct elementif (!constant) {return false;@@ -43,15 +51,15 @@ bool check_beta_value(const std::shared_ptr<ov::op::v0::Constant>& constant) {ov::pass::SwishFusionWithSigmoid::SwishFusionWithSigmoid() {MATCHER_SCOPE(SwishFusionWithSigmoid);// replaces a sub-graphs x * Sigmoid(x) with a Swish op.- auto input = pass::pattern::any_input();- auto sigmoid = std::make_shared<ov::op::v0::Sigmoid>(input);- auto mul = std::make_shared<ov::op::v1::Multiply>(input, sigmoid);+ auto input = any_input();+ auto sigmoid = std::make_shared<v0::Sigmoid>(input);+ auto mul = std::make_shared<v1::Multiply>(input, sigmoid);- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto exp_input = pattern_to_output.at(input);- auto swish = std::make_shared<ov::op::v4::Swish>(exp_input);+ auto swish = std::make_shared<v4::Swish>(exp_input);swish->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info(@@ -61,31 +69,31 @@ ov::pass::SwishFusionWithSigmoid::SwishFusionWithSigmoid() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul, matcher_name);+ auto m = std::make_shared<Matcher>(mul, matcher_name);register_matcher(m, callback);}ov::pass::SwishFusionWithSigmoidWithBeta::SwishFusionWithSigmoidWithBeta() {MATCHER_SCOPE(SwishFusionWithSigmoidWithBeta);// replaces a sub-graphs x * Sigmoid(x * beta) with a Swish op.- auto input = pass::pattern::any_input();- auto beta = pass::pattern::any_input();- auto mul_beta = std::make_shared<ov::op::v1::Multiply>(input, beta);- auto sigmoid = std::make_shared<ov::op::v0::Sigmoid>(mul_beta);- auto mul = std::make_shared<ov::op::v1::Multiply>(input, sigmoid);+ auto input = any_input();+ auto beta = any_input();+ auto mul_beta = std::make_shared<v1::Multiply>(input, beta);+ auto sigmoid = std::make_shared<v0::Sigmoid>(mul_beta);+ auto mul = std::make_shared<v1::Multiply>(input, sigmoid);- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto exp_input = pattern_to_output.at(input);auto beta_input = pattern_to_output.at(beta);- auto beta_constant = ov::as_type_ptr<ov::op::v0::Constant>(beta_input.get_node_shared_ptr());+ auto beta_constant = ov::as_type_ptr<v0::Constant>(beta_input.get_node_shared_ptr());Output<Node> new_beta;if (beta_constant) {if (check_beta_value(beta_constant)) {- new_beta = ov::op::v0::Constant::create(beta_input.get_element_type(),- Shape{},- {beta_constant->cast_vector<float>()[0]});+ new_beta = v0::Constant::create(beta_input.get_element_type(),+ Shape{},+ {beta_constant->cast_vector<float>()[0]});} else {return false;}@@ -97,7 +105,7 @@ ov::pass::SwishFusionWithSigmoidWithBeta::SwishFusionWithSigmoidWithBeta() {new_beta = beta_input;}- auto swish = std::make_shared<ov::op::v4::Swish>(exp_input, new_beta);+ auto swish = std::make_shared<v4::Swish>(exp_input, new_beta);swish->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info(@@ -107,32 +115,32 @@ ov::pass::SwishFusionWithSigmoidWithBeta::SwishFusionWithSigmoidWithBeta() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul, matcher_name);+ auto m = std::make_shared<Matcher>(mul, matcher_name);register_matcher(m, callback);}ov::pass::SwishFusionWithBeta::SwishFusionWithBeta() {MATCHER_SCOPE(SwishFusionWithBeta);// replaces a sub-graphs x / (1.0 + exp(-x * beta)) with a Swish op.- auto input = pass::pattern::any_input();- auto beta = pass::pattern::any_input();- auto mul = std::make_shared<ov::op::v1::Multiply>(input, beta);- auto neg = std::make_shared<ov::op::v0::Negative>(mul);- auto exp = std::make_shared<ov::op::v0::Exp>(neg);- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add = std::make_shared<ov::op::v1::Add>(exp, add_constant);- auto div = std::make_shared<ov::op::v1::Divide>(input, add);-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto input = any_input();+ auto beta = any_input();+ auto mul = std::make_shared<v1::Multiply>(input, beta);+ auto neg = std::make_shared<v0::Negative>(mul);+ auto exp = std::make_shared<v0::Exp>(neg);+ auto add_constant = wrap_type<v0::Constant>();+ auto add = std::make_shared<v1::Add>(exp, add_constant);+ auto div = std::make_shared<v1::Divide>(input, add);++ ov::matcher_pass_callback callback = [=](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto exp_input = pattern_to_output.at(input);- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- if (!ov::op::util::has_constant_value<float>(constant, 1.0f)) {+ auto constant = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ if (!op_util::has_constant_value<float>(constant, 1.0f)) {return false;}- auto swish = std::make_shared<ov::op::v4::Swish>(exp_input, pattern_to_output.at(beta));+ auto swish = std::make_shared<v4::Swish>(exp_input, pattern_to_output.at(beta));swish->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({pattern_to_output.at(beta).get_node_shared_ptr(),@@ -147,30 +155,30 @@ ov::pass::SwishFusionWithBeta::SwishFusionWithBeta() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(div, matcher_name);+ auto m = std::make_shared<Matcher>(div, matcher_name);register_matcher(m, callback);}ov::pass::SwishFusionWithoutBeta::SwishFusionWithoutBeta() {MATCHER_SCOPE(SwishFusionWithoutBeta);// replaces a sub-graphs x / (1.0 + exp(-x)) with a Swish op.- auto input = pass::pattern::any_input();- auto neg = std::make_shared<ov::op::v0::Negative>(input);- auto exp = std::make_shared<ov::op::v0::Exp>(neg);- auto add_constant = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto add = std::make_shared<ov::op::v1::Add>(exp, add_constant);- auto div = std::make_shared<ov::op::v1::Divide>(input, add);-- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ auto input = any_input();+ auto neg = std::make_shared<v0::Negative>(input);+ auto exp = std::make_shared<v0::Exp>(neg);+ auto add_constant = wrap_type<v0::Constant>();+ auto add = std::make_shared<v1::Add>(exp, add_constant);+ auto div = std::make_shared<v1::Divide>(input, add);++ ov::matcher_pass_callback callback = [=](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto exp_input = pattern_to_output.at(input);- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());- if (!ov::op::util::has_constant_value<float>(constant, 1.0f)) {+ auto constant = ov::as_type_ptr<v0::Constant>(pattern_to_output.at(add_constant).get_node_shared_ptr());+ if (!op_util::has_constant_value<float>(constant, 1.0f)) {return false;}- auto swish = std::make_shared<ov::op::v4::Swish>(exp_input);+ auto swish = std::make_shared<v4::Swish>(exp_input);swish->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({pattern_to_output.at(neg).get_node_shared_ptr(),@@ -183,6 +191,6 @@ ov::pass::SwishFusionWithoutBeta::SwishFusionWithoutBeta() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(div, matcher_name);+ auto m = std::make_shared<Matcher>(div, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.cpp b/src/common/transformations/src/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.cppindex 2acbeb75ba4..41e1abd7a62 100644--- a/src/common/transformations/src/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/transpose_reshape_elimination_for_matmul.cpp@@ -18,6 +18,13 @@#include "openvino/pass/pattern/op/or.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;namespace {/// \brief Check for correct Transpose orders which are before and after MatMul. Second Transpose must be back for/// first Transpose before MatMul@@ -87,7 +94,7 @@ bool check_transposes(const std::vector<int64_t>& before_order,/// \return True - Reshape has right new shape for reshaping, otherwise, Reshape has incorrect new shape for/// transformation///-bool check_input_reshape(const std::shared_ptr<ov::op::v1::Reshape>& reshape,+bool check_input_reshape(const std::shared_ptr<v1::Reshape>& reshape,const std::vector<int64_t>& new_shape,const bool transposed_b) {const auto input_shape = reshape->get_input_shape(0);@@ -114,74 +121,69 @@ bool check_input_reshape(const std::shared_ptr<ov::op::v1::Reshape>& reshape,ov::pass::TransposeReshapeEliminationForMatmul::TransposeReshapeEliminationForMatmul() {MATCHER_SCOPE(TransposeReshapeEliminationForMatmul);- auto input_1_pattern = pass::pattern::any_input([](const Output<Node>& node) -> bool {+ auto input_1_pattern = any_input([](const Output<Node>& node) -> bool {const auto& shape = node.get_partial_shape();const auto& rank = shape.rank();return rank.is_static() && rank.get_length() == 2 && shape.is_static();});- auto input_2_pattern = pass::pattern::any_input([](const Output<Node>& node) -> bool {+ auto input_2_pattern = any_input([](const Output<Node>& node) -> bool {return node.get_partial_shape().is_static();});- auto const_transpose_before_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto transpose_before_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Transpose>({input_2_pattern, const_transpose_before_pattern});+ auto const_transpose_before_pattern = wrap_type<v0::Constant>();+ auto transpose_before_pattern = wrap_type<v1::Transpose>({input_2_pattern, const_transpose_before_pattern});- auto const_optional_broadcast_before_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto optional_broadcast_before_pattern = ov::pass::pattern::wrap_type<ov::op::v3::Broadcast>(- {transpose_before_pattern, const_optional_broadcast_before_pattern});+ auto const_optional_broadcast_before_pattern = wrap_type<v0::Constant>();+ auto optional_broadcast_before_pattern =+ wrap_type<v3::Broadcast>({transpose_before_pattern, const_optional_broadcast_before_pattern});auto transpose_or_transpose_broadcast = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{transpose_before_pattern, optional_broadcast_before_pattern});- auto const_reshape_before_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto reshape_before_pattern = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>(- {transpose_or_transpose_broadcast, const_reshape_before_pattern});+ auto const_reshape_before_pattern = wrap_type<v0::Constant>();+ auto reshape_before_pattern =+ wrap_type<v1::Reshape>({transpose_or_transpose_broadcast, const_reshape_before_pattern});- auto matmul_pattern = ov::pass::pattern::wrap_type<ov::op::v0::MatMul>({input_1_pattern, reshape_before_pattern});+ auto matmul_pattern = wrap_type<v0::MatMul>({input_1_pattern, reshape_before_pattern});- auto const_reshape_after_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto reshape_after_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({matmul_pattern, const_reshape_after_pattern});+ auto const_reshape_after_pattern = wrap_type<v0::Constant>();+ auto reshape_after_pattern = wrap_type<v1::Reshape>({matmul_pattern, const_reshape_after_pattern});- auto const_transpose_after_pattern = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto transpose_after_pattern =- ov::pass::pattern::wrap_type<ov::op::v1::Transpose>({reshape_after_pattern, const_transpose_after_pattern});+ auto const_transpose_after_pattern = wrap_type<v0::Constant>();+ auto transpose_after_pattern = wrap_type<v1::Transpose>({reshape_after_pattern, const_transpose_after_pattern});- ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {const auto& pattern_value_map = m.get_pattern_value_map();const auto& input_1 = pattern_value_map.at(input_1_pattern);const auto& input_2 = pattern_value_map.at(input_2_pattern);- auto matmul = ov::as_type_ptr<ov::op::v0::MatMul>(pattern_value_map.at(matmul_pattern).get_node_shared_ptr());+ auto matmul = ov::as_type_ptr<v0::MatMul>(pattern_value_map.at(matmul_pattern).get_node_shared_ptr());if (!matmul)return false;const bool transposed_a = matmul->get_transpose_a();const bool transposed_b = matmul->get_transpose_b();auto reshape_before =- ov::as_type_ptr<ov::op::v1::Reshape>(pattern_value_map.at(reshape_before_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v1::Reshape>(pattern_value_map.at(reshape_before_pattern).get_node_shared_ptr());auto reshape_after =- ov::as_type_ptr<ov::op::v1::Reshape>(pattern_value_map.at(reshape_after_pattern).get_node_shared_ptr());- auto reshape_before_constant = ov::as_type_ptr<ov::op::v0::Constant>(- pattern_value_map.at(const_reshape_before_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v1::Reshape>(pattern_value_map.at(reshape_after_pattern).get_node_shared_ptr());+ auto reshape_before_constant =+ ov::as_type_ptr<v0::Constant>(pattern_value_map.at(const_reshape_before_pattern).get_node_shared_ptr());if (!reshape_before || !reshape_after || !reshape_before_constant)return false;if (!check_input_reshape(reshape_before, reshape_before_constant->cast_vector<int64_t>(), transposed_b))return false;// check transpose order before and after matmul- auto transpose_before = ov::as_type_ptr<ov::op::v1::Transpose>(- pattern_value_map.at(transpose_before_pattern).get_node_shared_ptr());+ auto transpose_before =+ ov::as_type_ptr<v1::Transpose>(pattern_value_map.at(transpose_before_pattern).get_node_shared_ptr());auto transpose_after =- ov::as_type_ptr<ov::op::v1::Transpose>(pattern_value_map.at(transpose_after_pattern).get_node_shared_ptr());+ ov::as_type_ptr<v1::Transpose>(pattern_value_map.at(transpose_after_pattern).get_node_shared_ptr());if (!transpose_before || !transpose_after)return false;- auto transpose_before_constant =- ov::as_type_ptr<ov::op::v0::Constant>(transpose_before->get_input_node_shared_ptr(1));- auto transpose_after_constant =- ov::as_type_ptr<ov::op::v0::Constant>(transpose_after->get_input_node_shared_ptr(1));+ auto transpose_before_constant = ov::as_type_ptr<v0::Constant>(transpose_before->get_input_node_shared_ptr(1));+ auto transpose_after_constant = ov::as_type_ptr<v0::Constant>(transpose_after->get_input_node_shared_ptr(1));if (!transpose_before_constant || !transpose_after_constant)return false;@@ -194,13 +196,13 @@ ov::pass::TransposeReshapeEliminationForMatmul::TransposeReshapeEliminationForMaauto matmul_2_input = input_2;// for einsum decomposition, check if broadcast exist and if so, reorder target shape based on transposeif (pattern_value_map.count(optional_broadcast_before_pattern)) {- auto broadcast_before = ov::as_type_ptr<ov::op::v3::Broadcast>(+ auto broadcast_before = ov::as_type_ptr<v3::Broadcast>(pattern_value_map.at(optional_broadcast_before_pattern).get_node_shared_ptr());if (!broadcast_before) {return false;}auto broadcast_before_constant =- ov::as_type_ptr<ov::op::v0::Constant>(broadcast_before->get_input_node_shared_ptr(1));+ ov::as_type_ptr<v0::Constant>(broadcast_before->get_input_node_shared_ptr(1));if (!broadcast_before_constant) {return false;}@@ -213,21 +215,20 @@ ov::pass::TransposeReshapeEliminationForMatmul::TransposeReshapeEliminationForMafor (auto idx : transpose_before_order) {broadcast_shape_no_transpose.push_back(broadcast_shape_after_transpose[idx]);}- auto broadcast_shape_no_transpose_constant =- ov::op::v0::Constant::create(element::i64,- broadcast_before_constant->get_shape(),- broadcast_shape_no_transpose);+ auto broadcast_shape_no_transpose_constant = v0::Constant::create(element::i64,+ broadcast_before_constant->get_shape(),+ broadcast_shape_no_transpose);matmul_2_input = broadcast_before->clone_with_new_inputs({input_2, broadcast_shape_no_transpose_constant});copy_runtime_info(broadcast_before, matmul_2_input.get_node_shared_ptr());}- const auto new_matmul = std::make_shared<ov::op::v0::MatMul>(input_1, matmul_2_input, transposed_a, false);+ const auto new_matmul = std::make_shared<v0::MatMul>(input_1, matmul_2_input, transposed_a, false);new_matmul->set_friendly_name(transpose_after->get_friendly_name());copy_runtime_info({transpose_before, reshape_before, matmul, reshape_after, transpose_after}, new_matmul);replace_node(transpose_after, new_matmul);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(transpose_after_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(transpose_after_pattern, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cpp b/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cppindex 82eab54fb5e..a883ba12759 100644--- a/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/transpose_sinking.cpp@@ -27,11 +27,18 @@using namespace ov;+using ov::pass::pattern::any_input;+using ov::pass::pattern::consumers_count;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;namespace {-std::shared_ptr<ov::op::v0::Constant> get_reduced_order_constant(- const std::shared_ptr<ov::op::v0::Constant>& axes_const,- const std::shared_ptr<ov::op::v0::Constant>& order_const) {+std::shared_ptr<v0::Constant> get_reduced_order_constant(const std::shared_ptr<v0::Constant>& axes_const,+ const std::shared_ptr<v0::Constant>& order_const) {auto order = order_const->cast_vector<int64_t>();auto axes = axes_const->cast_vector<int64_t>();@@ -54,11 +61,10 @@ std::shared_ptr<ov::op::v0::Constant> get_reduced_order_constant(std::replace(order.begin(), order.end(), *lowest_greater_eq_i, i);std::replace(order_sorted.begin(), order_sorted.end(), *lowest_greater_eq_i, i);}- return std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{order.size()}, order);+ return std::make_shared<v0::Constant>(ov::element::i64, ov::Shape{order.size()}, order);}-std::shared_ptr<ov::op::v0::Constant> get_reversed_order_constant(- const std::shared_ptr<ov::op::v0::Constant>& order_const) {+std::shared_ptr<v0::Constant> get_reversed_order_constant(const std::shared_ptr<v0::Constant>& order_const) {const auto& order = order_const->cast_vector<size_t>();const auto& rank = order.size();AxisVector default_order(rank);@@ -67,7 +73,7 @@ std::shared_ptr<ov::op::v0::Constant> get_reversed_order_constant(for (size_t i = 0; i < rank; ++i)reverse_order[order[i]] = default_order[i];- return std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{reverse_order.size()}, reverse_order);+ return std::make_shared<v0::Constant>(ov::element::i64, ov::Shape{reverse_order.size()}, reverse_order);}} // namespace@@ -75,18 +81,16 @@ std::shared_ptr<ov::op::v0::Constant> get_reversed_order_constant(ov::pass::TransposeEltwise::TransposeEltwise() {MATCHER_SCOPE(TransposeEltwise);- auto eltwise_data_input_p = pattern::any_input();- auto eltwise_const_input_p = pattern::wrap_type<ov::op::v0::Constant>();- auto eltwise_p = pattern::wrap_type<ov::op::util::BinaryElementwiseArithmetic>(+ auto eltwise_data_input_p = any_input();+ auto eltwise_const_input_p = wrap_type<v0::Constant>();+ auto eltwise_p = wrap_type<op_util::BinaryElementwiseArithmetic>({eltwise_data_input_p, eltwise_const_input_p},[](const Output<Node>& output) {return ov::is_preprocesing_node(output.get_node_shared_ptr());});- auto transpose_p =- pattern::wrap_type<ov::op::v1::Transpose>({eltwise_p, pattern::wrap_type<ov::op::v0::Constant>()},- pattern::consumers_count(1));+ auto transpose_p = wrap_type<v1::Transpose>({eltwise_p, wrap_type<v0::Constant>()}, consumers_count(1));- auto callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto eltwise = pattern_to_output.at(eltwise_p).get_node_shared_ptr();auto eltwise_const_input = pattern_to_output.at(eltwise_const_input_p);@@ -101,8 +105,7 @@ ov::pass::TransposeEltwise::TransposeEltwise() {}if (ov::shape_size(shape) != 1) {- eltwise_const_input =- std::make_shared<ov::op::v1::Transpose>(eltwise_const_input, transpose->input_value(1));+ eltwise_const_input = std::make_shared<v1::Transpose>(eltwise_const_input, transpose->input_value(1));if (auto const_node = ov::util::get_constant_from_source(eltwise_const_input)) {eltwise_const_input = const_node;}@@ -118,19 +121,17 @@ ov::pass::TransposeEltwise::TransposeEltwise() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(transpose_p, matcher_name);+ auto m = std::make_shared<Matcher>(transpose_p, matcher_name);register_matcher(m, callback);}ov::pass::TransposeConvert::TransposeConvert() {MATCHER_SCOPE(TransposeConvert);- auto transpose_label =- pattern::wrap_type<ov::op::v1::Transpose>({pattern::any_input(), pattern::wrap_type<ov::op::v0::Constant>()},- pattern::consumers_count(1));- auto convert_label = pattern::wrap_type<ov::op::v0::Convert>({transpose_label});+ auto transpose_label = wrap_type<v1::Transpose>({any_input(), wrap_type<v0::Constant>()}, consumers_count(1));+ auto convert_label = wrap_type<v0::Convert>({transpose_label});- matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto convert = pattern_to_output.at(convert_label).get_node_shared_ptr();@@ -145,29 +146,26 @@ ov::pass::TransposeConvert::TransposeConvert() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(convert_label, matcher_name);+ auto m = std::make_shared<Matcher>(convert_label, matcher_name);register_matcher(m, matcher_pass_callback);}ov::pass::TransposeReduction::TransposeReduction() {MATCHER_SCOPE(TransposeReduction);- auto transpose_label =- pattern::wrap_type<ov::op::v1::Transpose>({pattern::any_input(), pattern::wrap_type<ov::op::v0::Constant>()},- pattern::consumers_count(1));+ auto transpose_label = wrap_type<v1::Transpose>({any_input(), wrap_type<v0::Constant>()}, consumers_count(1));auto reduce_or_squeeze_label =- pattern::wrap_type<ov::op::util::ArithmeticReductionKeepDims,- ov::op::util::LogicalReductionKeepDims,- ov::op::v0::Squeeze>({transpose_label, pattern::wrap_type<ov::op::v0::Constant>()});+ wrap_type<op_util::ArithmeticReductionKeepDims, op_util::LogicalReductionKeepDims, v0::Squeeze>(+ {transpose_label, wrap_type<v0::Constant>()});- ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto reduction = pattern_to_output.at(reduce_or_squeeze_label).get_node_shared_ptr();- auto arithmetic_reduce = ov::as_type_ptr<ov::op::util::ArithmeticReductionKeepDims>(reduction);- auto logical_reduce = ov::as_type_ptr<ov::op::util::LogicalReductionKeepDims>(reduction);- auto squeeze = ov::as_type_ptr<ov::op::v0::Squeeze>(reduction);+ auto arithmetic_reduce = ov::as_type_ptr<op_util::ArithmeticReductionKeepDims>(reduction);+ auto logical_reduce = ov::as_type_ptr<op_util::LogicalReductionKeepDims>(reduction);+ auto squeeze = ov::as_type_ptr<v0::Squeeze>(reduction);if (!transpose || !(arithmetic_reduce || logical_reduce || squeeze))return false;@@ -177,8 +175,8 @@ ov::pass::TransposeReduction::TransposeReduction() {else if (arithmetic_reduce)keep_dims = arithmetic_reduce->get_keep_dims();- auto transpose_order = ov::as_type_ptr<ov::op::v0::Constant>(transpose->get_input_node_shared_ptr(1));- auto reduction_axes = ov::as_type_ptr<ov::op::v0::Constant>(reduction->get_input_node_shared_ptr(1));+ auto transpose_order = ov::as_type_ptr<v0::Constant>(transpose->get_input_node_shared_ptr(1));+ auto reduction_axes = ov::as_type_ptr<v0::Constant>(reduction->get_input_node_shared_ptr(1));if (!transpose_order || !reduction_axes)return false;@@ -186,13 +184,12 @@ ov::pass::TransposeReduction::TransposeReduction() {util::try_get_normalized_axis_vector(reduction_axes->get_tensor_view(),reduction->get_input_partial_shape(0).rank(),*reduction);- reduction_axes = ov::op::v0::Constant::create(ov::element::i64, {non_negative_axes.size()}, non_negative_axes);+ reduction_axes = v0::Constant::create(ov::element::i64, {non_negative_axes.size()}, non_negative_axes);ov::NodeVector new_ops;- auto new_axes =- ov::op::util::make_try_fold<ov::op::v1::Gather>(transpose_order,- reduction_axes,- ov::op::v0::Constant::create(ov::element::i64, {}, {0}));+ auto new_axes = op_util::make_try_fold<v1::Gather>(transpose_order,+ reduction_axes,+ v0::Constant::create(ov::element::i64, {}, {0}));new_ops.push_back(new_axes);auto new_reduce = reduction->clone_with_new_inputs({transpose->input_value(0), new_axes});new_ops.push_back(new_reduce);@@ -206,7 +203,7 @@ ov::pass::TransposeReduction::TransposeReduction() {if (!updated_order) {return false;}- auto new_transpose = register_new_node<ov::op::v1::Transpose>(new_reduce, updated_order);+ auto new_transpose = register_new_node<v1::Transpose>(new_reduce, updated_order);new_ops.push_back(new_transpose);new_transpose->set_friendly_name(reduction->get_friendly_name());@@ -216,33 +213,31 @@ ov::pass::TransposeReduction::TransposeReduction() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reduce_or_squeeze_label, matcher_name);+ auto m = std::make_shared<Matcher>(reduce_or_squeeze_label, matcher_name);register_matcher(m, matcher_pass_callback);}ov::pass::TransposeFQReduction::TransposeFQReduction() {MATCHER_SCOPE(TransposeFQReduction);- auto transpose_label =- pattern::wrap_type<ov::op::v1::Transpose>({pattern::any_input(), pattern::wrap_type<ov::op::v0::Constant>()});- auto fq_label = pattern::wrap_type<ov::op::v0::FakeQuantize>({transpose_label,- pattern::any_input(pattern::has_static_rank()),- pattern::any_input(pattern::has_static_rank()),- pattern::any_input(pattern::has_static_rank()),- pattern::any_input(pattern::has_static_rank())});+ auto transpose_label = wrap_type<v1::Transpose>({any_input(), wrap_type<v0::Constant>()});+ auto fq_label = wrap_type<v0::FakeQuantize>({transpose_label,+ any_input(ov::pass::pattern::has_static_rank()),+ any_input(ov::pass::pattern::has_static_rank()),+ any_input(ov::pass::pattern::has_static_rank()),+ any_input(ov::pass::pattern::has_static_rank())});auto reduce_or_squeeze_label =- pattern::wrap_type<ov::op::util::ArithmeticReductionKeepDims,- ov::op::util::LogicalReductionKeepDims,- ov::op::v0::Squeeze>({fq_label, pattern::wrap_type<ov::op::v0::Constant>()});+ wrap_type<op_util::ArithmeticReductionKeepDims, op_util::LogicalReductionKeepDims, v0::Squeeze>(+ {fq_label, wrap_type<v0::Constant>()});- ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();if (!transpose)return false;- auto transpose_order = ov::as_type_ptr<ov::op::v0::Constant>(transpose->get_input_node_shared_ptr(1));+ auto transpose_order = ov::as_type_ptr<v0::Constant>(transpose->get_input_node_shared_ptr(1));auto fq = pattern_to_output.at(fq_label).get_node_shared_ptr();if (!transpose_order || !fq)return false;@@ -261,21 +256,20 @@ ov::pass::TransposeFQReduction::TransposeFQReduction() {if (ranks_diff > 0) {std::vector<int64_t> axes(ranks_diff);std::iota(axes.begin(), axes.end(), 0);- const auto& axes_const = ov::op::v0::Constant::create(element::i64, Shape{axes.size()}, axes);+ const auto& axes_const = v0::Constant::create(element::i64, Shape{axes.size()}, axes);new_ops.push_back(axes_const);- const auto& unsqueezed_input = ov::op::util::make_try_fold<ov::op::v0::Unsqueeze>(input, axes_const);+ const auto& unsqueezed_input = op_util::make_try_fold<v0::Unsqueeze>(input, axes_const);new_ops.push_back(unsqueezed_input);input = unsqueezed_input->output(0);}- const auto& transposed_input =- ov::op::util::make_try_fold<ov::op::v1::Transpose>(input, reverse_order_constant);+ const auto& transposed_input = op_util::make_try_fold<v1::Transpose>(input, reverse_order_constant);new_ops.push_back(transposed_input);fq_inputs.push_back(transposed_input);}auto new_fq = fq->clone_with_new_inputs(fq_inputs);new_ops.push_back(new_fq);- auto new_transpose = register_new_node<ov::op::v1::Transpose>(new_fq, transpose_order);+ auto new_transpose = register_new_node<v1::Transpose>(new_fq, transpose_order);new_ops.push_back(new_transpose);new_transpose->set_friendly_name(fq->get_friendly_name());@@ -286,28 +280,25 @@ ov::pass::TransposeFQReduction::TransposeFQReduction() {return false;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reduce_or_squeeze_label, matcher_name);+ auto m = std::make_shared<Matcher>(reduce_or_squeeze_label, matcher_name);register_matcher(m, matcher_pass_callback);}ov::pass::TransposeFuse::TransposeFuse() {MATCHER_SCOPE(TransposeFuse);- auto transpose_1 =- pattern::wrap_type<ov::op::v1::Transpose>({pattern::any_input(), pattern::wrap_type<ov::op::v0::Constant>()},- pattern::consumers_count(1));- auto transpose_2 =- pattern::wrap_type<ov::op::v1::Transpose>({transpose_1, pattern::wrap_type<ov::op::v0::Constant>()});+ auto transpose_1 = wrap_type<v1::Transpose>({any_input(), wrap_type<v0::Constant>()}, consumers_count(1));+ auto transpose_2 = wrap_type<v1::Transpose>({transpose_1, wrap_type<v0::Constant>()});- ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose1 = pattern_to_output.at(transpose_1).get_node_shared_ptr();auto transpose2 = pattern_to_output.at(transpose_2).get_node_shared_ptr();auto input = transpose1->input_value(0);- auto transpose1_order = ov::as_type_ptr<ov::op::v0::Constant>(transpose1->get_input_node_shared_ptr(1));- auto transpose2_order = ov::as_type_ptr<ov::op::v0::Constant>(transpose2->get_input_node_shared_ptr(1));+ auto transpose1_order = ov::as_type_ptr<v0::Constant>(transpose1->get_input_node_shared_ptr(1));+ auto transpose2_order = ov::as_type_ptr<v0::Constant>(transpose2->get_input_node_shared_ptr(1));if (!transpose1_order || !transpose2_order)return false;@@ -330,8 +321,8 @@ ov::pass::TransposeFuse::TransposeFuse() {if (is_ordered) {return ov::replace_output_update_name(transpose2->output(0), input);} else {- auto new_order = ov::op::v0::Constant::create(transpose_order_type, {order2.size()}, order2);- auto new_transpose = register_new_node<ov::op::v1::Transpose>(input, new_order);+ auto new_order = v0::Constant::create(transpose_order_type, {order2.size()}, order2);+ auto new_transpose = register_new_node<v1::Transpose>(input, new_order);new_transpose->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info({transpose1, transpose2}, new_transpose);@@ -341,6 +332,6 @@ ov::pass::TransposeFuse::TransposeFuse() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(transpose_2, matcher_name);+ auto m = std::make_shared<Matcher>(transpose_2, matcher_name);register_matcher(m, matcher_pass_callback);}diff --git a/src/common/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp b/src/common/transformations/src/transformations/common_optimizations/transpose_to_reshape.cppindex 211cf335204..d823b2c7a55 100644--- a/src/common/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/transpose_to_reshape.cpp@@ -21,19 +21,24 @@using namespace ov;-ov::pass::TransposeToReshape::TransposeToReshape() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++TransposeToReshape::TransposeToReshape() {MATCHER_SCOPE(TransposeToReshape);- auto transpose_label = pattern::wrap_type<ov::op::v1::Transpose>(- {pattern::any_input(pattern::has_static_rank()), pattern::wrap_type<ov::op::v0::Constant>()});- ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto transpose_label = pattern::wrap_type<v1::Transpose>(+ {pattern::any_input(pattern::has_static_rank()), pattern::wrap_type<v0::Constant>()});+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto transpose = m.get_match_root();auto data = transpose->input_value(0);const auto input_shape = transpose->input(0).get_partial_shape();const size_t input_shape_rank = input_shape.rank().get_length();- auto order = ov::as_type_ptr<ov::op::v0::Constant>(transpose->input_value(1).get_node_shared_ptr());+ auto order = ov::as_type_ptr<v0::Constant>(transpose->input_value(1).get_node_shared_ptr());if (!order || !ov::shape_size(order->get_shape())) {return false;}@@ -91,18 +96,16 @@ ov::pass::TransposeToReshape::TransposeToReshape() {for (const auto& item : dims) {reshape_value[item.pos] = item.dim.is_dynamic() ? -1 : item.dim.get_length();}- reshape_dim = ov::op::v0::Constant::create(element::i64, Shape{reshape_value.size()}, reshape_value);+ reshape_dim = v0::Constant::create(element::i64, Shape{reshape_value.size()}, reshape_value);} else {auto shape_of = std::make_shared<ov::op::v3::ShapeOf>(data);new_ops.push_back(shape_of);reshape_dim =- std::make_shared<ov::op::v1::Gather>(shape_of,- order,- ov::op::v0::Constant::create(element::i64, Shape{1}, {0}));+ std::make_shared<v1::Gather>(shape_of, order, v0::Constant::create(element::i64, Shape{1}, {0}));new_ops.push_back(reshape_dim.get_node_shared_ptr());}- auto reshape_op = register_new_node<ov::op::v1::Reshape>(data, reshape_dim, true);+ auto reshape_op = register_new_node<v1::Reshape>(data, reshape_dim, true);new_ops.push_back(reshape_op);reshape_op->set_friendly_name(transpose->get_friendly_name());@@ -111,6 +114,8 @@ ov::pass::TransposeToReshape::TransposeToReshape() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(transpose_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp b/src/common/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cppindex f26c80fe0b2..1214837904d 100644--- a/src/common/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/weights_dequantize_to_fake_quantize.cpp@@ -16,26 +16,32 @@#include "transformations/rt_info/disable_constant_folding.hpp"#include "transformations/utils/utils.hpp"-ov::pass::WeightsDequantizeToFakeQuantize::WeightsDequantizeToFakeQuantize() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {++WeightsDequantizeToFakeQuantize::WeightsDequantizeToFakeQuantize() {MATCHER_SCOPE(WeightsDequantizeToFakeQuantize);- const auto weights = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(pattern::type_matches(element::i8));- const auto convert = ov::pass::pattern::wrap_type<ov::op::v0::Convert>({weights});- const auto sub_c_integer = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(pattern::type_matches(element::i8));- const auto convert_sub_c_integer = ov::pass::pattern::wrap_type<ov::op::v0::Convert>({sub_c_integer});- const auto sub_integer = ov::pass::pattern::wrap_type<ov::op::v1::Subtract>({convert, convert_sub_c_integer});- const auto sub_c = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- const auto sub = ov::pass::pattern::wrap_type<ov::op::v1::Subtract>({convert, sub_c});+ const auto weights = pattern::wrap_type<v0::Constant>(pattern::type_matches(element::i8));+ const auto convert = pattern::wrap_type<v0::Convert>({weights});+ const auto sub_c_integer = pattern::wrap_type<v0::Constant>(pattern::type_matches(element::i8));+ const auto convert_sub_c_integer = pattern::wrap_type<v0::Convert>({sub_c_integer});+ const auto sub_integer = pattern::wrap_type<v1::Subtract>({convert, convert_sub_c_integer});+ const auto sub_c = pattern::wrap_type<v0::Constant>();+ const auto sub = pattern::wrap_type<v1::Subtract>({convert, sub_c});const auto sub_or_sub_integer = std::make_shared<pattern::op::Or>(OutputVector{sub_integer, sub});const auto sub_or_convert = std::make_shared<pattern::op::Or>(OutputVector{convert, sub_or_sub_integer});- const auto mul_c = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- const auto mul = ov::pass::pattern::wrap_type<ov::op::v1::Multiply>({sub_or_convert, mul_c});+ const auto mul_c = pattern::wrap_type<v0::Constant>();+ const auto mul = pattern::wrap_type<v1::Multiply>({sub_or_convert, mul_c});- ov::matcher_pass_callback callback;- callback = [=](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback;+ callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_map();- const auto& weights_node = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(weights));+ const auto& weights_node = ov::as_type_ptr<v0::Constant>(pattern_map.at(weights));const auto& convert_node = pattern_map.at(convert);const auto& multiply_node = pattern_map.at(mul);const auto& scale_node = pattern_map.at(mul_c);@@ -48,32 +54,28 @@ ov::pass::WeightsDequantizeToFakeQuantize::WeightsDequantizeToFakeQuantize() {int64_t levels = (weights_minimum == static_cast<int8_t>(-128)) ? 256 : 255;int64_t in_low = -(levels / 2), in_high = levels + in_low - 1;- const auto& input_low = ov::op::v0::Constant::create(convert_node->get_element_type(), {}, {in_low});- const auto& input_high = ov::op::v0::Constant::create(convert_node->get_element_type(), {}, {in_high});- std::shared_ptr<ov::op::v0::Constant> zero_point;+ const auto& input_low = v0::Constant::create(convert_node->get_element_type(), {}, {in_low});+ const auto& input_high = v0::Constant::create(convert_node->get_element_type(), {}, {in_high});+ std::shared_ptr<v0::Constant> zero_point;if (pattern_map.count(sub_c)) {- const auto& sub_c_node = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(sub_c));+ const auto& sub_c_node = ov::as_type_ptr<v0::Constant>(pattern_map.at(sub_c));zero_point = sub_c_node;} else if (pattern_map.count(sub_c_integer)) {- const auto& sub_c_integer_node = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(sub_c_integer));- zero_point = ov::op::v0::Constant::create(convert_node->get_element_type(),- sub_c_integer_node->get_output_shape(0),- sub_c_integer_node->get_vector<int8_t>());+ const auto& sub_c_integer_node = ov::as_type_ptr<v0::Constant>(pattern_map.at(sub_c_integer));+ zero_point = v0::Constant::create(convert_node->get_element_type(),+ sub_c_integer_node->get_output_shape(0),+ sub_c_integer_node->get_vector<int8_t>());} else {- zero_point = ov::op::v0::Constant::create(convert_node->get_element_type(), {}, {0});+ zero_point = v0::Constant::create(convert_node->get_element_type(), {}, {0});}- const auto& output_low_const = ov::op::util::make_try_fold<ov::op::v1::Subtract>(input_low, zero_point);- const auto& output_low = ov::op::util::make_try_fold<ov::op::v1::Multiply>(output_low_const, scale_node);- const auto& output_high_const = ov::op::util::make_try_fold<ov::op::v1::Subtract>(input_high, zero_point);- const auto& output_high = ov::op::util::make_try_fold<ov::op::v1::Multiply>(output_high_const, scale_node);+ const auto& output_low_const = op_util::make_try_fold<v1::Subtract>(input_low, zero_point);+ const auto& output_low = op_util::make_try_fold<v1::Multiply>(output_low_const, scale_node);+ const auto& output_high_const = op_util::make_try_fold<v1::Subtract>(input_high, zero_point);+ const auto& output_high = op_util::make_try_fold<v1::Multiply>(output_high_const, scale_node);- auto fq = std::make_shared<ov::op::v0::FakeQuantize>(convert_node,- input_low,- input_high,- output_low,- output_high,- levels);+ auto fq =+ std::make_shared<v0::FakeQuantize>(convert_node, input_low, input_high, output_low, output_high, levels);NodeVector nodes_to_copy_RT_info_from{multiply_node, scale_node, zero_point};if (pattern_map.count(sub))@@ -88,6 +90,8 @@ ov::pass::WeightsDequantizeToFakeQuantize::WeightsDequantizeToFakeQuantize() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mul, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(mul, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/common_optimizations/wrap_interpolate_into_transposes.cpp b/src/common/transformations/src/transformations/common_optimizations/wrap_interpolate_into_transposes.cppindex af93cf20e72..2087f4c0fdf 100644--- a/src/common/transformations/src/transformations/common_optimizations/wrap_interpolate_into_transposes.cpp+++ b/src/common/transformations/src/transformations/common_optimizations/wrap_interpolate_into_transposes.cpp@@ -20,6 +20,12 @@#include "openvino/op/transpose.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;++namespace ov::pass {+namespace {std::vector<int64_t> reverse_permutation(const std::vector<int64_t>& perm) {if (perm.empty())@@ -54,11 +60,11 @@ std::vector<int64_t> build_new_axes(size_t num_of_axes, size_t rank) {}} // namespace-ov::pass::WrapInterpolateIntoTransposes::WrapInterpolateIntoTransposes() {+WrapInterpolateIntoTransposes::WrapInterpolateIntoTransposes() {MATCHER_SCOPE(WrapInterpolateIntoTransposes);- auto interpolate_pattern = ov::pass::pattern::wrap_type<ov::op::v4::Interpolate>();- ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto interpolate = ov::as_type_ptr<ov::op::v4::Interpolate>(m.get_match_root());+ auto interpolate_pattern = pattern::wrap_type<v4::Interpolate>();+ matcher_pass_callback callback = [=](pattern::Matcher& m) {+ auto interpolate = ov::as_type_ptr<v4::Interpolate>(m.get_match_root());if (!interpolate || interpolate->get_input_partial_shape(0).rank().is_dynamic() ||interpolate->inputs().size() != 4)return false;@@ -68,7 +74,7 @@ ov::pass::WrapInterpolateIntoTransposes::WrapInterpolateIntoTransposes() {if (input_rank < 3)return false;- auto axes_node = ov::as_type_ptr<ov::op::v0::Constant>(interpolate->input_value(3).get_node_shared_ptr());+ auto axes_node = ov::as_type_ptr<v0::Constant>(interpolate->input_value(3).get_node_shared_ptr());if (!axes_node)return false;@@ -83,15 +89,14 @@ ov::pass::WrapInterpolateIntoTransposes::WrapInterpolateIntoTransposes() {const auto first_perm = build_transposition_for_axes(axes, input_rank);const auto last_perm = reverse_permutation(first_perm);- auto first_transpose_perm = ov::op::v0::Constant::create(element::i64, {first_perm.size()}, first_perm);- auto first_transpose =- std::make_shared<ov::op::v1::Transpose>(interpolate->input_value(0), first_transpose_perm);+ auto first_transpose_perm = v0::Constant::create(element::i64, {first_perm.size()}, first_perm);+ auto first_transpose = std::make_shared<v1::Transpose>(interpolate->input_value(0), first_transpose_perm);auto new_axes = build_new_axes(axes.size(), input_rank);- auto new_axes_node = ov::op::v0::Constant::create(element::i64, {new_axes.size()}, new_axes);+ auto new_axes_node = v0::Constant::create(element::i64, {new_axes.size()}, new_axes);auto new_interpolate = interpolate->clone_with_new_inputs({first_transpose, interpolate->input_value(1), interpolate->input_value(2), new_axes_node});- auto last_transpose_perm = ov::op::v0::Constant::create(element::i64, {last_perm.size()}, last_perm);- auto last_transpose = std::make_shared<ov::op::v1::Transpose>(new_interpolate, last_transpose_perm);+ auto last_transpose_perm = v0::Constant::create(element::i64, {last_perm.size()}, last_perm);+ auto last_transpose = std::make_shared<v1::Transpose>(new_interpolate, last_transpose_perm);last_transpose->set_friendly_name(interpolate->get_friendly_name());copy_runtime_info(interpolate,@@ -109,3 +114,5 @@ ov::pass::WrapInterpolateIntoTransposes::WrapInterpolateIntoTransposes() {auto m = std::make_shared<pattern::Matcher>(interpolate_pattern, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/control_flow/unroll_tensor_iterator.cpp b/src/common/transformations/src/transformations/control_flow/unroll_tensor_iterator.cppindex 781ff9d8c50..afe51852ac9 100644--- a/src/common/transformations/src/transformations/control_flow/unroll_tensor_iterator.cpp+++ b/src/common/transformations/src/transformations/control_flow/unroll_tensor_iterator.cpp@@ -20,6 +20,7 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Model>& f) {RUN_ON_FUNCTION_SCOPE(UnrollTensorIterator);for (const auto& op : f->get_ops()) {@@ -52,13 +53,13 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Mode// Port map : inputs and back edgesfor (const auto& desc : sub_graph_op->get_input_descriptions()) {- if (const auto& input_desc = ov::as_type_ptr<ov::op::v0::TensorIterator::SliceInputDescription>(desc)) {+ if (const auto& input_desc = ov::as_type_ptr<v0::TensorIterator::SliceInputDescription>(desc)) {// Connect the sliced input (layer before the input) to the Split layer and connect// the corresponding Split output to the corresponding copy of the body.// If the number of iterations is 1, then the Split is not needed.auto in_data = sub_graph_op->input_values()[input_desc->m_input_index];- const auto const_axis = ov::op::v0::Constant::create(element::i64, Shape{}, {input_desc->m_axis});+ const auto const_axis = v0::Constant::create(element::i64, Shape{}, {input_desc->m_axis});if (num_iter > 1) {auto split = std::make_shared<ov::op::v1::Split>(in_data, const_axis, num_iter);@@ -79,8 +80,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Modeoutput.replace(in_data);}}- } else if (const auto& merged_desc =- ov::as_type_ptr<ov::op::v0::TensorIterator::MergedInputDescription>(desc)) {+ } else if (const auto& merged_desc = ov::as_type_ptr<v0::TensorIterator::MergedInputDescription>(desc)) {// Connect the input to the corresponding copy of the body.auto in_data = sub_graph_op->input_values()[merged_desc->m_input_index];const auto& param = body_functions[0]->get_parameters()[merged_desc->m_body_parameter_index];@@ -97,7 +97,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Mode}}} else if (const auto& invariant_desc =- ov::as_type_ptr<ov::op::v0::TensorIterator::InvariantInputDescription>(desc)) {+ ov::as_type_ptr<v0::TensorIterator::InvariantInputDescription>(desc)) {// Connect the input to the corresponding copy of the body.auto in_data = sub_graph_op->input_values()[invariant_desc->m_input_index];for (int64_t j = 0; j < num_iter; j++) {@@ -114,7 +114,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Mode// Port map: outputsfor (const auto& desc : sub_graph_op->get_output_descriptions()) {- if (const auto& concat_desc = ov::as_type_ptr<ov::op::v0::TensorIterator::ConcatOutputDescription>(desc)) {+ if (const auto& concat_desc = ov::as_type_ptr<v0::TensorIterator::ConcatOutputDescription>(desc)) {if (!concat_desc) {return false;}@@ -130,12 +130,12 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Mode// Connect outputs of the bodies to the Concat layerfor (int64_t j = 0; j < num_iter; j++) {auto idx = stride > 0 ? j : num_iter - j - 1;- std::shared_ptr<ov::op::v0::Result> result =+ std::shared_ptr<v0::Result> result =body_functions[idx]->get_results()[concat_desc->m_body_value_index];auto input_to_res = result->get_input_source_output(0);to_concat[j] = input_to_res;}- auto concat = std::make_shared<ov::op::v0::Concat>(to_concat, concat_desc->m_axis);+ auto concat = std::make_shared<v0::Concat>(to_concat, concat_desc->m_axis);copy_runtime_info(sub_graph_op, concat);// connect the Concat layer to the corresponding TI outputs@@ -144,7 +144,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Mode}} else {// Connect outputs of the bodies to the corresponding TI outputs- std::shared_ptr<ov::op::v0::Result> result =+ std::shared_ptr<v0::Result> result =body_functions[0]->get_results().at(concat_desc->m_body_value_index);const auto& input_to_res = result->get_input_source_output(0);@@ -152,8 +152,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Modeinput.replace_source_output(input_to_res);}}- } else if (const auto& output_desc =- ov::as_type_ptr<ov::op::v0::TensorIterator::BodyOutputDescription>(desc)) {+ } else if (const auto& output_desc = ov::as_type_ptr<v0::TensorIterator::BodyOutputDescription>(desc)) {// Connect outputs of the bodies to the corresponding TI outputsauto iter = output_desc->m_iteration;iter = iter >= 0 ? iter : num_iter - 1;@@ -194,7 +193,7 @@ bool ov::pass::UnrollTensorIterator::run_on_model(const std::shared_ptr<ov::Modefor (int64_t idx = 0; idx < num_iter; ++idx) {const auto iter_idx = loop->get_special_body_ports().current_iteration_input_idx;const auto& param_to_delete = body_functions[idx]->get_parameters()[iter_idx];- auto cur_iter_const = std::make_shared<ov::op::v0::Constant>(ov::element::i64, Shape{}, idx);+ auto cur_iter_const = std::make_shared<v0::Constant>(ov::element::i64, Shape{}, idx);replace_node(param_to_delete, cur_iter_const);body_functions[idx]->remove_parameter(param_to_delete);}diff --git a/src/common/transformations/src/transformations/convert_precision.cpp b/src/common/transformations/src/transformations/convert_precision.cppindex bd1b6be6453..d58a0279015 100644--- a/src/common/transformations/src/transformations/convert_precision.cpp+++ b/src/common/transformations/src/transformations/convert_precision.cpp@@ -28,6 +28,19 @@using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v5 = ov::op::v5;+namespace v6 = ov::op::v6;+namespace v8 = ov::op::v8;+namespace v9 = ov::op::v9;+namespace v10 = ov::op::v10;+namespace v13 = ov::op::v13;+namespace v14 = ov::op::v14;+namespace v15 = ov::op::v15;+namespace op_util = ov::op::util;bool fuse_type_to_parameter(const std::shared_ptr<ov::Node>& node,const precisions_map& precisions,bool convert_input_precision);@@ -170,7 +183,7 @@ bool convert_node_output_precision(bool function_changed) {bool node_changed = false;// Handle case with Constants as they can have consumers from other ov::Model object- const auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node);+ const auto constant = ov::as_type_ptr<v0::Constant>(node);const auto it = const_to_internal_output.find(node.get());if (constant && it != const_to_internal_output.end()) {return fuse_type_to_constant(node, precisions, it->second);@@ -260,8 +273,7 @@ bool convert_function_precision(ov::pass::PassBase& pass,auto register_constants = [&const_to_internal_output](const std::vector<std::shared_ptr<Node>>& ops) {for (auto& node : ops) {for (auto& input : node->inputs()) {- if (auto const_node =- ov::as_type_ptr<ov::op::v0::Constant>(input.get_source_output().get_node_shared_ptr())) {+ if (auto const_node = ov::as_type_ptr<v0::Constant>(input.get_source_output().get_node_shared_ptr())) {const_to_internal_output[const_node.get()].emplace_back(input);}}@@ -320,7 +332,7 @@ bool convert_function_precision(ov::pass::PassBase& pass,// TODO: we need to split NopElimination pass to separate MatcherPasses and call// Convert elimination herefor (auto& node : ops) {- if (auto convert = ov::as_type_ptr<ov::op::v0::Convert>(node)) {+ if (auto convert = ov::as_type_ptr<v0::Convert>(node)) {if (pass::constant_folding_is_disabled(node))continue;// WA for topK, dont remove fake convert@@ -338,7 +350,7 @@ bool convert_function_precision(ov::pass::PassBase& pass,auto& result = results[i];if (result->get_input_element_type(0) != orig_result_types[i]) {auto result_input = result->input_value(0);- const auto convert = std::make_shared<ov::op::v0::Convert>(result_input, orig_result_types[i]);+ const auto convert = std::make_shared<v0::Convert>(result_input, orig_result_types[i]);auto convert_f_name = result_input.get_node()->get_friendly_name();if (names_compatibility_mode) {@@ -402,7 +414,7 @@ precisions_set_t find_all_used_precisions(const std::shared_ptr<ov::Model>& fn)for (const auto& output : node->outputs()) {used_precisions.emplace(output.get_element_type());}- if (auto sub_graph_node = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(node)) {+ if (auto sub_graph_node = ov::as_type_ptr<op_util::MultiSubGraphOp>(node)) {size_t sub_graphs_num = sub_graph_node->get_internal_subgraphs_size();for (size_t sub_graph_ind = 0; sub_graph_ind < sub_graphs_num; ++sub_graph_ind) {auto sub_graph_precisions =@@ -432,56 +444,55 @@ bool ov::pass::ConvertPrecision::run_on_model(const std::shared_ptr<ov::Model>&bool has_fp16_compression = m_precisions.count(element::f32) > 0 && m_precisions[element::f32] == element::f16;type_to_fuse_map type_to_fuse{- {ov::op::v0::Convert::get_type_info_static(), fuse_type_to_convert},- {ov::op::v3::ShapeOf::get_type_info_static(), fuse_type_to_shapeof},- {ov::op::v6::Assign::get_type_info_static(),+ {v0::Convert::get_type_info_static(), fuse_type_to_convert},+ {v3::ShapeOf::get_type_info_static(), fuse_type_to_shapeof},+ {v6::Assign::get_type_info_static(),m_store_original_precision_as_rt_attribute ? store_original_type_as_attribute : wrap_into_original_type},- {ov::op::v6::ReadValue::get_type_info_static(),+ {v6::ReadValue::get_type_info_static(),m_store_original_precision_as_rt_attribute ? store_original_type_as_attribute : wrap_into_original_type},- {ov::op::v3::NonMaxSuppression::get_type_info_static(), fuse_type_to_nms3},- {ov::op::v4::NonMaxSuppression::get_type_info_static(), fuse_type_to_nms4},- {ov::op::v5::NonMaxSuppression::get_type_info_static(), fuse_type_to_nms5},- {ov::op::v9::NonMaxSuppression::get_type_info_static(), fuse_type_to_nms9},+ {v3::NonMaxSuppression::get_type_info_static(), fuse_type_to_nms3},+ {v4::NonMaxSuppression::get_type_info_static(), fuse_type_to_nms4},+ {v5::NonMaxSuppression::get_type_info_static(), fuse_type_to_nms5},+ {v9::NonMaxSuppression::get_type_info_static(), fuse_type_to_nms9},{op::v13::NMSRotated::get_type_info_static(), fuse_type_to_nms_rotated},- {ov::op::v8::MatrixNms::get_type_info_static(), fuse_type_to_matrix_nms},- {ov::op::v8::MulticlassNms::get_type_info_static(), fuse_type_to_multiclass_nms},- {ov::op::v9::MulticlassNms::get_type_info_static(), fuse_type_to_multiclass_nms},- {ov::op::v9::GenerateProposals::get_type_info_static(), fuse_type_to_generate_proposals},- {ov::op::v6::CTCGreedyDecoderSeqLen::get_type_info_static(), fuse_type_to_ctc_greedy_decoder_seq_len},- {ov::op::v1::TopK::get_type_info_static(), fuse_type_to_topk},- {ov::op::v3::TopK::get_type_info_static(), fuse_type_to_topk},+ {v8::MatrixNms::get_type_info_static(), fuse_type_to_matrix_nms},+ {v8::MulticlassNms::get_type_info_static(), fuse_type_to_multiclass_nms},+ {v9::MulticlassNms::get_type_info_static(), fuse_type_to_multiclass_nms},+ {v9::GenerateProposals::get_type_info_static(), fuse_type_to_generate_proposals},+ {v6::CTCGreedyDecoderSeqLen::get_type_info_static(), fuse_type_to_ctc_greedy_decoder_seq_len},+ {v1::TopK::get_type_info_static(), fuse_type_to_topk},+ {v3::TopK::get_type_info_static(), fuse_type_to_topk},{ov::op::v11::TopK::get_type_info_static(), fuse_type_to_topk},- {ov::op::v8::MaxPool::get_type_info_static(), fuse_type_to_maxpool},- {ov::op::v14::MaxPool::get_type_info_static(), fuse_type_to_maxpool},- {ov::op::v3::NonZero::get_type_info_static(), fuse_type_to_nonzero},- {ov::op::v3::Bucketize::get_type_info_static(), fuse_type_to_bucketize},- {ov::op::v1::Equal::get_type_info_static(), fuse_type_to_binary_comparision<ov::op::v1::Equal>},- {ov::op::v1::NotEqual::get_type_info_static(), fuse_type_to_binary_comparision<ov::op::v1::NotEqual>},- {ov::op::v1::Greater::get_type_info_static(), fuse_type_to_binary_comparision<ov::op::v1::Greater>},- {ov::op::v1::GreaterEqual::get_type_info_static(), fuse_type_to_binary_comparision<ov::op::v1::GreaterEqual>},- {ov::op::v1::Less::get_type_info_static(), fuse_type_to_binary_comparision<ov::op::v1::Less>},- {ov::op::v1::LessEqual::get_type_info_static(), fuse_type_to_binary_comparision<ov::op::v1::LessEqual>},- {ov::op::v10::IsFinite::get_type_info_static(), fuse_type_to_binary_comparision<ov::op::v10::IsFinite>},- {ov::op::v10::IsNaN::get_type_info_static(), fuse_type_to_binary_comparision<ov::op::v10::IsNaN>},- {ov::op::v10::IsInf::get_type_info_static(), fuse_type_to_binary_comparision<ov::op::v10::IsInf>},- {ov::op::v1::LogicalAnd::get_type_info_static(), fuse_type_to_logical<ov::op::v1::LogicalAnd>},- {ov::op::v1::LogicalOr::get_type_info_static(), fuse_type_to_logical<ov::op::v1::LogicalOr>},- {ov::op::v1::LogicalXor::get_type_info_static(), fuse_type_to_logical<ov::op::v1::LogicalXor>},- {ov::op::v1::LogicalNot::get_type_info_static(), fuse_type_to_logical<ov::op::v1::LogicalNot>},- {ov::op::v0::Xor::get_type_info_static(), fuse_type_to_logical<ov::op::v0::Xor>},- {ov::op::v1::ReduceLogicalAnd::get_type_info_static(),- fuse_type_to_reduce_logical<ov::op::v1::ReduceLogicalAnd>},- {ov::op::v1::ReduceLogicalOr::get_type_info_static(), fuse_type_to_reduce_logical<ov::op::v1::ReduceLogicalOr>},- {ov::op::v0::ShapeOf::get_type_info_static(), fuse_type_to_shapeof_v0},- {ov::op::v4::Range::get_type_info_static(), fuse_type_to_range_v4},- {ov::op::v9::Eye::get_type_info_static(), fuse_type_to_eye_v9},- {ov::op::v10::Unique::get_type_info_static(), fuse_type_to_unique_v10},- {ov::op::v8::RandomUniform::get_type_info_static(), fuse_type_to_random_uniform_v8},- {ov::op::v13::Multinomial::get_type_info_static(), fuse_type_to_multinomial_v13},- {ov::op::v0::PriorBox::get_type_info_static(), fuse_type_to_prior_box<ov::op::v0::PriorBox>},- {ov::op::v8::PriorBox::get_type_info_static(), fuse_type_to_prior_box<ov::op::v8::PriorBox>},- {ov::op::v0::PriorBoxClustered::get_type_info_static(), fuse_type_to_prior_box<ov::op::v0::PriorBoxClustered>},- {ov::op::v15::SearchSorted::get_type_info_static(), fuse_type_to_search_sorted_v15},+ {v8::MaxPool::get_type_info_static(), fuse_type_to_maxpool},+ {v14::MaxPool::get_type_info_static(), fuse_type_to_maxpool},+ {v3::NonZero::get_type_info_static(), fuse_type_to_nonzero},+ {v3::Bucketize::get_type_info_static(), fuse_type_to_bucketize},+ {v1::Equal::get_type_info_static(), fuse_type_to_binary_comparision<v1::Equal>},+ {v1::NotEqual::get_type_info_static(), fuse_type_to_binary_comparision<v1::NotEqual>},+ {v1::Greater::get_type_info_static(), fuse_type_to_binary_comparision<v1::Greater>},+ {v1::GreaterEqual::get_type_info_static(), fuse_type_to_binary_comparision<v1::GreaterEqual>},+ {v1::Less::get_type_info_static(), fuse_type_to_binary_comparision<v1::Less>},+ {v1::LessEqual::get_type_info_static(), fuse_type_to_binary_comparision<v1::LessEqual>},+ {v10::IsFinite::get_type_info_static(), fuse_type_to_binary_comparision<v10::IsFinite>},+ {v10::IsNaN::get_type_info_static(), fuse_type_to_binary_comparision<v10::IsNaN>},+ {v10::IsInf::get_type_info_static(), fuse_type_to_binary_comparision<v10::IsInf>},+ {v1::LogicalAnd::get_type_info_static(), fuse_type_to_logical<v1::LogicalAnd>},+ {v1::LogicalOr::get_type_info_static(), fuse_type_to_logical<v1::LogicalOr>},+ {v1::LogicalXor::get_type_info_static(), fuse_type_to_logical<v1::LogicalXor>},+ {v1::LogicalNot::get_type_info_static(), fuse_type_to_logical<v1::LogicalNot>},+ {v0::Xor::get_type_info_static(), fuse_type_to_logical<v0::Xor>},+ {v1::ReduceLogicalAnd::get_type_info_static(), fuse_type_to_reduce_logical<v1::ReduceLogicalAnd>},+ {v1::ReduceLogicalOr::get_type_info_static(), fuse_type_to_reduce_logical<v1::ReduceLogicalOr>},+ {v0::ShapeOf::get_type_info_static(), fuse_type_to_shapeof_v0},+ {v4::Range::get_type_info_static(), fuse_type_to_range_v4},+ {v9::Eye::get_type_info_static(), fuse_type_to_eye_v9},+ {v10::Unique::get_type_info_static(), fuse_type_to_unique_v10},+ {v8::RandomUniform::get_type_info_static(), fuse_type_to_random_uniform_v8},+ {v13::Multinomial::get_type_info_static(), fuse_type_to_multinomial_v13},+ {v0::PriorBox::get_type_info_static(), fuse_type_to_prior_box<v0::PriorBox>},+ {v8::PriorBox::get_type_info_static(), fuse_type_to_prior_box<v8::PriorBox>},+ {v0::PriorBoxClustered::get_type_info_static(), fuse_type_to_prior_box<v0::PriorBoxClustered>},+ {v15::SearchSorted::get_type_info_static(), fuse_type_to_search_sorted_v15},{ov::op::internal::RMS::get_type_info_static(), fuse_type_to_rms},// This is operation representing inline_extension from// src/bindings/python/src/openvino/frontend/pytorch/inlined_extension.py@@ -494,8 +505,8 @@ bool ov::pass::ConvertPrecision::run_on_model(const std::shared_ptr<ov::Model>&type_to_fuse.insert(m_additional_type_to_fuse_map.begin(), m_additional_type_to_fuse_map.end());static type_to_fuse_map type_to_extend{- {ov::op::v1::Select::get_type_info_static(), extend_select_type},- {ov::op::v1::Reverse::get_type_info_static(), extend_reverse_type},+ {v1::Select::get_type_info_static(), extend_select_type},+ {v1::Reverse::get_type_info_static(), extend_reverse_type},};bool is_changed = convert_precision(*this,@@ -530,7 +541,7 @@ bool fuse_type_to_shapeof(const std::shared_ptr<ov::Node>& node, const precisionif (it == precisions.end())return false;const auto& to = it->second;- if (auto shapeof = ov::as_type_ptr<ov::op::v3::ShapeOf>(node)) {+ if (auto shapeof = ov::as_type_ptr<v3::ShapeOf>(node)) {if (to == ov::element::i32 || to == ov::element::i64) {shapeof->set_output_type(to);return true;@@ -544,7 +555,7 @@ bool fuse_type_to_random_uniform_v8(const std::shared_ptr<ov::Node>& node, constif (it == precisions.end())return false;const auto& to = it->second;- if (auto random_uniform = ov::as_type_ptr<ov::op::v8::RandomUniform>(node)) {+ if (auto random_uniform = ov::as_type_ptr<v8::RandomUniform>(node)) {if (to.is_integral_number() || to.is_real()) {random_uniform->set_out_type(to);return true;@@ -555,7 +566,7 @@ bool fuse_type_to_random_uniform_v8(const std::shared_ptr<ov::Node>& node, constbool fuse_type_to_unique_v10(const std::shared_ptr<Node>& node, const precisions_map& precisions) {bool res = false;- if (auto unique = ov::as_type_ptr<ov::op::v10::Unique>(node)) {+ if (auto unique = ov::as_type_ptr<v10::Unique>(node)) {auto it = precisions.find(node->get_output_element_type(1));if (it != precisions.end()) {unique->set_index_element_type(it->second);@@ -572,7 +583,7 @@ bool fuse_type_to_unique_v10(const std::shared_ptr<Node>& node, const precisionsbool fuse_type_to_search_sorted_v15(const std::shared_ptr<Node>& node, const precisions_map& precisions) {bool res = false;- if (auto op = ov::as_type_ptr<ov::op::v15::SearchSorted>(node)) {+ if (auto op = ov::as_type_ptr<v15::SearchSorted>(node)) {auto it = precisions.find(node->get_output_element_type(0));if (it != precisions.end()) {op->set_output_type_attr(it->second);@@ -587,7 +598,7 @@ bool fuse_type_to_range_v4(const std::shared_ptr<ov::Node>& node, const precisioif (it == precisions.end())return false;const auto& to = it->second;- if (auto range = ov::as_type_ptr<ov::op::v4::Range>(node)) {+ if (auto range = ov::as_type_ptr<v4::Range>(node)) {if ((to == ov::element::f16 && !fp16_compression_is_disabled(node)) || to.is_integral_number()) {range->set_output_type(to);return true;@@ -601,7 +612,7 @@ bool fuse_type_to_eye_v9(const std::shared_ptr<ov::Node>& node, const precisionsif (it == precisions.end())return false;const auto& to = it->second;- if (auto eye_node = ov::as_type_ptr<ov::op::v9::Eye>(node)) {+ if (auto eye_node = ov::as_type_ptr<v9::Eye>(node)) {if (to.is_integral() || to.is_real()) {eye_node->set_out_type(to);return true;@@ -622,17 +633,17 @@ bool fuse_type_to_parameter(const std::shared_ptr<ov::Node>& node,return false;bool changed = false;const auto& to = it->second;- if (auto param = ov::as_type_ptr<ov::op::v0::Parameter>(node)) {+ if (auto param = ov::as_type_ptr<v0::Parameter>(node)) {if (convert_input_precision) {param->set_element_type(to);param->validate_and_infer_types();changed = true;} else {auto param_consumers = param->output(0).get_target_inputs();- auto convert = std::make_shared<ov::op::v0::Convert>(param, to);+ auto convert = std::make_shared<v0::Convert>(param, to);for (auto& input : param_consumers) {const auto consumer = input.get_node();- if (ov::is_type<ov::op::v0::Result>(consumer) || ov::is_type<ov::op::v0::Convert>(consumer) ||+ if (ov::is_type<v0::Result>(consumer) || ov::is_type<v0::Convert>(consumer) ||// TODO: refactor after ngraph op defined// The fourth and fifth inputs are kvcache and should be directly connected to parameters(consumer->get_type_name() == std::string("PagedAttentionExtension") &&@@ -655,15 +666,15 @@ bool wrap_into_original_type(const std::shared_ptr<ov::Node>& node, const precisconst auto& to = it->second;const auto& from = it->first;if (node->get_input_size()) {- auto convert_before = std::make_shared<ov::op::v0::Convert>(node->input_value(0), from);+ auto convert_before = std::make_shared<v0::Convert>(node->input_value(0), from);node->input(0).replace_source_output(convert_before);}if (node->get_output_size() == 1) {auto consumers = node->output(0).get_target_inputs();- auto convert_after = std::make_shared<ov::op::v0::Convert>(node, to);+ auto convert_after = std::make_shared<v0::Convert>(node, to);for (auto& input : consumers) {const auto consumer = input.get_node();- if (ov::is_type<ov::op::v0::Result>(consumer) || ov::is_type<ov::op::v0::Convert>(consumer)) {+ if (ov::is_type<v0::Result>(consumer) || ov::is_type<v0::Convert>(consumer)) {continue;}input.replace_source_output(convert_after);@@ -698,7 +709,7 @@ bool fuse_type_to_convert(const std::shared_ptr<ov::Node>& node, const precisionif (it == precisions.end())return false;const auto& to = it->second;- if (auto convert = ov::as_type_ptr<ov::op::v0::Convert>(node)) {+ if (auto convert = ov::as_type_ptr<v0::Convert>(node)) {convert->set_convert_element_type(to);return true;}@@ -710,7 +721,7 @@ bool fuse_type_to_nms3(const std::shared_ptr<ov::Node>& node, const precisions_mif (it == precisions.end())return false;const auto& to = it->second;- if (auto nms = ov::as_type_ptr<ov::op::v3::NonMaxSuppression>(node)) {+ if (auto nms = ov::as_type_ptr<v3::NonMaxSuppression>(node)) {if (to == ov::element::i32 || to == ov::element::i64) {nms->set_output_type(to);} else {@@ -726,7 +737,7 @@ bool fuse_type_to_nms4(const std::shared_ptr<ov::Node>& node, const precisions_mif (it == precisions.end())return false;const auto& to = it->second;- if (auto nms = ov::as_type_ptr<ov::op::v4::NonMaxSuppression>(node)) {+ if (auto nms = ov::as_type_ptr<v4::NonMaxSuppression>(node)) {if (to == ov::element::i32 || to == ov::element::i64) {nms->set_output_type(to);} else {@@ -738,7 +749,7 @@ bool fuse_type_to_nms4(const std::shared_ptr<ov::Node>& node, const precisions_m}bool fuse_type_to_nms5(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- auto nms = ov::as_type_ptr<ov::op::v5::NonMaxSuppression>(node);+ auto nms = ov::as_type_ptr<v5::NonMaxSuppression>(node);if (!nms) {return false;}@@ -780,15 +791,14 @@ bool fuse_type_to_nms5(const std::shared_ptr<ov::Node>& node, const precisions_moutput_types.push_back(to);}- auto relaxed_op = std::make_shared<ov::op::TypeRelaxed<ov::op::v5::NonMaxSuppression>>(*nms,- ov::element::TypeVector{},- output_types);+ auto relaxed_op =+ std::make_shared<ov::op::TypeRelaxed<v5::NonMaxSuppression>>(*nms, ov::element::TypeVector{}, output_types);replace_node(node, relaxed_op);return true;}bool fuse_type_to_nms9(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- auto nms = ov::as_type_ptr<ov::op::v9::NonMaxSuppression>(node);+ auto nms = ov::as_type_ptr<v9::NonMaxSuppression>(node);if (!nms) {return false;}@@ -830,9 +840,8 @@ bool fuse_type_to_nms9(const std::shared_ptr<ov::Node>& node, const precisions_moutput_types.push_back(to);}- auto relaxed_op = std::make_shared<ov::op::TypeRelaxed<ov::op::v9::NonMaxSuppression>>(*nms,- ov::element::TypeVector{},- output_types);+ auto relaxed_op =+ std::make_shared<ov::op::TypeRelaxed<v9::NonMaxSuppression>>(*nms, ov::element::TypeVector{}, output_types);replace_node(node, relaxed_op);return true;}@@ -916,7 +925,7 @@ bool update_type(size_t idx,} // namespacebool fuse_type_to_matrix_nms(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- auto nms = ov::as_type_ptr<ov::op::v8::MatrixNms>(node);+ auto nms = ov::as_type_ptr<v8::MatrixNms>(node);if (!nms) {return false;}@@ -927,11 +936,11 @@ bool fuse_type_to_matrix_nms(const std::shared_ptr<ov::Node>& node, const precis}bool fuse_type_to_multiclass_nms(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- std::shared_ptr<ov::op::util::MulticlassNmsBase> nms;- if (ov::is_type<ov::op::v8::MulticlassNms>(node)) {- nms = ov::as_type_ptr<ov::op::v8::MulticlassNms>(node);+ std::shared_ptr<op_util::MulticlassNmsBase> nms;+ if (ov::is_type<v8::MulticlassNms>(node)) {+ nms = ov::as_type_ptr<v8::MulticlassNms>(node);} else {- nms = ov::as_type_ptr<ov::op::v9::MulticlassNms>(node);+ nms = ov::as_type_ptr<v9::MulticlassNms>(node);}if (!nms) {return false;@@ -943,7 +952,7 @@ bool fuse_type_to_multiclass_nms(const std::shared_ptr<ov::Node>& node, const pr}bool fuse_type_to_multinomial_v13(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- auto multinomial = ov::as_type_ptr<ov::op::v13::Multinomial>(node);+ auto multinomial = ov::as_type_ptr<v13::Multinomial>(node);if (!multinomial) {return false;}@@ -954,7 +963,7 @@ bool fuse_type_to_multinomial_v13(const std::shared_ptr<ov::Node>& node, const p}bool fuse_type_to_generate_proposals(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- auto generate_proposals = ov::as_type_ptr<ov::op::v9::GenerateProposals>(node);+ auto generate_proposals = ov::as_type_ptr<v9::GenerateProposals>(node);if (!generate_proposals) {return false;}@@ -965,7 +974,7 @@ bool fuse_type_to_generate_proposals(const std::shared_ptr<ov::Node>& node, cons}bool fuse_type_to_topk(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- if (auto topk = ov::as_type_ptr<ov::op::util::TopKBase>(node)) {+ if (auto topk = ov::as_type_ptr<op_util::TopKBase>(node)) {return update_type(1, node, precisions, [&](const element::Type& to) {topk->set_index_element_type(to);});@@ -974,8 +983,8 @@ bool fuse_type_to_topk(const std::shared_ptr<ov::Node>& node, const precisions_m}bool fuse_type_to_maxpool(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- auto maxpool_v8 = ov::as_type_ptr<ov::op::v8::MaxPool>(node);- auto maxpool_v14 = ov::as_type_ptr<ov::op::v14::MaxPool>(node);+ auto maxpool_v8 = ov::as_type_ptr<v8::MaxPool>(node);+ auto maxpool_v14 = ov::as_type_ptr<v14::MaxPool>(node);if (maxpool_v14) {return update_type(1, node, precisions, [&](const element::Type& to) {maxpool_v14->set_index_element_type(to);@@ -990,7 +999,7 @@ bool fuse_type_to_maxpool(const std::shared_ptr<ov::Node>& node, const precisionbool fuse_type_to_ctc_greedy_decoder_seq_len(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {bool res = false;- if (auto ctc_decoder = ov::as_type_ptr<ov::op::v6::CTCGreedyDecoderSeqLen>(node)) {+ if (auto ctc_decoder = ov::as_type_ptr<v6::CTCGreedyDecoderSeqLen>(node)) {res = update_type(0, node, precisions, [&](const element::Type& to) {ctc_decoder->set_classes_index_type(to);});@@ -1006,7 +1015,7 @@ bool fuse_type_to_ctc_greedy_decoder_seq_len(const std::shared_ptr<ov::Node>& no}bool fuse_type_to_nonzero(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- if (auto nonzero = ov::as_type_ptr<ov::op::v3::NonZero>(node)) {+ if (auto nonzero = ov::as_type_ptr<v3::NonZero>(node)) {return update_type(0, node, precisions, [&](const element::Type& to) {nonzero->set_output_type(to);});@@ -1015,7 +1024,7 @@ bool fuse_type_to_nonzero(const std::shared_ptr<ov::Node>& node, const precision}bool fuse_type_to_bucketize(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- if (auto b = ov::as_type_ptr<ov::op::v3::Bucketize>(node)) {+ if (auto b = ov::as_type_ptr<v3::Bucketize>(node)) {return update_type(0, node, precisions, [&](const element::Type& to) {b->set_output_type(to);});@@ -1031,10 +1040,10 @@ bool fuse_type_to_shapeof_v0(const std::shared_ptr<ov::Node>& node, const precisif (auto type_relaxed = std::dynamic_pointer_cast<ov::op::TypeRelaxedBase>(node)) {type_relaxed->set_overridden_output_type(to);return true;- } else if (auto casted = ov::as_type_ptr<ov::op::v0::ShapeOf>(node)) {- auto relaxed_op = std::make_shared<ov::op::TypeRelaxed<ov::op::v0::ShapeOf>>(*casted,- ov::element::TypeVector{},- ov::element::TypeVector{to});+ } else if (auto casted = ov::as_type_ptr<v0::ShapeOf>(node)) {+ auto relaxed_op = std::make_shared<ov::op::TypeRelaxed<v0::ShapeOf>>(*casted,+ ov::element::TypeVector{},+ ov::element::TypeVector{to});replace_node(node, relaxed_op);return true;}@@ -1045,12 +1054,12 @@ bool extend_select_type(const std::shared_ptr<ov::Node>& node, const precisions_if (auto type_relaxed = std::dynamic_pointer_cast<ov::op::TypeRelaxedBase>(node)) {type_relaxed->set_origin_input_type(ov::element::boolean, 0);return true;- } else if (auto casted = ov::as_type_ptr<ov::op::v1::Select>(node)) {+ } else if (auto casted = ov::as_type_ptr<v1::Select>(node)) {if (precisions.count(ov::element::boolean) != 0) {auto relaxed_op =- std::make_shared<op::TypeRelaxed<ov::op::v1::Select>>(*casted,- ov::element::TypeVector{ov::element::boolean},- ov::element::TypeVector{});+ std::make_shared<op::TypeRelaxed<v1::Select>>(*casted,+ ov::element::TypeVector{ov::element::boolean},+ ov::element::TypeVector{});replace_node(node, relaxed_op);return true;}@@ -1059,9 +1068,9 @@ bool extend_select_type(const std::shared_ptr<ov::Node>& node, const precisions_}bool extend_reverse_type(const std::shared_ptr<ov::Node>& node, const precisions_map& precisions) {- if (const auto casted = ov::as_type_ptr<ov::op::v1::Reverse>(node)) {- if (casted->get_mode() == ov::op::v1::Reverse::Mode::MASK) {- auto relaxed_op = std::make_shared<op::TypeRelaxed<ov::op::v1::Reverse>>(+ if (const auto casted = ov::as_type_ptr<v1::Reverse>(node)) {+ if (casted->get_mode() == v1::Reverse::Mode::MASK) {+ auto relaxed_op = std::make_shared<op::TypeRelaxed<v1::Reverse>>(*casted,ov::element::TypeVector{casted->get_input_element_type(0), ov::element::boolean},ov::element::TypeVector{casted->get_output_element_type(0)});@@ -1103,14 +1112,14 @@ inline int32_t convert_value<uint32_t, int32_t>(uint32_t val) {namespace {template <ov::element::Type_t PREC_FROM, ov::element::Type_t PREC_TO>-std::shared_ptr<ov::Node> change_constant_precision(std::shared_ptr<ov::op::v0::Constant>& constant) {+std::shared_ptr<ov::Node> change_constant_precision(std::shared_ptr<v0::Constant>& constant) {using src_type = typename element_type_traits<PREC_FROM>::value_type;using dst_type = typename element_type_traits<PREC_TO>::value_type;const auto* src_data = constant->get_data_ptr<src_type>();const auto size = shape_size(constant->get_shape());- auto new_constant = std::make_shared<ov::op::v0::Constant>(PREC_TO, constant->get_shape());+ auto new_constant = std::make_shared<v0::Constant>(PREC_TO, constant->get_shape());new_constant->output(0).set_names(constant->output(0).get_names());auto* dst_data = const_cast<dst_type*>(reinterpret_cast<const dst_type*>(new_constant->get_data_ptr()));if (dst_data == nullptr)@@ -1124,14 +1133,14 @@ std::shared_ptr<ov::Node> change_constant_precision(std::shared_ptr<ov::op::v0::template <>std::shared_ptr<Node> change_constant_precision<ov::element::Type_t::f32, ov::element::Type_t::f16>(- std::shared_ptr<ov::op::v0::Constant>& constant) {+ std::shared_ptr<v0::Constant>& constant) {using src_type = typename element_type_traits<ov::element::Type_t::f32>::value_type;using dst_type = typename element_type_traits<ov::element::Type_t::f16>::value_type;const auto* src_data = constant->get_data_ptr<src_type>();const auto size = shape_size(constant->get_shape());- auto new_constant = std::make_shared<ov::op::v0::Constant>(ov::element::Type_t::f16, constant->get_shape());+ auto new_constant = std::make_shared<v0::Constant>(ov::element::Type_t::f16, constant->get_shape());new_constant->output(0).set_names(constant->output(0).get_names());auto* dst_data = const_cast<dst_type*>(reinterpret_cast<const dst_type*>(new_constant->get_data_ptr()));if (dst_data == nullptr)@@ -1144,14 +1153,14 @@ std::shared_ptr<Node> change_constant_precision<ov::element::Type_t::f32, ov::eltemplate <>std::shared_ptr<Node> change_constant_precision<ov::element::Type_t::bf16, ov::element::Type_t::f16>(- std::shared_ptr<ov::op::v0::Constant>& constant) {+ std::shared_ptr<v0::Constant>& constant) {using src_type = typename element_type_traits<ov::element::Type_t::bf16>::value_type;using dst_type = typename element_type_traits<ov::element::Type_t::f16>::value_type;const auto* src_data = constant->get_data_ptr<src_type>();const auto size = shape_size(constant->get_shape());- auto new_constant = std::make_shared<ov::op::v0::Constant>(ov::element::Type_t::f16, constant->get_shape());+ auto new_constant = std::make_shared<v0::Constant>(ov::element::Type_t::f16, constant->get_shape());new_constant->output(0).set_names(constant->output(0).get_names());auto* dst_data = const_cast<dst_type*>(reinterpret_cast<const dst_type*>(new_constant->get_data_ptr()));if (dst_data == nullptr)@@ -1164,14 +1173,14 @@ std::shared_ptr<Node> change_constant_precision<ov::element::Type_t::bf16, ov::etemplate <>std::shared_ptr<Node> change_constant_precision<ov::element::Type_t::f16, ov::element::Type_t::f32>(- std::shared_ptr<ov::op::v0::Constant>& constant) {+ std::shared_ptr<v0::Constant>& constant) {using src_type = typename element_type_traits<ov::element::Type_t::f16>::value_type;using dst_type = typename element_type_traits<ov::element::Type_t::f32>::value_type;const auto* src_data = constant->get_data_ptr<src_type>();const auto size = shape_size(constant->get_shape());- auto new_constant = std::make_shared<ov::op::v0::Constant>(ov::element::Type_t::f32, constant->get_shape());+ auto new_constant = std::make_shared<v0::Constant>(ov::element::Type_t::f32, constant->get_shape());new_constant->output(0).set_names(constant->output(0).get_names());auto* dst_data = const_cast<dst_type*>(reinterpret_cast<const dst_type*>(new_constant->get_data_ptr()));if (dst_data == nullptr)@@ -1264,8 +1273,7 @@ void convert_lp_value(const SRC& src,dst &= new_val;}-std::shared_ptr<Node> convert_low_precisions_int(std::shared_ptr<ov::op::v0::Constant>& constant,- ov::element::Type to) {+std::shared_ptr<Node> convert_low_precisions_int(std::shared_ptr<v0::Constant>& constant, ov::element::Type to) {// Supported integer precisionsstatic const precisions_set_t supported_integer_precisions = {ov::element::i4,ov::element::u4,@@ -1285,13 +1293,13 @@ std::shared_ptr<Node> convert_low_precisions_int(std::shared_ptr<ov::op::v0::Con// Use Convert operator's evaluate() to perform conversion// This ensures consistent nibble packing order (LSB-first) with element::iteratorauto outputs = ov::TensorVector{{to, constant->get_shape()}};- OPENVINO_ASSERT(ov::op::v0::Convert(constant, to).evaluate(outputs, {constant->get_tensor_view()}),+ OPENVINO_ASSERT(v0::Convert(constant, to).evaluate(outputs, {constant->get_tensor_view()}),"Failed to convert constant from ",src_type.get_type_name()," to ",to.get_type_name());- return std::make_shared<ov::op::v0::Constant>(std::move(outputs[0]));+ return std::make_shared<v0::Constant>(std::move(outputs[0]));}} // namespace@@ -1308,7 +1316,7 @@ bool fuse_type_to_constant(const std::shared_ptr<ov::Node>& node,if (it == precisions.end())return false;const auto& to = it->second;- if (auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node)) {+ if (auto constant = ov::as_type_ptr<v0::Constant>(node)) {std::shared_ptr<ov::Node> new_const;if (from == ov::element::u64 && to == ov::element::i32) {new_const = change_constant_precision<ov::element::Type_t::u64, ov::element::Type_t::i32>(constant);diff --git a/src/common/transformations/src/transformations/flush_fp32_subnormals_to_zero.cpp b/src/common/transformations/src/transformations/flush_fp32_subnormals_to_zero.cppindex e148ad17bed..b94c4d436d5 100644--- a/src/common/transformations/src/transformations/flush_fp32_subnormals_to_zero.cpp+++ b/src/common/transformations/src/transformations/flush_fp32_subnormals_to_zero.cpp@@ -17,13 +17,16 @@ using namespace std;using namespace ov;using namespace pass;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;ov::pass::FlushFP32SubnormalsToZero::FlushFP32SubnormalsToZero() {MATCHER_SCOPE(FlushFP32SubnormalsToZero);- auto node_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto node_pattern = ov::pass::pattern::wrap_type<v0::Constant>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto node = ov::as_type_ptr<ov::op::v0::Constant>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto node = ov::as_type_ptr<v0::Constant>(m.get_match_root());if (!node)return false;@@ -43,7 +46,7 @@ ov::pass::FlushFP32SubnormalsToZero::FlushFP32SubnormalsToZero() {if (!has_subnormals)return false;- auto new_constant = std::make_shared<ov::op::v0::Constant>(ov::element::f32, node->get_shape());+ auto new_constant = std::make_shared<v0::Constant>(ov::element::f32, node->get_shape());auto* dst_data = const_cast<float*>(new_constant->get_data_ptr<float>());for (size_t i = 0; i < size; ++i) {@@ -60,6 +63,6 @@ ov::pass::FlushFP32SubnormalsToZero::FlushFP32SubnormalsToZero() {return true;};- auto m = make_shared<pattern::Matcher>(node_pattern, matcher_name);+ auto m = make_shared<Matcher>(node_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/fp16_compression/align_mixed_fp32_fp16_types.cpp b/src/common/transformations/src/transformations/fp16_compression/align_mixed_fp32_fp16_types.cppindex bf6f3d430c1..b235b869bc9 100644--- a/src/common/transformations/src/transformations/fp16_compression/align_mixed_fp32_fp16_types.cpp+++ b/src/common/transformations/src/transformations/fp16_compression/align_mixed_fp32_fp16_types.cpp@@ -14,6 +14,7 @@using namespace ov;+namespace v0 = ov::op::v0;bool ov::pass::AlignMixedFP32FP16Types::run_on_model(const std::shared_ptr<ov::Model>& model) {RUN_ON_MODEL_SCOPE(AlignMixedFP32FP16Types);std::unordered_set<std::string> new_friendly_names;@@ -41,8 +42,7 @@ bool ov::pass::AlignMixedFP32FP16Types::run_on_model(const std::shared_ptr<ov::Mif (!incoming_output.get_element_type().is_real())continue;- auto convert =- std::make_shared<ov::op::v0::Convert>(incoming_output, incoming_output.get_element_type());+ auto convert = std::make_shared<v0::Convert>(incoming_output, incoming_output.get_element_type());auto init_name = incoming_node->get_friendly_name() + "_decompressed_to_f32";convert->set_friendly_name(generate_uniq_name(init_name));copy_runtime_info(incoming_node, convert);@@ -67,7 +67,7 @@ bool ov::pass::AlignMixedFP32FP16Types::run_on_model(const std::shared_ptr<ov::M// element_type of this convert will be changed automatically to f16 after// ConvertPrecision(f32 -> f16). It's kept here f32 to keep ov::Model validatable- auto convert = std::make_shared<ov::op::v0::Convert>(output, out_inputs.get_element_type());+ auto convert = std::make_shared<v0::Convert>(output, out_inputs.get_element_type());copy_runtime_info(node, convert);auto init_name = node->get_friendly_name() + "_compressed_to_f16";convert->set_friendly_name(generate_uniq_name(init_name));diff --git a/src/common/transformations/src/transformations/fp16_compression/mark_decompression_convert_constant_folding.cpp b/src/common/transformations/src/transformations/fp16_compression/mark_decompression_convert_constant_folding.cppindex 0b46727ea18..1ae30f28e87 100644--- a/src/common/transformations/src/transformations/fp16_compression/mark_decompression_convert_constant_folding.cpp+++ b/src/common/transformations/src/transformations/fp16_compression/mark_decompression_convert_constant_folding.cpp@@ -19,9 +19,13 @@using namespace ov;-pass::EnableDecompressionConvertConstantFolding::EnableDecompressionConvertConstantFolding() {+namespace v0 = ov::op::v0;++namespace ov::pass {++EnableDecompressionConvertConstantFolding::EnableDecompressionConvertConstantFolding() {MATCHER_SCOPE(EnableDecompressionConvertConstantFolding);- auto convert = pattern::wrap_type<ov::op::v0::Convert>();+ auto convert = pattern::wrap_type<v0::Convert>();matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& node = m.get_match_root();@@ -31,13 +35,13 @@ pass::EnableDecompressionConvertConstantFolding::EnableDecompressionConvertConstreturn true;};- auto m = std::make_shared<pass::pattern::Matcher>(convert, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(convert, matcher_name);this->register_matcher(m, callback);}-pass::DisableDecompressionConvertConstantFolding::DisableDecompressionConvertConstantFolding() {+DisableDecompressionConvertConstantFolding::DisableDecompressionConvertConstantFolding() {MATCHER_SCOPE(DisableDecompressionConvertConstantFolding);- auto convert = pattern::wrap_type<ov::op::v0::Convert>();+ auto convert = pattern::wrap_type<v0::Convert>();matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& node = m.get_match_root();@@ -47,19 +51,18 @@ pass::DisableDecompressionConvertConstantFolding::DisableDecompressionConvertConreturn true;};- auto m = std::make_shared<pass::pattern::Matcher>(convert, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(convert, matcher_name);this->register_matcher(m, callback);}-pass::KeepConstAndDecompression::KeepConstAndDecompression() {+KeepConstAndDecompression::KeepConstAndDecompression() {MATCHER_SCOPE(KeepDecompressionsInFP32Matcher);- auto node_pattern = pattern::wrap_type<ov::op::v0::Convert>();+ auto node_pattern = pattern::wrap_type<v0::Convert>();matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto node = m.get_match_root();- if (!is_decompression(node) || !is_type<ov::op::v0::Convert>(node) ||- ov::is_shape_subgraph(node->shared_from_this()))+ if (!is_decompression(node) || !is_type<v0::Convert>(node) || ov::is_shape_subgraph(node->shared_from_this()))return false;if (transformation_callback(node)) {@@ -68,7 +71,7 @@ pass::KeepConstAndDecompression::KeepConstAndDecompression() {disable_constant_folding(node);- if (!is_type<ov::op::v0::Constant>(node->input_value(0).get_node_shared_ptr()))+ if (!is_type<v0::Constant>(node->input_value(0).get_node_shared_ptr()))return false;enable_keep_const_precision(node->input_value(0).get_node_shared_ptr());@@ -78,9 +81,9 @@ pass::KeepConstAndDecompression::KeepConstAndDecompression() {register_matcher(m, callback);}-pass::KeepConstantsPrecisionAndAddConverts::KeepConstantsPrecisionAndAddConverts() {+KeepConstantsPrecisionAndAddConverts::KeepConstantsPrecisionAndAddConverts() {MATCHER_SCOPE(KeepConstantsPrecisionAndAddConverts);- auto const_pattern = pattern::wrap_type<ov::op::v0::Constant>();+ auto const_pattern = pattern::wrap_type<v0::Constant>();matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {auto const_node = m.get_match_root();@@ -93,7 +96,7 @@ pass::KeepConstantsPrecisionAndAddConverts::KeepConstantsPrecisionAndAddConvertsconst auto& constant_target_inputs = const_node->get_output_target_inputs(0);const auto& next_node = constant_target_inputs.begin()->get_node()->shared_from_this();- if (is_type<ov::op::v0::Convert>(next_node)) {+ if (is_type<v0::Convert>(next_node)) {disable_constant_folding(next_node);if (is_decompression(next_node)) {unmark_as_decompression(next_node);@@ -101,7 +104,7 @@ pass::KeepConstantsPrecisionAndAddConverts::KeepConstantsPrecisionAndAddConvertsreturn true;}- auto convert = std::make_shared<ov::op::v0::Convert>(const_node, const_node->get_element_type());+ auto convert = std::make_shared<v0::Convert>(const_node, const_node->get_element_type());convert->set_friendly_name(const_node->get_friendly_name());std::string postfix = const_node->get_element_type() == ov::element::f32 ? "compression" : "decompression";@@ -117,18 +120,18 @@ pass::KeepConstantsPrecisionAndAddConverts::KeepConstantsPrecisionAndAddConvertsreturn true;};- auto m = std::make_shared<pass::pattern::Matcher>(const_pattern, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(const_pattern, matcher_name);this->register_matcher(m, callback);}-pass::MarkCompressedFloatConstants::MarkCompressedFloatConstants() {+MarkCompressedFloatConstants::MarkCompressedFloatConstants() {MATCHER_SCOPE(MarkCompressedFloatConstants);- auto constant = pattern::wrap_type<ov::op::v0::Constant>();- auto convert = pattern::wrap_type<ov::op::v0::Convert>({constant});+ auto constant = pattern::wrap_type<v0::Constant>();+ auto convert = pattern::wrap_type<v0::Convert>({constant});matcher_pass_callback callback = [=](pattern::Matcher& m) {- const auto& convert_node = as_type_ptr<ov::op::v0::Convert>(m.get_match_root());+ const auto& convert_node = as_type_ptr<v0::Convert>(m.get_match_root());if (convert_node == nullptr)return false;@@ -151,6 +154,8 @@ pass::MarkCompressedFloatConstants::MarkCompressedFloatConstants() {return false;};- auto m = std::make_shared<pass::pattern::Matcher>(convert, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(convert, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/fp16_compression/mark_floatpoint_range.cpp b/src/common/transformations/src/transformations/fp16_compression/mark_floatpoint_range.cppindex f924671b3fb..44561760043 100644--- a/src/common/transformations/src/transformations/fp16_compression/mark_floatpoint_range.cpp+++ b/src/common/transformations/src/transformations/fp16_compression/mark_floatpoint_range.cpp@@ -18,32 +18,37 @@#include "transformations/rt_info/disable_fp16_compression.hpp"#include "transformations/utils/utils.hpp"-void ov::pass::mark_range_path(const std::shared_ptr<Node>& node) {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;++namespace ov::pass {++void mark_range_path(const std::shared_ptr<Node>& node) {node->get_rt_info().emplace("range_path", true);}-bool ov::pass::is_range_path(const std::shared_ptr<const Node>& node) {+bool is_range_path(const std::shared_ptr<const Node>& node) {return node->get_rt_info().count("range_path");}-void ov::pass::erase_range_path(const std::shared_ptr<Node>& node) {+void erase_range_path(const std::shared_ptr<Node>& node) {auto& rt_info = node->get_rt_info();rt_info.erase("range_path");}-ov::pass::MarkFloatingPointRange::MarkFloatingPointRange() {+MarkFloatingPointRange::MarkFloatingPointRange() {MATCHER_SCOPE(MarkFloatingPointRange);- using namespace ov::pass::pattern;// through these nodes- const auto range_propagating_nodes = pattern::wrap_type<ov::op::v0::Convert,- ov::op::v1::Greater,- ov::op::v1::GreaterEqual,- ov::op::v1::Less,- ov::op::v1::LessEqual,- ov::op::v1::Reshape,- ov::op::v4::Range,- ov::op::v0::Squeeze,- ov::op::v0::Unsqueeze>();+ const auto range_propagating_nodes = pattern::wrap_type<v0::Convert,+ v1::Greater,+ v1::GreaterEqual,+ v1::Less,+ v1::LessEqual,+ v1::Reshape,+ v4::Range,+ v0::Squeeze,+ v0::Unsqueeze>();ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& node = m.get_match_root();@@ -52,7 +57,7 @@ ov::pass::MarkFloatingPointRange::MarkFloatingPointRange() {bool is_changed = false;- auto range = ov::as_type_ptr<ov::op::v4::Range>(node);+ auto range = ov::as_type_ptr<v4::Range>(node);if (range && range->get_output_type().is_real()) {mark_range_path(node);ov::disable_fp16_compression(node);@@ -77,6 +82,8 @@ ov::pass::MarkFloatingPointRange::MarkFloatingPointRange() {return is_changed;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(range_propagating_nodes, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(range_propagating_nodes, matcher_name);register_matcher(m, callback);-}\ No newline at end of file+}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/fp16_compression/mark_subgraphs_to_keep_in_mixed_precision.cpp b/src/common/transformations/src/transformations/fp16_compression/mark_subgraphs_to_keep_in_mixed_precision.cppindex cda941bc3b1..c93687e563c 100644--- a/src/common/transformations/src/transformations/fp16_compression/mark_subgraphs_to_keep_in_mixed_precision.cpp+++ b/src/common/transformations/src/transformations/fp16_compression/mark_subgraphs_to_keep_in_mixed_precision.cpp@@ -56,8 +56,11 @@using namespace std;-namespace ov {-namespace pass {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;++namespace ov::pass {namespace {@@ -87,26 +90,26 @@ void erase_fq_path(const std::shared_ptr<Node>& node) {// Marking continues to propagate through these ops.const std::shared_ptr<Node> propagate_through_ops =- pattern::wrap_type<ov::op::v0::Squeeze,- ov::op::v0::Unsqueeze,- ov::op::v1::Reshape,+ pattern::wrap_type<v0::Squeeze,+ v0::Unsqueeze,+ v1::Reshape,op::util::BroadcastBase,op::util::BinaryElementwiseArithmetic,op::util::UnaryElementwiseArithmetic,ov::op::v6::MVN,- ov::op::v0::MVN,- ov::op::v0::NormalizeL2,- ov::op::v0::Sqrt,- ov::op::v1::StridedSlice,- ov::op::v1::ReduceSum,- ov::op::v1::ReduceMean,- ov::op::v8::Slice,- ov::op::v1::VariadicSplit,- ov::op::v1::Split,- ov::op::v0::Concat,- ov::op::v0::Convert, // through Convert can go only to Constants- ov::op::v0::Constant,- ov::op::v0::Tile>();+ v0::MVN,+ v0::NormalizeL2,+ v0::Sqrt,+ v1::StridedSlice,+ v1::ReduceSum,+ v1::ReduceMean,+ v8::Slice,+ v1::VariadicSplit,+ v1::Split,+ v0::Concat,+ v0::Convert, // through Convert can go only to Constants+ v0::Constant,+ v0::Tile>();} // namespace@@ -115,7 +118,7 @@ const std::shared_ptr<Node> propagate_through_ops =* during PropagateDownMark we need also mark its other inputs and this is done in this PropagateUpMark pass.* Propagation stops when we face ops not listed in propagate_through_ops: e.g. if we face Conv or MatMul.*/-class PropagateUpMarkToKeepInMixedPrecision : public pass::MatcherPass {+class PropagateUpMarkToKeepInMixedPrecision : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("PropagateUpMarkToKeepInMixedPrecision");PropagateUpMarkToKeepInMixedPrecision() {@@ -136,11 +139,11 @@ public:if (!has_marked_output)return false;- auto convert_node = as_type_ptr<ov::op::v0::Convert>(node);+ auto convert_node = as_type_ptr<v0::Convert>(node);if (convert_node) {// if during propagating up there is a Convert it must go to Const,// otherwise interrupt propagation- auto const_node = as_type_ptr<ov::op::v0::Constant>(node->input_value(0).get_node_shared_ptr());+ auto const_node = as_type_ptr<v0::Constant>(node->input_value(0).get_node_shared_ptr());if (!const_node)return false;}@@ -158,7 +161,7 @@ public:* ops like Slice, ReduceSum, Reshape, Elementwise, et al. to be kept in f32 as well.* Propagation stops when ops not listed in propagate_through_ops are faced: e.g. if we face Conv or MatMul.*/-class PropagateDownMarkToKeepInMixedPrecision : public pass::MatcherPass {+class PropagateDownMarkToKeepInMixedPrecision : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("PropagateDownMarkToKeepInMixedPrecision");PropagateDownMarkToKeepInMixedPrecision() {@@ -170,7 +173,7 @@ public:return false;// on convert down propagation should be interrupted- auto convert_node = as_type_ptr<ov::op::v0::Convert>(node);+ auto convert_node = as_type_ptr<v0::Convert>(node);if (convert_node)return false;@@ -196,13 +199,13 @@ public:}};-class InitMarkReduceOpPath : public pass::MatcherPass {+class InitMarkReduceOpPath : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("InitMarkReduceOpPath");InitMarkReduceOpPath() {MATCHER_SCOPE(InitMarkReduceOpPath);- auto reduce_ops = pattern::wrap_type<ov::op::v1::ReduceSum, ov::op::v1::ReduceMean>();+ auto reduce_ops = pattern::wrap_type<v1::ReduceSum, v1::ReduceMean>();matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& node = m.get_match_root();@@ -216,7 +219,7 @@ public:}};-class PropagateMarkUpReduceOpPath : public pass::MatcherPass {+class PropagateMarkUpReduceOpPath : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("PropagateMarkUpReduceOpPath");PropagateMarkUpReduceOpPath() {@@ -243,13 +246,13 @@ public:}};-class MarkExp : public pass::MatcherPass {+class MarkExp : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("MarkExp");// only exponent that go into ReduceOp should be marked as precision sensitive and kept in f32MarkExp() {MATCHER_SCOPE(MarkExp);- auto exp_pattern = pattern::wrap_type<ov::op::v0::Exp>();+ auto exp_pattern = pattern::wrap_type<v0::Exp>();matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& node = m.get_match_root();@@ -267,13 +270,13 @@ public:}};-class MarkRandomUniform : public pass::MatcherPass {+class MarkRandomUniform : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("MarkRandomUniform");MarkRandomUniform() {MATCHER_SCOPE(MarkRandomUniform);- auto random_uniform_pattern = pattern::wrap_type<ov::op::v8::RandomUniform>();+ auto random_uniform_pattern = pattern::wrap_type<v8::RandomUniform>();matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& node = m.get_match_root();@@ -335,21 +338,20 @@ public:auto input_1 = pattern::any_input();auto input_2 = pattern::any_input();- auto eps_const_pattern = pattern::wrap_type<ov::op::v0::Constant>();- auto optional_eps_convert = pattern::optional<ov::op::v0::Convert>(eps_const_pattern);+ auto eps_const_pattern = pattern::wrap_type<v0::Constant>();+ auto optional_eps_convert = pattern::optional<v0::Convert>(eps_const_pattern);- auto max_or_add =- pattern::wrap_type<ov::op::v1::Maximum, ov::op::v1::Add>(OutputVector{input_2, optional_eps_convert});+ auto max_or_add = pattern::wrap_type<v1::Maximum, v1::Add>(OutputVector{input_2, optional_eps_convert});- auto optional_sqrt = pattern::optional<ov::op::v0::Sqrt>(max_or_add);+ auto optional_sqrt = pattern::optional<v0::Sqrt>(max_or_add);// whether is divided directly or after sqrt (e.g. in L2Norm after sqrt, in MVN is divided directly)- auto divide = std::make_shared<ov::op::v1::Divide>(input_1, optional_sqrt);+ auto divide = std::make_shared<v1::Divide>(input_1, optional_sqrt);- auto pow_exp = pattern::wrap_type<ov::op::v0::Constant>();- auto optional_pow_convert = pattern::optional<ov::op::v0::Convert>(pow_exp);+ auto pow_exp = pattern::wrap_type<v0::Constant>();+ auto optional_pow_convert = pattern::optional<v0::Convert>(pow_exp);- auto pow_pattern = std::make_shared<ov::op::v1::Power>(max_or_add, optional_pow_convert);- auto mul_pattern = std::make_shared<ov::op::v1::Multiply>(input_1, pow_pattern);+ auto pow_pattern = std::make_shared<v1::Power>(max_or_add, optional_pow_convert);+ auto mul_pattern = std::make_shared<v1::Multiply>(input_1, pow_pattern);auto div_or_mul_to_negative_pow = std::make_shared<pattern::op::Or>(OutputVector{divide, mul_pattern});matcher_pass_callback callback = [=](pattern::Matcher& m) {@@ -357,11 +359,11 @@ public:if (!m.get_match_root())return false;- const auto mul = as_type_ptr<ov::op::v1::Multiply>(m.get_match_root());+ const auto mul = as_type_ptr<v1::Multiply>(m.get_match_root());// if pattern input_1*Pow(Maximum(input_2, eps), z) or input_1*Pow(Add(input_2, eps), z) is matched// need to check that power is negativeif (mul) {- const auto pow_const = as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(pow_exp));+ const auto pow_const = as_type_ptr<v0::Constant>(pattern_to_output.at(pow_exp));if (pow_const) {// continue only if exponent is negative (z < 0)if (pow_const->get_element_type() == element::f16) {@@ -376,7 +378,7 @@ public:}}- const auto eps_const = as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(eps_const_pattern));+ const auto eps_const = as_type_ptr<v0::Constant>(pattern_to_output.at(eps_const_pattern));if (!eps_const)return false;if (eps_const->get_element_type() == element::f32) {@@ -397,43 +399,43 @@ public:}};-class PropagateDownDisableSensitivityForQuantized : public pass::MatcherPass {+class PropagateDownDisableSensitivityForQuantized : public MatcherPass {public:OPENVINO_MATCHER_PASS_RTTI("PropagateDownDisableSensitivityForQuantized");PropagateDownDisableSensitivityForQuantized() {MATCHER_SCOPE(PropagateDownDisableSensitivityForQuantized);// through this nodes- const std::shared_ptr<Node> quantization_propagating_nodes = pattern::wrap_type<ov::op::v0::Squeeze,- ov::op::v0::Unsqueeze,- ov::op::v0::FakeQuantize,- ov::op::v1::Reshape,+ const std::shared_ptr<Node> quantization_propagating_nodes = pattern::wrap_type<v0::Squeeze,+ v0::Unsqueeze,+ v0::FakeQuantize,+ v1::Reshape,op::util::BroadcastBase,- ov::op::v0::DepthToSpace,- ov::op::v0::Interpolate,+ v0::DepthToSpace,+ v0::Interpolate,ov::op::v4::Interpolate,ov::op::v11::Interpolate,- ov::op::v1::MaxPool,- ov::op::v8::MaxPool,+ v1::MaxPool,+ v8::MaxPool,op::util::PadBase,- ov::op::v1::ReduceMax,- ov::op::v1::ReduceMin,- ov::op::v0::Relu,- ov::op::v1::Transpose,- ov::op::v0::ShuffleChannels,- ov::op::v1::StridedSlice,- ov::op::v8::Slice,- ov::op::v1::VariadicSplit,- ov::op::v1::Split,- ov::op::v0::Concat,- ov::op::v0::Tile>();+ v1::ReduceMax,+ v1::ReduceMin,+ v0::Relu,+ v1::Transpose,+ v0::ShuffleChannels,+ v1::StridedSlice,+ v8::Slice,+ v1::VariadicSplit,+ v1::Split,+ v0::Concat,+ v0::Tile>();matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& node = m.get_match_root();if (!node)return false;- auto is_quantize = as_type_ptr<ov::op::v0::FakeQuantize>(node);+ auto is_quantize = as_type_ptr<v0::FakeQuantize>(node);if (is_quantize) {mark_fq_path(node);return true;@@ -443,7 +445,7 @@ public:for (const auto& in_node_output : node->input_values()) {auto input_node = in_node_output.get_node_shared_ptr();- auto is_quantize = as_type_ptr<ov::op::v0::FakeQuantize>(input_node);+ auto is_quantize = as_type_ptr<v0::FakeQuantize>(input_node);if (is_quantize || is_fq_path(input_node)) {mark_fq_path(node);enable_fp16_compression(node);@@ -464,7 +466,7 @@ bool MarkSugraphsToKeepInMixedPrecision::run_on_model(const shared_ptr<ov::ModelManager manager(get_pass_config(), "MarkSugraphsToKeepInMixedPrecision");manager.set_per_pass_validation(false);// Mark root of Division with eps pattern to keep in FP32- REGISTER_PASS(manager, ov::pass::MarkFloatingPointRange)+ REGISTER_PASS(manager, MarkFloatingPointRange)REGISTER_PASS(manager, MarkDivWithEps)REGISTER_PASS(manager, MarkExpInReduceOpPath)REGISTER_PASS(manager, MarkRandomUniform)@@ -484,11 +486,10 @@ bool MarkSugraphsToKeepInMixedPrecision::run_on_model(const shared_ptr<ov::Modelfor (auto& node : m->get_ops()) {erase_reduceop_path(node);erase_fq_path(node);- ov::pass::erase_range_path(node);+ erase_range_path(node);}return false; // no need to revalidate}-} // namespace pass-} // namespace ov+} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/low_precision/mark_dequantization_subgraph.cpp b/src/common/transformations/src/transformations/low_precision/mark_dequantization_subgraph.cppindex 1a3d8b6c844..a94a864da38 100644--- a/src/common/transformations/src/transformations/low_precision/mark_dequantization_subgraph.cpp+++ b/src/common/transformations/src/transformations/low_precision/mark_dequantization_subgraph.cpp@@ -21,9 +21,13 @@#include "transformations/utils/utils.hpp"using namespace ov;-using namespace ov::op;-using namespace ov::pass::pattern;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++namespace {static std::string write_precisions(const ov::element::TypeVector& precisions) {std::stringstream sstream;#ifdef OPENVINO_DEBUG@@ -35,10 +39,8 @@ static std::string write_precisions(const ov::element::TypeVector& precisions) {return sstream.str();}-namespace {--ov::pass::pattern::op::Predicate check_precision(const ov::element::TypeVector& precisions) {- return ov::pass::pattern::op::Predicate(+pattern::op::Predicate check_precision(const ov::element::TypeVector& precisions) {+ return pattern::op::Predicate([=](const Output<Node>& output) -> bool {return std::find(precisions.begin(), precisions.end(), output.get_element_type()) != precisions.end();},@@ -46,7 +48,7 @@ ov::pass::pattern::op::Predicate check_precision(const ov::element::TypeVector&}using RTInfoSetter = std::function<void(const std::shared_ptr<ov::Node>& node)>;-void set_rt_info(const PatternValueMap& pt_map,+void set_rt_info(const pattern::PatternValueMap& pt_map,const RTInfoSetter& rt_info_setter,const NodeVector& pattern_nodes,const ov::element::TypeVector& precisions) {@@ -151,7 +153,7 @@ will be the same: forthe first branch step 1 is applied, for all theremainings step 2.*/-bool can_swap(const PatternValueMap& pt_map,+bool can_swap(const pattern::PatternValueMap& pt_map,const std::shared_ptr<Node>& first_pattern,const std::shared_ptr<Node>& second_pattern) {if (pt_map.count(first_pattern) && pt_map.count(second_pattern)) {@@ -186,7 +188,7 @@ bool can_swap(const PatternValueMap& pt_map,return false;}-bool swap_nodes(const PatternValueMap& pt_map,+bool swap_nodes(const pattern::PatternValueMap& pt_map,const std::shared_ptr<Node>& first,const std::shared_ptr<Node>& second) {if (can_swap(pt_map, first, second)) {@@ -207,28 +209,29 @@ bool swap_nodes(const PatternValueMap& pt_map,} // namespace-ov::pass::MarkDequantization::MarkDequantization(const element::TypeVector& precisions,- const bool fold_subtract_const,- const bool fold_multiply_const) {+MarkDequantization::MarkDequantization(const element::TypeVector& precisions,+ const bool fold_subtract_const,+ const bool fold_multiply_const) {MATCHER_SCOPE(MarkDequantization);// data input:- auto input_pattern = any_input(check_precision(precisions));- auto convert_pattern = wrap_type<v0::Convert>({input_pattern}, consumers_count(1));+ auto input_pattern = pattern::any_input(check_precision(precisions));+ auto convert_pattern = pattern::wrap_type<v0::Convert>({input_pattern}, pattern::consumers_count(1));// zero points:- auto zp_pattern = any_input();+ auto zp_pattern = pattern::any_input();auto zp_convert_pattern = pattern::optional<v0::Convert>(zp_pattern);- auto zp_reshape_pattern = pattern::optional<v1::Reshape, v0::Unsqueeze>({zp_convert_pattern, any_input()});+ auto zp_reshape_pattern = pattern::optional<v1::Reshape, v0::Unsqueeze>({zp_convert_pattern, pattern::any_input()});auto subtract_pattern = pattern::optional<v1::Subtract>({convert_pattern, zp_reshape_pattern});// scale:- auto scale_pattern = any_input();+ auto scale_pattern = pattern::any_input();auto scale_convert_pattern = pattern::optional<v0::Convert>(scale_pattern);- auto scale_reshape_pattern = pattern::optional<v1::Reshape, v0::Unsqueeze>({scale_convert_pattern, any_input()});- auto multiply_pattern = wrap_type<v1::Multiply>({subtract_pattern, scale_reshape_pattern});+ auto scale_reshape_pattern =+ pattern::optional<v1::Reshape, v0::Unsqueeze>({scale_convert_pattern, pattern::any_input()});+ auto multiply_pattern = pattern::wrap_type<v1::Multiply>({subtract_pattern, scale_reshape_pattern});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) -> bool {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) -> bool {const auto& pt_map = m.get_pattern_value_map();auto convert = pt_map.at(convert_pattern);auto input = pt_map.at(input_pattern);@@ -267,32 +270,33 @@ ov::pass::MarkDequantization::MarkDequantization(const element::TypeVector& precreturn changed;};- auto m = std::make_shared<Matcher>(multiply_pattern, "MarkDequantization");+ auto m = std::make_shared<pattern::Matcher>(multiply_pattern, "MarkDequantization");this->register_matcher(m, callback);}-ov::pass::KeepConstPrecision::KeepConstPrecision(const element::TypeVector& precisions,- bool fold_subtract_const,- bool fold_multiply_const) {+KeepConstPrecision::KeepConstPrecision(const element::TypeVector& precisions,+ bool fold_subtract_const,+ bool fold_multiply_const) {MATCHER_SCOPE(KeepConstPrecision);// data input:- auto input_pattern = any_input();- auto convert_pattern = wrap_type<v0::Convert>({input_pattern}, consumers_count(1));+ auto input_pattern = pattern::any_input();+ auto convert_pattern = pattern::wrap_type<v0::Convert>({input_pattern}, pattern::consumers_count(1));// zero points:- auto zp_pattern = any_input();+ auto zp_pattern = pattern::any_input();auto zp_convert_pattern = pattern::optional<v0::Convert>(zp_pattern);- auto zp_reshape_pattern = pattern::optional<v1::Reshape, v0::Unsqueeze>({zp_convert_pattern, any_input()});+ auto zp_reshape_pattern = pattern::optional<v1::Reshape, v0::Unsqueeze>({zp_convert_pattern, pattern::any_input()});auto subtract_pattern = pattern::optional<v1::Subtract>({convert_pattern, zp_reshape_pattern});// scale:- auto scale_pattern = any_input();+ auto scale_pattern = pattern::any_input();auto scale_convert_pattern = pattern::optional<v0::Convert>(scale_pattern);- auto scale_reshape_pattern = pattern::optional<v1::Reshape, v0::Unsqueeze>({scale_convert_pattern, any_input()});- auto multiply_pattern = wrap_type<v1::Multiply>({subtract_pattern, scale_reshape_pattern});+ auto scale_reshape_pattern =+ pattern::optional<v1::Reshape, v0::Unsqueeze>({scale_convert_pattern, pattern::any_input()});+ auto multiply_pattern = pattern::wrap_type<v1::Multiply>({subtract_pattern, scale_reshape_pattern});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) -> bool {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) -> bool {const auto& pt_map = m.get_pattern_value_map();const auto multiply = m.get_match_root();@@ -319,12 +323,12 @@ ov::pass::KeepConstPrecision::KeepConstPrecision(const element::TypeVector& precreturn false;};- auto m = std::make_shared<Matcher>(multiply_pattern, "KeepConstPrecision");+ auto m = std::make_shared<pattern::Matcher>(multiply_pattern, "KeepConstPrecision");this->register_matcher(m, callback);}-ov::pass::KeepDequantizationPrecision::KeepDequantizationPrecision(const element::TypeVector& precisions,- bool add_precision_sensitive_convert) {+KeepDequantizationPrecision::KeepDequantizationPrecision(const element::TypeVector& precisions,+ bool add_precision_sensitive_convert) {MATCHER_SCOPE(KeepDequantizationPrecision);auto input_pattern = pattern::wrap_type<v0::Constant>(pattern::type_matches_any(precisions));@@ -333,16 +337,17 @@ ov::pass::KeepDequantizationPrecision::KeepDequantizationPrecision(const element// zero points:auto zp_pattern = pattern::wrap_type<v0::Constant>();auto zp_convert_pattern = pattern::optional<v0::Convert>(zp_pattern);- auto zp_reshape_pattern = pattern::optional<v1::Reshape, v0::Unsqueeze>({zp_convert_pattern, any_input()});+ auto zp_reshape_pattern = pattern::optional<v1::Reshape, v0::Unsqueeze>({zp_convert_pattern, pattern::any_input()});auto subtract_pattern = pattern::optional<v1::Subtract>({convert_pattern, zp_reshape_pattern});// scale:auto scale_pattern = pattern::wrap_type<v0::Constant>();auto scale_convert_pattern = pattern::optional<v0::Convert>(scale_pattern);- auto scale_reshape_pattern = pattern::optional<v1::Reshape, v0::Unsqueeze>({scale_convert_pattern, any_input()});+ auto scale_reshape_pattern =+ pattern::optional<v1::Reshape, v0::Unsqueeze>({scale_convert_pattern, pattern::any_input()});auto multiply_pattern = pattern::wrap_type<v1::Multiply>({subtract_pattern, scale_reshape_pattern});- matcher_pass_callback callback = [=](Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pt_map = m.get_pattern_value_map();auto multiply = m.get_match_root();@@ -381,27 +386,27 @@ ov::pass::KeepDequantizationPrecision::KeepDequantizationPrecision(const elementreturn false;};- auto m = std::make_shared<Matcher>(multiply_pattern, "KeepDequantizationPrecision");+ auto m = std::make_shared<pattern::Matcher>(multiply_pattern, "KeepDequantizationPrecision");this->register_matcher(m, callback);}-ov::pass::MarkGatherSubgraph::MarkGatherSubgraph(const element::TypeVector& table_values_precisions,- const element::TypeVector& indices_precisions) {+MarkGatherSubgraph::MarkGatherSubgraph(const element::TypeVector& table_values_precisions,+ const element::TypeVector& indices_precisions) {MATCHER_SCOPE(MarkGatherSubgraph);// 1. Data input → (optional Convert) → (input to Gather[0])- auto data_input = wrap_type<op::v0::Constant>(check_precision(table_values_precisions));+ auto data_input = pattern::wrap_type<op::v0::Constant>(check_precision(table_values_precisions));auto data_convert = pattern::optional<op::v0::Convert>({data_input});// 2. Indices input → (optional Convert) → (input to Gather[1])- auto indices_input = wrap_type<op::v0::Constant, op::v0::Parameter>(check_precision(indices_precisions));+ auto indices_input = pattern::wrap_type<op::v0::Constant, op::v0::Parameter>(check_precision(indices_precisions));auto indices_convert = pattern::optional<op::v0::Convert>({indices_input});// Gather (fp, integral, any)- auto axis = any_input(value_matches("0"));- auto gather = wrap_type<op::v8::Gather>({data_convert, indices_convert, axis});+ auto axis = pattern::any_input(pattern::value_matches("0"));+ auto gather = pattern::wrap_type<op::v8::Gather>({data_convert, indices_convert, axis});- matcher_pass_callback callback = [=](Matcher& m) {+ matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pm = m.get_pattern_map();auto gather_node = pm.at(gather);if (transformation_callback(gather_node)) {@@ -421,6 +426,8 @@ ov::pass::MarkGatherSubgraph::MarkGatherSubgraph(const element::TypeVector& tablreturn false;};- auto m = std::make_shared<Matcher>(gather, "MarkGatherSubgraph");+ auto m = std::make_shared<pattern::Matcher>(gather, "MarkGatherSubgraph");this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/batch_norm_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/batch_norm_decomposition.cppindex ee04cb26052..6ac1d56d370 100644--- a/src/common/transformations/src/transformations/op_conversions/batch_norm_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/batch_norm_decomposition.cpp@@ -27,32 +27,39 @@using namespace ov;-ov::pass::BatchNormDecomposition::BatchNormDecomposition() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v5 = ov::op::v5;++namespace ov::pass {++BatchNormDecomposition::BatchNormDecomposition() {MATCHER_SCOPE(BatchNormDecomposition);- auto bn_1 = pattern::wrap_type<ov::op::v0::BatchNormInference>({pattern::any_input(),- pattern::any_input(),- pattern::any_input(pattern::has_static_rank()),- pattern::any_input(),- pattern::any_input()});- auto bn_5 = pattern::wrap_type<ov::op::v5::BatchNormInference>({pattern::any_input(pattern::has_static_rank()),- pattern::any_input(),- pattern::any_input(),- pattern::any_input(),- pattern::any_input()});- auto bn = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{bn_1, bn_5});-- matcher_pass_callback callback = [this](ov::pass::pattern::Matcher& m) {+ auto bn_1 = pattern::wrap_type<v0::BatchNormInference>({pattern::any_input(),+ pattern::any_input(),+ pattern::any_input(pattern::has_static_rank()),+ pattern::any_input(),+ pattern::any_input()});+ auto bn_5 = pattern::wrap_type<v5::BatchNormInference>({pattern::any_input(pattern::has_static_rank()),+ pattern::any_input(),+ pattern::any_input(),+ pattern::any_input(),+ pattern::any_input()});+ auto bn = std::make_shared<pattern::op::Or>(OutputVector{bn_1, bn_5});++ matcher_pass_callback callback = [this](pattern::Matcher& m) {auto m_bn = m.get_match_root();Output<Node> m_input, m_gamma, m_beta, m_mean, m_var;double eps;- if (auto m_bn_v1 = ov::as_type_ptr<ov::op::v0::BatchNormInference>(m_bn)) {+ if (auto m_bn_v1 = ov::as_type_ptr<v0::BatchNormInference>(m_bn)) {m_gamma = m_bn_v1->input_value(0);m_beta = m_bn_v1->input_value(1);m_input = m_bn_v1->input_value(2);m_mean = m_bn_v1->input_value(3);m_var = m_bn_v1->input_value(4);eps = m_bn_v1->get_eps_value();- } else if (auto m_bn_v5 = ov::as_type_ptr<ov::op::v5::BatchNormInference>(m_bn)) {+ } else if (auto m_bn_v5 = ov::as_type_ptr<v5::BatchNormInference>(m_bn)) {m_input = m_bn_v5->input_value(0);m_gamma = m_bn_v5->input_value(1);m_beta = m_bn_v5->input_value(2);@@ -65,27 +72,25 @@ ov::pass::BatchNormDecomposition::BatchNormDecomposition() {const auto& input_type = m_input.get_element_type();// scale_add = variance + eps- auto scale_add =- std::make_shared<ov::op::v1::Add>(m_var, ov::op::v0::Constant::create(input_type, Shape{}, {eps}));+ auto scale_add = std::make_shared<v1::Add>(m_var, v0::Constant::create(input_type, Shape{}, {eps}));// scale = sqrt(variance + eps)- auto scale = std::make_shared<ov::op::v0::Sqrt>(scale_add);+ auto scale = std::make_shared<v0::Sqrt>(scale_add);// Divide `gamma` by `sqrt(variance + eps)`- auto gamma_div_scale = std::make_shared<ov::op::v1::Divide>(m_gamma, scale);+ auto gamma_div_scale = std::make_shared<v1::Divide>(m_gamma, scale);int64_t dims_to_add = m_input.get_partial_shape().rank().get_length() - 2;- const auto one = ov::op::v0::Constant::create(element::i64, Shape{1}, {1});- const auto tail_shape_rank = ov::op::v0::Constant::create(element::i64, Shape{1}, {dims_to_add});- const auto tail_shape = std::make_shared<ov::op::v3::Broadcast>(one, tail_shape_rank);- const auto C_dim = std::make_shared<ov::op::v3::ShapeOf>(m_gamma);+ const auto one = v0::Constant::create(element::i64, Shape{1}, {1});+ const auto tail_shape_rank = v0::Constant::create(element::i64, Shape{1}, {dims_to_add});+ const auto tail_shape = std::make_shared<v3::Broadcast>(one, tail_shape_rank);+ const auto C_dim = std::make_shared<v3::ShapeOf>(m_gamma);// create new shape [1, C, 1, 1, ...]- const auto new_shape = std::make_shared<ov::op::v0::Concat>(OutputVector{one, C_dim, tail_shape}, 0);+ const auto new_shape = std::make_shared<v0::Concat>(OutputVector{one, C_dim, tail_shape}, 0);- std::shared_ptr<Node> gamma_div_scale_aligned =- std::make_shared<ov::op::v1::Reshape>(gamma_div_scale, new_shape, true);- std::shared_ptr<Node> beta_aligned = std::make_shared<ov::op::v1::Reshape>(m_beta, new_shape, true);- std::shared_ptr<Node> mean_aligned = std::make_shared<ov::op::v1::Reshape>(m_mean, new_shape, true);- auto mul_const = ov::op::v0::Constant::create(mean_aligned->get_output_element_type(0), Shape{}, {-1});- std::shared_ptr<Node> mean_negative = std::make_shared<ov::op::v1::Multiply>(mean_aligned, mul_const);+ std::shared_ptr<Node> gamma_div_scale_aligned = std::make_shared<v1::Reshape>(gamma_div_scale, new_shape, true);+ std::shared_ptr<Node> beta_aligned = std::make_shared<v1::Reshape>(m_beta, new_shape, true);+ std::shared_ptr<Node> mean_aligned = std::make_shared<v1::Reshape>(m_mean, new_shape, true);+ auto mul_const = v0::Constant::create(mean_aligned->get_output_element_type(0), Shape{}, {-1});+ std::shared_ptr<Node> mean_negative = std::make_shared<v1::Multiply>(mean_aligned, mul_const);if (auto constant = ov::util::get_constant_from_source(beta_aligned))beta_aligned = constant;@@ -95,11 +100,11 @@ ov::pass::BatchNormDecomposition::BatchNormDecomposition() {gamma_div_scale_aligned = constant;// input_sub_mean = input + mean * -1- auto input_sub_mean = register_new_node<ov::op::v1::Add>(m_input, mean_negative);+ auto input_sub_mean = register_new_node<v1::Add>(m_input, mean_negative);// Multiply `input - mean` and `gamma / sqrt(variance + eps)`- auto mul = register_new_node<ov::op::v1::Multiply>(input_sub_mean, gamma_div_scale_aligned);+ auto mul = register_new_node<v1::Multiply>(input_sub_mean, gamma_div_scale_aligned);// Add `(input - mean) * gamma / sqrt(variance + eps)` and `beta`- auto add = register_new_node<ov::op::v1::Add>(mul, beta_aligned);+ auto add = register_new_node<v1::Add>(mul, beta_aligned);add->set_friendly_name(m_bn->get_friendly_name());@@ -125,6 +130,8 @@ ov::pass::BatchNormDecomposition::BatchNormDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(bn, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(bn, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/bidirectional_sequences_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/bidirectional_sequences_decomposition.cppindex 3dbc386e49a..dc1f152dfe9 100644--- a/src/common/transformations/src/transformations/op_conversions/bidirectional_sequences_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/bidirectional_sequences_decomposition.cpp@@ -17,12 +17,18 @@#include "openvino/op/split.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceDecomposition() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v5 = ov::op::v5;++namespace ov::pass {++BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceDecomposition() {MATCHER_SCOPE(BidirectionalLSTMSequenceDecomposition);- auto lstm_sequence_ov = ov::pass::pattern::wrap_type<ov::op::v5::LSTMSequence>();+ auto lstm_sequence_ov = pattern::wrap_type<v5::LSTMSequence>();matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto lstm_sequence = ov::as_type_ptr<ov::op::v5::LSTMSequence>(m.get_match_root());+ auto lstm_sequence = ov::as_type_ptr<v5::LSTMSequence>(m.get_match_root());if (!lstm_sequence || transformation_callback(lstm_sequence)) {return false;}@@ -30,50 +36,48 @@ ov::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceDecomif (lstm_sequence->get_direction() != ov::op::RecurrentSequenceDirection::BIDIRECTIONAL)return false;- auto axis_0 = ov::op::v0::Constant::create(element::i64, Shape{}, {0});- auto axis_1 = ov::op::v0::Constant::create(element::i64, Shape{}, {1});- auto H = std::make_shared<ov::op::v1::Split>(lstm_sequence->input_value(1), axis_1, 2);- auto C = std::make_shared<ov::op::v1::Split>(lstm_sequence->input_value(2), axis_1, 2);- auto W = std::make_shared<ov::op::v1::Split>(lstm_sequence->input_value(4), axis_0, 2);- auto R = std::make_shared<ov::op::v1::Split>(lstm_sequence->input_value(5), axis_0, 2);- auto B = std::make_shared<ov::op::v1::Split>(lstm_sequence->input_value(6), axis_0, 2);- auto lstm_sequence_forward =- std::make_shared<ov::op::v5::LSTMSequence>(lstm_sequence->input_value(0),- H->output(0),- C->output(0),- lstm_sequence->input_value(3),- W->output(0),- R->output(0),- B->output(0),- lstm_sequence->get_hidden_size(),- ov::op::RecurrentSequenceDirection::FORWARD,- lstm_sequence->get_activations_alpha(),- lstm_sequence->get_activations_beta(),- lstm_sequence->get_activations(),- lstm_sequence->get_clip());-- auto lstm_sequence_reverse =- std::make_shared<ov::op::v5::LSTMSequence>(lstm_sequence->input_value(0),- H->output(1),- C->output(1),- lstm_sequence->input_value(3),- W->output(1),- R->output(1),- B->output(1),- lstm_sequence->get_hidden_size(),- ov::op::RecurrentSequenceDirection::REVERSE,- lstm_sequence->get_activations_alpha(),- lstm_sequence->get_activations_beta(),- lstm_sequence->get_activations(),- lstm_sequence->get_clip());-- auto concat_0 = std::make_shared<ov::op::v0::Concat>(+ auto axis_0 = v0::Constant::create(element::i64, Shape{}, {0});+ auto axis_1 = v0::Constant::create(element::i64, Shape{}, {1});+ auto H = std::make_shared<v1::Split>(lstm_sequence->input_value(1), axis_1, 2);+ auto C = std::make_shared<v1::Split>(lstm_sequence->input_value(2), axis_1, 2);+ auto W = std::make_shared<v1::Split>(lstm_sequence->input_value(4), axis_0, 2);+ auto R = std::make_shared<v1::Split>(lstm_sequence->input_value(5), axis_0, 2);+ auto B = std::make_shared<v1::Split>(lstm_sequence->input_value(6), axis_0, 2);+ auto lstm_sequence_forward = std::make_shared<v5::LSTMSequence>(lstm_sequence->input_value(0),+ H->output(0),+ C->output(0),+ lstm_sequence->input_value(3),+ W->output(0),+ R->output(0),+ B->output(0),+ lstm_sequence->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::FORWARD,+ lstm_sequence->get_activations_alpha(),+ lstm_sequence->get_activations_beta(),+ lstm_sequence->get_activations(),+ lstm_sequence->get_clip());++ auto lstm_sequence_reverse = std::make_shared<v5::LSTMSequence>(lstm_sequence->input_value(0),+ H->output(1),+ C->output(1),+ lstm_sequence->input_value(3),+ W->output(1),+ R->output(1),+ B->output(1),+ lstm_sequence->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::REVERSE,+ lstm_sequence->get_activations_alpha(),+ lstm_sequence->get_activations_beta(),+ lstm_sequence->get_activations(),+ lstm_sequence->get_clip());++ auto concat_0 = std::make_shared<v0::Concat>(OutputVector{lstm_sequence_forward->output(0), lstm_sequence_reverse->output(0)},1);- auto concat_1 = std::make_shared<ov::op::v0::Concat>(+ auto concat_1 = std::make_shared<v0::Concat>(OutputVector{lstm_sequence_forward->output(1), lstm_sequence_reverse->output(1)},1);- auto concat_2 = std::make_shared<ov::op::v0::Concat>(+ auto concat_2 = std::make_shared<v0::Concat>(OutputVector{lstm_sequence_forward->output(2), lstm_sequence_reverse->output(2)},1);ov::copy_runtime_info(@@ -86,16 +90,16 @@ ov::pass::BidirectionalLSTMSequenceDecomposition::BidirectionalLSTMSequenceDecomreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(lstm_sequence_ov, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(lstm_sequence_ov, matcher_name);this->register_matcher(m, callback);}-ov::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDecomposition() {+BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDecomposition() {MATCHER_SCOPE(BidirectionalGRUSequenceDecomposition);- auto gru_sequence_ov = ov::pass::pattern::wrap_type<ov::op::v5::GRUSequence>();+ auto gru_sequence_ov = pattern::wrap_type<v5::GRUSequence>();matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto gru_sequence = ov::as_type_ptr<ov::op::v5::GRUSequence>(m.get_match_root());+ auto gru_sequence = ov::as_type_ptr<v5::GRUSequence>(m.get_match_root());if (!gru_sequence || transformation_callback(gru_sequence)) {return false;}@@ -103,48 +107,46 @@ ov::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDecompoif (gru_sequence->get_direction() != ov::op::RecurrentSequenceDirection::BIDIRECTIONAL)return false;- auto axis_0 = ov::op::v0::Constant::create(element::i64, Shape{}, {0});- auto axis_1 = ov::op::v0::Constant::create(element::i64, Shape{}, {1});- auto H = std::make_shared<ov::op::v1::Split>(gru_sequence->input_value(1), axis_1, 2);- auto W = std::make_shared<ov::op::v1::Split>(gru_sequence->input_value(3), axis_0, 2);- auto R = std::make_shared<ov::op::v1::Split>(gru_sequence->input_value(4), axis_0, 2);- auto B = std::make_shared<ov::op::v1::Split>(gru_sequence->input_value(5), axis_0, 2);- auto gru_sequence_forward =- std::make_shared<ov::op::v5::GRUSequence>(gru_sequence->input_value(0),- H->output(0),- gru_sequence->input_value(2),- W->output(0),- R->output(0),- B->output(0),- gru_sequence->get_hidden_size(),- ov::op::RecurrentSequenceDirection::FORWARD,- gru_sequence->get_activations(),- gru_sequence->get_activations_alpha(),- gru_sequence->get_activations_beta(),- gru_sequence->get_clip(),- gru_sequence->get_linear_before_reset());-- auto gru_sequence_reverse =- std::make_shared<ov::op::v5::GRUSequence>(gru_sequence->input_value(0),- H->output(1),- gru_sequence->input_value(2),- W->output(1),- R->output(1),- B->output(1),- gru_sequence->get_hidden_size(),- ov::op::RecurrentSequenceDirection::REVERSE,- gru_sequence->get_activations(),- gru_sequence->get_activations_alpha(),- gru_sequence->get_activations_beta(),- gru_sequence->get_clip(),- gru_sequence->get_linear_before_reset());-- auto concat_0 = std::make_shared<ov::op::v0::Concat>(- OutputVector{gru_sequence_forward->output(0), gru_sequence_reverse->output(0)},- 1);- auto concat_1 = std::make_shared<ov::op::v0::Concat>(- OutputVector{gru_sequence_forward->output(1), gru_sequence_reverse->output(1)},- 1);+ auto axis_0 = v0::Constant::create(element::i64, Shape{}, {0});+ auto axis_1 = v0::Constant::create(element::i64, Shape{}, {1});+ auto H = std::make_shared<v1::Split>(gru_sequence->input_value(1), axis_1, 2);+ auto W = std::make_shared<v1::Split>(gru_sequence->input_value(3), axis_0, 2);+ auto R = std::make_shared<v1::Split>(gru_sequence->input_value(4), axis_0, 2);+ auto B = std::make_shared<v1::Split>(gru_sequence->input_value(5), axis_0, 2);+ auto gru_sequence_forward = std::make_shared<v5::GRUSequence>(gru_sequence->input_value(0),+ H->output(0),+ gru_sequence->input_value(2),+ W->output(0),+ R->output(0),+ B->output(0),+ gru_sequence->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::FORWARD,+ gru_sequence->get_activations(),+ gru_sequence->get_activations_alpha(),+ gru_sequence->get_activations_beta(),+ gru_sequence->get_clip(),+ gru_sequence->get_linear_before_reset());++ auto gru_sequence_reverse = std::make_shared<v5::GRUSequence>(gru_sequence->input_value(0),+ H->output(1),+ gru_sequence->input_value(2),+ W->output(1),+ R->output(1),+ B->output(1),+ gru_sequence->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::REVERSE,+ gru_sequence->get_activations(),+ gru_sequence->get_activations_alpha(),+ gru_sequence->get_activations_beta(),+ gru_sequence->get_clip(),+ gru_sequence->get_linear_before_reset());++ auto concat_0 =+ std::make_shared<v0::Concat>(OutputVector{gru_sequence_forward->output(0), gru_sequence_reverse->output(0)},+ 1);+ auto concat_1 =+ std::make_shared<v0::Concat>(OutputVector{gru_sequence_forward->output(1), gru_sequence_reverse->output(1)},+ 1);ov::copy_runtime_info(gru_sequence,{H, W, R, B, gru_sequence_forward, gru_sequence_reverse, concat_0, concat_1});concat_0->set_friendly_name(gru_sequence->get_friendly_name() + ".0");@@ -153,16 +155,16 @@ ov::pass::BidirectionalGRUSequenceDecomposition::BidirectionalGRUSequenceDecomporeturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(gru_sequence_ov, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(gru_sequence_ov, matcher_name);this->register_matcher(m, callback);}-ov::pass::BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDecomposition() {+BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDecomposition() {MATCHER_SCOPE(BidirectionalRNNSequenceDecomposition);- auto rnn_sequence_ov = ov::pass::pattern::wrap_type<ov::op::v5::RNNSequence>();+ auto rnn_sequence_ov = pattern::wrap_type<v5::RNNSequence>();matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto rnn_sequence = ov::as_type_ptr<ov::op::v5::RNNSequence>(m.get_match_root());+ auto rnn_sequence = ov::as_type_ptr<v5::RNNSequence>(m.get_match_root());if (!rnn_sequence || transformation_callback(rnn_sequence)) {return false;}@@ -170,46 +172,44 @@ ov::pass::BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDecompoif (rnn_sequence->get_direction() != ov::op::RecurrentSequenceDirection::BIDIRECTIONAL)return false;- auto axis_0 = ov::op::v0::Constant::create(element::i64, Shape{}, {0});- auto axis_1 = ov::op::v0::Constant::create(element::i64, Shape{}, {1});- auto H = std::make_shared<ov::op::v1::Split>(rnn_sequence->input_value(1), axis_1, 2);- auto W = std::make_shared<ov::op::v1::Split>(rnn_sequence->input_value(3), axis_0, 2);- auto R = std::make_shared<ov::op::v1::Split>(rnn_sequence->input_value(4), axis_0, 2);- auto B = std::make_shared<ov::op::v1::Split>(rnn_sequence->input_value(5), axis_0, 2);- auto rnn_sequence_forward =- std::make_shared<ov::op::v5::RNNSequence>(rnn_sequence->input_value(0),- H->output(0),- rnn_sequence->input_value(2),- W->output(0),- R->output(0),- B->output(0),- rnn_sequence->get_hidden_size(),- ov::op::RecurrentSequenceDirection::FORWARD,- rnn_sequence->get_activations(),- rnn_sequence->get_activations_alpha(),- rnn_sequence->get_activations_beta(),- rnn_sequence->get_clip());-- auto rnn_sequence_reverse =- std::make_shared<ov::op::v5::RNNSequence>(rnn_sequence->input_value(0),- H->output(1),- rnn_sequence->input_value(2),- W->output(1),- R->output(1),- B->output(1),- rnn_sequence->get_hidden_size(),- ov::op::RecurrentSequenceDirection::REVERSE,- rnn_sequence->get_activations(),- rnn_sequence->get_activations_alpha(),- rnn_sequence->get_activations_beta(),- rnn_sequence->get_clip());-- auto concat_0 = std::make_shared<ov::op::v0::Concat>(- OutputVector{rnn_sequence_forward->output(0), rnn_sequence_reverse->output(0)},- 1);- auto concat_1 = std::make_shared<ov::op::v0::Concat>(- OutputVector{rnn_sequence_forward->output(1), rnn_sequence_reverse->output(1)},- 1);+ auto axis_0 = v0::Constant::create(element::i64, Shape{}, {0});+ auto axis_1 = v0::Constant::create(element::i64, Shape{}, {1});+ auto H = std::make_shared<v1::Split>(rnn_sequence->input_value(1), axis_1, 2);+ auto W = std::make_shared<v1::Split>(rnn_sequence->input_value(3), axis_0, 2);+ auto R = std::make_shared<v1::Split>(rnn_sequence->input_value(4), axis_0, 2);+ auto B = std::make_shared<v1::Split>(rnn_sequence->input_value(5), axis_0, 2);+ auto rnn_sequence_forward = std::make_shared<v5::RNNSequence>(rnn_sequence->input_value(0),+ H->output(0),+ rnn_sequence->input_value(2),+ W->output(0),+ R->output(0),+ B->output(0),+ rnn_sequence->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::FORWARD,+ rnn_sequence->get_activations(),+ rnn_sequence->get_activations_alpha(),+ rnn_sequence->get_activations_beta(),+ rnn_sequence->get_clip());++ auto rnn_sequence_reverse = std::make_shared<v5::RNNSequence>(rnn_sequence->input_value(0),+ H->output(1),+ rnn_sequence->input_value(2),+ W->output(1),+ R->output(1),+ B->output(1),+ rnn_sequence->get_hidden_size(),+ ov::op::RecurrentSequenceDirection::REVERSE,+ rnn_sequence->get_activations(),+ rnn_sequence->get_activations_alpha(),+ rnn_sequence->get_activations_beta(),+ rnn_sequence->get_clip());++ auto concat_0 =+ std::make_shared<v0::Concat>(OutputVector{rnn_sequence_forward->output(0), rnn_sequence_reverse->output(0)},+ 1);+ auto concat_1 =+ std::make_shared<v0::Concat>(OutputVector{rnn_sequence_forward->output(1), rnn_sequence_reverse->output(1)},+ 1);ov::copy_runtime_info(rnn_sequence,{H, W, R, B, rnn_sequence_forward, rnn_sequence_reverse, concat_0, concat_1});concat_0->set_friendly_name(rnn_sequence->get_friendly_name() + ".0");@@ -218,6 +218,8 @@ ov::pass::BidirectionalRNNSequenceDecomposition::BidirectionalRNNSequenceDecomporeturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(rnn_sequence_ov, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(rnn_sequence_ov, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_avgpool_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_avgpool_downgrade.cppindex da0a0582f2e..e2e29017cb9 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_avgpool_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_avgpool_downgrade.cpp@@ -20,13 +20,20 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ConvertAvgPool14ToAvgPool1::ConvertAvgPool14ToAvgPool1() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v14 = ov::op::v14;++namespace ov::pass {++ConvertAvgPool14ToAvgPool1::ConvertAvgPool14ToAvgPool1() {MATCHER_SCOPE(ConvertAvgPool14ToAvgPool1);- const auto avg_pool_v14_pattern = pattern::wrap_type<ov::op::v14::AvgPool>();+ const auto avg_pool_v14_pattern = pattern::wrap_type<v14::AvgPool>();const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto avg_pool_v14 = ov::as_type_ptr<ov::op::v14::AvgPool>(m.get_match_root());+ const auto avg_pool_v14 = ov::as_type_ptr<v14::AvgPool>(m.get_match_root());if (!avg_pool_v14 || transformation_callback(avg_pool_v14)) {return false;}@@ -41,13 +48,13 @@ ov::pass::ConvertAvgPool14ToAvgPool1::ConvertAvgPool14ToAvgPool1() {ov::Shape pads_end;ov::Output<ov::Node> new_input;- using ov::op::v0::Constant;- using ov::op::v0::Concat;- using ov::op::v1::Pad;- using ov::op::v1::Subtract;- using ov::op::v1::ConvertLike;- using ov::op::v3::Broadcast;- using ov::op::v3::ShapeOf;+ using v0::Constant;+ using v0::Concat;+ using v1::Pad;+ using v1::Subtract;+ using v1::ConvertLike;+ using v3::Broadcast;+ using v3::ShapeOf;using ov::op::v4::Range;if (!exclude_pad && rounding_type_v14 == ov::op::RoundingType::CEIL_TORCH) {@@ -65,12 +72,10 @@ ov::pass::ConvertAvgPool14ToAvgPool1::ConvertAvgPool14ToAvgPool1() {const auto pads_len = node_registry.make<Constant>(element::i64, Shape{}, pads_begin_v14.size());const auto pads_diff = node_registry.make<Subtract>(rank, pads_len);const auto pads_remaining = node_registry.make<Broadcast>(zero_i64, pads_diff);- const auto pads_begin_v1 = node_registry.make<ov::op::v0::Concat>(- OutputVector{std::move(pads_remaining), std::move(pads_begin_node)},- 0);- const auto pads_end_v1 = node_registry.make<ov::op::v0::Concat>(- OutputVector{std::move(pads_remaining), std::move(pads_begin_node)},- 0);+ const auto pads_begin_v1 =+ node_registry.make<v0::Concat>(OutputVector{std::move(pads_remaining), std::move(pads_begin_node)}, 0);+ const auto pads_end_v1 =+ node_registry.make<v0::Concat>(OutputVector{std::move(pads_remaining), std::move(pads_begin_node)}, 0);const auto pad_node =node_registry.make<Pad>(input, pads_begin_v1, pads_end_v1, zero_node, ov::op::PadMode::CONSTANT);pads_begin = Shape(pads_begin_v14.size(), 0);@@ -81,14 +86,14 @@ ov::pass::ConvertAvgPool14ToAvgPool1::ConvertAvgPool14ToAvgPool1() {pads_end = avg_pool_v14->get_pads_end();new_input = input;}- const auto avg_pool_v1 = node_registry.make<ov::op::v1::AvgPool>(new_input,- avg_pool_v14->get_strides(),- pads_begin,- pads_end,- avg_pool_v14->get_kernel(),- exclude_pad,- rounding_type_v1,- avg_pool_v14->get_auto_pad());+ const auto avg_pool_v1 = node_registry.make<v1::AvgPool>(new_input,+ avg_pool_v14->get_strides(),+ pads_begin,+ pads_end,+ avg_pool_v14->get_kernel(),+ exclude_pad,+ rounding_type_v1,+ avg_pool_v14->get_auto_pad());avg_pool_v1->set_friendly_name(avg_pool_v14->get_friendly_name());copy_runtime_info(avg_pool_v14, node_registry.get());replace_node(avg_pool_v14, avg_pool_v1);@@ -98,3 +103,5 @@ ov::pass::ConvertAvgPool14ToAvgPool1::ConvertAvgPool14ToAvgPool1() {auto m = std::make_shared<pattern::Matcher>(avg_pool_v14_pattern, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp b/src/common/transformations/src/transformations/op_conversions/convert_batch_to_space.cppindex 375a9e623d7..79dca2e9380 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_batch_to_space.cpp@@ -30,11 +30,18 @@using namespace std;using namespace ov::element;-void ov::pass::ConvertBatchToSpace::convert_batch_to_space() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v8 = ov::op::v8;++namespace ov::pass {++void ConvertBatchToSpace::convert_batch_to_space() {MATCHER_SCOPE(ConvertBatchToSpace_convert_batch_to_space);- const auto batch_to_space = pattern::wrap_type<ov::op::v1::BatchToSpace>();+ const auto batch_to_space = pattern::wrap_type<v1::BatchToSpace>();matcher_pass_callback callback = [this](pattern::Matcher& m) {- const auto batch_to_space = ov::as_type_ptr<ov::op::v1::BatchToSpace>(m.get_match_root());+ const auto batch_to_space = ov::as_type_ptr<v1::BatchToSpace>(m.get_match_root());if (!batch_to_space || transformation_callback(batch_to_space)) {return false;}@@ -59,24 +66,23 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space() {// so as appropriate chunks of data where close to their destination place.// Finally squeeze data from respective dimensions- const auto zero = rg.make<ov::op::v0::Constant>(i64, Shape{1}, 0);- const auto shape_of_data = rg.make<ov::op::v3::ShapeOf>(data, block.get_element_type());- const auto batch = rg.make<ov::op::v8::Gather>(shape_of_data, zero, zero);- const auto block_prod = rg.make<ov::op::v1::ReduceProd>(block, zero);- const auto batch_div = rg.make<ov::op::v1::Divide>(batch, block_prod);+ const auto zero = rg.make<v0::Constant>(i64, Shape{1}, 0);+ const auto shape_of_data = rg.make<v3::ShapeOf>(data, block.get_element_type());+ const auto batch = rg.make<v8::Gather>(shape_of_data, zero, zero);+ const auto block_prod = rg.make<v1::ReduceProd>(block, zero);+ const auto batch_div = rg.make<v1::Divide>(batch, block_prod);// note: B_0 is expected to be 1.// x' = reshape(`data`, [B_1, ..., B_{N - 1}, batch / (B_1 * ... B_{N - 1}), D_1, D_2, ...,// D_{N - 1}]),// where B_i = block_shape[i]- const auto one = rg.make<ov::op::v0::Constant>(i64, Shape{1}, 1);- const auto end = rg.make<ov::op::v0::Constant>(i64, Shape{1}, block_length);- const auto block_tail = rg.make<ov::op::v8::Slice>(block, one, end, one);- const auto data_shape_tail = rg.make<ov::op::v8::Slice>(shape_of_data, one, end, one);- const auto dispersed_shape =- rg.make<ov::op::v0::Concat>(OutputVector{block_tail, batch_div, data_shape_tail}, 0);+ const auto one = rg.make<v0::Constant>(i64, Shape{1}, 1);+ const auto end = rg.make<v0::Constant>(i64, Shape{1}, block_length);+ const auto block_tail = rg.make<v8::Slice>(block, one, end, one);+ const auto data_shape_tail = rg.make<v8::Slice>(shape_of_data, one, end, one);+ const auto dispersed_shape = rg.make<v0::Concat>(OutputVector{block_tail, batch_div, data_shape_tail}, 0);const bool special_zero = false;- shared_ptr<Node> flat_node = rg.make<ov::op::v1::Reshape>(data, dispersed_shape, special_zero);+ shared_ptr<Node> flat_node = rg.make<v1::Reshape>(data, dispersed_shape, special_zero);// calculate axes to transpose// x'' = transpose(x', [N, N + 1, 0, N + 2, 1, ..., N + N - 1, N - 1])@@ -85,14 +91,14 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space() {axes_order.push_back(i + block_length);axes_order.push_back(i);}- const auto axes_order_const = rg.make<ov::op::v0::Constant>(i64, Shape{axes_order.size()}, axes_order);- flat_node = rg.make<ov::op::v1::Transpose>(flat_node, axes_order_const);+ const auto axes_order_const = rg.make<v0::Constant>(i64, Shape{axes_order.size()}, axes_order);+ flat_node = rg.make<v1::Transpose>(flat_node, axes_order_const);// x''' = reshape(x'', [batch / (B_1 * ... * B_{N - 1}), D_1 * B_1, D_2 * B_2, ... , D_{N - 1}// * B_{N - 1}])- const auto squeezed_shape_tail = rg.make<ov::op::v1::Multiply>(block_tail, data_shape_tail);- const auto squeezed_shape = rg.make<ov::op::v0::Concat>(OutputVector{batch_div, squeezed_shape_tail}, 0);- flat_node = rg.make<ov::op::v1::Reshape>(flat_node, squeezed_shape, special_zero);+ const auto squeezed_shape_tail = rg.make<v1::Multiply>(block_tail, data_shape_tail);+ const auto squeezed_shape = rg.make<v0::Concat>(OutputVector{batch_div, squeezed_shape_tail}, 0);+ flat_node = rg.make<v1::Reshape>(flat_node, squeezed_shape, special_zero);// Crop the start and end of dimensions according to `crops_begin`, `crops_end` to produce// the output of shape:@@ -100,12 +106,12 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space() {// `y = [batch / (B_1 * ... * B_{N - 1}), crop(D_1 * B_1, crops_begin[1], crops_end[1]),// crop(D_2 * B_2, crops_begin[2], crops_end[2]), ... ,// crop(D_{N - 1} * B_{N - 1}, crops_begin[N - 1], crops_end[N - 1])]`- const auto shape_of_flat_node = rg.make<ov::op::v3::ShapeOf>(flat_node, crops_end.get_element_type());- const auto upperbounds = rg.make<ov::op::v1::Subtract>(shape_of_flat_node, crops_end);+ const auto shape_of_flat_node = rg.make<v3::ShapeOf>(flat_node, crops_end.get_element_type());+ const auto upperbounds = rg.make<v1::Subtract>(shape_of_flat_node, crops_end);const auto begin_mask = vector<int64_t>(data_shape_rank.get_length(), 0);const auto& end_mask = begin_mask;- flat_node = rg.make<ov::op::v1::StridedSlice>(flat_node, crops_begin, upperbounds, begin_mask, end_mask);+ flat_node = rg.make<v1::StridedSlice>(flat_node, crops_begin, upperbounds, begin_mask, end_mask);flat_node->set_friendly_name(batch_to_space->get_friendly_name());copy_runtime_info(batch_to_space, rg.get());@@ -117,11 +123,11 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space() {this->register_matcher(m, callback);}-void ov::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() {+void ConvertBatchToSpace::convert_batch_to_space_by_elements() {MATCHER_SCOPE(ConvertBatchToSpace_convert_batch_to_space_by_elements);- const auto batch_to_space = pattern::wrap_type<ov::op::v1::BatchToSpace>();+ const auto batch_to_space = pattern::wrap_type<v1::BatchToSpace>();matcher_pass_callback callback = [this](pattern::Matcher& m) {- const auto batch_to_space = ov::as_type_ptr<ov::op::v1::BatchToSpace>(m.get_match_root());+ const auto batch_to_space = ov::as_type_ptr<v1::BatchToSpace>(m.get_match_root());if (!batch_to_space || transformation_callback(batch_to_space)) {return false;}@@ -143,14 +149,14 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() {const auto block_length = static_cast<int64_t>(block.get_shape()[0]);NodeRegistry rg;- const auto zero = rg.make<ov::op::v0::Constant>(i64, Shape{1}, 0);- const auto one = rg.make<ov::op::v0::Constant>(i64, Shape{1}, 1);- const auto two = rg.make<ov::op::v0::Constant>(i64, Shape{1}, 2);- const auto int_max = rg.make<ov::op::v0::Constant>(i64, Shape{1}, INT_MAX);-- const auto shape_of_data = rg.make<ov::op::v3::ShapeOf>(data, block.get_element_type());- const auto et_zero = rg.make<ov::op::v0::Constant>(block.get_element_type(), Shape{1}, 0);- shared_ptr<Node> dispersed_shape = rg.make<ov::op::v0::Concat>(OutputVector{et_zero, shape_of_data}, 0);+ const auto zero = rg.make<v0::Constant>(i64, Shape{1}, 0);+ const auto one = rg.make<v0::Constant>(i64, Shape{1}, 1);+ const auto two = rg.make<v0::Constant>(i64, Shape{1}, 2);+ const auto int_max = rg.make<v0::Constant>(i64, Shape{1}, INT_MAX);++ const auto shape_of_data = rg.make<v3::ShapeOf>(data, block.get_element_type());+ const auto et_zero = rg.make<v0::Constant>(block.get_element_type(), Shape{1}, 0);+ shared_ptr<Node> dispersed_shape = rg.make<v0::Concat>(OutputVector{et_zero, shape_of_data}, 0);shared_ptr<Node> squeezed_shape = shape_of_data;shared_ptr<Node> flat_node = data.get_node_shared_ptr();@@ -163,27 +169,27 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() {n.get_shape()[0] == 0;}),nodes.end());- return rg.make<ov::op::v0::Concat>(nodes, 0);+ return rg.make<v0::Concat>(nodes, 0);};shared_ptr<Node> div;for (int64_t b_idx = 1; b_idx < block_length; ++b_idx) {- const auto block_index = rg.make<ov::op::v0::Constant>(i64, Shape{1}, b_idx);- const auto block_index_next = rg.make<ov::op::v0::Constant>(i64, Shape{1}, b_idx + 1);- const auto block_value = rg.make<ov::op::v8::Gather>(block, block_index, zero);+ const auto block_index = rg.make<v0::Constant>(i64, Shape{1}, b_idx);+ const auto block_index_next = rg.make<v0::Constant>(i64, Shape{1}, b_idx + 1);+ const auto block_value = rg.make<v8::Gather>(block, block_index, zero);// dispersed_shape[0] = block[b_idx];// dispersed_shape[1] /= block[b_idx];if (!div) {- const auto batch = rg.make<ov::op::v8::Gather>(shape_of_data, zero, zero);- div = rg.make<ov::op::v1::Divide>(batch, block_value);+ const auto batch = rg.make<v8::Gather>(shape_of_data, zero, zero);+ div = rg.make<v1::Divide>(batch, block_value);} else {- div = rg.make<ov::op::v1::Divide>(div, block_value);+ div = rg.make<v1::Divide>(div, block_value);}- auto ds_tail = rg.make<ov::op::v8::Slice>(dispersed_shape, two, int_max, one);+ auto ds_tail = rg.make<v8::Slice>(dispersed_shape, two, int_max, one);dispersed_shape = make_concat({block_value, div, ds_tail});constexpr auto special_zero = false;- flat_node = rg.make<ov::op::v1::Reshape>(flat_node, dispersed_shape, special_zero);+ flat_node = rg.make<v1::Reshape>(flat_node, dispersed_shape, special_zero);vector<int64_t> axes_order(block_length + 1);int64_t val = 1;@@ -195,34 +201,32 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() {val++;}}- const auto axes_order_const = rg.make<ov::op::v0::Constant>(i64, Shape{axes_order.size()}, axes_order);- flat_node = rg.make<ov::op::v1::Transpose>(flat_node, axes_order_const);+ const auto axes_order_const = rg.make<v0::Constant>(i64, Shape{axes_order.size()}, axes_order);+ flat_node = rg.make<v1::Transpose>(flat_node, axes_order_const);// squeezed_shape[0] = dispersed_shape[1];// squeezed_shape[b_idx] *= block[b_idx];- const auto sq_slice = rg.make<ov::op::v8::Slice>(squeezed_shape, one, block_index, one);- const auto sq_bidx_dim = rg.make<ov::op::v8::Gather>(squeezed_shape, block_index, zero);- const auto sq_mul = rg.make<ov::op::v1::Multiply>(sq_bidx_dim, block_value);- const auto sq_shape_tail = rg.make<ov::op::v8::Slice>(squeezed_shape, block_index_next, int_max, one);+ const auto sq_slice = rg.make<v8::Slice>(squeezed_shape, one, block_index, one);+ const auto sq_bidx_dim = rg.make<v8::Gather>(squeezed_shape, block_index, zero);+ const auto sq_mul = rg.make<v1::Multiply>(sq_bidx_dim, block_value);+ const auto sq_shape_tail = rg.make<v8::Slice>(squeezed_shape, block_index_next, int_max, one);squeezed_shape.reset();squeezed_shape = make_concat({div, sq_slice, sq_mul, sq_shape_tail});- flat_node = rg.make<ov::op::v1::Reshape>(flat_node, squeezed_shape, special_zero);+ flat_node = rg.make<v1::Reshape>(flat_node, squeezed_shape, special_zero);// dispersed_shape[b_idx + 1] = squeezed_shape[b_idx];- const auto ds_front = rg.make<ov::op::v8::Slice>(dispersed_shape, zero, block_index_next, one);- ds_tail = rg.make<ov::op::v8::Slice>(dispersed_shape,- rg.make<ov::op::v0::Constant>(i64, Shape{1}, b_idx + 2),- int_max,- one);+ const auto ds_front = rg.make<v8::Slice>(dispersed_shape, zero, block_index_next, one);+ ds_tail =+ rg.make<v8::Slice>(dispersed_shape, rg.make<v0::Constant>(i64, Shape{1}, b_idx + 2), int_max, one);dispersed_shape = make_concat({ds_front, sq_mul, ds_tail});}- const auto shape_of_flat_node = rg.make<ov::op::v3::ShapeOf>(flat_node, crops_end.get_element_type());- const auto upperbounds = rg.make<ov::op::v1::Subtract>(shape_of_flat_node, crops_end);+ const auto shape_of_flat_node = rg.make<v3::ShapeOf>(flat_node, crops_end.get_element_type());+ const auto upperbounds = rg.make<v1::Subtract>(shape_of_flat_node, crops_end);const auto begin_mask = vector<int64_t>(data_shape_rank.get_length(), 0);const auto& end_mask = begin_mask;- flat_node = rg.make<ov::op::v1::StridedSlice>(flat_node, crops_begin, upperbounds, begin_mask, end_mask);+ flat_node = rg.make<v1::StridedSlice>(flat_node, crops_begin, upperbounds, begin_mask, end_mask);flat_node->set_friendly_name(batch_to_space->get_friendly_name());copy_runtime_info(batch_to_space, rg.get());@@ -233,3 +237,5 @@ void ov::pass::ConvertBatchToSpace::convert_batch_to_space_by_elements() {const auto m = make_shared<pattern::Matcher>(batch_to_space, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_bitwise_to_logical_bool.cpp b/src/common/transformations/src/transformations/op_conversions/convert_bitwise_to_logical_bool.cppindex c45d3a50f1f..3271ab2a68b 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_bitwise_to_logical_bool.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_bitwise_to_logical_bool.cpp@@ -18,21 +18,24 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ConvertBitwiseAndToLogicalAnd::ConvertBitwiseAndToLogicalAnd() {+namespace v1 = ov::op::v1;+namespace v13 = ov::op::v13;++namespace ov::pass {++ConvertBitwiseAndToLogicalAnd::ConvertBitwiseAndToLogicalAnd() {MATCHER_SCOPE(ConvertBitwiseAndToLogicalAnd);- auto pattern =- pattern::wrap_type<ov::op::v13::BitwiseAnd>({pattern::any_input(pattern::type_matches(element::boolean)),- pattern::any_input(pattern::type_matches(element::boolean))});+ auto pattern = pattern::wrap_type<v13::BitwiseAnd>({pattern::any_input(pattern::type_matches(element::boolean)),+ pattern::any_input(pattern::type_matches(element::boolean))});const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto bitwise = ov::as_type_ptr<ov::op::v13::BitwiseAnd>(m.get_match_root());+ const auto bitwise = ov::as_type_ptr<v13::BitwiseAnd>(m.get_match_root());if (!bitwise || transformation_callback(bitwise)) {return false;}- const auto logical = std::make_shared<ov::op::v1::LogicalAnd>(bitwise->input_value(0),- bitwise->input_value(1),- bitwise->get_autob());+ const auto logical =+ std::make_shared<v1::LogicalAnd>(bitwise->input_value(0), bitwise->input_value(1), bitwise->get_autob());logical->set_friendly_name(bitwise->get_friendly_name());copy_runtime_info(bitwise, logical);@@ -43,18 +46,18 @@ ov::pass::ConvertBitwiseAndToLogicalAnd::ConvertBitwiseAndToLogicalAnd() {auto m = std::make_shared<pattern::Matcher>(pattern, matcher_name);register_matcher(m, callback);}-ov::pass::ConvertBitwiseNotToLogicalNot::ConvertBitwiseNotToLogicalNot() {++ConvertBitwiseNotToLogicalNot::ConvertBitwiseNotToLogicalNot() {MATCHER_SCOPE(ConvertBitwiseNotToLogicalNot);- auto pattern =- pattern::wrap_type<ov::op::v13::BitwiseNot>({pattern::any_input(pattern::type_matches(element::boolean))});+ auto pattern = pattern::wrap_type<v13::BitwiseNot>({pattern::any_input(pattern::type_matches(element::boolean))});const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto bitwise = ov::as_type_ptr<ov::op::v13::BitwiseNot>(m.get_match_root());+ const auto bitwise = ov::as_type_ptr<v13::BitwiseNot>(m.get_match_root());if (!bitwise || transformation_callback(bitwise)) {return false;}- const auto logical = std::make_shared<ov::op::v1::LogicalNot>(bitwise->input_value(0));+ const auto logical = std::make_shared<v1::LogicalNot>(bitwise->input_value(0));logical->set_friendly_name(bitwise->get_friendly_name());copy_runtime_info(bitwise, logical);@@ -66,21 +69,19 @@ ov::pass::ConvertBitwiseNotToLogicalNot::ConvertBitwiseNotToLogicalNot() {register_matcher(m, callback);}-ov::pass::ConvertBitwiseOrToLogicalOr::ConvertBitwiseOrToLogicalOr() {+ConvertBitwiseOrToLogicalOr::ConvertBitwiseOrToLogicalOr() {MATCHER_SCOPE(ConvertBitwiseOrToLogicalOr);- auto pattern =- pattern::wrap_type<ov::op::v13::BitwiseOr>({pattern::any_input(pattern::type_matches(element::boolean)),- pattern::any_input(pattern::type_matches(element::boolean))});+ auto pattern = pattern::wrap_type<v13::BitwiseOr>({pattern::any_input(pattern::type_matches(element::boolean)),+ pattern::any_input(pattern::type_matches(element::boolean))});const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto bitwise = ov::as_type_ptr<ov::op::v13::BitwiseOr>(m.get_match_root());+ const auto bitwise = ov::as_type_ptr<v13::BitwiseOr>(m.get_match_root());if (!bitwise || transformation_callback(bitwise)) {return false;}- const auto logical = std::make_shared<ov::op::v1::LogicalOr>(bitwise->input_value(0),- bitwise->input_value(1),- bitwise->get_autob());+ const auto logical =+ std::make_shared<v1::LogicalOr>(bitwise->input_value(0), bitwise->input_value(1), bitwise->get_autob());logical->set_friendly_name(bitwise->get_friendly_name());copy_runtime_info(bitwise, logical);@@ -92,21 +93,19 @@ ov::pass::ConvertBitwiseOrToLogicalOr::ConvertBitwiseOrToLogicalOr() {register_matcher(m, callback);}-ov::pass::ConvertBitwiseXorToLogicalXor::ConvertBitwiseXorToLogicalXor() {+ConvertBitwiseXorToLogicalXor::ConvertBitwiseXorToLogicalXor() {MATCHER_SCOPE(ConvertBitwiseXorToLogicalXor);- auto pattern =- pattern::wrap_type<ov::op::v13::BitwiseXor>({pattern::any_input(pattern::type_matches(element::boolean)),- pattern::any_input(pattern::type_matches(element::boolean))});+ auto pattern = pattern::wrap_type<v13::BitwiseXor>({pattern::any_input(pattern::type_matches(element::boolean)),+ pattern::any_input(pattern::type_matches(element::boolean))});const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto bitwise = ov::as_type_ptr<ov::op::v13::BitwiseXor>(m.get_match_root());+ const auto bitwise = ov::as_type_ptr<v13::BitwiseXor>(m.get_match_root());if (!bitwise || transformation_callback(bitwise)) {return false;}- const auto logical = std::make_shared<ov::op::v1::LogicalXor>(bitwise->input_value(0),- bitwise->input_value(1),- bitwise->get_autob());+ const auto logical =+ std::make_shared<v1::LogicalXor>(bitwise->input_value(0), bitwise->input_value(1), bitwise->get_autob());logical->set_friendly_name(bitwise->get_friendly_name());copy_runtime_info(bitwise, logical);@@ -117,3 +116,5 @@ ov::pass::ConvertBitwiseXorToLogicalXor::ConvertBitwiseXorToLogicalXor() {auto m = std::make_shared<pattern::Matcher>(pattern, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_broadcast3.cpp b/src/common/transformations/src/transformations/op_conversions/convert_broadcast3.cppindex ba7d7e7eb0a..a28286d4631 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_broadcast3.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_broadcast3.cpp@@ -16,6 +16,10 @@#include "openvino/op/multiply.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace {bool make_compatible_shape(const ov::PartialShape& input_shape, std::vector<size_t>& target_shape) {@@ -60,12 +64,14 @@ bool make_compatible_shape(const ov::PartialShape& input_shape, std::vector<size} // namespace-ov::pass::ConvertBroadcast3::ConvertBroadcast3() {+namespace ov::pass {++ConvertBroadcast3::ConvertBroadcast3() {MATCHER_SCOPE(ConvertBroadcast3);- auto broadcast = pattern::wrap_type<ov::op::v3::Broadcast>();+ auto broadcast = pattern::wrap_type<v3::Broadcast>();matcher_pass_callback callback = [](pattern::Matcher& m) {- auto broadcast = ov::as_type_ptr<ov::op::v3::Broadcast>(m.get_match_root());+ auto broadcast = ov::as_type_ptr<v3::Broadcast>(m.get_match_root());if (!broadcast) {return false;}@@ -76,44 +82,41 @@ ov::pass::ConvertBroadcast3::ConvertBroadcast3() {const auto& input_element_type = input.get_element_type();if (broadcast_type == op::BroadcastType::NUMPY) {- input = std::make_shared<ov::op::v1::Broadcast>(input, target_shape_input, op::AutoBroadcastType::NUMPY);+ input = std::make_shared<v1::Broadcast>(input, target_shape_input, op::AutoBroadcastType::NUMPY);} else if (broadcast_type == op::BroadcastType::PDPD) {- input = std::make_shared<ov::op::v1::Broadcast>(input, target_shape_input, op::AutoBroadcastType::PDPD);+ input = std::make_shared<v1::Broadcast>(input, target_shape_input, op::AutoBroadcastType::PDPD);} else if (broadcast_type == op::BroadcastType::NONE) {- input = std::make_shared<ov::op::v1::Broadcast>(input,- target_shape_input,- broadcast->input_value(2),- op::AutoBroadcastType::NONE);+ input = std::make_shared<v1::Broadcast>(input,+ target_shape_input,+ broadcast->input_value(2),+ op::AutoBroadcastType::NONE);} else if (broadcast_type == op::BroadcastType::BIDIRECTIONAL) {- if (auto const_target_shape =- ov::as_type_ptr<ov::op::v0::Constant>(target_shape_input.get_node_shared_ptr())) {+ if (auto const_target_shape = ov::as_type_ptr<v0::Constant>(target_shape_input.get_node_shared_ptr())) {const auto& input_shape = input.get_partial_shape();const auto& target_shape = const_target_shape->cast_vector<size_t>();std::vector<size_t> aligned_target_shape{target_shape};if (make_compatible_shape(input_shape, aligned_target_shape)) {- input = std::make_shared<ov::op::v1::Broadcast>(+ input = std::make_shared<v1::Broadcast>(input,- ov::op::v0::Constant::create(element::i64,- Shape({aligned_target_shape.size()}),- aligned_target_shape));+ v0::Constant::create(element::i64, Shape({aligned_target_shape.size()}), aligned_target_shape));} else {if (input_element_type == element::boolean) {- input = std::make_shared<ov::op::v1::LogicalAnd>(+ input = std::make_shared<v1::LogicalAnd>(input,- ov::op::v0::Constant::create(input_element_type, target_shape, {1}));+ v0::Constant::create(input_element_type, target_shape, {1}));} else {- input = std::make_shared<ov::op::v1::Multiply>(- input,- ov::op::v0::Constant::create(input_element_type, target_shape, {1}));+ input =+ std::make_shared<v1::Multiply>(input,+ v0::Constant::create(input_element_type, target_shape, {1}));}}} else {- auto constant_one = ov::op::v0::Constant::create(input_element_type, {1}, {1});- auto broadcast_ones = std::make_shared<ov::op::v1::Broadcast>(constant_one, target_shape_input);+ auto constant_one = v0::Constant::create(input_element_type, {1}, {1});+ auto broadcast_ones = std::make_shared<v1::Broadcast>(constant_one, target_shape_input);if (input_element_type == element::boolean) {- input = std::make_shared<ov::op::v1::LogicalAnd>(input, broadcast_ones);+ input = std::make_shared<v1::LogicalAnd>(input, broadcast_ones);} else {- input = std::make_shared<ov::op::v1::Multiply>(input, broadcast_ones);+ input = std::make_shared<v1::Multiply>(input, broadcast_ones);}copy_runtime_info(broadcast, broadcast_ones);}@@ -130,3 +133,5 @@ ov::pass::ConvertBroadcast3::ConvertBroadcast3() {auto m = std::make_shared<pattern::Matcher>(broadcast, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_broadcast_to_tiles.cpp b/src/common/transformations/src/transformations/op_conversions/convert_broadcast_to_tiles.cppindex f74ac52d496..aad0d1ecbbd 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_broadcast_to_tiles.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_broadcast_to_tiles.cpp@@ -16,12 +16,17 @@#include "openvino/op/tile.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::ConvertBroadcastToTiles::ConvertBroadcastToTiles() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++ConvertBroadcastToTiles::ConvertBroadcastToTiles() {MATCHER_SCOPE(ConvertBroadcastToTiles);- auto broadcast = ov::pass::pattern::wrap_type<ov::op::v1::Broadcast>();+ auto broadcast = pattern::wrap_type<v1::Broadcast>();matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto broadcast = ov::as_type_ptr<ov::op::v1::Broadcast>(m.get_match_root());+ auto broadcast = ov::as_type_ptr<v1::Broadcast>(m.get_match_root());if (!broadcast) {return false;@@ -32,8 +37,8 @@ ov::pass::ConvertBroadcastToTiles::ConvertBroadcastToTiles() {return false;}- auto shape_node = ov::as_type_ptr<ov::op::v0::Constant>(broadcast->input_value(1).get_node_shared_ptr());- auto axes_node = ov::as_type_ptr<ov::op::v0::Constant>(broadcast->input_value(2).get_node_shared_ptr());+ auto shape_node = ov::as_type_ptr<v0::Constant>(broadcast->input_value(1).get_node_shared_ptr());+ auto axes_node = ov::as_type_ptr<v0::Constant>(broadcast->input_value(2).get_node_shared_ptr());if (!shape_node || !axes_node)return false;@@ -67,8 +72,8 @@ ov::pass::ConvertBroadcastToTiles::ConvertBroadcastToTiles() {} else {return false;}- auto shape_const = std::make_shared<ov::op::v0::Constant>(element::i64, Shape{shape.size()}, shape);- auto reshape = std::make_shared<ov::op::v1::Reshape>(data_node, shape_const, true);+ auto shape_const = std::make_shared<v0::Constant>(element::i64, Shape{shape.size()}, shape);+ auto reshape = std::make_shared<v1::Reshape>(data_node, shape_const, true);new_ops.push_back(reshape);last_node = reshape;input_shape = shape;@@ -91,8 +96,8 @@ ov::pass::ConvertBroadcastToTiles::ConvertBroadcastToTiles() {++input_shape_it;}- auto const_node = std::make_shared<ov::op::v0::Constant>(element::i64, Shape{dims_count}, dims);- auto tile = register_new_node<ov::op::v0::Tile>(last_node, const_node);+ auto const_node = std::make_shared<v0::Constant>(element::i64, Shape{dims_count}, dims);+ auto tile = register_new_node<v0::Tile>(last_node, const_node);new_ops.push_back(tile);tile->set_friendly_name(broadcast->get_friendly_name());@@ -101,6 +106,8 @@ ov::pass::ConvertBroadcastToTiles::ConvertBroadcastToTiles() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(broadcast, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(broadcast, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_convertlike.cpp b/src/common/transformations/src/transformations/op_conversions/convert_convertlike.cppindex 5e85129d41e..7a8884ebfde 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_convertlike.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_convertlike.cpp@@ -16,13 +16,17 @@using namespace ov;-ov::pass::ConvertConvertLike::ConvertConvertLike() {+namespace v1 = ov::op::v1;++namespace ov::pass {++ConvertConvertLike::ConvertConvertLike() {MATCHER_SCOPE(ConvertConvertLike);- auto convertlike = pattern::wrap_type<ov::op::v1::ConvertLike>();+ auto convertlike = pattern::wrap_type<v1::ConvertLike>();matcher_pass_callback callback = [](pattern::Matcher& m) {- auto cvtlike = ov::as_type_ptr<ov::op::v1::ConvertLike>(m.get_match_root());+ auto cvtlike = ov::as_type_ptr<v1::ConvertLike>(m.get_match_root());if (!cvtlike) {return false;}@@ -43,3 +47,5 @@ ov::pass::ConvertConvertLike::ConvertConvertLike() {auto m = std::make_shared<pattern::Matcher>(convertlike, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_convertpromotetypes.cpp b/src/common/transformations/src/transformations/op_conversions/convert_convertpromotetypes.cppindex bb3cf799b64..f820119ecc2 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_convertpromotetypes.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_convertpromotetypes.cpp@@ -11,24 +11,29 @@#include "openvino/op/convert_promote_types.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::ConvertConvertPromoteTypes::ConvertConvertPromoteTypes() {+namespace v0 = ov::op::v0;+namespace v14 = ov::op::v14;++namespace ov::pass {++ConvertConvertPromoteTypes::ConvertConvertPromoteTypes() {MATCHER_SCOPE(ConvertConvertPromoteTypes);auto has_static_defined_type = [](const Output<Node>& output) -> bool {return !pattern::type_matches_any({element::dynamic})(output);};- auto convert_promote_types = pattern::wrap_type<ov::op::v14::ConvertPromoteTypes>(has_static_defined_type);+ auto convert_promote_types = pattern::wrap_type<v14::ConvertPromoteTypes>(has_static_defined_type);matcher_pass_callback callback = [](pattern::Matcher& m) {- auto convert_promote_types = ov::as_type_ptr<ov::op::v14::ConvertPromoteTypes>(m.get_match_root());+ auto convert_promote_types = ov::as_type_ptr<v14::ConvertPromoteTypes>(m.get_match_root());if (!convert_promote_types) {return false;}const element::Type& dest_type = convert_promote_types->get_output_element_type(0);const auto friendly_name = convert_promote_types->get_friendly_name();NodeRegistry node_registry;- const auto out0 = node_registry.make<ov::op::v0::Convert>(convert_promote_types->input_value(0), dest_type);- const auto out1 = node_registry.make<ov::op::v0::Convert>(convert_promote_types->input_value(1), dest_type);+ const auto out0 = node_registry.make<v0::Convert>(convert_promote_types->input_value(0), dest_type);+ const auto out1 = node_registry.make<v0::Convert>(convert_promote_types->input_value(1), dest_type);out0->set_friendly_name(convert_promote_types->get_input_node_shared_ptr(0)->get_friendly_name() + "/" +friendly_name + ".0");out1->set_friendly_name(convert_promote_types->get_input_node_shared_ptr(1)->get_friendly_name() + "/" +@@ -41,3 +46,5 @@ ov::pass::ConvertConvertPromoteTypes::ConvertConvertPromoteTypes() {auto m = std::make_shared<pattern::Matcher>(convert_promote_types, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_deformable_conv_v8_to_v1.cpp b/src/common/transformations/src/transformations/op_conversions/convert_deformable_conv_v8_to_v1.cppindex 568a17b2246..066ec4876b4 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_deformable_conv_v8_to_v1.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_deformable_conv_v8_to_v1.cpp@@ -10,13 +10,17 @@#include "openvino/op/deformable_convolution.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::ConvertDeformableConv8To1::ConvertDeformableConv8To1() {+namespace v8 = ov::op::v8;++namespace ov::pass {++ConvertDeformableConv8To1::ConvertDeformableConv8To1() {MATCHER_SCOPE(ConvertDeformableConv8To1);- auto deformable_conv_v8 = pattern::wrap_type<ov::op::v8::DeformableConvolution>();+ auto deformable_conv_v8 = pattern::wrap_type<v8::DeformableConvolution>();matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto deformable_conv_v8_node = ov::as_type_ptr<ov::op::v8::DeformableConvolution>(m.get_match_root());+ auto deformable_conv_v8_node = ov::as_type_ptr<v8::DeformableConvolution>(m.get_match_root());if (!deformable_conv_v8_node)return false;@@ -47,3 +51,5 @@ ov::pass::ConvertDeformableConv8To1::ConvertDeformableConv8To1() {auto m = std::make_shared<pattern::Matcher>(deformable_conv_v8, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_depth_to_space.cpp b/src/common/transformations/src/transformations/op_conversions/convert_depth_to_space.cppindex 5145646d542..5f1f7913c3f 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_depth_to_space.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_depth_to_space.cpp@@ -16,13 +16,17 @@#include "openvino/op/transpose.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::ConvertDepthToSpace::ConvertDepthToSpace() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++ConvertDepthToSpace::ConvertDepthToSpace() {MATCHER_SCOPE(ConvertDepthToSpace);- auto dts_node =- ov::pass::pattern::wrap_type<ov::op::v0::DepthToSpace>({pattern::any_input(pattern::has_static_shape())});+ auto dts_node = pattern::wrap_type<v0::DepthToSpace>({pattern::any_input(pattern::has_static_shape())});matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto dts_node = ov::as_type_ptr<ov::op::v0::DepthToSpace>(m.get_match_root());+ auto dts_node = ov::as_type_ptr<v0::DepthToSpace>(m.get_match_root());if (!dts_node || transformation_callback(dts_node)) {return false;}@@ -55,10 +59,10 @@ ov::pass::ConvertDepthToSpace::ConvertDepthToSpace() {}switch (mode) {- case ov::op::v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST:+ case v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST:shape_begin.push_back(C);break;- case ov::op::v0::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST:+ case v0::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST:shape_begin.insert(shape_begin.begin() + 1, C);break;}@@ -70,14 +74,14 @@ ov::pass::ConvertDepthToSpace::ConvertDepthToSpace() {// Calculate Transpose orderstd::vector<int64_t> order{0};switch (mode) {- case ov::op::v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST:+ case v0::DepthToSpace::DepthToSpaceMode::BLOCKS_FIRST:order.push_back(spatial_dims + 1);for (size_t i = 1; i <= spatial_dims; ++i) {order.push_back(spatial_dims + 1 + i);order.push_back(i);}break;- case ov::op::v0::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST:+ case v0::DepthToSpace::DepthToSpaceMode::DEPTH_FIRST:order.push_back(1);for (size_t i = 1; i <= spatial_dims; ++i) {order.push_back(spatial_dims + 1 + i);@@ -92,19 +96,21 @@ ov::pass::ConvertDepthToSpace::ConvertDepthToSpace() {shape_end.push_back(block_size * input_shape[2 + i]);}- auto create_constant = [](std::vector<int64_t>& v) -> std::shared_ptr<ov::op::v0::Constant> {- return ov::op::v0::Constant::create(element::i64, Shape{v.size()}, v);+ auto create_constant = [](std::vector<int64_t>& v) -> std::shared_ptr<v0::Constant> {+ return v0::Constant::create(element::i64, Shape{v.size()}, v);};- auto reshape_begin = std::make_shared<ov::op::v1::Reshape>(input, create_constant(shape_begin), true);- auto transpose = std::make_shared<ov::op::v1::Transpose>(reshape_begin, create_constant(order));- auto reshape_end = std::make_shared<ov::op::v1::Reshape>(transpose, create_constant(shape_end), true);+ auto reshape_begin = std::make_shared<v1::Reshape>(input, create_constant(shape_begin), true);+ auto transpose = std::make_shared<v1::Transpose>(reshape_begin, create_constant(order));+ auto reshape_end = std::make_shared<v1::Reshape>(transpose, create_constant(shape_end), true);reshape_end->set_friendly_name(dts_node->get_friendly_name());ov::copy_runtime_info(dts_node, {reshape_begin, transpose, reshape_end});ov::replace_node(dts_node, reshape_end);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(dts_node, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(dts_node, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_divide.cpp b/src/common/transformations/src/transformations/op_conversions/convert_divide.cppindex 85562ffee09..5e0b5d305b5 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_divide.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_divide.cpp@@ -20,19 +20,23 @@#include "transformations/rt_info/nonconvertible_divide.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace {+bool convert_divide(std::shared_ptr<ov::Node> node) {- auto div = ov::as_type_ptr<ov::op::v1::Divide>(node);+ auto div = ov::as_type_ptr<v1::Divide>(node);// We can not apply this transformation in case with integer input data typeif (!div || ov::divide_is_nonconvertible(div) || div->get_input_element_type(0).is_integral()) {return false;}- std::shared_ptr<ov::Node> pow = std::make_shared<ov::op::v1::Power>(- div->input_value(1),- ov::op::v0::Constant::create(div->get_input_element_type(1), ov::Shape{}, {-1}));+ std::shared_ptr<ov::Node> pow =+ std::make_shared<v1::Power>(div->input_value(1),+ v0::Constant::create(div->get_input_element_type(1), ov::Shape{}, {-1}));- if (ov::as_type_ptr<ov::op::v0::Constant>(div->get_input_node_shared_ptr(1))) {+ if (ov::as_type_ptr<v0::Constant>(div->get_input_node_shared_ptr(1))) {if (auto const_pow = ov::util::get_constant_from_source(pow)) {pow = const_pow;} else {@@ -43,7 +47,7 @@ bool convert_divide(std::shared_ptr<ov::Node> node) {ov::copy_runtime_info(div, pow);}- auto mul = std::make_shared<ov::op::v1::Multiply>(div->input(0).get_source_output(), pow);+ auto mul = std::make_shared<v1::Multiply>(div->input(0).get_source_output(), pow);// if Divide is an inverse, then we don't need the Multiplyif (ov::op::util::can_eliminate_eltwise_node(mul, mul->input_value(0), mul->input_value(1))) {pow->set_friendly_name(div->get_friendly_name());@@ -55,29 +59,33 @@ bool convert_divide(std::shared_ptr<ov::Node> node) {}return true;}+} // namespace-ov::pass::ConvertDivide::ConvertDivide() {+namespace ov::pass {++ConvertDivide::ConvertDivide() {MATCHER_SCOPE(ConvertDivide);- auto div = ov::pass::pattern::wrap_type<ov::op::v1::Divide>();+ auto div = pattern::wrap_type<v1::Divide>();matcher_pass_callback callback = [](pattern::Matcher& m) {return convert_divide(m.get_match_root());};- auto m = std::make_shared<ov::pass::pattern::Matcher>(div, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(div, matcher_name);this->register_matcher(m, callback);}-ov::pass::ConvertDivideWithConstant::ConvertDivideWithConstant() {+ConvertDivideWithConstant::ConvertDivideWithConstant() {MATCHER_SCOPE(ConvertDivideWithConstant);- auto div = ov::pass::pattern::wrap_type<ov::op::v1::Divide>(- {pattern::any_input(), pattern::wrap_type<ov::op::v0::Constant>()});+ auto div = pattern::wrap_type<v1::Divide>({pattern::any_input(), pattern::wrap_type<v0::Constant>()});matcher_pass_callback callback = [](pattern::Matcher& m) {return convert_divide(m.get_match_root());};- auto m = std::make_shared<ov::pass::pattern::Matcher>(div, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(div, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_embedding_bag_offsets15_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_embedding_bag_offsets15_downgrade.cppindex 168f38231ae..213a698169e 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_embedding_bag_offsets15_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_embedding_bag_offsets15_downgrade.cpp@@ -12,16 +12,19 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ConvertEmbeddingBagOffsets15ToEmbeddingBagOffsetsSum3::- ConvertEmbeddingBagOffsets15ToEmbeddingBagOffsetsSum3() {+namespace v15 = ov::op::v15;++namespace ov::pass {++ConvertEmbeddingBagOffsets15ToEmbeddingBagOffsetsSum3::ConvertEmbeddingBagOffsets15ToEmbeddingBagOffsetsSum3() {MATCHER_SCOPE(ConvertEmbeddingBagOffsets15ToEmbeddingBagOffsetsSum3);- const auto emb_v15_pattern = pattern::wrap_type<ov::op::v15::EmbeddingBagOffsets>();+ const auto emb_v15_pattern = pattern::wrap_type<v15::EmbeddingBagOffsets>();const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto emb_v15 = ov::as_type_ptr<ov::op::v15::EmbeddingBagOffsets>(m.get_match_root());+ const auto emb_v15 = ov::as_type_ptr<v15::EmbeddingBagOffsets>(m.get_match_root());if (!emb_v15 || transformation_callback(emb_v15) ||- emb_v15->get_reduction() != ov::op::v15::EmbeddingBagOffsets::Reduction::SUM) {+ emb_v15->get_reduction() != v15::EmbeddingBagOffsets::Reduction::SUM) {return false;}std::shared_ptr<ov::op::v3::EmbeddingBagOffsetsSum> emb_v3;@@ -54,3 +57,5 @@ ov::pass::ConvertEmbeddingBagOffsets15ToEmbeddingBagOffsetsSum3::auto m = std::make_shared<pattern::Matcher>(emb_v15_pattern, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_embedding_bag_packed15_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_embedding_bag_packed15_downgrade.cppindex 0028dc78fe7..c8764af901e 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_embedding_bag_packed15_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_embedding_bag_packed15_downgrade.cpp@@ -12,15 +12,19 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ConvertEmbeddingBagPacked15ToEmbeddingBagPackedSum3::ConvertEmbeddingBagPacked15ToEmbeddingBagPackedSum3() {+namespace v15 = ov::op::v15;++namespace ov::pass {++ConvertEmbeddingBagPacked15ToEmbeddingBagPackedSum3::ConvertEmbeddingBagPacked15ToEmbeddingBagPackedSum3() {MATCHER_SCOPE(ConvertEmbeddingBagPacked15ToEmbeddingBagPackedSum3);- const auto emb_v15_pattern = pattern::wrap_type<ov::op::v15::EmbeddingBagPacked>();+ const auto emb_v15_pattern = pattern::wrap_type<v15::EmbeddingBagPacked>();const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto emb_v15 = ov::as_type_ptr<ov::op::v15::EmbeddingBagPacked>(m.get_match_root());+ const auto emb_v15 = ov::as_type_ptr<v15::EmbeddingBagPacked>(m.get_match_root());if (!emb_v15 || transformation_callback(emb_v15) ||- emb_v15->get_reduction() != ov::op::v15::EmbeddingBagPacked::Reduction::SUM) {+ emb_v15->get_reduction() != v15::EmbeddingBagPacked::Reduction::SUM) {return false;}std::shared_ptr<ov::op::v3::EmbeddingBagPackedSum> emb_v3;@@ -44,3 +48,5 @@ ov::pass::ConvertEmbeddingBagPacked15ToEmbeddingBagPackedSum3::ConvertEmbeddingBauto m = std::make_shared<pattern::Matcher>(emb_v15_pattern, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cppindex 4e1178be877..4899d7822f3 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp@@ -25,10 +25,14 @@#include "transformations/pattern_blocks/compressed_weights_block.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;++namespace ov::pass {+std::tuple<std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>>-ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::process_compressed_weights(- const std::shared_ptr<ov::pass::pattern::op::CompressedWeightsBlock>& weights_block,- const ov::pass::pattern::PatternValueMap& pattern_map,+ConvertFullyConnectedToFullyConnectedCompressed::process_compressed_weights(+ const std::shared_ptr<pattern::op::CompressedWeightsBlock>& weights_block,+ const pattern::PatternValueMap& pattern_map,bool convert_u4zp_to_u8,bool has_transpose,bool grouped,@@ -36,7 +40,7 @@ ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::process_compressed_westd::vector<std::shared_ptr<ov::Node>>& result_nodes) {const size_t final_weights_rank = batched_weights ? 3 : 2;auto combine_groups = [has_transpose, grouped, final_weights_rank](std::shared_ptr<ov::Node> node) {- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node);+ auto constant = ov::as_type_ptr<v0::Constant>(node);OPENVINO_ASSERT(constant != nullptr);const auto& current_shape = constant->get_shape();if (current_shape.size() <= final_weights_rank) {@@ -64,14 +68,14 @@ ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::process_compressed_wenew_OC = OC;new_IC = n_groups * group_size;}- return std::make_shared<ov::op::v0::Constant>(*constant, new_shape);+ return std::make_shared<v0::Constant>(*constant, new_shape);};auto convert_u4const_to_u8 = [convert_u4zp_to_u8](std::shared_ptr<ov::Node> node) -> std::shared_ptr<ov::Node> {- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node);+ auto constant = ov::as_type_ptr<v0::Constant>(node);if (constant->get_element_type() != ov::element::u4 || !convert_u4zp_to_u8)return std::dynamic_pointer_cast<ov::Node>(constant);- return std::make_shared<ov::op::v0::Convert>(node, ov::element::u8);+ return std::make_shared<v0::Convert>(node, ov::element::u8);};const auto& scale =@@ -99,8 +103,7 @@ ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::process_compressed_westd::vector<int32_t> new_order(fc_input_b->get_output_partial_shape(0).size());std::iota(new_order.begin(), new_order.end(), 0);std::swap(new_order[new_order.size() - 1], new_order[new_order.size() - 2]);- transpose_const =- std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{new_order.size()}, new_order);+ transpose_const = std::make_shared<v0::Constant>(ov::element::i32, ov::Shape{new_order.size()}, new_order);}fc_input_b = transpose->clone_with_new_inputs({fc_input_b->output(0), transpose_const});@@ -116,28 +119,25 @@ ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::process_compressed_we}}- fc_input_zp =- with_zero_point ? fc_input_zp : std::make_shared<ov::op::v0::Constant>(ov::element::dynamic, ov::Shape{0});+ fc_input_zp = with_zero_point ? fc_input_zp : std::make_shared<v0::Constant>(ov::element::dynamic, ov::Shape{0});ov::disable_constant_folding(fc_input_zp);result_nodes.push_back(fc_input_zp);return std::make_tuple(fc_input_b, fc_input_scale, fc_input_zp);}-ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyConnectedCompressed(+ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyConnectedCompressed(const std::vector<ov::element::Type>& supported_activation_types,const std::vector<ov::element::Type>& supported_weights_types,SupportsPredicate supports_config,bool convert_u4zp_to_u8) {- using namespace ov::pass::pattern;-auto weights_block =- std::make_shared<ov::pass::pattern::op::CompressedWeightsBlock>(supported_weights_types, std::set<size_t>{2});- auto activation = any_input(type_matches_any(supported_activation_types));- auto bias = any_input();- auto fully_connected = wrap_type<ov::op::internal::FullyConnected>({activation, weights_block, bias});+ std::make_shared<pattern::op::CompressedWeightsBlock>(supported_weights_types, std::set<size_t>{2});+ auto activation = pattern::any_input(pattern::type_matches_any(supported_activation_types));+ auto bias = pattern::any_input();+ auto fully_connected = pattern::wrap_type<ov::op::internal::FullyConnected>({activation, weights_block, bias});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto fc =ov::as_type_ptr<ov::op::internal::FullyConnected>(pattern_map.at(fully_connected).get_node_shared_ptr());@@ -181,6 +181,8 @@ ov::pass::ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedreturn true;};- auto m = std::make_shared<Matcher>(fully_connected, "ConvertFullyConnectedToFullyConnectedCompressed");+ auto m = std::make_shared<pattern::Matcher>(fully_connected, "ConvertFullyConnectedToFullyConnectedCompressed");this->register_matcher(m, callback);-}\ No newline at end of file+}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cppindex 3edc742d051..6c802e87706 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_fc_to_quantized_legacy.cpp@@ -18,21 +18,23 @@#include "ov_ops/fully_connected_quantized_legacy.hpp"#include "transformations/utils/utils.hpp"-ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() {- using namespace ov::pass::pattern;+namespace v0 = ov::op::v0;+namespace ov::pass {++ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() {std::vector<element::Type> activation_types{ov::element::u8, ov::element::i8};std::vector<element::Type> weights_types{ov::element::i8};- auto activations_m = pattern::any_input(ov::pass::pattern::type_matches_any(activation_types));+ auto activations_m = pattern::any_input(pattern::type_matches_any(activation_types));auto weights_m = pattern::any_input();auto bias_m = pattern::any_input();- auto fully_connected_m = wrap_type<ov::op::internal::FullyConnected>({activations_m, weights_m, bias_m});- auto dequantization_scales_m = wrap_type<ov::op::v0::Constant>();- auto multiply_m = wrap_type<ov::op::v1::Multiply>({fully_connected_m, dequantization_scales_m});+ auto fully_connected_m = pattern::wrap_type<ov::op::internal::FullyConnected>({activations_m, weights_m, bias_m});+ auto dequantization_scales_m = pattern::wrap_type<v0::Constant>();+ auto multiply_m = pattern::wrap_type<ov::op::v1::Multiply>({fully_connected_m, dequantization_scales_m});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto fc_output = pattern_map.at(fully_connected_m);@@ -45,7 +47,7 @@ ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() {const auto& multiply_output_shape = multiply.get_partial_shape();if (*fc_output_shape.rbegin() != *multiply_output_shape.rbegin() ||- !ov::op::util::is_on_path<ov::op::v0::Constant>(weights)) {+ !ov::op::util::is_on_path<v0::Constant>(weights)) {return false;}@@ -53,7 +55,7 @@ ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() {ov::as_type_ptr<ov::op::internal::FullyConnected>(pattern_map.at(fully_connected_m).get_node_shared_ptr());ov::NodeVector new_ops;- auto zp = std::make_shared<ov::op::v0::Constant>(element::dynamic, Shape{0});+ auto zp = std::make_shared<v0::Constant>(element::dynamic, Shape{0});new_ops.push_back(zp);auto fc_quantized =@@ -74,6 +76,8 @@ ov::pass::ConvertFCToFCQuantizedLegacy::ConvertFCToFCQuantizedLegacy() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(multiply_m, "ConvertFullyConnectedToFullyConnectedQuantized");+ auto m = std::make_shared<pattern::Matcher>(multiply_m, "ConvertFullyConnectedToFullyConnectedQuantized");this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_gather_0d.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gather_0d.cppindex c74ccd5487c..8397f08a630 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_gather_0d.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_gather_0d.cpp@@ -16,17 +16,21 @@#include "openvino/op/unsqueeze.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::ConvertGather0D::ConvertGather0D() {MATCHER_SCOPE(ConvertGather0D);- auto gather = ov::pass::pattern::wrap_type<ov::op::v1::Gather>();+ auto gather = ov::pass::pattern::wrap_type<v1::Gather>();- matcher_pass_callback callback = [](pattern::Matcher& m) {- auto gather = ov::as_type_ptr<ov::op::v1::Gather>(m.get_match_root());+ matcher_pass_callback callback = [](Matcher& m) {+ auto gather = ov::as_type_ptr<v1::Gather>(m.get_match_root());if (!gather) {return false;}- auto axes_constant = ov::as_type_ptr<ov::op::v0::Constant>(gather->input_value(2).get_node_shared_ptr());+ auto axes_constant = ov::as_type_ptr<v0::Constant>(gather->input_value(2).get_node_shared_ptr());if (!axes_constant) {return false;}@@ -40,11 +44,9 @@ ov::pass::ConvertGather0D::ConvertGather0D() {}auto axis = axes_constant->cast_vector<int64_t>()[0];- indices =- std::make_shared<ov::op::v0::Unsqueeze>(indices, ov::op::v0::Constant::create(element::i64, Shape{1}, {0}));- auto gather_new = std::make_shared<ov::op::v1::Gather>(gather->input_value(0), indices, axes_constant);- auto sq = std::make_shared<ov::op::v0::Squeeze>(gather_new,- ov::op::v0::Constant::create(element::i64, Shape{1}, {axis}));+ indices = std::make_shared<v0::Unsqueeze>(indices, v0::Constant::create(element::i64, Shape{1}, {0}));+ auto gather_new = std::make_shared<v1::Gather>(gather->input_value(0), indices, axes_constant);+ auto sq = std::make_shared<v0::Squeeze>(gather_new, v0::Constant::create(element::i64, Shape{1}, {axis}));sq->set_friendly_name(gather->get_friendly_name());ov::copy_runtime_info(gather, {indices.get_node_shared_ptr(), gather_new, sq});@@ -53,6 +55,6 @@ ov::pass::ConvertGather0D::ConvertGather0D() {return true;};- auto m1 = std::make_shared<ov::pass::pattern::Matcher>(gather, matcher_name);+ auto m1 = std::make_shared<Matcher>(gather, matcher_name);this->register_matcher(m1, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cppindex b01143289df..448e740e93c 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_gather_downgrade.cpp@@ -13,13 +13,19 @@using namespace std;using namespace ov;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v7 = ov::op::v7;+namespace v8 = ov::op::v8;pass::ConvertGather7ToGather1::ConvertGather7ToGather1() {MATCHER_SCOPE(ConvertGather7ToGather1);- auto gather_v7_pattern = pattern::wrap_type<ov::op::v7::Gather>();+ auto gather_v7_pattern = wrap_type<v7::Gather>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto gather_v7_node = ov::as_type_ptr<ov::op::v7::Gather>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto gather_v7_node = ov::as_type_ptr<v7::Gather>(m.get_match_root());if (!gather_v7_node)return false;if (gather_v7_node->get_batch_dims() != 0)@@ -35,25 +41,23 @@ pass::ConvertGather7ToGather1::ConvertGather7ToGather1() {return true;};- auto m = make_shared<pattern::Matcher>(gather_v7_pattern, matcher_name);+ auto m = make_shared<Matcher>(gather_v7_pattern, matcher_name);register_matcher(m, callback);}pass::ConvertGather8ToGather7::ConvertGather8ToGather7() {MATCHER_SCOPE(ConvertGather8ToGather7);- auto gather_v8_pattern = pattern::wrap_type<ov::op::v8::Gather>();+ auto gather_v8_pattern = wrap_type<v8::Gather>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto gather_v8_node = ov::as_type_ptr<ov::op::v8::Gather>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto gather_v8_node = ov::as_type_ptr<v8::Gather>(m.get_match_root());if (!gather_v8_node)return false;auto data = gather_v8_node->input_value(0);- auto indices_constant =- ov::as_type_ptr<ov::op::v0::Constant>(gather_v8_node->input_value(1).get_node_shared_ptr());- auto axis_constant =- ov::as_type_ptr<ov::op::v0::Constant>(gather_v8_node->input_value(2).get_node_shared_ptr());+ auto indices_constant = ov::as_type_ptr<v0::Constant>(gather_v8_node->input_value(1).get_node_shared_ptr());+ auto axis_constant = ov::as_type_ptr<v0::Constant>(gather_v8_node->input_value(2).get_node_shared_ptr());if (!indices_constant || !axis_constant)return false;@@ -93,17 +97,17 @@ pass::ConvertGather8ToGather7::ConvertGather8ToGather7() {std::shared_ptr<ov::Node> new_indices_constant;if (do_indices_normalization) {- new_indices_constant = std::make_shared<ov::op::v0::Constant>(indices_constant->get_element_type(),- indices_constant->get_shape(),- indices);+ new_indices_constant = std::make_shared<v0::Constant>(indices_constant->get_element_type(),+ indices_constant->get_shape(),+ indices);} else {new_indices_constant = indices_constant;}- auto gather_v7_node = make_shared<ov::op::v7::Gather>(gather_v8_node->input_value(0),- new_indices_constant,- gather_v8_node->input_value(2),- gather_v8_node->get_batch_dims());+ auto gather_v7_node = make_shared<v7::Gather>(gather_v8_node->input_value(0),+ new_indices_constant,+ gather_v8_node->input_value(2),+ gather_v8_node->get_batch_dims());gather_v7_node->set_friendly_name(gather_v8_node->get_friendly_name());ov::copy_runtime_info(gather_v8_node, gather_v7_node);@@ -111,6 +115,6 @@ pass::ConvertGather8ToGather7::ConvertGather8ToGather7() {return true;};- auto m = make_shared<pattern::Matcher>(gather_v8_pattern, matcher_name);+ auto m = make_shared<Matcher>(gather_v8_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gather_to_compressed.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gather_to_compressed.cppindex 55753c7b285..644220267ff 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_gather_to_compressed.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_gather_to_compressed.cpp@@ -20,9 +20,16 @@#include "transformations/rt_info/keep_const_precision.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::type_matches;+using ov::pass::pattern::wrap_type;+using ov::pass::pattern::op::Or;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;ov::pass::ConvertGatherToGatherCompressed::ConvertGatherToGatherCompressed() {- using namespace ov::pass::pattern;-auto compressed_constant = [](const ov::Output<ov::Node>& output) {return (output.get_element_type() == ov::element::u8 || output.get_element_type() == ov::element::i8 ||output.get_element_type() == ov::element::u4 || output.get_element_type() == ov::element::i4) &&@@ -35,54 +42,53 @@ ov::pass::ConvertGatherToGatherCompressed::ConvertGatherToGatherCompressed() {return in_ps.rank().is_static() && out_ps.rank().is_static() && in_ps.size() == 3 && out_ps.size() == 2;};- auto dicts_m = wrap_type<ov::op::v0::Constant>(compressed_constant);- auto convert_m = wrap_type<ov::op::v0::Convert>({dicts_m});+ auto dicts_m = wrap_type<v0::Constant>(compressed_constant);+ auto convert_m = wrap_type<v0::Convert>({dicts_m});- auto sub_const_m = ov::pass::pattern::any_input(); // const or const+convert- auto subtract_m = wrap_type<ov::op::v1::Subtract>({convert_m, sub_const_m});+ auto sub_const_m = any_input(); // const or const+convert+ auto subtract_m = wrap_type<v1::Subtract>({convert_m, sub_const_m});- auto mul_const_m = ov::pass::pattern::any_input(); // const or const+convert- auto mul_with_sub_m = wrap_type<ov::op::v1::Multiply>({subtract_m, mul_const_m});- auto mul_no_sub_m = wrap_type<ov::op::v1::Multiply>({convert_m, mul_const_m});- auto mul_m = std::make_shared<ov::pass::pattern::op::Or>(ov::OutputVector{mul_with_sub_m, mul_no_sub_m});+ auto mul_const_m = any_input(); // const or const+convert+ auto mul_with_sub_m = wrap_type<v1::Multiply>({subtract_m, mul_const_m});+ auto mul_no_sub_m = wrap_type<v1::Multiply>({convert_m, mul_const_m});+ auto mul_m = std::make_shared<Or>(ov::OutputVector{mul_with_sub_m, mul_no_sub_m});- auto reshape_const_m = wrap_type<ov::op::v0::Constant>();- auto reshape_m = wrap_type<ov::op::v1::Reshape>({mul_m, reshape_const_m}, reshape_3d_to_2d);+ auto reshape_const_m = wrap_type<v0::Constant>();+ auto reshape_m = wrap_type<v1::Reshape>({mul_m, reshape_const_m}, reshape_3d_to_2d);- auto last_convert_input = std::make_shared<ov::pass::pattern::op::Or>(ov::OutputVector{reshape_m, mul_m});- auto last_convert_m = wrap_type<ov::op::v0::Convert>({last_convert_input});+ auto last_convert_input = std::make_shared<Or>(ov::OutputVector{reshape_m, mul_m});+ auto last_convert_m = wrap_type<v0::Convert>({last_convert_input});- auto dicts_input_m =- std::make_shared<ov::pass::pattern::op::Or>(ov::OutputVector{reshape_m, last_convert_m, mul_m});- auto gather_m = wrap_type<ov::op::v8::Gather>({dicts_input_m, any_input(), wrap_type<ov::op::v0::Constant>()});+ auto dicts_input_m = std::make_shared<Or>(ov::OutputVector{reshape_m, last_convert_m, mul_m});+ auto gather_m = wrap_type<v8::Gather>({dicts_input_m, any_input(), wrap_type<v0::Constant>()});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();OPENVINO_ASSERT(pattern_map.count(gather_m));OPENVINO_ASSERT(pattern_map.count(mul_const_m));OPENVINO_ASSERT(pattern_map.count(dicts_m));OPENVINO_ASSERT(pattern_map.count(convert_m));ov::Shape dicts_shape = pattern_map.at(dicts_m).get_node_shared_ptr()->get_shape();- auto gather_node = ov::as_type_ptr<ov::op::v8::Gather>(pattern_map.at(gather_m).get_node_shared_ptr());+ auto gather_node = ov::as_type_ptr<v8::Gather>(pattern_map.at(gather_m).get_node_shared_ptr());if (!gather_node || transformation_callback(gather_node)) {return false;}auto reshape_const_to_2d = [](std::shared_ptr<ov::Node> node) -> std::shared_ptr<ov::Node> {- auto convert = ov::as_type_ptr<ov::op::v0::Convert>(node);+ auto convert = ov::as_type_ptr<v0::Convert>(node);if (convert != nullptr) {return node;- } else if (ov::as_type_ptr<ov::op::v1::Reshape>(node) != nullptr) {+ } else if (ov::as_type_ptr<v1::Reshape>(node) != nullptr) {return node;} else {- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node);+ auto constant = ov::as_type_ptr<v0::Constant>(node);OPENVINO_ASSERT(constant != nullptr);ov::Shape current_shape = constant->get_shape();if (current_shape.size() <= 2)return constant;OPENVINO_ASSERT(current_shape.size() == 3);auto new_shape = ov::Shape{current_shape[0], current_shape[1] * current_shape[2]};- return std::make_shared<ov::op::v0::Constant>(*constant, new_shape);+ return std::make_shared<v0::Constant>(*constant, new_shape);}};@@ -145,21 +151,19 @@ ov::pass::ConvertGatherToGatherCompressed::ConvertGatherToGatherCompressed() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(gather_m, "ConvertGatherToGatherCompressed");+ auto m = std::make_shared<Matcher>(gather_m, "ConvertGatherToGatherCompressed");this->register_matcher(m, callback);}ov::pass::MoveDecompressionAfterGather::MoveDecompressionAfterGather() {- using namespace ov::pass::pattern;-- auto dicts = wrap_type<ov::op::v0::Constant>(pattern::type_matches_any({element::f16, element::bf16}));+ auto dicts = wrap_type<v0::Constant>(ov::pass::pattern::type_matches_any({element::f16, element::bf16}));auto convert_predicate = [](ov::Output<ov::Node> output) -> bool {- return pattern::consumers_count(1)(output) && pattern::type_matches(ov::element::f32)(output);+ return ov::pass::pattern::consumers_count(1)(output) && type_matches(ov::element::f32)(output);};- auto convert = wrap_type<ov::op::v0::Convert>({dicts}, convert_predicate);- auto gather = wrap_type<ov::op::v8::Gather>({convert, any_input(), wrap_type<ov::op::v0::Constant>()});+ auto convert = wrap_type<v0::Convert>({dicts}, convert_predicate);+ auto gather = wrap_type<v8::Gather>({convert, any_input(), wrap_type<v0::Constant>()});- ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto constant_node = pattern_map.at(dicts).get_node_shared_ptr();auto convert_node = pattern_map.at(convert).get_node_shared_ptr();@@ -182,6 +186,6 @@ ov::pass::MoveDecompressionAfterGather::MoveDecompressionAfterGather() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(gather, "MoveDecompressionAfterGather");+ auto m = std::make_shared<Matcher>(gather, "MoveDecompressionAfterGather");this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gather_upgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gather_upgrade.cppindex 13cacec3930..df9787b4e78 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_gather_upgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_gather_upgrade.cpp@@ -13,20 +13,25 @@using namespace std;using namespace ov;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v1 = ov::op::v1;+namespace v7 = ov::op::v7;pass::ConvertGather1ToGather7::ConvertGather1ToGather7() {MATCHER_SCOPE(ConvertGather1ToGather7);- auto gather_v1_pattern = pattern::wrap_type<ov::op::v1::Gather>();+ auto gather_v1_pattern = wrap_type<v1::Gather>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto gather_v1_node = ov::as_type_ptr<ov::op::v1::Gather>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto gather_v1_node = ov::as_type_ptr<v1::Gather>(m.get_match_root());if (!gather_v1_node)return false;- auto gather_v7_node = make_shared<ov::op::v7::Gather>(gather_v1_node->input_value(0),- gather_v1_node->input_value(1),- gather_v1_node->input_value(2),- 0);+ auto gather_v7_node = make_shared<v7::Gather>(gather_v1_node->input_value(0),+ gather_v1_node->input_value(1),+ gather_v1_node->input_value(2),+ 0);gather_v7_node->set_friendly_name(gather_v1_node->get_friendly_name());ov::copy_runtime_info(gather_v1_node, gather_v7_node);@@ -34,17 +39,17 @@ pass::ConvertGather1ToGather7::ConvertGather1ToGather7() {return true;};- auto m = make_shared<pattern::Matcher>(gather_v1_pattern, matcher_name);+ auto m = make_shared<Matcher>(gather_v1_pattern, matcher_name);register_matcher(m, callback);}pass::ConvertGather7ToGather8::ConvertGather7ToGather8() {MATCHER_SCOPE(ConvertGather7ToGather8);- auto gather_v7_pattern = pattern::wrap_type<ov::op::v7::Gather>();+ auto gather_v7_pattern = wrap_type<v7::Gather>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto gather_v7_node = ov::as_type_ptr<ov::op::v7::Gather>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto gather_v7_node = ov::as_type_ptr<v7::Gather>(m.get_match_root());if (!gather_v7_node)return false;@@ -59,6 +64,6 @@ pass::ConvertGather7ToGather8::ConvertGather7ToGather8() {return true;};- auto m = make_shared<pattern::Matcher>(gather_v7_pattern, matcher_name);+ auto m = make_shared<Matcher>(gather_v7_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gelu.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gelu.cppindex 64ff622dfc3..673302fa6d2 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_gelu.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_gelu.cpp@@ -18,25 +18,28 @@#include "openvino/op/sqrt.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::ConvertGELU::ConvertGELU() {MATCHER_SCOPE(ConvertGELU);- auto gelu = pattern::wrap_type<ov::op::v0::Gelu>();+ auto gelu = ov::pass::pattern::wrap_type<v0::Gelu>();- matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto gelu = ov::as_type_ptr<ov::op::v0::Gelu>(m.get_match_root());+ matcher_pass_callback callback = [this](Matcher& m) {+ auto gelu = ov::as_type_ptr<v0::Gelu>(m.get_match_root());if (!gelu || transformation_callback(gelu))return false;auto input = gelu->input_value(0);auto input_type = input.get_element_type();// f(x) = 0.5 * x * (1.0 + erf( x / sqrt(2.0) )- auto mul =- std::make_shared<ov::op::v1::Multiply>(input, ov::op::v0::Constant::create(input_type, Shape{}, {0.5}));- auto sq2 = std::make_shared<ov::op::v0::Sqrt>(ov::op::v0::Constant::create(input_type, Shape{}, {2.0}));- auto div = register_new_node<ov::op::v1::Divide>(input, sq2); // can be decomposed- auto erf = std::make_shared<ov::op::v0::Erf>(div);- auto add = std::make_shared<ov::op::v1::Add>(erf, ov::op::v0::Constant::create(input_type, Shape{}, {1.0}));- auto res = std::make_shared<ov::op::v1::Multiply>(mul, add);+ auto mul = std::make_shared<v1::Multiply>(input, v0::Constant::create(input_type, Shape{}, {0.5}));+ auto sq2 = std::make_shared<v0::Sqrt>(v0::Constant::create(input_type, Shape{}, {2.0}));+ auto div = register_new_node<v1::Divide>(input, sq2); // can be decomposed+ auto erf = std::make_shared<v0::Erf>(div);+ auto add = std::make_shared<v1::Add>(erf, v0::Constant::create(input_type, Shape{}, {1.0}));+ auto res = std::make_shared<v1::Multiply>(mul, add);res->set_friendly_name(gelu->get_friendly_name());ov::copy_runtime_info(gelu, {mul, sq2, div, erf, add, res});@@ -44,6 +47,6 @@ ov::pass::ConvertGELU::ConvertGELU() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(gelu, matcher_name);+ auto m = std::make_shared<Matcher>(gelu, matcher_name);register_matcher(m, callback, PassProperty::CHANGE_DYNAMIC_STATE);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_gp9_to_gp_ie_internal.cpp b/src/common/transformations/src/transformations/op_conversions/convert_gp9_to_gp_ie_internal.cppindex 869492a753d..1d356c2f72a 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_gp9_to_gp_ie_internal.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_gp9_to_gp_ie_internal.cpp@@ -12,10 +12,13 @@#include "ov_ops/generate_proposals_ie_internal.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v9 = ov::op::v9;ov::pass::ConvertGP9ToGPIEInternal::ConvertGP9ToGPIEInternal() {- matcher_pass_callback callback = [](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [](Matcher& m) {const auto root = m.get_match_root();- const auto old_node = ov::as_type_ptr<ov::op::v9::GenerateProposals>(root);+ const auto old_node = ov::as_type_ptr<v9::GenerateProposals>(root);if (!old_node) {return false;}@@ -49,7 +52,7 @@ ov::pass::ConvertGP9ToGPIEInternal::ConvertGP9ToGPIEInternal() {return true;};- const auto generate_proposals = ov::pass::pattern::wrap_type<ov::op::v9::GenerateProposals>();- const auto matcher = std::make_shared<ov::pass::pattern::Matcher>(generate_proposals, "ConvertGP9ToGPIEInternal");+ const auto generate_proposals = ov::pass::pattern::wrap_type<v9::GenerateProposals>();+ const auto matcher = std::make_shared<Matcher>(generate_proposals, "ConvertGP9ToGPIEInternal");register_matcher(matcher, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_interpolate11_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_interpolate11_downgrade.cppindex e1d04ffaa1d..d60204f327e 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_interpolate11_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_interpolate11_downgrade.cpp@@ -17,33 +17,39 @@#include "transformations/utils/utils.hpp"#include "utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v11 = ov::op::v11;+namespace op_util = ov::op::util;namespace {// v4_sizes, v4_scalesstd::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> make_v4_inputs(- const std::shared_ptr<ov::op::v11::Interpolate>& interpolate) {+ const std::shared_ptr<v11::Interpolate>& interpolate) {ov::pass::NodeRegistry registry;std::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> ret;std::shared_ptr<ov::Node> broadcast_shape;if (interpolate->get_input_size() == 3) {// broadcast dummy constant to the shape of axes- broadcast_shape = registry.add(ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(interpolate->input_value(2)));+ broadcast_shape = registry.add(op_util::make_try_fold<v3::ShapeOf>(interpolate->input_value(2)));} else {// broadcast dummy constant to the rank of data- broadcast_shape = registry.add(ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(interpolate->input_value(0)));- broadcast_shape = registry.add(ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(broadcast_shape));+ broadcast_shape = registry.add(op_util::make_try_fold<v3::ShapeOf>(interpolate->input_value(0)));+ broadcast_shape = registry.add(op_util::make_try_fold<v3::ShapeOf>(broadcast_shape));}- if (interpolate->get_attrs().shape_calculation_mode == ov::op::util::InterpolateBase::ShapeCalcMode::SCALES) {+ if (interpolate->get_attrs().shape_calculation_mode == op_util::InterpolateBase::ShapeCalcMode::SCALES) {ret.second = interpolate->input_value(1);- std::shared_ptr<ov::Node> sizes_input = registry.make<ov::op::v0::Constant>(ov::element::i32, ov::Shape{}, 1);- sizes_input = registry.add(ov::op::util::make_try_fold<ov::op::v3::Broadcast>(sizes_input, broadcast_shape));+ std::shared_ptr<ov::Node> sizes_input = registry.make<v0::Constant>(ov::element::i32, ov::Shape{}, 1);+ sizes_input = registry.add(op_util::make_try_fold<v3::Broadcast>(sizes_input, broadcast_shape));ret.first = sizes_input;} else {ret.first = interpolate->input_value(1);- std::shared_ptr<ov::Node> scales_input =- registry.make<ov::op::v0::Constant>(ov::element::f32, ov::Shape{}, 1.0f);- scales_input = registry.add(ov::op::util::make_try_fold<ov::op::v3::Broadcast>(scales_input, broadcast_shape));+ std::shared_ptr<ov::Node> scales_input = registry.make<v0::Constant>(ov::element::f32, ov::Shape{}, 1.0f);+ scales_input = registry.add(op_util::make_try_fold<v3::Broadcast>(scales_input, broadcast_shape));ret.second = scales_input;}@@ -56,9 +62,9 @@ std::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> make_v4_inputs(ov::pass::ConvertInterpolate11ToInterpolate4::ConvertInterpolate11ToInterpolate4() {MATCHER_SCOPE(ConvertInterpolate11ToInterpolate4);- const auto interpolate_v11_pattern = pattern::wrap_type<ov::op::v11::Interpolate>();+ const auto interpolate_v11_pattern = ov::pass::pattern::wrap_type<v11::Interpolate>();- const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto v4_compatible_interpolation_mode = [](const op::util::InterpolateBase::InterpolateMode mode) {constexpr std::array<op::util::InterpolateBase::InterpolateMode, 4> allowed_modes = {op::util::InterpolateBase::InterpolateMode::NEAREST,@@ -69,29 +75,29 @@ ov::pass::ConvertInterpolate11ToInterpolate4::ConvertInterpolate11ToInterpolate4return std::find(std::begin(allowed_modes), std::end(allowed_modes), mode) != std::end(allowed_modes);};- const auto interpolate_v11 = ov::as_type_ptr<ov::op::v11::Interpolate>(m.get_match_root());+ const auto interpolate_v11 = ov::as_type_ptr<v11::Interpolate>(m.get_match_root());if (!interpolate_v11 || !v4_compatible_interpolation_mode(interpolate_v11->get_attrs().mode) ||transformation_callback(interpolate_v11)) {return false;}// downgrade only if the interpolation mode used to create v11 is supported by v4- std::shared_ptr<ov::op::v4::Interpolate> interpolate_v4;+ std::shared_ptr<v4::Interpolate> interpolate_v4;ov::Output<ov::Node> v4_input_output_shape;ov::Output<ov::Node> v4_input_scales;std::tie(v4_input_output_shape, v4_input_scales) = make_v4_inputs(interpolate_v11);if (interpolate_v11->get_input_size() == 3) { // with axes input- interpolate_v4 = std::make_shared<ov::op::v4::Interpolate>(interpolate_v11->input_value(0),- v4_input_output_shape,- v4_input_scales,- interpolate_v11->input_value(2),- interpolate_v11->get_attrs());+ interpolate_v4 = std::make_shared<v4::Interpolate>(interpolate_v11->input_value(0),+ v4_input_output_shape,+ v4_input_scales,+ interpolate_v11->input_value(2),+ interpolate_v11->get_attrs());} else {- interpolate_v4 = std::make_shared<ov::op::v4::Interpolate>(interpolate_v11->input_value(0),- v4_input_output_shape,- v4_input_scales,- interpolate_v11->get_attrs());+ interpolate_v4 = std::make_shared<v4::Interpolate>(interpolate_v11->input_value(0),+ v4_input_output_shape,+ v4_input_scales,+ interpolate_v11->get_attrs());}interpolate_v4->set_friendly_name(interpolate_v11->get_friendly_name());@@ -101,6 +107,6 @@ ov::pass::ConvertInterpolate11ToInterpolate4::ConvertInterpolate11ToInterpolate4return true;};- auto m = std::make_shared<pattern::Matcher>(interpolate_v11_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(interpolate_v11_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_interpolate1_to_interpolate4.cpp b/src/common/transformations/src/transformations/op_conversions/convert_interpolate1_to_interpolate4.cppindex b4d68bc959a..8c12a13ec6a 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_interpolate1_to_interpolate4.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_interpolate1_to_interpolate4.cpp@@ -18,20 +18,25 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v4 = ov::op::v4;ov::pass::ConvertInterpolate1ToInterpolate4::ConvertInterpolate1ToInterpolate4() {MATCHER_SCOPE(ConvertInterpolate1ToInterpolate4);- auto interpolate1 = ov::pass::pattern::wrap_type<ov::op::v0::Interpolate>(- {pattern::any_input(pattern::has_static_rank()), pattern::any_input()});- matcher_pass_callback callback = [](pattern::Matcher& m) {- auto interpolationV0 = ov::as_type_ptr<ov::op::v0::Interpolate>(m.get_match_root());+ auto interpolate1 =+ ov::pass::pattern::wrap_type<v0::Interpolate>({any_input(ov::pass::pattern::has_static_rank()), any_input()});+ matcher_pass_callback callback = [](Matcher& m) {+ auto interpolationV0 = ov::as_type_ptr<v0::Interpolate>(m.get_match_root());if (!interpolationV0) {return false;}auto attrsV0 = interpolationV0->get_attrs();std::vector<size_t> axes{attrsV0.axes.begin(), attrsV0.axes.end()};- const auto& out_dims = std::make_shared<ov::op::v0::Convert>(interpolationV0->input_value(1), element::f32);- const auto& in_dims = std::make_shared<ov::op::v0::Convert>(+ const auto& out_dims = std::make_shared<v0::Convert>(interpolationV0->input_value(1), element::f32);+ const auto& in_dims = std::make_shared<v0::Convert>(ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(interpolationV0->input_value(0), axes),element::f32);@@ -39,45 +44,45 @@ ov::pass::ConvertInterpolate1ToInterpolate4::ConvertInterpolate1ToInterpolate4()if (const auto& constant = ov::util::get_constant_from_source(scales)) {scales = constant;}- auto axisConstant = ov::op::v0::Constant::create(ov::element::i64, {axes.size()}, axes);+ auto axisConstant = v0::Constant::create(ov::element::i64, {axes.size()}, axes);- ov::op::v4::Interpolate::InterpolateAttrs attrsV4;+ v4::Interpolate::InterpolateAttrs attrsV4;auto input_shape_rank = interpolationV0->get_input_partial_shape(0).rank().get_length();if (attrsV0.mode == "nearest") {- attrsV4.mode = ov::op::v4::Interpolate::InterpolateMode::NEAREST;+ attrsV4.mode = v4::Interpolate::InterpolateMode::NEAREST;} else if (attrsV0.mode == "linear") {// If we write only- // attrsV4.mode = ov::op::v4::Interpolate::InterpolateMode::linear;+ // attrsV4.mode = v4::Interpolate::InterpolateMode::linear;// instead of a conditional statements below when attrsV0.mode == "linear",// then we have a performance drop, because CPU have no optimized// version of the 'linear' mode.// TODO: delete this conditional statement, when CPU will have// optimized version of the 'linear' mode.if (input_shape_rank < 5) {- attrsV4.mode = ov::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX;+ attrsV4.mode = v4::Interpolate::InterpolateMode::LINEAR_ONNX;} else if (input_shape_rank == 5) {- attrsV4.mode = ov::op::v4::Interpolate::InterpolateMode::LINEAR;+ attrsV4.mode = v4::Interpolate::InterpolateMode::LINEAR;} else {return false;}} else if (attrsV0.mode == "cubic") {- attrsV4.mode = ov::op::v4::Interpolate::InterpolateMode::CUBIC;+ attrsV4.mode = v4::Interpolate::InterpolateMode::CUBIC;} else if (attrsV0.mode == "linear_onnx") {- attrsV4.mode = ov::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX;+ attrsV4.mode = v4::Interpolate::InterpolateMode::LINEAR_ONNX;} else {return false;}- attrsV4.shape_calculation_mode = ov::op::v4::Interpolate::ShapeCalcMode::SIZES;- attrsV4.nearest_mode = ov::op::v4::Interpolate::NearestMode::SIMPLE;+ attrsV4.shape_calculation_mode = v4::Interpolate::ShapeCalcMode::SIZES;+ attrsV4.nearest_mode = v4::Interpolate::NearestMode::SIMPLE;attrsV4.pads_begin = attrsV0.pads_begin;attrsV4.pads_end = attrsV0.pads_end;attrsV4.antialias = attrsV0.antialias;- attrsV4.coordinate_transformation_mode = ov::op::v4::Interpolate::CoordinateTransformMode::ASYMMETRIC;+ attrsV4.coordinate_transformation_mode = v4::Interpolate::CoordinateTransformMode::ASYMMETRIC;attrsV4.cube_coeff = -0.75f;if (attrsV0.align_corners) {- attrsV4.coordinate_transformation_mode = ov::op::v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS;- } else if ((attrsV4.mode == ov::op::v4::Interpolate::InterpolateMode::LINEAR_ONNX ||- attrsV4.mode == ov::op::v4::Interpolate::InterpolateMode::LINEAR) &&+ attrsV4.coordinate_transformation_mode = v4::Interpolate::CoordinateTransformMode::ALIGN_CORNERS;+ } else if ((attrsV4.mode == v4::Interpolate::InterpolateMode::LINEAR_ONNX ||+ attrsV4.mode == v4::Interpolate::InterpolateMode::LINEAR) &&std::all_of(attrsV4.pads_begin.begin(),attrsV4.pads_begin.end(),[](size_t i) {@@ -89,14 +94,14 @@ ov::pass::ConvertInterpolate1ToInterpolate4::ConvertInterpolate1ToInterpolate4()return i == 0;}) &&!(input_shape_rank - 2 == 2 && attrsV0.axes == AxisSet{2, 3})) {- attrsV4.coordinate_transformation_mode = ov::op::v4::Interpolate::CoordinateTransformMode::HALF_PIXEL;+ attrsV4.coordinate_transformation_mode = v4::Interpolate::CoordinateTransformMode::HALF_PIXEL;}- auto interpolateV4 = std::make_shared<ov::op::v4::Interpolate>(interpolationV0->input_value(0),- interpolationV0->input_value(1),- scales,- axisConstant,- attrsV4);+ auto interpolateV4 = std::make_shared<v4::Interpolate>(interpolationV0->input_value(0),+ interpolationV0->input_value(1),+ scales,+ axisConstant,+ attrsV4);interpolateV4->set_friendly_name(interpolationV0->get_friendly_name());ov::copy_runtime_info(interpolationV0, interpolateV4);@@ -104,6 +109,6 @@ ov::pass::ConvertInterpolate1ToInterpolate4::ConvertInterpolate1ToInterpolate4()return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(interpolate1, matcher_name);+ auto m = std::make_shared<Matcher>(interpolate1, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.cpp b/src/common/transformations/src/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.cppindex 9ddcff0f5ac..ebdba786442 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_matrix_nms_to_matrix_nms_ie.cpp@@ -16,12 +16,16 @@#include "ov_ops/nms_static_shape_ie.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v8 = ov::op::v8;ov::pass::ConvertMatrixNmsToMatrixNmsIE::ConvertMatrixNmsToMatrixNmsIE(bool force_i32_output_type) {MATCHER_SCOPE(ConvertMatrixNmsToMatrixNmsIE);- auto nms = ov::pass::pattern::wrap_type<ov::op::v8::MatrixNms>();+ auto nms = ov::pass::pattern::wrap_type<v8::MatrixNms>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- auto nms = ov::as_type_ptr<ov::op::v8::MatrixNms>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto nms = ov::as_type_ptr<v8::MatrixNms>(m.get_match_root());if (!nms || transformation_callback(nms)) {return false;}@@ -36,9 +40,8 @@ ov::pass::ConvertMatrixNmsToMatrixNmsIE::ConvertMatrixNmsToMatrixNmsIE(bool forcNodeVector new_ops;auto attrs = nms->get_attrs();attrs.output_type = force_i32_output_type ? element::i32 : attrs.output_type;- auto nms_new = std::make_shared<op::internal::NmsStaticShapeIE<ov::op::v8::MatrixNms>>(new_args.at(0),- new_args.at(1),- attrs);+ auto nms_new =+ std::make_shared<op::internal::NmsStaticShapeIE<v8::MatrixNms>>(new_args.at(0), new_args.at(1), attrs);new_ops.emplace_back(nms_new);Output<Node> output_0 = nms_new->output(0);@@ -46,12 +49,12 @@ ov::pass::ConvertMatrixNmsToMatrixNmsIE::ConvertMatrixNmsToMatrixNmsIE(bool forcOutput<Node> output_2 = nms_new->output(2);if (nms->output(1).get_element_type() != output_1.get_element_type()) {- output_1 = std::make_shared<ov::op::v0::Convert>(output_1, nms->output(1).get_element_type());+ output_1 = std::make_shared<v0::Convert>(output_1, nms->output(1).get_element_type());new_ops.emplace_back(output_1.get_node_shared_ptr());}if (nms->output(2).get_element_type() != output_2.get_element_type()) {- output_2 = std::make_shared<ov::op::v0::Convert>(output_2, nms->output(2).get_element_type());+ output_2 = std::make_shared<v0::Convert>(output_2, nms->output(2).get_element_type());new_ops.emplace_back(output_2.get_node_shared_ptr());}@@ -61,6 +64,6 @@ ov::pass::ConvertMatrixNmsToMatrixNmsIE::ConvertMatrixNmsToMatrixNmsIE(bool forcreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(nms, matcher_name);+ auto m = std::make_shared<Matcher>(nms, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_maxpool_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_maxpool_downgrade.cppindex 7f2263ad76b..da553cb7f90 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_maxpool_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_maxpool_downgrade.cpp@@ -26,13 +26,20 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "openvino/pass/visualize_tree.hpp"+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;+namespace v14 = ov::op::v14;ov::pass::ConvertMaxPool8ToMaxPool1::ConvertMaxPool8ToMaxPool1() {MATCHER_SCOPE(ConvertMaxPool8ToMaxPool1);- auto maxpool_v8_pattern = pattern::wrap_type<ov::op::v8::MaxPool>();+ auto maxpool_v8_pattern = wrap_type<v8::MaxPool>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto maxpool_v8_node = ov::as_type_ptr<ov::op::v8::MaxPool>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto maxpool_v8_node = ov::as_type_ptr<v8::MaxPool>(m.get_match_root());if (!maxpool_v8_node || maxpool_v8_node->get_output_target_inputs(1).size() != 0)return false;@@ -41,13 +48,13 @@ ov::pass::ConvertMaxPool8ToMaxPool1::ConvertMaxPool8ToMaxPool1() {if (dilation != 1)return false;- auto maxpool_v1_node = std::make_shared<ov::op::v1::MaxPool>(maxpool_v8_node->input_value(0),- maxpool_v8_node->get_strides(),- maxpool_v8_node->get_pads_begin(),- maxpool_v8_node->get_pads_end(),- maxpool_v8_node->get_kernel(),- maxpool_v8_node->get_rounding_type(),- maxpool_v8_node->get_auto_pad());+ auto maxpool_v1_node = std::make_shared<v1::MaxPool>(maxpool_v8_node->input_value(0),+ maxpool_v8_node->get_strides(),+ maxpool_v8_node->get_pads_begin(),+ maxpool_v8_node->get_pads_end(),+ maxpool_v8_node->get_kernel(),+ maxpool_v8_node->get_rounding_type(),+ maxpool_v8_node->get_auto_pad());maxpool_v1_node->set_friendly_name(maxpool_v8_node->get_friendly_name());maxpool_v8_node->output(0).replace(maxpool_v1_node->output(0));@@ -57,34 +64,34 @@ ov::pass::ConvertMaxPool8ToMaxPool1::ConvertMaxPool8ToMaxPool1() {return true;};- auto m = std::make_shared<pattern::Matcher>(maxpool_v8_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(maxpool_v8_pattern, matcher_name);register_matcher(m, callback);}ov::pass::ConvertMaxPool14ToMaxPool8::ConvertMaxPool14ToMaxPool8() {MATCHER_SCOPE(ConvertMaxPool14ToMaxPool8);- const auto max_pool_v14_pattern = pattern::wrap_type<ov::op::v14::MaxPool>();-- const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- using ov::op::v0::Constant;- using ov::op::v0::Concat;- using ov::op::v1::Subtract;- using ov::op::v1::Multiply;- using ov::op::v1::Greater;- using ov::op::v1::Select;- using ov::op::v1::ConvertLike;- using ov::op::v1::Add;+ const auto max_pool_v14_pattern = wrap_type<v14::MaxPool>();++ const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ using v0::Constant;+ using v0::Concat;+ using v1::Subtract;+ using v1::Multiply;+ using v1::Greater;+ using v1::Select;+ using v1::ConvertLike;+ using v1::Add;using ov::op::v3::ShapeOf;using ov::op::v4::Range;- using ov::op::v8::Gather;+ using v8::Gather;using ov::op::v12::Pad;- const auto max_pool_v14 = ov::as_type_ptr<ov::op::v14::MaxPool>(m.get_match_root());+ const auto max_pool_v14 = ov::as_type_ptr<v14::MaxPool>(m.get_match_root());if (!max_pool_v14 || transformation_callback(max_pool_v14)) {return false;}const auto rounding_type_v14 = max_pool_v14->get_rounding_type();- std::shared_ptr<ov::op::v8::MaxPool> max_pool_v8;+ std::shared_ptr<v8::MaxPool> max_pool_v8;NodeRegistry node_registry;if (rounding_type_v14 == ov::op::RoundingType::CEIL_TORCH) {auto input = max_pool_v14->input_value(0);@@ -112,13 +119,13 @@ ov::pass::ConvertMaxPool14ToMaxPool8::ConvertMaxPool14ToMaxPool8() {const auto in_left_padded = node_registry.make<Add>(gth_in_dims, padding_begin_node);// gather output spatial dims and prepare it for compare as values (out_dim - 1) * stride- const auto mp = node_registry.make<ov::op::v8::MaxPool>(input,- max_pool_v14->get_strides(),- max_pool_v14->get_dilations(),- max_pool_v14->get_pads_begin(),- max_pool_v14->get_pads_end(),- max_pool_v14->get_kernel(),- ov::op::RoundingType::CEIL);+ const auto mp = node_registry.make<v8::MaxPool>(input,+ max_pool_v14->get_strides(),+ max_pool_v14->get_dilations(),+ max_pool_v14->get_pads_begin(),+ max_pool_v14->get_pads_end(),+ max_pool_v14->get_kernel(),+ ov::op::RoundingType::CEIL);const auto shape_of_mp = node_registry.make<ShapeOf>(mp, element::i32);const auto gth_out_dims = node_registry.make<Gather>(shape_of_mp, dim_idxs, zero);const auto out_sub_one = node_registry.make<Subtract>(gth_out_dims, one);@@ -141,28 +148,28 @@ ov::pass::ConvertMaxPool14ToMaxPool8::ConvertMaxPool14ToMaxPool8() {std::fill_n(pads_begin.begin(), pads_begin.size(), 0);std::fill_n(pads_end.begin(), pads_end.size(), 0);- max_pool_v8 = node_registry.make<ov::op::v8::MaxPool>(pad_node,- max_pool_v14->get_strides(),- max_pool_v14->get_dilations(),- pads_begin,- pads_end,- max_pool_v14->get_kernel(),- ov::op::RoundingType::CEIL,- ov::op::PadType::EXPLICIT,- max_pool_v14->get_index_element_type(),- max_pool_v14->get_axis());+ max_pool_v8 = node_registry.make<v8::MaxPool>(pad_node,+ max_pool_v14->get_strides(),+ max_pool_v14->get_dilations(),+ pads_begin,+ pads_end,+ max_pool_v14->get_kernel(),+ ov::op::RoundingType::CEIL,+ ov::op::PadType::EXPLICIT,+ max_pool_v14->get_index_element_type(),+ max_pool_v14->get_axis());copy_runtime_info(max_pool_v14, node_registry.get());} else {- max_pool_v8 = std::make_shared<ov::op::v8::MaxPool>(max_pool_v14->input_value(0),- max_pool_v14->get_strides(),- max_pool_v14->get_dilations(),- max_pool_v14->get_pads_begin(),- max_pool_v14->get_pads_end(),- max_pool_v14->get_kernel(),- rounding_type_v14,- max_pool_v14->get_auto_pad(),- max_pool_v14->get_index_element_type(),- max_pool_v14->get_axis());+ max_pool_v8 = std::make_shared<v8::MaxPool>(max_pool_v14->input_value(0),+ max_pool_v14->get_strides(),+ max_pool_v14->get_dilations(),+ max_pool_v14->get_pads_begin(),+ max_pool_v14->get_pads_end(),+ max_pool_v14->get_kernel(),+ rounding_type_v14,+ max_pool_v14->get_auto_pad(),+ max_pool_v14->get_index_element_type(),+ max_pool_v14->get_axis());copy_runtime_info(max_pool_v14, max_pool_v8);}max_pool_v8->set_friendly_name(max_pool_v14->get_friendly_name());@@ -171,6 +178,6 @@ ov::pass::ConvertMaxPool14ToMaxPool8::ConvertMaxPool14ToMaxPool8() {return true;};- auto m = std::make_shared<pattern::Matcher>(max_pool_v14_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(max_pool_v14_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_maxpool_upgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_maxpool_upgrade.cppindex 3fd2378eff5..42a2393a840 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_maxpool_upgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_maxpool_upgrade.cpp@@ -10,15 +10,18 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v1 = ov::op::v1;ov::pass::ConvertMaxPool1ToMaxPool8::ConvertMaxPool1ToMaxPool8() {MATCHER_SCOPE(ConvertMaxPool1ToMaxPool8);// Replaces v1::MaxPool with v8::MaxPool with default dilations, axis and index_element_type attributes- auto input = pattern::any_input(pattern::has_static_rank());- auto maxpool_v1_pattern = ov::pass::pattern::wrap_type<ov::op::v1::MaxPool>({input});+ auto input = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());+ auto maxpool_v1_pattern = ov::pass::pattern::wrap_type<v1::MaxPool>({input});- matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {- auto maxpool_v1_node = ov::as_type_ptr<ov::op::v1::MaxPool>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto maxpool_v1_node = ov::as_type_ptr<v1::MaxPool>(m.get_match_root());if (!maxpool_v1_node)return false;@@ -47,6 +50,6 @@ ov::pass::ConvertMaxPool1ToMaxPool8::ConvertMaxPool1ToMaxPool8() {return true;};- auto m = std::make_shared<pattern::Matcher>(maxpool_v1_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(maxpool_v1_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_mod.cpp b/src/common/transformations/src/transformations/op_conversions/convert_mod.cppindex 0b95f451681..e879de2ebf9 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_mod.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_mod.cpp@@ -20,33 +20,37 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/rt_info/nonconvertible_divide.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::ConvertMod::ConvertMod() {MATCHER_SCOPE(ConvertMod);- auto mod = ov::pass::pattern::wrap_type<ov::op::v1::Mod>();+ auto mod = ov::pass::pattern::wrap_type<v1::Mod>();- matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto mod = ov::as_type_ptr<ov::op::v1::Mod>(m.get_match_root());+ matcher_pass_callback callback = [this](Matcher& m) {+ auto mod = ov::as_type_ptr<v1::Mod>(m.get_match_root());if (!mod) {return false;}- const auto dividend = std::make_shared<ov::op::v0::Abs>(mod->input_value(0));- const auto dividend_sign = std::make_shared<ov::op::v0::Sign>(mod->input_value(0));+ const auto dividend = std::make_shared<v0::Abs>(mod->input_value(0));+ const auto dividend_sign = std::make_shared<v0::Sign>(mod->input_value(0));const auto dividend_et = dividend->get_element_type();- const auto divisor = std::make_shared<ov::op::v0::Abs>(mod->input_value(1));+ const auto divisor = std::make_shared<v0::Abs>(mod->input_value(1));// truncated(a / b)- auto div = register_new_node<ov::op::v1::Divide>(dividend, divisor);+ auto div = register_new_node<v1::Divide>(dividend, divisor);disable_divide_conversion(div);- auto convert_to_i64 = std::make_shared<ov::op::v0::Convert>(div, ov::element::i64);- auto convert = std::make_shared<ov::op::v0::Convert>(convert_to_i64, dividend_et);+ auto convert_to_i64 = std::make_shared<v0::Convert>(div, ov::element::i64);+ auto convert = std::make_shared<v0::Convert>(convert_to_i64, dividend_et);// truncated(a / b) * b- auto multiplication = std::make_shared<ov::op::v1::Multiply>(convert, divisor);+ auto multiplication = std::make_shared<v1::Multiply>(convert, divisor);// a mod b = a - truncated(a / b) * b- auto sub = register_new_node<ov::op::v1::Subtract>(dividend, multiplication);+ auto sub = register_new_node<v1::Subtract>(dividend, multiplication);// apply sign of dividend- auto mul = std::make_shared<ov::op::v1::Multiply>(dividend_sign, sub);+ auto mul = std::make_shared<v1::Multiply>(dividend_sign, sub);mul->set_friendly_name(mod->get_friendly_name());ov::copy_runtime_info(@@ -56,6 +60,6 @@ ov::pass::ConvertMod::ConvertMod() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mod, matcher_name);+ auto m = std::make_shared<Matcher>(mod, matcher_name);this->register_matcher(m, callback, PassProperty::CHANGE_DYNAMIC_STATE);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.cpp b/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.cppindex ec4e89895ff..cc931f47e98 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_to_multiclass_nms_ie.cpp@@ -17,11 +17,14 @@using namespace ov;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;pass::ConvertMulticlassNmsToMulticlassNmsIE::ConvertMulticlassNmsToMulticlassNmsIE(bool force_i32_output_type) {MATCHER_SCOPE(ConvertMulticlassNmsToMulticlassNmsIE);- auto nms = pattern::wrap_type<op::util::MulticlassNmsBase>();+ auto nms = ov::pass::pattern::wrap_type<op::util::MulticlassNmsBase>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto nms = ov::as_type_ptr<op::util::MulticlassNmsBase>(m.get_match_root());if (!nms || transformation_callback(nms)) {return false;@@ -60,12 +63,12 @@ pass::ConvertMulticlassNmsToMulticlassNmsIE::ConvertMulticlassNmsToMulticlassNmsOutput<Node> output_2 = nms_new->output(2);if (nms->output(1).get_element_type() != output_1.get_element_type()) {- output_1 = std::make_shared<ov::op::v0::Convert>(output_1, nms->output(1).get_element_type());+ output_1 = std::make_shared<v0::Convert>(output_1, nms->output(1).get_element_type());new_ops.emplace_back(output_1.get_node_shared_ptr());}if (nms->output(2).get_element_type() != output_2.get_element_type()) {- output_2 = std::make_shared<ov::op::v0::Convert>(output_2, nms->output(2).get_element_type());+ output_2 = std::make_shared<v0::Convert>(output_2, nms->output(2).get_element_type());new_ops.emplace_back(output_2.get_node_shared_ptr());}@@ -75,6 +78,6 @@ pass::ConvertMulticlassNmsToMulticlassNmsIE::ConvertMulticlassNmsToMulticlassNmsreturn true;};- auto m = std::make_shared<pattern::Matcher>(nms, matcher_name);+ auto m = std::make_shared<Matcher>(nms, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_upgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_upgrade.cppindex 37431ce1598..04ca91c21a2 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_upgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_multiclass_nms_upgrade.cpp@@ -10,13 +10,16 @@#include "openvino/op/multiclass_nms.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v8 = ov::op::v8;ov::pass::ConvertMulticlassNms8ToMulticlassNms9::ConvertMulticlassNms8ToMulticlassNms9() {MATCHER_SCOPE(ConvertMulticlassNms8ToMulticlassNms9);- auto nms_v8_pattern = pattern::wrap_type<ov::op::v8::MulticlassNms>();+ auto nms_v8_pattern = ov::pass::pattern::wrap_type<v8::MulticlassNms>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto nms_v8_node = ov::as_type_ptr<ov::op::v8::MulticlassNms>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto nms_v8_node = ov::as_type_ptr<v8::MulticlassNms>(m.get_match_root());if (!nms_v8_node)return false;@@ -32,6 +35,6 @@ ov::pass::ConvertMulticlassNms8ToMulticlassNms9::ConvertMulticlassNms8ToMulticlareturn true;};- auto m = std::make_shared<pattern::Matcher>(nms_v8_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(nms_v8_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_mvn1_to_mvn6.cpp b/src/common/transformations/src/transformations/op_conversions/convert_mvn1_to_mvn6.cppindex 7de0bbbd3f5..cb92f8e98e2 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_mvn1_to_mvn6.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_mvn1_to_mvn6.cpp@@ -14,12 +14,15 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;ov::pass::ConvertMVN1ToMVN6::ConvertMVN1ToMVN6() {MATCHER_SCOPE(ConvertMVN1ToMVN6);- auto mvn = pattern::wrap_type<ov::op::v0::MVN>();+ auto mvn = ov::pass::pattern::wrap_type<v0::MVN>();- matcher_pass_callback callback = [](pattern::Matcher& m) {- auto mvn_node = ov::as_type_ptr<ov::op::v0::MVN>(m.get_match_root());+ matcher_pass_callback callback = [](Matcher& m) {+ auto mvn_node = ov::as_type_ptr<v0::MVN>(m.get_match_root());if (!mvn_node) {return false;}@@ -38,7 +41,7 @@ ov::pass::ConvertMVN1ToMVN6::ConvertMVN1ToMVN6() {std::vector<int64_t> axes_v(input_rank.get_length() - start_axis);std::iota(axes_v.begin(), axes_v.end(), start_axis);- auto axes = ov::op::v0::Constant::create(ov::element::i64, {axes_v.size()}, axes_v);+ auto axes = v0::Constant::create(ov::element::i64, {axes_v.size()}, axes_v);auto mvn6_node = std::make_shared<ov::op::v6::MVN>(input,axes,mvn_node->get_normalize_variance(),@@ -51,6 +54,6 @@ ov::pass::ConvertMVN1ToMVN6::ConvertMVN1ToMVN6() {return true;};- auto m = std::make_shared<pattern::Matcher>(mvn, matcher_name);+ auto m = std::make_shared<Matcher>(mvn, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_negative.cpp b/src/common/transformations/src/transformations/op_conversions/convert_negative.cppindex 20afc1ade53..533b8e533eb 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_negative.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_negative.cpp@@ -15,25 +15,27 @@#include "openvino/op/negative.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;ov::pass::ConvertNegative::ConvertNegative() {MATCHER_SCOPE(ConvertNegative);- auto neg = ov::pass::pattern::wrap_type<ov::op::v0::Negative>();+ auto neg = ov::pass::pattern::wrap_type<v0::Negative>();- matcher_pass_callback callback = [](pattern::Matcher& m) {- auto neg = ov::as_type_ptr<ov::op::v0::Negative>(m.get_match_root());+ matcher_pass_callback callback = [](Matcher& m) {+ auto neg = ov::as_type_ptr<v0::Negative>(m.get_match_root());if (!neg) {return false;}- auto mul = std::make_shared<ov::op::v1::Multiply>(- neg->input(0).get_source_output(),- ov::op::v0::Constant::create(neg->get_element_type(), Shape{}, {-1}));+ auto mul = std::make_shared<ov::op::v1::Multiply>(neg->input(0).get_source_output(),+ v0::Constant::create(neg->get_element_type(), Shape{}, {-1}));mul->set_friendly_name(neg->get_friendly_name());ov::copy_runtime_info(neg, mul);ov::replace_node(neg, mul);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(neg, matcher_name);+ auto m = std::make_shared<Matcher>(neg, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_nms9_to_nms_ie_internal.cpp b/src/common/transformations/src/transformations/op_conversions/convert_nms9_to_nms_ie_internal.cppindex fe17915ae7a..1e140b20305 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_nms9_to_nms_ie_internal.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_nms9_to_nms_ie_internal.cpp@@ -18,12 +18,17 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "ov_ops/nms_ie_internal.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v9 = ov::op::v9;ov::pass::ConvertNMS9ToNMSIEInternal::ConvertNMS9ToNMSIEInternal() {MATCHER_SCOPE(ConvertNMS9ToNMSIEInternal);- auto nms = ov::pass::pattern::wrap_type<ov::op::v9::NonMaxSuppression>();+ auto nms = ov::pass::pattern::wrap_type<v9::NonMaxSuppression>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- auto nms_9 = ov::as_type_ptr<ov::op::v9::NonMaxSuppression>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto nms_9 = ov::as_type_ptr<v9::NonMaxSuppression>(m.get_match_root());if (!nms_9 || transformation_callback(nms_9)) {return false;}@@ -32,11 +37,11 @@ ov::pass::ConvertNMS9ToNMSIEInternal::ConvertNMS9ToNMSIEInternal() {const std::size_t num_of_inputs = new_args.size();const auto& max_per_class =- num_of_inputs > 2 ? new_args.at(2) : ov::op::v0::Constant::create(element::i32, Shape{}, {0});+ num_of_inputs > 2 ? new_args.at(2) : v0::Constant::create(element::i32, Shape{}, {0});const auto& iou_threshold =- num_of_inputs > 3 ? new_args.at(3) : ov::op::v0::Constant::create(element::f32, Shape{}, {.0f});+ num_of_inputs > 3 ? new_args.at(3) : v0::Constant::create(element::f32, Shape{}, {.0f});const auto& score_threshold =- num_of_inputs > 4 ? new_args.at(4) : ov::op::v0::Constant::create(element::f32, Shape{}, {.0f});+ num_of_inputs > 4 ? new_args.at(4) : v0::Constant::create(element::f32, Shape{}, {.0f});// vector of new openvino operationsNodeVector new_ops;@@ -48,27 +53,26 @@ ov::pass::ConvertNMS9ToNMSIEInternal::ConvertNMS9ToNMSIEInternal() {Output<Node> new_score_threshold;Output<Node> new_soft_nms_sigma;- Output<Node> new_shape_for_max_per_class = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});- Output<Node> new_shape_for_iou_threshold = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});- Output<Node> new_shape_for_score_threshold = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});- Output<Node> new_shape_for_soft_nms_sigma = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_max_per_class = v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_iou_threshold = v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_score_threshold = v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_soft_nms_sigma = v0::Constant::create(ov::element::i64, Shape{1}, {1});- new_max_per_class = std::make_shared<ov::op::v1::Reshape>(max_per_class, new_shape_for_max_per_class, true);+ new_max_per_class = std::make_shared<v1::Reshape>(max_per_class, new_shape_for_max_per_class, true);new_ops.emplace_back(new_max_per_class.get_node_shared_ptr());- new_iou_threshold = std::make_shared<ov::op::v1::Reshape>(iou_threshold, new_shape_for_iou_threshold, true);+ new_iou_threshold = std::make_shared<v1::Reshape>(iou_threshold, new_shape_for_iou_threshold, true);new_ops.emplace_back(new_iou_threshold.get_node_shared_ptr());- new_score_threshold =- std::make_shared<ov::op::v1::Reshape>(score_threshold, new_shape_for_score_threshold, true);+ new_score_threshold = std::make_shared<v1::Reshape>(score_threshold, new_shape_for_score_threshold, true);new_ops.emplace_back(new_score_threshold.get_node_shared_ptr());int center_point_box = 0;switch (nms_9->get_box_encoding()) {- case ov::op::v9::NonMaxSuppression::BoxEncodingType::CENTER:+ case v9::NonMaxSuppression::BoxEncodingType::CENTER:center_point_box = 1;break;- case ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER:+ case v9::NonMaxSuppression::BoxEncodingType::CORNER:center_point_box = 0;break;default:@@ -78,8 +82,7 @@ ov::pass::ConvertNMS9ToNMSIEInternal::ConvertNMS9ToNMSIEInternal() {std::shared_ptr<op::internal::NonMaxSuppressionIEInternal> nms_legacy{nullptr};if (num_of_inputs > 5 && !nms_9->is_soft_nms_sigma_constant_and_default()) {- new_soft_nms_sigma =- std::make_shared<ov::op::v1::Reshape>(new_args.at(5), new_shape_for_soft_nms_sigma, true);+ new_soft_nms_sigma = std::make_shared<v1::Reshape>(new_args.at(5), new_shape_for_soft_nms_sigma, true);new_ops.emplace_back(new_soft_nms_sigma.get_node_shared_ptr());nms_legacy =std::make_shared<op::internal::NonMaxSuppressionIEInternal>(new_args.at(0),@@ -109,14 +112,14 @@ ov::pass::ConvertNMS9ToNMSIEInternal::ConvertNMS9ToNMSIEInternal() {Output<Node> output_0 = nms_legacy->output(0);if (nms_9->output(0).get_element_type() != output_0.get_element_type()) {- output_0 = std::make_shared<ov::op::v0::Convert>(output_0, nms_9->output(0).get_element_type());+ output_0 = std::make_shared<v0::Convert>(output_0, nms_9->output(0).get_element_type());output_0.get_node_shared_ptr()->set_friendly_name(ov::util::make_default_tensor_name(nms_9->output(0)));new_ops.emplace_back(output_0.get_node_shared_ptr());}Output<Node> output_2 = nms_legacy->output(2);if (nms_9->output(2).get_element_type() != output_2.get_element_type()) {- output_2 = std::make_shared<ov::op::v0::Convert>(output_2, nms_9->output(2).get_element_type());+ output_2 = std::make_shared<v0::Convert>(output_2, nms_9->output(2).get_element_type());output_2.get_node_shared_ptr()->set_friendly_name(ov::util::make_default_tensor_name(nms_9->output(2)));new_ops.emplace_back(output_2.get_node_shared_ptr());}@@ -127,6 +130,6 @@ ov::pass::ConvertNMS9ToNMSIEInternal::ConvertNMS9ToNMSIEInternal() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(nms, matcher_name);+ auto m = std::make_shared<Matcher>(nms, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_nms_rotated_to_nms_ie_internal.cpp b/src/common/transformations/src/transformations/op_conversions/convert_nms_rotated_to_nms_ie_internal.cppindex 3305b580111..34bcdd6fc7b 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_nms_rotated_to_nms_ie_internal.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_nms_rotated_to_nms_ie_internal.cpp@@ -19,12 +19,17 @@#include "ov_ops/nms_ie_internal.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v13 = ov::op::v13;ov::pass::ConvertNMSRotatedToNMSIEInternal::ConvertNMSRotatedToNMSIEInternal() {MATCHER_SCOPE(ConvertNMSRotatedToNMSIEInternal);- auto nms = ov::pass::pattern::wrap_type<ov::op::v13::NMSRotated>();+ auto nms = ov::pass::pattern::wrap_type<v13::NMSRotated>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- auto nms_rotated = ov::as_type_ptr<ov::op::v13::NMSRotated>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto nms_rotated = ov::as_type_ptr<v13::NMSRotated>(m.get_match_root());if (!nms_rotated || transformation_callback(nms_rotated)) {return false;}@@ -47,19 +52,18 @@ ov::pass::ConvertNMSRotatedToNMSIEInternal::ConvertNMSRotatedToNMSIEInternal() {Output<Node> new_score_threshold;Output<Node> new_soft_nms_sigma;- Output<Node> new_shape_for_max_per_class = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});- Output<Node> new_shape_for_iou_threshold = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});- Output<Node> new_shape_for_score_threshold = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});- Output<Node> new_shape_for_soft_nms_sigma = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_max_per_class = v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_iou_threshold = v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_score_threshold = v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_soft_nms_sigma = v0::Constant::create(ov::element::i64, Shape{1}, {1});- new_max_per_class = std::make_shared<ov::op::v1::Reshape>(max_per_class, new_shape_for_max_per_class, true);+ new_max_per_class = std::make_shared<v1::Reshape>(max_per_class, new_shape_for_max_per_class, true);new_ops.emplace_back(new_max_per_class.get_node_shared_ptr());- new_iou_threshold = std::make_shared<ov::op::v1::Reshape>(iou_threshold, new_shape_for_iou_threshold, true);+ new_iou_threshold = std::make_shared<v1::Reshape>(iou_threshold, new_shape_for_iou_threshold, true);new_ops.emplace_back(new_iou_threshold.get_node_shared_ptr());- new_score_threshold =- std::make_shared<ov::op::v1::Reshape>(score_threshold, new_shape_for_score_threshold, true);+ new_score_threshold = std::make_shared<v1::Reshape>(score_threshold, new_shape_for_score_threshold, true);new_ops.emplace_back(new_score_threshold.get_node_shared_ptr());constexpr int BoxEncodingType_Center = 1; // see NonMaxSuppression::BoxEncodingType@@ -88,13 +92,13 @@ ov::pass::ConvertNMSRotatedToNMSIEInternal::ConvertNMSRotatedToNMSIEInternal() {Output<Node> output_0 = nms_legacy->output(0);if (nms_rotated->output(0).get_element_type() != output_0.get_element_type()) {- output_0 = std::make_shared<ov::op::v0::Convert>(output_0, nms_rotated->output(0).get_element_type());+ output_0 = std::make_shared<v0::Convert>(output_0, nms_rotated->output(0).get_element_type());new_ops.emplace_back(output_0.get_node_shared_ptr());}Output<Node> output_2 = nms_legacy->output(2);if (nms_rotated->output(2).get_element_type() != output_2.get_element_type()) {- output_2 = std::make_shared<ov::op::v0::Convert>(output_2, nms_rotated->output(2).get_element_type());+ output_2 = std::make_shared<v0::Convert>(output_2, nms_rotated->output(2).get_element_type());new_ops.emplace_back(output_2.get_node_shared_ptr());}@@ -104,6 +108,6 @@ ov::pass::ConvertNMSRotatedToNMSIEInternal::ConvertNMSRotatedToNMSIEInternal() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(nms, matcher_name);+ auto m = std::make_shared<Matcher>(nms, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_nms_to_nms_ie_internal.cpp b/src/common/transformations/src/transformations/op_conversions/convert_nms_to_nms_ie_internal.cppindex 88481b13dea..30733fc9b39 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_nms_to_nms_ie_internal.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_nms_to_nms_ie_internal.cpp@@ -18,12 +18,17 @@#include "ov_ops/nms_ie_internal.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v5 = ov::op::v5;ov::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() {MATCHER_SCOPE(ConvertNMSToNMSIEInternal);- auto nms = ov::pass::pattern::wrap_type<ov::op::v5::NonMaxSuppression>();+ auto nms = ov::pass::pattern::wrap_type<v5::NonMaxSuppression>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- auto nms_5 = ov::as_type_ptr<ov::op::v5::NonMaxSuppression>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto nms_5 = ov::as_type_ptr<v5::NonMaxSuppression>(m.get_match_root());if (!nms_5 || transformation_callback(nms_5)) {return false;}@@ -31,12 +36,9 @@ ov::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() {const auto new_args = nms_5->input_values();const std::size_t num_of_inputs = new_args.size();- const auto& arg2 =- num_of_inputs > 2 ? new_args.at(2) : ov::op::v0::Constant::create(element::i32, Shape{}, {0});- const auto& arg3 =- num_of_inputs > 3 ? new_args.at(3) : ov::op::v0::Constant::create(element::f32, Shape{}, {.0f});- const auto& arg4 =- num_of_inputs > 4 ? new_args.at(4) : ov::op::v0::Constant::create(element::f32, Shape{}, {.0f});+ const auto& arg2 = num_of_inputs > 2 ? new_args.at(2) : v0::Constant::create(element::i32, Shape{}, {0});+ const auto& arg3 = num_of_inputs > 3 ? new_args.at(3) : v0::Constant::create(element::f32, Shape{}, {.0f});+ const auto& arg4 = num_of_inputs > 4 ? new_args.at(4) : v0::Constant::create(element::f32, Shape{}, {.0f});// vector of new openvino operationsNodeVector new_ops;@@ -48,26 +50,26 @@ ov::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() {Output<Node> new_score_threshold;Output<Node> new_soft_nms_sigma;- Output<Node> new_shape_for_max_per_class = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});- Output<Node> new_shape_for_iou_threshold = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});- Output<Node> new_shape_for_score_threshold = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});- Output<Node> new_shape_for_soft_nms_sigma = ov::op::v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_max_per_class = v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_iou_threshold = v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_score_threshold = v0::Constant::create(ov::element::i64, Shape{1}, {1});+ Output<Node> new_shape_for_soft_nms_sigma = v0::Constant::create(ov::element::i64, Shape{1}, {1});- new_max_per_class = std::make_shared<ov::op::v1::Reshape>(arg2, new_shape_for_max_per_class, true);+ new_max_per_class = std::make_shared<v1::Reshape>(arg2, new_shape_for_max_per_class, true);new_ops.emplace_back(new_max_per_class.get_node_shared_ptr());- new_iou_threshold = std::make_shared<ov::op::v1::Reshape>(arg3, new_shape_for_iou_threshold, true);+ new_iou_threshold = std::make_shared<v1::Reshape>(arg3, new_shape_for_iou_threshold, true);new_ops.emplace_back(new_iou_threshold.get_node_shared_ptr());- new_score_threshold = std::make_shared<ov::op::v1::Reshape>(arg4, new_shape_for_score_threshold, true);+ new_score_threshold = std::make_shared<v1::Reshape>(arg4, new_shape_for_score_threshold, true);new_ops.emplace_back(new_score_threshold.get_node_shared_ptr());int center_point_box = 0;switch (nms_5->get_box_encoding()) {- case ov::op::v5::NonMaxSuppression::BoxEncodingType::CENTER:+ case v5::NonMaxSuppression::BoxEncodingType::CENTER:center_point_box = 1;break;- case ov::op::v5::NonMaxSuppression::BoxEncodingType::CORNER:+ case v5::NonMaxSuppression::BoxEncodingType::CORNER:center_point_box = 0;break;default:@@ -77,8 +79,7 @@ ov::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() {std::shared_ptr<op::internal::NonMaxSuppressionIEInternal> nms_legacy{nullptr};if (num_of_inputs > 5 && !nms_5->is_soft_nms_sigma_constant_and_default()) {- new_soft_nms_sigma =- std::make_shared<ov::op::v1::Reshape>(new_args.at(5), new_shape_for_soft_nms_sigma, true);+ new_soft_nms_sigma = std::make_shared<v1::Reshape>(new_args.at(5), new_shape_for_soft_nms_sigma, true);new_ops.emplace_back(new_soft_nms_sigma.get_node_shared_ptr());nms_legacy =std::make_shared<op::internal::NonMaxSuppressionIEInternal>(new_args.at(0),@@ -108,13 +109,13 @@ ov::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() {Output<Node> output_0 = nms_legacy->output(0);if (nms_5->output(0).get_element_type() != output_0.get_element_type()) {- output_0 = std::make_shared<ov::op::v0::Convert>(output_0, nms_5->output(0).get_element_type());+ output_0 = std::make_shared<v0::Convert>(output_0, nms_5->output(0).get_element_type());new_ops.emplace_back(output_0.get_node_shared_ptr());}Output<Node> output_2 = nms_legacy->output(2);if (nms_5->output(2).get_element_type() != output_2.get_element_type()) {- output_2 = std::make_shared<ov::op::v0::Convert>(output_2, nms_5->output(2).get_element_type());+ output_2 = std::make_shared<v0::Convert>(output_2, nms_5->output(2).get_element_type());new_ops.emplace_back(output_2.get_node_shared_ptr());}@@ -124,6 +125,6 @@ ov::pass::ConvertNMSToNMSIEInternal::ConvertNMSToNMSIEInternal() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(nms, matcher_name);+ auto m = std::make_shared<Matcher>(nms, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_one_hot_v16_to_v1.cpp b/src/common/transformations/src/transformations/op_conversions/convert_one_hot_v16_to_v1.cppindex a68fefa3934..bf85741cc97 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_one_hot_v16_to_v1.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_one_hot_v16_to_v1.cpp@@ -10,12 +10,13 @@#include "openvino/op/one_hot.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;ov::pass::ConvertOneHot16To1::ConvertOneHot16To1() {MATCHER_SCOPE(ConvertOneHot16To1);- auto one_hot_v16 = pattern::wrap_type<ov::op::v16::OneHot>();+ auto one_hot_v16 = ov::pass::pattern::wrap_type<ov::op::v16::OneHot>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {+ matcher_pass_callback callback = [=](Matcher& m) {auto one_hot_v16_node = ov::as_type_ptr<ov::op::v16::OneHot>(m.get_match_root());if (!one_hot_v16_node)return false;@@ -35,6 +36,6 @@ ov::pass::ConvertOneHot16To1::ConvertOneHot16To1() {return true;};- auto m = std::make_shared<pattern::Matcher>(one_hot_v16, matcher_name);+ auto m = std::make_shared<Matcher>(one_hot_v16, matcher_name);register_matcher(m, callback);}\ No newline at end of filediff --git a/src/common/transformations/src/transformations/op_conversions/convert_pad12_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_pad12_downgrade.cppindex 6fa4a5c3340..51c9f621df4 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_pad12_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_pad12_downgrade.cpp@@ -11,33 +11,37 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v1 = ov::op::v1;+namespace v12 = ov::op::v12;ov::pass::ConvertPad12ToPad1::ConvertPad12ToPad1() {MATCHER_SCOPE(ConvertPad12ToPad1);- const auto pad_v12_pattern = pattern::wrap_type<ov::op::v12::Pad>();+ const auto pad_v12_pattern = ov::pass::pattern::wrap_type<v12::Pad>();- const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto pad_v12 = ov::as_type_ptr<ov::op::v12::Pad>(m.get_match_root());+ const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ const auto pad_v12 = ov::as_type_ptr<v12::Pad>(m.get_match_root());if (!pad_v12 || transformation_callback(pad_v12)) {return false;}std::shared_ptr<ov::Node> pad_v1;if (pad_v12->get_input_size() == 4) {- pad_v1 = std::make_shared<ov::op::v1::Pad>(pad_v12->input_value(0),- pad_v12->input_value(1),- pad_v12->input_value(2),- pad_v12->input_value(3),- pad_v12->get_pad_mode());+ pad_v1 = std::make_shared<v1::Pad>(pad_v12->input_value(0),+ pad_v12->input_value(1),+ pad_v12->input_value(2),+ pad_v12->input_value(3),+ pad_v12->get_pad_mode());} else {const auto pad_value =ov::op::v0::Constant::create(pad_v12->input_value(0).get_element_type(), ov::Shape{}, {0});- pad_v1 = std::make_shared<ov::op::v1::Pad>(pad_v12->input_value(0),- pad_v12->input_value(1),- pad_v12->input_value(2),- pad_value,- pad_v12->get_pad_mode());+ pad_v1 = std::make_shared<v1::Pad>(pad_v12->input_value(0),+ pad_v12->input_value(1),+ pad_v12->input_value(2),+ pad_value,+ pad_v12->get_pad_mode());}pad_v1->set_friendly_name(pad_v12->get_friendly_name());copy_runtime_info(pad_v12, pad_v1);@@ -46,6 +50,6 @@ ov::pass::ConvertPad12ToPad1::ConvertPad12ToPad1() {return true;};- auto m = std::make_shared<pattern::Matcher>(pad_v12_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(pad_v12_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_pad_to_group_conv.cpp b/src/common/transformations/src/transformations/op_conversions/convert_pad_to_group_conv.cppindex cdb23fe977d..e76b37b6ac0 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_pad_to_group_conv.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_pad_to_group_conv.cpp@@ -16,11 +16,14 @@#include "openvino/pass/pattern/op/pattern.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;ov::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() {MATCHER_SCOPE(ConvertPadToGroupConvolution);- auto neg = ov::pass::pattern::wrap_type<op::util::PadBase>(pattern::has_static_dim(1));+ auto neg = ov::pass::pattern::wrap_type<op::util::PadBase>(ov::pass::pattern::has_static_dim(1));- matcher_pass_callback callback = [](pattern::Matcher& m) {+ matcher_pass_callback callback = [](Matcher& m) {auto pad = ov::as_type_ptr<ov::op::util::PadBase>(m.get_match_root());if (!pad) {return false;@@ -42,7 +45,7 @@ ov::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() {}if (pad->inputs().size() == 4) {- if (auto pad_value = ov::as_type_ptr<ov::op::v0::Constant>(pad->input_value(3).get_node_shared_ptr())) {+ if (auto pad_value = ov::as_type_ptr<v0::Constant>(pad->input_value(3).get_node_shared_ptr())) {// pad value is a scalarif (pad_value->cast_vector<float>()[0] != 0) {return false;@@ -83,7 +86,7 @@ ov::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() {// Create fake weights with ones GOIXYShape weights_shape(rank + 1, 1);weights_shape[0] = channel_dim; // G dimension- auto weights = ov::op::v0::Constant::create(pad->input(0).get_element_type(), weights_shape, {1});+ auto weights = v0::Constant::create(pad->input(0).get_element_type(), weights_shape, {1});// Create GroupConvolution attributesStrides stride(rank - 2, 1);@@ -99,6 +102,6 @@ ov::pass::ConvertPadToGroupConvolution::ConvertPadToGroupConvolution() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(neg, matcher_name);+ auto m = std::make_shared<Matcher>(neg, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp b/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cppindex ddb0f24d524..c91e6061bee 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_5.cpp@@ -16,28 +16,36 @@using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v5 = ov::op::v5;++namespace ov::pass {+namespace {struct NMSAttributes {ov::element::Type output_type;- ov::op::v5::NonMaxSuppression::BoxEncodingType box_encoding;+ v5::NonMaxSuppression::BoxEncodingType box_encoding;bool sort_result_descending;bool is_supported_nms;};-NMSAttributes get_nms4_attrs(const std::shared_ptr<ov::op::v4::NonMaxSuppression>& nms4) {+NMSAttributes get_nms4_attrs(const std::shared_ptr<v4::NonMaxSuppression>& nms4) {NMSAttributes attrs;- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CORNER;+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CORNER;attrs.is_supported_nms = true;attrs.sort_result_descending = true;attrs.output_type = ::ov::element::i64;switch (nms4->get_box_encoding()) {- case ov::op::v4::NonMaxSuppression::BoxEncodingType::CENTER:- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CENTER;+ case v4::NonMaxSuppression::BoxEncodingType::CENTER:+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CENTER;break;- case ov::op::v4::NonMaxSuppression::BoxEncodingType::CORNER:- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CORNER;+ case v4::NonMaxSuppression::BoxEncodingType::CORNER:+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CORNER;break;default:OPENVINO_THROW("NonMaxSuppression layer " + nms4->get_friendly_name() + " has unsupported box encoding");@@ -49,20 +57,20 @@ NMSAttributes get_nms4_attrs(const std::shared_ptr<ov::op::v4::NonMaxSuppressionreturn attrs;}-NMSAttributes get_nms3_attrs(const std::shared_ptr<ov::op::v3::NonMaxSuppression>& nms3) {+NMSAttributes get_nms3_attrs(const std::shared_ptr<v3::NonMaxSuppression>& nms3) {NMSAttributes attrs;- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CORNER;+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CORNER;attrs.is_supported_nms = true;attrs.sort_result_descending = true;attrs.output_type = ::ov::element::i64;switch (nms3->get_box_encoding()) {- case ov::op::v3::NonMaxSuppression::BoxEncodingType::CENTER:- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CENTER;+ case v3::NonMaxSuppression::BoxEncodingType::CENTER:+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CENTER;break;- case ov::op::v3::NonMaxSuppression::BoxEncodingType::CORNER:- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CORNER;+ case v3::NonMaxSuppression::BoxEncodingType::CORNER:+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CORNER;break;default:OPENVINO_THROW("NonMaxSuppression layer " + nms3->get_friendly_name() + " has unsupported box encoding");@@ -74,20 +82,20 @@ NMSAttributes get_nms3_attrs(const std::shared_ptr<ov::op::v3::NonMaxSuppressionreturn attrs;}-NMSAttributes get_nms1_attrs(const std::shared_ptr<ov::op::v1::NonMaxSuppression>& nms1) {+NMSAttributes get_nms1_attrs(const std::shared_ptr<v1::NonMaxSuppression>& nms1) {NMSAttributes attrs;- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CORNER;+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CORNER;attrs.is_supported_nms = true;attrs.sort_result_descending = true;attrs.output_type = ::ov::element::i64;switch (nms1->get_box_encoding()) {- case ov::op::v1::NonMaxSuppression::BoxEncodingType::CENTER:- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CENTER;+ case v1::NonMaxSuppression::BoxEncodingType::CENTER:+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CENTER;break;- case ov::op::v1::NonMaxSuppression::BoxEncodingType::CORNER:- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CORNER;+ case v1::NonMaxSuppression::BoxEncodingType::CORNER:+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CORNER;break;default:OPENVINO_THROW("NonMaxSuppression layer " + nms1->get_friendly_name() + " has unsupported box encoding");@@ -101,19 +109,19 @@ NMSAttributes get_nms1_attrs(const std::shared_ptr<ov::op::v1::NonMaxSuppressionNMSAttributes get_nms_attrs(const std::shared_ptr<ov::Node>& root) {NMSAttributes attrs;attrs.output_type = ::ov::element::i64;- attrs.box_encoding = ov::op::v5::NonMaxSuppression::BoxEncodingType::CORNER;+ attrs.box_encoding = v5::NonMaxSuppression::BoxEncodingType::CORNER;attrs.sort_result_descending = false;attrs.is_supported_nms = false;- auto nms_4 = ov::as_type_ptr<ov::op::v4::NonMaxSuppression>(root);+ auto nms_4 = ov::as_type_ptr<v4::NonMaxSuppression>(root);if (nms_4) {return get_nms4_attrs(nms_4);}- auto nms_3 = ov::as_type_ptr<ov::op::v3::NonMaxSuppression>(root);+ auto nms_3 = ov::as_type_ptr<v3::NonMaxSuppression>(root);if (nms_3) {return get_nms3_attrs(nms_3);}- auto nms_1 = ov::as_type_ptr<ov::op::v1::NonMaxSuppression>(root);+ auto nms_1 = ov::as_type_ptr<v1::NonMaxSuppression>(root);if (nms_1) {return get_nms1_attrs(nms_1);}@@ -121,7 +129,7 @@ NMSAttributes get_nms_attrs(const std::shared_ptr<ov::Node>& root) {return attrs;}-bool callback_func(pass::pattern::Matcher& m, pass::MatcherPass* impl) {+bool callback_func(pattern::Matcher& m, MatcherPass* impl) {auto root = m.get_match_root();auto attrs = get_nms_attrs(root);@@ -133,18 +141,18 @@ bool callback_func(pass::pattern::Matcher& m, pass::MatcherPass* impl) {size_t num_of_args = new_args.size();- const auto& arg2 = num_of_args > 2 ? new_args.at(2) : ov::op::v0::Constant::create(element::i64, Shape{}, {0});- const auto& arg3 = num_of_args > 3 ? new_args.at(3) : ov::op::v0::Constant::create(element::f32, Shape{}, {.0f});- const auto& arg4 = num_of_args > 4 ? new_args.at(4) : ov::op::v0::Constant::create(element::f32, Shape{}, {.0f});+ const auto& arg2 = num_of_args > 2 ? new_args.at(2) : v0::Constant::create(element::i64, Shape{}, {0});+ const auto& arg3 = num_of_args > 3 ? new_args.at(3) : v0::Constant::create(element::f32, Shape{}, {.0f});+ const auto& arg4 = num_of_args > 4 ? new_args.at(4) : v0::Constant::create(element::f32, Shape{}, {.0f});- const auto nms_5 = impl->register_new_node<ov::op::v5::NonMaxSuppression>(new_args.at(0),- new_args.at(1),- arg2,- arg3,- arg4,- attrs.box_encoding,- attrs.sort_result_descending,- attrs.output_type);+ const auto nms_5 = impl->register_new_node<v5::NonMaxSuppression>(new_args.at(0),+ new_args.at(1),+ arg2,+ arg3,+ arg4,+ attrs.box_encoding,+ attrs.sort_result_descending,+ attrs.output_type);nms_5->set_friendly_name(root->get_friendly_name());ov::copy_runtime_info(root, nms_5);@@ -153,9 +161,9 @@ bool callback_func(pass::pattern::Matcher& m, pass::MatcherPass* impl) {}} // namespace-ov::pass::ConvertNMS4ToNMS5::ConvertNMS4ToNMS5() {+ConvertNMS4ToNMS5::ConvertNMS4ToNMS5() {MATCHER_SCOPE(ConvertNMS4ToNMS5);- auto nms = pattern::wrap_type<ov::op::v4::NonMaxSuppression>();+ auto nms = pattern::wrap_type<v4::NonMaxSuppression>();matcher_pass_callback callback = [this](pattern::Matcher& m) {return callback_func(m, this);};@@ -164,9 +172,9 @@ ov::pass::ConvertNMS4ToNMS5::ConvertNMS4ToNMS5() {this->register_matcher(m, callback);}-ov::pass::ConvertNMS3ToNMS5::ConvertNMS3ToNMS5() {+ConvertNMS3ToNMS5::ConvertNMS3ToNMS5() {MATCHER_SCOPE(ConvertNMS3ToNMS5);- auto nms = pattern::wrap_type<ov::op::v3::NonMaxSuppression>();+ auto nms = pattern::wrap_type<v3::NonMaxSuppression>();matcher_pass_callback callback = [this](pattern::Matcher& m) {return callback_func(m, this);};@@ -175,9 +183,9 @@ ov::pass::ConvertNMS3ToNMS5::ConvertNMS3ToNMS5() {this->register_matcher(m, callback);}-ov::pass::ConvertNMS1ToNMS5::ConvertNMS1ToNMS5() {+ConvertNMS1ToNMS5::ConvertNMS1ToNMS5() {MATCHER_SCOPE(ConvertNMS1ToNMS5);- auto nms = pattern::wrap_type<ov::op::v1::NonMaxSuppression>();+ auto nms = pattern::wrap_type<v1::NonMaxSuppression>();matcher_pass_callback callback = [this](pattern::Matcher& m) {return callback_func(m, this);};@@ -185,3 +193,5 @@ ov::pass::ConvertNMS1ToNMS5::ConvertNMS1ToNMS5() {auto m = std::make_shared<pattern::Matcher>(nms, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_9.cpp b/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_9.cppindex 42687516ac6..346c447ef16 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_9.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_previous_nms_to_nms_9.cpp@@ -17,28 +17,37 @@using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v5 = ov::op::v5;+namespace v9 = ov::op::v9;++namespace ov::pass {+namespace {struct NMS9Attributes {ov::element::Type output_type;- ov::op::v9::NonMaxSuppression::BoxEncodingType box_encoding;+ v9::NonMaxSuppression::BoxEncodingType box_encoding;bool sort_result_descending;bool is_supported_nms;};-NMS9Attributes get_nms9_attrs_from_nms5(const std::shared_ptr<ov::op::v5::NonMaxSuppression>& nms5) {+NMS9Attributes get_nms9_attrs_from_nms5(const std::shared_ptr<v5::NonMaxSuppression>& nms5) {NMS9Attributes attrs;- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER;+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CORNER;attrs.is_supported_nms = true;attrs.sort_result_descending = true;attrs.output_type = ::ov::element::i64;switch (nms5->get_box_encoding()) {- case ov::op::v5::NonMaxSuppression::BoxEncodingType::CENTER:- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CENTER;+ case v5::NonMaxSuppression::BoxEncodingType::CENTER:+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CENTER;break;- case ov::op::v5::NonMaxSuppression::BoxEncodingType::CORNER:- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER;+ case v5::NonMaxSuppression::BoxEncodingType::CORNER:+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CORNER;break;default:OPENVINO_THROW("NonMaxSuppression layer " + nms5->get_friendly_name() + " has unsupported box encoding");@@ -50,20 +59,20 @@ NMS9Attributes get_nms9_attrs_from_nms5(const std::shared_ptr<ov::op::v5::NonMaxreturn attrs;}-NMS9Attributes get_nms9_attrs_from_nms4(const std::shared_ptr<ov::op::v4::NonMaxSuppression>& nms4) {+NMS9Attributes get_nms9_attrs_from_nms4(const std::shared_ptr<v4::NonMaxSuppression>& nms4) {NMS9Attributes attrs;- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER;+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CORNER;attrs.is_supported_nms = true;attrs.sort_result_descending = true;attrs.output_type = ::ov::element::i64;switch (nms4->get_box_encoding()) {- case ov::op::v4::NonMaxSuppression::BoxEncodingType::CENTER:- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CENTER;+ case v4::NonMaxSuppression::BoxEncodingType::CENTER:+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CENTER;break;- case ov::op::v4::NonMaxSuppression::BoxEncodingType::CORNER:- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER;+ case v4::NonMaxSuppression::BoxEncodingType::CORNER:+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CORNER;break;default:OPENVINO_THROW("NonMaxSuppression layer " + nms4->get_friendly_name() + " has unsupported box encoding");@@ -75,20 +84,20 @@ NMS9Attributes get_nms9_attrs_from_nms4(const std::shared_ptr<ov::op::v4::NonMaxreturn attrs;}-NMS9Attributes get_nms9_attrs_from_nms3(const std::shared_ptr<ov::op::v3::NonMaxSuppression>& nms3) {+NMS9Attributes get_nms9_attrs_from_nms3(const std::shared_ptr<v3::NonMaxSuppression>& nms3) {NMS9Attributes attrs;- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER;+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CORNER;attrs.is_supported_nms = true;attrs.sort_result_descending = true;attrs.output_type = ::ov::element::i64;switch (nms3->get_box_encoding()) {- case ov::op::v3::NonMaxSuppression::BoxEncodingType::CENTER:- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CENTER;+ case v3::NonMaxSuppression::BoxEncodingType::CENTER:+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CENTER;break;- case ov::op::v3::NonMaxSuppression::BoxEncodingType::CORNER:- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER;+ case v3::NonMaxSuppression::BoxEncodingType::CORNER:+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CORNER;break;default:OPENVINO_THROW("NonMaxSuppression layer " + nms3->get_friendly_name() + " has unsupported box encoding");@@ -100,20 +109,20 @@ NMS9Attributes get_nms9_attrs_from_nms3(const std::shared_ptr<ov::op::v3::NonMaxreturn attrs;}-NMS9Attributes get_nms9_attrs_from_nms1(const std::shared_ptr<ov::op::v1::NonMaxSuppression>& nms1) {+NMS9Attributes get_nms9_attrs_from_nms1(const std::shared_ptr<v1::NonMaxSuppression>& nms1) {NMS9Attributes attrs;- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER;+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CORNER;attrs.is_supported_nms = true;attrs.sort_result_descending = true;attrs.output_type = ::ov::element::i64;switch (nms1->get_box_encoding()) {- case ov::op::v1::NonMaxSuppression::BoxEncodingType::CENTER:- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CENTER;+ case v1::NonMaxSuppression::BoxEncodingType::CENTER:+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CENTER;break;- case ov::op::v1::NonMaxSuppression::BoxEncodingType::CORNER:- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER;+ case v1::NonMaxSuppression::BoxEncodingType::CORNER:+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CORNER;break;default:OPENVINO_THROW("NonMaxSuppression layer " + nms1->get_friendly_name() + " has unsupported box encoding");@@ -127,23 +136,23 @@ NMS9Attributes get_nms9_attrs_from_nms1(const std::shared_ptr<ov::op::v1::NonMaxNMS9Attributes get_nms9_attrs(const std::shared_ptr<ov::Node>& root) {NMS9Attributes attrs;attrs.output_type = ::ov::element::i64;- attrs.box_encoding = ov::op::v9::NonMaxSuppression::BoxEncodingType::CORNER;+ attrs.box_encoding = v9::NonMaxSuppression::BoxEncodingType::CORNER;attrs.sort_result_descending = false;attrs.is_supported_nms = false;- auto nms_5 = ov::as_type_ptr<ov::op::v5::NonMaxSuppression>(root);+ auto nms_5 = ov::as_type_ptr<v5::NonMaxSuppression>(root);if (nms_5) {return get_nms9_attrs_from_nms5(nms_5);}- auto nms_4 = ov::as_type_ptr<ov::op::v4::NonMaxSuppression>(root);+ auto nms_4 = ov::as_type_ptr<v4::NonMaxSuppression>(root);if (nms_4) {return get_nms9_attrs_from_nms4(nms_4);}- auto nms_3 = ov::as_type_ptr<ov::op::v3::NonMaxSuppression>(root);+ auto nms_3 = ov::as_type_ptr<v3::NonMaxSuppression>(root);if (nms_3) {return get_nms9_attrs_from_nms3(nms_3);}- auto nms_1 = ov::as_type_ptr<ov::op::v1::NonMaxSuppression>(root);+ auto nms_1 = ov::as_type_ptr<v1::NonMaxSuppression>(root);if (nms_1) {return get_nms9_attrs_from_nms1(nms_1);}@@ -151,7 +160,7 @@ NMS9Attributes get_nms9_attrs(const std::shared_ptr<ov::Node>& root) {return attrs;}-bool nms_to_nms9_callback_func(pass::pattern::Matcher& m, pass::MatcherPass* impl) {+bool nms_to_nms9_callback_func(pattern::Matcher& m, MatcherPass* impl) {auto root = m.get_match_root();auto attrs = get_nms9_attrs(root);@@ -163,29 +172,26 @@ bool nms_to_nms9_callback_func(pass::pattern::Matcher& m, pass::MatcherPass* impsize_t num_of_args = nms_input.size();- const auto& max_selected_box =- num_of_args > 2 ? nms_input.at(2) : ov::op::v0::Constant::create(element::i64, Shape{}, {0});- const auto& iou_threshold =- num_of_args > 3 ? nms_input.at(3) : ov::op::v0::Constant::create(element::f32, Shape{}, {.0f});+ const auto& max_selected_box = num_of_args > 2 ? nms_input.at(2) : v0::Constant::create(element::i64, Shape{}, {0});+ const auto& iou_threshold = num_of_args > 3 ? nms_input.at(3) : v0::Constant::create(element::f32, Shape{}, {.0f});const auto& score_threshold =- num_of_args > 4 ? nms_input.at(4) : ov::op::v0::Constant::create(element::f32, Shape{}, {.0f});- const auto& soft_sigma =- num_of_args > 5 ? nms_input.at(5) : ov::op::v0::Constant::create(element::f32, Shape{}, {.0f});-- const auto nms_9 = impl->register_new_node<ov::op::v9::NonMaxSuppression>(nms_input.at(0),- nms_input.at(1),- max_selected_box,- iou_threshold,- score_threshold,- soft_sigma,- attrs.box_encoding,- attrs.sort_result_descending,- attrs.output_type);+ num_of_args > 4 ? nms_input.at(4) : v0::Constant::create(element::f32, Shape{}, {.0f});+ const auto& soft_sigma = num_of_args > 5 ? nms_input.at(5) : v0::Constant::create(element::f32, Shape{}, {.0f});++ const auto nms_9 = impl->register_new_node<v9::NonMaxSuppression>(nms_input.at(0),+ nms_input.at(1),+ max_selected_box,+ iou_threshold,+ score_threshold,+ soft_sigma,+ attrs.box_encoding,+ attrs.sort_result_descending,+ attrs.output_type);nms_9->set_friendly_name(root->get_friendly_name());ov::copy_runtime_info(root, nms_9);// nms0-4 have one output, nms5/9 have 3 outputs.- if (ov::as_type_ptr<ov::op::v5::NonMaxSuppression>(root))+ if (ov::as_type_ptr<v5::NonMaxSuppression>(root))ov::replace_node(root, nms_9);elseroot->output(0).replace(nms_9->output(0));@@ -193,9 +199,9 @@ bool nms_to_nms9_callback_func(pass::pattern::Matcher& m, pass::MatcherPass* imp}} // namespace-ov::pass::ConvertNMS5ToNMS9::ConvertNMS5ToNMS9() {+ConvertNMS5ToNMS9::ConvertNMS5ToNMS9() {MATCHER_SCOPE(ConvertNMS5ToNMS9);- auto nms = pass::pattern::wrap_type<ov::op::v5::NonMaxSuppression>();+ auto nms = pattern::wrap_type<v5::NonMaxSuppression>();matcher_pass_callback callback = [this](pattern::Matcher& m) {return nms_to_nms9_callback_func(m, this);};@@ -204,9 +210,9 @@ ov::pass::ConvertNMS5ToNMS9::ConvertNMS5ToNMS9() {this->register_matcher(m, callback);}-ov::pass::ConvertNMS4ToNMS9::ConvertNMS4ToNMS9() {+ConvertNMS4ToNMS9::ConvertNMS4ToNMS9() {MATCHER_SCOPE(ConvertNMS4ToNMS9);- auto nms = pass::pattern::wrap_type<ov::op::v4::NonMaxSuppression>();+ auto nms = pattern::wrap_type<v4::NonMaxSuppression>();matcher_pass_callback callback = [this](pattern::Matcher& m) {return nms_to_nms9_callback_func(m, this);};@@ -215,9 +221,9 @@ ov::pass::ConvertNMS4ToNMS9::ConvertNMS4ToNMS9() {this->register_matcher(m, callback);}-ov::pass::ConvertNMS3ToNMS9::ConvertNMS3ToNMS9() {+ConvertNMS3ToNMS9::ConvertNMS3ToNMS9() {MATCHER_SCOPE(ConvertNMS3ToNMS9);- auto nms = pass::pattern::wrap_type<ov::op::v3::NonMaxSuppression>();+ auto nms = pattern::wrap_type<v3::NonMaxSuppression>();matcher_pass_callback callback = [this](pattern::Matcher& m) {return nms_to_nms9_callback_func(m, this);};@@ -226,9 +232,9 @@ ov::pass::ConvertNMS3ToNMS9::ConvertNMS3ToNMS9() {this->register_matcher(m, callback);}-ov::pass::ConvertNMS1ToNMS9::ConvertNMS1ToNMS9() {+ConvertNMS1ToNMS9::ConvertNMS1ToNMS9() {MATCHER_SCOPE(ConvertNMS1ToNMS9);- auto nms = pass::pattern::wrap_type<ov::op::v1::NonMaxSuppression>();+ auto nms = pattern::wrap_type<v1::NonMaxSuppression>();matcher_pass_callback callback = [this](pattern::Matcher& m) {return nms_to_nms9_callback_func(m, this);};@@ -236,3 +242,5 @@ ov::pass::ConvertNMS1ToNMS9::ConvertNMS1ToNMS9() {auto m = std::make_shared<pattern::Matcher>(nms, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_prior_box_v8_to_v0.cpp b/src/common/transformations/src/transformations/op_conversions/convert_prior_box_v8_to_v0.cppindex 85a24027200..c33ed8f50d0 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_prior_box_v8_to_v0.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_prior_box_v8_to_v0.cpp@@ -10,21 +10,25 @@#include "openvino/op/prior_box.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v8 = ov::op::v8;ov::pass::ConvertPriorBox8To0::ConvertPriorBox8To0() {MATCHER_SCOPE(ConvertPriorBox8To0);- auto prior_box_v8 = pattern::wrap_type<ov::op::v8::PriorBox>();+ auto prior_box_v8 = ov::pass::pattern::wrap_type<v8::PriorBox>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto prior_box_v8_node = ov::as_type_ptr<ov::op::v8::PriorBox>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto prior_box_v8_node = ov::as_type_ptr<v8::PriorBox>(m.get_match_root());if (!prior_box_v8_node)return false;- ov::op::v8::PriorBox::Attributes attrs_v8 = prior_box_v8_node->get_attrs();+ v8::PriorBox::Attributes attrs_v8 = prior_box_v8_node->get_attrs();if (!attrs_v8.min_max_aspect_ratios_order)return false;- ov::op::v0::PriorBox::Attributes attrs_v0;+ v0::PriorBox::Attributes attrs_v0;attrs_v0.min_size = attrs_v8.min_size;attrs_v0.max_size = attrs_v8.max_size;attrs_v0.aspect_ratio = attrs_v8.aspect_ratio;@@ -38,9 +42,9 @@ ov::pass::ConvertPriorBox8To0::ConvertPriorBox8To0() {attrs_v0.variance = attrs_v8.variance;attrs_v0.scale_all_sizes = attrs_v8.scale_all_sizes;- auto prior_box_v0 = std::make_shared<ov::op::v0::PriorBox>(prior_box_v8_node->input_value(0),- prior_box_v8_node->input_value(1),- attrs_v0);+ auto prior_box_v0 = std::make_shared<v0::PriorBox>(prior_box_v8_node->input_value(0),+ prior_box_v8_node->input_value(1),+ attrs_v0);prior_box_v0->set_friendly_name(prior_box_v8_node->get_friendly_name());ov::copy_runtime_info(prior_box_v8_node, prior_box_v0);ov::replace_node(prior_box_v8_node, prior_box_v0);@@ -48,6 +52,6 @@ ov::pass::ConvertPriorBox8To0::ConvertPriorBox8To0() {return true;};- auto m = std::make_shared<pattern::Matcher>(prior_box_v8, matcher_name);+ auto m = std::make_shared<Matcher>(prior_box_v8, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_pooling.cpp b/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_pooling.cppindex 6a4ba44a5b5..88f9a4b753e 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_pooling.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_pooling.cpp@@ -7,30 +7,39 @@#include "itt.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::ConvertReduceMeanToPooling::ConvertReduceMeanToPooling() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++ConvertReduceMeanToPooling::ConvertReduceMeanToPooling() {MATCHER_SCOPE(ConvertReduceMeanToPooling);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceMean>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceMean>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_pooling<ov::op::v1::ReduceMean>());+ register_matcher(m, convert_reduce_to_pooling<v1::ReduceMean>());}-ov::pass::ConvertReduceMaxToPooling::ConvertReduceMaxToPooling() {++ConvertReduceMaxToPooling::ConvertReduceMaxToPooling() {MATCHER_SCOPE(ConvertReduceMaxToPooling);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceMax>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceMax>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_pooling<ov::op::v1::ReduceMax>());+ register_matcher(m, convert_reduce_to_pooling<v1::ReduceMax>());}-ov::pass::ConvertReduceSumToPooling::ConvertReduceSumToPooling() {++ConvertReduceSumToPooling::ConvertReduceSumToPooling() {MATCHER_SCOPE(ConvertReduceSumToPooling);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceSum>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceSum>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_pooling<ov::op::v1::ReduceSum>());+ register_matcher(m, convert_reduce_to_pooling<v1::ReduceSum>());}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_reshape.cpp b/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_reshape.cppindex 80b732c6c76..7b10665cbfe 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_reshape.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_reduce_to_reshape.cpp@@ -14,79 +14,86 @@#include "openvino/op/reduce_sum.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+bool CvtReduceBase::is_redundant(ov::Shape input, ov::Shape output) {- if (shape_size(input) != shape_size(output))+ if (ov::shape_size(input) != ov::shape_size(output))return false;return true;}-ov::pass::ConvertReduceMeanToReshape::ConvertReduceMeanToReshape() {+namespace ov::pass {++ConvertReduceMeanToReshape::ConvertReduceMeanToReshape() {MATCHER_SCOPE(ConvertReduceMeanToReshape);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceMean>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceMean>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_reshape<ov::op::v1::ReduceMean>());+ register_matcher(m, convert_reduce_to_reshape<v1::ReduceMean>());}-ov::pass::ConvertReduceSumToReshape::ConvertReduceSumToReshape() {+ConvertReduceSumToReshape::ConvertReduceSumToReshape() {MATCHER_SCOPE(ConvertReduceSumToReshape);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceSum>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceSum>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_reshape<ov::op::v1::ReduceSum>());+ register_matcher(m, convert_reduce_to_reshape<v1::ReduceSum>());}-ov::pass::ConvertReduceProdToReshape::ConvertReduceProdToReshape() {+ConvertReduceProdToReshape::ConvertReduceProdToReshape() {MATCHER_SCOPE(ConvertReduceProdToReshape);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceProd>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceProd>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_reshape<ov::op::v1::ReduceProd>());+ register_matcher(m, convert_reduce_to_reshape<v1::ReduceProd>());}-ov::pass::ConvertReduceMaxToReshape::ConvertReduceMaxToReshape() {+ConvertReduceMaxToReshape::ConvertReduceMaxToReshape() {MATCHER_SCOPE(ConvertReduceMaxToReshape);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceMax>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceMax>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_reshape<ov::op::v1::ReduceMax>());+ register_matcher(m, convert_reduce_to_reshape<v1::ReduceMax>());}-ov::pass::ConvertReduceMinToReshape::ConvertReduceMinToReshape() {+ConvertReduceMinToReshape::ConvertReduceMinToReshape() {MATCHER_SCOPE(ConvertReduceMinToReshape);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceMin>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceMin>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_reshape<ov::op::v1::ReduceMin>());+ register_matcher(m, convert_reduce_to_reshape<v1::ReduceMin>());}-ov::pass::ConvertReduceLogicalAndToReshape::ConvertReduceLogicalAndToReshape() {+ConvertReduceLogicalAndToReshape::ConvertReduceLogicalAndToReshape() {MATCHER_SCOPE(ConvertReduceLogicalAndToReshape);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceLogicalAnd>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceLogicalAnd>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_reshape<ov::op::v1::ReduceLogicalAnd>());+ register_matcher(m, convert_reduce_to_reshape<v1::ReduceLogicalAnd>());}-ov::pass::ConvertReduceLogicalOrToReshape::ConvertReduceLogicalOrToReshape() {+ConvertReduceLogicalOrToReshape::ConvertReduceLogicalOrToReshape() {MATCHER_SCOPE(ConvertReduceLogicalOrToReshape);auto m = std::make_shared<pattern::Matcher>(- pattern::wrap_type<ov::op::v1::ReduceLogicalOr>(- {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<ov::op::v0::Constant>()},+ pattern::wrap_type<v1::ReduceLogicalOr>(+ {pattern::any_input(pattern::has_static_shape()), pattern::wrap_type<v0::Constant>()},pattern::has_static_shape()),matcher_name);- register_matcher(m, convert_reduce_to_reshape<ov::op::v1::ReduceLogicalOr>());+ register_matcher(m, convert_reduce_to_reshape<v1::ReduceLogicalOr>());}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_roi_align_v3_to_v9.cpp b/src/common/transformations/src/transformations/op_conversions/convert_roi_align_v3_to_v9.cppindex 80ddb5661f8..4a1ffea719e 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_roi_align_v3_to_v9.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_roi_align_v3_to_v9.cpp@@ -10,13 +10,17 @@#include "openvino/op/roi_align.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v3 = ov::op::v3;+namespace v9 = ov::op::v9;ov::pass::ConvertROIAlign3To9::ConvertROIAlign3To9() {MATCHER_SCOPE(ConvertROIAlign3To9);- auto roi_align_v3 = pattern::wrap_type<ov::op::v3::ROIAlign>();+ auto roi_align_v3 = ov::pass::pattern::wrap_type<v3::ROIAlign>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto roi_align_v3_node = ov::as_type_ptr<ov::op::v3::ROIAlign>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto roi_align_v3_node = ov::as_type_ptr<v3::ROIAlign>(m.get_match_root());if (!roi_align_v3_node)return false;@@ -24,15 +28,15 @@ ov::pass::ConvertROIAlign3To9::ConvertROIAlign3To9() {const int pooled_w = roi_align_v3_node->get_pooled_w();const int sampling_ratio = roi_align_v3_node->get_sampling_ratio();const float spatial_scale = roi_align_v3_node->get_spatial_scale();- ov::op::v3::ROIAlign::PoolingMode m_mode_v3 = roi_align_v3_node->get_mode();- ov::op::v9::ROIAlign::PoolingMode m_mode_v9;+ v3::ROIAlign::PoolingMode m_mode_v3 = roi_align_v3_node->get_mode();+ v9::ROIAlign::PoolingMode m_mode_v9;switch (m_mode_v3) {- case ov::op::v3::ROIAlign::PoolingMode::AVG: {- m_mode_v9 = ov::op::v9::ROIAlign::PoolingMode::AVG;+ case v3::ROIAlign::PoolingMode::AVG: {+ m_mode_v9 = v9::ROIAlign::PoolingMode::AVG;break;}- case ov::op::v3::ROIAlign::PoolingMode::MAX: {- m_mode_v9 = ov::op::v9::ROIAlign::PoolingMode::MAX;+ case v3::ROIAlign::PoolingMode::MAX: {+ m_mode_v9 = v9::ROIAlign::PoolingMode::MAX;break;}default: {@@ -40,14 +44,14 @@ ov::pass::ConvertROIAlign3To9::ConvertROIAlign3To9() {}}- auto roi_align_v9 = std::make_shared<ov::op::v9::ROIAlign>(roi_align_v3_node->input_value(0),- roi_align_v3_node->input_value(1),- roi_align_v3_node->input_value(2),- pooled_h,- pooled_w,- sampling_ratio,- spatial_scale,- m_mode_v9);+ auto roi_align_v9 = std::make_shared<v9::ROIAlign>(roi_align_v3_node->input_value(0),+ roi_align_v3_node->input_value(1),+ roi_align_v3_node->input_value(2),+ pooled_h,+ pooled_w,+ sampling_ratio,+ spatial_scale,+ m_mode_v9);roi_align_v9->set_friendly_name(roi_align_v3_node->get_friendly_name());ov::copy_runtime_info(roi_align_v3_node, roi_align_v9);ov::replace_node(roi_align_v3_node, roi_align_v9);@@ -55,6 +59,6 @@ ov::pass::ConvertROIAlign3To9::ConvertROIAlign3To9() {return true;};- auto m = std::make_shared<pattern::Matcher>(roi_align_v3, matcher_name);+ auto m = std::make_shared<Matcher>(roi_align_v3, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_roi_align_v9_to_v3.cpp b/src/common/transformations/src/transformations/op_conversions/convert_roi_align_v9_to_v3.cppindex 4132e8f9ff8..21cfb9d0b2a 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_roi_align_v9_to_v3.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_roi_align_v9_to_v3.cpp@@ -10,33 +10,37 @@#include "openvino/op/roi_align.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v3 = ov::op::v3;+namespace v9 = ov::op::v9;ov::pass::ConvertROIAlign9To3::ConvertROIAlign9To3() {MATCHER_SCOPE(ConvertROIAlign9To3);- auto roi_align_v9 = pattern::wrap_type<ov::op::v9::ROIAlign>();+ auto roi_align_v9 = ov::pass::pattern::wrap_type<v9::ROIAlign>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto roi_align_v9_node = ov::as_type_ptr<ov::op::v9::ROIAlign>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto roi_align_v9_node = ov::as_type_ptr<v9::ROIAlign>(m.get_match_root());if (!roi_align_v9_node)return false;- ov::op::v9::ROIAlign::AlignedMode aligned_mode_v9 = roi_align_v9_node->get_aligned_mode();- if (aligned_mode_v9 != ov::op::v9::ROIAlign::AlignedMode::ASYMMETRIC)+ v9::ROIAlign::AlignedMode aligned_mode_v9 = roi_align_v9_node->get_aligned_mode();+ if (aligned_mode_v9 != v9::ROIAlign::AlignedMode::ASYMMETRIC)return false;const int pooled_h = roi_align_v9_node->get_pooled_h();const int pooled_w = roi_align_v9_node->get_pooled_w();const int sampling_ratio = roi_align_v9_node->get_sampling_ratio();const float spatial_scale = roi_align_v9_node->get_spatial_scale();- ov::op::v9::ROIAlign::PoolingMode m_mode_v9 = roi_align_v9_node->get_mode();- ov::op::v3::ROIAlign::PoolingMode m_mode_v3;+ v9::ROIAlign::PoolingMode m_mode_v9 = roi_align_v9_node->get_mode();+ v3::ROIAlign::PoolingMode m_mode_v3;switch (m_mode_v9) {- case ov::op::v9::ROIAlign::PoolingMode::AVG: {- m_mode_v3 = ov::op::v3::ROIAlign::PoolingMode::AVG;+ case v9::ROIAlign::PoolingMode::AVG: {+ m_mode_v3 = v3::ROIAlign::PoolingMode::AVG;break;}- case ov::op::v9::ROIAlign::PoolingMode::MAX: {- m_mode_v3 = ov::op::v3::ROIAlign::PoolingMode::MAX;+ case v9::ROIAlign::PoolingMode::MAX: {+ m_mode_v3 = v3::ROIAlign::PoolingMode::MAX;break;}default: {@@ -44,14 +48,14 @@ ov::pass::ConvertROIAlign9To3::ConvertROIAlign9To3() {}}- auto roi_align_v3 = std::make_shared<ov::op::v3::ROIAlign>(roi_align_v9_node->input_value(0),- roi_align_v9_node->input_value(1),- roi_align_v9_node->input_value(2),- pooled_h,- pooled_w,- sampling_ratio,- spatial_scale,- m_mode_v3);+ auto roi_align_v3 = std::make_shared<v3::ROIAlign>(roi_align_v9_node->input_value(0),+ roi_align_v9_node->input_value(1),+ roi_align_v9_node->input_value(2),+ pooled_h,+ pooled_w,+ sampling_ratio,+ spatial_scale,+ m_mode_v3);roi_align_v3->set_friendly_name(roi_align_v9_node->get_friendly_name());ov::copy_runtime_info(roi_align_v9_node, roi_align_v3);ov::replace_node(roi_align_v9_node, roi_align_v3);@@ -59,6 +63,6 @@ ov::pass::ConvertROIAlign9To3::ConvertROIAlign9To3() {return true;};- auto m = std::make_shared<pattern::Matcher>(roi_align_v9, matcher_name);+ auto m = std::make_shared<Matcher>(roi_align_v9, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_to_scatter.cpp b/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_to_scatter.cppindex 8af016feb2c..ae24b81a401 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_to_scatter.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_to_scatter.cpp@@ -19,22 +19,26 @@#include "openvino/op/scatter_update.hpp"#include "openvino/op/squeeze.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v3 = ov::op::v3;ov::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() {MATCHER_SCOPE(ConvertScatterElementsToScatter);- auto data = std::make_shared<pattern::op::Label>(element::f32, Shape{1});- auto indices = std::make_shared<pattern::op::Label>(element::i64, Shape{1});- auto updates = std::make_shared<pattern::op::Label>(element::f32, Shape{1});- auto axis = ov::op::v0::Constant::create(element::i64, {1}, {0});+ auto data = std::make_shared<ov::pass::pattern::op::Label>(element::f32, Shape{1});+ auto indices = std::make_shared<ov::pass::pattern::op::Label>(element::i64, Shape{1});+ auto updates = std::make_shared<ov::pass::pattern::op::Label>(element::f32, Shape{1});+ auto axis = v0::Constant::create(element::i64, {1}, {0});- auto broadcast_shape = std::make_shared<pattern::op::Label>(element::i64, Shape{1});- auto broadcast = std::make_shared<ov::op::v3::Broadcast>(indices, broadcast_shape);+ auto broadcast_shape = std::make_shared<ov::pass::pattern::op::Label>(element::i64, Shape{1});+ auto broadcast = std::make_shared<v3::Broadcast>(indices, broadcast_shape);- auto scatter = std::make_shared<ov::op::v3::ScatterElementsUpdate>(data, broadcast, updates, axis);+ auto scatter = std::make_shared<v3::ScatterElementsUpdate>(data, broadcast, updates, axis);- matcher_pass_callback callback = [](pattern::Matcher& m) {+ matcher_pass_callback callback = [](Matcher& m) {auto scatter = m.get_match_root();auto broadcast = scatter->input_value(1).get_node_shared_ptr();- auto axis_const = ov::as_type_ptr<ov::op::v0::Constant>(scatter->input_value(3).get_node_shared_ptr());+ auto axis_const = ov::as_type_ptr<v0::Constant>(scatter->input_value(3).get_node_shared_ptr());if (!axis_const) {return false;@@ -179,7 +183,7 @@ ov::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() {if (indices_shape != indices_new_shape) {indices_input = std::make_shared<ov::op::v1::Reshape>(indices_input,- ov::op::v0::Constant::create(element::i64, Shape{indices_new_shape.size()}, indices_new_shape),+ v0::Constant::create(element::i64, Shape{indices_new_shape.size()}, indices_new_shape),false);new_ops.push_back(indices_input.get_node_shared_ptr());}@@ -201,17 +205,17 @@ ov::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() {if (indices_rank > 1) {std::vector<int64_t> squeeze_axes(indices_rank - 1ul);std::iota(squeeze_axes.begin(), squeeze_axes.end(), 1);- indices_input = std::make_shared<ov::op::v0::Squeeze>(+ indices_input = std::make_shared<v0::Squeeze>(indices_input,- ov::op::v0::Constant::create(element::i64, Shape{squeeze_axes.size()}, squeeze_axes));+ v0::Constant::create(element::i64, Shape{squeeze_axes.size()}, squeeze_axes));new_ops.push_back(indices_input.get_node_shared_ptr());}}- auto scatter_update = std::make_shared<ov::op::v3::ScatterUpdate>(scatter->input_value(0),- indices_input,- scatter->input_value(2),- scatter->input_value(3));+ auto scatter_update = std::make_shared<v3::ScatterUpdate>(scatter->input_value(0),+ indices_input,+ scatter->input_value(2),+ scatter->input_value(3));new_ops.push_back(scatter_update);scatter_update->set_friendly_name(scatter->get_friendly_name());ov::copy_runtime_info({scatter, broadcast}, {new_ops});@@ -219,6 +223,6 @@ ov::pass::ConvertScatterElementsToScatter::ConvertScatterElementsToScatter() {return true;};- auto m = std::make_shared<pass::pattern::Matcher>(scatter, matcher_name);+ auto m = std::make_shared<Matcher>(scatter, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_update12_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_update12_downgrade.cppindex 0f51551c4f6..d3179f0ac3f 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_update12_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_scatter_elements_update12_downgrade.cpp@@ -11,16 +11,19 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v12 = ov::op::v12;ov::pass::ConvertScatterElementsUpdate12ToScatterElementsUpdate3::ConvertScatterElementsUpdate12ToScatterElementsUpdate3() {MATCHER_SCOPE(ConvertScatterElementsUpdate12ToScatterElementsUpdate3);- const auto seu_v12_pattern = pattern::wrap_type<ov::op::v12::ScatterElementsUpdate>();+ const auto seu_v12_pattern = ov::pass::pattern::wrap_type<v12::ScatterElementsUpdate>();- const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto seu_v12 = ov::as_type_ptr<ov::op::v12::ScatterElementsUpdate>(m.get_match_root());+ const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ const auto seu_v12 = ov::as_type_ptr<v12::ScatterElementsUpdate>(m.get_match_root());if (!seu_v12 || transformation_callback(seu_v12) ||- seu_v12->get_reduction() != ov::op::v12::ScatterElementsUpdate::Reduction::NONE) {+ seu_v12->get_reduction() != v12::ScatterElementsUpdate::Reduction::NONE) {return false;}@@ -36,6 +39,6 @@ ov::pass::ConvertScatterElementsUpdate12ToScatterElementsUpdate3::return true;};- auto m = std::make_shared<pattern::Matcher>(seu_v12_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(seu_v12_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_scatter_nd_update15_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_scatter_nd_update15_downgrade.cppindex d56659098bc..a13c80f2d3f 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_scatter_nd_update15_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_scatter_nd_update15_downgrade.cpp@@ -11,17 +11,20 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v15 = ov::op::v15;ov::pass::ConvertScatterNDUpdate15ToScatterNDUpdate3::ConvertScatterNDUpdate15ToScatterNDUpdate3() {MATCHER_SCOPE(ConvertScatterNDUpdate15ToScatterNDUpdate3);- const auto scatter_v15_pattern = pattern::wrap_type<ov::op::v15::ScatterNDUpdate>();+ const auto scatter_v15_pattern = ov::pass::pattern::wrap_type<v15::ScatterNDUpdate>();- const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto scatter_v15 = ov::as_type_ptr<ov::op::v15::ScatterNDUpdate>(m.get_match_root());+ const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ const auto scatter_v15 = ov::as_type_ptr<v15::ScatterNDUpdate>(m.get_match_root());if (!scatter_v15 || transformation_callback(scatter_v15)) {return false;}- if (scatter_v15->get_reduction() != ov::op::v15::ScatterNDUpdate::Reduction::NONE) {+ if (scatter_v15->get_reduction() != v15::ScatterNDUpdate::Reduction::NONE) {return false;}const auto scatter_v3 = std::make_shared<ov::op::v3::ScatterNDUpdate>(scatter_v15->input_value(0),@@ -35,6 +38,6 @@ ov::pass::ConvertScatterNDUpdate15ToScatterNDUpdate3::ConvertScatterNDUpdate15Toreturn true;};- auto m = std::make_shared<pattern::Matcher>(scatter_v15_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(scatter_v15_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp b/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cppindex 71ab47528f7..827d62f668a 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_sequences_to_tensor_iterator.cpp@@ -31,52 +31,57 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v5 = ov::op::v5;+namespace op_util = ov::op::util;++namespace ov::pass {+namespace {ov::Output<ov::Node> get_current_iter(ov::ParameterVector& body_params,ov::ResultVector& body_results,const ov::Output<ov::Node>& seq_lengths) {- auto curr_iter_body_param = std::make_shared<ov::op::v0::Parameter>(seq_lengths.get_element_type(), ov::Shape{1});+ auto curr_iter_body_param = std::make_shared<v0::Parameter>(seq_lengths.get_element_type(), ov::Shape{1});// increment current iteration- auto one = ov::op::v0::Constant::create(seq_lengths.get_element_type(), ov::Shape{1}, {1});- auto add = std::make_shared<ov::op::v1::Add>(curr_iter_body_param, one);- auto curr_iter_result = std::make_shared<ov::op::v0::Result>(add);+ auto one = v0::Constant::create(seq_lengths.get_element_type(), ov::Shape{1}, {1});+ auto add = std::make_shared<v1::Add>(curr_iter_body_param, one);+ auto curr_iter_result = std::make_shared<v0::Result>(add);body_params.push_back(curr_iter_body_param);body_results.push_back(curr_iter_result);return curr_iter_body_param;}-ov::Output<ov::Node> get_masked_value(const std::shared_ptr<ov::op::v0::TensorIterator>& ti,+ov::Output<ov::Node> get_masked_value(const std::shared_ptr<v0::TensorIterator>& ti,ov::ParameterVector& body_params,ov::ResultVector& body_results,const ov::Output<ov::Node>& current_iter,const ov::Output<ov::Node>& data,const ov::Output<ov::Node>& seq_lengths) {// body parameters- auto aggregated_Y_h_body_param =- std::make_shared<ov::op::v0::Parameter>(data.get_element_type(), data.get_partial_shape());+ auto aggregated_Y_h_body_param = std::make_shared<v0::Parameter>(data.get_element_type(), data.get_partial_shape());body_params.push_back(aggregated_Y_h_body_param);// Create mask node deciding whether or not to mask batch data.- auto data_shape = ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(data);- auto axis = ov::op::v0::Constant::create(data_shape->get_element_type(), {1}, {0});- auto batch_seq_length = ov::op::util::make_try_fold<ov::op::v3::Broadcast>(seq_lengths,- data_shape,- axis,- ov::op::BroadcastType::EXPLICIT);+ auto data_shape = op_util::make_try_fold<v3::ShapeOf>(data);+ auto axis = v0::Constant::create(data_shape->get_element_type(), {1}, {0});+ auto batch_seq_length =+ op_util::make_try_fold<v3::Broadcast>(seq_lengths, data_shape, axis, ov::op::BroadcastType::EXPLICIT);- auto mask_condition = std::make_shared<ov::op::v1::Greater>(current_iter, batch_seq_length);- auto mask_Y_h = std::make_shared<ov::op::v1::Equal>(current_iter, batch_seq_length);+ auto mask_condition = std::make_shared<v1::Greater>(current_iter, batch_seq_length);+ auto mask_Y_h = std::make_shared<v1::Equal>(current_iter, batch_seq_length);// Select values depending on mask.// Select(<condition>, <true_value>, <false_value>)- auto select_aggregated_H = std::make_shared<ov::op::v1::Select>(mask_Y_h, data, aggregated_Y_h_body_param);- auto aggregated_result = std::make_shared<ov::op::v0::Result>(select_aggregated_H);+ auto select_aggregated_H = std::make_shared<v1::Select>(mask_Y_h, data, aggregated_Y_h_body_param);+ auto aggregated_result = std::make_shared<v0::Result>(select_aggregated_H);body_results.push_back(aggregated_result);- auto scalar_mask_value = ov::op::v0::Constant::create(data.get_element_type(), {}, {0.f});- auto mask_value = ov::op::util::make_try_fold<ov::op::v3::Broadcast>(scalar_mask_value, data_shape);- return ov::op::util::make_try_fold<ov::op::v1::Select>(mask_condition, mask_value, data);+ auto scalar_mask_value = v0::Constant::create(data.get_element_type(), {}, {0.f});+ auto mask_value = op_util::make_try_fold<v3::Broadcast>(scalar_mask_value, data_shape);+ return op_util::make_try_fold<v1::Select>(mask_condition, mask_value, data);}bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,@@ -93,57 +98,57 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,return false;}- bool enable_mask = ov::op::util::is_seq_len_provided(X.get_node_shared_ptr(), seq_lengths.get_node_shared_ptr());+ bool enable_mask = op_util::is_seq_len_provided(X.get_node_shared_ptr(), seq_lengths.get_node_shared_ptr());const bool is_reverse = direction == ov::op::RecurrentSequenceDirection::REVERSE;std::shared_ptr<ov::Node> reverse_seq_before;if (is_reverse && enable_mask) {- reverse_seq_before = std::make_shared<ov::op::v0::ReverseSequence>(X, seq_lengths, 0, 1);+ reverse_seq_before = std::make_shared<v0::ReverseSequence>(X, seq_lengths, 0, 1);}- auto axis_0 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {0});- auto axis_1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});+ auto axis_0 = v0::Constant::create(ov::element::i64, ov::Shape{1}, {0});+ auto axis_1 = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});// TensorIterator Body: beginauto X_param_pshape = X_pshape;X_param_pshape[1] = 1; // split by seq_lengths dimension- auto X_body_param = std::make_shared<ov::op::v0::Parameter>(X.get_element_type(), X_param_pshape);+ auto X_body_param = std::make_shared<v0::Parameter>(X.get_element_type(), X_param_pshape);- const auto squeezed_h = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(H_t, axis_1);- auto H_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_h->get_element_type(),- squeezed_h->get_output_partial_shape(0));+ const auto squeezed_h = op_util::make_try_fold<v0::Squeeze>(H_t, axis_1);+ auto H_body_param =+ std::make_shared<v0::Parameter>(squeezed_h->get_element_type(), squeezed_h->get_output_partial_shape(0));auto seq_body_param =- std::make_shared<ov::op::v0::Parameter>(seq_lengths.get_element_type(), seq_lengths.get_partial_shape());+ std::make_shared<v0::Parameter>(seq_lengths.get_element_type(), seq_lengths.get_partial_shape());// LSTM sequence caseconst bool cell_state_defined = C_t.get_node_shared_ptr() != nullptr;- std::shared_ptr<ov::op::v0::Parameter> C_body_param = nullptr;+ std::shared_ptr<v0::Parameter> C_body_param = nullptr;std::shared_ptr<ov::Node> squeezed_c = nullptr;if (cell_state_defined) {- squeezed_c = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(C_t, axis_1);- C_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_c->get_element_type(),- squeezed_c->get_output_partial_shape(0));+ squeezed_c = op_util::make_try_fold<v0::Squeeze>(C_t, axis_1);+ C_body_param =+ std::make_shared<v0::Parameter>(squeezed_c->get_element_type(), squeezed_c->get_output_partial_shape(0));}- const auto squeezed_x = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(X_body_param, axis_1);- const auto squeezed_w = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(W, axis_0);- std::shared_ptr<ov::op::v0::Parameter> W_body_param;- if (!ov::op::util::is_on_path<ov::op::v0::Constant>(squeezed_w))- W_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_w->get_element_type(),- squeezed_w->get_output_partial_shape(0));- const auto squeezed_r = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(R, axis_0);- std::shared_ptr<ov::op::v0::Parameter> R_body_param;- if (!ov::op::util::is_on_path<ov::op::v0::Constant>(squeezed_r))- R_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_r->get_element_type(),- squeezed_r->get_output_partial_shape(0));- const auto squeezed_b = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(B, axis_0);- std::shared_ptr<ov::op::v0::Parameter> B_body_param;- if (!ov::op::util::is_on_path<ov::op::v0::Constant>(squeezed_b))- B_body_param = std::make_shared<ov::op::v0::Parameter>(squeezed_b->get_element_type(),- squeezed_b->get_output_partial_shape(0));+ const auto squeezed_x = op_util::make_try_fold<v0::Squeeze>(X_body_param, axis_1);+ const auto squeezed_w = op_util::make_try_fold<v0::Squeeze>(W, axis_0);+ std::shared_ptr<v0::Parameter> W_body_param;+ if (!op_util::is_on_path<v0::Constant>(squeezed_w))+ W_body_param =+ std::make_shared<v0::Parameter>(squeezed_w->get_element_type(), squeezed_w->get_output_partial_shape(0));+ const auto squeezed_r = op_util::make_try_fold<v0::Squeeze>(R, axis_0);+ std::shared_ptr<v0::Parameter> R_body_param;+ if (!op_util::is_on_path<v0::Constant>(squeezed_r))+ R_body_param =+ std::make_shared<v0::Parameter>(squeezed_r->get_element_type(), squeezed_r->get_output_partial_shape(0));+ const auto squeezed_b = op_util::make_try_fold<v0::Squeeze>(B, axis_0);+ std::shared_ptr<v0::Parameter> B_body_param;+ if (!op_util::is_on_path<v0::Constant>(squeezed_b))+ B_body_param =+ std::make_shared<v0::Parameter>(squeezed_b->get_element_type(), squeezed_b->get_output_partial_shape(0));std::shared_ptr<ov::Node> cell;- if (const auto lstm_sequence = ov::as_type_ptr<ov::op::v5::LSTMSequence>(sequence)) {+ if (const auto lstm_sequence = ov::as_type_ptr<v5::LSTMSequence>(sequence)) {cell = std::make_shared<ov::op::v4::LSTMCell>(squeezed_x,H_body_param,C_body_param,@@ -155,29 +160,29 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,lstm_sequence->get_activations_alpha(),lstm_sequence->get_activations_beta(),lstm_sequence->get_clip());- } else if (const auto rnn_sequence = ov::as_type_ptr<ov::op::v5::RNNSequence>(sequence)) {- cell = std::make_shared<ov::op::v0::RNNCell>(squeezed_x,- H_body_param,- W_body_param ? W_body_param : squeezed_w,- R_body_param ? R_body_param : squeezed_r,- B_body_param ? B_body_param : squeezed_b,- rnn_sequence->get_hidden_size(),- rnn_sequence->get_activations(),- rnn_sequence->get_activations_alpha(),- rnn_sequence->get_activations_beta(),- rnn_sequence->get_clip());- } else if (const auto gnn_sequence = ov::as_type_ptr<ov::op::v5::GRUSequence>(sequence)) {- cell = std::make_shared<ov::op::v3::GRUCell>(squeezed_x,- H_body_param,- W_body_param ? W_body_param : squeezed_w,- R_body_param ? R_body_param : squeezed_r,- B_body_param ? B_body_param : squeezed_b,- gnn_sequence->get_hidden_size(),- gnn_sequence->get_activations(),- gnn_sequence->get_activations_alpha(),- gnn_sequence->get_activations_beta(),- gnn_sequence->get_clip(),- gnn_sequence->get_linear_before_reset());+ } else if (const auto rnn_sequence = ov::as_type_ptr<v5::RNNSequence>(sequence)) {+ cell = std::make_shared<v0::RNNCell>(squeezed_x,+ H_body_param,+ W_body_param ? W_body_param : squeezed_w,+ R_body_param ? R_body_param : squeezed_r,+ B_body_param ? B_body_param : squeezed_b,+ rnn_sequence->get_hidden_size(),+ rnn_sequence->get_activations(),+ rnn_sequence->get_activations_alpha(),+ rnn_sequence->get_activations_beta(),+ rnn_sequence->get_clip());+ } else if (const auto gnn_sequence = ov::as_type_ptr<v5::GRUSequence>(sequence)) {+ cell = std::make_shared<v3::GRUCell>(squeezed_x,+ H_body_param,+ W_body_param ? W_body_param : squeezed_w,+ R_body_param ? R_body_param : squeezed_r,+ B_body_param ? B_body_param : squeezed_b,+ gnn_sequence->get_hidden_size(),+ gnn_sequence->get_activations(),+ gnn_sequence->get_activations_alpha(),+ gnn_sequence->get_activations_beta(),+ gnn_sequence->get_clip(),+ gnn_sequence->get_linear_before_reset());} else {return false;}@@ -190,7 +195,7 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,if (cell_state_defined)cell_state = cell->output(1);- auto tensor_iterator = std::make_shared<ov::op::v0::TensorIterator>();+ auto tensor_iterator = std::make_shared<v0::TensorIterator>();if (enable_mask) {const auto current_iter = get_current_iter(body_params, body_results, seq_body_param);hidden_state =@@ -200,10 +205,10 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,get_masked_value(tensor_iterator, body_params, body_results, current_iter, cell_state, seq_body_param);}- auto H_res = std::make_shared<ov::op::v0::Result>(hidden_state);- auto C_res = cell_state_defined ? std::make_shared<ov::op::v0::Result>(cell_state) : nullptr;- auto hidden_state_unsqueezed = std::make_shared<ov::op::v0::Unsqueeze>(hidden_state, axis_1);- auto concat_res = std::make_shared<ov::op::v0::Result>(hidden_state_unsqueezed);+ auto H_res = std::make_shared<v0::Result>(hidden_state);+ auto C_res = cell_state_defined ? std::make_shared<v0::Result>(cell_state) : nullptr;+ auto hidden_state_unsqueezed = std::make_shared<v0::Unsqueeze>(hidden_state, axis_1);+ auto concat_res = std::make_shared<v0::Result>(hidden_state_unsqueezed);body_params.push_back(X_body_param);body_params.push_back(H_body_param);@@ -257,12 +262,11 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,if (enable_mask) {// create initial values for body_parameters in outer graph// aggregated Y_h - concatenation of the last non-zero values for each batch- auto H_body_param_shape = ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(squeezed_h);- auto aggregated_Y_h_scalar = ov::op::v0::Constant::create(squeezed_h->get_element_type(), {}, {0.f});- auto aggregated_Y_h =- ov::op::util::make_try_fold<ov::op::v3::Broadcast>(aggregated_Y_h_scalar, H_body_param_shape);+ auto H_body_param_shape = op_util::make_try_fold<v3::ShapeOf>(squeezed_h);+ auto aggregated_Y_h_scalar = v0::Constant::create(squeezed_h->get_element_type(), {}, {0.f});+ auto aggregated_Y_h = op_util::make_try_fold<v3::Broadcast>(aggregated_Y_h_scalar, H_body_param_shape);- auto init_val_curr_iter = ov::op::v0::Constant::create(seq_lengths.get_element_type(), ov::Shape{1}, {1});+ auto init_val_curr_iter = v0::Constant::create(seq_lengths.get_element_type(), ov::Shape{1}, {1});ov::copy_runtime_info(sequence, {aggregated_Y_h, init_val_curr_iter});// set initial value and back edge for current iteration@@ -273,10 +277,9 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,H_out = tensor_iterator->get_function()->get_results()[1];if (cell_state_defined) {- auto C_body_param_shape = ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(squeezed_c);- auto aggregated_Y_c_scalar = ov::op::v0::Constant::create(squeezed_c->get_element_type(), {}, {0.f});- auto aggregated_Y_c =- ov::op::util::make_try_fold<ov::op::v3::Broadcast>(aggregated_Y_c_scalar, C_body_param_shape);+ auto C_body_param_shape = op_util::make_try_fold<v3::ShapeOf>(squeezed_c);+ auto aggregated_Y_c_scalar = v0::Constant::create(squeezed_c->get_element_type(), {}, {0.f});+ auto aggregated_Y_c = op_util::make_try_fold<v3::Broadcast>(aggregated_Y_c_scalar, C_body_param_shape);ov::copy_runtime_info(sequence, aggregated_Y_c);// set initial value and back edge for aggregated C@@ -294,8 +297,7 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,new_nodes.push_back(squeezed_c);ov::OutputVector nodes_to_replace;if (enable_mask && is_reverse) {- auto reverse_seq_after =- std::make_shared<ov::op::v0::ReverseSequence>(tensor_iterator->output(0), seq_lengths, 0, 1);+ auto reverse_seq_after = std::make_shared<v0::ReverseSequence>(tensor_iterator->output(0), seq_lengths, 0, 1);// Resolve a collision of names data nodes in CNN Network in Reverse case with mask./** Before transformation (no collisions)@@ -332,7 +334,7 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,}for (size_t i = 0; i < nodes_to_replace.size(); i++) {- auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(nodes_to_replace[i], axis_1);+ auto unsqueeze = std::make_shared<v0::Unsqueeze>(nodes_to_replace[i], axis_1);unsqueeze->set_friendly_name(sequence->get_friendly_name() + "." + std::to_string(i));nodes_to_replace[i] = unsqueeze;new_nodes.push_back(unsqueeze);@@ -344,7 +346,7 @@ bool convert_sequence_to_ti(const std::shared_ptr<ov::Node>& sequence,}} // namespace-ov::pass::ConvertRNNSequenceToTensorIterator::ConvertRNNSequenceToTensorIterator() {+ConvertRNNSequenceToTensorIterator::ConvertRNNSequenceToTensorIterator() {MATCHER_SCOPE(ConvertRNNSequenceToTensorIterator);auto X_m = pattern::any_input(pattern::has_static_rank());auto H_t_m = pattern::any_input();@@ -352,10 +354,10 @@ ov::pass::ConvertRNNSequenceToTensorIterator::ConvertRNNSequenceToTensorIteratorauto W_m = pattern::any_input();auto R_m = pattern::any_input();auto B_m = pattern::any_input();- auto rnn_seq = ov::pass::pattern::wrap_type<ov::op::v5::RNNSequence>({X_m, H_t_m, seq_lengths_m, W_m, R_m, B_m});+ auto rnn_seq = pattern::wrap_type<v5::RNNSequence>({X_m, H_t_m, seq_lengths_m, W_m, R_m, B_m});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {- auto sequence = ov::as_type_ptr<ov::op::v5::RNNSequence>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ auto sequence = ov::as_type_ptr<v5::RNNSequence>(m.get_match_root());// Bidirectional Sequence op should be decomposed to Reverse + Forward// (e.g. apply BidirectionalRNNSequenceDecomposition transformation before this one)@@ -383,11 +385,11 @@ ov::pass::ConvertRNNSequenceToTensorIterator::ConvertRNNSequenceToTensorIteratorsequence->get_direction());};- auto m = std::make_shared<ov::pass::pattern::Matcher>(rnn_seq, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(rnn_seq, matcher_name);register_matcher(m, callback);}-ov::pass::ConvertGRUSequenceToTensorIterator::ConvertGRUSequenceToTensorIterator() {+ConvertGRUSequenceToTensorIterator::ConvertGRUSequenceToTensorIterator() {MATCHER_SCOPE(ConvertGRUSequenceToTensorIterator);auto X_m = pattern::any_input(pattern::has_static_rank());auto H_t_m = pattern::any_input();@@ -395,10 +397,10 @@ ov::pass::ConvertGRUSequenceToTensorIterator::ConvertGRUSequenceToTensorIteratorauto W_m = pattern::any_input();auto R_m = pattern::any_input();auto B_m = pattern::any_input();- auto gru_seq = ov::pass::pattern::wrap_type<ov::op::v5::GRUSequence>({X_m, H_t_m, seq_lengths_m, W_m, R_m, B_m});+ auto gru_seq = pattern::wrap_type<v5::GRUSequence>({X_m, H_t_m, seq_lengths_m, W_m, R_m, B_m});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {- auto sequence = ov::as_type_ptr<ov::op::v5::GRUSequence>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ auto sequence = ov::as_type_ptr<v5::GRUSequence>(m.get_match_root());// Bidirectional Sequence op should be decomposed to Reverse + Forward// (e.g. apply BidirectionalRNNSequenceDecomposition transformation before this one)@@ -426,11 +428,11 @@ ov::pass::ConvertGRUSequenceToTensorIterator::ConvertGRUSequenceToTensorIteratorsequence->get_direction());};- auto m = std::make_shared<ov::pass::pattern::Matcher>(gru_seq, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(gru_seq, matcher_name);register_matcher(m, callback);}-ov::pass::ConvertLSTMSequenceToTensorIterator::ConvertLSTMSequenceToTensorIterator() {+ConvertLSTMSequenceToTensorIterator::ConvertLSTMSequenceToTensorIterator() {MATCHER_SCOPE(ConvertLSTMSequenceToTensorIterator);auto X_m = pattern::any_input(pattern::has_static_rank());auto H_t_m = pattern::any_input();@@ -439,11 +441,10 @@ ov::pass::ConvertLSTMSequenceToTensorIterator::ConvertLSTMSequenceToTensorIteratauto W_m = pattern::any_input();auto R_m = pattern::any_input();auto B_m = pattern::any_input();- auto lstm_seq =- ov::pass::pattern::wrap_type<ov::op::v5::LSTMSequence>({X_m, H_t_m, C_t_m, seq_lengths_m, W_m, R_m, B_m});+ auto lstm_seq = pattern::wrap_type<v5::LSTMSequence>({X_m, H_t_m, C_t_m, seq_lengths_m, W_m, R_m, B_m});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {- auto sequence = ov::as_type_ptr<ov::op::v5::LSTMSequence>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ auto sequence = ov::as_type_ptr<v5::LSTMSequence>(m.get_match_root());// Bidirectional Sequence op should be decomposed to Reverse + Forward// (e.g. apply BidirectionalRNNSequenceDecomposition transformation before this one)@@ -464,12 +465,14 @@ ov::pass::ConvertLSTMSequenceToTensorIterator::ConvertLSTMSequenceToTensorIteratreturn convert_sequence_to_ti(sequence, X, H_t, C_t, seq_lengths, W, R, B, sequence->get_direction());};- auto m = std::make_shared<ov::pass::pattern::Matcher>(lstm_seq, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(lstm_seq, matcher_name);register_matcher(m, callback);}-ov::pass::ConvertSequenceToTensorIterator::ConvertSequenceToTensorIterator() {+ConvertSequenceToTensorIterator::ConvertSequenceToTensorIterator() {add_matcher<ConvertLSTMSequenceToTensorIterator>();add_matcher<ConvertRNNSequenceToTensorIterator>();add_matcher<ConvertGRUSequenceToTensorIterator>();}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_shapeof3.cpp b/src/common/transformations/src/transformations/op_conversions/convert_shapeof3.cppindex 17ee5c5e708..52d1447017c 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_shapeof3.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_shapeof3.cpp@@ -14,12 +14,16 @@#include "openvino/op/shape_of.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v3 = ov::op::v3;ov::pass::ConvertShapeOf3::ConvertShapeOf3() {MATCHER_SCOPE(ConvertShapeOf3);- auto shapeof = pattern::wrap_type<ov::op::v3::ShapeOf>();+ auto shapeof = ov::pass::pattern::wrap_type<v3::ShapeOf>();- matcher_pass_callback callback = [](pattern::Matcher& m) {- auto shapeof = ov::as_type_ptr<ov::op::v3::ShapeOf>(m.get_match_root());+ matcher_pass_callback callback = [](Matcher& m) {+ auto shapeof = ov::as_type_ptr<v3::ShapeOf>(m.get_match_root());if (!shapeof) {return false;}@@ -27,13 +31,13 @@ ov::pass::ConvertShapeOf3::ConvertShapeOf3() {Output<Node> last;ov::NodeVector new_ops;- auto new_shapeof = std::make_shared<ov::op::v0::ShapeOf>(shapeof->input_value(0));+ auto new_shapeof = std::make_shared<v0::ShapeOf>(shapeof->input_value(0));new_ops.push_back(new_shapeof);// if the output is the i64 then it matches behavior of the v1::ShapeOf otherwise need to insert Convertif (shapeof->get_output_type() == element::i64) {last = new_shapeof;} else {- last = std::make_shared<ov::op::v0::Convert>(new_shapeof, shapeof->get_output_type());+ last = std::make_shared<v0::Convert>(new_shapeof, shapeof->get_output_type());new_ops.push_back(last.get_node_shared_ptr());}@@ -43,6 +47,6 @@ ov::pass::ConvertShapeOf3::ConvertShapeOf3() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(shapeof, matcher_name);+ auto m = std::make_shared<Matcher>(shapeof, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_shuffle_channels3.cpp b/src/common/transformations/src/transformations/op_conversions/convert_shuffle_channels3.cppindex 4b973a06d2c..0dec6225964 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_shuffle_channels3.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_shuffle_channels3.cpp@@ -22,12 +22,16 @@using namespace ov;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::ConvertShuffleChannels3::ConvertShuffleChannels3() {MATCHER_SCOPE(ConvertShuffleChannels3);- auto shuffle_channels = pattern::wrap_type<ov::op::v0::ShuffleChannels>();+ auto shuffle_channels = ov::pass::pattern::wrap_type<v0::ShuffleChannels>();- matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto shuffle_channels = ov::as_type_ptr<ov::op::v0::ShuffleChannels>(m.get_match_root());+ matcher_pass_callback callback = [this](Matcher& m) {+ auto shuffle_channels = ov::as_type_ptr<v0::ShuffleChannels>(m.get_match_root());if (!shuffle_channels || transformation_callback(shuffle_channels)) {return false;}@@ -35,11 +39,11 @@ ov::pass::ConvertShuffleChannels3::ConvertShuffleChannels3() {return false;}- auto reduce_axis_const = ov::op::v0::Constant::create(element::i64, Shape({1}), std::vector<int64_t>{0});+ auto reduce_axis_const = v0::Constant::create(element::i64, Shape({1}), std::vector<int64_t>{0});auto shuffle_axis = shuffle_channels->get_axis();int64_t shuffle_group = static_cast<int64_t>(shuffle_channels->get_group());int64_t input_rank = shuffle_channels->input_value(0).get_partial_shape().rank().get_length();- auto original_shape = std::make_shared<ov::op::v0::ShapeOf>(shuffle_channels->input_value(0));+ auto original_shape = std::make_shared<v0::ShapeOf>(shuffle_channels->input_value(0));if (shuffle_axis < 0) {shuffle_axis += input_rank;}@@ -55,45 +59,44 @@ ov::pass::ConvertShuffleChannels3::ConvertShuffleChannels3() {}// get input tensor dimensions divided into parts with help of VariadicSplit- auto split_input_dimensions = std::make_shared<ov::op::v1::VariadicSplit>(+ auto split_input_dimensions = std::make_shared<v1::VariadicSplit>(original_shape->output(0),- ov::op::v0::Constant::create(element::i64, Shape({1}), std::vector<int64_t>{0}),- ov::op::v0::Constant::create(element::i64, Shape({split_lengts.size()}), split_lengts));+ v0::Constant::create(element::i64, Shape({1}), std::vector<int64_t>{0}),+ v0::Constant::create(element::i64, Shape({split_lengts.size()}), split_lengts));// calculate new dimension of the reshape. Start with two elements of {group, -1}::OutputVector new_dimensions = {- ov::op::v0::Constant::create(element::i64, Shape({1}), std::vector<int64_t>{shuffle_group}),- ov::op::v0::Constant::create(element::i64, Shape({1}), std::vector<int64_t>{-1})};+ v0::Constant::create(element::i64, Shape({1}), std::vector<int64_t>{shuffle_group}),+ v0::Constant::create(element::i64, Shape({1}), std::vector<int64_t>{-1})};// add more elements to the reshape output dimensions based on shuffle_axisstd::vector<int64_t> transpose_order;if (shuffle_axis == 0) {new_dimensions.push_back(- std::make_shared<ov::op::v1::ReduceProd>(split_input_dimensions->output(1), reduce_axis_const, true));+ std::make_shared<v1::ReduceProd>(split_input_dimensions->output(1), reduce_axis_const, true));transpose_order = {1, 0, 2};} else if (shuffle_axis + 1 == input_rank) {new_dimensions.insert(new_dimensions.begin(),- std::make_shared<ov::op::v1::ReduceProd>(split_input_dimensions->output(0), reduce_axis_const, true));+ std::make_shared<v1::ReduceProd>(split_input_dimensions->output(0), reduce_axis_const, true));transpose_order = {0, 2, 1};} else {new_dimensions.insert(new_dimensions.begin(),- std::make_shared<ov::op::v1::ReduceProd>(split_input_dimensions->output(0), reduce_axis_const, true));+ std::make_shared<v1::ReduceProd>(split_input_dimensions->output(0), reduce_axis_const, true));new_dimensions.push_back(- std::make_shared<ov::op::v1::ReduceProd>(split_input_dimensions->output(2), reduce_axis_const, true));+ std::make_shared<v1::ReduceProd>(split_input_dimensions->output(2), reduce_axis_const, true));transpose_order = {0, 2, 1, 3};}// reshape the tensor to a new shape- auto new_shape = std::make_shared<ov::op::v0::Concat>(new_dimensions, 0);- auto reshape = std::make_shared<ov::op::v1::Reshape>(shuffle_channels->input_value(0), new_shape, false);+ auto new_shape = std::make_shared<v0::Concat>(new_dimensions, 0);+ auto reshape = std::make_shared<v1::Reshape>(shuffle_channels->input_value(0), new_shape, false);// swap dimensions appearing after splitting the "shuffle_axis" dimension into two- auto transpose = std::make_shared<ov::op::v1::Transpose>(+ auto transpose = std::make_shared<v1::Transpose>(reshape->output(0),- ov::op::v0::Constant::create(element::i64, Shape({transpose_order.size()}), transpose_order));+ v0::Constant::create(element::i64, Shape({transpose_order.size()}), transpose_order));// restore original shape- auto reshape_back =- std::make_shared<ov::op::v1::Reshape>(transpose->output(0), original_shape->output(0), false);+ auto reshape_back = std::make_shared<v1::Reshape>(transpose->output(0), original_shape->output(0), false);::NodeVector new_ops = {original_shape, split_input_dimensions, transpose, reshape, reshape_back, new_shape};for (auto output : new_dimensions)@@ -104,6 +107,6 @@ ov::pass::ConvertShuffleChannels3::ConvertShuffleChannels3() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(shuffle_channels, matcher_name);+ auto m = std::make_shared<Matcher>(shuffle_channels, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_slice_to_strided_slice.cpp b/src/common/transformations/src/transformations/op_conversions/convert_slice_to_strided_slice.cppindex a654175172d..2b144313510 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_slice_to_strided_slice.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_slice_to_strided_slice.cpp@@ -22,6 +22,11 @@using namespace ov;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;namespace {Output<ov::Node> align_indices(const Output<ov::Node>& indices,const Output<ov::Node>& slice_axes,@@ -40,14 +45,13 @@ Output<ov::Node> align_indices(const Output<ov::Node>& indices,// expected_output_shape: {3, 3, 1, 1}const auto default_indices =- ov::op::v0::Constant::create(indices.get_element_type(), Shape{slice_indices_length}, {fill_in_value});- std::shared_ptr<ov::Node> adjusted_indices =- ov::op::util::make_try_fold<ov::op::v3::ScatterUpdate>(default_indices,- slice_axes,- indices, // updates- scatter_axis);-- if (!ov::op::util::is_constant(adjusted_indices)) {+ v0::Constant::create(indices.get_element_type(), Shape{slice_indices_length}, {fill_in_value});+ std::shared_ptr<ov::Node> adjusted_indices = op_util::make_try_fold<ov::op::v3::ScatterUpdate>(default_indices,+ slice_axes,+ indices, // updates+ scatter_axis);++ if (!op_util::is_constant(adjusted_indices)) {new_ops.push_back(default_indices);}return adjusted_indices;@@ -65,9 +69,9 @@ std::vector<int64_t> axes_to_mask(const std::vector<int64_t>& axes, size_t sliceov::pass::SliceToStridedSlice::SliceToStridedSlice(bool use_shapes) {MATCHER_SCOPE(SliceToStridedSlice);- auto slice = pattern::wrap_type<ov::op::v8::Slice>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto slice_node = ov::as_type_ptr<ov::op::v8::Slice>(m.get_match_root());+ auto slice = ov::pass::pattern::wrap_type<v8::Slice>();+ matcher_pass_callback callback = [=](Matcher& m) {+ auto slice_node = ov::as_type_ptr<v8::Slice>(m.get_match_root());if (!slice_node)return false;@@ -76,29 +80,28 @@ ov::pass::SliceToStridedSlice::SliceToStridedSlice(bool use_shapes) {auto arg = slice_node->input_value(0);- std::shared_ptr<ov::op::v0::Constant> start_const;- std::shared_ptr<ov::op::v0::Constant> stop_const;- std::shared_ptr<ov::op::v0::Constant> step_const;+ std::shared_ptr<v0::Constant> start_const;+ std::shared_ptr<v0::Constant> stop_const;+ std::shared_ptr<v0::Constant> step_const;if (use_shapes) {start_const = ov::util::get_constant_from_source(slice_node->input_value(1));stop_const = ov::util::get_constant_from_source(slice_node->input_value(2));step_const = ov::util::get_constant_from_source(slice_node->input_value(3));} else {- start_const = ov::as_type_ptr<ov::op::v0::Constant>(slice_node->input_value(1).get_node_shared_ptr());- stop_const = ov::as_type_ptr<ov::op::v0::Constant>(slice_node->input_value(2).get_node_shared_ptr());- step_const = ov::as_type_ptr<ov::op::v0::Constant>(slice_node->input_value(3).get_node_shared_ptr());+ start_const = ov::as_type_ptr<v0::Constant>(slice_node->input_value(1).get_node_shared_ptr());+ stop_const = ov::as_type_ptr<v0::Constant>(slice_node->input_value(2).get_node_shared_ptr());+ step_const = ov::as_type_ptr<v0::Constant>(slice_node->input_value(3).get_node_shared_ptr());}auto start_input = start_const ? start_const : slice_node->input_value(1);auto stop_input = stop_const ? stop_const : slice_node->input_value(2);auto step_input = step_const ? step_const : slice_node->input_value(3);- std::shared_ptr<ov::op::v0::Constant> axes_const;+ std::shared_ptr<v0::Constant> axes_const;if (slice_node->get_input_size() > 4) {- axes_const = use_shapes- ? ov::util::get_constant_from_source(slice_node->input_value(4))- : ov::as_type_ptr<ov::op::v0::Constant>(slice_node->input_value(4).get_node_shared_ptr());+ axes_const = use_shapes ? ov::util::get_constant_from_source(slice_node->input_value(4))+ : ov::as_type_ptr<v0::Constant>(slice_node->input_value(4).get_node_shared_ptr());} else {axes_const = slice_node->get_default_const_axes(start_input);}@@ -124,8 +127,8 @@ ov::pass::SliceToStridedSlice::SliceToStridedSlice(bool use_shapes) {NodeVector new_ops;if (!are_indices_aligned) {- const auto scatter_axis = ov::op::v0::Constant::create(element::i32, Shape{1}, {0});- const auto slice_axes = ov::op::v0::Constant::create(element::i64, Shape{axes_vec.size()}, axes_vec);+ const auto scatter_axis = v0::Constant::create(element::i32, Shape{1}, {0});+ const auto slice_axes = v0::Constant::create(element::i64, Shape{axes_vec.size()}, axes_vec);new_ops.insert(new_ops.end(), {scatter_axis, slice_axes});start_input = align_indices(start_input, slice_axes, scatter_axis, slice_indices_length, 0, new_ops);@@ -150,6 +153,6 @@ ov::pass::SliceToStridedSlice::SliceToStridedSlice(bool use_shapes) {return true;};- auto m = std::make_shared<pattern::Matcher>(slice, matcher_name);+ auto m = std::make_shared<Matcher>(slice, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_slicescatter.cpp b/src/common/transformations/src/transformations/op_conversions/convert_slicescatter.cppindex 5559b936109..a8308dbca01 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_slicescatter.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_slicescatter.cpp@@ -20,51 +20,56 @@#include "openvino/op/slice_scatter.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v8 = ov::op::v8;+namespace v15 = ov::op::v15;ov::pass::ConvertSliceScatter::ConvertSliceScatter() {MATCHER_SCOPE(ConvertSliceScatter);- const auto& slicescatter = pattern::wrap_type<ov::op::v15::SliceScatter>();+ const auto& slicescatter = ov::pass::pattern::wrap_type<v15::SliceScatter>();- const matcher_pass_callback callback = [this](pattern::Matcher& m) {- const auto& slice_node = ov::as_type_ptr<ov::op::v15::SliceScatter>(m.get_match_root());+ const matcher_pass_callback callback = [this](Matcher& m) {+ const auto& slice_node = ov::as_type_ptr<v15::SliceScatter>(m.get_match_root());if (!slice_node || transformation_callback(slice_node)) {return false;}NodeRegistry node_registry;- const auto& const_0 = node_registry.make<ov::op::v0::Constant>(ov::element::i64, Shape{}, 0);- const auto& const_1 = node_registry.make<ov::op::v0::Constant>(ov::element::i64, Shape{}, 1);+ const auto& const_0 = node_registry.make<v0::Constant>(ov::element::i64, Shape{}, 0);+ const auto& const_1 = node_registry.make<v0::Constant>(ov::element::i64, Shape{}, 1);const auto& const_1d_neg_1 =- node_registry.make<ov::op::v0::Constant>(ov::element::i64, Shape{1}, std::vector<int64_t>{-1});+ node_registry.make<v0::Constant>(ov::element::i64, Shape{1}, std::vector<int64_t>{-1});const auto& const_scatter_indices_shape =- node_registry.make<ov::op::v0::Constant>(ov::element::i64, Shape{2}, std::vector<int64_t>{-1, 1});- const auto& data_shape = node_registry.make<ov::op::v3::ShapeOf>(slice_node->input_value(0), ov::element::i64);- const auto& num_elements_data = node_registry.make<ov::op::v1::ReduceProd>(data_shape, const_0, false);+ node_registry.make<v0::Constant>(ov::element::i64, Shape{2}, std::vector<int64_t>{-1, 1});+ const auto& data_shape = node_registry.make<v3::ShapeOf>(slice_node->input_value(0), ov::element::i64);+ const auto& num_elements_data = node_registry.make<v1::ReduceProd>(data_shape, const_0, false);const auto& data_indices_flatten =node_registry.make<ov::op::v4::Range>(const_0, num_elements_data, const_1, ov::element::i64);- const auto& full_data_indices =- node_registry.make<ov::op::v1::Reshape>(data_indices_flatten, data_shape, false);- std::shared_ptr<ov::op::v8::Slice> slice_indices;+ const auto& full_data_indices = node_registry.make<v1::Reshape>(data_indices_flatten, data_shape, false);+ std::shared_ptr<v8::Slice> slice_indices;if (slice_node->get_input_size() == 5) {- slice_indices = node_registry.make<ov::op::v8::Slice>(full_data_indices,- slice_node->input_value(2),- slice_node->input_value(3),- slice_node->input_value(4));+ slice_indices = node_registry.make<v8::Slice>(full_data_indices,+ slice_node->input_value(2),+ slice_node->input_value(3),+ slice_node->input_value(4));} else {- slice_indices = node_registry.make<ov::op::v8::Slice>(full_data_indices,- slice_node->input_value(2),- slice_node->input_value(3),- slice_node->input_value(4),- slice_node->input_value(5));+ slice_indices = node_registry.make<v8::Slice>(full_data_indices,+ slice_node->input_value(2),+ slice_node->input_value(3),+ slice_node->input_value(4),+ slice_node->input_value(5));}const auto& slice_indices_flatten =- node_registry.make<ov::op::v1::Reshape>(slice_indices, const_scatter_indices_shape, false);+ node_registry.make<v1::Reshape>(slice_indices, const_scatter_indices_shape, false);const auto& updates_flatten =- node_registry.make<ov::op::v1::Reshape>(slice_node->input_value(1), const_1d_neg_1, false);- const auto& data_flatten =- node_registry.make<ov::op::v1::Reshape>(slice_node->input_value(0), const_1d_neg_1, false);+ node_registry.make<v1::Reshape>(slice_node->input_value(1), const_1d_neg_1, false);+ const auto& data_flatten = node_registry.make<v1::Reshape>(slice_node->input_value(0), const_1d_neg_1, false);const auto& output_flatten =- node_registry.make<ov::op::v3::ScatterNDUpdate>(data_flatten, slice_indices_flatten, updates_flatten);- const auto& output = node_registry.make<ov::op::v1::Reshape>(output_flatten, data_shape, false);+ node_registry.make<v3::ScatterNDUpdate>(data_flatten, slice_indices_flatten, updates_flatten);+ const auto& output = node_registry.make<v1::Reshape>(output_flatten, data_shape, false);output->set_friendly_name(slice_node->get_friendly_name());copy_runtime_info(slice_node, node_registry.get());@@ -73,6 +78,6 @@ ov::pass::ConvertSliceScatter::ConvertSliceScatter() {return true;};- const auto& m = std::make_shared<pattern::Matcher>(slicescatter, matcher_name);+ const auto& m = std::make_shared<Matcher>(slicescatter, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cppindex 70086b0b256..9319554ded7 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp@@ -11,14 +11,17 @@#include "openvino/op/softmax.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v8 = ov::op::v8;ov::pass::ConvertSoftMax8ToSoftMax1::ConvertSoftMax8ToSoftMax1() {MATCHER_SCOPE(ConvertSoftMax8ToSoftMax1);- auto input = pattern::any_input(pattern::has_static_rank());- auto softmax_v8_pattern = pattern::wrap_type<ov::op::v8::Softmax>({input});+ auto input = ov::pass::pattern::any_input(ov::pass::pattern::has_static_rank());+ auto softmax_v8_pattern = ov::pass::pattern::wrap_type<v8::Softmax>({input});- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto softmax_v8_node = ov::as_type_ptr<ov::op::v8::Softmax>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto softmax_v8_node = ov::as_type_ptr<v8::Softmax>(m.get_match_root());if (!softmax_v8_node)return false;@@ -34,6 +37,6 @@ ov::pass::ConvertSoftMax8ToSoftMax1::ConvertSoftMax8ToSoftMax1() {return true;};- auto m = std::make_shared<pattern::Matcher>(softmax_v8_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(softmax_v8_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_softmax_upgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_softmax_upgrade.cppindex 4ee0abb20f0..a4e40513d63 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_softmax_upgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_softmax_upgrade.cpp@@ -10,13 +10,16 @@#include "openvino/op/softmax.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v1 = ov::op::v1;ov::pass::ConvertSoftMax1ToSoftMax8::ConvertSoftMax1ToSoftMax8() {MATCHER_SCOPE(ConvertSoftMax1ToSoftMax8);- auto softmax_v1_pattern = pattern::wrap_type<ov::op::v1::Softmax>();+ auto softmax_v1_pattern = ov::pass::pattern::wrap_type<v1::Softmax>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto softmax_v1_node = ov::as_type_ptr<ov::op::v1::Softmax>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto softmax_v1_node = ov::as_type_ptr<v1::Softmax>(m.get_match_root());if (!softmax_v1_node)return false;@@ -29,6 +32,6 @@ ov::pass::ConvertSoftMax1ToSoftMax8::ConvertSoftMax1ToSoftMax8() {return true;};- auto m = std::make_shared<pattern::Matcher>(softmax_v1_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(softmax_v1_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp b/src/common/transformations/src/transformations/op_conversions/convert_space_to_batch.cppindex cbbc5ec0d13..4f43fcb2b66 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_space_to_batch.cpp@@ -28,11 +28,18 @@using namespace std;using namespace ov::element;-void ov::pass::ConvertSpaceToBatch::convert_space_to_batch() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v8 = ov::op::v8;++namespace ov::pass {++void ConvertSpaceToBatch::convert_space_to_batch() {MATCHER_SCOPE(ConvertSpaceToBatch_convert_space_to_batch);- const auto space_to_batch = pattern::wrap_type<ov::op::v1::SpaceToBatch>();+ const auto space_to_batch = pattern::wrap_type<v1::SpaceToBatch>();matcher_pass_callback callback = [this](pattern::Matcher& m) {- const auto space_to_batch = ov::as_type_ptr<ov::op::v1::SpaceToBatch>(m.get_match_root());+ const auto space_to_batch = ov::as_type_ptr<v1::SpaceToBatch>(m.get_match_root());if (!space_to_batch || transformation_callback(space_to_batch)) {return false;}@@ -59,12 +66,12 @@ void ov::pass::ConvertSpaceToBatch::convert_space_to_batch() {// note: P_0 for batch dimension is expected to be 0 (no-padding).// x = [batch + P_0, D_1 + P_1, D_2 + P_2, ..., D_{N - 1} + P_{N - 1}], where P_i =// pads_begin[i] + pads_end[i]- shared_ptr<Node> flat_node = rg.make<ov::op::v1::Pad>(data, pads_begin, pads_end, op::PadMode::CONSTANT);- const auto out_shape = rg.make<ov::op::v3::ShapeOf>(flat_node, block.get_element_type());+ shared_ptr<Node> flat_node = rg.make<v1::Pad>(data, pads_begin, pads_end, op::PadMode::CONSTANT);+ const auto out_shape = rg.make<v3::ShapeOf>(flat_node, block.get_element_type());- const auto zero = rg.make<ov::op::v0::Constant>(i64, Shape{1}, 0);- const auto one = rg.make<ov::op::v0::Constant>(i64, Shape{1}, 1);- const auto int_max = rg.make<ov::op::v0::Constant>(i64, Shape{1}, INT_MAX);+ const auto zero = rg.make<v0::Constant>(i64, Shape{1}, 0);+ const auto one = rg.make<v0::Constant>(i64, Shape{1}, 1);+ const auto int_max = rg.make<v0::Constant>(i64, Shape{1}, INT_MAX);// First we have to disperse the data from spatial dimensions, then// rearrange them so as appropriate chunks of data where close to their@@ -73,26 +80,21 @@ void ov::pass::ConvertSpaceToBatch::convert_space_to_batch() {// note: B_0 for batch is ignored.// x' = reshape(x, [batch, (D_1 + P_1) / B_1, B_1, (D_2 + P_2) / B_2, B_2, ...,// (D_{N - 1} + P_{N - 1}) / B_{N - 1}, B_{N - 1}]), where B_i = block_shape[i]- const auto batch = rg.make<ov::op::v8::Gather>(out_shape, zero, zero);- const auto out_shape_tail = rg.make<ov::op::v8::Slice>(out_shape, one, int_max, one);- const auto block_tail = rg.make<ov::op::v8::Slice>(block, one, int_max, one);- const auto os_tail_div = rg.make<ov::op::v1::Divide>(out_shape_tail, block_tail);+ const auto batch = rg.make<v8::Gather>(out_shape, zero, zero);+ const auto out_shape_tail = rg.make<v8::Slice>(out_shape, one, int_max, one);+ const auto block_tail = rg.make<v8::Slice>(block, one, int_max, one);+ const auto os_tail_div = rg.make<v1::Divide>(out_shape_tail, block_tail);// interleave os_tail_div with block_tail- const auto c = rg.make<ov::op::v0::Concat>(NodeVector{os_tail_div, block_tail}, 0);- const auto r = rg.make<ov::op::v1::Reshape>(- c,- rg.make<ov::op::v0::Constant>(i64, Shape{2}, vector<int64_t>{2, block_length - 1}),- false);- const auto t =- rg.make<ov::op::v1::Transpose>(r, rg.make<ov::op::v0::Constant>(i64, Shape{2}, vector<int64_t>{1, 0}));+ const auto c = rg.make<v0::Concat>(NodeVector{os_tail_div, block_tail}, 0);+ const auto r =+ rg.make<v1::Reshape>(c, rg.make<v0::Constant>(i64, Shape{2}, vector<int64_t>{2, block_length - 1}), false);+ const auto t = rg.make<v1::Transpose>(r, rg.make<v0::Constant>(i64, Shape{2}, vector<int64_t>{1, 0}));const auto interleaved =- rg.make<ov::op::v1::Reshape>(t,- rg.make<ov::op::v0::Constant>(i64, Shape{1}, 2 * (block_length - 1)),- false);+ rg.make<v1::Reshape>(t, rg.make<v0::Constant>(i64, Shape{1}, 2 * (block_length - 1)), false);- const auto dispersed_shape = rg.make<ov::op::v0::Concat>(NodeVector{batch, interleaved}, 0);- flat_node = rg.make<ov::op::v1::Reshape>(flat_node, dispersed_shape, false);+ const auto dispersed_shape = rg.make<v0::Concat>(NodeVector{batch, interleaved}, 0);+ flat_node = rg.make<v1::Reshape>(flat_node, dispersed_shape, false);// x'' = transpose(x', [2, 4, ..., (N - 1) + (N - 1), 0, 1, 3, ..., N + (N - 1)])vector<int64_t> axes_order;@@ -104,16 +106,16 @@ void ov::pass::ConvertSpaceToBatch::convert_space_to_batch() {axes_order.push_back(j);}- const auto axes_order_const = rg.make<ov::op::v0::Constant>(i64, Shape{axes_order.size()}, axes_order);- flat_node = rg.make<ov::op::v1::Transpose>(flat_node, axes_order_const);+ const auto axes_order_const = rg.make<v0::Constant>(i64, Shape{axes_order.size()}, axes_order);+ flat_node = rg.make<v1::Transpose>(flat_node, axes_order_const);// y = reshape(x'', [batch * B_1 * ... * B_{N - 1}, (D_1 + P_1) / B_1, (D_2 + P_2) / B_2, ...,// (D_{N - 1} + P_{N - 1}) / B_{N - 1}])// note: B_0 is assumed to be 1 by op definion- const auto block_prod = rg.make<ov::op::v1::ReduceProd>(block, zero);+ const auto block_prod = rg.make<v1::ReduceProd>(block, zero);const auto squeezed_shape =- rg.make<ov::op::v0::Concat>(NodeVector{rg.make<ov::op::v1::Multiply>(batch, block_prod), os_tail_div}, 0);- flat_node = rg.make<ov::op::v1::Reshape>(flat_node, squeezed_shape, false);+ rg.make<v0::Concat>(NodeVector{rg.make<v1::Multiply>(batch, block_prod), os_tail_div}, 0);+ flat_node = rg.make<v1::Reshape>(flat_node, squeezed_shape, false);flat_node->set_friendly_name(space_to_batch->get_friendly_name());copy_runtime_info(space_to_batch, rg.get());@@ -125,11 +127,11 @@ void ov::pass::ConvertSpaceToBatch::convert_space_to_batch() {this->register_matcher(m, callback);}-void ov::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() {+void ConvertSpaceToBatch::convert_space_to_batch_by_elements() {MATCHER_SCOPE(ConvertSpaceToBatch_convert_space_to_batch_by_elements);- const auto space_to_batch = pattern::wrap_type<ov::op::v1::SpaceToBatch>();+ const auto space_to_batch = pattern::wrap_type<v1::SpaceToBatch>();matcher_pass_callback callback = [this](pattern::Matcher& m) {- const auto space_to_batch = ov::as_type_ptr<ov::op::v1::SpaceToBatch>(m.get_match_root());+ const auto space_to_batch = ov::as_type_ptr<v1::SpaceToBatch>(m.get_match_root());if (!space_to_batch || transformation_callback(space_to_batch)) {return false;}@@ -150,33 +152,32 @@ void ov::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() {NodeRegistry rg;- shared_ptr<Node> flat_node = rg.make<ov::op::v1::Pad>(data, pads_begin, pads_end, op::PadMode::CONSTANT);+ shared_ptr<Node> flat_node = rg.make<v1::Pad>(data, pads_begin, pads_end, op::PadMode::CONSTANT);- shared_ptr<Node> squeezed_shape = rg.make<ov::op::v3::ShapeOf>(flat_node, block.get_element_type());+ shared_ptr<Node> squeezed_shape = rg.make<v3::ShapeOf>(flat_node, block.get_element_type());- const auto zero = rg.make<ov::op::v0::Constant>(i64, Shape{1}, 0);- const auto one = rg.make<ov::op::v0::Constant>(i64, Shape{1}, 1);- const auto int_max = rg.make<ov::op::v0::Constant>(i64, Shape{1}, INT_MAX);+ const auto zero = rg.make<v0::Constant>(i64, Shape{1}, 0);+ const auto one = rg.make<v0::Constant>(i64, Shape{1}, 1);+ const auto int_max = rg.make<v0::Constant>(i64, Shape{1}, INT_MAX);for (int64_t b_idx = block_length - 1; b_idx >= 0; --b_idx) {- const auto block_index = rg.make<ov::op::v0::Constant>(i64, Shape{1}, b_idx);- const auto block_index_next = rg.make<ov::op::v0::Constant>(i64, Shape{1}, b_idx + 1);- const auto block_value = rg.make<ov::op::v8::Gather>(block, block_index, zero);+ const auto block_index = rg.make<v0::Constant>(i64, Shape{1}, b_idx);+ const auto block_index_next = rg.make<v0::Constant>(i64, Shape{1}, b_idx + 1);+ const auto block_value = rg.make<v8::Gather>(block, block_index, zero);NodeVector dispersed_shape_prep;dispersed_shape_prep.reserve(block_length + 1);if (b_idx > 0) // avoid addind empty Slice into Concat- dispersed_shape_prep.push_back(rg.make<ov::op::v8::Slice>(squeezed_shape, zero, block_index, one));- const auto squeezed_element = rg.make<ov::op::v8::Gather>(squeezed_shape, block_index, zero);- dispersed_shape_prep.push_back(rg.make<ov::op::v1::Divide>(squeezed_element, block_value));+ dispersed_shape_prep.push_back(rg.make<v8::Slice>(squeezed_shape, zero, block_index, one));+ const auto squeezed_element = rg.make<v8::Gather>(squeezed_shape, block_index, zero);+ dispersed_shape_prep.push_back(rg.make<v1::Divide>(squeezed_element, block_value));dispersed_shape_prep.push_back(block_value);if (b_idx + 1 < block_length) // avoid addind empty Slice into Concat- dispersed_shape_prep.push_back(- rg.make<ov::op::v8::Slice>(squeezed_shape, block_index_next, int_max, one));+ dispersed_shape_prep.push_back(rg.make<v8::Slice>(squeezed_shape, block_index_next, int_max, one));- const auto dispersed_shape = rg.make<ov::op::v0::Concat>(dispersed_shape_prep, 0);+ const auto dispersed_shape = rg.make<v0::Concat>(dispersed_shape_prep, 0);constexpr auto special_zero = false;- flat_node = rg.make<ov::op::v1::Reshape>(flat_node, dispersed_shape, special_zero);+ flat_node = rg.make<v1::Reshape>(flat_node, dispersed_shape, special_zero);vector<int64_t> axes_order(block_length + 1);int64_t axis_idx = axes_order.size() - 1;@@ -191,30 +192,27 @@ void ov::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() {axis_idx--;}}- const auto axes_order_const = rg.make<ov::op::v0::Constant>(i64, Shape{axes_order.size()}, axes_order);- flat_node = rg.make<ov::op::v1::Transpose>(flat_node, axes_order_const);+ const auto axes_order_const = rg.make<v0::Constant>(i64, Shape{axes_order.size()}, axes_order);+ flat_node = rg.make<v1::Transpose>(flat_node, axes_order_const);// don't change squeezed_shape at the last iteration, block[0] is assumed to be 1 by op definionif (b_idx > 0) {NodeVector squeezed_shape_prep;squeezed_shape_prep.reserve(block_length);squeezed_shape_prep.push_back(- rg.make<ov::op::v1::Multiply>(rg.make<ov::op::v8::Gather>(squeezed_shape, zero, zero),- block_value));+ rg.make<v1::Multiply>(rg.make<v8::Gather>(squeezed_shape, zero, zero), block_value));if (b_idx > 1) { // avoid addind empty Slice into Concat- squeezed_shape_prep.push_back(rg.make<ov::op::v8::Slice>(squeezed_shape, one, block_index, one));+ squeezed_shape_prep.push_back(rg.make<v8::Slice>(squeezed_shape, one, block_index, one));}squeezed_shape_prep.push_back(- rg.make<ov::op::v1::Divide>(rg.make<ov::op::v8::Gather>(squeezed_shape, block_index, zero),- block_value));+ rg.make<v1::Divide>(rg.make<v8::Gather>(squeezed_shape, block_index, zero), block_value));if (b_idx + 1 < block_length) { // avoid addind empty Slice into Concat- squeezed_shape_prep.push_back(- rg.make<ov::op::v8::Slice>(squeezed_shape, block_index_next, int_max, one));+ squeezed_shape_prep.push_back(rg.make<v8::Slice>(squeezed_shape, block_index_next, int_max, one));}- squeezed_shape = rg.make<ov::op::v0::Concat>(squeezed_shape_prep, 0);+ squeezed_shape = rg.make<v0::Concat>(squeezed_shape_prep, 0);}- flat_node = rg.make<ov::op::v1::Reshape>(flat_node, squeezed_shape, special_zero);+ flat_node = rg.make<v1::Reshape>(flat_node, squeezed_shape, special_zero);}flat_node->set_friendly_name(space_to_batch->get_friendly_name());@@ -226,3 +224,5 @@ void ov::pass::ConvertSpaceToBatch::convert_space_to_batch_by_elements() {const auto m = make_shared<pattern::Matcher>(space_to_batch, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_space_to_depth.cpp b/src/common/transformations/src/transformations/op_conversions/convert_space_to_depth.cppindex 1500840ef21..1e7224b4623 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_space_to_depth.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_space_to_depth.cpp@@ -16,13 +16,17 @@#include "openvino/op/transpose.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::ConvertSpaceToDepth::ConvertSpaceToDepth() {MATCHER_SCOPE(ConvertSpaceToDepth);- auto dts =- ov::pass::pattern::wrap_type<ov::op::v0::SpaceToDepth>({pattern::any_input(pattern::has_static_shape())});+ auto dts = ov::pass::pattern::wrap_type<v0::SpaceToDepth>(+ {ov::pass::pattern::any_input(ov::pass::pattern::has_static_shape())});- matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto std_node = ov::as_type_ptr<ov::op::v0::SpaceToDepth>(m.get_match_root());+ matcher_pass_callback callback = [this](Matcher& m) {+ auto std_node = ov::as_type_ptr<v0::SpaceToDepth>(m.get_match_root());if (!std_node || transformation_callback(std_node)) {return false;}@@ -60,10 +64,10 @@ ov::pass::ConvertSpaceToDepth::ConvertSpaceToDepth() {}switch (mode) {- case ov::op::v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST:+ case v0::SpaceToDepth::SpaceToDepthMode::BLOCKS_FIRST:order.push_back(1);break;- case ov::op::v0::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST:+ case v0::SpaceToDepth::SpaceToDepthMode::DEPTH_FIRST:order.insert(order.begin() + 1, 1);break;}@@ -81,19 +85,19 @@ ov::pass::ConvertSpaceToDepth::ConvertSpaceToDepth() {}shape_end.insert(shape_end.begin() + 1, C);- auto create_constant = [](std::vector<int64_t>& v) -> std::shared_ptr<ov::op::v0::Constant> {- return ov::op::v0::Constant::create(element::i64, Shape{v.size()}, v);+ auto create_constant = [](std::vector<int64_t>& v) -> std::shared_ptr<v0::Constant> {+ return v0::Constant::create(element::i64, Shape{v.size()}, v);};- auto reshape_begin = std::make_shared<ov::op::v1::Reshape>(input, create_constant(shape_begin), true);- auto transpose = std::make_shared<ov::op::v1::Transpose>(reshape_begin, create_constant(order));- auto reshape_end = std::make_shared<ov::op::v1::Reshape>(transpose, create_constant(shape_end), true);+ auto reshape_begin = std::make_shared<v1::Reshape>(input, create_constant(shape_begin), true);+ auto transpose = std::make_shared<v1::Transpose>(reshape_begin, create_constant(order));+ auto reshape_end = std::make_shared<v1::Reshape>(transpose, create_constant(shape_end), true);reshape_end->set_friendly_name(std_node->get_friendly_name());ov::copy_runtime_info(std_node, {reshape_begin, transpose, reshape_end});ov::replace_node(std_node, reshape_end);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(dts, matcher_name);+ auto m = std::make_shared<Matcher>(dts, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_squeeze15_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_squeeze15_downgrade.cppindex cdef96d2738..be1dc518568 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_squeeze15_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_squeeze15_downgrade.cpp@@ -11,13 +11,16 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v15 = ov::op::v15;ov::pass::ConvertSqueeze15ToSqueeze0::ConvertSqueeze15ToSqueeze0() {MATCHER_SCOPE(ConvertSqueeze15ToSqueeze0);- const auto& squeeze_v15_pattern = pattern::wrap_type<ov::op::v15::Squeeze>();+ const auto& squeeze_v15_pattern = ov::pass::pattern::wrap_type<v15::Squeeze>();- const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto& squeeze_v15 = ov::as_type_ptr<ov::op::v15::Squeeze>(m.get_match_root());+ const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ const auto& squeeze_v15 = ov::as_type_ptr<v15::Squeeze>(m.get_match_root());if (!squeeze_v15 || transformation_callback(squeeze_v15)) {return false;}@@ -36,6 +39,6 @@ ov::pass::ConvertSqueeze15ToSqueeze0::ConvertSqueeze15ToSqueeze0() {return true;};- auto m = std::make_shared<pattern::Matcher>(squeeze_v15_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(squeeze_v15_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_subtract.cpp b/src/common/transformations/src/transformations/op_conversions/convert_subtract.cppindex 25e8557e7af..483c1033e2d 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_subtract.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_subtract.cpp@@ -17,8 +17,14 @@using namespace ov;-static bool convert_subtract(const std::shared_ptr<Node>& node) {- auto sub = ov::as_type_ptr<ov::op::v1::Subtract>(node);+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++namespace {+bool convert_subtract(const std::shared_ptr<Node>& node) {+ auto sub = ov::as_type_ptr<v1::Subtract>(node);if (!sub) {return false;}@@ -31,9 +37,9 @@ static bool convert_subtract(const std::shared_ptr<Node>& node) {return false;}- std::shared_ptr<Node> neg = std::make_shared<ov::op::v1::Multiply>(- sub->input_value(1),- ov::op::v0::Constant::create(sub->get_input_element_type(1), Shape{}, {-1}));+ std::shared_ptr<Node> neg =+ std::make_shared<v1::Multiply>(sub->input_value(1),+ v0::Constant::create(sub->get_input_element_type(1), Shape{}, {-1}));NodeVector new_nodes;if (auto constant = ov::util::get_constant_from_source(neg)) {neg = constant;@@ -41,7 +47,7 @@ static bool convert_subtract(const std::shared_ptr<Node>& node) {new_nodes.push_back(neg);}- auto add = std::make_shared<ov::op::v1::Add>(sub->input_value(0), neg);+ auto add = std::make_shared<v1::Add>(sub->input_value(0), neg);new_nodes.push_back(add);add->set_friendly_name(sub->get_friendly_name());@@ -50,10 +56,11 @@ static bool convert_subtract(const std::shared_ptr<Node>& node) {return true;}+} // namespace-pass::ConvertSubtract::ConvertSubtract() {+ConvertSubtract::ConvertSubtract() {MATCHER_SCOPE(ConvertSubtract);- auto sub = pattern::wrap_type<ov::op::v1::Subtract>();+ auto sub = pattern::wrap_type<v1::Subtract>();matcher_pass_callback callback = [=](pattern::Matcher& m) {auto node = m.get_match_root();@@ -64,10 +71,9 @@ pass::ConvertSubtract::ConvertSubtract() {this->register_matcher(m, callback);}-pass::ConvertSubtractWithConstant::ConvertSubtractWithConstant() {+ConvertSubtractWithConstant::ConvertSubtractWithConstant() {MATCHER_SCOPE(ConvertSubtractWithConstant);- auto sub =- pattern::wrap_type<ov::op::v1::Subtract>({pattern::any_input(), pattern::wrap_type<ov::op::v0::Constant>()});+ auto sub = pattern::wrap_type<v1::Subtract>({pattern::any_input(), pattern::wrap_type<v0::Constant>()});matcher_pass_callback callback = [=](pattern::Matcher& m) {auto node = m.get_match_root();@@ -77,3 +83,5 @@ pass::ConvertSubtractWithConstant::ConvertSubtractWithConstant() {auto m = std::make_shared<pattern::Matcher>(sub, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/convert_ti_to_sequences.cpp b/src/common/transformations/src/transformations/op_conversions/convert_ti_to_sequences.cppindex 05474f93e61..3ce575535fb 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_ti_to_sequences.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_ti_to_sequences.cpp@@ -47,11 +47,22 @@using namespace ov;using namespace ov::pass;-using namespace ov::op::util;+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::rank_equals;+using ov::pass::pattern::wrap_type;+using ov::pass::pattern::op::Or;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v5 = ov::op::v5;+namespace op_util = ov::op::util;namespace {-bool convertTensorIteratorToSequence(const std::shared_ptr<ov::op::v0::TensorIterator>& ti,- const std::shared_ptr<ov::op::util::RNNCellBase>& found_cell,+bool convertTensorIteratorToSequence(const std::shared_ptr<v0::TensorIterator>& ti,+ const std::shared_ptr<op_util::RNNCellBase>& found_cell,const ov::Output<ov::Node>& data,const ov::Output<ov::Node>& h_pattern,const ov::Output<ov::Node>& c_pattern,@@ -62,7 +73,7 @@ bool convertTensorIteratorToSequence(const std::shared_ptr<ov::op::v0::TensorIteconst auto& func = ti->get_function();const auto& params = func->get_parameters();- std::vector<std::shared_ptr<ov::op::v0::TensorIterator::InputDescription>> ordered_in_descs(3);+ std::vector<std::shared_ptr<v0::TensorIterator::InputDescription>> ordered_in_descs(3);int64_t stride = 0, slice_axis = 0;// Remember the order of the X and initial_hidden_state (+ initial_cell_state in case of LSTM) in the TensorIterator@@ -70,7 +81,7 @@ bool convertTensorIteratorToSequence(const std::shared_ptr<ov::op::v0::TensorItefor (const auto& input_desc : ti->get_input_descriptions()) {auto param = params[input_desc->m_body_parameter_index];if (param == data.get_node_shared_ptr()) {- auto slice_input = ov::as_type_ptr<ov::op::v0::TensorIterator::SliceInputDescription>(input_desc);+ auto slice_input = ov::as_type_ptr<v0::TensorIterator::SliceInputDescription>(input_desc);if (!slice_input)return false;@@ -91,13 +102,13 @@ bool convertTensorIteratorToSequence(const std::shared_ptr<ov::op::v0::TensorIte}const auto& results = func->get_results();- std::vector<std::shared_ptr<ov::op::v0::TensorIterator::OutputDescription>> ordered_out_descs(3);+ std::vector<std::shared_ptr<v0::TensorIterator::OutputDescription>> ordered_out_descs(3);// Remember the order of cell outputs in the TensorIteratorfor (const auto& output_desc : ti->get_output_descriptions()) {- std::shared_ptr<ov::op::v0::Result> res = results[output_desc->m_body_value_index];+ std::shared_ptr<v0::Result> res = results[output_desc->m_body_value_index];if (res->input_value(0) == unsqueeze_after_cell) {- auto concat_output = ov::as_type_ptr<ov::op::v0::TensorIterator::ConcatOutputDescription>(output_desc);+ auto concat_output = ov::as_type_ptr<v0::TensorIterator::ConcatOutputDescription>(output_desc);if (!concat_output)return false;@@ -115,39 +126,37 @@ bool convertTensorIteratorToSequence(const std::shared_ptr<ov::op::v0::TensorIteconst auto ti_inputs = ti->input_values();auto X = ti_inputs[ordered_in_descs[0]->m_input_index];if (slice_axis == 0) {- auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, 0, 2});- X = std::make_shared<ov::op::v1::Transpose>(ti_inputs[ordered_in_descs[0]->m_input_index], order);+ auto order = v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, 0, 2});+ X = std::make_shared<v1::Transpose>(ti_inputs[ordered_in_descs[0]->m_input_index], order);}// We must prepare cell inputs to sequence creation: insert num_directions elem via unsqueeze where needed (please,// see specification)- auto axis_1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});- auto initial_hidden_state =- std::make_shared<ov::op::v0::Unsqueeze>(ti_inputs[ordered_in_descs[1]->m_input_index], axis_1);+ auto axis_1 = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});+ auto initial_hidden_state = std::make_shared<v0::Unsqueeze>(ti_inputs[ordered_in_descs[1]->m_input_index], axis_1);// LSTM casestd::shared_ptr<ov::Node> initial_cell_state =c_pattern.get_node_shared_ptr() == nullptr? nullptr- : std::make_shared<ov::op::v0::Unsqueeze>(ti_inputs[ordered_in_descs[2]->m_input_index], axis_1);-- auto shape_of = std::make_shared<ov::op::v3::ShapeOf>(X);- auto batch_dimension =- std::make_shared<ov::op::v1::Gather>(shape_of,- ov::op::v0::Constant::create(ov::element::i64, {1}, {0}),- ov::op::v0::Constant::create(ov::element::i64, {}, {0}));- auto seq_len_dim = std::make_shared<ov::op::v1::Gather>(shape_of,- ov::op::v0::Constant::create(ov::element::i64, {1}, {1}),- ov::op::v0::Constant::create(ov::element::i64, {}, {0}));- auto seq_lengths = std::make_shared<ov::op::v3::Broadcast>(seq_len_dim, batch_dimension);- auto axis_0 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {0});- auto W = ov::op::util::make_try_fold<ov::op::v0::Unsqueeze>(w_pattern, axis_0);- auto R = ov::op::util::make_try_fold<ov::op::v0::Unsqueeze>(r_pattern, axis_0);- auto B = ov::op::util::make_try_fold<ov::op::v0::Unsqueeze>(b_pattern, axis_0);+ : std::make_shared<v0::Unsqueeze>(ti_inputs[ordered_in_descs[2]->m_input_index], axis_1);++ auto shape_of = std::make_shared<v3::ShapeOf>(X);+ auto batch_dimension = std::make_shared<v1::Gather>(shape_of,+ v0::Constant::create(ov::element::i64, {1}, {0}),+ v0::Constant::create(ov::element::i64, {}, {0}));+ auto seq_len_dim = std::make_shared<v1::Gather>(shape_of,+ v0::Constant::create(ov::element::i64, {1}, {1}),+ v0::Constant::create(ov::element::i64, {}, {0}));+ auto seq_lengths = std::make_shared<v3::Broadcast>(seq_len_dim, batch_dimension);+ auto axis_0 = v0::Constant::create(ov::element::i64, ov::Shape{1}, {0});+ auto W = op_util::make_try_fold<v0::Unsqueeze>(w_pattern, axis_0);+ auto R = op_util::make_try_fold<v0::Unsqueeze>(r_pattern, axis_0);+ auto B = op_util::make_try_fold<v0::Unsqueeze>(b_pattern, axis_0);std::shared_ptr<ov::Node> sequence;- if (ov::is_type<ov::op::v4::LSTMCell>(found_cell) || ov::is_type<ov::op::v0::LSTMCell>(found_cell)) {- sequence = std::make_shared<ov::op::v5::LSTMSequence>(+ if (ov::is_type<v4::LSTMCell>(found_cell) || ov::is_type<v0::LSTMCell>(found_cell)) {+ sequence = std::make_shared<v5::LSTMSequence>(X,initial_hidden_state,initial_cell_state,@@ -161,8 +170,8 @@ bool convertTensorIteratorToSequence(const std::shared_ptr<ov::op::v0::TensorItefound_cell->get_activations_beta(),found_cell->get_activations(),found_cell->get_clip());- } else if (ov::is_type<ov::op::v0::RNNCell>(found_cell)) {- sequence = std::make_shared<ov::op::v5::RNNSequence>(+ } else if (ov::is_type<v0::RNNCell>(found_cell)) {+ sequence = std::make_shared<v5::RNNSequence>(X,initial_hidden_state,seq_lengths,@@ -175,9 +184,9 @@ bool convertTensorIteratorToSequence(const std::shared_ptr<ov::op::v0::TensorItefound_cell->get_activations_alpha(),found_cell->get_activations_beta(),found_cell->get_clip());- } else if (ov::is_type<ov::op::v3::GRUCell>(found_cell)) {- const auto gru_cell = ov::as_type_ptr<ov::op::v3::GRUCell>(found_cell);- sequence = std::make_shared<ov::op::v5::GRUSequence>(+ } else if (ov::is_type<v3::GRUCell>(found_cell)) {+ const auto gru_cell = ov::as_type_ptr<v3::GRUCell>(found_cell);+ sequence = std::make_shared<v5::GRUSequence>(X,initial_hidden_state,seq_lengths,@@ -197,22 +206,22 @@ bool convertTensorIteratorToSequence(const std::shared_ptr<ov::op::v0::TensorIteov::Output<ov::Node> out = sequence->output(0);if (slice_axis == 0) {- auto order = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {2, 1, 0, 3});- out = std::make_shared<ov::op::v1::Transpose>(out, order);+ auto order = v0::Constant::create(ov::element::i64, ov::Shape{4}, {2, 1, 0, 3});+ out = std::make_shared<v1::Transpose>(out, order);}ov::NodeVector outputs;// We must remove num_directions dimension that was added before sequence creation- auto axis_out = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});- auto out_0 = std::make_shared<ov::op::v0::Squeeze>(out, axis_out);- auto out_1 = std::make_shared<ov::op::v0::Squeeze>(sequence->output(1), axis_out);+ auto axis_out = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});+ auto out_0 = std::make_shared<v0::Squeeze>(out, axis_out);+ auto out_1 = std::make_shared<v0::Squeeze>(sequence->output(1), axis_out);out_0->set_friendly_name(ti->get_friendly_name() + ".0");out_1->set_friendly_name(ti->get_friendly_name() + ".1");outputs.emplace_back(out_0);outputs.emplace_back(out_1);if (sequence->get_output_size() == 3) {- auto out_2 = std::make_shared<ov::op::v0::Squeeze>(sequence->output(2), axis_out);+ auto out_2 = std::make_shared<v0::Squeeze>(sequence->output(2), axis_out);out_2->set_friendly_name(ti->get_friendly_name() + ".2");outputs.emplace_back(out_2);}@@ -253,34 +262,33 @@ bool check_condition_increment_pattern(const std::shared_ptr<op::v5::Loop>& loop,const ov::ParameterVector& body_params,const ov::ResultVector& body_results,- const ov::op::util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector& input_descriptions,+ const op_util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector& input_descriptions,Output<Node>& num_iters_output) {// return a number of iterations if pattern matches// pattern for condition sub-graph in Loop operarion- auto num_iter_const_label = pattern::wrap_type<op::v0::Constant>();- auto num_iter_param_label = pattern::wrap_type<op::v0::Parameter>();- auto num_iterations_label =- std::make_shared<pattern::op::Or>(OutputVector{num_iter_const_label, num_iter_param_label});- auto counter_label = pattern::wrap_type<op::v0::Parameter>();- auto counter_step_label = pattern::wrap_type<op::v0::Constant>();- auto updated_counter_label = pattern::wrap_type<op::v1::Add>({counter_label, counter_step_label});- auto less_label = pattern::wrap_type<op::v1::Less>({updated_counter_label, num_iterations_label});- auto condition_label = pattern::wrap_type<op::v0::Result>({less_label});+ auto num_iter_const_label = wrap_type<op::v0::Constant>();+ auto num_iter_param_label = wrap_type<op::v0::Parameter>();+ auto num_iterations_label = std::make_shared<Or>(OutputVector{num_iter_const_label, num_iter_param_label});+ auto counter_label = wrap_type<op::v0::Parameter>();+ auto counter_step_label = wrap_type<op::v0::Constant>();+ auto updated_counter_label = wrap_type<op::v1::Add>({counter_label, counter_step_label});+ auto less_label = wrap_type<op::v1::Less>({updated_counter_label, num_iterations_label});+ auto condition_label = wrap_type<op::v0::Result>({less_label});// check a pattern of condition graph and get a number of iterations- ov::pass::pattern::Matcher condition_matcher(condition_label);+ Matcher condition_matcher(condition_label);if (!condition_matcher.match(cond_result->output(0))) {return false;}const auto& condition_map = condition_matcher.get_pattern_value_map();int64_t counter_step = -1;- if (!get_constant_value(condition_map.at(counter_step_label).get_node_shared_ptr(), counter_step) ||+ if (!op_util::get_constant_value(condition_map.at(counter_step_label).get_node_shared_ptr(), counter_step) ||counter_step != 1) {return false;}// get initial value of counterint64_t initial_counter = -1;- auto counter_param = ov::as_type_ptr<ov::op::v0::Parameter>(condition_map.at(counter_label).get_node_shared_ptr());+ auto counter_param = ov::as_type_ptr<v0::Parameter>(condition_map.at(counter_label).get_node_shared_ptr());if (!counter_param) {return false;}@@ -291,7 +299,7 @@ bool check_condition_increment_pattern(continue;}// it must be merged input and incremented each iteration- auto merged_desc = ov::as_type_ptr<ov::op::util::MultiSubGraphOp::MergedInputDescription>(input_desc);+ auto merged_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::MergedInputDescription>(input_desc);if (!merged_desc) {return false;}@@ -301,7 +309,7 @@ bool check_condition_increment_pattern(return false;}// get initial value of counter- if (!get_constant_value(loop->input_value(input_idx).get_node_shared_ptr(), initial_counter)) {+ if (!op_util::get_constant_value(loop->input_value(input_idx).get_node_shared_ptr(), initial_counter)) {return false;}// suitable counter-parameter is found and checked@@ -324,11 +332,11 @@ bool check_condition_increment_pattern(break;}} else if (condition_map.count(num_iter_const_label)) {- if (!get_constant_value(condition_map.at(num_iter_const_label).get_node_shared_ptr(), num_iters) ||+ if (!op_util::get_constant_value(condition_map.at(num_iter_const_label).get_node_shared_ptr(), num_iters) ||num_iters < 1) {return false;}- num_iters_output = std::make_shared<ov::op::v0::Constant>(element::i64, Shape{}, num_iters);+ num_iters_output = std::make_shared<v0::Constant>(element::i64, Shape{}, num_iters);} else {return false;}@@ -340,11 +348,11 @@ bool check_condition_true_pattern(const std::shared_ptr<op::v0::Result>& cond_reconst std::shared_ptr<op::v5::Loop>& loop,Output<Node>& num_iters_output) {// return a number of iterations if pattern matches- auto cond_const_label = pattern::wrap_type<op::v0::Constant>();- auto condition_label = pattern::wrap_type<op::v0::Result>({cond_const_label});+ auto cond_const_label = wrap_type<op::v0::Constant>();+ auto condition_label = wrap_type<op::v0::Result>({cond_const_label});// check a pattern of condition graph and get a number of iterations- ov::pass::pattern::Matcher condition_matcher(condition_label);+ Matcher condition_matcher(condition_label);if (!condition_matcher.match(cond_result->output(0))) {return false;}@@ -352,7 +360,7 @@ bool check_condition_true_pattern(const std::shared_ptr<op::v0::Result>& cond_reconst auto& cond_const =ov::as_type_ptr<op::v0::Constant>(condition_map.at(cond_const_label).get_node_shared_ptr());bool cond_value = false;- if (!ov::op::util::get_constant_value(cond_const, cond_value) || !cond_value) {+ if (!op_util::get_constant_value(cond_const, cond_value) || !cond_value) {return false;}// number of iteration is retrieve from the first input port@@ -365,20 +373,20 @@ void create_mul_by_one_pattern(std::shared_ptr<Node>& param,std::shared_ptr<Node>& broadcast_value,std::shared_ptr<Node>& mul,bool with_first_squeeze = false) {- param = pattern::wrap_type<op::v0::Parameter>();+ param = wrap_type<op::v0::Parameter>();auto shape_of_input = param;if (with_first_squeeze) {- auto first_squeeze_axes = pattern::wrap_type<op::v0::Constant>();- shape_of_input = pattern::wrap_type<op::v0::Squeeze>({param, first_squeeze_axes});+ auto first_squeeze_axes = wrap_type<op::v0::Constant>();+ shape_of_input = wrap_type<op::v0::Squeeze>({param, first_squeeze_axes});}- auto shape_of = pattern::wrap_type<op::v3::ShapeOf>({shape_of_input});- auto concat_value = pattern::wrap_type<op::v0::Constant>();- auto concat = pattern::wrap_type<op::v0::Concat>({concat_value, shape_of});- broadcast_value = pattern::wrap_type<op::v0::Constant>();- auto broadcast = pattern::wrap_type<op::v3::Broadcast>({broadcast_value, concat});- auto squeeze_axes = pattern::wrap_type<op::v0::Constant>();- auto squeeze = pattern::wrap_type<op::v0::Squeeze>({broadcast, squeeze_axes});- mul = pattern::wrap_type<op::v1::Multiply>({shape_of_input, squeeze});+ auto shape_of = wrap_type<op::v3::ShapeOf>({shape_of_input});+ auto concat_value = wrap_type<op::v0::Constant>();+ auto concat = wrap_type<op::v0::Concat>({concat_value, shape_of});+ broadcast_value = wrap_type<op::v0::Constant>();+ auto broadcast = wrap_type<op::v3::Broadcast>({broadcast_value, concat});+ auto squeeze_axes = wrap_type<op::v0::Constant>();+ auto squeeze = wrap_type<op::v0::Squeeze>({broadcast, squeeze_axes});+ mul = wrap_type<op::v1::Multiply>({shape_of_input, squeeze});}bool check_const_one(const std::shared_ptr<Node>& node) {@@ -393,30 +401,29 @@ bool check_const_one(const std::shared_ptr<Node>& node) {return true;}-bool check_lstm_cell_pattern(- const std::shared_ptr<op::v5::Loop>& loop,- const ov::ParameterVector& body_params,- const ov::ResultVector& body_results,- const ov::op::util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector& input_descriptions,- ov::Output<Node>& init_hidden_state,- ov::Output<Node>& init_cell_state,- ov::Output<Node>& x,- ov::Output<Node>& W,- ov::Output<Node>& R,- ov::Output<Node>& B,- std::shared_ptr<op::v0::Result>& result_hidden_state,- std::shared_ptr<ov::op::v4::LSTMCell>& lstm_cell_node) {+bool check_lstm_cell_pattern(const std::shared_ptr<op::v5::Loop>& loop,+ const ov::ParameterVector& body_params,+ const ov::ResultVector& body_results,+ const op_util::MultiSubGraphOp::MultiSubgraphInputDescriptionVector& input_descriptions,+ ov::Output<Node>& init_hidden_state,+ ov::Output<Node>& init_cell_state,+ ov::Output<Node>& x,+ ov::Output<Node>& W,+ ov::Output<Node>& R,+ ov::Output<Node>& B,+ std::shared_ptr<op::v0::Result>& result_hidden_state,+ std::shared_ptr<v4::LSTMCell>& lstm_cell_node) {// check pattern with LSMCell and return key points// required for fusion to LSTMSequence// pattern for LSTMCell in the body- auto xi_label = pattern::wrap_type<op::v0::Parameter>();- auto squeeze_axis_label = pattern::wrap_type<op::v0::Constant>();- auto xi_reshape_label = pattern::wrap_type<op::v0::Squeeze>({xi_label, squeeze_axis_label});- auto init_hidden_state_i_label = pattern::wrap_type<op::v0::Parameter>();- auto init_cell_state_i_label = pattern::wrap_type<op::v0::Parameter>();- auto W_label = pattern::wrap_type<op::v0::Constant>();- auto R_label = pattern::wrap_type<op::v0::Constant>();- auto B_label = pattern::wrap_type<op::v0::Constant>();+ auto xi_label = wrap_type<op::v0::Parameter>();+ auto squeeze_axis_label = wrap_type<op::v0::Constant>();+ auto xi_reshape_label = wrap_type<op::v0::Squeeze>({xi_label, squeeze_axis_label});+ auto init_hidden_state_i_label = wrap_type<op::v0::Parameter>();+ auto init_cell_state_i_label = wrap_type<op::v0::Parameter>();+ auto W_label = wrap_type<op::v0::Constant>();+ auto R_label = wrap_type<op::v0::Constant>();+ auto B_label = wrap_type<op::v0::Constant>();// TODO: 152648 - remove this WA// create multiply by one pattern for x input@@ -426,17 +433,17 @@ bool check_lstm_cell_pattern(std::shared_ptr<Node> h_param, h_broadcast_value, h_mul;create_mul_by_one_pattern(h_param, h_broadcast_value, h_mul, false);- auto xi_common_label = std::make_shared<pattern::op::Or>(OutputVector{xi_reshape_label, x_mul});- auto hidden_common_label = std::make_shared<pattern::op::Or>(OutputVector{init_hidden_state_i_label, h_mul});+ auto xi_common_label = std::make_shared<Or>(OutputVector{xi_reshape_label, x_mul});+ auto hidden_common_label = std::make_shared<Or>(OutputVector{init_hidden_state_i_label, h_mul});- auto lstm_cell_label = pattern::wrap_type<op::v4::LSTMCell>(+ auto lstm_cell_label = wrap_type<op::v4::LSTMCell>({xi_common_label, hidden_common_label, init_cell_state_i_label, W_label, R_label, B_label});- auto unsqueeze_axis_label = pattern::wrap_type<op::v0::Constant>();- auto unsqueeze_hidden_state_label = pattern::wrap_type<op::v0::Unsqueeze>({lstm_cell_label, unsqueeze_axis_label});- auto result_hidden_state_label = pattern::wrap_type<op::v0::Result>({unsqueeze_hidden_state_label});+ auto unsqueeze_axis_label = wrap_type<op::v0::Constant>();+ auto unsqueeze_hidden_state_label = wrap_type<op::v0::Unsqueeze>({lstm_cell_label, unsqueeze_axis_label});+ auto result_hidden_state_label = wrap_type<op::v0::Result>({unsqueeze_hidden_state_label});// check that body-graph contains a pattern corresponding LSTMCell- ov::pass::pattern::Matcher lstm_cell_matcher(result_hidden_state_label);+ Matcher lstm_cell_matcher(result_hidden_state_label);int64_t unsqueeze_hidden_state_result_idx = -1;for (int64_t result_idx = 0; result_idx < static_cast<int64_t>(body_results.size()); ++result_idx) {if (lstm_cell_matcher.match(body_results[result_idx]->output(0))) {@@ -485,7 +492,7 @@ bool check_lstm_cell_pattern(auto input_idx = input_desc->m_input_index;if (body_params[param_idx] == lstm_cell_map.at(init_hidden_state_i_label).get_node_shared_ptr()) {// hidden state Parameter node- auto merged_desc = ov::as_type_ptr<ov::op::util::MultiSubGraphOp::MergedInputDescription>(input_desc);+ auto merged_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::MergedInputDescription>(input_desc);if (!merged_desc) {return false;}@@ -497,7 +504,7 @@ bool check_lstm_cell_pattern(init_hidden_state = loop->input_value(input_idx);} else if (body_params[param_idx] == lstm_cell_map.at(init_cell_state_i_label).get_node_shared_ptr()) {// cell state Parameter node- auto merged_desc = ov::as_type_ptr<ov::op::util::MultiSubGraphOp::MergedInputDescription>(input_desc);+ auto merged_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::MergedInputDescription>(input_desc);if (!merged_desc) {return false;}@@ -509,7 +516,7 @@ bool check_lstm_cell_pattern(init_cell_state = loop->input_value(input_idx);} else if (body_params[param_idx] == lstm_cell_map.at(xi_label).get_node_shared_ptr()) {// input data Parameter node- auto sliced_desc = ov::as_type_ptr<ov::op::util::MultiSubGraphOp::SliceInputDescription>(input_desc);+ auto sliced_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::SliceInputDescription>(input_desc);if (!sliced_desc || (sliced_desc->m_axis != 0) || (sliced_desc->m_start != 0) ||(sliced_desc->m_stride != 1) || (sliced_desc->m_end != -1)) {return false;@@ -528,30 +535,30 @@ bool check_lstm_cell_pattern(ov::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSequence() {MATCHER_SCOPE(ConvertTensorIteratorToLSTMSequence);- auto tensor_iterator = pattern::wrap_type<ov::op::v0::TensorIterator>();+ auto tensor_iterator = wrap_type<v0::TensorIterator>();- matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto ti = ov::as_type_ptr<ov::op::v0::TensorIterator>(m.get_match_root());+ matcher_pass_callback callback = [this](Matcher& m) {+ auto ti = ov::as_type_ptr<v0::TensorIterator>(m.get_match_root());if (!ti || transformation_callback(ti))return false;// create a pattern for the TensorIterator body- auto data = ov::pass::pattern::wrap_type<ov::op::v0::Parameter>(ov::pass::pattern::rank_equals(3));- auto pattern_1 = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(1));- auto squeeze = ov::pass::pattern::wrap_type<ov::op::v1::Reshape, ov::op::v0::Squeeze>({data, pattern_1});+ auto data = wrap_type<v0::Parameter>(rank_equals(3));+ auto pattern_1 = wrap_type<v0::Constant>(rank_equals(1));+ auto squeeze = wrap_type<v1::Reshape, v0::Squeeze>({data, pattern_1});- auto input_H_state = ov::pass::pattern::wrap_type<ov::op::v0::Parameter>(ov::pass::pattern::rank_equals(2));- auto input_C_state = ov::pass::pattern::wrap_type<ov::op::v0::Parameter>(ov::pass::pattern::rank_equals(2));- auto input_W = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(2));- auto input_R = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(2));- auto input_B = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(1));+ auto input_H_state = wrap_type<v0::Parameter>(rank_equals(2));+ auto input_C_state = wrap_type<v0::Parameter>(rank_equals(2));+ auto input_W = wrap_type<v0::Constant>(rank_equals(2));+ auto input_R = wrap_type<v0::Constant>(rank_equals(2));+ auto input_B = wrap_type<v0::Constant>(rank_equals(1));ov::OutputVector cell_inputs{squeeze, input_H_state, input_C_state, input_W, input_R, input_B};- auto cell = ov::pass::pattern::wrap_type<ov::op::v0::LSTMCell, ov::op::v4::LSTMCell>(cell_inputs);+ auto cell = wrap_type<v0::LSTMCell, v4::LSTMCell>(cell_inputs);- auto pattern_2 = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(1));- auto unsqueeze = ov::pass::pattern::wrap_type<ov::op::v1::Reshape, ov::op::v0::Unsqueeze>({cell, pattern_2});- ov::pass::pattern::Matcher matcher(unsqueeze);+ auto pattern_2 = wrap_type<v0::Constant>(rank_equals(1));+ auto unsqueeze = wrap_type<v1::Reshape, v0::Unsqueeze>({cell, pattern_2});+ Matcher matcher(unsqueeze);bool match = false;auto func = ti->get_body();@@ -567,7 +574,7 @@ ov::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSequenconst auto& pattern_map = matcher.get_pattern_value_map();std::shared_ptr<Node> found_cell = pattern_map.at(cell).get_node_shared_ptr();- const auto lstm_cell = ov::as_type_ptr<ov::op::util::RNNCellBase>(found_cell);+ const auto lstm_cell = ov::as_type_ptr<op_util::RNNCellBase>(found_cell);if (lstm_cell == nullptr)return false;@@ -582,35 +589,35 @@ ov::pass::ConvertTensorIteratorToLSTMSequence::ConvertTensorIteratorToLSTMSequenpattern_map.at(unsqueeze));};- auto m = std::make_shared<ov::pass::pattern::Matcher>(tensor_iterator, matcher_name);+ auto m = std::make_shared<Matcher>(tensor_iterator, matcher_name);register_matcher(m, callback);}ov::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequence() {MATCHER_SCOPE(ConvertTensorIteratorToRNNSequence);- auto tensor_iterator = pattern::wrap_type<ov::op::v0::TensorIterator>();+ auto tensor_iterator = wrap_type<v0::TensorIterator>();- matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto ti = ov::as_type_ptr<ov::op::v0::TensorIterator>(m.get_match_root());+ matcher_pass_callback callback = [this](Matcher& m) {+ auto ti = ov::as_type_ptr<v0::TensorIterator>(m.get_match_root());if (!ti || transformation_callback(ti))return false;// create a pattern for the TensorIterator body- auto data = ov::pass::pattern::wrap_type<ov::op::v0::Parameter>(ov::pass::pattern::rank_equals(3));- auto pattern_1 = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(1));- auto squeeze = ov::pass::pattern::wrap_type<ov::op::v1::Reshape, ov::op::v0::Squeeze>({data, pattern_1});+ auto data = wrap_type<v0::Parameter>(rank_equals(3));+ auto pattern_1 = wrap_type<v0::Constant>(rank_equals(1));+ auto squeeze = wrap_type<v1::Reshape, v0::Squeeze>({data, pattern_1});- auto input_H_state = ov::pass::pattern::wrap_type<ov::op::v0::Parameter>(ov::pass::pattern::rank_equals(2));- auto input_W = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(2));- auto input_R = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(2));- auto input_B = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(1));+ auto input_H_state = wrap_type<v0::Parameter>(rank_equals(2));+ auto input_W = wrap_type<v0::Constant>(rank_equals(2));+ auto input_R = wrap_type<v0::Constant>(rank_equals(2));+ auto input_B = wrap_type<v0::Constant>(rank_equals(1));ov::OutputVector cell_inputs{squeeze, input_H_state, input_W, input_R, input_B};- auto cell = ov::pass::pattern::wrap_type<ov::op::v0::RNNCell>(cell_inputs);+ auto cell = wrap_type<v0::RNNCell>(cell_inputs);- auto pattern_2 = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(1));- auto unsqueeze = ov::pass::pattern::wrap_type<ov::op::v1::Reshape, ov::op::v0::Unsqueeze>({cell, pattern_2});- ov::pass::pattern::Matcher matcher(unsqueeze);+ auto pattern_2 = wrap_type<v0::Constant>(rank_equals(1));+ auto unsqueeze = wrap_type<v1::Reshape, v0::Unsqueeze>({cell, pattern_2});+ Matcher matcher(unsqueeze);bool match = false;auto func = ti->get_body();@@ -625,7 +632,7 @@ ov::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequencereturn false;const auto& pattern_map = matcher.get_pattern_value_map();- const auto& rnn_cell = ov::as_type_ptr<ov::op::v0::RNNCell>(pattern_map.at(cell).get_node_shared_ptr());+ const auto& rnn_cell = ov::as_type_ptr<v0::RNNCell>(pattern_map.at(cell).get_node_shared_ptr());if (rnn_cell == nullptr)return false;@@ -640,36 +647,36 @@ ov::pass::ConvertTensorIteratorToRNNSequence::ConvertTensorIteratorToRNNSequencepattern_map.at(unsqueeze));};- auto m = std::make_shared<ov::pass::pattern::Matcher>(tensor_iterator, matcher_name);+ auto m = std::make_shared<Matcher>(tensor_iterator, matcher_name);register_matcher(m, callback);}ov::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequence() {MATCHER_SCOPE(ConvertTensorIteratorToGRUSequence);- auto tensor_iterator = pattern::wrap_type<ov::op::v0::TensorIterator>();+ auto tensor_iterator = wrap_type<v0::TensorIterator>();- matcher_pass_callback callback = [this](pattern::Matcher& m) {- auto ti = ov::as_type_ptr<ov::op::v0::TensorIterator>(m.get_match_root());+ matcher_pass_callback callback = [this](Matcher& m) {+ auto ti = ov::as_type_ptr<v0::TensorIterator>(m.get_match_root());if (!ti || transformation_callback(ti))return false;// create a pattern for the TensorIterator body- auto data = ov::pass::pattern::wrap_type<ov::op::v0::Parameter>(ov::pass::pattern::rank_equals(3));- auto pattern_1 = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(1));- auto squeeze = ov::pass::pattern::wrap_type<ov::op::v1::Reshape, ov::op::v0::Squeeze>({data, pattern_1});+ auto data = wrap_type<v0::Parameter>(rank_equals(3));+ auto pattern_1 = wrap_type<v0::Constant>(rank_equals(1));+ auto squeeze = wrap_type<v1::Reshape, v0::Squeeze>({data, pattern_1});- auto input_H_state = ov::pass::pattern::wrap_type<ov::op::v0::Parameter>(ov::pass::pattern::rank_equals(2));- auto input_W = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(2));- auto input_R = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(2));- auto input_B = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(1));+ auto input_H_state = wrap_type<v0::Parameter>(rank_equals(2));+ auto input_W = wrap_type<v0::Constant>(rank_equals(2));+ auto input_R = wrap_type<v0::Constant>(rank_equals(2));+ auto input_B = wrap_type<v0::Constant>(rank_equals(1));ov::OutputVector cell_inputs{squeeze, input_H_state, input_W, input_R, input_B};- auto cell = ov::pass::pattern::wrap_type<ov::op::v3::GRUCell>(cell_inputs);+ auto cell = wrap_type<v3::GRUCell>(cell_inputs);- auto pattern_2 = ov::pass::pattern::wrap_type<ov::op::v0::Constant>(ov::pass::pattern::rank_equals(1));- auto unsqueeze = ov::pass::pattern::wrap_type<ov::op::v1::Reshape, ov::op::v0::Unsqueeze>({cell, pattern_2});+ auto pattern_2 = wrap_type<v0::Constant>(rank_equals(1));+ auto unsqueeze = wrap_type<v1::Reshape, v0::Unsqueeze>({cell, pattern_2});- ov::pass::pattern::Matcher matcher(unsqueeze);+ Matcher matcher(unsqueeze);bool match = false;auto func = ti->get_body();@@ -684,7 +691,7 @@ ov::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequencereturn false;const auto& pattern_map = matcher.get_pattern_value_map();- const auto& gru_cell = ov::as_type_ptr<ov::op::v3::GRUCell>(pattern_map.at(cell).get_node_shared_ptr());+ const auto& gru_cell = ov::as_type_ptr<v3::GRUCell>(pattern_map.at(cell).get_node_shared_ptr());if (gru_cell == nullptr)return false;@@ -699,7 +706,7 @@ ov::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequencepattern_map.at(unsqueeze));};- auto m = std::make_shared<ov::pass::pattern::Matcher>(tensor_iterator, matcher_name);+ auto m = std::make_shared<Matcher>(tensor_iterator, matcher_name);register_matcher(m, callback);}@@ -780,76 +787,65 @@ ov::pass::ConvertTensorIteratorToGRUSequence::ConvertTensorIteratorToGRUSequenceov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpdateToLSTMSequence() {MATCHER_SCOPE(ConvertLoopWithScatterUpdateToLSTMSequence);- auto input_label = pattern::any_input(pattern::rank_equals(3));- auto input_transpose_const_label = pattern::wrap_type<op::v0::Constant>();+ auto input_label = any_input(rank_equals(3));+ auto input_transpose_const_label = wrap_type<op::v0::Constant>();auto input_transpose_label =- pattern::wrap_type<op::v1::Transpose, op::v1::Reshape>({input_label, input_transpose_const_label},- pattern::rank_equals(3));- auto scatter_indexes_label = pattern::wrap_type<op::v0::Constant>();- auto scatter_update_label = std::make_shared<pattern::op::Or>(OutputVector{input_transpose_label, input_label});- auto scatter_label = pattern::wrap_type<op::v3::ScatterNDUpdate>(- {pattern::any_input(), scatter_indexes_label, scatter_update_label});- auto trip_count_label = pattern::wrap_type<op::v0::Constant>();- auto cond_label = pattern::wrap_type<op::v0::Constant>();- auto loop_label = pattern::wrap_type<op::v5::Loop>({trip_count_label,- cond_label,- pattern::any_input(),- pattern::any_input(),- pattern::any_input(),- pattern::any_input(),- pattern::any_input(),- scatter_label});- auto output_transpose_const_label = pattern::wrap_type<op::v0::Constant>();- auto output_transpose_label = pattern::wrap_type<op::v1::Transpose>({loop_label, output_transpose_const_label});+ wrap_type<op::v1::Transpose, op::v1::Reshape>({input_label, input_transpose_const_label}, rank_equals(3));+ auto scatter_indexes_label = wrap_type<op::v0::Constant>();+ auto scatter_update_label = std::make_shared<Or>(OutputVector{input_transpose_label, input_label});+ auto scatter_label = wrap_type<op::v3::ScatterNDUpdate>({any_input(), scatter_indexes_label, scatter_update_label});+ auto trip_count_label = wrap_type<op::v0::Constant>();+ auto cond_label = wrap_type<op::v0::Constant>();+ auto loop_label = wrap_type<op::v5::Loop>(+ {trip_count_label, cond_label, any_input(), any_input(), any_input(), any_input(), any_input(), scatter_label});+ auto output_transpose_const_label = wrap_type<op::v0::Constant>();+ auto output_transpose_label = wrap_type<op::v1::Transpose>({loop_label, output_transpose_const_label});// Loop body pattern:- auto sequence_index_label = pattern::any_input(pattern::rank_equals(0));- auto iteration_counter_label = pattern::any_input();- auto iteration_counter_step_label = pattern::wrap_type<op::v0::Constant>();+ auto sequence_index_label = any_input(rank_equals(0));+ auto iteration_counter_label = any_input();+ auto iteration_counter_step_label = wrap_type<op::v0::Constant>();auto iteration_counter_incremented_label =- pattern::wrap_type<op::v1::Add>({iteration_counter_label, iteration_counter_step_label});- auto iteration_counter_limit_label = pattern::wrap_type<op::v0::Constant>();+ wrap_type<op::v1::Add>({iteration_counter_label, iteration_counter_step_label});+ auto iteration_counter_limit_label = wrap_type<op::v0::Constant>();auto iteration_counter_less_than_limit_label =- pattern::wrap_type<op::v1::Less>({iteration_counter_incremented_label, iteration_counter_limit_label});- auto sequence_index_step_label = pattern::wrap_type<op::v0::Constant>();- auto sequence_index_incremented_label =- pattern::wrap_type<op::v1::Add>({sequence_index_label, sequence_index_step_label});- auto sequence_index_limit_label = pattern::wrap_type<op::v0::Constant>();+ wrap_type<op::v1::Less>({iteration_counter_incremented_label, iteration_counter_limit_label});+ auto sequence_index_step_label = wrap_type<op::v0::Constant>();+ auto sequence_index_incremented_label = wrap_type<op::v1::Add>({sequence_index_label, sequence_index_step_label});+ auto sequence_index_limit_label = wrap_type<op::v0::Constant>();auto sequence_index_less_than_limit_label =- pattern::wrap_type<op::v1::Less>({sequence_index_incremented_label, sequence_index_limit_label});- auto and_label = pattern::wrap_type<op::v1::LogicalAnd>(- {iteration_counter_less_than_limit_label, sequence_index_less_than_limit_label});- auto loop_condition_label = pattern::wrap_type<op::v0::Result>({and_label});-- auto X_body_label = pattern::any_input(pattern::rank_equals(3));- auto C_body_label = pattern::any_input(pattern::rank_equals(2));- auto H_body_label = pattern::any_input(pattern::rank_equals(2));- auto gather_axis_label = pattern::wrap_type<op::v0::Constant>();- auto sequence_index_new_shape_label = pattern::wrap_type<op::v0::Constant>();+ wrap_type<op::v1::Less>({sequence_index_incremented_label, sequence_index_limit_label});+ auto and_label =+ wrap_type<op::v1::LogicalAnd>({iteration_counter_less_than_limit_label, sequence_index_less_than_limit_label});+ auto loop_condition_label = wrap_type<op::v0::Result>({and_label});++ auto X_body_label = any_input(rank_equals(3));+ auto C_body_label = any_input(rank_equals(2));+ auto H_body_label = any_input(rank_equals(2));+ auto gather_axis_label = wrap_type<op::v0::Constant>();+ auto sequence_index_new_shape_label = wrap_type<op::v0::Constant>();auto sequence_index_reshaped_label =- pattern::wrap_type<op::v1::Reshape>({sequence_index_label, sequence_index_new_shape_label});+ wrap_type<op::v1::Reshape>({sequence_index_label, sequence_index_new_shape_label});auto sequence_index_or_label =- std::make_shared<pattern::op::Or>(OutputVector{sequence_index_label, sequence_index_reshaped_label});+ std::make_shared<Or>(OutputVector{sequence_index_label, sequence_index_reshaped_label});auto gather_body_label =- pattern::wrap_type<ov::op::v8::Gather>({X_body_label, sequence_index_or_label, gather_axis_label},- pattern::rank_equals(2));- auto W_label = pattern::any_input();- auto R_label = pattern::any_input();- auto B_label = pattern::wrap_type<op::v0::Constant>();- auto lstm_cell_label = pattern::wrap_type<ov::op::v4::LSTMCell>(- {gather_body_label, H_body_label, C_body_label, W_label, R_label, B_label});- auto scatter_index_new_shape_label = pattern::wrap_type<op::v0::Constant>();- auto scatter_index_body_label =- pattern::wrap_type<op::v1::Reshape>({sequence_index_label, scatter_index_new_shape_label});- auto updates_label = pattern::wrap_type<op::v1::Reshape, op::v0::Unsqueeze>(- {lstm_cell_label, pattern::wrap_type<op::v0::Constant>()});- auto scatter_axis_label = pattern::wrap_type<op::v0::Constant>();- auto scatter_body_label = pattern::wrap_type<op::v3::ScatterUpdate>(- {pattern::any_input(), scatter_index_body_label, updates_label, scatter_axis_label},- pattern::rank_equals(3));- auto loop_output_label = pattern::wrap_type<op::v0::Result>({scatter_body_label});-- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ wrap_type<ov::op::v8::Gather>({X_body_label, sequence_index_or_label, gather_axis_label}, rank_equals(2));+ auto W_label = any_input();+ auto R_label = any_input();+ auto B_label = wrap_type<op::v0::Constant>();+ auto lstm_cell_label =+ wrap_type<v4::LSTMCell>({gather_body_label, H_body_label, C_body_label, W_label, R_label, B_label});+ auto scatter_index_new_shape_label = wrap_type<op::v0::Constant>();+ auto scatter_index_body_label = wrap_type<op::v1::Reshape>({sequence_index_label, scatter_index_new_shape_label});+ auto updates_label =+ wrap_type<op::v1::Reshape, op::v0::Unsqueeze>({lstm_cell_label, wrap_type<op::v0::Constant>()});+ auto scatter_axis_label = wrap_type<op::v0::Constant>();+ auto scatter_body_label =+ wrap_type<op::v3::ScatterUpdate>({any_input(), scatter_index_body_label, updates_label, scatter_axis_label},+ rank_equals(3));+ auto loop_output_label = wrap_type<op::v0::Result>({scatter_body_label});++ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();auto match_root = m.get_match_root();@@ -857,13 +853,12 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpdaconst auto& output_descs = loop->get_output_descriptions();if (output_descs.size() != 1)return false;- const auto body_output_desc =- ov::as_type_ptr<op::util::MultiSubGraphOp::BodyOutputDescription>(output_descs[0]);+ const auto body_output_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::BodyOutputDescription>(output_descs[0]);if (!body_output_desc || body_output_desc->m_iteration != -1)return false;- ov::pass::pattern::Matcher loop_condition_matcher(loop_condition_label);- ov::pass::pattern::Matcher loop_output_matcher(loop_output_label);+ Matcher loop_condition_matcher(loop_condition_label);+ Matcher loop_output_matcher(loop_output_label);auto body = loop->get_function();const auto& body_parameters = body->get_parameters();@@ -879,33 +874,33 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpdaconst auto& loop_output_map = loop_output_matcher.get_pattern_value_map();int64_t iteration_counter_step = -1;- if (!get_constant_value(loop_condition_map.at(iteration_counter_step_label).get_node_shared_ptr(),- iteration_counter_step) ||+ if (!op_util::get_constant_value(loop_condition_map.at(iteration_counter_step_label).get_node_shared_ptr(),+ iteration_counter_step) ||iteration_counter_step != 1)return false;int64_t sequence_index_step = -1;- if (!get_constant_value(loop_condition_map.at(sequence_index_step_label).get_node_shared_ptr(),- sequence_index_step) ||+ if (!op_util::get_constant_value(loop_condition_map.at(sequence_index_step_label).get_node_shared_ptr(),+ sequence_index_step) ||sequence_index_step != 1)return false;int64_t iteration_counter_limit = -1;- if (!get_constant_value(loop_condition_map.at(iteration_counter_limit_label).get_node_shared_ptr(),- iteration_counter_limit))+ if (!op_util::get_constant_value(loop_condition_map.at(iteration_counter_limit_label).get_node_shared_ptr(),+ iteration_counter_limit))return false;int64_t sequence_index_limit = -1;- if (!get_constant_value(loop_condition_map.at(sequence_index_limit_label).get_node_shared_ptr(),- sequence_index_limit))+ if (!op_util::get_constant_value(loop_condition_map.at(sequence_index_limit_label).get_node_shared_ptr(),+ sequence_index_limit))return false;if (iteration_counter_limit != sequence_index_limit)return false;int64_t gather_axis = -1;- if (!get_constant_value(loop_output_map.at(gather_axis_label).get_node_shared_ptr(), gather_axis) ||+ if (!op_util::get_constant_value(loop_output_map.at(gather_axis_label).get_node_shared_ptr(), gather_axis) ||gather_axis != 0)return false;int64_t scatter_axis = -1;- if (!get_constant_value(loop_output_map.at(scatter_axis_label).get_node_shared_ptr(), scatter_axis) ||+ if (!op_util::get_constant_value(loop_output_map.at(scatter_axis_label).get_node_shared_ptr(), scatter_axis) ||scatter_axis != 0)return false;@@ -931,7 +926,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpdaconst auto& input_descs = loop->get_input_descriptions();for (const auto& desc : input_descs) {if (body_parameters[desc->m_body_parameter_index] == X_body) {- if (!ov::as_type_ptr<op::util::MultiSubGraphOp::InvariantInputDescription>(desc)) {+ if (!ov::as_type_ptr<op_util::MultiSubGraphOp::InvariantInputDescription>(desc)) {return false;}if (loop->input_value(desc->m_input_index) != pattern_map.at(scatter_label)) {@@ -939,7 +934,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpda}}if (body_parameters[desc->m_body_parameter_index] == H_body) {- auto merged_desc = ov::as_type_ptr<op::util::MultiSubGraphOp::MergedInputDescription>(desc);+ auto merged_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::MergedInputDescription>(desc);if (!merged_desc) {return false;}@@ -950,7 +945,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpda}}if (body_parameters[desc->m_body_parameter_index] == C_body) {- auto merged_desc = ov::as_type_ptr<op::util::MultiSubGraphOp::MergedInputDescription>(desc);+ auto merged_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::MergedInputDescription>(desc);if (!merged_desc) {return false;}@@ -961,13 +956,13 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpda}}if (body_parameters[desc->m_body_parameter_index] == sequence_index) {- auto merged_desc = ov::as_type_ptr<op::util::MultiSubGraphOp::MergedInputDescription>(desc);+ auto merged_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::MergedInputDescription>(desc);if (!merged_desc) {return false;}}if (body_parameters[desc->m_body_parameter_index] == iteration_counter) {- auto merged_desc = ov::as_type_ptr<op::util::MultiSubGraphOp::MergedInputDescription>(desc);+ auto merged_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::MergedInputDescription>(desc);if (!merged_desc) {return false;}@@ -980,7 +975,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpdareturn false;}float value = -1.0f;- return ov::op::util::get_single_value(constant, value) && value == 0.0f;+ return op_util::get_single_value(constant, value) && value == 0.0f;};if (!constant_is_zero(H))@@ -1084,7 +1079,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpdafor (auto&& loop_consumer : loop->output(0).get_target_inputs()) {auto node = loop_consumer.get_node()->shared_from_this();- if (ov::is_type<op::util::ShapeOfBase>(node)) {+ if (ov::is_type<op_util::ShapeOfBase>(node)) {auto shapeof = std::make_shared<op::v3::ShapeOf>(H_squeezed);auto indices = op::v0::Constant::create(element::i32, Shape{3}, {1, 0, 2});auto shapeof_gather = std::make_shared<op::v8::Gather>(shapeof, indices, zero);@@ -1099,7 +1094,7 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpdareturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(output_transpose_label, matcher_name);+ auto m = std::make_shared<Matcher>(output_transpose_label, matcher_name);register_matcher(m, callback);}@@ -1154,10 +1149,10 @@ ov::pass::ConvertLoopWithScatterUpdateToLSTMSequence::ConvertLoopWithScatterUpdaov::pass::ConvertLoopWithSlicedInputConcatOutputToLSTMSequence::ConvertLoopWithSlicedInputConcatOutputToLSTMSequence() {MATCHER_SCOPE(ConvertLoopWithSlicedInputConcatOutputToLSTMSequence);- auto loop_label = pattern::wrap_type<ov::op::v5::Loop>();+ auto loop_label = wrap_type<v5::Loop>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- auto loop = ov::as_type_ptr<ov::op::v5::Loop>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto loop = ov::as_type_ptr<v5::Loop>(m.get_match_root());if (!loop) {return false;}@@ -1190,7 +1185,7 @@ ov::pass::ConvertLoopWithSlicedInputConcatOutputToLSTMSequence::ConvertLoopWithS// and extract key points for LSTMSequence creationov::Output<Node> init_hidden_state, init_cell_state, x, W, R, B;std::shared_ptr<op::v0::Result> result_hidden_state;- std::shared_ptr<ov::op::v4::LSTMCell> lstm_cell_node;+ std::shared_ptr<v4::LSTMCell> lstm_cell_node;if (!check_lstm_cell_pattern(loop,body_params,body_results,@@ -1220,7 +1215,7 @@ ov::pass::ConvertLoopWithSlicedInputConcatOutputToLSTMSequence::ConvertLoopWithS}continue;}- auto concat_desc = ov::as_type_ptr<ov::op::util::MultiSubGraphOp::ConcatOutputDescription>(output_desc);+ auto concat_desc = ov::as_type_ptr<op_util::MultiSubGraphOp::ConcatOutputDescription>(output_desc);if (concat_desc) {// all hidden states are concatenatedif ((concat_desc->m_axis != 0) || (concat_desc->m_start != 0) || (concat_desc->m_end != -1) ||@@ -1237,47 +1232,47 @@ ov::pass::ConvertLoopWithSlicedInputConcatOutputToLSTMSequence::ConvertLoopWithS// preparation of the right format of inputs and outputs is remained before reconnectionNodeRegistry rg;// x is in a format [seq_len, batch_size, input_size]- auto tr_order = rg.make<ov::op::v0::Constant>(element::i32, Shape{3}, std::vector<int32_t>{1, 0, 2});- auto x_prep = rg.make<ov::op::v1::Transpose>(x, tr_order);+ auto tr_order = rg.make<v0::Constant>(element::i32, Shape{3}, std::vector<int32_t>{1, 0, 2});+ auto x_prep = rg.make<v1::Transpose>(x, tr_order);// initial hidden and cell states are of shape [batch_size, hidden_size]// needs to add num_directions size- auto unsqueeze_axis = rg.make<ov::op::v0::Constant>(element::i32, Shape{1}, std::vector<int32_t>{1});- auto init_hidden_state_prep = rg.make<ov::op::v0::Unsqueeze>(init_hidden_state, unsqueeze_axis);- auto init_cell_state_prep = rg.make<ov::op::v0::Unsqueeze>(init_cell_state, unsqueeze_axis);+ auto unsqueeze_axis = rg.make<v0::Constant>(element::i32, Shape{1}, std::vector<int32_t>{1});+ auto init_hidden_state_prep = rg.make<v0::Unsqueeze>(init_hidden_state, unsqueeze_axis);+ auto init_cell_state_prep = rg.make<v0::Unsqueeze>(init_cell_state, unsqueeze_axis);// sequence length is currently scalar and it needs broadcasting to shape [batch_size]- auto x_shape = rg.make<ov::op::v3::ShapeOf>(x, element::i64);- auto ss_start = rg.make<ov::op::v0::Constant>(element::i64, Shape{1}, 1);- auto ss_stop = rg.make<ov::op::v0::Constant>(element::i64, Shape{1}, 2);- auto ss_step = rg.make<ov::op::v0::Constant>(element::i64, Shape{1}, 1);- auto batch_size = rg.make<ov::op::v1::StridedSlice>(x_shape,- ss_start,- ss_stop,- ss_step,- std::vector<int64_t>{0},- std::vector<int64_t>{0});- auto seq_lens_prep = rg.make<ov::op::v1::Broadcast>(num_iters_output, batch_size);+ auto x_shape = rg.make<v3::ShapeOf>(x, element::i64);+ auto ss_start = rg.make<v0::Constant>(element::i64, Shape{1}, 1);+ auto ss_stop = rg.make<v0::Constant>(element::i64, Shape{1}, 2);+ auto ss_step = rg.make<v0::Constant>(element::i64, Shape{1}, 1);+ auto batch_size = rg.make<v1::StridedSlice>(x_shape,+ ss_start,+ ss_stop,+ ss_step,+ std::vector<int64_t>{0},+ std::vector<int64_t>{0});+ auto seq_lens_prep = rg.make<v1::Broadcast>(num_iters_output, batch_size);// prepare W, R, B to add num_directions dimension- unsqueeze_axis = rg.make<ov::op::v0::Constant>(element::i32, Shape{1}, std::vector<int32_t>{0});- auto W_prep = rg.make<ov::op::v0::Unsqueeze>(W, unsqueeze_axis);- auto R_prep = rg.make<ov::op::v0::Unsqueeze>(R, unsqueeze_axis);- auto B_prep = rg.make<ov::op::v0::Unsqueeze>(B, unsqueeze_axis);+ unsqueeze_axis = rg.make<v0::Constant>(element::i32, Shape{1}, std::vector<int32_t>{0});+ auto W_prep = rg.make<v0::Unsqueeze>(W, unsqueeze_axis);+ auto R_prep = rg.make<v0::Unsqueeze>(R, unsqueeze_axis);+ auto B_prep = rg.make<v0::Unsqueeze>(B, unsqueeze_axis);// create LSTMSequence operation since all inputs are prepared// extract hidden size that should be static as a requirement of OpenVINO LSTMCell operationint64_t hidden_size = static_cast<int64_t>(lstm_cell_node->get_hidden_size());- auto lstm_sequence = rg.make<ov::op::v5::LSTMSequence>(x_prep,- init_hidden_state_prep,- init_cell_state_prep,- seq_lens_prep,- W_prep,- R_prep,- B_prep,- hidden_size,- ov::op::RecurrentSequenceDirection::FORWARD,- lstm_cell_node->get_activations_alpha(),- lstm_cell_node->get_activations_beta(),- lstm_cell_node->get_activations(),- lstm_cell_node->get_clip());+ auto lstm_sequence = rg.make<v5::LSTMSequence>(x_prep,+ init_hidden_state_prep,+ init_cell_state_prep,+ seq_lens_prep,+ W_prep,+ R_prep,+ B_prep,+ hidden_size,+ ov::op::RecurrentSequenceDirection::FORWARD,+ lstm_cell_node->get_activations_alpha(),+ lstm_cell_node->get_activations_beta(),+ lstm_cell_node->get_activations(),+ lstm_cell_node->get_clip());if (transformation_callback(lstm_sequence))return false;@@ -1285,14 +1280,13 @@ ov::pass::ConvertLoopWithSlicedInputConcatOutputToLSTMSequence::ConvertLoopWithS// prepare outputs of LSTMSequence// output with concatenated hidden states must be in a format [seq_len, batch_size, hidden_size]// LSTMSequence generates it in a format [batch_size, num_directions, seq_len, hidden_size]- auto squeeze_axis = rg.make<ov::op::v0::Constant>(element::i32, Shape{1}, std::vector<int32_t>{1});- ov::Output<Node> all_hidden_states_prep = rg.make<ov::op::v0::Squeeze>(lstm_sequence->output(0), squeeze_axis);- all_hidden_states_prep = rg.make<ov::op::v1::Transpose>(all_hidden_states_prep, tr_order);+ auto squeeze_axis = rg.make<v0::Constant>(element::i32, Shape{1}, std::vector<int32_t>{1});+ ov::Output<Node> all_hidden_states_prep = rg.make<v0::Squeeze>(lstm_sequence->output(0), squeeze_axis);+ all_hidden_states_prep = rg.make<v1::Transpose>(all_hidden_states_prep, tr_order);// prepare output with last hidden state// LSTMSequence operation outputs it in a format [batch_size, num_directions, hidden_size]- auto tr_order2 = rg.make<ov::op::v0::Constant>(element::i32, Shape{3}, std::vector<int32_t>{1, 0, 2});- ov::Output<ov::Node> last_hidden_state_prep =- rg.make<ov::op::v1::Transpose>(lstm_sequence->output(1), tr_order2);+ auto tr_order2 = rg.make<v0::Constant>(element::i32, Shape{3}, std::vector<int32_t>{1, 0, 2});+ ov::Output<ov::Node> last_hidden_state_prep = rg.make<v1::Transpose>(lstm_sequence->output(1), tr_order2);// reconnect all consumers for hidden statesfor (auto output_idx : all_hidden_states_output_ids) {@@ -1312,7 +1306,7 @@ ov::pass::ConvertLoopWithSlicedInputConcatOutputToLSTMSequence::ConvertLoopWithSreturn true;};- auto m = std::make_shared<pattern::Matcher>(loop_label, matcher_name);+ auto m = std::make_shared<Matcher>(loop_label, matcher_name);register_matcher(m, callback);}@@ -1323,22 +1317,20 @@ public:using namespace ov;using namespace ov::pass;- auto data_label = pattern::any_input(pattern::rank_equals(3));- auto shapeof_label = pattern::wrap_type<op::util::ShapeOfBase>({data_label});- auto shapeof_gather_label = pattern::wrap_type<op::util::GatherBase>(- {shapeof_label, pattern::wrap_type<op::v0::Constant>(), pattern::wrap_type<op::v0::Constant>()});- auto shapeof_gather2_label = pattern::wrap_type<op::util::GatherBase>(- {shapeof_gather_label, pattern::wrap_type<op::v0::Constant>(), pattern::wrap_type<op::v0::Constant>()});- auto reshape_label =- pattern::wrap_type<op::v1::Reshape>({shapeof_gather2_label, pattern::wrap_type<op::v0::Constant>()});- auto range_label = pattern::wrap_type<op::v4::Range>(- {pattern::wrap_type<op::v0::Constant>(), reshape_label, pattern::wrap_type<op::v0::Constant>()});- auto match_node = pass::pattern::wrap_type<op::util::GatherBase>(- {data_label, range_label, pattern::wrap_type<op::v0::Constant>()});-- matcher_pass_callback callback = [=](pass::pattern::Matcher& m) {+ auto data_label = any_input(rank_equals(3));+ auto shapeof_label = wrap_type<op_util::ShapeOfBase>({data_label});+ auto shapeof_gather_label = wrap_type<op_util::GatherBase>(+ {shapeof_label, wrap_type<op::v0::Constant>(), wrap_type<op::v0::Constant>()});+ auto shapeof_gather2_label = wrap_type<op_util::GatherBase>(+ {shapeof_gather_label, wrap_type<op::v0::Constant>(), wrap_type<op::v0::Constant>()});+ auto reshape_label = wrap_type<op::v1::Reshape>({shapeof_gather2_label, wrap_type<op::v0::Constant>()});+ auto range_label =+ wrap_type<op::v4::Range>({wrap_type<op::v0::Constant>(), reshape_label, wrap_type<op::v0::Constant>()});+ auto match_node = wrap_type<op_util::GatherBase>({data_label, range_label, wrap_type<op::v0::Constant>()});++ matcher_pass_callback callback = [=](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();- auto gather = ov::as_type_ptr<op::util::GatherBase>(m.get_match_root());+ auto gather = ov::as_type_ptr<op_util::GatherBase>(m.get_match_root());if (!gather)return false;auto axis = gather->get_axis();@@ -1355,9 +1347,9 @@ public:const auto shapeof_gather2 = pattern_map.at(shapeof_gather2_label).get_node_shared_ptr();int64_t shapeof_gather2_index = -1;int64_t shapeof_gather2_axis = -1;- if (!get_constant_value(shapeof_gather2->get_input_node_shared_ptr(1), shapeof_gather2_index))+ if (!op_util::get_constant_value(shapeof_gather2->get_input_node_shared_ptr(1), shapeof_gather2_index))return false;- if (!get_constant_value(shapeof_gather2->get_input_node_shared_ptr(2), shapeof_gather2_axis) ||+ if (!op_util::get_constant_value(shapeof_gather2->get_input_node_shared_ptr(2), shapeof_gather2_axis) ||shapeof_gather2_axis != 0)return false;const auto reshape = pattern_map.at(reshape_label).get_node_shared_ptr();@@ -1367,20 +1359,20 @@ public:const auto range = pattern_map.at(range_label).get_node_shared_ptr();int64_t range_start = -1;int64_t range_step = -1;- if (!get_constant_value(range->get_input_node_shared_ptr(0), range_start) || range_start != 0)+ if (!op_util::get_constant_value(range->get_input_node_shared_ptr(0), range_start) || range_start != 0)return false;- if (!get_constant_value(range->get_input_node_shared_ptr(2), range_step) || range_step != 1)+ if (!op_util::get_constant_value(range->get_input_node_shared_ptr(2), range_step) || range_step != 1)return false;int64_t gather_axis = -1;- if (!get_constant_value(gather->get_input_node_shared_ptr(2), gather_axis) ||+ if (!op_util::get_constant_value(gather->get_input_node_shared_ptr(2), gather_axis) ||gather_axis != shapeof_gather_indexes[shapeof_gather2_index])return false;return replace_output_update_name(gather->output(0), gather->input_value(0));};- auto m = std::make_shared<pattern::Matcher>(match_node, "EliminateGatherWithRange");+ auto m = std::make_shared<Matcher>(match_node, "EliminateGatherWithRange");register_matcher(m, callback);}};@@ -1388,29 +1380,21 @@ public:ov::pass::FuseReverseLSTMSequence::FuseReverseLSTMSequence() {MATCHER_SCOPE(FuseReverseLSTMSequence);- auto data_label = pattern::any_input(pattern::rank_equals(3));+ auto data_label = any_input(rank_equals(3));auto first_transpose_label =- pattern::wrap_type<op::v1::Transpose, op::v1::Reshape>({data_label, pattern::wrap_type<op::v0::Constant>()},- pattern::rank_equals(3));- auto input_to_first_reverse_sequence_label =- std::make_shared<pattern::op::Or>(OutputVector{first_transpose_label, data_label});+ wrap_type<op::v1::Transpose, op::v1::Reshape>({data_label, wrap_type<op::v0::Constant>()}, rank_equals(3));+ auto input_to_first_reverse_sequence_label = std::make_shared<Or>(OutputVector{first_transpose_label, data_label});auto first_reverse_sequence_label =- pattern::wrap_type<op::v0::ReverseSequence>({input_to_first_reverse_sequence_label, pattern::any_input()});+ wrap_type<op::v0::ReverseSequence>({input_to_first_reverse_sequence_label, any_input()});auto second_transpose_label =- pattern::wrap_type<op::v1::Transpose>({first_reverse_sequence_label, pattern::wrap_type<op::v0::Constant>()});- auto lstm_label = pattern::wrap_type<op::v5::LSTMSequence>({second_transpose_label,- pattern::any_input(),- pattern::any_input(),- pattern::any_input(),- pattern::any_input(),- pattern::any_input(),- pattern::any_input()},- pattern::consumers_count(1));- auto squeeze_label = pattern::wrap_type<op::v0::Squeeze>({lstm_label, pattern::wrap_type<op::v0::Constant>()});- auto second_reverse_sequence_label =- pattern::wrap_type<op::v0::ReverseSequence>({squeeze_label, pattern::any_input()});-- matcher_pass_callback callback = [=](pattern::Matcher& m) {+ wrap_type<op::v1::Transpose>({first_reverse_sequence_label, wrap_type<op::v0::Constant>()});+ auto lstm_label = wrap_type<op::v5::LSTMSequence>(+ {second_transpose_label, any_input(), any_input(), any_input(), any_input(), any_input(), any_input()},+ ov::pass::pattern::consumers_count(1));+ auto squeeze_label = wrap_type<op::v0::Squeeze>({lstm_label, wrap_type<op::v0::Constant>()});+ auto second_reverse_sequence_label = wrap_type<op::v0::ReverseSequence>({squeeze_label, any_input()});++ matcher_pass_callback callback = [=](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& data = pattern_map.at(data_label);const auto second_transpose = pattern_map.at(second_transpose_label).get_node_shared_ptr();@@ -1492,7 +1476,7 @@ ov::pass::FuseReverseLSTMSequence::FuseReverseLSTMSequence() {if (squeeze->input_value(0) != lstm->output(0))return false;int64_t squeeze_axis = -1;- if (!get_constant_value(squeeze->get_input_node_shared_ptr(1), squeeze_axis) || squeeze_axis != 1)+ if (!op_util::get_constant_value(squeeze->get_input_node_shared_ptr(1), squeeze_axis) || squeeze_axis != 1)return false;auto new_squeeze = node_registry.make<op::v0::Squeeze>(new_lstm->output(0), squeeze->input_value(1));const auto match_root = m.get_match_root();@@ -1500,7 +1484,7 @@ ov::pass::FuseReverseLSTMSequence::FuseReverseLSTMSequence() {for (auto& consumer : second_transpose->output(0).get_target_inputs()) {auto node = consumer.get_node()->shared_from_this();- if (ov::is_type<op::util::ShapeOfBase>(node)) {+ if (ov::is_type<op_util::ShapeOfBase>(node)) {auto shapeof = std::make_shared<op::v3::ShapeOf>(new_lstm_input);replace_node(node, shapeof);}@@ -1521,69 +1505,62 @@ ov::pass::FuseReverseLSTMSequence::FuseReverseLSTMSequence() {return true;};- auto m = std::make_shared<pattern::Matcher>(second_reverse_sequence_label, matcher_name);+ auto m = std::make_shared<Matcher>(second_reverse_sequence_label, matcher_name);register_matcher(m, callback);}ov::pass::FuseLSTMSequencesToBidirectionalLSTMSequence::FuseLSTMSequencesToBidirectionalLSTMSequence() {MATCHER_SCOPE(FuseLSTMSequencesToBidirectionalLSTMSequence);- auto data_label = pattern::any_input();+ auto data_label = any_input();// forward pattern- auto transpose_forward_label =- pattern::wrap_type<op::v1::Transpose>({data_label, pattern::wrap_type<op::v0::Constant>()});+ auto transpose_forward_label = wrap_type<op::v1::Transpose>({data_label, wrap_type<op::v0::Constant>()});auto lstm_sequence_forward_first_input_label =- std::make_shared<pattern::op::Or>(OutputVector{transpose_forward_label, data_label});- auto shapeof_forward_label = pattern::wrap_type<op::util::ShapeOfBase>({lstm_sequence_forward_first_input_label});- auto gather_forward_label = pattern::wrap_type<op::util::GatherBase>(- {shapeof_forward_label, pattern::wrap_type<op::v0::Constant>(), pattern::wrap_type<op::v0::Constant>()});- auto max_sequence_len_forward_label = pattern::wrap_type<op::v0::Constant>();- auto broadcast_forward_label =- pattern::wrap_type<op::v3::Broadcast>({max_sequence_len_forward_label, gather_forward_label});- auto const_sequence_lengths_forward_label = pattern::wrap_type<op::v0::Constant>();+ std::make_shared<Or>(OutputVector{transpose_forward_label, data_label});+ auto shapeof_forward_label = wrap_type<op_util::ShapeOfBase>({lstm_sequence_forward_first_input_label});+ auto gather_forward_label = wrap_type<op_util::GatherBase>(+ {shapeof_forward_label, wrap_type<op::v0::Constant>(), wrap_type<op::v0::Constant>()});+ auto max_sequence_len_forward_label = wrap_type<op::v0::Constant>();+ auto broadcast_forward_label = wrap_type<op::v3::Broadcast>({max_sequence_len_forward_label, gather_forward_label});+ auto const_sequence_lengths_forward_label = wrap_type<op::v0::Constant>();auto sequence_lengths_forward_label =- std::make_shared<pattern::op::Or>(OutputVector{broadcast_forward_label, const_sequence_lengths_forward_label});- auto lstm_sequence_forward_label =- pattern::wrap_type<op::v5::LSTMSequence>({lstm_sequence_forward_first_input_label,- pattern::any_input(),- pattern::any_input(),- sequence_lengths_forward_label,- pattern::any_input(),- pattern::any_input(),- pattern::any_input()});+ std::make_shared<Or>(OutputVector{broadcast_forward_label, const_sequence_lengths_forward_label});+ auto lstm_sequence_forward_label = wrap_type<op::v5::LSTMSequence>({lstm_sequence_forward_first_input_label,+ any_input(),+ any_input(),+ sequence_lengths_forward_label,+ any_input(),+ any_input(),+ any_input()});auto squeeze_forward_label =- pattern::wrap_type<op::v0::Squeeze>({lstm_sequence_forward_label, pattern::wrap_type<op::v0::Constant>()},- pattern::rank_equals(3));+ wrap_type<op::v0::Squeeze>({lstm_sequence_forward_label, wrap_type<op::v0::Constant>()}, rank_equals(3));// backward patternauto transpose_reverse_label =- pattern::wrap_type<op::v1::Transpose, op::v1::Reshape>({data_label, pattern::wrap_type<op::v0::Constant>()});+ wrap_type<op::v1::Transpose, op::v1::Reshape>({data_label, wrap_type<op::v0::Constant>()});auto lstm_sequence_reverse_first_input_label =- std::make_shared<pattern::op::Or>(OutputVector{transpose_reverse_label, data_label});- auto shapeof_reverse_label = pattern::wrap_type<op::util::ShapeOfBase>({lstm_sequence_reverse_first_input_label});- auto gather_reverse_label = pattern::wrap_type<op::util::GatherBase>(- {shapeof_reverse_label, pattern::wrap_type<op::v0::Constant>(), pattern::wrap_type<op::v0::Constant>()});- auto max_sequence_len_reverse_label = pattern::wrap_type<op::v0::Constant>();- auto broadcast_reverse_label =- pattern::wrap_type<op::v3::Broadcast>({max_sequence_len_reverse_label, gather_reverse_label});- auto const_sequence_lengths_reverse_label = pattern::wrap_type<op::v0::Constant>();+ std::make_shared<Or>(OutputVector{transpose_reverse_label, data_label});+ auto shapeof_reverse_label = wrap_type<op_util::ShapeOfBase>({lstm_sequence_reverse_first_input_label});+ auto gather_reverse_label = wrap_type<op_util::GatherBase>(+ {shapeof_reverse_label, wrap_type<op::v0::Constant>(), wrap_type<op::v0::Constant>()});+ auto max_sequence_len_reverse_label = wrap_type<op::v0::Constant>();+ auto broadcast_reverse_label = wrap_type<op::v3::Broadcast>({max_sequence_len_reverse_label, gather_reverse_label});+ auto const_sequence_lengths_reverse_label = wrap_type<op::v0::Constant>();auto sequence_lengths_reverse_label =- std::make_shared<pattern::op::Or>(OutputVector{broadcast_reverse_label, const_sequence_lengths_reverse_label});- auto lstm_sequence_reverse_label =- pattern::wrap_type<op::v5::LSTMSequence>({lstm_sequence_reverse_first_input_label,- pattern::any_input(),- pattern::any_input(),- sequence_lengths_reverse_label,- pattern::any_input(),- pattern::any_input(),- pattern::any_input()});+ std::make_shared<Or>(OutputVector{broadcast_reverse_label, const_sequence_lengths_reverse_label});+ auto lstm_sequence_reverse_label = wrap_type<op::v5::LSTMSequence>({lstm_sequence_reverse_first_input_label,+ any_input(),+ any_input(),+ sequence_lengths_reverse_label,+ any_input(),+ any_input(),+ any_input()});auto squeeze_reverse_label =- pattern::wrap_type<op::v0::Squeeze>({lstm_sequence_reverse_label, pattern::wrap_type<op::v0::Constant>()},- pattern::rank_equals(3));+ wrap_type<op::v0::Squeeze>({lstm_sequence_reverse_label, wrap_type<op::v0::Constant>()}, rank_equals(3));- auto concat_label = pattern::wrap_type<op::v0::Concat>({squeeze_forward_label, squeeze_reverse_label});+ auto concat_label = wrap_type<op::v0::Concat>({squeeze_forward_label, squeeze_reverse_label});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_map = m.get_pattern_map();auto lstm_forward = ov::as_type_ptr<op::v5::LSTMSequence>(pattern_map.at(lstm_sequence_forward_label));auto lstm_reverse = ov::as_type_ptr<op::v5::LSTMSequence>(pattern_map.at(lstm_sequence_reverse_label));@@ -1609,7 +1586,7 @@ ov::pass::FuseLSTMSequencesToBidirectionalLSTMSequence::FuseLSTMSequencesToBidirif (squeeze_forward->input_value(0) != lstm_forward->output(0))return false;int64_t squeeze_forward_axis = -1;- if (!get_constant_value(squeeze_forward->get_input_node_shared_ptr(1), squeeze_forward_axis) ||+ if (!op_util::get_constant_value(squeeze_forward->get_input_node_shared_ptr(1), squeeze_forward_axis) ||squeeze_forward_axis != 1)return false;@@ -1617,7 +1594,7 @@ ov::pass::FuseLSTMSequencesToBidirectionalLSTMSequence::FuseLSTMSequencesToBidirif (squeeze_reverse->input_value(0) != lstm_reverse->output(0))return false;int64_t squeeze_reverse_axis = -1;- if (!get_constant_value(squeeze_reverse->get_input_node_shared_ptr(1), squeeze_reverse_axis) ||+ if (!op_util::get_constant_value(squeeze_reverse->get_input_node_shared_ptr(1), squeeze_reverse_axis) ||squeeze_reverse_axis != 1)return false;@@ -1667,17 +1644,21 @@ ov::pass::FuseLSTMSequencesToBidirectionalLSTMSequence::FuseLSTMSequencesToBidirauto gather_forward = pattern_map.at(gather_forward_label);int64_t gather_index = -1;int64_t gather_axis = -1;- if (!get_constant_value(gather_forward->get_input_node_shared_ptr(1), gather_index) || gather_index != 0)+ if (!op_util::get_constant_value(gather_forward->get_input_node_shared_ptr(1), gather_index) ||+ gather_index != 0)return false;- if (!get_constant_value(gather_forward->get_input_node_shared_ptr(2), gather_axis) || gather_axis != 0)+ if (!op_util::get_constant_value(gather_forward->get_input_node_shared_ptr(2), gather_axis) ||+ gather_axis != 0)return false;auto gather_reverse = pattern_map.at(gather_reverse_label);gather_index = -1;gather_axis = -1;- if (!get_constant_value(gather_reverse->get_input_node_shared_ptr(1), gather_index) || gather_index != 0)+ if (!op_util::get_constant_value(gather_reverse->get_input_node_shared_ptr(1), gather_index) ||+ gather_index != 0)return false;- if (!get_constant_value(gather_reverse->get_input_node_shared_ptr(2), gather_axis) || gather_axis != 0)+ if (!op_util::get_constant_value(gather_reverse->get_input_node_shared_ptr(2), gather_axis) ||+ gather_axis != 0)return false;from.push_back(max_sequence_len_forward);@@ -1732,7 +1713,7 @@ ov::pass::FuseLSTMSequencesToBidirectionalLSTMSequence::FuseLSTMSequencesToBidirreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(concat_label, matcher_name);+ auto m = std::make_shared<Matcher>(concat_label, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_topk11_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_topk11_downgrade.cppindex f12d085d49b..680811b622b 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_topk11_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_topk11_downgrade.cpp@@ -11,13 +11,16 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v11 = ov::op::v11;ov::pass::ConvertTopK11ToTopK3::ConvertTopK11ToTopK3() {MATCHER_SCOPE(ConvertTopK11ToTopK3);- const auto topk_v11_pattern = pattern::wrap_type<ov::op::v11::TopK>();+ const auto topk_v11_pattern = ov::pass::pattern::wrap_type<v11::TopK>();- const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- const auto topk_v11 = ov::as_type_ptr<ov::op::v11::TopK>(m.get_match_root());+ const matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ const auto topk_v11 = ov::as_type_ptr<v11::TopK>(m.get_match_root());if (!topk_v11 || transformation_callback(topk_v11)) {return false;}@@ -40,6 +43,6 @@ ov::pass::ConvertTopK11ToTopK3::ConvertTopK11ToTopK3() {return true;};- auto m = std::make_shared<pattern::Matcher>(topk_v11_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(topk_v11_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_topk3.cpp b/src/common/transformations/src/transformations/op_conversions/convert_topk3.cppindex c3531f4c8c7..b8c4cbd689e 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_topk3.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_topk3.cpp@@ -13,12 +13,16 @@#include "openvino/op/topk.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v3 = ov::op::v3;ov::pass::ConvertTopK3::ConvertTopK3() {MATCHER_SCOPE(ConvertTopK3);- auto topk = pattern::wrap_type<ov::op::v3::TopK>();+ auto topk = ov::pass::pattern::wrap_type<v3::TopK>();- matcher_pass_callback callback = [](pattern::Matcher& m) {- auto topk = ov::as_type_ptr<ov::op::v3::TopK>(m.get_match_root());+ matcher_pass_callback callback = [](Matcher& m) {+ auto topk = ov::as_type_ptr<v3::TopK>(m.get_match_root());if (!topk) {return false;}@@ -41,15 +45,15 @@ ov::pass::ConvertTopK3::ConvertTopK3() {new_topk->set_friendly_name(topk->get_friendly_name());} else if (topk->get_output_target_inputs(0).size() == 0) {last0 = topk->output(0);- last1 = std::make_shared<ov::op::v0::Convert>(new_topk->output(1), topk->get_index_element_type());+ last1 = std::make_shared<v0::Convert>(new_topk->output(1), topk->get_index_element_type());new_ops.push_back(last1.get_node_shared_ptr());// workaround for naming two outputs of TopKlast1.get_node_shared_ptr()->set_friendly_name(topk->get_friendly_name() + ".1");} else {// create fake convert for 0 output, it is a workaround in purpose of correct output names preserving- last0 = std::make_shared<ov::op::v0::Convert>(new_topk->output(0), topk->get_output_element_type(0));- last1 = std::make_shared<ov::op::v0::Convert>(new_topk->output(1), topk->get_index_element_type());+ last0 = std::make_shared<v0::Convert>(new_topk->output(0), topk->get_output_element_type(0));+ last1 = std::make_shared<v0::Convert>(new_topk->output(1), topk->get_index_element_type());new_ops.push_back(last0.get_node_shared_ptr());new_ops.push_back(last1.get_node_shared_ptr());@@ -64,6 +68,6 @@ ov::pass::ConvertTopK3::ConvertTopK3() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(topk, matcher_name);+ auto m = std::make_shared<Matcher>(topk, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/convert_xor_to_logical_xor.cpp b/src/common/transformations/src/transformations/op_conversions/convert_xor_to_logical_xor.cppindex d615651e0fe..29a85d63484 100644--- a/src/common/transformations/src/transformations/op_conversions/convert_xor_to_logical_xor.cpp+++ b/src/common/transformations/src/transformations/op_conversions/convert_xor_to_logical_xor.cpp@@ -11,13 +11,16 @@#include "openvino/op/xor.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;ov::pass::ConvertXorToLogicalXor::ConvertXorToLogicalXor() {MATCHER_SCOPE(ConvertXorToLogicalXor);- auto xor_v1 = pattern::wrap_type<ov::op::v0::Xor>();+ auto xor_v1 = ov::pass::pattern::wrap_type<v0::Xor>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto xor_v1_node = ov::as_type_ptr<ov::op::v0::Xor>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto xor_v1_node = ov::as_type_ptr<v0::Xor>(m.get_match_root());if (!xor_v1_node)return false;@@ -33,6 +36,6 @@ ov::pass::ConvertXorToLogicalXor::ConvertXorToLogicalXor() {return true;};- auto m = std::make_shared<pattern::Matcher>(xor_v1, matcher_name);+ auto m = std::make_shared<Matcher>(xor_v1, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/detection_output_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/detection_output_downgrade.cppindex f9cf528fb2d..1469cfa36d7 100644--- a/src/common/transformations/src/transformations/op_conversions/detection_output_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/detection_output_downgrade.cpp@@ -13,15 +13,18 @@using namespace std;using namespace ov;-using namespace ov::op::util;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v8 = ov::op::v8;pass::ConvertDetectionOutput8ToDetectionOutput1::ConvertDetectionOutput8ToDetectionOutput1() {MATCHER_SCOPE(ConvertDetectionOutput8ToDetectionOutput1);- auto detection_output_v8_pattern = pattern::wrap_type<ov::op::v8::DetectionOutput>();+ auto detection_output_v8_pattern = ov::pass::pattern::wrap_type<v8::DetectionOutput>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto detection_output_v8_node = ov::as_type_ptr<ov::op::v8::DetectionOutput>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto detection_output_v8_node = ov::as_type_ptr<v8::DetectionOutput>(m.get_match_root());if (!detection_output_v8_node)return false;const auto& attributes_v8 = detection_output_v8_node->get_attrs();@@ -31,7 +34,7 @@ pass::ConvertDetectionOutput8ToDetectionOutput1::ConvertDetectionOutput8ToDetectif (num_classes.is_dynamic())return false;- ov::op::v0::DetectionOutput::Attributes attributes_v1;+ v0::DetectionOutput::Attributes attributes_v1;attributes_v1.background_label_id = attributes_v8.background_label_id;attributes_v1.clip_after_nms = attributes_v8.clip_after_nms;attributes_v1.clip_before_nms = attributes_v8.clip_before_nms;@@ -49,21 +52,19 @@ pass::ConvertDetectionOutput8ToDetectionOutput1::ConvertDetectionOutput8ToDetectattributes_v1.top_k = attributes_v8.top_k;attributes_v1.variance_encoded_in_target = attributes_v8.variance_encoded_in_target;- std::shared_ptr<ov::op::v0::DetectionOutput> detection_output_v1_node = nullptr;+ std::shared_ptr<v0::DetectionOutput> detection_output_v1_node = nullptr;if (detection_output_v8_node->get_input_size() == 3) {- detection_output_v1_node =- make_shared<ov::op::v0::DetectionOutput>(detection_output_v8_node->input_value(0),- detection_output_v8_node->input_value(1),- detection_output_v8_node->input_value(2),- attributes_v1);+ detection_output_v1_node = make_shared<v0::DetectionOutput>(detection_output_v8_node->input_value(0),+ detection_output_v8_node->input_value(1),+ detection_output_v8_node->input_value(2),+ attributes_v1);} else if (detection_output_v8_node->get_input_size() == 5) {- detection_output_v1_node =- make_shared<ov::op::v0::DetectionOutput>(detection_output_v8_node->input_value(0),- detection_output_v8_node->input_value(1),- detection_output_v8_node->input_value(2),- detection_output_v8_node->input_value(3),- detection_output_v8_node->input_value(4),- attributes_v1);+ detection_output_v1_node = make_shared<v0::DetectionOutput>(detection_output_v8_node->input_value(0),+ detection_output_v8_node->input_value(1),+ detection_output_v8_node->input_value(2),+ detection_output_v8_node->input_value(3),+ detection_output_v8_node->input_value(4),+ attributes_v1);}if (!detection_output_v1_node)return false;@@ -74,6 +75,6 @@ pass::ConvertDetectionOutput8ToDetectionOutput1::ConvertDetectionOutput8ToDetectreturn true;};- auto m = make_shared<pattern::Matcher>(detection_output_v8_pattern, matcher_name);+ auto m = make_shared<Matcher>(detection_output_v8_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/detection_output_upgrade.cpp b/src/common/transformations/src/transformations/op_conversions/detection_output_upgrade.cppindex 098c2f51b6e..fea6fdebca2 100644--- a/src/common/transformations/src/transformations/op_conversions/detection_output_upgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/detection_output_upgrade.cpp@@ -12,20 +12,23 @@using namespace std;using namespace ov;-using namespace ov::op::util;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v8 = ov::op::v8;pass::ConvertDetectionOutput1ToDetectionOutput8::ConvertDetectionOutput1ToDetectionOutput8() {MATCHER_SCOPE(ConvertDetectionOutput1ToDetectionOutput8);- auto detection_output_v1_pattern = pattern::wrap_type<ov::op::v0::DetectionOutput>();+ auto detection_output_v1_pattern = ov::pass::pattern::wrap_type<v0::DetectionOutput>();- matcher_pass_callback callback = [=](pattern::Matcher& m) {- auto detection_output_v1_node = ov::as_type_ptr<ov::op::v0::DetectionOutput>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto detection_output_v1_node = ov::as_type_ptr<v0::DetectionOutput>(m.get_match_root());if (!detection_output_v1_node)return false;const auto& attributes_v1 = detection_output_v1_node->get_attrs();- ov::op::v8::DetectionOutput::Attributes attributes_v8;+ v8::DetectionOutput::Attributes attributes_v8;attributes_v8.background_label_id = attributes_v1.background_label_id;attributes_v8.clip_after_nms = attributes_v1.clip_after_nms;attributes_v8.clip_before_nms = attributes_v1.clip_before_nms;@@ -42,21 +45,19 @@ pass::ConvertDetectionOutput1ToDetectionOutput8::ConvertDetectionOutput1ToDetectattributes_v8.top_k = attributes_v1.top_k;attributes_v8.variance_encoded_in_target = attributes_v1.variance_encoded_in_target;- std::shared_ptr<ov::op::v8::DetectionOutput> detection_output_v8_node = nullptr;+ std::shared_ptr<v8::DetectionOutput> detection_output_v8_node = nullptr;if (detection_output_v1_node->get_input_size() == 3) {- detection_output_v8_node =- make_shared<ov::op::v8::DetectionOutput>(detection_output_v1_node->input_value(0),- detection_output_v1_node->input_value(1),- detection_output_v1_node->input_value(2),- attributes_v8);+ detection_output_v8_node = make_shared<v8::DetectionOutput>(detection_output_v1_node->input_value(0),+ detection_output_v1_node->input_value(1),+ detection_output_v1_node->input_value(2),+ attributes_v8);} else if (detection_output_v1_node->get_input_size() == 5) {- detection_output_v8_node =- make_shared<ov::op::v8::DetectionOutput>(detection_output_v1_node->input_value(0),- detection_output_v1_node->input_value(1),- detection_output_v1_node->input_value(2),- detection_output_v1_node->input_value(3),- detection_output_v1_node->input_value(4),- attributes_v8);+ detection_output_v8_node = make_shared<v8::DetectionOutput>(detection_output_v1_node->input_value(0),+ detection_output_v1_node->input_value(1),+ detection_output_v1_node->input_value(2),+ detection_output_v1_node->input_value(3),+ detection_output_v1_node->input_value(4),+ attributes_v8);}if (!detection_output_v8_node)return false;@@ -67,6 +68,6 @@ pass::ConvertDetectionOutput1ToDetectionOutput8::ConvertDetectionOutput1ToDetectreturn true;};- auto m = make_shared<pattern::Matcher>(detection_output_v1_pattern, matcher_name);+ auto m = make_shared<Matcher>(detection_output_v1_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/einsum_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/einsum_decomposition.cppindex f1c81cf3c97..6fdb89fa874 100644--- a/src/common/transformations/src/transformations/op_conversions/einsum_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/einsum_decomposition.cpp@@ -36,6 +36,12 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v7 = ov::op::v7;namespace {/// \brief Compute einsum_path for a given Einsum node meaning that the (pseudo-)optimal/// order of operands contraction in terms of performance and memory consumption@@ -45,7 +51,7 @@ namespace {/// \return a vector of pairs with input indices assuming that the intermediate result is/// appended in the tail///-std::vector<std::pair<size_t, size_t>> compute_einsum_path(std::shared_ptr<const ov::op::v7::Einsum> einsum_node) {+std::vector<std::pair<size_t, size_t>> compute_einsum_path(std::shared_ptr<const v7::Einsum> einsum_node) {// TODO: implement algorithm for finding (pseudo-)optimal einsum_pathstd::vector<std::pair<size_t, size_t>> einsum_path;const size_t num_inputs = einsum_node->get_input_size();@@ -137,7 +143,7 @@ std::string generate_grouping_subscript(const std::string& input_subscript,return input_subscript;}- auto labels = ov::op::v7::Einsum::extract_labels(input_subscript);+ auto labels = v7::Einsum::extract_labels(input_subscript);std::string required_subscript = "";for (auto index : labels_inds) {required_subscript += labels[index];@@ -187,7 +193,7 @@ using LabelDimMap = std::unordered_map<std::string, std::vector<size_t>>;///LabelDimMap compute_label_dim_map(const ov::Rank& input_rank, const std::string& input_subscript) {static const std::string ellipsis = "...";- const auto labels = ov::op::v7::Einsum::extract_labels(input_subscript);+ const auto labels = v7::Einsum::extract_labels(input_subscript);const auto static_input_rank = input_rank.is_static();OPENVINO_ASSERT(static_input_rank || (std::find(labels.begin(), labels.end(), ellipsis) == labels.end()),"Input rank cannot be dynamic in case of ellipsis in input subscript");@@ -311,16 +317,14 @@ ov::OutputVector compute_sub_shape(const ov::Output<ov::Node>& data_shape,}std::vector<int64_t> begin_mask(1, 0);std::vector<int64_t> end_mask(1, 0);- auto begin_const = ov::op::v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {begin});- auto end_const = ov::op::v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {end});- auto stride_const = ov::op::v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {1});- auto sub_shape =- std::make_shared<ov::op::v1::StridedSlice>(data_shape, begin_const, end_const, begin_mask, end_mask);+ auto begin_const = v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {begin});+ auto end_const = v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {end});+ auto stride_const = v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {1});+ auto sub_shape = std::make_shared<v1::StridedSlice>(data_shape, begin_const, end_const, begin_mask, end_mask);if (is_product) {- auto reduce_axis_const = ov::op::v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {0});- auto separate_shape_prod =- std::make_shared<ov::op::v1::ReduceProd>(sub_shape->output(0), reduce_axis_const, true);+ auto reduce_axis_const = v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {0});+ auto separate_shape_prod = std::make_shared<v1::ReduceProd>(sub_shape->output(0), reduce_axis_const, true);sub_shape_vector.push_back(separate_shape_prod->output(0));subgraph_nodes.insert(subgraph_nodes.end(), {reduce_axis_const, separate_shape_prod});} else {@@ -348,8 +352,8 @@ ov::Output<ov::Node> unsqueeze_input(const ov::Output<ov::Node>& input_node,return input_node;}auto unsqueeze_axes_const =- ov::op::v0::Constant::create(ov::element::Type_t::i64, ov::Shape{unsqueeze_axes.size()}, unsqueeze_axes);- auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(input_node, unsqueeze_axes_const);+ v0::Constant::create(ov::element::Type_t::i64, ov::Shape{unsqueeze_axes.size()}, unsqueeze_axes);+ auto unsqueeze = std::make_shared<v0::Unsqueeze>(input_node, unsqueeze_axes_const);subgraph_nodes.insert(subgraph_nodes.end(), {unsqueeze_axes_const, unsqueeze});return unsqueeze->output(0);}@@ -374,7 +378,7 @@ ov::OutputVector broadcast_merge_shapes(const ov::OutputVector& shapes_lhs,if (shapes_lhs.size() == 1 && shapes_rhs.size() == 1) {// For common and reference subshapes, same rank should already be ensured by function// `unsqueeze_ellipses_to_same_rank`.- const auto& maximum = std::make_shared<ov::op::v1::Maximum>(shapes_lhs[0], shapes_rhs[0]);+ const auto& maximum = std::make_shared<v1::Maximum>(shapes_lhs[0], shapes_rhs[0]);subgraph_nodes.push_back(maximum);broadcasted_shape_nodes.push_back(maximum);} else if (shapes_lhs.size() == 0 && shapes_rhs.size() == 1) {@@ -421,18 +425,17 @@ ov::Output<ov::Node> broadcast_input(const ov::Output<ov::Node>& input_node,if (new_shape_parts.size() == 0) {return input_node;}- auto new_shape_op = std::make_shared<ov::op::v0::Concat>(new_shape_parts, 0);+ auto new_shape_op = std::make_shared<v0::Concat>(new_shape_parts, 0);// if new shape is possible to compute on the shape infer stage, insert Constant node immediately// in order to prevent repeated computing during constant-folding pass- std::shared_ptr<ov::op::v3::Broadcast> reshaped_input_op;+ std::shared_ptr<v3::Broadcast> reshaped_input_op;if (auto new_shape_const = ov::util::get_constant_from_source(new_shape_op)) {reshaped_input_op =- std::make_shared<ov::op::v3::Broadcast>(input_node, new_shape_const, ov::op::BroadcastType::BIDIRECTIONAL);+ std::make_shared<v3::Broadcast>(input_node, new_shape_const, ov::op::BroadcastType::BIDIRECTIONAL);subgraph_nodes.insert(subgraph_nodes.end(), {new_shape_const});} else {- reshaped_input_op = std::make_shared<ov::op::v3::Broadcast>(input_node,- new_shape_op->output(0),- ov::op::BroadcastType::BIDIRECTIONAL);+ reshaped_input_op =+ std::make_shared<v3::Broadcast>(input_node, new_shape_op->output(0), ov::op::BroadcastType::BIDIRECTIONAL);subgraph_nodes.insert(subgraph_nodes.end(), {new_shape_op});}@@ -465,26 +468,25 @@ ov::Output<ov::Node> reshape_input_for_matmul(const ov::Output<ov::Node>& input_// compute a product of a sub-shape for separate labelsov::OutputVector separate_parts;- auto reduce_axis_const = ov::op::v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {0});+ auto reduce_axis_const = v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {0});if (common_sub_shape.size() > 0 && separate_sub_shape.size() == 0) {// in this case new dimension corresponding to separate labels must be added// since MatMul operation is not possible to do without separate dimensions if the// common dimension presents- auto separate_new_dim = ov::op::v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {1});+ auto separate_new_dim = v0::Constant::create(ov::element::Type_t::i64, ov::Shape{1}, {1});separate_parts.push_back(separate_new_dim);subgraph_nodes.insert(subgraph_nodes.end(), {separate_new_dim});} else if (separate_sub_shape.size() > 0) {// in this case compute a product of separate dimension sizes since they must be// presented with just one dimension for MatMul- auto separate_shape_prod =- std::make_shared<ov::op::v1::ReduceProd>(separate_sub_shape[0], reduce_axis_const, true);+ auto separate_shape_prod = std::make_shared<v1::ReduceProd>(separate_sub_shape[0], reduce_axis_const, true);separate_parts.push_back(separate_shape_prod->output(0));subgraph_nodes.insert(subgraph_nodes.end(), {reduce_axis_const, separate_shape_prod});}ov::OutputVector reduced_sub_shape_prod;if (reduced_sub_shape.size() > 0) {- auto const_0 = ov::op::v0::Constant::create(ov::element::i32, {1}, {0});- auto product = std::make_shared<ov::op::v1::ReduceProd>(reduced_sub_shape[0], const_0, true);+ auto const_0 = v0::Constant::create(ov::element::i32, {1}, {0});+ auto product = std::make_shared<v1::ReduceProd>(reduced_sub_shape[0], const_0, true);subgraph_nodes.insert(subgraph_nodes.end(), {reduce_axis_const, const_0, product});reduced_sub_shape_prod.push_back(product->output(0));}@@ -505,16 +507,16 @@ ov::Output<ov::Node> reshape_input_for_matmul(const ov::Output<ov::Node>& input_return input_node;}- auto new_shape_op = std::make_shared<ov::op::v0::Concat>(new_shape_parts, 0);+ auto new_shape_op = std::make_shared<v0::Concat>(new_shape_parts, 0);// if new shape is possible to compute on the shape infer stage, insert Constant node immediately// in order to prevent repeated computing during constant-folding pass- std::shared_ptr<ov::op::v1::Reshape> reshaped_input_op;+ std::shared_ptr<v1::Reshape> reshaped_input_op;if (auto new_shape_const = ov::util::get_constant_from_source(new_shape_op)) {- reshaped_input_op = std::make_shared<ov::op::v1::Reshape>(input_node, new_shape_const, false);+ reshaped_input_op = std::make_shared<v1::Reshape>(input_node, new_shape_const, false);subgraph_nodes.insert(subgraph_nodes.end(), {new_shape_const});} else {- reshaped_input_op = std::make_shared<ov::op::v1::Reshape>(input_node, new_shape_op->output(0), false);+ reshaped_input_op = std::make_shared<v1::Reshape>(input_node, new_shape_op->output(0), false);subgraph_nodes.insert(subgraph_nodes.end(), {new_shape_op});}@@ -556,8 +558,8 @@ void transpose_input(ov::OutputVector& input_nodes,// find permutation that establishes bijection between the input subscript// and the required oneconst auto& input_node = input_nodes[input_ind];- const auto labels = ov::op::v7::Einsum::extract_labels(input_subscript);- const auto required_labels = ov::op::v7::Einsum::extract_labels(required_subscript);+ const auto labels = v7::Einsum::extract_labels(input_subscript);+ const auto required_labels = v7::Einsum::extract_labels(required_subscript);const auto label_dim_map = compute_label_dim_map(input_node.get_partial_shape().rank(), input_subscript);for (const auto& required_label : required_labels) {const auto label_dims_it = label_dim_map.find(required_label);@@ -568,8 +570,8 @@ void transpose_input(ov::OutputVector& input_nodes,// create a sub-graph for transposing into the required layoutconst auto permutation_const =- ov::op::v0::Constant::create(ov::element::Type_t::i64, ov::Shape{permutation.size()}, permutation);- const auto transpose = std::make_shared<ov::op::v1::Transpose>(input_node, permutation_const);+ v0::Constant::create(ov::element::Type_t::i64, ov::Shape{permutation.size()}, permutation);+ const auto transpose = std::make_shared<v1::Transpose>(input_node, permutation_const);// update a vector of inputs and input subscriptsinput_nodes[input_ind] = transpose->output(0);@@ -605,7 +607,7 @@ void reduce_input(ov::OutputVector& input_nodes,// compute output shape and axes to reducestd::set<int64_t> reduced_axes;- const auto labels = ov::op::v7::Einsum::extract_labels(input_subscripts[input_ind]);+ const auto labels = v7::Einsum::extract_labels(input_subscripts[input_ind]);auto label_dim_map = compute_label_dim_map(input_node.get_partial_shape().rank(), input_subscript);std::string new_input_subscript = "";@@ -633,8 +635,8 @@ void reduce_input(ov::OutputVector& input_nodes,// reduce by summed up elements along dimension for which label is met just onceconst std::vector<int64_t> reduced_axes_vec{reduced_axes.cbegin(), reduced_axes.cend()};const auto axes_const =- ov::op::v0::Constant::create(ov::element::Type_t::i64, ov::Shape{reduced_axes.size()}, reduced_axes_vec);- const auto reduce_sum = std::make_shared<ov::op::v1::ReduceSum>(input_node, axes_const, false);+ v0::Constant::create(ov::element::Type_t::i64, ov::Shape{reduced_axes.size()}, reduced_axes_vec);+ const auto reduce_sum = std::make_shared<v1::ReduceSum>(input_node, axes_const, false);// update a vector of inputs and input subscriptsinput_nodes[input_ind] = reduce_sum->output(0);input_subscripts[input_ind] = new_input_subscript;@@ -664,7 +666,7 @@ void prepare_diagonal_extraction_data(const std::string& input_subscript,std::vector<std::string>& unrepeated_labels,ov::AxisVector& reduced_axes) {static const std::string ellipsis = "...";- const auto labels = ov::op::v7::Einsum::extract_labels(input_subscript);+ const auto labels = v7::Einsum::extract_labels(input_subscript);std::vector<std::string> repeated_labels_with_duplicates;size_t reduced_dim = 1;for (const auto& label : labels) {@@ -750,15 +752,15 @@ void extract_diagonal(ov::OutputVector& inputs,transpose_input(inputs, input_subscripts, resultant_subscript, input_ind, subgraph_nodes);// Create a ShapeOf operation to get the shape of the input tensor- const auto& input_shape = std::make_shared<ov::op::v3::ShapeOf>(input_node);+ const auto& input_shape = std::make_shared<v3::ShapeOf>(input_node);ov::NodeVector begins;ov::NodeVector ends;// Compute the label to dimension map for the transposed input subscriptconst auto transposed_label_dim_map =compute_label_dim_map(input_node.get_partial_shape().rank(), resultant_subscript_with_duplicates);- const auto& const_0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});- const auto& const_1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});+ const auto& const_0 = v0::Constant::create(ov::element::i64, {1}, {0});+ const auto& const_1 = v0::Constant::create(ov::element::i64, {1}, {1});subgraph_nodes.insert(subgraph_nodes.end(), {input_shape, const_0, const_1});ov::NodeVector convenient_shape_vector;ov::NodeVector shape_after_pad_vector;@@ -769,20 +771,19 @@ void extract_diagonal(ov::OutputVector& inputs,OPENVINO_ASSERT(dim_map_repeated_label != transposed_label_dim_map.end());const auto& repeated_label_dims = dim_map_repeated_label->second;const auto& repeated_label_indices =- ov::op::v0::Constant::create(ov::element::i64, {repeated_label_dims.size()}, repeated_label_dims);+ v0::Constant::create(ov::element::i64, {repeated_label_dims.size()}, repeated_label_dims);const auto& repeated_label_indices_len =- ov::op::v0::Constant::create(ov::element::i64, {}, {repeated_label_dims.size()});- const auto& repeated_dimensions =- std::make_shared<ov::op::v7::Gather>(input_shape, repeated_label_indices, const_0);- const auto& repeated_dimension = std::make_shared<ov::op::v7::Gather>(repeated_dimensions, const_0, const_0);- const auto& range_max_val = std::make_shared<ov::op::v1::Power>(repeated_dimension, repeated_label_indices_len);- const auto& step_numerator = std::make_shared<ov::op::v1::Subtract>(range_max_val, const_1);- const auto& step_denominator = std::make_shared<ov::op::v1::Subtract>(repeated_dimension, const_1);- const auto& step_denominator_but_not_0 = std::make_shared<ov::op::v1::Maximum>(step_denominator, const_1);- const auto& step_numerator_but_not_0 = std::make_shared<ov::op::v1::Maximum>(step_numerator, const_1);- const auto& step = std::make_shared<ov::op::v1::Divide>(step_numerator_but_not_0, step_denominator_but_not_0);- const auto& end = std::make_shared<ov::op::v1::Subtract>(step, const_1);- const auto& reduced_size = std::make_shared<ov::op::v1::ReduceProd>(repeated_dimensions, const_0, true);+ v0::Constant::create(ov::element::i64, {}, {repeated_label_dims.size()});+ const auto& repeated_dimensions = std::make_shared<v7::Gather>(input_shape, repeated_label_indices, const_0);+ const auto& repeated_dimension = std::make_shared<v7::Gather>(repeated_dimensions, const_0, const_0);+ const auto& range_max_val = std::make_shared<v1::Power>(repeated_dimension, repeated_label_indices_len);+ const auto& step_numerator = std::make_shared<v1::Subtract>(range_max_val, const_1);+ const auto& step_denominator = std::make_shared<v1::Subtract>(repeated_dimension, const_1);+ const auto& step_denominator_but_not_0 = std::make_shared<v1::Maximum>(step_denominator, const_1);+ const auto& step_numerator_but_not_0 = std::make_shared<v1::Maximum>(step_numerator, const_1);+ const auto& step = std::make_shared<v1::Divide>(step_numerator_but_not_0, step_denominator_but_not_0);+ const auto& end = std::make_shared<v1::Subtract>(step, const_1);+ const auto& reduced_size = std::make_shared<v1::ReduceProd>(repeated_dimensions, const_0, true);// Flatten dimensions of repeated labelconvenient_shape_vector.push_back(reduced_size);// Compute the new shape after padding, separate diagonal elements@@ -819,26 +820,25 @@ void extract_diagonal(ov::OutputVector& inputs,}// Gather the dimensions for unrepeated labels in single call- const auto& unrepeated_dimensions_indices = ov::op::v0::Constant::create(ov::element::i64,- {unrepeated_dimension_indices_vec.size()},- unrepeated_dimension_indices_vec);+ const auto& unrepeated_dimensions_indices = v0::Constant::create(ov::element::i64,+ {unrepeated_dimension_indices_vec.size()},+ unrepeated_dimension_indices_vec);const auto& unrepeated_dimensions =- std::make_shared<ov::op::v7::Gather>(input_shape, unrepeated_dimensions_indices, const_0);+ std::make_shared<v7::Gather>(input_shape, unrepeated_dimensions_indices, const_0);subgraph_nodes.insert(subgraph_nodes.end(), {unrepeated_dimensions_indices, unrepeated_dimensions});convenient_shape_vector.push_back(unrepeated_dimensions);shape_after_pad_vector.push_back(unrepeated_dimensions);// Create the new shape for the input tensor that would flatten repeated label dimensions- const auto& convenient_shape = std::make_shared<ov::op::v0::Concat>(convenient_shape_vector, 0);- const auto& reshaped_input = std::make_shared<ov::op::v1::Reshape>(input_node, convenient_shape, false);+ const auto& convenient_shape = std::make_shared<v0::Concat>(convenient_shape_vector, 0);+ const auto& reshaped_input = std::make_shared<v1::Reshape>(input_node, convenient_shape, false);// Create the pads for the label-flattened input tensor to extract the diagonal elements- const auto& pads_end = std::make_shared<ov::op::v0::Concat>(ends, 0);- const auto& pads_begin = std::make_shared<ov::op::v0::Concat>(begins, 0);- const auto& pad =- std::make_shared<ov::op::v1::Pad>(reshaped_input, pads_begin, pads_end, ov::op::PadMode::CONSTANT);+ const auto& pads_end = std::make_shared<v0::Concat>(ends, 0);+ const auto& pads_begin = std::make_shared<v0::Concat>(begins, 0);+ const auto& pad = std::make_shared<v1::Pad>(reshaped_input, pads_begin, pads_end, ov::op::PadMode::CONSTANT);// Reshape the tensor after padding to extract the diagonal elements to separate dimensions- const auto& reshape_after_pad_target = std::make_shared<ov::op::v0::Concat>(shape_after_pad_vector, 0);- const auto& reshape_after_pad = std::make_shared<ov::op::v1::Reshape>(pad, reshape_after_pad_target, false);+ const auto& reshape_after_pad_target = std::make_shared<v0::Concat>(shape_after_pad_vector, 0);+ const auto& reshape_after_pad = std::make_shared<v1::Reshape>(pad, reshape_after_pad_target, false);subgraph_nodes.insert(subgraph_nodes.end(),{convenient_shape, pads_begin, pads_end, reshaped_input, pad, reshape_after_pad_target, reshape_after_pad});@@ -846,14 +846,14 @@ void extract_diagonal(ov::OutputVector& inputs,// Gather the diagonal elementsstd::shared_ptr<ov::Node> gather = reshape_after_pad;for (auto axis : reduced_axes) {- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, {1}, {axis});- gather = std::make_shared<ov::op::v7::Gather>(gather, const_0, axis_const);+ auto axis_const = v0::Constant::create(ov::element::i64, {1}, {axis});+ gather = std::make_shared<v7::Gather>(gather, const_0, axis_const);subgraph_nodes.insert(subgraph_nodes.end(), {axis_const, gather});}// Squeeze the gathered tensor to remove the reduced axes- const auto& reduced_indices = ov::op::v0::Constant::create(ov::element::i64, {reduced_axes.size()}, reduced_axes);- const auto& out_node = std::make_shared<ov::op::v0::Squeeze>(gather, reduced_indices);+ const auto& reduced_indices = v0::Constant::create(ov::element::i64, {reduced_axes.size()}, reduced_axes);+ const auto& out_node = std::make_shared<v0::Squeeze>(gather, reduced_indices);subgraph_nodes.insert(subgraph_nodes.end(), {reduced_indices, out_node});// Update the input tensor and its subscript@@ -958,9 +958,9 @@ void contract_two_inputs(ov::OutputVector& input_nodes,// neither the output subscript nor the input subscripts for other Einsum inputs excluding// two given inputsauto& input_subscript1 = input_subscripts[input_ind1];- auto labels1 = ov::op::v7::Einsum::extract_labels(input_subscript1);+ auto labels1 = v7::Einsum::extract_labels(input_subscript1);auto& input_subscript2 = input_subscripts[input_ind2];- auto labels2 = ov::op::v7::Einsum::extract_labels(input_subscript2);+ auto labels2 = v7::Einsum::extract_labels(input_subscript2);std::string common_part = "";std::string separate_part1 = "";std::string separate_part2 = "";@@ -1030,9 +1030,8 @@ void contract_two_inputs(ov::OutputVector& input_nodes,auto unsqueeze_output2 = unsqueeze_input(input_node2, unsqueeze_axis2, subgraph_nodes);// multiply both operands with broadcasting- auto mul = std::make_shared<ov::op::v1::Multiply>(unsqueeze_output1,- unsqueeze_output2,- ov::op::AutoBroadcastType::NUMPY);+ auto mul =+ std::make_shared<v1::Multiply>(unsqueeze_output1, unsqueeze_output2, ov::op::AutoBroadcastType::NUMPY);// update input operand and input subscript for Einsum operationupdate_operands(input_nodes, input_subscripts, input_ind1, input_ind2, mul->output(0), resultant_subscript);@@ -1095,8 +1094,8 @@ void contract_two_inputs(ov::OutputVector& input_nodes,ov::OutputVector common_sub_shape, separate1_sub_shape, separate2_sub_shape;- auto data_shape1 = std::make_shared<ov::op::v3::ShapeOf>(input_node1);- auto data_shape2 = std::make_shared<ov::op::v3::ShapeOf>(input_node2);+ auto data_shape1 = std::make_shared<v3::ShapeOf>(input_node1);+ auto data_shape2 = std::make_shared<v3::ShapeOf>(input_node2);subgraph_nodes.insert(subgraph_nodes.end(), {data_shape1});subgraph_nodes.insert(subgraph_nodes.end(), {data_shape2});common_sub_shape = compute_sub_shape(data_shape1, common_dims_begin, common_dims_end, subgraph_nodes);@@ -1173,7 +1172,7 @@ void contract_two_inputs(ov::OutputVector& input_nodes,// step 3. apply MatMul operation for formatted inputsbool transpose_a = (is_separate_first1 ? false : true);bool transpose_b = (is_separate_first2 ? true : false);- auto matmul = std::make_shared<ov::op::v0::MatMul>(matmul_operand1, matmul_operand2, transpose_a, transpose_b);+ auto matmul = std::make_shared<v0::MatMul>(matmul_operand1, matmul_operand2, transpose_a, transpose_b);// step 4. reshape back by unrolling dimensions corresponding to separate labels if needed// now dimensions corresponding to reduced labels are reduced by the MatMul operation@@ -1191,16 +1190,16 @@ void contract_two_inputs(ov::OutputVector& input_nodes,new_shape.insert(new_shape.end(), common_sub_shape.begin(), common_sub_shape.end());new_shape.insert(new_shape.end(), separate1_sub_shape.begin(), separate1_sub_shape.end());new_shape.insert(new_shape.end(), separate2_sub_shape.begin(), separate2_sub_shape.end());- auto result_shape_op = std::make_shared<ov::op::v0::Concat>(new_shape, 0);+ auto result_shape_op = std::make_shared<v0::Concat>(new_shape, 0);// if new shape is possible to compute on the shape infer stage, insert Constant node immediately// in order to prevent repeated computing during constant-folding pass- std::shared_ptr<ov::op::v1::Reshape> result_op;+ std::shared_ptr<v1::Reshape> result_op;if (auto new_shape_const = ov::util::get_constant_from_source(result_shape_op)) {- result_op = std::make_shared<ov::op::v1::Reshape>(matmul->output(0), new_shape_const, false);+ result_op = std::make_shared<v1::Reshape>(matmul->output(0), new_shape_const, false);subgraph_nodes.insert(subgraph_nodes.end(), {result_shape_op, new_shape_const});} else {- result_op = std::make_shared<ov::op::v1::Reshape>(matmul->output(0), result_shape_op->output(0), false);+ result_op = std::make_shared<v1::Reshape>(matmul->output(0), result_shape_op->output(0), false);subgraph_nodes.insert(subgraph_nodes.end(), {result_shape_op});}@@ -1238,7 +1237,7 @@ void fix_inputs_with_0d_ellipsis(ov::OutputVector& input_nodes,bool all_no_ellipsis_or_empty = true;for (size_t i = 0; i < input_nodes.size(); ++i) {- const auto& labels = ov::op::v7::Einsum::extract_labels(input_subscripts[i]);+ const auto& labels = v7::Einsum::extract_labels(input_subscripts[i]);bool has_ellipsis_in_input = std::find(labels.begin(), labels.end(), ellipsis) != labels.end();has_ellipsis |= has_ellipsis_in_input;all_no_ellipsis_or_empty &=@@ -1260,7 +1259,7 @@ void fix_inputs_with_0d_ellipsis(ov::OutputVector& input_nodes,}} else {for (size_t i = 0; i < input_nodes.size(); ++i) {- const auto& labels = ov::op::v7::Einsum::extract_labels(input_subscripts[i]);+ const auto& labels = v7::Einsum::extract_labels(input_subscripts[i]);if (std::find(labels.begin(), labels.end(), ellipsis) != labels.end() &&input_nodes[i].get_partial_shape().size() + 1 == labels.size()) {input_nodes[i] = unsqueeze_input(@@ -1293,9 +1292,9 @@ void fix_inputs_with_0d_ellipsis(ov::OutputVector& input_nodes,/// preserving the original node's name and runtime information.ov::pass::EinsumDecomposition::EinsumDecomposition() {MATCHER_SCOPE(EinsumDecomposition);- auto einsum = ov::pass::pattern::wrap_type<ov::op::v7::Einsum>();- matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {- auto einsum_node = ov::as_type_ptr<ov::op::v7::Einsum>(m.get_match_root());+ auto einsum = ov::pass::pattern::wrap_type<v7::Einsum>();+ matcher_pass_callback callback = [=](Matcher& m) {+ auto einsum_node = ov::as_type_ptr<v7::Einsum>(m.get_match_root());if (!einsum_node) {return false;}@@ -1304,7 +1303,7 @@ ov::pass::EinsumDecomposition::EinsumDecomposition() {auto equation = einsum_node->get_equation();std::vector<std::string> input_subscripts;std::string output_subscript;- ov::op::v7::Einsum::parse_equation(equation, input_subscripts, output_subscript);+ v7::Einsum::parse_equation(equation, input_subscripts, output_subscript);// create a list of input nodes with preserving their order// and a vector of sub-graph nodes for copy_runtime_info@@ -1353,6 +1352,6 @@ ov::pass::EinsumDecomposition::EinsumDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(einsum, matcher_name);+ auto m = std::make_shared<Matcher>(einsum, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/eye_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/eye_decomposition.cppindex 25793321d78..013d7fcd447 100644--- a/src/common/transformations/src/transformations/op_conversions/eye_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/eye_decomposition.cpp@@ -26,15 +26,21 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-namespace ov {-namespace pass {+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v9 = ov::op::v9;+namespace ov::pass {namespace {/** \brief Check if output is rank one and data type can be i32 or i64. */const auto is_rank_one_int_shape = [](const Output<Node>& output) -> bool {- return pattern::type_matches_any({element::i32, element::i64})(output) && pattern::has_static_shape()(output) &&- pattern::rank_equals(1)(output);+ return ov::pass::pattern::type_matches_any({element::i32, element::i64})(output) &&+ ov::pass::pattern::has_static_shape()(output) && ov::pass::pattern::rank_equals(1)(output);};/** \brief Predicate to check eye k node is valid. */@@ -65,34 +71,33 @@ std::shared_ptr<Node> make_eye_model(NodeRegistry& reg,const Output<Node>& width,const Output<Node>& k,element::Type dtype) {- const auto zero_int = reg.add(ov::op::v0::Constant::create(element::i64, Shape{1}, {0}));- const auto zero = reg.add(ov::op::v0::Constant::create(dtype, Shape{1}, {0}));- const auto one = reg.add(ov::op::v0::Constant::create(dtype, Shape{1}, {1}));+ const auto zero_int = reg.add(v0::Constant::create(element::i64, Shape{1}, {0}));+ const auto zero = reg.add(v0::Constant::create(dtype, Shape{1}, {0}));+ const auto one = reg.add(v0::Constant::create(dtype, Shape{1}, {1}));- const auto k_neg = reg.make<ov::op::v0::Negative>(k);- const auto k_axis = reg.make<ov::op::v0::Concat>(OutputVector{k_neg, k}, 0);+ const auto k_neg = reg.make<v0::Negative>(k);+ const auto k_axis = reg.make<v0::Concat>(OutputVector{k_neg, k}, 0);- const auto eye_shape = reg.make<ov::op::v0::Concat>(OutputVector{height, width}, 0);+ const auto eye_shape = reg.make<v0::Concat>(OutputVector{height, width}, 0);// Calculate eye zero padding and internal square eye size.- const auto pad_start = reg.make<ov::op::v1::Minimum>(eye_shape, reg.make<ov::op::v1::Maximum>(zero_int, k_axis));- const auto shape_pad_diff = reg.make<ov::op::v1::Subtract>(eye_shape, pad_start);- const auto eye_size = reg.make<ov::op::v1::ReduceMin>(shape_pad_diff, zero_int, true);- const auto pad_end = reg.make<ov::op::v1::Subtract>(shape_pad_diff, eye_size);+ const auto pad_start = reg.make<v1::Minimum>(eye_shape, reg.make<v1::Maximum>(zero_int, k_axis));+ const auto shape_pad_diff = reg.make<v1::Subtract>(eye_shape, pad_start);+ const auto eye_size = reg.make<v1::ReduceMin>(shape_pad_diff, zero_int, true);+ const auto pad_end = reg.make<v1::Subtract>(shape_pad_diff, eye_size);// Make 1d-eye as eye_size times of (1, zeros(eye_size)), trimmed at end by eye_size elements.- const auto zeros = reg.make<ov::op::v0::Tile>(zero, eye_size);- const auto one_followed_by_zeros = reg.make<ov::op::v0::Concat>(OutputVector{one, zeros}, 0);- const auto eye_1d = reg.make<ov::op::v1::Pad>(reg.make<ov::op::v0::Tile>(one_followed_by_zeros, eye_size),- zero_int,- reg.make<ov::op::v0::Negative>(eye_size),- op::PadMode::CONSTANT);+ const auto zeros = reg.make<v0::Tile>(zero, eye_size);+ const auto one_followed_by_zeros = reg.make<v0::Concat>(OutputVector{one, zeros}, 0);+ const auto eye_1d = reg.make<v1::Pad>(reg.make<v0::Tile>(one_followed_by_zeros, eye_size),+ zero_int,+ reg.make<v0::Negative>(eye_size),+ op::PadMode::CONSTANT);// Reshape 1d-eye to 2d-eye- const auto eye_2d =- reg.make<ov::op::v1::Reshape>(eye_1d, reg.make<ov::op::v0::Concat>(OutputVector{eye_size, eye_size}, 0), false);+ const auto eye_2d = reg.make<v1::Reshape>(eye_1d, reg.make<v0::Concat>(OutputVector{eye_size, eye_size}, 0), false);// Pad Eye to get final shape- return reg.make<ov::op::v1::Pad>(eye_2d, pad_start, pad_end, op::PadMode::CONSTANT);+ return reg.make<v1::Pad>(eye_2d, pad_start, pad_end, op::PadMode::CONSTANT);}/**@@ -105,12 +110,12 @@ std::shared_ptr<Node> make_eye_model(NodeRegistry& reg,* \return Pointer to decomposed eye model.*/std::shared_ptr<Node> make_eye_batches(NodeRegistry& reg, const Output<Node>& eye, const Output<Node>& batch) {- const auto eye_tile = reg.make<ov::op::v0::Constant>(element::i64, Shape{2}, 1);+ const auto eye_tile = reg.make<v0::Constant>(element::i64, Shape{2}, 1);// `batch_repeats` repeat eye matrix as tile only in higher dimensions than 1 by number(s) in batch parameter.- const auto batch_repeats = reg.make<ov::op::v0::Concat>(OutputVector{batch, eye_tile}, 0);+ const auto batch_repeats = reg.make<v0::Concat>(OutputVector{batch, eye_tile}, 0);- return reg.make<ov::op::v0::Tile>(eye, batch_repeats);+ return reg.make<v0::Tile>(eye, batch_repeats);}} // namespace@@ -118,18 +123,18 @@ std::shared_ptr<Node> make_eye_batches(NodeRegistry& reg, const Output<Node>& eyEyeDecomposition::EyeDecomposition() {MATCHER_SCOPE(EyeDecomposition);- auto p_height = pattern::any_input();- auto p_width = pattern::any_input();- auto p_k = pattern::wrap_type<ov::op::v0::Constant>(k_predicate);- auto p_batch = pattern::wrap_type<ov::op::v0::Constant>(batch_predicate);+ auto p_height = any_input();+ auto p_width = any_input();+ auto p_k = wrap_type<v0::Constant>(k_predicate);+ auto p_batch = wrap_type<v0::Constant>(batch_predicate);- auto p_eye_no_batch = pattern::wrap_type<ov::op::v9::Eye>({p_height, p_width, p_k});- auto p_eye_batch = pattern::wrap_type<ov::op::v9::Eye>({p_height, p_width, p_k, p_batch});+ auto p_eye_no_batch = wrap_type<v9::Eye>({p_height, p_width, p_k});+ auto p_eye_batch = wrap_type<v9::Eye>({p_height, p_width, p_k, p_batch});- auto p_eye = std::make_shared<pattern::op::Or>(OutputVector{p_eye_batch, p_eye_no_batch});+ auto p_eye = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{p_eye_batch, p_eye_no_batch});- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {- auto m_eye = ov::as_type_ptr<ov::op::v9::Eye>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto m_eye = ov::as_type_ptr<v9::Eye>(m.get_match_root());if ((!m_eye) || transformation_callback(m_eye)) {return false;@@ -155,9 +160,8 @@ EyeDecomposition::EyeDecomposition() {return true;};- auto m = std::make_shared<pattern::Matcher>(p_eye, matcher_name);+ auto m = std::make_shared<Matcher>(p_eye, matcher_name);register_matcher(m, callback);}-} // namespace pass-} // namespace ov+} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/op_conversions/fake_convert_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/fake_convert_decomposition.cppindex ca5d6540958..97fcf116eb6 100644--- a/src/common/transformations/src/transformations/op_conversions/fake_convert_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/fake_convert_decomposition.cpp@@ -21,14 +21,19 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v13 = ov::op::v13;ov::pass::FakeConvertDecomposition::FakeConvertDecomposition() {MATCHER_SCOPE(FakeConvertDecomposition);- auto fake_convert_m = ov::pass::pattern::wrap_type<ov::op::v13::FakeConvert>();+ auto fake_convert_m = ov::pass::pattern::wrap_type<v13::FakeConvert>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();const auto fake_convert =- ov::as_type_ptr<ov::op::v13::FakeConvert>(pattern_to_output.at(fake_convert_m).get_node_shared_ptr());+ ov::as_type_ptr<v13::FakeConvert>(pattern_to_output.at(fake_convert_m).get_node_shared_ptr());if (fake_convert == nullptr || transformation_callback(fake_convert)) {return false;@@ -41,14 +46,14 @@ ov::pass::FakeConvertDecomposition::FakeConvertDecomposition() {ov::pass::NodeRegistry decomp_ops;if (input_type != input_scale.get_element_type()) {input_type = input_scale.get_element_type();- data = decomp_ops.make<ov::op::v0::Convert>(data, input_type);+ data = decomp_ops.make<v0::Convert>(data, input_type);}- std::shared_ptr<Node> result = decomp_ops.make<ov::op::v1::Multiply>(data, input_scale);+ std::shared_ptr<Node> result = decomp_ops.make<v1::Multiply>(data, input_scale);bool with_shift = fake_convert->get_input_size() == 3;if (with_shift) {const auto& shift_const = fake_convert->input_value(2);- auto input_shift = decomp_ops.make<ov::op::v1::Subtract>(result, shift_const);+ auto input_shift = decomp_ops.make<v1::Subtract>(result, shift_const);if (ov::op::util::can_eliminate_eltwise_node(input_shift, shift_const, result)) {with_shift = false;} else {@@ -70,29 +75,29 @@ ov::pass::FakeConvertDecomposition::FakeConvertDecomposition() {}}();- result = decomp_ops.make<ov::op::v0::Clamp>(result, lower_bound, upper_bound);- result = decomp_ops.make<ov::op::v0::Convert>(result, fake_convert->get_destination_element_type());- result = decomp_ops.make<ov::op::v0::Convert>(result, input_type);+ result = decomp_ops.make<v0::Clamp>(result, lower_bound, upper_bound);+ result = decomp_ops.make<v0::Convert>(result, fake_convert->get_destination_element_type());+ result = decomp_ops.make<v0::Convert>(result, input_type);// Note: upconvert part is composed as Subtract->Multiply sequence// in order to match LPT dequantization operations representationif (with_shift) {- const auto negative = decomp_ops.make<ov::op::v0::Negative>(fake_convert->input_value(2));+ const auto negative = decomp_ops.make<v0::Negative>(fake_convert->input_value(2));if (const auto constant = ov::util::get_constant_from_source(negative)) {- result = decomp_ops.make<ov::op::v1::Subtract>(result, constant);+ result = decomp_ops.make<v1::Subtract>(result, constant);} else {- result = decomp_ops.make<ov::op::v1::Subtract>(result, negative);+ result = decomp_ops.make<v1::Subtract>(result, negative);}}- const auto power_const = decomp_ops.make<ov::op::v0::Constant>(input_type, Shape{}, -1.f);- const auto power = decomp_ops.make<ov::op::v1::Power>(input_scale, power_const);+ const auto power_const = decomp_ops.make<v0::Constant>(input_type, Shape{}, -1.f);+ const auto power = decomp_ops.make<v1::Power>(input_scale, power_const);if (const auto constant = ov::util::get_constant_from_source(power)) {- result = decomp_ops.make<ov::op::v1::Multiply>(result, constant);+ result = decomp_ops.make<v1::Multiply>(result, constant);} else {- result = decomp_ops.make<ov::op::v1::Multiply>(result, power);+ result = decomp_ops.make<v1::Multiply>(result, power);}if (result->get_output_element_type(0) != fake_convert->get_output_element_type(0)) {- result = decomp_ops.make<ov::op::v0::Convert>(result, fake_convert->get_output_element_type(0));+ result = decomp_ops.make<v0::Convert>(result, fake_convert->get_output_element_type(0));}result->set_friendly_name(fake_convert->get_friendly_name());@@ -101,6 +106,6 @@ ov::pass::FakeConvertDecomposition::FakeConvertDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(fake_convert_m, matcher_name);+ auto m = std::make_shared<Matcher>(fake_convert_m, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/fq_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/fq_decomposition.cppindex 589249b0b51..e6c0e0c7f1e 100644--- a/src/common/transformations/src/transformations/op_conversions/fq_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/fq_decomposition.cpp@@ -23,18 +23,24 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v5 = ov::op::v5;namespace {-bool isValidRangesInputs(const std::shared_ptr<ov::op::v0::FakeQuantize>& fq) {+bool isValidRangesInputs(const std::shared_ptr<v0::FakeQuantize>& fq) {auto il = fq->input_value(1);auto ih = fq->input_value(2);- auto greater_equal = std::make_shared<ov::op::v1::GreaterEqual>(il, ih);+ auto greater_equal = std::make_shared<v1::GreaterEqual>(il, ih);ov::OutputVector result(1);if (!greater_equal->constant_fold(result, greater_equal->input_values()))return false;- auto res_node = ov::as_type_ptr<const ov::op::v0::Constant>(result[0].get_node_shared_ptr());+ auto res_node = ov::as_type_ptr<const v0::Constant>(result[0].get_node_shared_ptr());const std::vector<bool> comp_result = res_node->cast_vector<bool>();@@ -47,17 +53,17 @@ bool isValidRangesInputs(const std::shared_ptr<ov::op::v0::FakeQuantize>& fq) {ov::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() {MATCHER_SCOPE(FakeQuantizeDecomposition);- auto data = pattern::any_input();- auto il = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto ih = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto ol = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto oh = ov::pass::pattern::wrap_type<ov::op::v0::Constant>();- auto fake_quantize = ov::pass::pattern::wrap_type<ov::op::v0::FakeQuantize>({data, il, ih, ol, oh});-- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto data = ov::pass::pattern::any_input();+ auto il = wrap_type<v0::Constant>();+ auto ih = wrap_type<v0::Constant>();+ auto ol = wrap_type<v0::Constant>();+ auto oh = wrap_type<v0::Constant>();+ auto fake_quantize = wrap_type<v0::FakeQuantize>({data, il, ih, ol, oh});++ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();const auto fake_quantize_node =- ov::as_type_ptr<ov::op::v0::FakeQuantize>(pattern_to_output.at(fake_quantize).get_node_shared_ptr());+ ov::as_type_ptr<v0::FakeQuantize>(pattern_to_output.at(fake_quantize).get_node_shared_ptr());if (fake_quantize_node == nullptr || transformation_callback(fake_quantize_node) ||!isValidRangesInputs(fake_quantize_node)) {@@ -74,61 +80,60 @@ ov::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() {ov::NodeVector decomp_ops;if (input_type != input_low.get_element_type()) {input_type = input_low.get_element_type();- data = std::make_shared<ov::op::v0::Convert>(data, input_type);+ data = std::make_shared<v0::Convert>(data, input_type);decomp_ops.push_back(data.get_node_shared_ptr());}// if we set input_low or input_high in formula we got output = output_low and output = output_high respectively// so we just clamp x- const auto max = std::make_shared<ov::op::v1::Maximum>(data, input_low);- const auto min = std::make_shared<ov::op::v1::Minimum>(max, input_high);+ const auto max = std::make_shared<v1::Maximum>(data, input_low);+ const auto min = std::make_shared<v1::Minimum>(max, input_high);decomp_ops.push_back(max);decomp_ops.push_back(min);// (levels-1)const auto levels_minus_one =- std::make_shared<ov::op::v0::Constant>(input_type, Shape{}, fake_quantize_node->get_levels() - 1);+ std::make_shared<v0::Constant>(input_type, Shape{}, fake_quantize_node->get_levels() - 1);decomp_ops.push_back(levels_minus_one);// (input_high - input_low)- const auto subInHighLow = std::make_shared<ov::op::v1::Subtract>(input_high, input_low);+ const auto subInHighLow = std::make_shared<v1::Subtract>(input_high, input_low);// (levels-1) / (input_high - input_low)- const auto isc = std::make_shared<ov::op::v1::Divide>(levels_minus_one, subInHighLow);+ const auto isc = std::make_shared<v1::Divide>(levels_minus_one, subInHighLow);// input_low * (levels-1) / (input_high - input_low)- const auto ish = std::make_shared<ov::op::v1::Multiply>(input_low, isc);+ const auto ish = std::make_shared<v1::Multiply>(input_low, isc);decomp_ops.push_back(subInHighLow);decomp_ops.push_back(isc);decomp_ops.push_back(ish);// x * (levels-1) / (input_high - input_low)- const auto after_isc_apply = std::make_shared<ov::op::v1::Multiply>(min, isc);+ const auto after_isc_apply = std::make_shared<v1::Multiply>(min, isc);// x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)- const auto after_ish_apply = std::make_shared<ov::op::v1::Subtract>(after_isc_apply, ish);+ const auto after_ish_apply = std::make_shared<v1::Subtract>(after_isc_apply, ish);decomp_ops.push_back(after_isc_apply);decomp_ops.push_back(after_ish_apply);// round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low))- const auto round =- std::make_shared<ov::op::v5::Round>(after_ish_apply, ov::op::v5::Round::RoundMode::HALF_TO_EVEN);+ const auto round = std::make_shared<v5::Round>(after_ish_apply, v5::Round::RoundMode::HALF_TO_EVEN);decomp_ops.push_back(round);// (output_high - output_low)- const auto sub_out_high_low = std::make_shared<ov::op::v1::Subtract>(output_high, output_low);+ const auto sub_out_high_low = std::make_shared<v1::Subtract>(output_high, output_low);// (output_high - output_low) / (levels-1)- const auto osc = std::make_shared<ov::op::v1::Divide>(sub_out_high_low, levels_minus_one);+ const auto osc = std::make_shared<v1::Divide>(sub_out_high_low, levels_minus_one);decomp_ops.push_back(sub_out_high_low);decomp_ops.push_back(osc);// round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) *// (output_high - output_low) / (levels-1)- const auto after_osc_apply = std::make_shared<ov::op::v1::Multiply>(round, osc);+ const auto after_osc_apply = std::make_shared<v1::Multiply>(round, osc);// round(x * (levels-1) / (input_high - input_low) - input_low * (levels-1) / (input_high - input_low)) *// (output_high - output_low) / (levels-1) + output_low- std::shared_ptr<Node> result = std::make_shared<ov::op::v1::Add>(after_osc_apply, output_low);+ std::shared_ptr<Node> result = std::make_shared<v1::Add>(after_osc_apply, output_low);decomp_ops.push_back(after_osc_apply);decomp_ops.push_back(result);if (result->get_output_element_type(0) != fake_quantize_node->get_output_element_type(0)) {- result = std::make_shared<ov::op::v0::Convert>(result, fake_quantize_node->get_output_element_type(0));+ result = std::make_shared<v0::Convert>(result, fake_quantize_node->get_output_element_type(0));decomp_ops.push_back(result);}@@ -138,6 +143,6 @@ ov::pass::FakeQuantizeDecomposition::FakeQuantizeDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(fake_quantize, matcher_name);+ auto m = std::make_shared<Matcher>(fake_quantize, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/gelu7_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/gelu7_downgrade.cppindex b92a428b853..29925f10b89 100644--- a/src/common/transformations/src/transformations/op_conversions/gelu7_downgrade.cpp+++ b/src/common/transformations/src/transformations/op_conversions/gelu7_downgrade.cpp@@ -13,13 +13,16 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v7 = ov::op::v7;ov::pass::Gelu7Downgrade::Gelu7Downgrade() {MATCHER_SCOPE(Gelu7Downgrade);- auto gelu = ov::pass::pattern::wrap_type<ov::op::v7::Gelu>();+ auto gelu = ov::pass::pattern::wrap_type<v7::Gelu>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();- auto gelu_node = ov::as_type_ptr<ov::op::v7::Gelu>(pattern_to_output.at(gelu).get_node_shared_ptr());+ auto gelu_node = ov::as_type_ptr<v7::Gelu>(pattern_to_output.at(gelu).get_node_shared_ptr());if (gelu_node == nullptr || transformation_callback(gelu_node)) {return false;@@ -32,6 +35,6 @@ ov::pass::Gelu7Downgrade::Gelu7Downgrade() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(gelu, matcher_name);+ auto m = std::make_shared<Matcher>(gelu, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/group_normalization_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/group_normalization_decomposition.cppindex d2612a99e4b..240ed47edaf 100644--- a/src/common/transformations/src/transformations/op_conversions/group_normalization_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/group_normalization_decomposition.cpp@@ -32,6 +32,7 @@ using namespace ov;using namespace op;using namespace ov::pass;+using ov::pass::pattern::Matcher;namespace {// This function creates a shape to which we need to reshape the input// before normalization.@@ -65,9 +66,9 @@ std::shared_ptr<Node> get_range(NodeRegistry& reg, int64_t start, int64_t stop)ov::pass::GroupNormalizationDecomposition::GroupNormalizationDecomposition() {MATCHER_SCOPE(GroupNormalizationDecomposition);- auto group_norm_pattern = pattern::wrap_type<v12::GroupNormalization>();+ auto group_norm_pattern = ov::pass::pattern::wrap_type<v12::GroupNormalization>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& matcher) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& matcher) {NodeRegistry reg;const auto group_norm_node = ov::as_type_ptr<v12::GroupNormalization>(matcher.get_match_root());@@ -111,6 +112,6 @@ ov::pass::GroupNormalizationDecomposition::GroupNormalizationDecomposition() {return true;};- auto m = make_shared<pattern::Matcher>(group_norm_pattern, matcher_name);+ auto m = make_shared<Matcher>(group_norm_pattern, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cppindex 1084cd72604..987643418d2 100644--- a/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/group_query_attention_decomposition.cpp@@ -31,11 +31,19 @@#include "openvino/op/unsqueeze.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v8 = ov::op::v8;+namespace v13 = ov::op::v13;ov::pass::GroupQueryAttentionDecomposition::GroupQueryAttentionDecomposition() {MATCHER_SCOPE(GroupQeuryAttentionDecomposition);auto pattern_node = ov::pass::pattern::wrap_type<ov::op::internal::GroupQueryAttention>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto node = ov::as_type_ptr<ov::op::internal::GroupQueryAttention>(pattern_to_output.at(pattern_node).get_node_shared_ptr());@@ -49,14 +57,12 @@ ov::pass::GroupQueryAttentionDecomposition::GroupQueryAttentionDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(pattern_node, matcher_name);+ auto m = std::make_shared<Matcher>(pattern_node, matcher_name);register_matcher(m, callback);}ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(std::shared_ptr<ov::op::internal::GroupQueryAttention> node) {- using namespace ov::op;-const auto num_heads = node->get_num_heads();const auto kv_num_heads = node->get_kv_num_heads();const auto scale = node->get_scale();@@ -203,7 +209,6 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::decompose(ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::make_split(const ov::Output<ov::Node>& value,int64_t num_splits,int64_t axis) {- using namespace ov::op;const auto axis_node = register_new_node(v0::Constant::create(ov::element::i64, ov::Shape{}, {axis}));const auto split = register_new_node<v1::Split>(value, axis_node, num_splits);@@ -211,9 +216,8 @@ ov::OutputVector ov::pass::GroupQueryAttentionDecomposition::make_split(const ov}std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::get_dimensions(- const std::shared_ptr<ov::op::v3::ShapeOf>& shape,+ const std::shared_ptr<v3::ShapeOf>& shape,const std::vector<int>& dims) {- using namespace ov::op;const auto zero = v0::Constant::create(ov::element::i32, ov::Shape{}, {0});const auto dims_const = v0::Constant::create(ov::element::i32, ov::Shape{dims.size()}, dims);return register_new_node<v8::Gather>(shape, dims_const, zero);@@ -222,14 +226,13 @@ std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::get_dimensstd::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::get_dimensions(const std::shared_ptr<ov::Node>& node,const std::vector<int>& dims) {- return get_dimensions(register_new_node<ov::op::v3::ShapeOf>(node), dims);+ return get_dimensions(register_new_node<v3::ShapeOf>(node), dims);}std::shared_ptr<ov::Node> ov::pass::GroupQueryAttentionDecomposition::rotaryEmbedding(ov::Output<ov::Node> input,ov::Output<ov::Node> cos,ov::Output<ov::Node> sin,bool interleaved) {- using namespace ov::op;auto zero = v0::Constant::create(ov::element::i64, ov::Shape{1}, {0});auto one = v0::Constant::create(ov::element::i64, ov::Shape{1}, {1});diff --git a/src/common/transformations/src/transformations/op_conversions/gru_cell_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/gru_cell_decomposition.cppindex 70a0f41f522..f346c00d965 100644--- a/src/common/transformations/src/transformations/op_conversions/gru_cell_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/gru_cell_decomposition.cpp@@ -21,11 +21,17 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace op_util = ov::op::util;ov::pass::GRUCellDecomposition::GRUCellDecomposition() {MATCHER_SCOPE(GRUCellDecomposition);- auto gru_cell = ov::pass::pattern::wrap_type<ov::op::v3::GRUCell>();- matcher_pass_callback callback = [this](ov::pass::pattern::Matcher& m) {- auto gru_cell = ov::as_type_ptr<ov::op::v3::GRUCell>(m.get_match_root());+ auto gru_cell = ov::pass::pattern::wrap_type<v3::GRUCell>();+ matcher_pass_callback callback = [this](Matcher& m) {+ auto gru_cell = ov::as_type_ptr<v3::GRUCell>(m.get_match_root());if (!gru_cell || transformation_callback(gru_cell)) {return false;}@@ -37,70 +43,70 @@ ov::pass::GRUCellDecomposition::GRUCellDecomposition() {const Output<Node>& B = gru_cell->input_value(4);// Xt*(W^T)- auto Xt_W = std::make_shared<ov::op::v0::MatMul>(X, W, false, true);+ auto Xt_W = std::make_shared<v0::MatMul>(X, W, false, true);// Ht-1*(R^T)- auto Ht_R = std::make_shared<ov::op::v0::MatMul>(H_t, R, false, true);+ auto Ht_R = std::make_shared<v0::MatMul>(H_t, R, false, true);// split to gates:- auto axis_0 = ov::op::v0::Constant::create(element::i64, Shape{}, {0});- auto axis_1 = ov::op::v0::Constant::create(element::i64, Shape{}, {1});- auto Xt_W_zrh = std::make_shared<ov::op::v1::Split>(Xt_W, axis_1, 3);- auto R_zrh = std::make_shared<ov::op::v1::Split>(R, axis_0, 3);- auto Ht_R_zrh = std::make_shared<ov::op::v1::Split>(Ht_R, axis_1, 3);- auto biases_zrh = std::make_shared<ov::op::v1::Split>(B, axis_0, gru_cell->get_linear_before_reset() ? 4 : 3);+ auto axis_0 = v0::Constant::create(element::i64, Shape{}, {0});+ auto axis_1 = v0::Constant::create(element::i64, Shape{}, {1});+ auto Xt_W_zrh = std::make_shared<v1::Split>(Xt_W, axis_1, 3);+ auto R_zrh = std::make_shared<v1::Split>(R, axis_0, 3);+ auto Ht_R_zrh = std::make_shared<v1::Split>(Ht_R, axis_1, 3);+ auto biases_zrh = std::make_shared<v1::Split>(B, axis_0, gru_cell->get_linear_before_reset() ? 4 : 3);// Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz- auto add_z_1 = std::make_shared<ov::op::v1::Add>(Ht_R_zrh->output(0), biases_zrh->output(0));- auto add_z_2 = std::make_shared<ov::op::v1::Add>(Xt_W_zrh->output(0), add_z_1);+ auto add_z_1 = std::make_shared<v1::Add>(Ht_R_zrh->output(0), biases_zrh->output(0));+ auto add_z_2 = std::make_shared<v1::Add>(Xt_W_zrh->output(0), add_z_1);// Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr- auto add_r_1 = std::make_shared<ov::op::v1::Add>(Ht_R_zrh->output(1), biases_zrh->output(1));- auto add_r_2 = std::make_shared<ov::op::v1::Add>(Xt_W_zrh->output(1), add_r_1);+ auto add_r_1 = std::make_shared<v1::Add>(Ht_R_zrh->output(1), biases_zrh->output(1));+ auto add_r_2 = std::make_shared<v1::Add>(Xt_W_zrh->output(1), add_r_1);auto clip = gru_cell->get_clip();std::shared_ptr<Node> clamp_z = add_z_2;std::shared_ptr<Node> clamp_r = add_r_2;if (clip > 0.f) {- clamp_z = std::make_shared<ov::op::v0::Clamp>(add_z_2, -clip, clip);- clamp_r = std::make_shared<ov::op::v0::Clamp>(add_r_2, -clip, clip);+ clamp_z = std::make_shared<v0::Clamp>(add_z_2, -clip, clip);+ clamp_r = std::make_shared<v0::Clamp>(add_r_2, -clip, clip);ov::copy_runtime_info(gru_cell, {clamp_z, clamp_r});}// zt = f(Xt*(Wz^T) + Ht-1*(Rz^T) + Wbz + Rbz)- auto z_t = ov::op::util::activation(gru_cell->get_activations()[0], clamp_z);+ auto z_t = op_util::activation(gru_cell->get_activations()[0], clamp_z);// rt = f(Xt*(Wr^T) + Ht-1*(Rr^T) + Wbr + Rbr)- auto r_t = ov::op::util::activation(gru_cell->get_activations()[0], clamp_r);+ auto r_t = op_util::activation(gru_cell->get_activations()[0], clamp_r);std::shared_ptr<Node> _h;if (gru_cell->get_linear_before_reset()) {// _h = Xt*(Wh^T) + (rt (.) (Ht-1*(Rh^T) + Rbh)) + Wbh- auto Ht_Rh_Rbh = std::make_shared<ov::op::v1::Add>(Ht_R_zrh->output(2), biases_zrh->output(3));- auto mul_h_1 = std::make_shared<ov::op::v1::Multiply>(r_t, Ht_Rh_Rbh);- auto add_h_1 = std::make_shared<ov::op::v1::Add>(mul_h_1, biases_zrh->output(2));- _h = std::make_shared<ov::op::v1::Add>(Xt_W_zrh->output(2), add_h_1);+ auto Ht_Rh_Rbh = std::make_shared<v1::Add>(Ht_R_zrh->output(2), biases_zrh->output(3));+ auto mul_h_1 = std::make_shared<v1::Multiply>(r_t, Ht_Rh_Rbh);+ auto add_h_1 = std::make_shared<v1::Add>(mul_h_1, biases_zrh->output(2));+ _h = std::make_shared<v1::Add>(Xt_W_zrh->output(2), add_h_1);ov::copy_runtime_info(gru_cell, {Ht_Rh_Rbh, mul_h_1, add_h_1, _h});} else {// _h = Xt*(Wh^T) + (rt (.) Ht-1)*(Rh^T) + Rbh + Wbh- auto rt_Ht = std::make_shared<ov::op::v1::Multiply>(r_t, H_t);- auto mul_h_1 = std::make_shared<ov::op::v0::MatMul>(rt_Ht, R_zrh->output(2), false, true);- auto add_h_1 = std::make_shared<ov::op::v1::Add>(mul_h_1, biases_zrh->output(2));- _h = std::make_shared<ov::op::v1::Add>(Xt_W_zrh->output(2), add_h_1);+ auto rt_Ht = std::make_shared<v1::Multiply>(r_t, H_t);+ auto mul_h_1 = std::make_shared<v0::MatMul>(rt_Ht, R_zrh->output(2), false, true);+ auto add_h_1 = std::make_shared<v1::Add>(mul_h_1, biases_zrh->output(2));+ _h = std::make_shared<v1::Add>(Xt_W_zrh->output(2), add_h_1);ov::copy_runtime_info(gru_cell, {rt_Ht, mul_h_1, add_h_1, _h});}// ht = g(_h)std::shared_ptr<Node> clamp_h = _h;if (clip > 0.f) {- clamp_h = std::make_shared<ov::op::v0::Clamp>(_h, -clip, clip);+ clamp_h = std::make_shared<v0::Clamp>(_h, -clip, clip);ov::copy_runtime_info(gru_cell, clamp_h);}- auto h_t = ov::op::util::activation(gru_cell->get_activations()[1], clamp_h);+ auto h_t = op_util::activation(gru_cell->get_activations()[1], clamp_h);// Ht = (1 - zt) (.) ht + zt (.) Ht-1- auto one = ov::op::v0::Constant::create(z_t->get_element_type(), Shape{1}, {1.f});- auto sub = std::make_shared<ov::op::v1::Subtract>(one, z_t);- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(sub, h_t);- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(z_t, H_t);- auto out_H = std::make_shared<ov::op::v1::Add>(mul_1, mul_2);+ auto one = v0::Constant::create(z_t->get_element_type(), Shape{1}, {1.f});+ auto sub = std::make_shared<v1::Subtract>(one, z_t);+ auto mul_1 = std::make_shared<v1::Multiply>(sub, h_t);+ auto mul_2 = std::make_shared<v1::Multiply>(z_t, H_t);+ auto out_H = std::make_shared<v1::Add>(mul_1, mul_2);out_H->set_friendly_name(gru_cell->get_friendly_name());ov::copy_runtime_info(gru_cell,@@ -125,6 +131,6 @@ ov::pass::GRUCellDecomposition::GRUCellDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(gru_cell, matcher_name);+ auto m = std::make_shared<Matcher>(gru_cell, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/hard_sigmoid_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/hard_sigmoid_decomposition.cppindex 758c724fa97..ac59ef23fbb 100644--- a/src/common/transformations/src/transformations/op_conversions/hard_sigmoid_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/hard_sigmoid_decomposition.cpp@@ -17,12 +17,16 @@#include "openvino/op/multiply.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::HardSigmoidDecomposition::HardSigmoidDecomposition() {MATCHER_SCOPE(HardSigmoidDecomposition);// Decomposes HardSigmoid(x) op into sub-graph max(0, min(1, alpha * x + beta))- auto hard_sigmoid = ov::pass::pattern::wrap_type<ov::op::v0::HardSigmoid>();+ auto hard_sigmoid = ov::pass::pattern::wrap_type<v0::HardSigmoid>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto hard_sigmoid_node = pattern_to_output.at(hard_sigmoid).get_node_shared_ptr();@@ -31,17 +35,17 @@ ov::pass::HardSigmoidDecomposition::HardSigmoidDecomposition() {}auto alpha_constant = hard_sigmoid_node->input_value(1);- auto multiply = std::make_shared<ov::op::v1::Multiply>(hard_sigmoid_node->input_value(0), alpha_constant);+ auto multiply = std::make_shared<v1::Multiply>(hard_sigmoid_node->input_value(0), alpha_constant);auto betta_constant = hard_sigmoid_node->input_value(2);- auto add = std::make_shared<ov::op::v1::Add>(multiply, betta_constant);+ auto add = std::make_shared<v1::Add>(multiply, betta_constant);auto input_type = hard_sigmoid_node->input_value(0).get_element_type();- auto min_constant = ov::op::v0::Constant::create(input_type, ov::Shape{}, {1.f});- auto min = std::make_shared<ov::op::v1::Minimum>(add, min_constant);+ auto min_constant = v0::Constant::create(input_type, ov::Shape{}, {1.f});+ auto min = std::make_shared<v1::Minimum>(add, min_constant);- auto max_constant = ov::op::v0::Constant::create(input_type, ov::Shape{}, {0.0});- auto max = std::make_shared<ov::op::v1::Maximum>(min, max_constant);+ auto max_constant = v0::Constant::create(input_type, ov::Shape{}, {0.0});+ auto max = std::make_shared<v1::Maximum>(min, max_constant);max->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info(hard_sigmoid_node,@@ -57,6 +61,6 @@ ov::pass::HardSigmoidDecomposition::HardSigmoidDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(hard_sigmoid, matcher_name);+ auto m = std::make_shared<Matcher>(hard_sigmoid, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/hsigmoid_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/hsigmoid_decomposition.cppindex b73899dc3f9..a5d80a31b76 100644--- a/src/common/transformations/src/transformations/op_conversions/hsigmoid_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/hsigmoid_decomposition.cpp@@ -18,12 +18,16 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::HSigmoidDecomposition::HSigmoidDecomposition() {MATCHER_SCOPE(HSigmoidDecomposition);// Decomposes HSigmoid(x) op into sub-graph (min(Relu(x + 3), 6) * const(1/6)auto hsigmoid = ov::pass::pattern::wrap_type<ov::op::v5::HSigmoid>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto hsigmoid_node = pattern_to_output.at(hsigmoid).get_node_shared_ptr();@@ -32,13 +36,13 @@ ov::pass::HSigmoidDecomposition::HSigmoidDecomposition() {}auto input_type = hsigmoid_node->input_value(0).get_element_type();- auto add_constant = ov::op::v0::Constant::create(input_type, ov::Shape{}, {3.0});- auto add = std::make_shared<ov::op::v1::Add>(hsigmoid_node->input_value(0), add_constant);- auto relu = std::make_shared<ov::op::v0::Relu>(add);- auto min_constant = ov::op::v0::Constant::create(input_type, ov::Shape{}, {6.0});- auto min = register_new_node<ov::op::v1::Minimum>(relu, min_constant);- auto mul_constant = ov::op::v0::Constant::create(input_type, ov::Shape{}, {(1.0 / 6.0)}); // const(1/6)- auto mul = std::make_shared<ov::op::v1::Multiply>(min, mul_constant);+ auto add_constant = v0::Constant::create(input_type, ov::Shape{}, {3.0});+ auto add = std::make_shared<v1::Add>(hsigmoid_node->input_value(0), add_constant);+ auto relu = std::make_shared<v0::Relu>(add);+ auto min_constant = v0::Constant::create(input_type, ov::Shape{}, {6.0});+ auto min = register_new_node<v1::Minimum>(relu, min_constant);+ auto mul_constant = v0::Constant::create(input_type, ov::Shape{}, {(1.0 / 6.0)}); // const(1/6)+ auto mul = std::make_shared<v1::Multiply>(min, mul_constant);mul->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info(hsigmoid_node, {add_constant, add, relu, min_constant, min, min_constant, mul});@@ -46,6 +50,6 @@ ov::pass::HSigmoidDecomposition::HSigmoidDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(hsigmoid, matcher_name);+ auto m = std::make_shared<Matcher>(hsigmoid, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/hswish_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/hswish_decomposition.cppindex 53659ed5a00..f80c0e9f0a8 100644--- a/src/common/transformations/src/transformations/op_conversions/hswish_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/hswish_decomposition.cpp@@ -18,12 +18,16 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::HSwishDecomposition::HSwishDecomposition() {MATCHER_SCOPE(HSwishDecomposition);// Decomposes HSwish(x) op into sub-graph x * (min(Relu(x + 3), 6) * const(1/6)auto hswish = ov::pass::pattern::wrap_type<ov::op::v4::HSwish>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto hswish_node = pattern_to_output.at(hswish).get_node_shared_ptr();@@ -32,14 +36,14 @@ ov::pass::HSwishDecomposition::HSwishDecomposition() {}auto input_type = hswish_node->input_value(0).get_element_type();- auto add_constant = ov::op::v0::Constant::create(input_type, ov::Shape{}, {3.0});- auto add = std::make_shared<ov::op::v1::Add>(hswish_node->input_value(0), add_constant);- auto relu = std::make_shared<ov::op::v0::Relu>(add);- auto min_constant = ov::op::v0::Constant::create(input_type, ov::Shape{}, {6.0});- auto min = register_new_node<ov::op::v1::Minimum>(relu, min_constant);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(hswish_node->input_value(0), min);- auto mul_constant = ov::op::v0::Constant::create(input_type, ov::Shape{}, {(1.0 / 6.0)}); // const(1/6)- auto mul_second = std::make_shared<ov::op::v1::Multiply>(mul_first, mul_constant);+ auto add_constant = v0::Constant::create(input_type, ov::Shape{}, {3.0});+ auto add = std::make_shared<v1::Add>(hswish_node->input_value(0), add_constant);+ auto relu = std::make_shared<v0::Relu>(add);+ auto min_constant = v0::Constant::create(input_type, ov::Shape{}, {6.0});+ auto min = register_new_node<v1::Minimum>(relu, min_constant);+ auto mul_first = std::make_shared<v1::Multiply>(hswish_node->input_value(0), min);+ auto mul_constant = v0::Constant::create(input_type, ov::Shape{}, {(1.0 / 6.0)}); // const(1/6)+ auto mul_second = std::make_shared<v1::Multiply>(mul_first, mul_constant);mul_second->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info(hswish_node,@@ -48,6 +52,6 @@ ov::pass::HSwishDecomposition::HSwishDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(hswish, matcher_name);+ auto m = std::make_shared<Matcher>(hswish, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cppindex 628dd27b87a..6bc60616b68 100644--- a/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp@@ -19,28 +19,33 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v5 = ov::op::v5;ov::pass::LogSoftmaxDecomposition::LogSoftmaxDecomposition() {MATCHER_SCOPE(LogSoftmaxDecomposition);// Decomposes LogSoftmax(x, axis) op into sub-graph x - log(reduce_sum(exp(x), axis))- auto log_softmax = ov::pass::pattern::wrap_type<ov::op::v5::LogSoftmax>();+ auto log_softmax = ov::pass::pattern::wrap_type<v5::LogSoftmax>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto log_softmax_node =- ov::as_type_ptr<ov::op::v5::LogSoftmax>(pattern_to_output.at(log_softmax).get_node_shared_ptr());+ ov::as_type_ptr<v5::LogSoftmax>(pattern_to_output.at(log_softmax).get_node_shared_ptr());if (log_softmax_node == nullptr || transformation_callback(log_softmax_node)) {return false;}- auto axis1 = ov::op::v0::Constant::create(element::Type_t::i64, ov::Shape{1}, {log_softmax_node->get_axis()});- auto axis2 = ov::op::v0::Constant::create(element::Type_t::i64, ov::Shape{1}, {log_softmax_node->get_axis()});- auto max = std::make_shared<ov::op::v1::ReduceMax>(log_softmax_node->input_value(0), axis1, true);- auto sub = std::make_shared<ov::op::v1::Subtract>(log_softmax_node->input_value(0), max);- auto exp = std::make_shared<ov::op::v0::Exp>(sub);- auto sum = std::make_shared<ov::op::v1::ReduceSum>(exp, axis2, true);- auto log = std::make_shared<ov::op::v0::Log>(sum);- auto sub_end = std::make_shared<ov::op::v1::Subtract>(sub, log);+ auto axis1 = v0::Constant::create(element::Type_t::i64, ov::Shape{1}, {log_softmax_node->get_axis()});+ auto axis2 = v0::Constant::create(element::Type_t::i64, ov::Shape{1}, {log_softmax_node->get_axis()});+ auto max = std::make_shared<v1::ReduceMax>(log_softmax_node->input_value(0), axis1, true);+ auto sub = std::make_shared<v1::Subtract>(log_softmax_node->input_value(0), max);+ auto exp = std::make_shared<v0::Exp>(sub);+ auto sum = std::make_shared<v1::ReduceSum>(exp, axis2, true);+ auto log = std::make_shared<v0::Log>(sum);+ auto sub_end = std::make_shared<v1::Subtract>(sub, log);sub_end->set_friendly_name(m.get_match_root()->get_friendly_name());ov::copy_runtime_info(log_softmax_node, {axis1, axis2, max, sub, exp, sum, log, sub_end});@@ -48,6 +53,6 @@ ov::pass::LogSoftmaxDecomposition::LogSoftmaxDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(log_softmax, matcher_name);+ auto m = std::make_shared<Matcher>(log_softmax, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/lstm_cell_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/lstm_cell_decomposition.cppindex 1b684240763..9abd55187a4 100644--- a/src/common/transformations/src/transformations/op_conversions/lstm_cell_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/lstm_cell_decomposition.cpp@@ -20,11 +20,16 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;ov::pass::LSTMCellDecomposition::LSTMCellDecomposition() {MATCHER_SCOPE(LSTMCellDecomposition);- auto any_lstm = pattern::wrap_type<ov::op::v0::LSTMCell, ov::op::v4::LSTMCell>();+ auto any_lstm = ov::pass::pattern::wrap_type<v0::LSTMCell, ov::op::v4::LSTMCell>();- matcher_pass_callback callback = [this](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [this](Matcher& m) {auto lstm_cell = ov::as_type_ptr<op::util::RNNCellBase>(m.get_match_root());if (!lstm_cell || transformation_callback(lstm_cell)) {return false;@@ -37,15 +42,15 @@ ov::pass::LSTMCellDecomposition::LSTMCellDecomposition() {const Output<Node>& bias = lstm_cell->input_value(5);// Xt*(W^T)- auto Xt_W = std::make_shared<ov::op::v0::MatMul>(X, W, false, true);+ auto Xt_W = std::make_shared<v0::MatMul>(X, W, false, true);// Ht-1*(R^T)- auto Ht_R = std::make_shared<ov::op::v0::MatMul>(H_t, R, false, true);+ auto Ht_R = std::make_shared<v0::MatMul>(H_t, R, false, true);// Xt*(W^T) + Ht-1*(R^T) + Wb + Rb- auto add = std::make_shared<ov::op::v1::Add>(Ht_R, bias);- auto XHB = std::make_shared<ov::op::v1::Add>(Xt_W, add);+ auto add = std::make_shared<v1::Add>(Ht_R, bias);+ auto XHB = std::make_shared<v1::Add>(Xt_W, add);- auto axis_node = ov::op::v0::Constant::create(element::u64, Shape{}, {1});- auto split = std::make_shared<ov::op::v1::Split>(XHB, axis_node, 4);+ auto axis_node = v0::Constant::create(element::u64, Shape{}, {1});+ auto split = std::make_shared<v1::Split>(XHB, axis_node, 4);Output<Node> f = split->output(0);Output<Node> i = split->output(1);Output<Node> c = split->output(2);@@ -53,10 +58,10 @@ ov::pass::LSTMCellDecomposition::LSTMCellDecomposition() {auto clip = lstm_cell->get_clip();if (clip > 0.f) {- auto clamp_f = std::make_shared<ov::op::v0::Clamp>(f, -clip, clip);- auto clamp_i = std::make_shared<ov::op::v0::Clamp>(i, -clip, clip);- auto clamp_c = std::make_shared<ov::op::v0::Clamp>(c, -clip, clip);- auto clamp_o = std::make_shared<ov::op::v0::Clamp>(o, -clip, clip);+ auto clamp_f = std::make_shared<v0::Clamp>(f, -clip, clip);+ auto clamp_i = std::make_shared<v0::Clamp>(i, -clip, clip);+ auto clamp_c = std::make_shared<v0::Clamp>(c, -clip, clip);+ auto clamp_o = std::make_shared<v0::Clamp>(o, -clip, clip);f = clamp_f;i = clamp_i;c = clamp_c;@@ -68,19 +73,19 @@ ov::pass::LSTMCellDecomposition::LSTMCellDecomposition() {// it = f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi)// ct = g(Xt*(Wc^T) + Ht-1*(Rc^T) + Wbc + Rbc)// ot = f(Xt*(Wo^T) + Ht-1*(Ro^T) + Wbo + Rbo)- auto f_t = ov::op::util::activation(lstm_cell->get_activations()[0], f);- auto i_t = ov::op::util::activation(lstm_cell->get_activations()[0], i);- auto c_t = ov::op::util::activation(lstm_cell->get_activations()[1], c);- auto o_t = ov::op::util::activation(lstm_cell->get_activations()[0], o);+ auto f_t = op_util::activation(lstm_cell->get_activations()[0], f);+ auto i_t = op_util::activation(lstm_cell->get_activations()[0], i);+ auto c_t = op_util::activation(lstm_cell->get_activations()[1], c);+ auto o_t = op_util::activation(lstm_cell->get_activations()[0], o);// Ct = ft (.) Ct-1 + it (.) ct- auto mul1 = std::make_shared<ov::op::v1::Multiply>(f_t, C_t);- auto mul2 = std::make_shared<ov::op::v1::Multiply>(i_t, c_t);- auto out_C = std::make_shared<ov::op::v1::Add>(mul1, mul2);+ auto mul1 = std::make_shared<v1::Multiply>(f_t, C_t);+ auto mul2 = std::make_shared<v1::Multiply>(i_t, c_t);+ auto out_C = std::make_shared<v1::Add>(mul1, mul2);// H = ot (.) h(Ct)- auto hC = ov::op::util::activation(lstm_cell->get_activations()[2], out_C);- auto out_H = std::make_shared<ov::op::v1::Multiply>(o_t, hC);+ auto hC = op_util::activation(lstm_cell->get_activations()[2], out_C);+ auto out_H = std::make_shared<v1::Multiply>(o_t, hC);out_H->set_friendly_name(lstm_cell->get_friendly_name() + ".0");out_C->set_friendly_name(lstm_cell->get_friendly_name() + ".1");@@ -91,6 +96,6 @@ ov::pass::LSTMCellDecomposition::LSTMCellDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(any_lstm, matcher_name);+ auto m = std::make_shared<Matcher>(any_lstm, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/mvn6_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/mvn6_decomposition.cppindex 061feadd794..6ba6add24d3 100644--- a/src/common/transformations/src/transformations/op_conversions/mvn6_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/mvn6_decomposition.cpp@@ -20,16 +20,21 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v6 = ov::op::v6;ov::pass::MVN6Decomposition::MVN6Decomposition() {MATCHER_SCOPE(MVN6Decomposition);// Decomposes MVN(x, axes) op if normalize_variance is false into sub-graph// x - ReduceMean(x, axes), if normalize_variance is true into sub-graph// (x - ReduceMean(x, axes)) / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2))- auto mvn = ov::pass::pattern::wrap_type<ov::op::v6::MVN>();+ auto mvn = ov::pass::pattern::wrap_type<v6::MVN>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();- auto mvn_node = ov::as_type_ptr<ov::op::v6::MVN>(pattern_to_output.at(mvn).get_node_shared_ptr());+ auto mvn_node = ov::as_type_ptr<v6::MVN>(pattern_to_output.at(mvn).get_node_shared_ptr());if (mvn_node == nullptr || transformation_callback(mvn_node)) {return false;@@ -39,8 +44,8 @@ ov::pass::MVN6Decomposition::MVN6Decomposition() {const auto axes = mvn_node->input_value(1);// (x - ReduceMean(x, axes))- auto mean = std::make_shared<ov::op::v1::ReduceMean>(data, axes, true);- auto mean_normalization = std::make_shared<ov::op::v1::Subtract>(data, mean);+ auto mean = std::make_shared<v1::ReduceMean>(data, axes, true);+ auto mean_normalization = std::make_shared<v1::Subtract>(data, mean);if (!mvn_node->get_normalize_variance()) {mean_normalization->set_friendly_name(mvn_node->get_friendly_name());@@ -48,31 +53,31 @@ ov::pass::MVN6Decomposition::MVN6Decomposition() {ov::replace_node(mvn_node, mean_normalization);} else {// (x - ReduceMean(x, axes)) ^ 2- auto sqr_const = ov::op::v0::Constant::create(data.get_element_type(), ov::Shape{1}, {2});- auto sqr = std::make_shared<ov::op::v1::Power>(mean_normalization, sqr_const);+ auto sqr_const = v0::Constant::create(data.get_element_type(), ov::Shape{1}, {2});+ auto sqr = std::make_shared<v1::Power>(mean_normalization, sqr_const);// ReduceMean((x - ReduceMean(x, axes)) ^ 2)- auto mean2 = std::make_shared<ov::op::v1::ReduceMean>(sqr, axes, true);+ auto mean2 = std::make_shared<v1::ReduceMean>(sqr, axes, true);auto eps = mvn_node->get_eps();- auto eps_node = ov::op::v0::Constant::create(data.get_element_type(), ov::Shape{1}, {eps});+ auto eps_node = v0::Constant::create(data.get_element_type(), ov::Shape{1}, {eps});auto eps_mode = mvn_node->get_eps_mode();- std::shared_ptr<ov::op::v1::Add> eps_add;- std::shared_ptr<ov::op::v0::Sqrt> sqrt;- std::shared_ptr<ov::op::v1::Divide> div;+ std::shared_ptr<v1::Add> eps_add;+ std::shared_ptr<v0::Sqrt> sqrt;+ std::shared_ptr<v1::Divide> div;if (eps_mode == op::MVNEpsMode::INSIDE_SQRT) {// Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps)- eps_add = std::make_shared<ov::op::v1::Add>(mean2, eps_node);- sqrt = std::make_shared<ov::op::v0::Sqrt>(eps_add);+ eps_add = std::make_shared<v1::Add>(mean2, eps_node);+ sqrt = std::make_shared<v0::Sqrt>(eps_add);// (x - ReduceMean(x, axes)) / Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2) + eps)- div = std::make_shared<ov::op::v1::Divide>(mean_normalization, sqrt);+ div = std::make_shared<v1::Divide>(mean_normalization, sqrt);} else if (eps_mode == op::MVNEpsMode::OUTSIDE_SQRT) {// Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) + eps- sqrt = std::make_shared<ov::op::v0::Sqrt>(mean2);- eps_add = std::make_shared<ov::op::v1::Add>(sqrt, eps_node);+ sqrt = std::make_shared<v0::Sqrt>(mean2);+ eps_add = std::make_shared<v1::Add>(sqrt, eps_node);// (x - ReduceMean(x, axes)) / (Sqrt(ReduceMean((x - ReduceMean(x, axes)) ^ 2)) + eps)- div = std::make_shared<ov::op::v1::Divide>(mean_normalization, eps_add);+ div = std::make_shared<v1::Divide>(mean_normalization, eps_add);} else {return false;}@@ -84,6 +89,6 @@ ov::pass::MVN6Decomposition::MVN6Decomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(mvn, matcher_name);+ auto m = std::make_shared<Matcher>(mvn, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cppindex 15bb9fac126..e708c523beb 100644--- a/src/common/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/normalize_l2_decomposition.cpp@@ -20,38 +20,42 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::NormalizeL2Decomposition::NormalizeL2Decomposition() {MATCHER_SCOPE(NormalizeL2Decomposition);- auto normalize_l2_pattern = ov::pass::pattern::wrap_type<ov::op::v0::NormalizeL2>();+ auto normalize_l2_pattern = ov::pass::pattern::wrap_type<v0::NormalizeL2>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {- auto normalize_l2 = ov::as_type_ptr<ov::op::v0::NormalizeL2>(m.get_match_root());+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto normalize_l2 = ov::as_type_ptr<v0::NormalizeL2>(m.get_match_root());if (!normalize_l2 || transformation_callback(normalize_l2)) {return false;}- auto power = std::make_shared<ov::op::v1::Power>(- normalize_l2->input_value(0),- ov::op::v0::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {2.0}));- auto reduce_sum = std::make_shared<ov::op::v1::ReduceSum>(power, normalize_l2->input_value(1), true);+ auto power =+ std::make_shared<v1::Power>(normalize_l2->input_value(0),+ v0::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {2.0}));+ auto reduce_sum = std::make_shared<v1::ReduceSum>(power, normalize_l2->input_value(1), true);std::shared_ptr<Node> eps_node;auto eps_const_node =- ov::op::v0::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {normalize_l2->get_eps()});+ v0::Constant::create(normalize_l2->get_input_element_type(0), Shape{}, {normalize_l2->get_eps()});switch (normalize_l2->get_eps_mode()) {case op::EpsMode::ADD:- eps_node = std::make_shared<ov::op::v1::Add>(reduce_sum, eps_const_node);+ eps_node = std::make_shared<v1::Add>(reduce_sum, eps_const_node);break;case op::EpsMode::MAX:- eps_node = std::make_shared<ov::op::v1::Maximum>(reduce_sum, eps_const_node);+ eps_node = std::make_shared<v1::Maximum>(reduce_sum, eps_const_node);break;default:return false;}- auto sqrt = std::make_shared<ov::op::v0::Sqrt>(eps_node);- auto div = std::make_shared<ov::op::v1::Divide>(normalize_l2->input_value(0), sqrt);+ auto sqrt = std::make_shared<v0::Sqrt>(eps_node);+ auto div = std::make_shared<v1::Divide>(normalize_l2->input_value(0), sqrt);div->set_friendly_name(normalize_l2->get_friendly_name());ov::copy_runtime_info(normalize_l2, {power, reduce_sum, eps_node, sqrt, div});@@ -59,6 +63,6 @@ ov::pass::NormalizeL2Decomposition::NormalizeL2Decomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(normalize_l2_pattern, matcher_name);+ auto m = std::make_shared<Matcher>(normalize_l2_pattern, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/reduce_l1_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/reduce_l1_decomposition.cppindex 3c0a76c3472..451ff33036f 100644--- a/src/common/transformations/src/transformations/op_conversions/reduce_l1_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/reduce_l1_decomposition.cpp@@ -15,15 +15,17 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v4 = ov::op::v4;ov::pass::ReduceL1Decomposition::ReduceL1Decomposition() {MATCHER_SCOPE(ReduceL1Decomposition);// decomposes ReduceL1 operations into ReduceSum(abs(x))- auto reduce_l1 = ov::pass::pattern::wrap_type<ov::op::v4::ReduceL1>();+ auto reduce_l1 = ov::pass::pattern::wrap_type<v4::ReduceL1>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();- auto reduce_l1_node =- ov::as_type_ptr<ov::op::v4::ReduceL1>(pattern_to_output.at(reduce_l1).get_node_shared_ptr());+ auto reduce_l1_node = ov::as_type_ptr<v4::ReduceL1>(pattern_to_output.at(reduce_l1).get_node_shared_ptr());if (reduce_l1_node == nullptr || transformation_callback(reduce_l1_node)) {return false;@@ -40,6 +42,6 @@ ov::pass::ReduceL1Decomposition::ReduceL1Decomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reduce_l1, matcher_name);+ auto m = std::make_shared<Matcher>(reduce_l1, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/reduce_l2_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/reduce_l2_decomposition.cppindex cebe516b1e4..beb88a2394c 100644--- a/src/common/transformations/src/transformations/op_conversions/reduce_l2_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/reduce_l2_decomposition.cpp@@ -18,26 +18,29 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;ov::pass::ReduceL2Decomposition::ReduceL2Decomposition() {MATCHER_SCOPE(ReduceL2Decomposition);// decomposes ReduceL2 operations into sqrt(ReduceSum(x * x))- auto reduce_l2 = ov::pass::pattern::wrap_type<ov::op::v4::ReduceL2>();+ auto reduce_l2 = ov::pass::pattern::wrap_type<v4::ReduceL2>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();- auto reduce_l2_node =- ov::as_type_ptr<ov::op::v4::ReduceL2>(pattern_to_output.at(reduce_l2).get_node_shared_ptr());+ auto reduce_l2_node = ov::as_type_ptr<v4::ReduceL2>(pattern_to_output.at(reduce_l2).get_node_shared_ptr());if (reduce_l2_node == nullptr || transformation_callback(reduce_l2_node)) {return false;}- auto const_2 = ov::op::v0::Constant::create(reduce_l2_node->input_value(0).get_element_type(), Shape{}, {2.0f});- auto square = std::make_shared<ov::op::v1::Power>(reduce_l2_node->input_value(0), const_2);- auto reduce_sum = register_new_node<ov::op::v1::ReduceSum>(square,- reduce_l2_node->input_value(1),- reduce_l2_node->get_keep_dims());- auto sqrt = std::make_shared<ov::op::v0::Sqrt>(reduce_sum);+ auto const_2 = v0::Constant::create(reduce_l2_node->input_value(0).get_element_type(), Shape{}, {2.0f});+ auto square = std::make_shared<v1::Power>(reduce_l2_node->input_value(0), const_2);+ auto reduce_sum =+ register_new_node<v1::ReduceSum>(square, reduce_l2_node->input_value(1), reduce_l2_node->get_keep_dims());+ auto sqrt = std::make_shared<v0::Sqrt>(reduce_sum);sqrt->set_friendly_name(m.get_match_root()->get_friendly_name());ov::NodeVector rt_info_from_nodes{reduce_l2_node};const auto reduce_l2_input_1 = reduce_l2_node->input_value(1).get_node();@@ -48,6 +51,6 @@ ov::pass::ReduceL2Decomposition::ReduceL2Decomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reduce_l2, matcher_name);+ auto m = std::make_shared<Matcher>(reduce_l2, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/rnn_cell_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/rnn_cell_decomposition.cppindex bf4d658d86d..f4145725434 100644--- a/src/common/transformations/src/transformations/op_conversions/rnn_cell_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/rnn_cell_decomposition.cpp@@ -16,11 +16,15 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::RNNCellDecomposition::RNNCellDecomposition() {MATCHER_SCOPE(RNNCellDecomposition);- auto rnn_cell = ov::pass::pattern::wrap_type<ov::op::v0::RNNCell>();- matcher_pass_callback callback = [this](ov::pass::pattern::Matcher& m) {- auto rnn_cell = ov::as_type_ptr<ov::op::v0::RNNCell>(m.get_match_root());+ auto rnn_cell = ov::pass::pattern::wrap_type<v0::RNNCell>();+ matcher_pass_callback callback = [this](Matcher& m) {+ auto rnn_cell = ov::as_type_ptr<v0::RNNCell>(m.get_match_root());if (!rnn_cell || transformation_callback(rnn_cell)) {return false;}@@ -31,18 +35,18 @@ ov::pass::RNNCellDecomposition::RNNCellDecomposition() {const Output<Node>& bias = rnn_cell->input_value(4);// Xt*(W^T)- auto Xt_W = std::make_shared<ov::op::v0::MatMul>(X, W, false, true);+ auto Xt_W = std::make_shared<v0::MatMul>(X, W, false, true);// Ht-1*(R^T)- auto Ht_R = std::make_shared<ov::op::v0::MatMul>(H_t, R, false, true);+ auto Ht_R = std::make_shared<v0::MatMul>(H_t, R, false, true);// Xt*(W^T) + Ht-1*(R^T) + Wb + Rb- auto add = std::make_shared<ov::op::v1::Add>(Ht_R, bias);- auto i_t = std::make_shared<ov::op::v1::Add>(Xt_W, add);+ auto add = std::make_shared<v1::Add>(Ht_R, bias);+ auto i_t = std::make_shared<v1::Add>(Xt_W, add);// f(Xt*(Wi^T) + Ht-1*(Ri^T) + Wbi + Rbi)auto clip = rnn_cell->get_clip();std::shared_ptr<Node> clamp = i_t;if (clip > 0.f) {- clamp = std::make_shared<ov::op::v0::Clamp>(i_t, -clip, clip);+ clamp = std::make_shared<v0::Clamp>(i_t, -clip, clip);ov::copy_runtime_info(rnn_cell, clamp);}auto out = ov::op::util::activation(rnn_cell->get_activations()[0], clamp);@@ -52,6 +56,6 @@ ov::pass::RNNCellDecomposition::RNNCellDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(rnn_cell, matcher_name);+ auto m = std::make_shared<Matcher>(rnn_cell, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/scaled_dot_product_attention_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/scaled_dot_product_attention_decomposition.cppindex 0dfa2ebc593..1cce88954de 100644--- a/src/common/transformations/src/transformations/op_conversions/scaled_dot_product_attention_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/scaled_dot_product_attention_decomposition.cpp@@ -35,6 +35,14 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v8 = ov::op::v8;+namespace v13 = ov::op::v13;namespace {bool can_move_scale_after_matmul(const ov::Output<ov::Node>& query,@@ -54,8 +62,8 @@ bool can_move_scale_after_matmul(const ov::Output<ov::Node>& query,// using the original implementation to calculate the shapes.// we need to move the scale after MatMul only if the tensor after MatMul is smaller.- auto q_scaled = std::make_shared<ov::op::v1::Multiply>(query, scale);- auto scaled_attn = std::make_shared<ov::op::v0::MatMul>(q_scaled, kT);+ auto q_scaled = std::make_shared<v1::Multiply>(query, scale);+ auto scaled_attn = std::make_shared<v0::MatMul>(q_scaled, kT);const auto& scaled_attn_pshape = scaled_attn->output(0).get_partial_shape();if (scaled_attn_pshape.is_static()) {return ov::shape_size(query_pshape.to_shape()) > ov::shape_size(scaled_attn_pshape.to_shape());@@ -67,12 +75,12 @@ bool can_move_scale_after_matmul(const ov::Output<ov::Node>& query,ov::pass::ScaledDotProductAttentionDecomposition::ScaledDotProductAttentionDecomposition() {MATCHER_SCOPE(ScaledDotProductAttentionDecomposition);- auto pattern_node = ov::pass::pattern::wrap_type<ov::op::v13::ScaledDotProductAttention>();+ auto pattern_node = ov::pass::pattern::wrap_type<v13::ScaledDotProductAttention>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();- auto node = ov::as_type_ptr<ov::op::v13::ScaledDotProductAttention>(- pattern_to_output.at(pattern_node).get_node_shared_ptr());+ auto node =+ ov::as_type_ptr<v13::ScaledDotProductAttention>(pattern_to_output.at(pattern_node).get_node_shared_ptr());if (node == nullptr || transformation_callback(node)) {return false;@@ -83,13 +91,12 @@ ov::pass::ScaledDotProductAttentionDecomposition::ScaledDotProductAttentionDecomreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(pattern_node, matcher_name);+ auto m = std::make_shared<Matcher>(pattern_node, matcher_name);register_matcher(m, callback);}std::shared_ptr<ov::Node> ov::pass::ScaledDotProductAttentionDecomposition::decompose(- std::shared_ptr<ov::op::v13::ScaledDotProductAttention> node) {- using namespace ov::op;+ std::shared_ptr<v13::ScaledDotProductAttention> node) {auto query = node->input_value(0);auto key = node->input_value(1);auto value = node->input_value(2);diff --git a/src/common/transformations/src/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.cpp b/src/common/transformations/src/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.cppindex 6b472ac1277..c18b7b3b21f 100644--- a/src/common/transformations/src/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.cpp+++ b/src/common/transformations/src/transformations/op_conversions/simplify_ctc_greedy_decoder_seq_len.cpp@@ -25,20 +25,25 @@#include "openvino/op/transpose.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v6 = ov::op::v6;ov::pass::SimplifyCTCGreedyDecoderSeqLen::SimplifyCTCGreedyDecoderSeqLen() {MATCHER_SCOPE(SimplifyCTCGreedyDecoderSeqLen);- auto decoder = pattern::wrap_type<ov::op::v6::CTCGreedyDecoderSeqLen>();+ auto decoder = ov::pass::pattern::wrap_type<v6::CTCGreedyDecoderSeqLen>();- matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {- auto decoder_seq_len = ov::as_type_ptr<ov::op::v6::CTCGreedyDecoderSeqLen>(m.get_match_root());+ matcher_pass_callback callback = [=](Matcher& m) {+ auto decoder_seq_len = ov::as_type_ptr<v6::CTCGreedyDecoderSeqLen>(m.get_match_root());if (!decoder_seq_len) {return false;}if (decoder_seq_len->get_input_size() > 2) {const auto data_pshape = decoder_seq_len->get_input_partial_shape(0);- auto blank_index =- ov::as_type_ptr<ov::op::v0::Constant>(decoder_seq_len->input_value(2).get_node_shared_ptr());+ auto blank_index = ov::as_type_ptr<v0::Constant>(decoder_seq_len->input_value(2).get_node_shared_ptr());if (!blank_index || data_pshape.rank().is_dynamic() || data_pshape[2].is_dynamic()) {return false;}@@ -53,78 +58,74 @@ ov::pass::SimplifyCTCGreedyDecoderSeqLen::SimplifyCTCGreedyDecoderSeqLen() {element::Type data_type = decoder_seq_len->input_value(0).get_element_type();element::Type seq_len_type = decoder_seq_len->input_value(1).get_element_type();// Transposing input data channels from [N, T, C] to [T, N, C]. Need for compatible with CTCGreedyDecoder v1- auto transpose =- std::make_shared<ov::op::v1::Transpose>(decoder_seq_len->input_value(0),- ov::op::v0::Constant::create(element::i32, Shape({3}), {1, 0, 2}));+ auto transpose = std::make_shared<v1::Transpose>(decoder_seq_len->input_value(0),+ v0::Constant::create(element::i32, Shape({3}), {1, 0, 2}));// Receive time and batch dimensions and concatenate to [T, N] tensor shapes- auto data_shape = std::make_shared<ov::op::v3::ShapeOf>(decoder_seq_len->input_value(0));- auto axisT = ov::op::v0::Constant::create(seq_len_type, Shape{}, {0});- auto indexT = ov::op::v0::Constant::create(seq_len_type, Shape{1}, {1});- auto T = std::make_shared<ov::op::v1::Gather>(data_shape, indexT, axisT);-- auto axisN = ov::op::v0::Constant::create(seq_len_type, Shape{}, {0});- auto indexN = ov::op::v0::Constant::create(seq_len_type, Shape{1}, {0});- auto N = std::make_shared<ov::op::v1::Gather>(data_shape, indexN, axisN);-- auto start = ov::op::v0::Constant::create(seq_len_type, Shape{}, {1});- auto step = ov::op::v0::Constant::create(seq_len_type, Shape{}, {1});- auto plus1 = ov::op::v0::Constant::create(element::i64, Shape{1}, {1});- auto plusT = std::make_shared<ov::op::v1::Add>(T, plus1);- auto const_plusT = ov::op::v0::Constant::create(seq_len_type, Shape{1}, {0});- auto plusT_scalar = std::make_shared<ov::op::v0::Squeeze>(plusT, const_plusT);+ auto data_shape = std::make_shared<v3::ShapeOf>(decoder_seq_len->input_value(0));+ auto axisT = v0::Constant::create(seq_len_type, Shape{}, {0});+ auto indexT = v0::Constant::create(seq_len_type, Shape{1}, {1});+ auto T = std::make_shared<v1::Gather>(data_shape, indexT, axisT);++ auto axisN = v0::Constant::create(seq_len_type, Shape{}, {0});+ auto indexN = v0::Constant::create(seq_len_type, Shape{1}, {0});+ auto N = std::make_shared<v1::Gather>(data_shape, indexN, axisN);++ auto start = v0::Constant::create(seq_len_type, Shape{}, {1});+ auto step = v0::Constant::create(seq_len_type, Shape{}, {1});+ auto plus1 = v0::Constant::create(element::i64, Shape{1}, {1});+ auto plusT = std::make_shared<v1::Add>(T, plus1);+ auto const_plusT = v0::Constant::create(seq_len_type, Shape{1}, {0});+ auto plusT_scalar = std::make_shared<v0::Squeeze>(plusT, const_plusT);auto range1T = std::make_shared<ov::op::v4::Range>(start, plusT_scalar, step, seq_len_type);- auto mask_shape = std::make_shared<ov::op::v0::Concat>(OutputVector{T->output(0), N->output(0)}, 0);+ auto mask_shape = std::make_shared<v0::Concat>(OutputVector{T->output(0), N->output(0)}, 0);// Generate 2D tensor [T, N] for seq mask- auto upper_bounds =- std::make_shared<ov::op::v3::Broadcast>(decoder_seq_len->input_value(1), mask_shape->output(0));+ auto upper_bounds = std::make_shared<v3::Broadcast>(decoder_seq_len->input_value(1), mask_shape->output(0));auto transpose_upper_bounds =- std::make_shared<ov::op::v1::Transpose>(upper_bounds->output(0),- ov::op::v0::Constant::create(seq_len_type, Shape({2}), {1, 0}));+ std::make_shared<v1::Transpose>(upper_bounds->output(0),+ v0::Constant::create(seq_len_type, Shape({2}), {1, 0}));// Compute boolean sequence mask- auto bool_seq_mask =- std::make_shared<ov::op::v1::GreaterEqual>(transpose_upper_bounds->output(0), range1T->output(0));+ auto bool_seq_mask = std::make_shared<v1::GreaterEqual>(transpose_upper_bounds->output(0), range1T->output(0));// Generate resulted seq mask- auto mask_val_true = ov::op::v0::Constant::create(seq_len_type, Shape{}, {1});- auto mask_val_false = ov::op::v0::Constant::create(seq_len_type, Shape{}, {0});- auto seq_mask = std::make_shared<ov::op::v1::Select>(bool_seq_mask, mask_val_true, mask_val_false);+ auto mask_val_true = v0::Constant::create(seq_len_type, Shape{}, {1});+ auto mask_val_false = v0::Constant::create(seq_len_type, Shape{}, {0});+ auto seq_mask = std::make_shared<v1::Select>(bool_seq_mask, mask_val_true, mask_val_false);auto transpose_seq_mask =- std::make_shared<ov::op::v1::Transpose>(seq_mask->output(0),- ov::op::v0::Constant::create(seq_len_type, Shape({2}), {1, 0}));- auto transpose_seq_mask_f = std::make_shared<ov::op::v0::Convert>(transpose_seq_mask->output(0), data_type);+ std::make_shared<v1::Transpose>(seq_mask->output(0),+ v0::Constant::create(seq_len_type, Shape({2}), {1, 0}));+ auto transpose_seq_mask_f = std::make_shared<v0::Convert>(transpose_seq_mask->output(0), data_type);// Create CTCGreedyDecoder with original merge_repeated attribute and connect data and resulted seq_mask- auto decoder = std::make_shared<ov::op::v0::CTCGreedyDecoder>(transpose,- transpose_seq_mask_f->output(0),- decoder_seq_len->get_merge_repeated());+ auto decoder = std::make_shared<v0::CTCGreedyDecoder>(transpose,+ transpose_seq_mask_f->output(0),+ decoder_seq_len->get_merge_repeated());decoder->set_friendly_name(decoder_seq_len->get_friendly_name());// Normalize output from CTCGreedyDecoder = output_f and create second output with output_seq_len- auto squeeze2_axis = ov::op::v0::Constant::create(seq_len_type, Shape({1}), {3});- auto squeeze2_output_f = std::make_shared<ov::op::v0::Squeeze>(decoder->output(0), squeeze2_axis);- auto squeeze1_axis = ov::op::v0::Constant::create(seq_len_type, Shape({1}), {2});- auto squeeze1_output_f = std::make_shared<ov::op::v0::Squeeze>(squeeze2_output_f->output(0), squeeze1_axis);+ auto squeeze2_axis = v0::Constant::create(seq_len_type, Shape({1}), {3});+ auto squeeze2_output_f = std::make_shared<v0::Squeeze>(decoder->output(0), squeeze2_axis);+ auto squeeze1_axis = v0::Constant::create(seq_len_type, Shape({1}), {2});+ auto squeeze1_output_f = std::make_shared<v0::Squeeze>(squeeze2_output_f->output(0), squeeze1_axis);element::Type ci_type = decoder_seq_len->get_classes_index_type();element::Type sl_type = decoder_seq_len->get_sequence_length_type();// CTCGreedyDecoder return floating point output. For Normalize output we need to convert output to// classes_index_type Receive the first output with correct classes_index_type- auto output_i = std::make_shared<ov::op::v0::Convert>(squeeze1_output_f->output(0), ci_type);- auto minus1 = ov::op::v0::Constant::create(ci_type, Shape{}, {-1});+ auto output_i = std::make_shared<v0::Convert>(squeeze1_output_f->output(0), ci_type);+ auto minus1 = v0::Constant::create(ci_type, Shape{}, {-1});// Get to know where equal -1- auto where_equal_minus1 = std::make_shared<ov::op::v1::Equal>(output_i, minus1);+ auto where_equal_minus1 = std::make_shared<v1::Equal>(output_i, minus1);// Compute output seq mask- auto seq_mask_const0 = ov::op::v0::Constant::create(ci_type, Shape{1}, {0});- auto seq_mask_const1 = ov::op::v0::Constant::create(ci_type, Shape{1}, {1});- auto output_seq_mask =- std::make_shared<ov::op::v1::Select>(where_equal_minus1, seq_mask_const0, seq_mask_const1);- auto seq_mask_axis = ov::op::v0::Constant::create(ci_type, Shape{1}, {1});+ auto seq_mask_const0 = v0::Constant::create(ci_type, Shape{1}, {0});+ auto seq_mask_const1 = v0::Constant::create(ci_type, Shape{1}, {1});+ auto output_seq_mask = std::make_shared<v1::Select>(where_equal_minus1, seq_mask_const0, seq_mask_const1);+ auto seq_mask_axis = v0::Constant::create(ci_type, Shape{1}, {1});// Receive the second output- auto output_seq_len = std::make_shared<ov::op::v1::ReduceSum>(output_seq_mask, seq_mask_axis);+ auto output_seq_len = std::make_shared<v1::ReduceSum>(output_seq_mask, seq_mask_axis);// Receive the second output with correct seq_len_type- auto output_seq_len_i = std::make_shared<ov::op::v0::Convert>(output_seq_len->output(0), sl_type);+ auto output_seq_len_i = std::make_shared<v0::Convert>(output_seq_len->output(0), sl_type);ov::copy_runtime_info(decoder_seq_len,{transpose,decoder,@@ -156,6 +157,6 @@ ov::pass::SimplifyCTCGreedyDecoderSeqLen::SimplifyCTCGreedyDecoderSeqLen() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(decoder, matcher_name);+ auto m = std::make_shared<Matcher>(decoder, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cppindex d99e63a6181..5159d7575c1 100644--- a/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp@@ -21,10 +21,15 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;ov::pass::SoftmaxDecomposition::SoftmaxDecomposition() {MATCHER_SCOPE(SoftmaxDecomposition);- auto softmax = pattern::wrap_type<ov::op::v1::Softmax, ov::op::v8::Softmax>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto softmax = ov::pass::pattern::wrap_type<v1::Softmax, v8::Softmax>();+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto m_softmax = m.get_match_root();Output<Node> input;int64_t softmax_axis;@@ -33,22 +38,22 @@ ov::pass::SoftmaxDecomposition::SoftmaxDecomposition() {return false;}- if (auto m_softmax_v1 = ov::as_type_ptr<ov::op::v1::Softmax>(m_softmax)) {+ if (auto m_softmax_v1 = ov::as_type_ptr<v1::Softmax>(m_softmax)) {input = m_softmax_v1->input_value(0);softmax_axis = static_cast<int64_t>(m_softmax_v1->get_axis());- } else if (auto m_softmax_v8 = ov::as_type_ptr<ov::op::v8::Softmax>(m_softmax)) {+ } else if (auto m_softmax_v8 = ov::as_type_ptr<v8::Softmax>(m_softmax)) {input = m_softmax_v8->input_value(0);softmax_axis = m_softmax_v8->get_axis();} else {return false;}- auto axis = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {softmax_axis});- auto reduce_max = std::make_shared<ov::op::v1::ReduceMax>(input, axis, true);- auto sub = std::make_shared<ov::op::v1::Subtract>(input, reduce_max);- auto exp = std::make_shared<ov::op::v0::Exp>(sub);- auto reduce_sum = std::make_shared<ov::op::v1::ReduceSum>(exp, axis, true);- auto div = std::make_shared<ov::op::v1::Divide>(exp, reduce_sum);+ auto axis = v0::Constant::create(ov::element::i64, ov::Shape{1}, {softmax_axis});+ auto reduce_max = std::make_shared<v1::ReduceMax>(input, axis, true);+ auto sub = std::make_shared<v1::Subtract>(input, reduce_max);+ auto exp = std::make_shared<v0::Exp>(sub);+ auto reduce_sum = std::make_shared<v1::ReduceSum>(exp, axis, true);+ auto div = std::make_shared<v1::Divide>(exp, reduce_sum);replace_node(m_softmax, div);copy_runtime_info(m_softmax, {reduce_max, reduce_sum, sub, exp, div});@@ -56,6 +61,6 @@ ov::pass::SoftmaxDecomposition::SoftmaxDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(softmax, matcher_name);+ auto m = std::make_shared<Matcher>(softmax, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/softplus_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/softplus_decomposition.cppindex 38deebd004b..3dc07829d26 100644--- a/src/common/transformations/src/transformations/op_conversions/softplus_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/softplus_decomposition.cpp@@ -18,13 +18,16 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;ov::pass::SoftPlusDecomposition::SoftPlusDecomposition() {MATCHER_SCOPE(SoftPlusDecomposition);// decomposes SoftPlus(x) operation into ln(exp(x) + 1.0)- auto input = pattern::any_input();+ auto input = ov::pass::pattern::any_input();auto softplus = std::make_shared<ov::op::v4::SoftPlus>(input);- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto& pattern_to_output = m.get_pattern_value_map();auto softplus_input = pattern_to_output.at(input);auto softplus_node = pattern_to_output.at(softplus).get_node_shared_ptr();@@ -33,11 +36,11 @@ ov::pass::SoftPlusDecomposition::SoftPlusDecomposition() {return false;}- auto exp = std::make_shared<ov::op::v0::Exp>(softplus_input);+ auto exp = std::make_shared<v0::Exp>(softplus_input);auto add = std::make_shared<ov::op::v1::Add>(exp,- ov::op::v0::Constant::create(softplus_input.get_element_type(), ov::Shape{1}, {1.0}));- auto log = std::make_shared<ov::op::v0::Log>(add);+ v0::Constant::create(softplus_input.get_element_type(), ov::Shape{1}, {1.0}));+ auto log = std::make_shared<v0::Log>(add);log->set_friendly_name(softplus_node->get_friendly_name());ov::copy_runtime_info(softplus_node, {exp, add, log});@@ -45,6 +48,6 @@ ov::pass::SoftPlusDecomposition::SoftPlusDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(softplus, matcher_name);+ auto m = std::make_shared<Matcher>(softplus, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/softsign_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/softsign_decomposition.cppindex 14be3d82f92..83e63d6b55a 100644--- a/src/common/transformations/src/transformations/op_conversions/softsign_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/softsign_decomposition.cpp@@ -17,10 +17,14 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::SoftSignDecomposition::SoftSignDecomposition() {MATCHER_SCOPE(SoftSignDecomposition);- auto softsign = pattern::wrap_type<ov::op::v9::SoftSign>();- matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {+ auto softsign = ov::pass::pattern::wrap_type<ov::op::v9::SoftSign>();+ matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {auto m_softsign = m.get_match_root();if (transformation_callback(m_softsign)) {@@ -29,10 +33,10 @@ ov::pass::SoftSignDecomposition::SoftSignDecomposition() {const auto input = m_softsign->input_value(0);const auto& data_type = m_softsign->get_input_element_type(0);- auto abs = std::make_shared<ov::op::v0::Abs>(input);- auto constant = ov::op::v0::Constant::create(data_type, ov::Shape{1}, {1});- auto add = std::make_shared<ov::op::v1::Add>(abs, constant);- auto div = std::make_shared<ov::op::v1::Divide>(input, add);+ auto abs = std::make_shared<v0::Abs>(input);+ auto constant = v0::Constant::create(data_type, ov::Shape{1}, {1});+ auto add = std::make_shared<v1::Add>(abs, constant);+ auto div = std::make_shared<v1::Divide>(input, add);replace_node(m_softsign, div);copy_runtime_info(m_softsign, {abs, add, div});@@ -40,6 +44,6 @@ ov::pass::SoftSignDecomposition::SoftSignDecomposition() {return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(softsign, matcher_name);+ auto m = std::make_shared<Matcher>(softsign, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/op_conversions/unique_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/unique_decomposition.cppindex c0c5f261525..76b3433fca5 100644--- a/src/common/transformations/src/transformations/op_conversions/unique_decomposition.cpp+++ b/src/common/transformations/src/transformations/op_conversions/unique_decomposition.cpp@@ -38,13 +38,21 @@ using namespace std;using namespace ov;using namespace ov::pass;+using ov::pass::pattern::Matcher;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v8 = ov::op::v8;+namespace v10 = ov::op::v10;namespace {Output<Node> get_elements_number_1d(const ov::Output<ov::Node>& output,ov::element::Type output_type,ov::pass::NodeRegistry& rg) {auto output_rank = output.get_partial_shape().rank();- auto shape = rg.make<ov::op::v3::ShapeOf>(output, output_type);- auto num_elements = rg.make<ov::op::v0::Squeeze>(shape);+ auto shape = rg.make<v3::ShapeOf>(output, output_type);+ auto num_elements = rg.make<v0::Squeeze>(shape);return num_elements;}} // namespace@@ -52,12 +60,12 @@ Output<Node> get_elements_number_1d(const ov::Output<ov::Node>& output,ov::pass::UniqueDecomposition::UniqueDecomposition() {MATCHER_SCOPE(UniqueDecomposition);- auto unique = pattern::wrap_type<ov::op::v10::Unique>();+ auto unique = ov::pass::pattern::wrap_type<v10::Unique>();- matcher_pass_callback callback = [=](pattern::Matcher& matcher) {+ matcher_pass_callback callback = [=](Matcher& matcher) {NodeRegistry rg;- auto unique_node = ov::as_type_ptr<ov::op::v10::Unique>(matcher.get_match_root());+ auto unique_node = ov::as_type_ptr<v10::Unique>(matcher.get_match_root());if (!unique_node) {return false;}@@ -78,8 +86,8 @@ ov::pass::UniqueDecomposition::UniqueDecomposition() {auto x_unflatten = unique_node->input_value(0);// make input tensor flatten- auto minus_one_const = rg.make<ov::op::v0::Constant>(element::i32, Shape{1}, -1);- auto x = rg.make<ov::op::v1::Reshape>(x_unflatten, minus_one_const, false);+ auto minus_one_const = rg.make<v0::Constant>(element::i32, Shape{1}, -1);+ auto x = rg.make<v1::Reshape>(x_unflatten, minus_one_const, false);auto output_indices_type = unique_node->get_index_element_type();auto x_type = x_unflatten.get_element_type();@@ -99,7 +107,7 @@ ov::pass::UniqueDecomposition::UniqueDecomposition() {}if (!unique_node->get_output_target_inputs(2).empty()) {- auto zero_const = rg.make<ov::op::v0::Constant>(output_indices_type, Shape{1}, 0);+ auto zero_const = rg.make<v0::Constant>(output_indices_type, Shape{1}, 0);zero_const->set_friendly_name(unique_node->get_friendly_name() + ".2");unique_node->output(2).replace(zero_const->output(0));}@@ -112,65 +120,60 @@ ov::pass::UniqueDecomposition::UniqueDecomposition() {auto n = get_elements_number_1d(x, element::i32, rg);// create auxiliry constants to be re-used by different operations- auto zero_const = rg.make<ov::op::v0::Constant>(element::i32, Shape{1}, 0);- auto one_const = rg.make<ov::op::v0::Constant>(element::i32, Shape{1}, 1);- auto one_const_scalar = rg.make<ov::op::v0::Constant>(element::i32, Shape{}, 1);- auto true_const = rg.make<ov::op::v0::Constant>(element::boolean, Shape{1}, true);- auto one_const_out_idx = rg.make<ov::op::v0::Constant>(output_indices_type, Shape{1}, 1);- auto zero_const_out_idx = rg.make<ov::op::v0::Constant>(output_indices_type, Shape{1}, 0);+ auto zero_const = rg.make<v0::Constant>(element::i32, Shape{1}, 0);+ auto one_const = rg.make<v0::Constant>(element::i32, Shape{1}, 1);+ auto one_const_scalar = rg.make<v0::Constant>(element::i32, Shape{}, 1);+ auto true_const = rg.make<v0::Constant>(element::boolean, Shape{1}, true);+ auto one_const_out_idx = rg.make<v0::Constant>(output_indices_type, Shape{1}, 1);+ auto zero_const_out_idx = rg.make<v0::Constant>(output_indices_type, Shape{1}, 0);// compute unique elements but not in the original order// 1. sort elements in x in order to compute unique elements- auto x_sorted = rg.make<ov::op::v3::TopK>(x,- n,- 0,- ov::op::v3::TopK::Mode::MIN,- ov::op::v3::TopK::SortType::SORT_VALUES,- element::i32);+ auto x_sorted = rg.make<v3::TopK>(x, n, 0, v3::TopK::Mode::MIN, v3::TopK::SortType::SORT_VALUES, element::i32);// 2. generate two vectors from x_sorted vector by padding in the beginning and in the end:// x1 = [0, x0, x1, ..., xn]// x2 = [x0, x1, ..., xn, 0]- auto pad = rg.make<ov::op::v0::Constant>(x_type, Shape{1}, 0);- auto x1 = rg.make<ov::op::v0::Concat>(OutputVector{pad, x_sorted->output(0)}, 0);- auto x2 = rg.make<ov::op::v0::Concat>(OutputVector{x_sorted->output(0), pad}, 0);+ auto pad = rg.make<v0::Constant>(x_type, Shape{1}, 0);+ auto x1 = rg.make<v0::Concat>(OutputVector{pad, x_sorted->output(0)}, 0);+ auto x2 = rg.make<v0::Concat>(OutputVector{x_sorted->output(0), pad}, 0);// 3. compare two vectors to see where unique elements are placed// and correct a mask because the first element is always unique// because the latest boolean element must be removed from the mask since// the vectors are padded- auto mask1 = rg.make<ov::op::v1::NotEqual>(x1, x2);- auto mask1_part = rg.make<ov::op::v8::Slice>(mask1, one_const, minus_one_const, one_const, zero_const);- auto is_unique = rg.make<ov::op::v0::Concat>(OutputVector{true_const, mask1_part}, 0);+ auto mask1 = rg.make<v1::NotEqual>(x1, x2);+ auto mask1_part = rg.make<v8::Slice>(mask1, one_const, minus_one_const, one_const, zero_const);+ auto is_unique = rg.make<v0::Concat>(OutputVector{true_const, mask1_part}, 0);// 5. compute positions where unique elements are placed in the sorted x- auto is_unique_01 = rg.make<ov::op::v1::Select>(is_unique, one_const, zero_const);- auto indices = rg.make<ov::op::v3::NonZero>(is_unique_01, element::i64);- auto unique_element_indices = rg.make<ov::op::v0::Squeeze>(indices, zero_const);+ auto is_unique_01 = rg.make<v1::Select>(is_unique, one_const, zero_const);+ auto indices = rg.make<v3::NonZero>(is_unique_01, element::i64);+ auto unique_element_indices = rg.make<v0::Squeeze>(indices, zero_const);// 6. collect unique elements but currently they are not in the original order- auto unique_elements = rg.make<ov::op::v8::Gather>(x_sorted->output(0), unique_element_indices, zero_const);+ auto unique_elements = rg.make<v8::Gather>(x_sorted->output(0), unique_element_indices, zero_const);// compute unique elements in the original order- auto unsqueeze_x = rg.make<ov::op::v0::Unsqueeze>(x, zero_const);- auto unsqueeze_unique_elements = rg.make<ov::op::v0::Unsqueeze>(unique_elements, one_const);+ auto unsqueeze_x = rg.make<v0::Unsqueeze>(x, zero_const);+ auto unsqueeze_unique_elements = rg.make<v0::Unsqueeze>(unique_elements, one_const);// 1. compute a mask of pair comparison where each unique element is placed in the original- auto nplus1 = rg.make<ov::op::v1::Add>(n, one_const_scalar);- auto unique_vs_x = rg.make<ov::op::v1::Equal>(unsqueeze_unique_elements, unsqueeze_x);- auto unique_vs_x_01 = rg.make<ov::op::v1::Select>(unique_vs_x, one_const_scalar, nplus1);- auto range_1nplus1 = rg.make<ov::op::v4::Range>(one_const_scalar, nplus1, one_const_scalar, element::i32);- auto unsqueeze_range_1nplus1 = rg.make<ov::op::v0::Unsqueeze>(range_1nplus1, zero_const);+ auto nplus1 = rg.make<v1::Add>(n, one_const_scalar);+ auto unique_vs_x = rg.make<v1::Equal>(unsqueeze_unique_elements, unsqueeze_x);+ auto unique_vs_x_01 = rg.make<v1::Select>(unique_vs_x, one_const_scalar, nplus1);+ auto range_1nplus1 = rg.make<v4::Range>(one_const_scalar, nplus1, one_const_scalar, element::i32);+ auto unsqueeze_range_1nplus1 = rg.make<v0::Unsqueeze>(range_1nplus1, zero_const);// 2. compute a mask with indices counting from one- auto unique_vs_x_ind = rg.make<ov::op::v1::Multiply>(unique_vs_x_01, unsqueeze_range_1nplus1);+ auto unique_vs_x_ind = rg.make<v1::Multiply>(unique_vs_x_01, unsqueeze_range_1nplus1);// 3. compute positions of the first occurrence for each unique element// or these are positions of unique elements in the original order- auto minimum_indices_plus1 = rg.make<ov::op::v1::ReduceMin>(unique_vs_x_ind, one_const);- auto minimum_indices = rg.make<ov::op::v1::Subtract>(minimum_indices_plus1, one_const);+ auto minimum_indices_plus1 = rg.make<v1::ReduceMin>(unique_vs_x_ind, one_const);+ auto minimum_indices = rg.make<v1::Subtract>(minimum_indices_plus1, one_const);// denote a number of unique elements as mauto m = get_elements_number_1d(minimum_indices, element::i32, rg);- auto sorted_minumum_indices = rg.make<ov::op::v3::TopK>(minimum_indices,- m,- 0,- ov::op::v3::TopK::Mode::MIN,- ov::op::v3::TopK::SortType::SORT_VALUES,- element::i32);- auto output_unique_elements = rg.make<ov::op::v8::Gather>(x, sorted_minumum_indices->output(0), zero_const);+ auto sorted_minumum_indices = rg.make<v3::TopK>(minimum_indices,+ m,+ 0,+ v3::TopK::Mode::MIN,+ v3::TopK::SortType::SORT_VALUES,+ element::i32);+ auto output_unique_elements = rg.make<v8::Gather>(x, sorted_minumum_indices->output(0), zero_const);if (!unique_node->get_output_target_inputs(0).empty()) {output_unique_elements->set_friendly_name(unique_node->get_friendly_name() + ".0");@@ -181,19 +184,17 @@ ov::pass::UniqueDecomposition::UniqueDecomposition() {// compute the second output// indices of elements of x in the vector of unique elements// 1. compute a mask for unique elements in the original order- auto unsqueeze_output_unique_elements = rg.make<ov::op::v0::Unsqueeze>(output_unique_elements, one_const);- auto unique_vs_x_orig = rg.make<ov::op::v1::Equal>(unsqueeze_output_unique_elements, unsqueeze_x);- auto mplus1 = rg.make<ov::op::v1::Add>(m, one_const_scalar);- auto unique_vs_x_orig_01 =- rg.make<ov::op::v1::Select>(unique_vs_x_orig, one_const_out_idx, zero_const_out_idx);+ auto unsqueeze_output_unique_elements = rg.make<v0::Unsqueeze>(output_unique_elements, one_const);+ auto unique_vs_x_orig = rg.make<v1::Equal>(unsqueeze_output_unique_elements, unsqueeze_x);+ auto mplus1 = rg.make<v1::Add>(m, one_const_scalar);+ auto unique_vs_x_orig_01 = rg.make<v1::Select>(unique_vs_x_orig, one_const_out_idx, zero_const_out_idx);// 2. compute positions where each element from x is located in unique elements vector// the position counts from 1- auto range_1mplus1 =- rg.make<ov::op::v4::Range>(one_const_scalar, mplus1, one_const_scalar, output_indices_type);- auto unsqueeze_range_1mplus1 = rg.make<ov::op::v0::Unsqueeze>(range_1mplus1, one_const);- auto unique_vs_x_ind_orig = rg.make<ov::op::v1::Multiply>(unique_vs_x_orig_01, unsqueeze_range_1mplus1);- auto output_idx_plus1 = rg.make<ov::op::v1::ReduceMax>(unique_vs_x_ind_orig, zero_const);- auto output_idx = rg.make<ov::op::v1::Subtract>(output_idx_plus1, one_const_out_idx);+ auto range_1mplus1 = rg.make<v4::Range>(one_const_scalar, mplus1, one_const_scalar, output_indices_type);+ auto unsqueeze_range_1mplus1 = rg.make<v0::Unsqueeze>(range_1mplus1, one_const);+ auto unique_vs_x_ind_orig = rg.make<v1::Multiply>(unique_vs_x_orig_01, unsqueeze_range_1mplus1);+ auto output_idx_plus1 = rg.make<v1::ReduceMax>(unique_vs_x_ind_orig, zero_const);+ auto output_idx = rg.make<v1::Subtract>(output_idx_plus1, one_const_out_idx);output_idx->set_friendly_name(unique_node->get_friendly_name() + ".2");unique_node->output(2).replace(output_idx->output(0));@@ -204,6 +205,6 @@ ov::pass::UniqueDecomposition::UniqueDecomposition() {return true;};- auto m = make_shared<pattern::Matcher>(unique, matcher_name);+ auto m = make_shared<Matcher>(unique, matcher_name);this->register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/pattern_blocks/compressed_weights_block.cpp b/src/common/transformations/src/transformations/pattern_blocks/compressed_weights_block.cppindex 6f0836648c3..e808fc0650d 100644--- a/src/common/transformations/src/transformations/pattern_blocks/compressed_weights_block.cpp+++ b/src/common/transformations/src/transformations/pattern_blocks/compressed_weights_block.cpp@@ -24,26 +24,29 @@#include "ov_ops/fully_connected_compressed.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::pass::pattern;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;ov::pass::pattern::op::CompressedWeightsBlock::CompressedWeightsBlock(const std::vector<ov::element::Type>& supported_weights_types,const std::set<size_t>& supported_weights_ranks): Block({}, {}, "CompressedWeightsBlock") {- auto weights = wrap_type<ov::op::v0::Constant>(type_matches_any(supported_weights_types));- auto convert = wrap_type<ov::op::v0::Convert>({weights});+ auto weights = wrap_type<v0::Constant>(ov::pass::pattern::type_matches_any(supported_weights_types));+ auto convert = wrap_type<v0::Convert>({weights});- auto sub_const = wrap_type<ov::op::v0::Constant>();- auto sub_convert_const = wrap_type<ov::op::v0::Convert>({sub_const});- auto sub_with_convert = wrap_type<ov::op::v1::Subtract>({convert, sub_convert_const});- auto sub_no_convert = wrap_type<ov::op::v1::Subtract>({convert, sub_const});+ auto sub_const = wrap_type<v0::Constant>();+ auto sub_convert_const = wrap_type<v0::Convert>({sub_const});+ auto sub_with_convert = wrap_type<v1::Subtract>({convert, sub_convert_const});+ auto sub_no_convert = wrap_type<v1::Subtract>({convert, sub_const});auto subtract = sub_with_convert | sub_no_convert;- auto mul_const = wrap_type<ov::op::v0::Constant>();- auto mul_convert_const = wrap_type<ov::op::v0::Convert>({mul_const});+ auto mul_const = wrap_type<v0::Constant>();+ auto mul_convert_const = wrap_type<v0::Convert>({mul_const});auto mul_scale = mul_const | mul_convert_const;- auto mul_with_sub = wrap_type<ov::op::v1::Multiply>({subtract, mul_scale});- auto mul_no_sub = wrap_type<ov::op::v1::Multiply>({convert, mul_scale});+ auto mul_with_sub = wrap_type<v1::Multiply>({subtract, mul_scale});+ auto mul_no_sub = wrap_type<v1::Multiply>({convert, mul_scale});auto mul = mul_with_sub | mul_no_sub;auto reshape_predicate = [supported_weights_ranks](const ov::Output<ov::Node>& output) {@@ -57,14 +60,14 @@ ov::pass::pattern::op::CompressedWeightsBlock::CompressedWeightsBlock(supported_weights_ranks_before_reshape.count(in_ps.size()) &&supported_weights_ranks.count(out_ps.size());};- auto reshape_const = wrap_type<ov::op::v0::Constant>();- auto reshape = wrap_type<ov::op::v1::Reshape>({mul, reshape_const}, reshape_predicate);+ auto reshape_const = wrap_type<v0::Constant>();+ auto reshape = wrap_type<v1::Reshape>({mul, reshape_const}, reshape_predicate);auto transpose_input = reshape | mul;- auto transpose_const = wrap_type<ov::op::v0::Constant>();- auto transpose = wrap_type<ov::op::v1::Transpose>({transpose_input, transpose_const});+ auto transpose_const = wrap_type<v0::Constant>();+ auto transpose = wrap_type<v1::Transpose>({transpose_input, transpose_const});- auto weights_input = optional<ov::op::v0::Convert>({reshape | transpose | mul});+ auto weights_input = ov::pass::pattern::optional<v0::Convert>({reshape | transpose | mul});// Block initializationm_inputs = ov::OutputVector{weights};diff --git a/src/common/transformations/src/transformations/resolve_names_collisions.cpp b/src/common/transformations/src/transformations/resolve_names_collisions.cppindex 4f73c130b4c..9c1b0c39f41 100644--- a/src/common/transformations/src/transformations/resolve_names_collisions.cpp+++ b/src/common/transformations/src/transformations/resolve_names_collisions.cpp@@ -14,6 +14,7 @@#include "openvino/pass/manager.hpp"#include "openvino/util/common_util.hpp"+namespace op_util = ov::op::util;namespace ov::pass {using NodeNamesMap = std::unordered_map<std::string, std::list<Node*>>;@@ -96,7 +97,7 @@ void resolve_tensor_names(const ov::Model& model, TensorNamesMap& names_map) {}for (auto&& node : model.get_ordered_ops()) {- if (auto msn = ov::as_type<ov::op::util::MultiSubGraphOp>(node.get())) {+ if (auto msn = ov::as_type<op_util::MultiSubGraphOp>(node.get())) {for (const auto& body : msn->get_functions()) {resolve_tensor_names(*body, names_map);}@@ -111,7 +112,7 @@ void collect_name_collisions_map(const std::shared_ptr<ov::Model>& model, NodeNa// Collect a names collision map for all nodes in the graphconst auto& friendly_name = node->get_friendly_name();name_collisions_map[friendly_name].emplace_back(node.get());- if (auto msn = ov::as_type<ov::op::util::MultiSubGraphOp>(node.get())) {+ if (auto msn = ov::as_type<op_util::MultiSubGraphOp>(node.get())) {for (const auto& body : msn->get_functions()) {collect_name_collisions_map(body, name_collisions_map);}diff --git a/src/common/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp b/src/common/transformations/src/transformations/rt_info/primitives_priority_attribute.cppindex 35e8d8d0e00..716c93fe9b9 100644--- a/src/common/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp+++ b/src/common/transformations/src/transformations/rt_info/primitives_priority_attribute.cpp@@ -18,6 +18,7 @@using namespace ov;+namespace v1 = ov::op::v1;std::string ov::getPrimitivesPriority(const std::shared_ptr<ov::Node>& node) {if (node) {const auto& rtInfo = node->get_rt_info();@@ -33,9 +34,9 @@ std::string ov::getPrimitivesPriority(const std::shared_ptr<ov::Node>& node) {Any PrimitivesPriority::merge(const ov::NodeVector& nodes) const {auto canBeMerged = [](const std::shared_ptr<Node>& node) -> bool {- if (ov::as_type_ptr<ov::op::v1::Convolution>(node) || ov::as_type_ptr<ov::op::v1::GroupConvolution>(node) ||- ov::as_type_ptr<ov::op::v1::GroupConvolutionBackpropData>(node) ||- ov::as_type_ptr<ov::op::v1::ConvolutionBackpropData>(node) || ov::as_type_ptr<ov::op::v0::MatMul>(node)) {+ if (ov::as_type_ptr<v1::Convolution>(node) || ov::as_type_ptr<v1::GroupConvolution>(node) ||+ ov::as_type_ptr<v1::GroupConvolutionBackpropData>(node) ||+ ov::as_type_ptr<v1::ConvolutionBackpropData>(node) || ov::as_type_ptr<ov::op::v0::MatMul>(node)) {return true;}return false;diff --git a/src/common/transformations/src/transformations/sdpa_to_paged_attention/position_ids_replacer.cpp b/src/common/transformations/src/transformations/sdpa_to_paged_attention/position_ids_replacer.cppindex 2e5b96bb56e..036d8d334a1 100644--- a/src/common/transformations/src/transformations/sdpa_to_paged_attention/position_ids_replacer.cpp+++ b/src/common/transformations/src/transformations/sdpa_to_paged_attention/position_ids_replacer.cpp@@ -26,9 +26,13 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::op;-using namespace ov::pass::pattern;+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;// TODO: Instead of using the following transformation that matches quite a specific place in a model graph in case when// position_ids parameter is missing, consider replacing always existing attention_mask parameter with a sub-graph using// a new slot_mapping parameter.@@ -44,7 +48,7 @@ ov::pass::PositionIDsReplacer::PositionIDsReplacer(const Output<Node>& position_auto convert = wrap_type<v0::Convert>({add_offset});auto position_embed = wrap_type<v8::Gather>({any_input(), convert, any_input()});- auto mul = optional<v0::MatMul>({input_embed, any_input()});+ auto mul = ov::pass::pattern::optional<v0::MatMul>({input_embed, any_input()});auto add = wrap_type<v1::Add>({mul, position_embed});@@ -63,8 +67,8 @@ ov::pass::PositionIDsReplacerQwen::PositionIDsReplacerQwen(const Output<Node>& p// total seq len:auto p_max_context_len = wrap_type<v0::Parameter>();- auto p_opt_convert = optional<v0::Convert>(p_max_context_len);- auto p_opt_reshape = optional<v1::Reshape>({p_opt_convert, any_input()});+ auto p_opt_convert = ov::pass::pattern::optional<v0::Convert>(p_max_context_len);+ auto p_opt_reshape = ov::pass::pattern::optional<v1::Reshape>({p_opt_convert, any_input()});// current seq len:// it might be present in 2 different ways:@@ -72,12 +76,13 @@ ov::pass::PositionIDsReplacerQwen::PositionIDsReplacerQwen(const Output<Node>& p// QKV -> variadic_split(Q or K) -> rope Q/K -> shape_of -> gather// Probably we can use the symbols to re-use one of these ways.// Currently, "any_input" is used to detect the both places.- auto p_shape_of = wrap_type<v3::ShapeOf>({any_input()});- auto p_current_len = wrap_type<v8::Gather>({p_shape_of, wrap_const(), wrap_const()});+ auto p_shape_of = wrap_type<ov::op::v3::ShapeOf>({any_input()});+ auto p_current_len =+ wrap_type<v8::Gather>({p_shape_of, ov::pass::pattern::wrap_const(), ov::pass::pattern::wrap_const()});auto p_neg_const = wrap_type<v0::Constant>();- auto p_neg_const_convert = optional<v0::Convert>(p_neg_const);- auto p_neg_const_reshape = optional<v1::Reshape>({p_neg_const_convert, any_input()});+ auto p_neg_const_convert = ov::pass::pattern::optional<v0::Convert>(p_neg_const);+ auto p_neg_const_reshape = ov::pass::pattern::optional<v1::Reshape>({p_neg_const_convert, any_input()});auto p_neg_mul = wrap_type<v1::Multiply>({p_current_len, p_neg_const_reshape});// For now, it has always been a constant, but this may change in the future.@@ -86,11 +91,18 @@ ov::pass::PositionIDsReplacerQwen::PositionIDsReplacerQwen(const Output<Node>& p//// Also, it hasn't been observed yet, but, theoretically, there can also be a// dequantizing subgraph, so it's going to be any_input() here.- auto p_rotary_emb_sincos = pattern::any_input();+ auto p_rotary_emb_sincos = any_input();// the rotary_emb_cos/rotary_emb_sin are sliced by the total length [1,..4096,1,128]- auto p_slice_1 =- wrap_type<v8::Slice>({p_rotary_emb_sincos, wrap_const(), p_opt_reshape, wrap_const(), wrap_const()});- auto p_slice_2 = wrap_type<v8::Slice>({p_slice_1, p_neg_mul, wrap_const(), wrap_const(), wrap_const()});+ auto p_slice_1 = wrap_type<v8::Slice>({p_rotary_emb_sincos,+ ov::pass::pattern::wrap_const(),+ p_opt_reshape,+ ov::pass::pattern::wrap_const(),+ ov::pass::pattern::wrap_const()});+ auto p_slice_2 = wrap_type<v8::Slice>({p_slice_1,+ p_neg_mul,+ ov::pass::pattern::wrap_const(),+ ov::pass::pattern::wrap_const(),+ ov::pass::pattern::wrap_const()});ov::matcher_pass_callback callback = [=](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -132,18 +144,19 @@ ov::pass::PositionIDsReplacerQwen::PositionIDsReplacerQwen(const Output<Node>& pov::pass::PositionIDsReplacerCodeGen2::PositionIDsReplacerCodeGen2(const std::shared_ptr<v0::Parameter>& position_ids) {MATCHER_SCOPE(PositionIDsReplacerCodeGen2);- auto p_range = wrap_type<v4::Range>();+ auto p_range = wrap_type<ov::op::v4::Range>();auto p_power = wrap_type<v1::Power>();- auto p_einsum = wrap_type<v7::Einsum>({p_range, p_power});+ auto p_einsum = wrap_type<ov::op::v7::Einsum>({p_range, p_power});auto p_sin_cos = wrap_type<v0::Sin, v0::Cos>({p_einsum});auto p_reshape = wrap_type<v1::Reshape>({p_sin_cos, any_input()});auto p_tile = wrap_type<v0::Tile>({p_reshape, any_input()});- auto p_opt_reshape = optional<v1::Reshape>({p_tile, any_input()});- auto p_opt_unsq = optional<v0::Unsqueeze>({p_opt_reshape, any_input()});+ auto p_opt_reshape = ov::pass::pattern::optional<v1::Reshape>({p_tile, any_input()});+ auto p_opt_unsq = ov::pass::pattern::optional<v0::Unsqueeze>({p_opt_reshape, any_input()});auto p_reshape_1in = wrap_type<v1::Reshape>({any_input(), any_input()});auto p_add_2in = wrap_type<v1::Add>({any_input(), any_input()});- auto p_slice = wrap_type<v8::Slice>({p_opt_unsq, p_reshape_1in, p_add_2in, wrap_const(), wrap_const()});+ auto p_slice = wrap_type<v8::Slice>(+ {p_opt_unsq, p_reshape_1in, p_add_2in, ov::pass::pattern::wrap_const(), ov::pass::pattern::wrap_const()});auto p_add = wrap_type<v1::Add>();matcher_pass_callback callback = [=, &position_ids](Matcher& m) {diff --git a/src/common/transformations/src/transformations/sdpa_to_paged_attention/prev_sequence_length_pattern.cpp b/src/common/transformations/src/transformations/sdpa_to_paged_attention/prev_sequence_length_pattern.cppindex 21001c6d5b1..a207c4d9f33 100644--- a/src/common/transformations/src/transformations/sdpa_to_paged_attention/prev_sequence_length_pattern.cpp+++ b/src/common/transformations/src/transformations/sdpa_to_paged_attention/prev_sequence_length_pattern.cpp@@ -13,8 +13,13 @@#include "openvino/op/subtract.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-using namespace ov::op;+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;+namespace v0 = ov::op::v0;+namespace v3 = ov::op::v3;+namespace v8 = ov::op::v8;ov::pass::PrevSequenceLengthPattern::PrevSequenceLengthPattern(const std::shared_ptr<ov::Node>& unsqueezed_input_ids,const std::shared_ptr<ov::Node>& max_context_len,const std::shared_ptr<ov::Node>& position_ids) {@@ -22,12 +27,12 @@ ov::pass::PrevSequenceLengthPattern::PrevSequenceLengthPattern(const std::shared// The transformation addresses two cases that look similar: (1) previous sequence length, (2) batch size in// kv-cache state In first case it should replace it by prev_max_seq_len. For the second case, connect to batch_dim.- auto kv_past = pattern::wrap_type<v6::ReadValue>({pattern::any_input()});- auto kv_gather = pattern::wrap_type<v8::Gather>({kv_past, pattern::any_input(), pattern::any_input()});- auto kv_shape = pattern::wrap_type<v3::ShapeOf>({kv_gather});- auto seq = pattern::wrap_type<v8::Gather>({kv_shape, pattern::any_input(), pattern::any_input()});+ auto kv_past = wrap_type<ov::op::v6::ReadValue>({any_input()});+ auto kv_gather = wrap_type<v8::Gather>({kv_past, any_input(), any_input()});+ auto kv_shape = wrap_type<v3::ShapeOf>({kv_gather});+ auto seq = wrap_type<v8::Gather>({kv_shape, any_input(), any_input()});- ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {+ ov::matcher_pass_callback callback = [=](Matcher& m) {// TODO: Check that seq has axis that really takes sequence len but not any other dimension -- use symbolics or// look at the constant input// Detect the case by taking initialization expression for ReadValue and compare it with the second gather index@@ -46,7 +51,7 @@ ov::pass::PrevSequenceLengthPattern::PrevSequenceLengthPattern(const std::sharedv0::Constant::create(element::i64, Shape{}, {1}),v0::Constant::create(element::i64, Shape{}, {0}));auto cur_seq_len_i32 = std::make_shared<v0::Convert>(cur_seq_len, element::i32);- auto prev_max_seq_len = std::make_shared<v1::Subtract>(max_context_len, cur_seq_len_i32);+ auto prev_max_seq_len = std::make_shared<ov::op::v1::Subtract>(max_context_len, cur_seq_len_i32);replacement = prev_max_seq_len;} else {// it is not always required, so will be disposed if not needed@@ -67,6 +72,6 @@ ov::pass::PrevSequenceLengthPattern::PrevSequenceLengthPattern(const std::sharedreturn true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(seq, matcher_name);+ auto m = std::make_shared<Matcher>(seq, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/sdpa_to_paged_attention/state_management_pattern.cpp b/src/common/transformations/src/transformations/sdpa_to_paged_attention/state_management_pattern.cppindex c52427a3713..8e35e8c8d43 100644--- a/src/common/transformations/src/transformations/sdpa_to_paged_attention/state_management_pattern.cpp+++ b/src/common/transformations/src/transformations/sdpa_to_paged_attention/state_management_pattern.cpp@@ -39,55 +39,62 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;+using ov::pass::pattern::op::Or;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v8 = ov::op::v8;+namespace v13 = ov::op::v13;+namespace v15 = ov::op::v15;constexpr const char* NUM_K_HEADS = "num_k_heads";constexpr const char* K_HEAD_SIZE = "k_head_size";constexpr const char* NUM_V_HEADS = "num_v_heads";constexpr const char* V_HEAD_SIZE = "v_head_size";--using namespace ov::op;using namespace ov::pass;using ov::OutputVector;static std::tuple<std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>> general_alibi_pattern() {// Optional pattern to capture alibi slopes (based on pattern from bloom)- auto general_alibi = pattern::any_input();- auto general_sdpa_mask =- pattern::wrap_type<v1::Multiply>({pattern::any_input(), general_alibi}); // apply input position_ids- general_sdpa_mask = pattern::wrap_type<v1::Reshape>({general_sdpa_mask, pattern::any_input()});- general_sdpa_mask = pattern::wrap_type<v1::Reshape>({general_sdpa_mask, pattern::any_input()});- general_sdpa_mask = pattern::wrap_type<v1::Select>({pattern::any_input(), pattern::any_input(), general_sdpa_mask});+ auto general_alibi = any_input();+ auto general_sdpa_mask = wrap_type<v1::Multiply>({any_input(), general_alibi}); // apply input position_ids+ general_sdpa_mask = wrap_type<v1::Reshape>({general_sdpa_mask, any_input()});+ general_sdpa_mask = wrap_type<v1::Reshape>({general_sdpa_mask, any_input()});+ general_sdpa_mask = wrap_type<v1::Select>({any_input(), any_input(), general_sdpa_mask});return {general_alibi, general_sdpa_mask};}static std::tuple<std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>> jais_13b_alibi_pattern() {- auto jais_13b_alibi = pattern::any_input();- auto mirroring_abs = pattern::wrap_type<v0::Abs>({pattern::any_input()});- auto unsqueeze = pattern::wrap_type<v0::Unsqueeze>({mirroring_abs, pattern::any_input()});- auto jais_alibi_mask = pattern::wrap_type<v1::Multiply>({jais_13b_alibi, unsqueeze});- jais_alibi_mask = pattern::wrap_type<v3::Broadcast>({jais_alibi_mask, pattern::any_input()});- jais_alibi_mask = pattern::wrap_type<v0::Unsqueeze>({jais_alibi_mask, pattern::any_input()});- jais_alibi_mask = pattern::wrap_type<v1::Add>({pattern::any_input(), jais_alibi_mask});+ auto jais_13b_alibi = any_input();+ auto mirroring_abs = wrap_type<v0::Abs>({any_input()});+ auto unsqueeze = wrap_type<v0::Unsqueeze>({mirroring_abs, any_input()});+ auto jais_alibi_mask = wrap_type<v1::Multiply>({jais_13b_alibi, unsqueeze});+ jais_alibi_mask = wrap_type<v3::Broadcast>({jais_alibi_mask, any_input()});+ jais_alibi_mask = wrap_type<v0::Unsqueeze>({jais_alibi_mask, any_input()});+ jais_alibi_mask = wrap_type<v1::Add>({any_input(), jais_alibi_mask});return {jais_13b_alibi, jais_alibi_mask};}static std::tuple<std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>> baichuan2_13b_alibi_pattern() {- auto baichuan2_alibi = pattern::any_input();+ auto baichuan2_alibi = any_input();// this slice expected to be replaced with Slice(alibi_const, start {1, 1}, stop {2, 2}, step {1, 1}, axes{1, 2});- auto alibi_slice_to_replace = pattern::wrap_type<v8::Slice>(- {baichuan2_alibi, pattern::any_input(), pattern::any_input(), pattern::any_input(), pattern::any_input()});- auto alibi_path = pattern::wrap_type<v3::ShapeOf>({alibi_slice_to_replace});- alibi_path = pattern::wrap_type<v8::Gather>({alibi_path, pattern::any_input(), pattern::any_input()});- alibi_path = pattern::wrap_type<v0::Concat>({pattern::any_input(), pattern::any_input(), alibi_path});- alibi_path = pattern::wrap_type<v3::Broadcast>({pattern::any_input(), alibi_path});- alibi_path = pattern::wrap_type<v0::Convert>({alibi_path});- alibi_path = pattern::wrap_type<v1::Multiply>({alibi_path, pattern::any_input()});- alibi_path = pattern::wrap_type<v1::Subtract>({pattern::any_input(), alibi_path});- alibi_path = pattern::wrap_type<v1::Select>({pattern::any_input(), pattern::any_input(), alibi_path});- auto alibi_unsqueeze = pattern::wrap_type<v0::Unsqueeze>({alibi_slice_to_replace, pattern::any_input()});- alibi_path = pattern::wrap_type<v1::Add>({alibi_path, alibi_unsqueeze});- auto mul = pattern::wrap_type<v1::Multiply>({pattern::any_input(), pattern::any_input()});- alibi_path = pattern::wrap_type<v8::Slice>(- {alibi_path, mul, pattern::any_input(), pattern::any_input(), pattern::any_input()});+ auto alibi_slice_to_replace =+ wrap_type<v8::Slice>({baichuan2_alibi, any_input(), any_input(), any_input(), any_input()});+ auto alibi_path = wrap_type<v3::ShapeOf>({alibi_slice_to_replace});+ alibi_path = wrap_type<v8::Gather>({alibi_path, any_input(), any_input()});+ alibi_path = wrap_type<v0::Concat>({any_input(), any_input(), alibi_path});+ alibi_path = wrap_type<v3::Broadcast>({any_input(), alibi_path});+ alibi_path = wrap_type<v0::Convert>({alibi_path});+ alibi_path = wrap_type<v1::Multiply>({alibi_path, any_input()});+ alibi_path = wrap_type<v1::Subtract>({any_input(), alibi_path});+ alibi_path = wrap_type<v1::Select>({any_input(), any_input(), alibi_path});+ auto alibi_unsqueeze = wrap_type<v0::Unsqueeze>({alibi_slice_to_replace, any_input()});+ alibi_path = wrap_type<v1::Add>({alibi_path, alibi_unsqueeze});+ auto mul = wrap_type<v1::Multiply>({any_input(), any_input()});+ alibi_path = wrap_type<v8::Slice>({alibi_path, mul, any_input(), any_input(), any_input()});return {baichuan2_alibi, alibi_path};}@@ -186,45 +193,41 @@ static std::shared_ptr<ov::Node> handle_baichuan2_13b_alibi(}static std::tuple<std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>> phi3_sliding_window_pattern() {- using namespace ov::pass::pattern;-auto offset = wrap_type<v0::Constant>();auto t196 = wrap_type<v1::Add>({any_input(), offset});- auto t197 = pattern::optional<v0::Convert>(t196);- auto t200 = pattern::wrap_type<v4::Range>({t197, any_input(), any_input()});- auto t201 = pattern::wrap_type<v0::Unsqueeze>({t200, any_input()});- auto t202 = pattern::wrap_type<v1::GreaterEqual>({any_input(), t201});- auto t208 = pattern::wrap_type<v1::Select>({t202, any_input(), any_input()});- auto t209 = pattern::wrap_type<v1::Subtract>({any_input(), t208});- auto t210 = pattern::optional<v0::Convert>(t209);- auto t211 = pattern::wrap_type<v1::Select>({t210, any_input(), any_input()});- auto t213 = pattern::wrap_type<v0::Unsqueeze>({t211, any_input()});- auto t214 = pattern::wrap_type<v0::Unsqueeze>({t213, any_input()});- auto t218 = pattern::wrap_type<v3::Broadcast>({t214, any_input()});- auto t219 = pattern::wrap_type<v1::Select>({any_input(), any_input(), t218});- auto mask = pattern::wrap_type<v8::Slice>({t219, any_input(), any_input(), any_input(), any_input()});+ auto t197 = ov::pass::pattern::optional<v0::Convert>(t196);+ auto t200 = wrap_type<ov::op::v4::Range>({t197, any_input(), any_input()});+ auto t201 = wrap_type<v0::Unsqueeze>({t200, any_input()});+ auto t202 = wrap_type<v1::GreaterEqual>({any_input(), t201});+ auto t208 = wrap_type<v1::Select>({t202, any_input(), any_input()});+ auto t209 = wrap_type<v1::Subtract>({any_input(), t208});+ auto t210 = ov::pass::pattern::optional<v0::Convert>(t209);+ auto t211 = wrap_type<v1::Select>({t210, any_input(), any_input()});+ auto t213 = wrap_type<v0::Unsqueeze>({t211, any_input()});+ auto t214 = wrap_type<v0::Unsqueeze>({t213, any_input()});+ auto t218 = wrap_type<v3::Broadcast>({t214, any_input()});+ auto t219 = wrap_type<v1::Select>({any_input(), any_input(), t218});+ auto mask = wrap_type<v8::Slice>({t219, any_input(), any_input(), any_input(), any_input()});return {mask, offset};}static std::tuple<std::shared_ptr<ov::Node>, std::shared_ptr<ov::Node>> gpt_oss_sliding_window_pattern() {- using namespace ov::pass::pattern;-- auto q_idx = pattern::any_input();- auto kv_idx = pattern::any_input();+ auto q_idx = any_input();+ auto kv_idx = any_input();- auto kv_idx_opt_conv = pattern::optional<v0::Convert>(kv_idx);+ auto kv_idx_opt_conv = ov::pass::pattern::optional<v0::Convert>(kv_idx);auto offset = wrap_type<v0::Constant>();auto add = wrap_type<v1::Add>({q_idx, offset});- auto greater = pattern::wrap_type<v1::Greater>({kv_idx_opt_conv, add});- auto bitwise_and = pattern::wrap_type<v13::BitwiseAnd>({any_input(), greater});- auto bitwise_and_1 = pattern::wrap_type<v13::BitwiseAnd>({bitwise_and, any_input()});- auto bitwise_and_2 = pattern::wrap_type<v13::BitwiseAnd>({any_input(), bitwise_and_1});- auto bitwise_and_3 = pattern::wrap_type<v13::BitwiseAnd>({bitwise_and_2, any_input()});- auto broadcast = pattern::wrap_type<v3::Broadcast>({bitwise_and_3, any_input()});- auto select = pattern::wrap_type<v1::Select>({broadcast, any_input(), any_input()});- auto mask = pattern::wrap_type<v8::Slice>({select, any_input(), any_input(), any_input(), any_input()});+ auto greater = wrap_type<v1::Greater>({kv_idx_opt_conv, add});+ auto bitwise_and = wrap_type<v13::BitwiseAnd>({any_input(), greater});+ auto bitwise_and_1 = wrap_type<v13::BitwiseAnd>({bitwise_and, any_input()});+ auto bitwise_and_2 = wrap_type<v13::BitwiseAnd>({any_input(), bitwise_and_1});+ auto bitwise_and_3 = wrap_type<v13::BitwiseAnd>({bitwise_and_2, any_input()});+ auto broadcast = wrap_type<v3::Broadcast>({bitwise_and_3, any_input()});+ auto select = wrap_type<v1::Select>({broadcast, any_input(), any_input()});+ auto mask = wrap_type<v8::Slice>({select, any_input(), any_input(), any_input(), any_input()});return {mask, offset};}@@ -244,20 +247,18 @@ typedef std::node_tuple;static node_tuple kv_read_and_concat(ov::Output<ov::Node> kv_current) {- auto kv_past_var = pattern::wrap_type<v6::ReadValue>({pattern::any_input()});- auto kv_past_par = pattern::wrap_type<v0::Parameter>();- auto kv_past = std::make_shared<pattern::op::Or>(- OutputVector{pattern::wrap_type<v8::Gather>({kv_past_var, pattern::any_input(), pattern::any_input()}),- kv_past_par});- kv_past = std::make_shared<pattern::op::Or>(+ auto kv_past_var = wrap_type<ov::op::v6::ReadValue>({any_input()});+ auto kv_past_par = wrap_type<v0::Parameter>();+ auto kv_past =+ std::make_shared<Or>(OutputVector{wrap_type<v8::Gather>({kv_past_var, any_input(), any_input()}), kv_past_par});+ kv_past = std::make_shared<Or>(OutputVector{kv_past,- pattern::wrap_type<v1::Transpose>(- {kv_past, pattern::any_input()})}); // Transpose is used when kv-cache is stored in a not- // usual layout, example: bloom- auto kv_current2 = pattern::any_input();- auto kv_current_reshaped = pattern::wrap_type<v1::Reshape>({kv_current2, pattern::any_input()});- auto kv_concat = pattern::wrap_type<v0::Concat>(- {kv_past, std::make_shared<pattern::op::Or>(OutputVector{kv_current_reshaped, kv_current})});+ wrap_type<v1::Transpose>({kv_past, any_input()})}); // Transpose is used when kv-cache is stored+ // in a not usual layout, example: bloom+ auto kv_current2 = any_input();+ auto kv_current_reshaped = wrap_type<v1::Reshape>({kv_current2, any_input()});+ auto kv_concat =+ wrap_type<v0::Concat>({kv_past, std::make_shared<Or>(OutputVector{kv_current_reshaped, kv_current})});return node_tuple(kv_past_par, kv_current2, kv_current_reshaped, kv_concat);}@@ -277,7 +278,7 @@ static ov::Dimension extract_num_kv_heads(const std::shared_ptr<ov::Node>& unsqureturn ov::Dimension();}auto axis = unsqueeze->get_input_node_ptr(1);- auto constant = ov::as_type<ov::op::v0::Constant>(axis);+ auto constant = ov::as_type<v0::Constant>(axis);if (!constant) {return ov::Dimension();}@@ -322,11 +323,11 @@ ov::pass::StateManagementPattern::StateManagementPattern(const std::map<std::string, std::shared_ptr<op::v0::Parameter>>& optional_model_wide_params) {MATCHER_SCOPE(StateManagementPattern);- auto k_current = pattern::any_input();+ auto k_current = any_input();std::shared_ptr<ov::Node> k_past_par, k_current2, k_concat, k_current_reshaped;std::tie(k_past_par, k_current2, k_current_reshaped, k_concat) = kv_read_and_concat(k_current);- auto v_current = pattern::any_input();+ auto v_current = any_input();std::shared_ptr<ov::Node> v_past_par, v_current2, v_concat, v_current_reshaped;std::tie(v_past_par, v_current2, v_current_reshaped, v_concat) = kv_read_and_concat(v_current);@@ -335,37 +336,28 @@ ov::pass::StateManagementPattern::StateManagementPattern(// TODO: Consider not specifying VariadicSplit as an input for Concat, it is not really used in the pattern, but// just sets more strict requirement for the graph. The risk with not specifying VariadicSplit is that it can be// ambiguous which part the matcher should take: KV merged part or where K and V are separate, requires experiments.- auto qkv_current_split_node =- pattern::wrap_type<v1::VariadicSplit>({pattern::any_input(), pattern::any_input(), pattern::any_input()});+ auto qkv_current_split_node = wrap_type<v1::VariadicSplit>({any_input(), any_input(), any_input()});qkv_current_split_node->set_output_size(2);auto kv_current = qkv_current_split_node->output(1);std::shared_ptr<ov::Node> kv_past_par, kv_current2, kv_concat, kv_current_reshaped;std::tie(kv_past_par, kv_current2, kv_current_reshaped, kv_concat) = kv_read_and_concat(kv_current);- auto kv_concat_split =- pattern::wrap_type<v1::VariadicSplit>({kv_concat, pattern::any_input(), pattern::any_input()});+ auto kv_concat_split = wrap_type<v1::VariadicSplit>({kv_concat, any_input(), any_input()});kv_concat_split->set_output_size(2);- k_concat = std::make_shared<pattern::op::Or>(OutputVector{kv_concat_split->output(0), k_concat});- v_concat = std::make_shared<pattern::op::Or>(OutputVector{kv_concat_split->output(1), v_concat});+ k_concat = std::make_shared<Or>(OutputVector{kv_concat_split->output(0), k_concat});+ v_concat = std::make_shared<Or>(OutputVector{kv_concat_split->output(1), v_concat});auto kv_shaping = [=](const std::shared_ptr<Node>& kv_concat, std::shared_ptr<Node>& unsqueeze) {// Return unsqeeze (return param) to deduce number of kv heads in// the place where they are being broadcases in case of GQA and MQ- auto interim = pattern::wrap_type<v1::StridedSlice>(- {kv_concat, pattern::any_input(), pattern::any_input(), pattern::any_input()});- interim = pattern::wrap_type<v1::StridedSlice>(- {interim, pattern::any_input(), pattern::any_input(), pattern::any_input()});- unsqueeze = pattern::wrap_type<v0::Unsqueeze>(- {std::make_shared<pattern::op::Or>(OutputVector{kv_concat, interim}), pattern::any_input()});- interim = pattern::wrap_type<v1::StridedSlice>(- {unsqueeze, pattern::any_input(), pattern::any_input(), pattern::any_input()});- interim = pattern::wrap_type<v1::StridedSlice>(- {interim, pattern::any_input(), pattern::any_input(), pattern::any_input()});- interim = pattern::wrap_type<v3::Broadcast>(- {std::make_shared<pattern::op::Or>(OutputVector{unsqueeze, interim}), pattern::any_input()});- interim = std::make_shared<pattern::op::Or>(- OutputVector{pattern::wrap_type<v1::Reshape>({interim, pattern::any_input()}),- interim}); // Reshape is missing sometimes in MQA case+ auto interim = wrap_type<v1::StridedSlice>({kv_concat, any_input(), any_input(), any_input()});+ interim = wrap_type<v1::StridedSlice>({interim, any_input(), any_input(), any_input()});+ unsqueeze = wrap_type<v0::Unsqueeze>({std::make_shared<Or>(OutputVector{kv_concat, interim}), any_input()});+ interim = wrap_type<v1::StridedSlice>({unsqueeze, any_input(), any_input(), any_input()});+ interim = wrap_type<v1::StridedSlice>({interim, any_input(), any_input(), any_input()});+ interim = wrap_type<v3::Broadcast>({std::make_shared<Or>(OutputVector{unsqueeze, interim}), any_input()});+ interim = std::make_shared<Or>(OutputVector{wrap_type<v1::Reshape>({interim, any_input()}),+ interim}); // Reshape is missing sometimes in MQA casereturn interim;};@@ -374,17 +366,17 @@ ov::pass::StateManagementPattern::StateManagementPattern(auto k_shaped = kv_shaping(k_concat, k_heads_unsqueeze);auto v_shaped = kv_shaping(v_concat, v_heads_unsqueeze);- auto k_simply_shaped = pattern::wrap_type<v1::Reshape>({k_concat, pattern::any_input()});- auto v_simply_shaped = pattern::wrap_type<v1::Reshape>({v_concat, pattern::any_input()});+ auto k_simply_shaped = wrap_type<v1::Reshape>({k_concat, any_input()});+ auto v_simply_shaped = wrap_type<v1::Reshape>({v_concat, any_input()});- auto k_order = pattern::any_input();- auto v_order = pattern::any_input();+ auto k_order = any_input();+ auto v_order = any_input();// KV-path may already have Transposes that will be rewritten based on PA KV inputs required layout- auto k_shaped_transposed = pattern::wrap_type<v1::Transpose>(- {std::make_shared<pattern::op::Or>(OutputVector{k_concat, k_shaped}), k_order});- auto v_shaped_transposed = pattern::wrap_type<v1::Transpose>(- {std::make_shared<pattern::op::Or>(OutputVector{v_concat, v_shaped}), v_order});+ auto k_shaped_transposed =+ wrap_type<v1::Transpose>({std::make_shared<Or>(OutputVector{k_concat, k_shaped}), k_order});+ auto v_shaped_transposed =+ wrap_type<v1::Transpose>({std::make_shared<Or>(OutputVector{v_concat, v_shaped}), v_order});// Optional pattern to capture alibi slopes (based on pattern from bloom)std::shared_ptr<ov::Node> general_alibi, general_alibi_mask;@@ -412,31 +404,27 @@ ov::pass::StateManagementPattern::StateManagementPattern((output.get_partial_shape() == ov::PartialShape{1} && output.get_partial_shape()[0] == 1);};- auto q = pattern::any_input();- auto scale_input = pattern::any_input(scale_predicate);- auto sinks = pattern::any_input(pattern::has_static_shape() && pattern::rank_equals(4));+ auto q = any_input();+ auto scale_input = any_input(scale_predicate);+ auto sinks = any_input(ov::pass::pattern::has_static_shape() && ov::pass::pattern::rank_equals(4));- auto k_to_sdpa =- std::make_shared<pattern::op::Or>(OutputVector{k_concat, k_shaped, k_shaped_transposed, k_simply_shaped});- auto v_to_sdpa =- std::make_shared<pattern::op::Or>(OutputVector{v_concat, v_shaped, v_shaped_transposed, v_simply_shaped});+ auto k_to_sdpa = std::make_shared<Or>(OutputVector{k_concat, k_shaped, k_shaped_transposed, k_simply_shaped});+ auto v_to_sdpa = std::make_shared<Or>(OutputVector{v_concat, v_shaped, v_shaped_transposed, v_simply_shaped});- auto mask_to_sdpa = std::make_shared<pattern::op::Or>(OutputVector{phi3_mask,- general_alibi_mask,- jais_alibi_mask,- baichuan2_13b_alibi_mask,- gpt_oss_mask,- pattern::any_input()});+ auto mask_to_sdpa = std::make_shared<Or>(OutputVector{phi3_mask,+ general_alibi_mask,+ jais_alibi_mask,+ baichuan2_13b_alibi_mask,+ gpt_oss_mask,+ any_input()});- auto sdpa_with_4_inputs =- pattern::wrap_type<v13::ScaledDotProductAttention>({q, k_to_sdpa, v_to_sdpa, mask_to_sdpa});+ auto sdpa_with_4_inputs = wrap_type<v13::ScaledDotProductAttention>({q, k_to_sdpa, v_to_sdpa, mask_to_sdpa});auto sdpa_with_5_inputs =- pattern::wrap_type<v13::ScaledDotProductAttention>({q, k_to_sdpa, v_to_sdpa, mask_to_sdpa, scale_input});+ wrap_type<v13::ScaledDotProductAttention>({q, k_to_sdpa, v_to_sdpa, mask_to_sdpa, scale_input});auto sdpa_with_6_inputs =- pattern::wrap_type<v13::ScaledDotProductAttention>({q, k_to_sdpa, v_to_sdpa, mask_to_sdpa, scale_input, sinks});+ wrap_type<v13::ScaledDotProductAttention>({q, k_to_sdpa, v_to_sdpa, mask_to_sdpa, scale_input, sinks});- auto sdpa_variants =- std::make_shared<pattern::op::Or>(OutputVector{sdpa_with_4_inputs, sdpa_with_5_inputs, sdpa_with_6_inputs});+ auto sdpa_variants = std::make_shared<Or>(OutputVector{sdpa_with_4_inputs, sdpa_with_5_inputs, sdpa_with_6_inputs});ov::matcher_pass_callback callback = [=,&kv_parameters,@@ -450,7 +438,7 @@ ov::pass::StateManagementPattern::StateManagementPattern(&xattention_threshold_inputs_for_each_layer,&adaptive_rkv_diversity_block_set_indices_inputs_for_each_layer,&adaptive_rkv_diversity_block_set_indices_begins_inputs_for_each_layer,- &adaptive_rkv_diversity_results](ov::pass::pattern::Matcher& m) {+ &adaptive_rkv_diversity_results](Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();const auto& real_q = pattern_map.at(q);@@ -804,6 +792,6 @@ ov::pass::StateManagementPattern::StateManagementPattern(return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(sdpa_variants, matcher_name);+ auto m = std::make_shared<Matcher>(sdpa_variants, matcher_name);register_matcher(m, callback);}diff --git a/src/common/transformations/src/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.cpp b/src/common/transformations/src/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.cppindex aab7b8cb134..f4c7113b3e9 100644--- a/src/common/transformations/src/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.cpp+++ b/src/common/transformations/src/transformations/sdpa_to_paged_attention/total_sequence_length_pattern.cpp@@ -19,9 +19,14 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::op;-using namespace ov::pass::pattern;-+using ov::pass::pattern::any_input;+using ov::pass::pattern::Matcher;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v8 = ov::op::v8;namespace {void align_replacement(std::shared_ptr<ov::Node>& replacement,@@ -39,10 +44,10 @@ void align_replacement(std::shared_ptr<ov::Node>& replacement,} // namespaceov::pass::TotalSequenceLengthPattern::TotalSequenceLengthPattern(- const std::shared_ptr<ov::op::v0::Parameter>& max_context_len) {+ const std::shared_ptr<v0::Parameter>& max_context_len) {MATCHER_SCOPE(TotalSequenceLengthPattern);- auto kv_past = wrap_type<v6::ReadValue>({any_input()});+ auto kv_past = wrap_type<ov::op::v6::ReadValue>({any_input()});auto kv_gather = wrap_type<v8::Gather>({kv_past, any_input(), any_input()});auto kv_current = any_input();auto kv_concat = wrap_type<v0::Concat>({kv_gather, kv_current});@@ -115,21 +120,21 @@ ov::pass::TotalSequenceLengthPattern::TotalSequenceLengthPattern(}ov::pass::TotalSequenceLengthPatternQwen::TotalSequenceLengthPatternQwen(- const std::shared_ptr<ov::op::v0::Parameter>& max_context_len) {+ const std::shared_ptr<v0::Parameter>& max_context_len) {MATCHER_SCOPE(TotalSequenceLengthPatternQwen);auto p_input_ids = wrap_type<v0::Parameter>();auto p_unsqueeze = wrap_type<v0::Unsqueeze>({p_input_ids, any_input()});- auto p_opt_reshape_1 = optional<v1::Reshape>({p_unsqueeze, any_input()});- auto p_opt_convert_1 = optional<v0::Convert>(p_opt_reshape_1);+ auto p_opt_reshape_1 = ov::pass::pattern::optional<v1::Reshape>({p_unsqueeze, any_input()});+ auto p_opt_convert_1 = ov::pass::pattern::optional<v0::Convert>(p_opt_reshape_1);auto p_kv_shape_current = wrap_type<v3::ShapeOf>({p_opt_convert_1});auto p_seq_current = wrap_type<v8::Gather>({p_kv_shape_current, any_input(), any_input()});- auto p_opt_convert_2 = optional<v0::Convert>(p_seq_current);+ auto p_opt_convert_2 = ov::pass::pattern::optional<v0::Convert>(p_seq_current);auto p_max_context_len = wrap_type<v0::Parameter>();auto p_prev_max_seq_len = wrap_type<v1::Subtract>({p_max_context_len, any_input()});- auto p_opt_convert_3 = optional<v0::Convert>(p_prev_max_seq_len);- auto p_opt_reshape_2 = optional<v1::Reshape>({p_opt_convert_3, any_input()});+ auto p_opt_convert_3 = ov::pass::pattern::optional<v0::Convert>(p_prev_max_seq_len);+ auto p_opt_reshape_2 = ov::pass::pattern::optional<v1::Reshape>({p_opt_convert_3, any_input()});auto p_total_seq = wrap_type<v1::Add>({p_opt_convert_2, p_opt_reshape_2});ov::matcher_pass_callback callback = [=](Matcher& m) {@@ -150,7 +155,7 @@ ov::pass::TotalSequenceLengthPatternQwen::TotalSequenceLengthPatternQwen(}ov::pass::TotalSequenceLengthPatternCodeGen2::TotalSequenceLengthPatternCodeGen2(- const std::shared_ptr<ov::op::v0::Parameter>& max_context_len) {+ const std::shared_ptr<v0::Parameter>& max_context_len) {MATCHER_SCOPE(TotalSequenceLengthPatternCodeGen2);auto p_max_context_len = wrap_type<v0::Parameter>();diff --git a/src/common/transformations/src/transformations/smart_reshape/broadcast_const_range_replacement.cpp b/src/common/transformations/src/transformations/smart_reshape/broadcast_const_range_replacement.cppindex 65692ff6704..dfb8212e2fa 100644--- a/src/common/transformations/src/transformations/smart_reshape/broadcast_const_range_replacement.cpp+++ b/src/common/transformations/src/transformations/smart_reshape/broadcast_const_range_replacement.cpp@@ -20,24 +20,30 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/utils/utils.hpp"-ov::pass::BroadcastConstRangeReplacement::BroadcastConstRangeReplacement() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;++namespace ov::pass {++BroadcastConstRangeReplacement::BroadcastConstRangeReplacement() {MATCHER_SCOPE(BroadcastConstRangeReplacement);- auto data_input = pattern::wrap_type<ov::op::v0::Constant>();+ auto data_input = pattern::wrap_type<v0::Constant>();auto target_shape = pattern::any_input();- auto broadcast_pattern_node = pattern::wrap_type<ov::op::v3::Broadcast>({data_input, target_shape});+ auto broadcast_pattern_node = pattern::wrap_type<v3::Broadcast>({data_input, target_shape});matcher_pass_callback callback = [=](pattern::Matcher& m) {const auto broadcast = m.get_match_root();// The transformation was requested only for models with BroadcastType::BIDIRECTIONAL// Further analysis is needed for other broadcast modes enablement- const auto broadcast_ptr = ov::as_type_ptr<ov::op::v3::Broadcast>(broadcast);+ const auto broadcast_ptr = ov::as_type_ptr<v3::Broadcast>(broadcast);if (!broadcast_ptr || broadcast_ptr->get_broadcast_spec().m_type != ov::op::BroadcastType::BIDIRECTIONAL)return false;const auto data_const_out = broadcast->get_input_source_output(0);const auto target_shape_out = broadcast->get_input_source_output(1);- const auto const_node = ov::as_type_ptr<ov::op::v0::Constant>(data_const_out.get_node_shared_ptr());+ const auto const_node = ov::as_type_ptr<v0::Constant>(data_const_out.get_node_shared_ptr());if (!const_node || !const_node->get_element_type().is_integral_number())return false;@@ -69,24 +75,24 @@ ov::pass::BroadcastConstRangeReplacement::BroadcastConstRangeReplacement() {NodeRegistry node_registry;- const auto axis_node = node_registry.add(ov::op::v0::Constant::create(ov::element::i32, {}, {0}));+ const auto axis_node = node_registry.add(v0::Constant::create(ov::element::i32, {}, {0}));const auto target_dim_index_node =- node_registry.add(ov::op::v0::Constant::create(ov::element::i64, {}, {target_dim_neg_index}));+ node_registry.add(v0::Constant::create(ov::element::i64, {}, {target_dim_neg_index}));const auto gather_dim =node_registry.make<ov::op::v8::Gather>(target_shape_out, target_dim_index_node, axis_node);// If the corresponding target dim is 1, use the original end of rangeconst auto one_dim_const =- node_registry.add(ov::op::v0::Constant::create(target_shape_out.get_element_type(), {}, {1}));- const auto dim_check_one = node_registry.make<ov::op::v1::Equal>(gather_dim, one_dim_const);+ node_registry.add(v0::Constant::create(target_shape_out.get_element_type(), {}, {1}));+ const auto dim_check_one = node_registry.make<v1::Equal>(gather_dim, one_dim_const);- const auto start = node_registry.add(ov::op::v0::Constant::create(data_elem_type, {}, {0}));- const auto original_end = node_registry.add(ov::op::v0::Constant::create(data_elem_type, {}, {elem_count}));+ const auto start = node_registry.add(v0::Constant::create(data_elem_type, {}, {0}));+ const auto original_end = node_registry.add(v0::Constant::create(data_elem_type, {}, {elem_count}));- const auto cast_gather_dim = node_registry.make<ov::op::v0::Convert>(gather_dim, data_elem_type);- const auto select_end = node_registry.make<ov::op::v1::Select>(dim_check_one, original_end, cast_gather_dim);+ const auto cast_gather_dim = node_registry.make<v0::Convert>(gather_dim, data_elem_type);+ const auto select_end = node_registry.make<v1::Select>(dim_check_one, original_end, cast_gather_dim);- const auto default_range_step = node_registry.add(ov::op::v0::Constant::create(data_elem_type, {}, {1}));+ const auto default_range_step = node_registry.add(v0::Constant::create(data_elem_type, {}, {1}));std::shared_ptr<Node> replacement =node_registry.make<ov::op::v4::Range>(start, select_end, default_range_step, data_elem_type);@@ -95,9 +101,9 @@ ov::pass::BroadcastConstRangeReplacement::BroadcastConstRangeReplacement() {std::vector<int64_t> final_shape_axes(const_rank);std::iota(final_shape_axes.begin(), final_shape_axes.end(), 0);final_shape_axes.erase(final_shape_axes.begin() + target_dim_index);- const auto axes_to_unsqueeze = node_registry.add(- ov::op::v0::Constant::create(ov::element::i64, {final_shape_axes.size()}, final_shape_axes));- replacement = node_registry.make<ov::op::v0::Unsqueeze>(replacement, axes_to_unsqueeze);+ const auto axes_to_unsqueeze =+ node_registry.add(v0::Constant::create(ov::element::i64, {final_shape_axes.size()}, final_shape_axes));+ replacement = node_registry.make<v0::Unsqueeze>(replacement, axes_to_unsqueeze);}copy_runtime_info(const_node, node_registry.get());@@ -105,6 +111,8 @@ ov::pass::BroadcastConstRangeReplacement::BroadcastConstRangeReplacement() {return false;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(broadcast_pattern_node, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(broadcast_pattern_node, matcher_name);this->register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/smart_reshape/lstm_states_broadcast.cpp b/src/common/transformations/src/transformations/smart_reshape/lstm_states_broadcast.cppindex 49bac82499a..f95893c3a45 100644--- a/src/common/transformations/src/transformations/smart_reshape/lstm_states_broadcast.cpp+++ b/src/common/transformations/src/transformations/smart_reshape/lstm_states_broadcast.cpp@@ -22,10 +22,15 @@using namespace std;+namespace v0 = ov::op::v0;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;namespace {-ov::Input<ov::Node> get_outer_input_of_ti_by_parameter(const shared_ptr<ov::op::v0::Parameter>& parameter,- const shared_ptr<ov::op::v0::TensorIterator>& ti) {+ov::Input<ov::Node> get_outer_input_of_ti_by_parameter(const shared_ptr<v0::Parameter>& parameter,+ const shared_ptr<v0::TensorIterator>& ti) {int64_t parameter_index = ti->get_body()->get_parameter_index(parameter);for (const auto& input_descriptor : ti->get_input_descriptions())if (static_cast<int64_t>(input_descriptor->m_body_parameter_index) == parameter_index)@@ -36,12 +41,11 @@ ov::Input<ov::Node> get_outer_input_of_ti_by_parameter(const shared_ptr<ov::op::parameter);}-shared_ptr<ov::Node> deduce_outer_source_of_batch_for_inner_lstm_cell(- const shared_ptr<ov::op::v0::TensorIterator>& ti,- const shared_ptr<ov::op::v4::LSTMCell>& lstm_cell) {+shared_ptr<ov::Node> deduce_outer_source_of_batch_for_inner_lstm_cell(const shared_ptr<v0::TensorIterator>& ti,+ const shared_ptr<v4::LSTMCell>& lstm_cell) {const auto& body = ti->get_body(); // body is not nullptr -- we checked earlier- map<ov::op::v0::Parameter*, ov::PartialShape> original_shapes;+ map<v0::Parameter*, ov::PartialShape> original_shapes;// mark all input dimensions with symbols and making them dynamic, keeping original shapesfor (auto& parameter : body->get_parameters()) {@@ -69,7 +73,7 @@ shared_ptr<ov::Node> deduce_outer_source_of_batch_for_inner_lstm_cell(}// batch symbol was tracked -- finding parameter that delivered it- shared_ptr<ov::op::v0::Parameter> batch_delivering_parameter;+ shared_ptr<v0::Parameter> batch_delivering_parameter;size_t index_of_batch_dim = 0;auto batch_symbol = lstm_cell->get_input_partial_shape(0)[0].get_symbol();@@ -95,16 +99,16 @@ shared_ptr<ov::Node> deduce_outer_source_of_batch_for_inner_lstm_cell(return nullptr;const auto& batched_source = get_outer_input_of_ti_by_parameter(batch_delivering_parameter, ti);- const auto& batched_shape = make_shared<ov::op::v3::ShapeOf>(batched_source.get_source_output());- const auto& batch = make_shared<ov::op::v8::Gather>(- batched_shape,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {index_of_batch_dim}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0}));+ const auto& batched_shape = make_shared<v3::ShapeOf>(batched_source.get_source_output());+ const auto& batch =+ make_shared<v8::Gather>(batched_shape,+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {index_of_batch_dim}),+ v0::Constant::create(ov::element::i64, ov::Shape{}, {0}));return batch;}bool broadcast_state_by_batch(ov::Input<ov::Node> input, const shared_ptr<ov::Node>& batch_delivering_node) {- auto constant_state = ov::as_type_ptr<ov::op::v0::Constant>(input.get_source_output().get_node_shared_ptr());+ auto constant_state = ov::as_type_ptr<v0::Constant>(input.get_source_output().get_node_shared_ptr());if (constant_state == nullptr)return false;const auto& constant_shape = constant_state->get_shape();@@ -113,43 +117,42 @@ bool broadcast_state_by_batch(ov::Input<ov::Node> input, const shared_ptr<ov::Noreturn false;const auto& constant_copy = constant_state->copy_with_new_inputs({});- const auto& broadcast_by_batch = make_shared<ov::op::v3::Broadcast>(+ const auto& broadcast_by_batch = make_shared<v3::Broadcast>(constant_copy,- make_shared<ov::op::v0::Concat>(- ov::NodeVector{batch_delivering_node,- ov::op::util::make_try_fold<ov::op::v8::Gather>(- ov::op::util::make_try_fold<ov::op::v3::ShapeOf>(constant_copy),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0}))},- 0));+ make_shared<v0::Concat>(ov::NodeVector{batch_delivering_node,+ op_util::make_try_fold<v8::Gather>(+ op_util::make_try_fold<v3::ShapeOf>(constant_copy),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}),+ v0::Constant::create(ov::element::i64, ov::Shape{}, {0}))},+ 0));input.replace_source_output(broadcast_by_batch->output(0));return true;}-bool relax_batch_for_initial_states_of_lstm_in_ti(const shared_ptr<ov::op::v0::TensorIterator>& ti,- const shared_ptr<ov::op::v4::LSTMCell>& lstm_cell) {+bool relax_batch_for_initial_states_of_lstm_in_ti(const shared_ptr<v0::TensorIterator>& ti,+ const shared_ptr<v4::LSTMCell>& lstm_cell) {bool rewritten = false;auto batch_delivering_node = deduce_outer_source_of_batch_for_inner_lstm_cell(ti, lstm_cell);if (batch_delivering_node == nullptr)return rewritten;- if (auto init_hidden_state = ov::as_type_ptr<ov::op::v0::Parameter>(lstm_cell->get_input_node_shared_ptr(1))) {+ if (auto init_hidden_state = ov::as_type_ptr<v0::Parameter>(lstm_cell->get_input_node_shared_ptr(1))) {auto outer_init_hidden_state_input = get_outer_input_of_ti_by_parameter(init_hidden_state, ti);rewritten = broadcast_state_by_batch(outer_init_hidden_state_input, batch_delivering_node) || rewritten;}- if (auto init_cell_state = ov::as_type_ptr<ov::op::v0::Parameter>(lstm_cell->get_input_node_shared_ptr(2))) {+ if (auto init_cell_state = ov::as_type_ptr<v0::Parameter>(lstm_cell->get_input_node_shared_ptr(2))) {auto outer_init_cell_state_input = get_outer_input_of_ti_by_parameter(init_cell_state, ti);rewritten = broadcast_state_by_batch(outer_init_cell_state_input, batch_delivering_node) || rewritten;}return rewritten;}-bool relax_batch_for_initial_states_of_lstm(const shared_ptr<ov::op::v4::LSTMCell>& lstm_cell) {+bool relax_batch_for_initial_states_of_lstm(const shared_ptr<v4::LSTMCell>& lstm_cell) {bool rewritten = false;- const auto& batched_shape = make_shared<ov::op::v3::ShapeOf>(lstm_cell->get_input_source_output(0));+ const auto& batched_shape = make_shared<v3::ShapeOf>(lstm_cell->get_input_source_output(0));const auto& batch_delivering_node =- make_shared<ov::op::v8::Gather>(batched_shape,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0}));+ make_shared<v8::Gather>(batched_shape,+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}),+ v0::Constant::create(ov::element::i64, ov::Shape{}, {0}));rewritten = broadcast_state_by_batch(lstm_cell->input(1), batch_delivering_node) || rewritten;rewritten = broadcast_state_by_batch(lstm_cell->input(2), batch_delivering_node) || rewritten;return rewritten;@@ -162,19 +165,19 @@ bool ov::pass::LSTMStatesBroadcast::run_on_model(const shared_ptr<ov::Model>& f)bool rewritten = false;for (auto& node : f->get_ordered_ops()) {// Recursively apply transformation for sub-graph based operations- rewritten = ov::op::util::process_subgraph(*this, node) || rewritten;+ rewritten = op_util::process_subgraph(*this, node) || rewritten;// Case without TI (LSTMCell and Constant are in the same ov::Model)- if (const auto& lstm_cell = ov::as_type_ptr<ov::op::v4::LSTMCell>(node))+ if (const auto& lstm_cell = ov::as_type_ptr<v4::LSTMCell>(node))rewritten = relax_batch_for_initial_states_of_lstm(lstm_cell) || rewritten;// Case with TI (LSTMCell and Constant are in different ov::Model objects)- if (auto ti = ov::as_type_ptr<ov::op::v0::TensorIterator>(node)) {+ if (auto ti = ov::as_type_ptr<v0::TensorIterator>(node)) {auto body = ti->get_body();if (body == nullptr)continue;for (const auto& body_node : body->get_ordered_ops())- if (const auto& lstm_cell = ov::as_type_ptr<ov::op::v4::LSTMCell>(body_node))+ if (const auto& lstm_cell = ov::as_type_ptr<v4::LSTMCell>(body_node))rewritten = relax_batch_for_initial_states_of_lstm_in_ti(ti, lstm_cell) || rewritten;}}diff --git a/src/common/transformations/src/transformations/smart_reshape/matmul_sr.cpp b/src/common/transformations/src/transformations/smart_reshape/matmul_sr.cppindex b6051b3a4a5..5418eb81e51 100644--- a/src/common/transformations/src/transformations/smart_reshape/matmul_sr.cpp+++ b/src/common/transformations/src/transformations/smart_reshape/matmul_sr.cpp@@ -20,38 +20,43 @@#include "openvino/pass/pattern/matcher.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+namespace {-bool relax_hc_reshape_followed_by_matmul(const ov::pass::pattern::PatternValueMap& pattern_to_output,+bool relax_hc_reshape_followed_by_matmul(const pattern::PatternValueMap& pattern_to_output,const std::shared_ptr<ov::Node>& matmul_label,const std::shared_ptr<ov::Node>& reshape_label,const std::shared_ptr<ov::Node>& other_input_label,const std::shared_ptr<ov::Node>& reshape_pattern_label,bool reshape_is_A_input) {- const auto matmul = ov::as_type_ptr<ov::op::v0::MatMul>(pattern_to_output.at(matmul_label).get_node_shared_ptr());+ const auto matmul = ov::as_type_ptr<v0::MatMul>(pattern_to_output.at(matmul_label).get_node_shared_ptr());if (!matmul)return false;const auto& shape_source = pattern_to_output.at(other_input_label);- if (ov::is_type<ov::op::v1::Transpose>(shape_source.get_node_shared_ptr()) ||- ov::is_type<ov::op::v1::Reshape>(shape_source.get_node_shared_ptr()))+ if (ov::is_type<v1::Transpose>(shape_source.get_node_shared_ptr()) ||+ ov::is_type<v1::Reshape>(shape_source.get_node_shared_ptr()))// avoiding loop creationreturn false;- bool is_1d = ov::pass::pattern::rank_equals(1)(shape_source);+ bool is_1d = pattern::rank_equals(1)(shape_source);int64_t idx = -1;if (!is_1d) {idx = reshape_is_A_input ? (matmul->get_transpose_b() ? -1 : -2) : (matmul->get_transpose_a() ? -2 : -1);}const auto in_C_0 = std::make_shared<ov::op::v3::ShapeOf>(shape_source);- const auto in_C_1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {idx});- const auto in_C_2 = ov::op::v0::Constant::create(ov::element::i64, {}, {0});+ const auto in_C_1 = v0::Constant::create(ov::element::i64, {1}, {idx});+ const auto in_C_2 = v0::Constant::create(ov::element::i64, {}, {0});const auto C = std::make_shared<ov::op::v8::Gather>(in_C_0, in_C_1, in_C_2);- const auto N = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});+ const auto N = v0::Constant::create(ov::element::i64, {1}, {-1});const auto pattern_vector = reshape_is_A_input? (matmul->get_transpose_a() ? ov::OutputVector({C, N}) : ov::OutputVector({N, C})): (matmul->get_transpose_b() ? ov::OutputVector({N, C}) : ov::OutputVector({C, N}));- const auto new_reshape_pattern = std::make_shared<ov::op::v0::Concat>(pattern_vector, 0);+ const auto new_reshape_pattern = std::make_shared<v0::Concat>(pattern_vector, 0);auto reshape_pattern = pattern_to_output.at(reshape_pattern_label).get_node_shared_ptr();ov::NodeVector nodes_to_copy_rt_info{new_reshape_pattern, C, N, in_C_0, in_C_1, in_C_2};@@ -64,17 +69,17 @@ bool relax_hc_reshape_followed_by_matmul(const ov::pass::pattern::PatternValueMa} // namespace-ov::pass::ReshapeAMatMul::ReshapeAMatMul() {+ReshapeAMatMul::ReshapeAMatMul() {MATCHER_SCOPE(ReshapeAMatMul);- auto other_input_label = pattern::any_input(ov::pass::pattern::has_static_rank());+ auto other_input_label = pattern::any_input(pattern::has_static_rank());auto reshape_input_label = pattern::any_input();auto reshape_pattern_label = pattern::any_input();auto reshape_predicate = [](ov::Output<ov::Node> output) -> bool {- return ov::pass::pattern::rank_equals(2)(output) && ov::pass::pattern::consumers_count(1)(output);+ return pattern::rank_equals(2)(output) && pattern::consumers_count(1)(output);};- auto reshape_label = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({reshape_input_label, reshape_pattern_label},- reshape_predicate);- auto matmul_label = ov::pass::pattern::wrap_type<ov::op::v0::MatMul>({reshape_label, other_input_label});+ auto reshape_label =+ pattern::wrap_type<v1::Reshape>({reshape_input_label, reshape_pattern_label}, reshape_predicate);+ auto matmul_label = pattern::wrap_type<v0::MatMul>({reshape_label, other_input_label});matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();@@ -85,21 +90,21 @@ ov::pass::ReshapeAMatMul::ReshapeAMatMul() {reshape_pattern_label,true);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(matmul_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(matmul_label, matcher_name);register_matcher(m, callback);}-ov::pass::ReshapeBMatMul::ReshapeBMatMul() {+ReshapeBMatMul::ReshapeBMatMul() {MATCHER_SCOPE(ReshapeBMatMul);- auto other_input_label = pattern::any_input(ov::pass::pattern::has_static_rank());+ auto other_input_label = pattern::any_input(pattern::has_static_rank());auto reshape_input_label = pattern::any_input();auto reshape_pattern_label = pattern::any_input();auto reshape_predicate = [](ov::Output<ov::Node> output) -> bool {- return ov::pass::pattern::rank_equals(2)(output) && ov::pass::pattern::consumers_count(1)(output);+ return pattern::rank_equals(2)(output) && pattern::consumers_count(1)(output);};- auto reshape_label = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>({reshape_input_label, reshape_pattern_label},- reshape_predicate);- auto matmul_label = ov::pass::pattern::wrap_type<ov::op::v0::MatMul>({other_input_label, reshape_label});+ auto reshape_label =+ pattern::wrap_type<v1::Reshape>({reshape_input_label, reshape_pattern_label}, reshape_predicate);+ auto matmul_label = pattern::wrap_type<v0::MatMul>({other_input_label, reshape_label});matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();@@ -110,25 +115,25 @@ ov::pass::ReshapeBMatMul::ReshapeBMatMul() {reshape_pattern_label,false);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(matmul_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(matmul_label, matcher_name);register_matcher(m, callback);}-ov::pass::TransposeMatMul::TransposeMatMul() {+TransposeMatMul::TransposeMatMul() {MATCHER_SCOPE(TransposeMatMul);- auto matmul_label = ov::pass::pattern::wrap_type<ov::op::v0::MatMul>();+ auto matmul_label = pattern::wrap_type<v0::MatMul>();matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {const auto& pattern_to_output = m.get_pattern_value_map();- auto matmul = ov::as_type_ptr<ov::op::v0::MatMul>(pattern_to_output.at(matmul_label).get_node_shared_ptr());+ auto matmul = ov::as_type_ptr<v0::MatMul>(pattern_to_output.at(matmul_label).get_node_shared_ptr());if (!matmul)return false;auto transpose_is_fusable = [](const std::shared_ptr<ov::Node>& input) {const auto& input_rank = input->get_output_partial_shape(0).rank();if (input_rank.is_static() && input_rank.get_length() >= 2) {- if (auto transpose = ov::as_type_ptr<ov::op::v1::Transpose>(input)) {- if (auto order = ov::as_type_ptr<ov::op::v0::Constant>(transpose->get_input_node_shared_ptr(1))) {+ if (auto transpose = ov::as_type_ptr<v1::Transpose>(input)) {+ if (auto order = ov::as_type_ptr<v0::Constant>(transpose->get_input_node_shared_ptr(1))) {const auto& order_vector = order->cast_vector<int64_t>();std::vector<int64_t> fusable_order(input_rank.get_length());std::iota(fusable_order.begin(), fusable_order.end(), 0);@@ -159,7 +164,7 @@ ov::pass::TransposeMatMul::TransposeMatMul() {}if (!fused_nodes.empty()) {- auto updated_matmul = std::make_shared<ov::op::v0::MatMul>(input_A, input_B, transpose_A, transpose_B);+ auto updated_matmul = std::make_shared<v0::MatMul>(input_A, input_B, transpose_A, transpose_B);fused_nodes.push_back(matmul);copy_runtime_info(fused_nodes, updated_matmul);updated_matmul->set_friendly_name(matmul->get_friendly_name());@@ -168,6 +173,8 @@ ov::pass::TransposeMatMul::TransposeMatMul() {}return false;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(matmul_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(matmul_label, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/smart_reshape/proposal_scales_stridedslice.cpp b/src/common/transformations/src/transformations/smart_reshape/proposal_scales_stridedslice.cppindex 46db34bf910..60f00264f89 100644--- a/src/common/transformations/src/transformations/smart_reshape/proposal_scales_stridedslice.cpp+++ b/src/common/transformations/src/transformations/smart_reshape/proposal_scales_stridedslice.cpp@@ -16,19 +16,24 @@#include "openvino/pass/pattern/op/optional.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+namespace {-bool crop_scales_for_proposal(const ov::pass::pattern::PatternValueMap& pattern_to_output,+bool crop_scales_for_proposal(const pattern::PatternValueMap& pattern_to_output,const std::shared_ptr<ov::Node>& parameter_label,const std::shared_ptr<ov::Node>& proposal_label) {const auto& parameter = pattern_to_output.at(parameter_label);const auto& proposal = pattern_to_output.at(proposal_label).get_node_shared_ptr();- auto cropped_scales = std::make_shared<ov::op::v1::StridedSlice>(+ auto cropped_scales = std::make_shared<v1::StridedSlice>(proposal->input_value(2),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {parameter.get_partial_shape()[1].get_length()}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {parameter.get_partial_shape()[1].get_length()}),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}),std::vector<int64_t>{0},std::vector<int64_t>{0});@@ -38,51 +43,52 @@ bool crop_scales_for_proposal(const ov::pass::pattern::PatternValueMap& pattern_} // namespace-ov::pass::Proposal1Scales::Proposal1Scales() {+Proposal1Scales::Proposal1Scales() {// TODO: enable conditional compile// MATCHER_SCOPE(Proposal1Scales);- auto parameter_label = ov::pass::pattern::wrap_type<ov::op::v0::Parameter>([](const Output<Node>& output) {+ auto parameter_label = pattern::wrap_type<v0::Parameter>([](const Output<Node>& output) {const auto& shape = output.get_partial_shape();return shape.rank().is_static() && shape.rank().get_length() == 2 && shape[1].is_static() &&(shape[1].get_length() == 3 || shape[1].get_length() == 4);});- auto optional_convert = pattern::optional<ov::op::v0::Convert>(parameter_label);- auto reshape_label = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>(- {optional_convert, ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},- [](const Output<Node>& output) {- return output.get_partial_shape().rank().is_static() && output.get_partial_shape().rank().get_length() == 1;- });- auto proposal_label =- ov::pass::pattern::wrap_type<ov::op::v0::Proposal>({pattern::any_input(), pattern::any_input(), reshape_label});+ auto optional_convert = pattern::optional<v0::Convert>(parameter_label);+ auto reshape_label = pattern::wrap_type<v1::Reshape>({optional_convert, pattern::wrap_type<v0::Constant>()},+ [](const Output<Node>& output) {+ return output.get_partial_shape().rank().is_static() &&+ output.get_partial_shape().rank().get_length() == 1;+ });+ auto proposal_label = pattern::wrap_type<v0::Proposal>({pattern::any_input(), pattern::any_input(), reshape_label});matcher_pass_callback callback = [parameter_label, proposal_label](pattern::Matcher& m) -> bool {return crop_scales_for_proposal(m.get_pattern_value_map(), parameter_label, proposal_label);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(proposal_label /*, matcher_name */);+ auto m = std::make_shared<pattern::Matcher>(proposal_label /*, matcher_name */);register_matcher(m, callback);}-ov::pass::Proposal4Scales::Proposal4Scales() {+Proposal4Scales::Proposal4Scales() {// TODO: enable conditional compile// MATCHER_SCOPE(Proposal4Scales);- auto parameter_label = ov::pass::pattern::wrap_type<ov::op::v0::Parameter>([](const Output<Node>& output) {+ auto parameter_label = pattern::wrap_type<v0::Parameter>([](const Output<Node>& output) {const auto& shape = output.get_partial_shape();return shape.rank().is_static() && shape.rank().get_length() == 2 && shape[1].is_static() &&(shape[1].get_length() == 3 || shape[1].get_length() == 4);});- auto optional_convert = ov::pass::pattern::optional<ov::op::v0::Convert>(parameter_label);- auto reshape_label = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>(- {optional_convert, ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},- [](const Output<Node>& output) {- return output.get_partial_shape().rank().is_static() && output.get_partial_shape().rank().get_length() == 1;- });+ auto optional_convert = pattern::optional<v0::Convert>(parameter_label);+ auto reshape_label = pattern::wrap_type<v1::Reshape>({optional_convert, pattern::wrap_type<v0::Constant>()},+ [](const Output<Node>& output) {+ return output.get_partial_shape().rank().is_static() &&+ output.get_partial_shape().rank().get_length() == 1;+ });auto proposal_label =- ov::pass::pattern::wrap_type<ov::op::v4::Proposal>({pattern::any_input(), pattern::any_input(), reshape_label});+ pattern::wrap_type<ov::op::v4::Proposal>({pattern::any_input(), pattern::any_input(), reshape_label});matcher_pass_callback callback = [parameter_label, proposal_label](pattern::Matcher& m) -> bool {return crop_scales_for_proposal(m.get_pattern_value_map(), parameter_label, proposal_label);};- auto m = std::make_shared<ov::pass::pattern::Matcher>(proposal_label /*, matcher_name */);+ auto m = std::make_shared<pattern::Matcher>(proposal_label /*, matcher_name */);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/smart_reshape/reshape_sinking.cpp b/src/common/transformations/src/transformations/smart_reshape/reshape_sinking.cppindex 447c9ec4cee..c9950169ea9 100644--- a/src/common/transformations/src/transformations/smart_reshape/reshape_sinking.cpp+++ b/src/common/transformations/src/transformations/smart_reshape/reshape_sinking.cpp@@ -15,7 +15,12 @@using namespace std;-ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++ReshapeSinkingMatMul::ReshapeSinkingMatMul() {MATCHER_SCOPE(ReshapeSinkingMatMul);/* Original graph: Transformed graph:*@@ -28,23 +33,20 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() {* Reshape output_pattern=(B=1, S, O) Reshape output_pattern=(0, S, O)* | shape=[1, S, O] | shape=[B, S, O]*/- auto any_input = pattern::any_input(pattern::has_static_rank());- auto reshape_label = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>(- {pattern::any_input(), ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(2));-- auto matmul_label = ov::pass::pattern::wrap_type<ov::op::v0::MatMul>(- {reshape_label, ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(2));- auto add_label = ov::pass::pattern::wrap_type<ov::op::v1::Add>(- {matmul_label, ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},- pattern::rank_equals(2));+ auto input_pattern = pattern::any_input(pattern::has_static_rank());+ auto reshape_label = pattern::wrap_type<v1::Reshape>({pattern::any_input(), pattern::wrap_type<v0::Constant>()},+ pattern::rank_equals(2));++ auto matmul_label =+ pattern::wrap_type<v0::MatMul>({reshape_label, pattern::wrap_type<v0::Constant>()}, pattern::rank_equals(2));+ auto add_label =+ pattern::wrap_type<v1::Add>({matmul_label, pattern::wrap_type<v0::Constant>()}, pattern::rank_equals(2));auto matmul_or_matmul_add_label = make_shared<pattern::op::Or>(OutputVector{add_label, matmul_label});- auto reshape_1_label = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>(- {matmul_or_matmul_add_label, ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},- pattern::has_static_rank());+ auto reshape_1_label =+ pattern::wrap_type<v1::Reshape>({matmul_or_matmul_add_label, pattern::wrap_type<v0::Constant>()},+ pattern::has_static_rank());matcher_pass_callback callback = [=](pattern::Matcher& m) -> bool {auto pattern_to_node = m.get_pattern_map();@@ -52,7 +54,7 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() {// check first Reshape eligibility: has a constant output pattern in a form of [-1, K]auto reshape = pattern_to_node.at(reshape_label);int64_t K = -1;- if (const auto& constant = ov::as_type_ptr<ov::op::v0::Constant>(reshape->get_input_node_shared_ptr(1))) {+ if (const auto& constant = ov::as_type_ptr<v0::Constant>(reshape->get_input_node_shared_ptr(1))) {auto output_pattern_vector = constant->cast_vector<int64_t>();if (output_pattern_vector.size() != 2 || output_pattern_vector[0] != -1)return false;@@ -70,11 +72,11 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() {return false;// check matmul eligibility: has constant second input in a form of [O, K]- auto matmul = ov::as_type_ptr<ov::op::v0::MatMul>(pattern_to_node.at(matmul_label));+ auto matmul = ov::as_type_ptr<v0::MatMul>(pattern_to_node.at(matmul_label));if (!matmul || matmul->get_transpose_a())return false;int64_t O = -1;- if (const auto& constant = ov::as_type_ptr<ov::op::v0::Constant>(matmul->get_input_node_shared_ptr(1))) {+ if (const auto& constant = ov::as_type_ptr<v0::Constant>(matmul->get_input_node_shared_ptr(1))) {const auto& constant_shape = constant->get_shape();if (constant_shape.size() != 2)return false;@@ -90,10 +92,10 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() {// check add eligibility if present: has constant second input that has a form of [1, 1, ..., O] (doesn't// broadcast first input)if (pattern_to_node.count(add_label)) {- auto add = ov::as_type_ptr<ov::op::v1::Add>(pattern_to_node.at(add_label));+ auto add = ov::as_type_ptr<v1::Add>(pattern_to_node.at(add_label));if (!add || add->get_autob() != ov::op::AutoBroadcastType::NUMPY)return false;- const auto& constant = ov::as_type_ptr<ov::op::v0::Constant>(add->get_input_node_shared_ptr(1));+ const auto& constant = ov::as_type_ptr<v0::Constant>(add->get_input_node_shared_ptr(1));if (!constant)return false;const auto& constant_shape = constant->get_shape();@@ -110,7 +112,7 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() {// input_shape of the pattern except for the batch and last dimensionauto reshape_1 = m.get_match_root();- const auto& constant = ov::as_type_ptr<ov::op::v0::Constant>(reshape_1->get_input_node_shared_ptr(1));+ const auto& constant = ov::as_type_ptr<v0::Constant>(reshape_1->get_input_node_shared_ptr(1));if (constant == nullptr)return false;auto output_pattern = constant->cast_vector<int64_t>();@@ -131,8 +133,8 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() {return false;}- auto first_reshape = ov::as_type_ptr<ov::op::v1::Reshape>(reshape);- auto second_reshape = ov::as_type_ptr<ov::op::v1::Reshape>(reshape_1);+ auto first_reshape = ov::as_type_ptr<v1::Reshape>(reshape);+ auto second_reshape = ov::as_type_ptr<v1::Reshape>(reshape_1);if (!first_reshape || !second_reshape)return false;@@ -142,16 +144,17 @@ ov::pass::ReshapeSinkingMatMul::ReshapeSinkingMatMul() {vector<int64_t> output_pattern_vector(input_rank - 1, 0);output_pattern_vector.push_back(K);- auto new_reshape_constant =- ov::op::v0::Constant::create(ov::element::i64, Shape{input_rank}, output_pattern_vector);+ auto new_reshape_constant = v0::Constant::create(ov::element::i64, Shape{input_rank}, output_pattern_vector);reshape->input(1).replace_source_output(new_reshape_constant->output(0));output_pattern[0] = 0;- auto new_reshape_1_constant = ov::op::v0::Constant::create(ov::element::i64, Shape{input_rank}, output_pattern);+ auto new_reshape_1_constant = v0::Constant::create(ov::element::i64, Shape{input_rank}, output_pattern);reshape_1->input(1).replace_source_output(new_reshape_1_constant->output(0));return true;};- auto m = make_shared<ov::pass::pattern::Matcher>(reshape_1_label, matcher_name);+ auto m = make_shared<pattern::Matcher>(reshape_1_label, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/smart_reshape/reshape_to_1D.cpp b/src/common/transformations/src/transformations/smart_reshape/reshape_to_1D.cppindex 9abf532798f..291f3f64b28 100644--- a/src/common/transformations/src/transformations/smart_reshape/reshape_to_1D.cpp+++ b/src/common/transformations/src/transformations/smart_reshape/reshape_to_1D.cpp@@ -11,19 +11,25 @@#include "openvino/pass/pattern/matcher.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::ReshapeTo1D::ReshapeTo1D() {+namespace v0 = ov::op::v0;++namespace ov::pass {++ReshapeTo1D::ReshapeTo1D() {// TODO: enable conditional compile// MATCHER_SCOPE(ReshapeTo1D);- auto reshape_label = ov::pass::pattern::wrap_type<ov::op::v1::Reshape>(- {pattern::any_input(), ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},+ auto reshape_label = pattern::wrap_type<ov::op::v1::Reshape>(+ {pattern::any_input(), pattern::wrap_type<v0::Constant>()},[](const Output<Node>& output) {return output.get_partial_shape().rank().is_static() && output.get_partial_shape().rank().get_length() == 1;});matcher_pass_callback callback = [](pattern::Matcher& m) -> bool {- m.get_match_root()->input(1).replace_source_output(ov::op::v0::Constant::create(ov::element::i64, {1}, {-1}));+ m.get_match_root()->input(1).replace_source_output(v0::Constant::create(ov::element::i64, {1}, {-1}));return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(reshape_label /*, matcher_name*/);+ auto m = std::make_shared<pattern::Matcher>(reshape_label /*, matcher_name*/);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/smart_reshape/shape_of_const_folding.cpp b/src/common/transformations/src/transformations/smart_reshape/shape_of_const_folding.cppindex 68655684234..da616f389dd 100644--- a/src/common/transformations/src/transformations/smart_reshape/shape_of_const_folding.cpp+++ b/src/common/transformations/src/transformations/smart_reshape/shape_of_const_folding.cpp@@ -12,7 +12,9 @@#include "openvino/op/shape_of.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"-ov::pass::ShapeOfConstFolding::ShapeOfConstFolding() {+namespace ov::pass {++ShapeOfConstFolding::ShapeOfConstFolding() {MATCHER_SCOPE(ShapeOfConstFolding);auto constant_label = pattern::wrap_type<ov::op::v0::Constant>();auto shape_of_label = pattern::wrap_type<op::v0::ShapeOf, ov::op::v3::ShapeOf>({constant_label});@@ -32,3 +34,5 @@ ov::pass::ShapeOfConstFolding::ShapeOfConstFolding() {auto m = std::make_shared<pattern::Matcher>(shape_of_label, matcher_name);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp b/src/common/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cppindex f185dd53cbd..9307bd36d77 100644--- a/src/common/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp+++ b/src/common/transformations/src/transformations/smart_reshape/strided_slice_squeeze.cpp@@ -16,23 +16,27 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations_visibility.hpp"-ov::pass::StridedSliceSqueeze::StridedSliceSqueeze() {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {++StridedSliceSqueeze::StridedSliceSqueeze() {// TODO: enable conditional compile// MATCHER_SCOPE(StridedSliceSqueeze);- auto ss_label = ov::pass::pattern::wrap_type<ov::op::v1::StridedSlice>(pattern::consumers_count(1));- auto squeeze_label = ov::pass::pattern::wrap_type<ov::op::v0::Squeeze>(- {ss_label, ov::pass::pattern::wrap_type<ov::op::v0::Constant>()});+ auto ss_label = pattern::wrap_type<v1::StridedSlice>(pattern::consumers_count(1));+ auto squeeze_label = pattern::wrap_type<v0::Squeeze>({ss_label, pattern::wrap_type<v0::Constant>()});matcher_pass_callback callback = [](pattern::Matcher& m) -> bool {const auto& squeeze = m.get_match_root();- const auto& const_axes = ov::as_type_ptr<ov::op::v0::Constant>(squeeze->get_input_node_shared_ptr(1));- auto slice = ov::as_type_ptr<ov::op::v1::StridedSlice>(squeeze->get_input_node_shared_ptr(0));+ const auto& const_axes = ov::as_type_ptr<v0::Constant>(squeeze->get_input_node_shared_ptr(1));+ auto slice = ov::as_type_ptr<v1::StridedSlice>(squeeze->get_input_node_shared_ptr(0));if (!const_axes || !slice)return false;- auto begin = ov::as_type_ptr<ov::op::v0::Constant>(slice->input_value(1).get_node_shared_ptr());- auto end = ov::as_type_ptr<ov::op::v0::Constant>(slice->input_value(2).get_node_shared_ptr());- auto strides = ov::as_type_ptr<ov::op::v0::Constant>(slice->input_value(3).get_node_shared_ptr());+ auto begin = ov::as_type_ptr<v0::Constant>(slice->input_value(1).get_node_shared_ptr());+ auto end = ov::as_type_ptr<v0::Constant>(slice->input_value(2).get_node_shared_ptr());+ auto strides = ov::as_type_ptr<v0::Constant>(slice->input_value(3).get_node_shared_ptr());if (!begin || !end || !strides)return false;@@ -96,43 +100,43 @@ ov::pass::StridedSliceSqueeze::StridedSliceSqueeze() {shrink_axis_mask[axis] = 1;}- auto new_slice = std::make_shared<ov::op::v1::StridedSlice>(- slice->input_value(0),- ov::op::v0::Constant::create(element::i64, {begin_vec.size()}, begin_vec),- ov::op::v0::Constant::create(element::i64, {end_vec.size()}, end_vec),- ov::op::v0::Constant::create(element::i64, {strides_vec.size()}, strides_vec),- begin_mask,- end_mask,- new_axis_mask,- shrink_axis_mask,- ellipsis_mask);+ auto new_slice =+ std::make_shared<v1::StridedSlice>(slice->input_value(0),+ v0::Constant::create(element::i64, {begin_vec.size()}, begin_vec),+ v0::Constant::create(element::i64, {end_vec.size()}, end_vec),+ v0::Constant::create(element::i64, {strides_vec.size()}, strides_vec),+ begin_mask,+ end_mask,+ new_axis_mask,+ shrink_axis_mask,+ ellipsis_mask);return replace_output_update_name(squeeze->output(0), new_slice->output(squeeze->input_value(0).get_index()));};- auto m = std::make_shared<ov::pass::pattern::Matcher>(squeeze_label /*, matcher_name */);+ auto m = std::make_shared<pattern::Matcher>(squeeze_label /*, matcher_name */);register_matcher(m, callback);}-ov::pass::SqueezeStridedSlice::SqueezeStridedSlice() {++SqueezeStridedSlice::SqueezeStridedSlice() {// TODO: enable conditional compile// MATCHER_SCOPE(SqueezeStridedSlice);- auto squeeze_label = ov::pass::pattern::wrap_type<ov::op::v0::Squeeze>(- {pattern::any_input(), ov::pass::pattern::wrap_type<ov::op::v0::Constant>()},- pattern::consumers_count(1));- auto ss_label = ov::pass::pattern::wrap_type<ov::op::v1::StridedSlice>(+ auto squeeze_label = pattern::wrap_type<v0::Squeeze>({pattern::any_input(), pattern::wrap_type<v0::Constant>()},+ pattern::consumers_count(1));+ auto ss_label = pattern::wrap_type<v1::StridedSlice>({squeeze_label, pattern::any_input(), pattern::any_input(), pattern::any_input()});matcher_pass_callback callback = [](pattern::Matcher& m) -> bool {- auto slice = ov::as_type_ptr<ov::op::v1::StridedSlice>(m.get_match_root());+ auto slice = ov::as_type_ptr<v1::StridedSlice>(m.get_match_root());if (!slice)return false;auto squeeze = slice->get_input_node_shared_ptr(0);- const auto& const_axes = ov::as_type_ptr<ov::op::v0::Constant>(squeeze->get_input_node_shared_ptr(1));+ const auto& const_axes = ov::as_type_ptr<v0::Constant>(squeeze->get_input_node_shared_ptr(1));if (!const_axes)return false;- auto begin = ov::as_type_ptr<ov::op::v0::Constant>(slice->input_value(1).get_node_shared_ptr());- auto end = ov::as_type_ptr<ov::op::v0::Constant>(slice->input_value(2).get_node_shared_ptr());- auto strides = ov::as_type_ptr<ov::op::v0::Constant>(slice->input_value(3).get_node_shared_ptr());+ auto begin = ov::as_type_ptr<v0::Constant>(slice->input_value(1).get_node_shared_ptr());+ auto end = ov::as_type_ptr<v0::Constant>(slice->input_value(2).get_node_shared_ptr());+ auto strides = ov::as_type_ptr<v0::Constant>(slice->input_value(3).get_node_shared_ptr());if (!begin || !end || !strides)return false;@@ -175,22 +179,24 @@ ov::pass::SqueezeStridedSlice::SqueezeStridedSlice() {ellipsis_mask.insert(ellipsis_mask.begin() + axis, 0);}- auto new_slice = std::make_shared<ov::op::v1::StridedSlice>(- slice->get_input_node_shared_ptr(0)->input_value(0),- ov::op::v0::Constant::create(element::i64, {begin_vec.size()}, begin_vec),- ov::op::v0::Constant::create(element::i64, {end_vec.size()}, end_vec),- ov::op::v0::Constant::create(element::i64, {strides_vec.size()}, strides_vec),- begin_mask,- end_mask,- new_axis_mask,- shrink_axis_mask,- ellipsis_mask);+ auto new_slice =+ std::make_shared<v1::StridedSlice>(slice->get_input_node_shared_ptr(0)->input_value(0),+ v0::Constant::create(element::i64, {begin_vec.size()}, begin_vec),+ v0::Constant::create(element::i64, {end_vec.size()}, end_vec),+ v0::Constant::create(element::i64, {strides_vec.size()}, strides_vec),+ begin_mask,+ end_mask,+ new_axis_mask,+ shrink_axis_mask,+ ellipsis_mask);replace_node(slice, new_slice);new_slice->set_friendly_name(slice->get_friendly_name());copy_runtime_info(slice, new_slice);return true;};- auto m = std::make_shared<ov::pass::pattern::Matcher>(ss_label /*, matcher_name */);+ auto m = std::make_shared<pattern::Matcher>(ss_label /*, matcher_name */);register_matcher(m, callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/symbolic_transformations/chained_maximum.cpp b/src/common/transformations/src/transformations/symbolic_transformations/chained_maximum.cppindex ca2c74f84cf..063d2adc032 100644--- a/src/common/transformations/src/transformations/symbolic_transformations/chained_maximum.cpp+++ b/src/common/transformations/src/transformations/symbolic_transformations/chained_maximum.cpp@@ -13,7 +13,9 @@using namespace ov::symbol::util;-ov::pass::ChainedMaximumOptimization::ChainedMaximumOptimization() {+namespace ov::pass {++ChainedMaximumOptimization::ChainedMaximumOptimization() {MATCHER_SCOPE(ChainedMaximumOptimization);auto A_input = pattern::any_input();auto B_input = pattern::any_input();@@ -48,3 +50,5 @@ ov::pass::ChainedMaximumOptimization::ChainedMaximumOptimization() {auto m = std::make_shared<pattern::Matcher>(maximum, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/symbolic_transformations/dereshape_matmul.cpp b/src/common/transformations/src/transformations/symbolic_transformations/dereshape_matmul.cppindex 1ba4966a573..b636b3a74e6 100644--- a/src/common/transformations/src/transformations/symbolic_transformations/dereshape_matmul.cpp+++ b/src/common/transformations/src/transformations/symbolic_transformations/dereshape_matmul.cpp@@ -23,12 +23,18 @@using namespace ov::symbol::util;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;++namespace ov::pass {+namespace {bool concat_predicate(ov::Output<ov::Node> output) {auto output_pshape = output.get_partial_shape();if (output_pshape.rank().is_dynamic() || output_pshape.size() <= 2)return false;- const auto& concat = ov::as_type_ptr<ov::op::v0::Concat>(output.get_node_shared_ptr());+ const auto& concat = ov::as_type_ptr<v0::Concat>(output.get_node_shared_ptr());if (!concat)return false;@@ -76,7 +82,7 @@ void get_dims(const ov::Output<ov::Node>& source,ov::NodeVector& dims) {std::vector<size_t> non_constant_ids;for (size_t i = from; i < to; ++i) {- auto node = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(source, {i}, copy_rt_info_from);+ auto node = op_util::node_to_get_shape_value_of_indices_from_shape_source(source, {i}, copy_rt_info_from);if (auto constant = ov::util::get_constant_from_source(node)) {node = constant;} else {@@ -100,20 +106,20 @@ ov::Output<ov::Node> get_target_shape_from_sources(const ov::Output<ov::Node>& bsize_t num_non_const_nodes = 0; // candidates for becoming a Constant -1 -- special value for Reshape patternfor (size_t curr_i = 0; curr_i + 1 < dims.size(); ++curr_i) {auto curr_node = dims[curr_i], next_node = dims[curr_i + 1];- bool curr_is_const = ov::op::util::is_constant(curr_node), next_is_const = ov::op::util::is_constant(next_node);+ bool curr_is_const = op_util::is_constant(curr_node), next_is_const = op_util::is_constant(next_node);if (num_non_const_nodes == 0 && !curr_is_const && next_is_const) {- curr_node = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});+ curr_node = v0::Constant::create(ov::element::i64, {1}, {-1});curr_is_const = true;num_non_const_nodes += 1;}if (num_non_const_nodes == 0 && !next_is_const && curr_is_const) {- next_node = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});+ next_node = v0::Constant::create(ov::element::i64, {1}, {-1});next_is_const = true;num_non_const_nodes += 1;}if (curr_is_const && next_is_const) {dims[curr_i] = nullptr;- dims[curr_i + 1] = ov::op::util::make_try_fold<ov::op::v0::Concat>(ov::NodeVector{curr_node, next_node}, 0);+ dims[curr_i + 1] = op_util::make_try_fold<v0::Concat>(ov::NodeVector{curr_node, next_node}, 0);ov::copy_runtime_info(copy_rt_info_from, dims[curr_i + 1]);}}@@ -123,12 +129,12 @@ ov::Output<ov::Node> get_target_shape_from_sources(const ov::Output<ov::Node>& breturn node == nullptr;}),dims.end());- auto target_shape = ov::op::util::make_try_fold<ov::op::v0::Concat>(dims, 0);+ auto target_shape = op_util::make_try_fold<v0::Concat>(dims, 0);ov::copy_runtime_info(copy_rt_info_from, target_shape);return target_shape->output(0);}-void pull_reshape_through_optional_concat_and_bea(const ov::pass::pattern::PatternValueMap& vm,+void pull_reshape_through_optional_concat_and_bea(const pattern::PatternValueMap& vm,std::shared_ptr<ov::Node> concat_label,std::shared_ptr<ov::Node> bea_label,ov::Output<ov::Node> reshape_output,@@ -137,7 +143,7 @@ void pull_reshape_through_optional_concat_and_bea(const ov::pass::pattern::Patte// Reshape -- [Concat] -- [BEA with scalar] -- > MatMulauto original_reshape = reshape_output.get_node_shared_ptr();if (vm.count(concat_label)) {- auto concat_node = ov::as_type_ptr<ov::op::v0::Concat>(vm.at(concat_label).get_node_shared_ptr());+ auto concat_node = ov::as_type_ptr<v0::Concat>(vm.at(concat_label).get_node_shared_ptr());OPENVINO_ASSERT(concat_node != nullptr,"DeReshapeMatMul transformation matched operation which should be Concat -- but it is not");auto rank = concat_node->get_output_partial_shape(0).rank().get_length();@@ -160,7 +166,7 @@ void pull_reshape_through_optional_concat_and_bea(const ov::pass::pattern::Pattenew_concat_inputs[idx_of_reshape_input] = concat_node->input_value(idx_of_reshape_input);new_concat_inputs[idx_of_non_reshape_input] = input_reshape->output(0);- auto new_concat = std::make_shared<ov::op::v0::Concat>(new_concat_inputs, axis);+ auto new_concat = std::make_shared<v0::Concat>(new_concat_inputs, axis);ov::copy_runtime_info({concat_node, original_reshape}, new_concat);auto target_shape_of_output =@@ -194,7 +200,7 @@ void pull_reshape_through_optional_concat_and_bea(const ov::pass::pattern::Pattereturn out.get_partial_shape().is_static() && ov::shape_size(out.get_shape()) == 1; \});-ov::pass::DeReshapeMatMul::DeReshapeMatMul() {+DeReshapeMatMul::DeReshapeMatMul() {MATCHER_SCOPE(DeReshapeMatMul);// BEGIN: symmetrical patterns for MatMul inputs@@ -284,9 +290,9 @@ ov::pass::DeReshapeMatMul::DeReshapeMatMul() {}// preventing wrong matches- if (vm.count(lhs_concat) && !ov::as_type_ptr<ov::op::v0::Concat>(pm.at(lhs_concat)))+ if (vm.count(lhs_concat) && !ov::as_type_ptr<v0::Concat>(pm.at(lhs_concat)))return false;- if (vm.count(rhs_concat) && !ov::as_type_ptr<ov::op::v0::Concat>(pm.at(rhs_concat)))+ if (vm.count(rhs_concat) && !ov::as_type_ptr<v0::Concat>(pm.at(rhs_concat)))return false;pull_reshape_through_optional_concat_and_bea(vm,@@ -310,24 +316,22 @@ ov::pass::DeReshapeMatMul::DeReshapeMatMul() {size_t matmul_port = (add_node->input_value(0) == vm.at(matmul) ? 0 : 1);size_t non_matmul_port = static_cast<size_t>(!matmul_port);- auto first_batch_dim = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(- add_node->input_value(non_matmul_port),- {0},- {in_reshape_0, in_reshape_1});- auto divisor =- ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(in_reshape_0->input_value(0),- {1},- {in_reshape_0, in_reshape_1});- first_batch_dim = std::make_shared<ov::op::v1::Divide>(first_batch_dim, divisor, true);- auto minus_one = ov::op::v0::Constant::create(element::i64, {1}, {-1});- auto non_batch_dims = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(- add_node->input_value(non_matmul_port),- {1, 2},- {in_reshape_0, in_reshape_1});- auto pattern =- std::make_shared<ov::op::v0::Concat>(OutputVector{first_batch_dim, minus_one, non_batch_dims}, 0);+ auto first_batch_dim =+ op_util::node_to_get_shape_value_of_indices_from_shape_source(add_node->input_value(non_matmul_port),+ {0},+ {in_reshape_0, in_reshape_1});+ auto divisor = op_util::node_to_get_shape_value_of_indices_from_shape_source(in_reshape_0->input_value(0),+ {1},+ {in_reshape_0, in_reshape_1});+ first_batch_dim = std::make_shared<v1::Divide>(first_batch_dim, divisor, true);+ auto minus_one = v0::Constant::create(element::i64, {1}, {-1});+ auto non_batch_dims =+ op_util::node_to_get_shape_value_of_indices_from_shape_source(add_node->input_value(non_matmul_port),+ {1, 2},+ {in_reshape_0, in_reshape_1});+ auto pattern = std::make_shared<v0::Concat>(OutputVector{first_batch_dim, minus_one, non_batch_dims}, 0);auto other_input_reshape =- op::util::make_try_fold<ov::op::v1::Reshape>(add_node->input_value(non_matmul_port), pattern, true);+ op::util::make_try_fold<v1::Reshape>(add_node->input_value(non_matmul_port), pattern, true);add_node->input(non_matmul_port).replace_source_output(other_input_reshape->output(0));ov::copy_runtime_info({in_reshape_0, in_reshape_1},{first_batch_dim, minus_one, other_input_reshape, pattern});@@ -341,20 +345,20 @@ ov::pass::DeReshapeMatMul::DeReshapeMatMul() {register_matcher(m, matcher_pass_callback);}-ov::pass::DeReshapeFullyConnected::DeReshapeFullyConnected() {+DeReshapeFullyConnected::DeReshapeFullyConnected() {MATCHER_SCOPE(DeReshapeFullyConnected);- using namespace ov::op;- using namespace ov::pass::pattern;-- auto input = wrap_type<v1::Reshape>({any_input(shape_matches("BATCHES_1...,Y")), any_input()},- shape_matches("BATCHES_2...,Y"));- auto converted = pattern::optional<v0::Convert>(input, consumers_count(1));- auto mm_label = wrap_type<v0::MatMul>({converted, any_input(rank_equals(2))},- consumers_count(1) && shape_matches("BATCHES_2...,Z"),- {{"transpose_a", false}});- auto output = wrap_type<v1::Reshape>({mm_label, any_input()}, shape_matches("BATCHES_1...,Z"));-- ov::matcher_pass_callback matcher_pass_callback = [=](Matcher& m) {+ auto input = pattern::wrap_type<v1::Reshape>(+ {pattern::any_input(pattern::shape_matches("BATCHES_1...,Y")), pattern::any_input()},+ pattern::shape_matches("BATCHES_2...,Y"));+ auto converted = pattern::optional<v0::Convert>(input, pattern::consumers_count(1));+ auto mm_label =+ pattern::wrap_type<v0::MatMul>({converted, pattern::any_input(pattern::rank_equals(2))},+ pattern::consumers_count(1) && pattern::shape_matches("BATCHES_2...,Z"),+ {{"transpose_a", false}});+ auto output =+ pattern::wrap_type<v1::Reshape>({mm_label, pattern::any_input()}, pattern::shape_matches("BATCHES_1...,Z"));++ ov::matcher_pass_callback matcher_pass_callback = [=](pattern::Matcher& m) {const auto& pm = m.get_pattern_map();const auto& in_reshape = pm.at(input);const auto& matmul = pm.at(mm_label);@@ -371,6 +375,8 @@ ov::pass::DeReshapeFullyConnected::DeReshapeFullyConnected() {return true;};- auto m = std::make_shared<Matcher>(output, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(output, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/symbolic_transformations/nop_broadcast.cpp b/src/common/transformations/src/transformations/symbolic_transformations/nop_broadcast.cppindex f5bb1697a5a..7a26825e650 100644--- a/src/common/transformations/src/transformations/symbolic_transformations/nop_broadcast.cpp+++ b/src/common/transformations/src/transformations/symbolic_transformations/nop_broadcast.cpp@@ -18,12 +18,13 @@using namespace std;using namespace ov;-using namespace ov::op;using namespace ov::symbol::util;+namespace ov::pass {+namespace {shared_ptr<Node> broadcast_label(const OutputVector& inputs) {- return ov::pass::pattern::wrap_type<op::v1::Broadcast, op::v3::Broadcast>(inputs, [](Output<Node> output) {+ return pattern::wrap_type<op::v1::Broadcast, op::v3::Broadcast>(inputs, [](Output<Node> output) {const auto& op = output.get_node_shared_ptr();auto data_rank = op->get_input_partial_shape(0).rank();auto new_shape_shape = op->get_input_partial_shape(1);@@ -32,7 +33,7 @@ shared_ptr<Node> broadcast_label(const OutputVector& inputs) {}} // namespace-ov::pass::NopBroadcast::NopBroadcast() {+NopBroadcast::NopBroadcast() {MATCHER_SCOPE(NopBroadcast);auto data_label = pattern::any_input(pattern::has_static_rank());@@ -59,3 +60,5 @@ ov::pass::NopBroadcast::NopBroadcast() {auto m = std::make_shared<pattern::Matcher>(broadcast, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/symbolic_transformations/reshape_optimizations.cpp b/src/common/transformations/src/transformations/symbolic_transformations/reshape_optimizations.cppindex 236fbeaa041..b4f30305675 100644--- a/src/common/transformations/src/transformations/symbolic_transformations/reshape_optimizations.cpp+++ b/src/common/transformations/src/transformations/symbolic_transformations/reshape_optimizations.cpp@@ -13,17 +13,20 @@using namespace std;using namespace ov;-using namespace ov::op;using namespace ov::symbol::util;-ov::pass::ReshapeOptimizations::ReshapeOptimizations() {+namespace v0 = ov::op::v0;++namespace ov::pass {++ReshapeOptimizations::ReshapeOptimizations() {MATCHER_SCOPE(ReshapeOptimizations);auto data_label = pattern::any_input(pattern::has_static_rank());auto pattern_label = pattern::any_input(pattern::has_static_shape() && pattern::class_other_than<v0::Constant>());auto reshape_label = pattern::wrap_type<op::v1::Reshape>({data_label, pattern_label}, pattern::has_static_rank());ov::matcher_pass_callback matcher_pass_callback = [](pattern::Matcher& m) {- const auto& reshape = ov::as_type_ptr<v1::Reshape>(m.get_match_root());+ const auto& reshape = ov::as_type_ptr<ov::op::v1::Reshape>(m.get_match_root());if (!reshape)return false;const auto& in_shape = reshape->get_input_partial_shape(0);@@ -48,7 +51,7 @@ ov::pass::ReshapeOptimizations::ReshapeOptimizations() {int64_t cnt_neg_ones = std::count(output_pattern.begin(), output_pattern.end(), -1);if (cnt_neg_ones == 0 || (cnt_neg_ones == 1 && cnt_static_zeros == 0)) {- auto new_pattern = ov::op::v0::Constant::create(element::i64, Shape{output_pattern.size()}, output_pattern);+ auto new_pattern = 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));@@ -60,3 +63,5 @@ ov::pass::ReshapeOptimizations::ReshapeOptimizations() {auto m = std::make_shared<pattern::Matcher>(reshape_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/symbolic_transformations/symbol_optimization.cpp b/src/common/transformations/src/transformations/symbolic_transformations/symbol_optimization.cppindex cb79d458483..69bbaecba02 100644--- a/src/common/transformations/src/transformations/symbolic_transformations/symbol_optimization.cpp+++ b/src/common/transformations/src/transformations/symbolic_transformations/symbol_optimization.cpp@@ -22,6 +22,10 @@#include "openvino/op/util/op_types.hpp"#include "transformations/utils/utils.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace op_util = ov::op::util;namespace {void update_symbol(std::shared_ptr<ov::Symbol>& symbol) {if (symbol != nullptr)@@ -31,7 +35,7 @@ void update_symbol(std::shared_ptr<ov::Symbol>& symbol) {void apply_table_of_equivalence_on_model(const std::shared_ptr<ov::Model>& m) {for (const auto& op : m->get_ordered_ops()) {// handle inner sub-graphs- if (auto multi_subgraph_op = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(op))+ if (auto multi_subgraph_op = ov::as_type_ptr<op_util::MultiSubGraphOp>(op))for (const auto& sub_graph : multi_subgraph_op->get_functions())if (sub_graph)apply_table_of_equivalence_on_model(sub_graph);@@ -95,17 +99,17 @@ ov::Output<ov::Node> alternative_source_from_existing_value(const std::shared_ptconst auto &original_et = original_output.get_element_type(),&alternative_et = alternative_source.get_element_type();if (alternative_shape != original_shape && (original_shape.empty() || original_shape == ov::Shape{0})) {- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(alternative_source);+ auto squeeze = std::make_shared<v0::Squeeze>(alternative_source);ov::copy_runtime_info(original_output.get_node_shared_ptr(), squeeze);alternative_source = squeeze->output(0);} else if (alternative_shape != original_shape) {- auto shape = ov::op::v0::Constant::create(ov::element::i64, {original_shape.size()}, original_shape);- auto reshape = std::make_shared<ov::op::v1::Reshape>(alternative_source, shape, false);+ auto shape = v0::Constant::create(ov::element::i64, {original_shape.size()}, original_shape);+ auto reshape = std::make_shared<v1::Reshape>(alternative_source, shape, false);ov::copy_runtime_info(original_output.get_node_shared_ptr(), reshape);alternative_source = reshape->output(0);}if (alternative_et != original_et) {- auto convert = std::make_shared<ov::op::v0::Convert>(alternative_source, original_et);+ auto convert = std::make_shared<v0::Convert>(alternative_source, original_et);ov::copy_runtime_info(original_output.get_node_shared_ptr(), convert);alternative_source = convert->output(0);}@@ -127,14 +131,14 @@ ov::Output<ov::Node> alternative_source_from_shape_source(const STS_map& symbol_const auto& original_et = original_output.get_element_type();std::shared_ptr<ov::Node> shape;if (original_et == ov::element::i32 || original_et == ov::element::i64) {- shape = std::make_shared<ov::op::v3::ShapeOf>(source, original_et);+ shape = std::make_shared<v3::ShapeOf>(source, original_et);} else {- shape = std::make_shared<ov::op::v3::ShapeOf>(source);+ shape = std::make_shared<v3::ShapeOf>(source);ov::copy_runtime_info(original_output.get_node_shared_ptr(), shape);- shape = std::make_shared<ov::op::v0::Convert>(shape, original_et);+ shape = std::make_shared<v0::Convert>(shape, original_et);}- auto indices = ov::op::v0::Constant::create(ov::element::i64, original_output.get_shape(), {idx});- auto axis = ov::op::v0::Constant::create(ov::element::i64, {}, {0});+ auto indices = v0::Constant::create(ov::element::i64, original_output.get_shape(), {idx});+ auto axis = v0::Constant::create(ov::element::i64, {}, {0});auto gather = std::make_shared<ov::op::v8::Gather>(shape, indices, axis);ov::copy_runtime_info(original_output.get_node_shared_ptr(), {shape, indices, axis, gather});alternative_source = gather;@@ -164,7 +168,7 @@ ov::Output<ov::Node> alternative_source_from_concat_input_sources(const STS_map&auto alternative_source = ov::Output<ov::Node>();if (symbol_shape_source.count(symbol)) {const auto& source = symbol_shape_source.at(symbol);- auto concat = ov::as_type_ptr<ov::op::v0::Concat>(source.get_node_shared_ptr());+ auto concat = ov::as_type_ptr<v0::Concat>(source.get_node_shared_ptr());if (!concat || concat->get_input_size() != 2)return alternative_source;int64_t idx = get_idx_of_symbol_in_source(source, symbol);@@ -190,7 +194,7 @@ ov::Output<ov::Node> alternative_source_from_concat_input_sources(const STS_map&symbol_value_source);if (lhs_alternative.get_node_shared_ptr() && rhs_alternative.get_node_shared_ptr()) {- alternative_source = std::make_shared<ov::op::v1::Add>(lhs_alternative, rhs_alternative);+ alternative_source = std::make_shared<v1::Add>(lhs_alternative, rhs_alternative);ov::copy_runtime_info(original_output.get_node_shared_ptr(), alternative_source.get_node_shared_ptr());alternative_source.get_tensor().set_value_symbol({symbol});symbol_value_source[symbol] = alternative_source;@@ -233,11 +237,10 @@ std::vector<std::shared_ptr<ov::Node>> topological_order(const std::shared_ptr<oconst std::string op_depends_on_parameter = "topological_sort_op_depends_on";// values: true - parameter dependent; false otherwisefor (const auto& op : order) {- if (ov::as_type_ptr<ov::op::v0::Parameter>(op)) {+ if (ov::as_type_ptr<v0::Parameter>(op)) {op->get_rt_info()[op_depends_on_parameter] = true;- } else if (ov::as_type_ptr<ov::op::v0::Constant>(op) || ov::as_type_ptr<ov::op::v0::ShapeOf>(op) ||- ov::as_type_ptr<ov::op::v3::ShapeOf>(op) ||- std::dynamic_pointer_cast<ov::op::util::VariableExtension>(op)) {+ } else if (ov::as_type_ptr<v0::Constant>(op) || ov::as_type_ptr<v0::ShapeOf>(op) ||+ ov::as_type_ptr<v3::ShapeOf>(op) || std::dynamic_pointer_cast<op_util::VariableExtension>(op)) {op->get_rt_info()[op_depends_on_parameter] = false;} else { // deduce op type from inputsconst auto& inputs = op->input_values();@@ -257,7 +260,7 @@ std::vector<std::shared_ptr<ov::Node>> topological_order(const std::shared_ptr<ofor (auto it = order.rbegin(); it != order.rend(); ++it) {const auto& op = *it;int64_t weight = 0;- if (ov::as_type_ptr<ov::op::v0::Result>(op)) {+ if (ov::as_type_ptr<v0::Result>(op)) {op->get_rt_info()[weight_rt_info_name] = weight;} else {bool output_has_weight = false;@@ -318,7 +321,7 @@ std::vector<std::shared_ptr<ov::Node>> topological_order(const std::shared_ptr<o}void save_shape_sources(const std::shared_ptr<ov::Node>& op, STS_map& symbol_shape_source) {- if (ov::is_type<ov::op::v0::ShapeOf>(op) || ov::is_type<ov::op::v3::ShapeOf>(op)) {+ if (ov::is_type<v0::ShapeOf>(op) || ov::is_type<v3::ShapeOf>(op)) {const auto& output = op->input_value(0);if (output.get_partial_shape().rank().is_dynamic())return;@@ -332,7 +335,7 @@ void save_shape_sources(const std::shared_ptr<ov::Node>& op, STS_map& symbol_shacontinue;symbol_shape_source[symbol] = output;}- } else if (const auto concat = ov::as_type_ptr<ov::op::v0::Concat>(op)) {+ } else if (const auto concat = ov::as_type_ptr<v0::Concat>(op)) {// we agreed to detach ShapeOf sourcing output axis dimension from Concat operations for smoother matching// this code allows to find places to reconnect ShapeOfsconst auto rank = concat->get_output_partial_shape(0).rank();@@ -414,7 +417,7 @@ void save_and_update_value_sources(const std::shared_ptr<ov::Node>& op,if (multi_symbol_source.count(*result)) {auto alternative_source = multi_symbol_source[*result];if (output.get_element_type() != alternative_source.get_element_type()) {- auto convert = std::make_shared<ov::op::v0::Convert>(alternative_source, output.get_element_type());+ auto convert = std::make_shared<v0::Convert>(alternative_source, output.get_element_type());ov::copy_runtime_info(output.get_node_shared_ptr(), convert);alternative_source = convert->output(0);}@@ -446,7 +449,7 @@ bool ov::pass::OptimizeSymbolsUsedAsValues::run_on_model(const std::shared_ptr<ocontinue;// LTS maps aren't shared with sub-graphs because inner graph can not access outer graph for label sources- ov::op::util::process_subgraph(*this, op);+ op_util::process_subgraph(*this, op);for (auto& output : op->outputs())optimize_value_usage(output, symbol_shape_source, symbol_value_source);diff --git a/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp b/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cppindex f75cd346699..63b69ed9893 100644--- a/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp+++ b/src/common/transformations/src/transformations/symbolic_transformations/symbolic_optimizations.cpp@@ -33,6 +33,8 @@using namespace ov::pass;using namespace ov::symbol::util;+namespace ov::pass {+namespace {void symbolic_set_up_for_shape(ov::PartialShape& shape) {if (shape.rank().is_dynamic())@@ -92,7 +94,7 @@ void special_case_range_symbol_propagation(const std::shared_ptr<ov::Node>& node}} // namespace-bool ov::pass::SymbolicPropagation::run_on_model(const std::shared_ptr<ov::Model>& m) {+bool SymbolicPropagation::run_on_model(const std::shared_ptr<ov::Model>& m) {RUN_ON_MODEL_SCOPE(SymbolicPropagation);for (const auto& op : m->get_ordered_ops()) {@@ -117,14 +119,14 @@ bool ov::pass::SymbolicPropagation::run_on_model(const std::shared_ptr<ov::Modelreturn true;}-ov::pass::LabelResolvingThroughSelect::LabelResolvingThroughSelect() {+LabelResolvingThroughSelect::LabelResolvingThroughSelect() {MATCHER_SCOPE(LabelResolvingThroughSelect);auto add = pattern::wrap_type<op::util::BinaryElementwiseArithmetic>();auto input_reshape = pattern::wrap_type<op::v1::Reshape>({add, pattern::any_input()});auto select_then = pattern::wrap_type<op::v1::Select>({pattern::any_input(), input_reshape, pattern::any_input()});auto select_else = pattern::wrap_type<op::v1::Select>({pattern::any_input(), pattern::any_input(), input_reshape});- auto select = std::make_shared<pass::pattern::op::Or>(OutputVector{select_then, select_else});+ auto select = std::make_shared<pattern::op::Or>(OutputVector{select_then, select_else});auto softmax = pattern::wrap_type<op::v1::Softmax>({select});auto reshape = pattern::wrap_type<op::v1::Reshape>({softmax, pattern::any_input()});@@ -171,8 +173,7 @@ ov::pass::LabelResolvingThroughSelect::LabelResolvingThroughSelect() {register_matcher(m, matcher_pass_callback);}-ov::pass::SymbolicOptimizations::SymbolicOptimizations(bool full_run,- std::shared_ptr<ov::pass::PassConfig> pass_config) {+SymbolicOptimizations::SymbolicOptimizations(bool full_run, std::shared_ptr<PassConfig> pass_config) {if (pass_config)m_manager = std::make_shared<pass::Manager>(*pass_config, "Symbolic");else@@ -203,7 +204,7 @@ ov::pass::SymbolicOptimizations::SymbolicOptimizations(bool full_run,}}-bool ov::pass::SymbolicOptimizations::run_on_model(const std::shared_ptr<ov::Model>& m) {+bool SymbolicOptimizations::run_on_model(const std::shared_ptr<ov::Model>& m) {RUN_ON_FUNCTION_SCOPE(SymbolicOptimizations);// Eliminate Squeeze/Unsqueeze might convert Squeeze/Unsqueeze ops to Reshape@@ -219,3 +220,5 @@ bool ov::pass::SymbolicOptimizations::run_on_model(const std::shared_ptr<ov::Modov::remove_skip_invalidation_rti(m);return true;}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_base.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_base.cppindex 375f861db14..d4d293e78b2 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_base.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_base.cpp@@ -15,11 +15,11 @@#include "transformations/rt_info/transpose_sinking_attr.hpp"#include "transformations/transpose_sinking/ts_utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace ov::pass {+void TSForwardBase::transpose_sinking(const std::string& pass_name,const TSForwardBase::sinking_function& sinking_transformation) {ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {@@ -77,3 +77,5 @@ bool TSForwardBase::if_node_has_transpose_inputs(utils::GetFirstTransposeInput(output.get_node_shared_ptr(), transpose_indices, if_transpose_sinkable);return !inputs_info.isEmpty();}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_binary.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_binary.cppindex fee387029b7..64a06d15b1e 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_binary.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_binary.cpp@@ -19,18 +19,20 @@#include "transformations/rt_info/transpose_sinking_attr.hpp"#include "transformations/transpose_sinking/ts_utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;++namespace ov::pass {+TSBinaryForward::TSBinaryForward() : TSForwardBase() {MATCHER_SCOPE(TSBinaryForward);create_pattern<op::util::BinaryElementwiseArithmetic,op::util::BinaryElementwiseComparison,op::util::BinaryElementwiseLogical,- ov::op::v0::PRelu,- ov::op::v0::FakeQuantize>();+ v0::PRelu,+ v0::FakeQuantize>();transpose_sinking(matcher_name);}@@ -47,8 +49,8 @@ NodePtr InsertBroadcastUnsqueezePReluSlope(const Output<Node>& node, size_t n_didims[0] = 0;std::iota(dims.begin() + 1, dims.end(), 2);- auto unsqueeze_const = std::make_shared<ov::op::v0::Constant>(ov::element::i64, Shape{dims.size()}, dims);- auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(node, unsqueeze_const);+ auto unsqueeze_const = std::make_shared<v0::Constant>(ov::element::i64, Shape{dims.size()}, dims);+ auto unsqueeze = std::make_shared<v0::Unsqueeze>(node, unsqueeze_const);copy_runtime_info(node.get_node_shared_ptr(), {unsqueeze, unsqueeze_const});return unsqueeze;}@@ -59,7 +61,7 @@ NodePtr InsertBroadcastUnsqueezePReluSlope(const Output<Node>& node, size_t n_di* In such a case we need to insert Unsqueeze before Transpose with another axes.*/bool IsSpecialPRelu(NodePtr node) {- auto prelu = as_type_ptr<ov::op::v0::PRelu>(node);+ auto prelu = as_type_ptr<v0::PRelu>(node);if (!prelu)return false;@@ -86,25 +88,25 @@ bool IsSpecialPRelu(NodePtr node) {TSBinaryBackward::TSBinaryBackward() {MATCHER_SCOPE(TSBinaryBackward);- auto main_node_label = wrap_type<op::util::BinaryElementwiseArithmetic,- op::util::BinaryElementwiseComparison,- op::util::BinaryElementwiseLogical,- ov::op::v0::PRelu,- ov::op::v0::FakeQuantize>([](const Output<Node>& output) -> bool {- return has_static_rank()(output) && CheckTransposeConsumers(output);+ auto main_node_label = pattern::wrap_type<op::util::BinaryElementwiseArithmetic,+ op::util::BinaryElementwiseComparison,+ op::util::BinaryElementwiseLogical,+ v0::PRelu,+ v0::FakeQuantize>([](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output) && CheckTransposeConsumers(output);});- auto transpose_const_label = wrap_type<ov::op::v0::Constant>();+ auto transpose_const_label = pattern::wrap_type<v0::Constant>();- auto transpose_label = wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });+ auto transpose_label = pattern::wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });- matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose_const =- as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());+ as_type_ptr<v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr();if (transformation_callback(main_node)) {@@ -124,6 +126,8 @@ TSBinaryBackward::TSBinaryBackward() {return true;};- auto m = std::make_shared<Matcher>(transpose_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_concat.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_concat.cppindex 029e113d3e8..3395682400b 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_concat.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_concat.cpp@@ -14,20 +14,22 @@#include "transformations/rt_info/transpose_sinking_attr.hpp"#include "transformations/transpose_sinking/ts_utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;++namespace ov::pass {+TSConcatForward::TSConcatForward() {MATCHER_SCOPE(TSConcatForward);- create_pattern<ov::op::v0::Concat>();+ create_pattern<v0::Concat>();auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {// todo: support dynamic rank case- auto concat_node = as_type_ptr<ov::op::v0::Concat>(main_node);+ auto concat_node = as_type_ptr<v0::Concat>(main_node);if (!concat_node) {return false;}@@ -64,28 +66,28 @@ TSConcatForward::TSConcatForward() {TSConcatBackward::TSConcatBackward() {MATCHER_SCOPE(TSConcatBackward);- auto main_node_label = wrap_type<ov::op::v0::Concat>([](const Output<Node>& output) -> bool {- return has_static_rank()(output) && CheckTransposeConsumers(output);+ auto main_node_label = pattern::wrap_type<v0::Concat>([](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output) && CheckTransposeConsumers(output);});- auto transpose_const_label = wrap_type<ov::op::v0::Constant>();+ auto transpose_const_label = pattern::wrap_type<v0::Constant>();- auto transpose_label = wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });+ auto transpose_label = pattern::wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });- matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose_const =- as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());+ as_type_ptr<v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr();if (transformation_callback(main_node)) {return false;}- auto concat_node = as_type_ptr<ov::op::v0::Concat>(main_node);+ auto concat_node = as_type_ptr<v0::Concat>(main_node);if (!concat_node) {return false;}@@ -118,6 +120,8 @@ TSConcatBackward::TSConcatBackward() {return true;};- auto m = std::make_shared<Matcher>(transpose_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_cumsum.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_cumsum.cppindex 41282ec0a53..e47baef55c5 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_cumsum.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_cumsum.cpp@@ -14,18 +14,20 @@#include "transformations/rt_info/transpose_sinking_attr.hpp"#include "transformations/transpose_sinking/ts_utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+#undef CUMSUM_AXIS_INPUT_IDX#define CUMSUM_AXIS_INPUT_IDX 1+namespace ov::pass {+TSCumSumForward::TSCumSumForward() {MATCHER_SCOPE(TSCumSumForward);- create_pattern<ov::op::v0::CumSum>({0});+ create_pattern<v0::CumSum>({0});auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {@@ -38,7 +40,7 @@ TSCumSumForward::TSCumSumForward() {return res;const auto transpose_axis_order = transpose_info.transpose_const->get_axis_vector_val();- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);const auto& new_axes = ChangeAxes(main_node->input_value(CUMSUM_AXIS_INPUT_IDX), transpose_axis_order, axis);main_node->input(CUMSUM_AXIS_INPUT_IDX).replace_source_output(new_axes);@@ -50,20 +52,20 @@ TSCumSumForward::TSCumSumForward() {TSCumSumBackward::TSCumSumBackward() {MATCHER_SCOPE(TSCumSumBackward);- auto main_node_label = wrap_type<ov::op::v0::CumSum>([](const Output<Node>& output) -> bool {- return has_static_rank()(output) && CheckTransposeConsumers(output);+ auto main_node_label = pattern::wrap_type<v0::CumSum>([](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output) && CheckTransposeConsumers(output);});- auto transpose_const_label = wrap_type<ov::op::v0::Constant>();+ auto transpose_const_label = pattern::wrap_type<v0::Constant>();- auto transpose_label = wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });- matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto transpose_label = pattern::wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose_const =- as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());+ as_type_ptr<v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr();@@ -80,13 +82,15 @@ TSCumSumBackward::TSCumSumBackward() {RemoveTransposeConsumers(main_node);const auto transpose_axis_order = transpose_const->get_axis_vector_val();const auto reversed_transpose_order = ReverseTransposeOrder(transpose_axis_order);- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);auto new_axes = ChangeAxes(main_node->input_value(CUMSUM_AXIS_INPUT_IDX), reversed_transpose_order, axis);main_node->input(CUMSUM_AXIS_INPUT_IDX).replace_source_output(new_axes);main_node->validate_and_infer_types();return true;};- auto m = std::make_shared<Matcher>(transpose_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_data_movement.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_data_movement.cppindex d4432bdaa85..347bef60395 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_data_movement.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_data_movement.cpp@@ -18,17 +18,20 @@#include "transformations/rt_info/transpose_sinking_attr.hpp"#include "transformations/transpose_sinking/ts_utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+namespace {std::vector<size_t> get_indices_by_op_type(const std::shared_ptr<Node>& main_node) {if (as_type_ptr<ov::op::util::PadBase>(main_node)) {return {1, 2};- } else if (as_type_ptr<ov::op::v1::BatchToSpace>(main_node) || as_type_ptr<ov::op::v1::SpaceToBatch>(main_node)) {+ } else if (as_type_ptr<v1::BatchToSpace>(main_node) || as_type_ptr<v1::SpaceToBatch>(main_node)) {return {1, 2, 3};} else {return {};@@ -39,8 +42,7 @@ std::vector<size_t> get_indices_by_op_type(const std::shared_ptr<Node>& main_nodTSDataMovementForward::TSDataMovementForward() {MATCHER_SCOPE(TSDataMovementForward);- create_pattern<op::util::PadBase, ov::op::v1::BatchToSpace, ov::op::v1::SpaceToBatch, ov::op::v0::ReverseSequence>(- {0});+ create_pattern<op::util::PadBase, v1::BatchToSpace, v1::SpaceToBatch, v0::ReverseSequence>({0});auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {@@ -50,7 +52,7 @@ TSDataMovementForward::TSDataMovementForward() {const auto transpose_axis_order = transpose_info.transpose_const->get_axis_vector_val();const auto reversed_transpose_order = ReverseTransposeOrder(transpose_axis_order);- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);const auto& indices = get_indices_by_op_type(main_node);for (const auto& idx : indices) {@@ -58,7 +60,7 @@ TSDataMovementForward::TSDataMovementForward() {ChangeValuesOrder(main_node->input_value(idx), reversed_transpose_order, axis));}- if (auto reverse_seq = as_type_ptr<ov::op::v0::ReverseSequence>(main_node)) {+ if (auto reverse_seq = as_type_ptr<v0::ReverseSequence>(main_node)) {reverse_seq->set_batch_axis(transpose_axis_order[reverse_seq->get_batch_axis()]);reverse_seq->set_sequence_axis(transpose_axis_order[reverse_seq->get_sequence_axis()]);}@@ -74,22 +76,22 @@ TSDataMovementBackward::TSDataMovementBackward() {MATCHER_SCOPE(TSDataMovementBackward);auto main_node_label =- wrap_type<op::util::PadBase, ov::op::v1::BatchToSpace, ov::op::v1::SpaceToBatch, ov::op::v0::ReverseSequence>(+ pattern::wrap_type<op::util::PadBase, v1::BatchToSpace, v1::SpaceToBatch, v0::ReverseSequence>([](const Output<Node>& output) -> bool {- return has_static_rank()(output) && CheckTransposeConsumers(output);+ return pattern::has_static_rank()(output) && CheckTransposeConsumers(output);});- auto transpose_const_label = wrap_type<ov::op::v0::Constant>();+ auto transpose_const_label = pattern::wrap_type<v0::Constant>();- auto transpose_label = wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });+ auto transpose_label = pattern::wrap_type<v1::Transpose>({main_node_label, transpose_const_label},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });- matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose_const =- as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());+ as_type_ptr<v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr();if (transformation_callback(main_node)) {@@ -105,14 +107,14 @@ TSDataMovementBackward::TSDataMovementBackward() {RemoveTransposeConsumers(main_node);const auto transpose_axis_order = transpose_const->get_axis_vector_val();const auto reversed_transpose_order = ReverseTransposeOrder(transpose_axis_order);- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);const auto& indices = get_indices_by_op_type(main_node);for (const auto& idx : indices) {main_node->input(idx).replace_source_output(ChangeValuesOrder(main_node->input_value(idx), transpose_axis_order, axis));}- if (auto reverse_seq = as_type_ptr<ov::op::v0::ReverseSequence>(main_node)) {+ if (auto reverse_seq = as_type_ptr<v0::ReverseSequence>(main_node)) {reverse_seq->set_batch_axis(reversed_transpose_order[reverse_seq->get_batch_axis()]);reverse_seq->set_sequence_axis(reversed_transpose_order[reverse_seq->get_sequence_axis()]);}@@ -120,6 +122,8 @@ TSDataMovementBackward::TSDataMovementBackward() {return true;};- auto m = std::make_shared<Matcher>(transpose_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_fuse.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_fuse.cppindex f9298a8bb0f..040a8c8c0af 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_fuse.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_fuse.cpp@@ -16,17 +16,20 @@#include "transformations/transpose_sinking/ts_utils.hpp"#include "transformations/utils/utils.hpp"-using namespace ov;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+TSFuse::TSFuse() {MATCHER_SCOPE(TransposeFuse);auto transpose_1_label =- pattern::wrap_type<ov::op::v1::Transpose>({pattern::any_input(), pattern::wrap_type<ov::op::v0::Constant>()},- CheckTransposeConsumers);- auto transpose_2_label =- pattern::wrap_type<ov::op::v1::Transpose>({transpose_1_label, pattern::wrap_type<ov::op::v0::Constant>()});+ pattern::wrap_type<v1::Transpose>({pattern::any_input(), pattern::wrap_type<v0::Constant>()},+ CheckTransposeConsumers);+ auto transpose_2_label = pattern::wrap_type<v1::Transpose>({transpose_1_label, pattern::wrap_type<v0::Constant>()});ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_map();@@ -34,8 +37,8 @@ TSFuse::TSFuse() {auto transpose2 = pattern_to_output.at(transpose_2_label);auto input = transpose1->input_value(0);- auto transpose1_order = ov::as_type_ptr<ov::op::v0::Constant>(transpose1->get_input_node_shared_ptr(1));- auto transpose2_order = ov::as_type_ptr<ov::op::v0::Constant>(transpose2->get_input_node_shared_ptr(1));+ auto transpose1_order = ov::as_type_ptr<v0::Constant>(transpose1->get_input_node_shared_ptr(1));+ auto transpose2_order = ov::as_type_ptr<v0::Constant>(transpose2->get_input_node_shared_ptr(1));if (!transpose1_order || !transpose2_order)return false;@@ -63,8 +66,8 @@ TSFuse::TSFuse() {ov::replace_output_update_name(out_transpose.get_node()->output(0), input);}} else {- auto new_order = ov::op::v0::Constant::create(transpose_order_type, {order2.size()}, order2);- auto new_transpose = register_new_node<ov::op::v1::Transpose>(input, new_order);+ auto new_order = v0::Constant::create(transpose_order_type, {order2.size()}, order2);+ auto new_transpose = register_new_node<v1::Transpose>(input, new_order);new_transpose->set_friendly_name(m.get_match_root()->get_friendly_name());RemoveTransposeConsumers(transpose1);@@ -79,3 +82,5 @@ TSFuse::TSFuse() {auto m = std::make_shared<pattern::Matcher>(transpose_2_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_gather.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_gather.cppindex 39240cb4ab3..e6c86b5b3f4 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_gather.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_gather.cpp@@ -15,25 +15,29 @@#include "transformations/rt_info/transpose_sinking_attr.hpp"#include "transformations/transpose_sinking/ts_utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;++namespace ov::pass {+TSGatherForward::TSGatherForward() {MATCHER_SCOPE(TSGatherForward);- create_pattern<ov::op::v8::Gather>({0});+ create_pattern<v8::Gather>({0});- auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,+ auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<ov::Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {- auto gather = as_type_ptr<ov::op::v8::Gather>(main_node);+ auto gather = ov::as_type_ptr<v8::Gather>(main_node);if (!gather) {return false;}auto transpose_order = transpose_info.transpose_const;- auto gather_axis = as_type_ptr<ov::op::v0::Constant>(main_node->get_input_node_shared_ptr(2));+ auto gather_axis = ov::as_type_ptr<v0::Constant>(main_node->get_input_node_shared_ptr(2));if (!gather_axis) {return false;}@@ -132,18 +136,18 @@ TSGatherForward::TSGatherForward() {++j;}}- auto new_order_const = ov::op::v0::Constant::create(transpose_order->get_element_type(),- {new_transpose_order.size()},- new_transpose_order);+ auto new_order_const = v0::Constant::create(transpose_order->get_element_type(),+ {new_transpose_order.size()},+ new_transpose_order);TransposeInputsInfo transpose_input_info = {transpose_info.transpose, new_order_const, 0};// deletes Transpose from 0 inputauto success = sink_forward::UpdateInputTransposes(main_node, transpose_input_info, {0});if (!success) {return false;}- auto new_axis = ov::op::v0::Constant::create(gather_axis->get_element_type(), gather_axis->get_shape(), {axis});+ auto new_axis = v0::Constant::create(gather_axis->get_element_type(), gather_axis->get_shape(), {axis});main_node->input(2).replace_source_output(new_axis);- copy_runtime_info(gather_axis, new_axis);+ ov::copy_runtime_info(gather_axis, new_axis);default_outputs_update(main_node, transpose_input_info);return true;@@ -155,24 +159,25 @@ TSGatherForward::TSGatherForward() {TSGatherBackward::TSGatherBackward() {MATCHER_SCOPE(TSGatherBackward);- auto gather_label = wrap_type<ov::op::v8::Gather>({any_input(), any_input(), wrap_type<ov::op::v0::Constant>()},- CheckTransposeConsumers);- auto transpose_label = wrap_type<ov::op::v1::Transpose>({gather_label, wrap_type<ov::op::v0::Constant>()},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });+ auto gather_label =+ pattern::wrap_type<v8::Gather>({pattern::any_input(), pattern::any_input(), pattern::wrap_type<v0::Constant>()},+ CheckTransposeConsumers);+ auto transpose_label = pattern::wrap_type<v1::Transpose>({gather_label, pattern::wrap_type<v0::Constant>()},+ [](const ov::Output<ov::Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_map();- auto transpose = as_type_ptr<ov::op::v1::Transpose>(pattern_to_output.at(transpose_label));- auto main_node = as_type_ptr<ov::op::v8::Gather>(pattern_to_output.at(gather_label));+ auto transpose = ov::as_type_ptr<v1::Transpose>(pattern_to_output.at(transpose_label));+ auto main_node = ov::as_type_ptr<v8::Gather>(pattern_to_output.at(gather_label));if (!transpose || !main_node || transformation_callback(main_node)) {return false;}- auto transpose_order = as_type_ptr<ov::op::v0::Constant>(transpose->get_input_node_shared_ptr(1));- auto gather_axis = as_type_ptr<ov::op::v0::Constant>(main_node->get_input_node_shared_ptr(2));+ auto transpose_order = ov::as_type_ptr<v0::Constant>(transpose->get_input_node_shared_ptr(1));+ auto gather_axis = ov::as_type_ptr<v0::Constant>(main_node->get_input_node_shared_ptr(2));if (!transpose_order || !gather_axis) {return false;}@@ -215,7 +220,7 @@ TSGatherBackward::TSGatherBackward() {bool optimization = out_pshape.is_static() && main_node->input_value(1).get_partial_shape().is_static();bool success = false;std::vector<size_t> axes_val;- std::shared_ptr<ov::op::v0::Squeeze> squeeze;+ std::shared_ptr<v0::Squeeze> squeeze;// In some cases shape of 2nd input to Gather op (indices) has `1` dims which can// prevent TransposeSinking in backward direction.// We can get around this case by wrapping Transpose op with Squeeze+Unsqueeze pair.@@ -237,8 +242,8 @@ TSGatherBackward::TSGatherBackward() {Transpose output: shape(1,8,2)*/if (optimization) {- squeeze = std::make_shared<ov::op::v0::Squeeze>(main_node->input_value(1));- copy_runtime_info(main_node, squeeze);+ squeeze = std::make_shared<v0::Squeeze>(main_node->input_value(1));+ ov::copy_runtime_info(main_node, squeeze);main_node->input(1).replace_source_output(squeeze);main_node->validate_and_infer_types();auto new_out_pshape = main_node->get_output_partial_shape(0);@@ -277,7 +282,7 @@ TSGatherBackward::TSGatherBackward() {order_val = GetOrderAfterReduction(axes_val, order_val);}- std::shared_ptr<ov::op::v0::Constant> new_axis;+ std::shared_ptr<v0::Constant> new_axis;const auto& indices_rank_val = static_cast<size_t>(main_node->get_input_partial_shape(1).rank().get_length());std::vector<size_t> new_transpose_order;@@ -310,14 +315,14 @@ TSGatherBackward::TSGatherBackward() {} else {const std::vector<size_t> axes_values = {axis};new_transpose_order = GetOrderBeforeReduction(axes_values, order_val);- new_axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{1}, axis);+ new_axis = std::make_shared<v0::Constant>(ov::element::i32, ov::Shape{1}, axis);}RemoveTransposeConsumers(main_node);if (success) {auto target_inputs = main_node->get_output_target_inputs(0);- auto unsqueeze_axes = ov::op::v0::Constant::create(element::i32, {new_axes_val.size()}, new_axes_val);- auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(main_node, unsqueeze_axes);+ auto unsqueeze_axes = v0::Constant::create(ov::element::i32, {new_axes_val.size()}, new_axes_val);+ auto unsqueeze = std::make_shared<v0::Unsqueeze>(main_node, unsqueeze_axes);for (const auto& input : target_inputs) {input.replace_source_output(unsqueeze);}@@ -325,21 +330,21 @@ TSGatherBackward::TSGatherBackward() {main_node->output(0).set_names({});unsqueeze->set_friendly_name(main_node->get_friendly_name());main_node->set_friendly_name("");- copy_runtime_info(main_node, {unsqueeze, unsqueeze_axes});+ ov::copy_runtime_info(main_node, {unsqueeze, unsqueeze_axes});}const auto reversed_transpose_order = ReverseTransposeOrder(order_val);- const auto& transpose_const = ov::op::v0::Constant::create(transpose_order->get_element_type(),- {new_transpose_order.size()},- new_transpose_order);+ const auto& transpose_const = v0::Constant::create(transpose_order->get_element_type(),+ {new_transpose_order.size()},+ new_transpose_order);for (auto& new_node : sink_backward::InsertTransposeBeforeNode(main_node,transpose_const,/* input_indexes= */ {0})) {register_new_node(new_node);}if (!new_axis) {- new_axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{1}, reversed_transpose_order[axis]);+ new_axis = std::make_shared<v0::Constant>(ov::element::i32, ov::Shape{1}, reversed_transpose_order[axis]);}- copy_runtime_info(gather_axis, new_axis);+ ov::copy_runtime_info(gather_axis, new_axis);main_node->input(2).replace_source_output(new_axis);main_node->validate_and_infer_types();return true;@@ -348,3 +353,5 @@ TSGatherBackward::TSGatherBackward() {auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_interpolate.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_interpolate.cppindex fc3b23a0b99..0a95ab8a181 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_interpolate.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_interpolate.cpp@@ -16,14 +16,17 @@#include "transformations/transpose_sinking/ts_utils.hpp"#include "transformations/utils/utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace v4 = ov::op::v4;++namespace ov::pass {+TSInterpolateForward::TSInterpolateForward() {MATCHER_SCOPE(TSInterpolateForward);- create_pattern<ov::op::v4::Interpolate>({0});+ create_pattern<v4::Interpolate>({0});auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {@@ -32,12 +35,12 @@ TSInterpolateForward::TSInterpolateForward() {main_node->input(0).replace_source_output(transpose_parent);const auto transpose_axis_order = transpose_info.transpose_const->get_axis_vector_val();- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);const auto& new_axes = ChangeAxes(main_node->input_value(3), transpose_axis_order, axis);main_node->input(3).replace_source_output(new_axes);- const auto& interpolate = ov::as_type_ptr<ov::op::v4::Interpolate>(main_node);+ const auto& interpolate = ov::as_type_ptr<v4::Interpolate>(main_node);if (interpolate) {op::v4::Interpolate::InterpolateAttrs attrs = interpolate->get_attrs();if (!attrs.pads_begin.empty() || !attrs.pads_end.empty()) {@@ -65,21 +68,21 @@ TSInterpolateForward::TSInterpolateForward() {TSInterpolateBackward::TSInterpolateBackward() {MATCHER_SCOPE(TSInterpolateBackward);- auto main_node_label = wrap_type<ov::op::v4::Interpolate>([](const Output<Node>& output) -> bool {- return has_static_rank()(output) && CheckTransposeConsumers(output);+ auto main_node_label = pattern::wrap_type<v4::Interpolate>([](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output) && CheckTransposeConsumers(output);});- auto transpose_const_label = wrap_type<ov::op::v0::Constant>();+ auto transpose_const_label = pattern::wrap_type<v0::Constant>();- auto transpose_label = wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });+ auto transpose_label = pattern::wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });- matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose_const =- as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());+ as_type_ptr<v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr();if (transformation_callback(main_node)) {@@ -95,11 +98,11 @@ TSInterpolateBackward::TSInterpolateBackward() {RemoveTransposeConsumers(main_node);const auto transpose_axis_order = transpose_const->get_axis_vector_val();const auto reversed_transpose_order = ReverseTransposeOrder(transpose_axis_order);- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);auto new_axes = ChangeAxes(main_node->input_value(3), reversed_transpose_order, axis);main_node->input(3).replace_source_output(new_axes);- const auto& interpolate = ov::as_type_ptr<ov::op::v4::Interpolate>(main_node);+ const auto& interpolate = ov::as_type_ptr<v4::Interpolate>(main_node);if (interpolate) {op::v4::Interpolate::InterpolateAttrs attrs = interpolate->get_attrs();if (!attrs.pads_begin.empty() || !attrs.pads_end.empty()) {@@ -120,6 +123,8 @@ TSInterpolateBackward::TSInterpolateBackward() {return true;};- auto m = std::make_shared<Matcher>(transpose_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_reduction.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_reduction.cppindex 58ff18e9dda..768ecebd3c0 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_reduction.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_reduction.cpp@@ -18,16 +18,19 @@#include "transformations/transpose_sinking/ts_utils.hpp"#include "transformations/utils/utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace op_util = ov::op::util;++namespace ov::pass {+namespace {bool get_keep_dims(const std::shared_ptr<Node>& main_node) {- auto arithmetic_reduce = as_type_ptr<ov::op::util::ArithmeticReductionKeepDims>(main_node);- auto logical_reduce = as_type_ptr<ov::op::util::LogicalReductionKeepDims>(main_node);+ auto arithmetic_reduce = as_type_ptr<op_util::ArithmeticReductionKeepDims>(main_node);+ auto logical_reduce = as_type_ptr<op_util::LogicalReductionKeepDims>(main_node);bool keep_dims = false; // squeeze/unsqueeze always reduces number of output dimensionsif (logical_reduce)@@ -47,7 +50,7 @@ TSReductionForward::TSReductionForward() {const TransposeInputsInfo& transpose_info) -> bool {auto keep_dims = get_keep_dims(main_node);auto transpose_order = transpose_info.transpose_const;- auto reduction_axes = as_type_ptr<ov::op::v0::Constant>(main_node->get_input_node_shared_ptr(1));+ auto reduction_axes = as_type_ptr<v0::Constant>(main_node->get_input_node_shared_ptr(1));if (!transpose_order || !reduction_axes)return false;@@ -66,12 +69,11 @@ TSReductionForward::TSReductionForward() {transpose_order_values = GetOrderAfterReduction(non_negative_axes, transpose_order_values);}- auto new_transpose_order = ov::op::v0::Constant::create(transpose_order->get_element_type(),- {transpose_order_values.size()},- transpose_order_values);+ auto new_transpose_order = v0::Constant::create(transpose_order->get_element_type(),+ {transpose_order_values.size()},+ transpose_order_values);- auto new_const =- ov::op::v0::Constant::create(reduction_axes->get_element_type(), {new_values.size()}, new_values);+ auto new_const = v0::Constant::create(reduction_axes->get_element_type(), {new_values.size()}, new_values);main_node->input(1).replace_source_output(new_const);TransposeInputsInfo transpose_input_info = {transpose_info.transpose, new_transpose_order, 0};// deletes Transpose from 0 input@@ -92,13 +94,13 @@ TSReductionForward::TSReductionForward() {TSReductionBackward::TSReductionBackward() {MATCHER_SCOPE(TSReductionBackward);- auto reduce_label = wrap_type<op::util::ArithmeticReductionKeepDims, op::util::LogicalReductionKeepDims>(- {any_input(), wrap_type<ov::op::v0::Constant>()},+ auto reduce_label = pattern::wrap_type<op::util::ArithmeticReductionKeepDims, op::util::LogicalReductionKeepDims>(+ {pattern::any_input(), pattern::wrap_type<v0::Constant>()},CheckTransposeConsumers);- auto transpose_label = wrap_type<ov::op::v1::Transpose>({reduce_label, wrap_type<ov::op::v0::Constant>()},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });+ auto transpose_label = pattern::wrap_type<ov::op::v1::Transpose>({reduce_label, pattern::wrap_type<v0::Constant>()},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_map();@@ -110,8 +112,8 @@ TSReductionBackward::TSReductionBackward() {auto keep_dims = get_keep_dims(main_node);- auto transpose_order = as_type_ptr<ov::op::v0::Constant>(transpose->get_input_node_shared_ptr(1));- auto reduction_axes = as_type_ptr<ov::op::v0::Constant>(main_node->get_input_node_shared_ptr(1));+ auto transpose_order = as_type_ptr<v0::Constant>(transpose->get_input_node_shared_ptr(1));+ auto reduction_axes = as_type_ptr<v0::Constant>(main_node->get_input_node_shared_ptr(1));if (!transpose_order || !reduction_axes)return false;@@ -124,17 +126,16 @@ TSReductionBackward::TSReductionBackward() {transpose_order_values = GetOrderBeforeReduction(non_negative_axes, transpose_order_values);}auto reversed_order_values = ReverseTransposeOrder(transpose_order_values);- auto new_transpose_order = ov::op::v0::Constant::create(transpose_order->get_element_type(),- {transpose_order_values.size()},- transpose_order_values);+ auto new_transpose_order = v0::Constant::create(transpose_order->get_element_type(),+ {transpose_order_values.size()},+ transpose_order_values);std::vector<size_t> new_values;for (const auto& axis : non_negative_axes) {new_values.push_back(reversed_order_values[axis]);}- auto new_const =- ov::op::v0::Constant::create(reduction_axes->get_element_type(), {new_values.size()}, new_values);+ auto new_const = v0::Constant::create(reduction_axes->get_element_type(), {new_values.size()}, new_values);main_node->input(1).replace_source_output(new_const);for (auto& new_node : sink_backward::InsertTransposeBeforeNode(main_node, new_transpose_order, {0})) {register_new_node(new_node);@@ -148,3 +149,5 @@ TSReductionBackward::TSReductionBackward() {auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_reset_no_sinking_attribute.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_reset_no_sinking_attribute.cppindex e67dfa676c5..b86c0a86c19 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_reset_no_sinking_attribute.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_reset_no_sinking_attribute.cpp@@ -10,14 +10,14 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "transformations/rt_info/transpose_sinking_attr.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;+namespace ov::pass {+TSResetNoSinkingAttribute::TSResetNoSinkingAttribute() {MATCHER_SCOPE(TSResetNoSinkingAttribute);- auto transpose_label = wrap_type<ov::op::v1::Transpose>([](const Output<Node>& output) -> bool {+ auto transpose_label = pattern::wrap_type<ov::op::v1::Transpose>([](const Output<Node>& output) -> bool {const auto& rt_info = output.get_node()->get_rt_info();return rt_info.find(NoTransposeSinkingAttr::get_type_info_static()) != rt_info.end();});@@ -31,3 +31,5 @@ TSResetNoSinkingAttribute::TSResetNoSinkingAttribute() {auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_slice.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_slice.cppindex 070e3d4d1c1..ab5a804b4e0 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_slice.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_slice.cpp@@ -16,14 +16,17 @@#include "transformations/rt_info/transpose_sinking_attr.hpp"#include "transformations/transpose_sinking/ts_utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace v8 = ov::op::v8;++namespace ov::pass {+TSSliceForward::TSSliceForward() {MATCHER_SCOPE(TSSliceForward);- create_pattern<ov::op::v8::Slice>({0});+ create_pattern<v8::Slice>({0});auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {@@ -36,13 +39,12 @@ TSSliceForward::TSSliceForward() {main_node->input(0).replace_source_output(transpose_parent);const auto transpose_axis_order = transpose_info.transpose_const->get_axis_vector_val();- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, std::vector<int32_t>{0});+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, std::vector<int32_t>{0});- auto data = std::make_shared<ov::op::v0::Constant>(element::i32,- Shape{transpose_axis_order.size()},- transpose_axis_order);+ auto data =+ std::make_shared<v0::Constant>(element::i32, Shape{transpose_axis_order.size()}, transpose_axis_order);const auto& indices = main_node->input_value(4);- auto new_axis = std::make_shared<ov::op::v8::Gather>(data, indices, axis);+ auto new_axis = std::make_shared<v8::Gather>(data, indices, axis);ov::copy_runtime_info(indices.get_node_shared_ptr(), new_axis);main_node->input(4).replace_source_output(new_axis);@@ -57,21 +59,21 @@ TSSliceForward::TSSliceForward() {TSSliceBackward::TSSliceBackward() {MATCHER_SCOPE(TSSliceBackward);- auto main_node_label = wrap_type<ov::op::v8::Slice>([](const Output<Node>& output) -> bool {- return has_static_rank()(output) && CheckTransposeConsumers(output);+ auto main_node_label = pattern::wrap_type<v8::Slice>([](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output) && CheckTransposeConsumers(output);});- auto transpose_const_label = wrap_type<ov::op::v0::Constant>();+ auto transpose_const_label = pattern::wrap_type<v0::Constant>();- auto transpose_label = wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });+ auto transpose_label = pattern::wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });- matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose_const =- as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());+ as_type_ptr<v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr();if (transformation_callback(main_node)) {@@ -91,12 +93,12 @@ TSSliceBackward::TSSliceBackward() {RemoveTransposeConsumers(main_node);const auto transpose_axis_order = transpose_const->get_axis_vector_val();const auto reversed_transpose_order = ReverseTransposeOrder(transpose_axis_order);- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, std::vector<int32_t>{0});- auto data = std::make_shared<ov::op::v0::Constant>(element::i32,- Shape{reversed_transpose_order.size()},- reversed_transpose_order);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, std::vector<int32_t>{0});+ auto data = std::make_shared<v0::Constant>(element::i32,+ Shape{reversed_transpose_order.size()},+ reversed_transpose_order);const auto& indices = main_node->input_value(4);- auto new_axis = std::make_shared<ov::op::v8::Gather>(data, indices, axis);+ auto new_axis = std::make_shared<v8::Gather>(data, indices, axis);ov::copy_runtime_info(indices.get_node_shared_ptr(), new_axis);main_node->input(4).replace_source_output(new_axis);@@ -104,6 +106,8 @@ TSSliceBackward::TSSliceBackward() {return true;};- auto m = std::make_shared<Matcher>(transpose_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_split.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_split.cppindex 7b5e3b97a1a..5f1abf19d60 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_split.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_split.cpp@@ -16,28 +16,31 @@#include "transformations/transpose_sinking/ts_utils.hpp"#include "transformations/utils/utils.hpp"-using namespace ov::pass::pattern;-using namespace ov;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+namespace {using NodePtr = std::shared_ptr<Node>;struct OutputTranspose {OutputTranspose() : transpose(nullptr), transpose_const(nullptr) {}- ov::op::v1::Transpose* transpose;- ov::op::v0::Constant* transpose_const;+ v1::Transpose* transpose;+ v0::Constant* transpose_const;};OutputTranspose GetOutputTransposes(const NodePtr& node) {for (size_t output_idx = 0; output_idx < node->get_output_size(); ++output_idx) {for (auto& input : node->get_output_target_inputs(output_idx)) {- auto transpose_node = ov::as_type<ov::op::v1::Transpose>(input.get_node());+ auto transpose_node = ov::as_type<v1::Transpose>(input.get_node());if (!transpose_node)continue;- auto constant_node = ov::as_type<ov::op::v0::Constant>(transpose_node->input_value(1).get_node());+ auto constant_node = ov::as_type<v0::Constant>(transpose_node->input_value(1).get_node());if (!constant_node)continue;{@@ -65,7 +68,7 @@ std::shared_ptr<ov::Node> FindInputNode(ov::Node* node) {}bool HasInputSplitAndTransposeSiblings(const Output<Node>& output) {- NodePtr main_node = FindInputNode<ov::op::v1::Split>(output.get_node());+ NodePtr main_node = FindInputNode<v1::Split>(output.get_node());if (!main_node) {return false;}@@ -77,7 +80,7 @@ bool IsSplitSinked(const Output<Node>& output) {return HasInputSplitAndTransposeSiblings(output);}-bool GetSplitAxis(const std::shared_ptr<ov::op::v0::Constant>& split_axis, const ov::Rank& rank, int64_t& axis) {+bool GetSplitAxis(const std::shared_ptr<v0::Constant>& split_axis, const ov::Rank& rank, int64_t& axis) {auto split_axis_val = split_axis->cast_vector<int64_t>();if (split_axis_val.empty()) {return false;@@ -93,16 +96,17 @@ bool GetSplitAxis(const std::shared_ptr<ov::op::v0::Constant>& split_axis, const}return true;}+} // namespaceTSSplitForward::TSSplitForward() {MATCHER_SCOPE(TSSplitForward);- create_pattern<ov::op::v1::Split, ov::op::v1::VariadicSplit>({0});+ create_pattern<v1::Split, v1::VariadicSplit>({0});auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {- auto split_axis_constant = as_type_ptr<ov::op::v0::Constant>(main_node->input_value(1).get_node_shared_ptr());+ auto split_axis_constant = as_type_ptr<v0::Constant>(main_node->input_value(1).get_node_shared_ptr());if (!split_axis_constant) {return false;}@@ -115,9 +119,8 @@ TSSplitForward::TSSplitForward() {sink_forward::RemoveInputNode(main_node, /* input_idx */ 0);const auto transpose_axis_order = transpose_info.transpose_const->get_axis_vector_val();const size_t transposed_split_axis = transpose_axis_order[split_axis];- auto new_split_axis_const = std::make_shared<ov::op::v0::Constant>(split_axis_constant->get_element_type(),- Shape{},- transposed_split_axis);+ auto new_split_axis_const =+ std::make_shared<v0::Constant>(split_axis_constant->get_element_type(), Shape{}, transposed_split_axis);main_node->input(1).replace_source_output(new_split_axis_const);copy_runtime_info({split_axis_constant, transpose_info.transpose, transpose_info.transpose_const},new_split_axis_const);@@ -158,22 +161,23 @@ TSSplitForward::TSSplitForward() {TSSplitBackward::TSSplitBackward() {MATCHER_SCOPE(TSSplitBackward);- auto transpose_const_label = wrap_type<ov::op::v0::Constant>();- auto transpose_label = wrap_type<ov::op::v1::Transpose>({any_input(), transpose_const_label}, IsSplitSinked);+ auto transpose_const_label = pattern::wrap_type<v0::Constant>();+ auto transpose_label =+ pattern::wrap_type<v1::Transpose>({pattern::any_input(), transpose_const_label}, IsSplitSinked);- matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose_label_node = pattern_to_output.at(transpose_label).get_node();- NodePtr split = FindInputNode<ov::op::v1::Split>(transpose_label_node);+ NodePtr split = FindInputNode<v1::Split>(transpose_label_node);if (!split) {- split = FindInputNode<ov::op::v1::VariadicSplit>(transpose_label_node);+ split = FindInputNode<v1::VariadicSplit>(transpose_label_node);}if (!split || transformation_callback(split)) {return false;}- auto split_axis_constant = as_type_ptr<ov::op::v0::Constant>(split->input_value(1).get_node_shared_ptr());+ auto split_axis_constant = as_type_ptr<v0::Constant>(split->input_value(1).get_node_shared_ptr());if (!split_axis_constant) {return false;}@@ -194,10 +198,10 @@ TSSplitBackward::TSSplitBackward() {// insert transpose before split{auto input_node = split->input_value(0);- auto new_transpose_const = std::make_shared<ov::op::v0::Constant>(transpose_element_type,- Shape{transpose_axis_order.size()},- transpose_axis_order);- auto new_transpose = std::make_shared<ov::op::v1::Transpose>(input_node, new_transpose_const);+ auto new_transpose_const = std::make_shared<v0::Constant>(transpose_element_type,+ Shape{transpose_axis_order.size()},+ transpose_axis_order);+ auto new_transpose = std::make_shared<v1::Transpose>(input_node, new_transpose_const);split->input(0).replace_source_output(new_transpose->output(0));@@ -207,9 +211,9 @@ TSSplitBackward::TSSplitBackward() {}// update split axis- auto new_split_axis_const = std::make_shared<ov::op::v0::Constant>(split_axis_constant->get_element_type(),- Shape{},- reversed_transposed_split_axis);+ auto new_split_axis_const = std::make_shared<v0::Constant>(split_axis_constant->get_element_type(),+ Shape{},+ reversed_transposed_split_axis);split->input(1).replace_source_output(new_split_axis_const);copy_runtime_info({split_axis_constant,output_transpose.transpose->shared_from_this(),@@ -222,6 +226,8 @@ TSSplitBackward::TSSplitBackward() {return true;};- auto m = std::make_shared<Matcher>(transpose_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_squeeze.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_squeeze.cppindex 01efca09659..bd4faa78e14 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_squeeze.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_squeeze.cpp@@ -19,15 +19,18 @@#include "transformations/transpose_sinking/ts_utils.hpp"#include "transformations/utils/utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+namespace {/**- * @brief Checks that Reshape operation is equal to ov::op::v0::Squeeze:+ * @brief Checks that Reshape operation is equal to v0::Squeeze:* Only 1 dims are deleted, all other dims must be the same.* Converts these 1 dims to axes format.* @arg reshape Reshape operation.@@ -35,7 +38,7 @@ namespace {* @arg result_axes Contains axes which will be squeezed.*/bool shape_to_squeeze_axes(const std::shared_ptr<Node>& reshape,- const std::shared_ptr<ov::op::v0::Constant>& reshape_to_shape,+ const std::shared_ptr<v0::Constant>& reshape_to_shape,std::vector<size_t>& result_axes) {result_axes.clear();auto reduction_axes_values = reshape_to_shape->cast_vector<int64_t>();@@ -104,18 +107,18 @@ bool squeeze_axes_to_shape(const Output<Node>& input_node,TSSqueezeForward::TSSqueezeForward() {MATCHER_SCOPE(TSSqueezeForward);- create_pattern<ov::op::v0::Squeeze, ov::op::v1::Reshape>({0});+ create_pattern<v0::Squeeze, v1::Reshape>({0});auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {std::vector<size_t> non_negative_axes;- std::shared_ptr<ov::op::v0::Constant> squeeze_axes;+ std::shared_ptr<v0::Constant> squeeze_axes;if (main_node->get_input_size() > 1) {- squeeze_axes = as_type_ptr<ov::op::v0::Constant>(main_node->get_input_node_shared_ptr(1));+ squeeze_axes = as_type_ptr<v0::Constant>(main_node->get_input_node_shared_ptr(1));if (!squeeze_axes) {return false;}- if (as_type_ptr<ov::op::v1::Reshape>(main_node)) {+ if (as_type_ptr<v1::Reshape>(main_node)) {auto success = shape_to_squeeze_axes(main_node, squeeze_axes, non_negative_axes);if (!success) {return false;@@ -148,11 +151,11 @@ TSSqueezeForward::TSSqueezeForward() {}transpose_order_values = GetOrderAfterReduction(non_negative_axes, transpose_order_values);- auto new_transpose_order = ov::op::v0::Constant::create(transpose_info.transpose_const->get_element_type(),- {transpose_order_values.size()},- transpose_order_values);+ auto new_transpose_order = v0::Constant::create(transpose_info.transpose_const->get_element_type(),+ {transpose_order_values.size()},+ transpose_order_values);- if (as_type_ptr<ov::op::v1::Reshape>(main_node)) {+ if (as_type_ptr<v1::Reshape>(main_node)) {std::vector<size_t> to_shape;auto success = squeeze_axes_to_shape(transpose_info.transpose->input_value(0), new_values, to_shape);if (!success) {@@ -162,8 +165,7 @@ TSSqueezeForward::TSSqueezeForward() {}if (squeeze_axes) {- auto new_const =- ov::op::v0::Constant::create(squeeze_axes->get_element_type(), {new_values.size()}, new_values);+ auto new_const = v0::Constant::create(squeeze_axes->get_element_type(), {new_values.size()}, new_values);main_node->input(1).replace_source_output(new_const);copy_runtime_info(squeeze_axes, new_const);}@@ -184,17 +186,17 @@ TSSqueezeForward::TSSqueezeForward() {TSSqueezeBackward::TSSqueezeBackward() {MATCHER_SCOPE(TSSqueezeBackward);- auto squeeze_with_1_input = wrap_type<ov::op::v0::Squeeze>({any_input()}, CheckTransposeConsumers);+ auto squeeze_with_1_input = pattern::wrap_type<v0::Squeeze>({pattern::any_input()}, CheckTransposeConsumers);auto squeeze_label =- wrap_type<ov::op::v0::Squeeze, ov::op::v1::Reshape>({any_input(), wrap_type<ov::op::v0::Constant>()},- CheckTransposeConsumers);+ pattern::wrap_type<v0::Squeeze, v1::Reshape>({pattern::any_input(), pattern::wrap_type<v0::Constant>()},+ CheckTransposeConsumers);auto pattern = std::make_shared<pattern::op::Or>(OutputVector{squeeze_with_1_input, squeeze_label});- auto transpose_label = wrap_type<ov::op::v1::Transpose>({pattern, wrap_type<ov::op::v0::Constant>()},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });+ auto transpose_label = pattern::wrap_type<v1::Transpose>({pattern, pattern::wrap_type<v0::Constant>()},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });- ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_map();auto transpose = pattern_to_output.at(transpose_label);@@ -209,20 +211,20 @@ TSSqueezeBackward::TSSqueezeBackward() {return false;}- auto transpose_order = as_type_ptr<ov::op::v0::Constant>(transpose->get_input_node_shared_ptr(1));+ auto transpose_order = as_type_ptr<v0::Constant>(transpose->get_input_node_shared_ptr(1));if (!transpose_order) {return false;}std::vector<size_t> non_negative_axes;- std::shared_ptr<ov::op::v0::Constant> squeeze_axes;+ std::shared_ptr<v0::Constant> squeeze_axes;if (main_node->get_input_size() > 1) {- squeeze_axes = as_type_ptr<ov::op::v0::Constant>(main_node->get_input_node_shared_ptr(1));+ squeeze_axes = as_type_ptr<v0::Constant>(main_node->get_input_node_shared_ptr(1));if (!squeeze_axes) {return false;}- if (as_type_ptr<ov::op::v1::Reshape>(main_node)) {+ if (as_type_ptr<v1::Reshape>(main_node)) {auto success = shape_to_squeeze_axes(main_node, squeeze_axes, non_negative_axes);if (!success) {return false;@@ -257,11 +259,11 @@ TSSqueezeBackward::TSSqueezeBackward() {new_values.push_back(reversed_order_values[axis]);}- auto new_transpose_order = ov::op::v0::Constant::create(transpose_order->get_element_type(),- {transpose_order_values.size()},- transpose_order_values);+ auto new_transpose_order = v0::Constant::create(transpose_order->get_element_type(),+ {transpose_order_values.size()},+ transpose_order_values);auto new_transpose = transpose->clone_with_new_inputs({main_node->input_value(0), new_transpose_order});- if (as_type_ptr<ov::op::v1::Reshape>(main_node)) {+ if (as_type_ptr<v1::Reshape>(main_node)) {std::vector<size_t> to_shape;auto success = squeeze_axes_to_shape(new_transpose->output(0), new_values, to_shape);if (!success) {@@ -272,8 +274,7 @@ TSSqueezeBackward::TSSqueezeBackward() {std::shared_ptr<Node> new_squeeze;if (!squeeze_all_dims) {- auto new_const =- ov::op::v0::Constant::create(squeeze_axes->get_element_type(), {new_values.size()}, new_values);+ auto new_const = v0::Constant::create(squeeze_axes->get_element_type(), {new_values.size()}, new_values);main_node->input(1).replace_source_output(new_const);copy_runtime_info(squeeze_axes, new_const);}@@ -290,3 +291,5 @@ TSSqueezeBackward::TSSqueezeBackward() {auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_tile.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_tile.cppindex 60febd5fa01..35631e4376c 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_tile.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_tile.cpp@@ -14,18 +14,20 @@#include "transformations/rt_info/transpose_sinking_attr.hpp"#include "transformations/transpose_sinking/ts_utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+#undef TILE_REPEATS_INPUT_IDX#define TILE_REPEATS_INPUT_IDX 1+namespace ov::pass {+TSTileForward::TSTileForward() {MATCHER_SCOPE(TSTileForward);- create_pattern<ov::op::v0::Tile>({0});+ create_pattern<v0::Tile>({0});auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {@@ -38,7 +40,7 @@ TSTileForward::TSTileForward() {return res;const auto transpose_axis_order = transpose_info.transpose_const->get_axis_vector_val();- auto repeats = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto repeats = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);const auto& new_repeats =ChangeValuesOrder(main_node->input_value(TILE_REPEATS_INPUT_IDX), transpose_axis_order, repeats);main_node->input(TILE_REPEATS_INPUT_IDX).replace_source_output(new_repeats);@@ -51,20 +53,20 @@ TSTileForward::TSTileForward() {TSTileBackward::TSTileBackward() {MATCHER_SCOPE(TSTileBackward);- auto main_node_label = wrap_type<ov::op::v0::Tile>([](const Output<Node>& output) -> bool {- return has_static_rank()(output) && CheckTransposeConsumers(output);+ auto main_node_label = pattern::wrap_type<v0::Tile>([](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output) && CheckTransposeConsumers(output);});- auto transpose_const_label = wrap_type<ov::op::v0::Constant>();+ auto transpose_const_label = pattern::wrap_type<v0::Constant>();- auto transpose_label = wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });- matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ auto transpose_label = pattern::wrap_type<ov::op::v1::Transpose>({main_node_label, transpose_const_label},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });+ matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose_const =- as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());+ as_type_ptr<v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto main_node = pattern_to_output.at(main_node_label).get_node_shared_ptr();@@ -80,7 +82,7 @@ TSTileBackward::TSTileBackward() {RemoveTransposeConsumers(main_node);const auto transpose_axis_order = transpose_const->get_axis_vector_val();- auto repeats = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto repeats = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);auto new_repeats =ChangeValuesOrder(main_node->input_value(TILE_REPEATS_INPUT_IDX), transpose_axis_order, repeats);main_node->input(TILE_REPEATS_INPUT_IDX).replace_source_output(new_repeats);@@ -88,6 +90,8 @@ TSTileBackward::TSTileBackward() {main_node->validate_and_infer_types();return true;};- auto m = std::make_shared<Matcher>(transpose_label, matcher_name);+ auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_unary.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_unary.cppindex ce4118402a2..58bf00fcbd2 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_unary.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_unary.cpp@@ -28,18 +28,24 @@#include "transformations/transpose_sinking/ts_utils.hpp"#include "transformations/utils/utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;-using namespace ov::op::util;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;+namespace v5 = ov::op::v5;+namespace v10 = ov::op::v10;+namespace op_util = ov::op::util;++namespace ov::pass {+namespace {using NodePtr = std::shared_ptr<ov::Node>;-bool if_transpose_sinkable(const std::shared_ptr<ov::op::v1::Transpose>& transpose,- const std::shared_ptr<ov::op::v0::Constant>& transpose_order) {+bool if_transpose_sinkable(const std::shared_ptr<v1::Transpose>& transpose,+ const std::shared_ptr<v0::Constant>& transpose_order) {return static_cast<bool>(transpose);}@@ -50,20 +56,20 @@ TSUnaryForward::TSUnaryForward() {// We consider HardSigmoid, Swish, Selu, ConvertLike as unary ops// and handle only 0th input of these ops.- create_pattern<UnaryElementwiseArithmetic,- ov::op::v0::Clamp,- ov::op::v0::Elu,- ov::op::v4::SoftPlus,- ov::op::v1::LogicalNot,- ov::op::v0::Convert,- ov::op::v10::IsInf,- ov::op::v10::IsNaN,- ov::op::v10::IsFinite,- ov::op::v0::Selu,- ov::op::v4::Swish,- ov::op::v0::HardSigmoid,- ov::op::v5::LogSoftmax,- ov::op::v1::ConvertLike>({0}, if_transpose_sinkable);+ create_pattern<op_util::UnaryElementwiseArithmetic,+ v0::Clamp,+ v0::Elu,+ v4::SoftPlus,+ v1::LogicalNot,+ v0::Convert,+ v10::IsInf,+ v10::IsNaN,+ v10::IsFinite,+ v0::Selu,+ v4::Swish,+ v0::HardSigmoid,+ v5::LogSoftmax,+ v1::ConvertLike>({0}, if_transpose_sinkable);auto ts_unary_sinking_function = [this](const std::shared_ptr<Node>& main_node,const utils::TransposeInputsInfo& transpose_info) -> bool {bool res = utils::sink_forward::UpdateInputTransposes(main_node, transpose_info, {0});@@ -82,34 +88,35 @@ TSUnaryBackward::TSUnaryBackward() {return CheckTransposeConsumers(output);};- auto unary_with_1_input_label = wrap_type<UnaryElementwiseArithmetic,- ov::op::v0::Clamp,- ov::op::v0::Elu,- ov::op::v4::SoftPlus,- ov::op::v1::LogicalNot,- ov::op::v0::Convert,- ov::op::v10::IsInf,- ov::op::v10::IsNaN,- ov::op::v10::IsFinite,- ov::op::v5::LogSoftmax>({any_input()}, unary_restrictions);+ auto unary_with_1_input_label = pattern::wrap_type<op_util::UnaryElementwiseArithmetic,+ v0::Clamp,+ v0::Elu,+ v4::SoftPlus,+ v1::LogicalNot,+ v0::Convert,+ v10::IsInf,+ v10::IsNaN,+ v10::IsFinite,+ v5::LogSoftmax>({pattern::any_input()}, unary_restrictions);auto unary_with_2_inputs_label =- wrap_type<ov::op::v4::Swish, ov::op::v1::ConvertLike>({any_input(), any_input()}, unary_restrictions);- auto unary_with_3_inputs_label =- wrap_type<ov::op::v0::Selu, ov::op::v0::HardSigmoid>({any_input(), any_input(), any_input()},- unary_restrictions);+ pattern::wrap_type<v4::Swish, v1::ConvertLike>({pattern::any_input(), pattern::any_input()},+ unary_restrictions);+ auto unary_with_3_inputs_label = pattern::wrap_type<v0::Selu, v0::HardSigmoid>(+ {pattern::any_input(), pattern::any_input(), pattern::any_input()},+ unary_restrictions);auto unary_label = std::make_shared<pattern::op::Or>(ov::OutputVector{unary_with_1_input_label, unary_with_2_inputs_label, unary_with_3_inputs_label});- auto transpose_const_label = wrap_type<ov::op::v0::Constant>();+ auto transpose_const_label = pattern::wrap_type<v0::Constant>();- auto transpose_label = wrap_type<ov::op::v1::Transpose>({unary_label, transpose_const_label});+ auto transpose_label = pattern::wrap_type<v1::Transpose>({unary_label, transpose_const_label});- ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](Matcher& m) {+ ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_value_map();auto transpose_const =- as_type_ptr<ov::op::v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());+ as_type_ptr<v0::Constant>(pattern_to_output.at(transpose_const_label).get_node_shared_ptr());auto transpose = pattern_to_output.at(transpose_label).get_node_shared_ptr();auto unary = transpose->get_input_node_shared_ptr(0);if (transformation_callback(unary)) {@@ -124,6 +131,8 @@ TSUnaryBackward::TSUnaryBackward() {return true;};- auto m = std::make_shared<Matcher>(transpose_label, "ov::pass::TSUnaryBackward");+ auto m = std::make_shared<pattern::Matcher>(transpose_label, "ov::pass::TSUnaryBackward");register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_unsqueeze.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_unsqueeze.cppindex d73a171a83a..51b03038af3 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_unsqueeze.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_unsqueeze.cpp@@ -17,15 +17,18 @@#include "transformations/transpose_sinking/ts_utils.hpp"#include "transformations/utils/utils.hpp"-using namespace ov;-using namespace ov::pass::pattern;using namespace ov::pass::transpose_sinking;using namespace ov::pass::transpose_sinking::utils;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;++namespace ov::pass {+namespace {/**- * @brief Checks that Reshape operation is equal to ov::op::v0::Unsqueeze:+ * @brief Checks that Reshape operation is equal to v0::Unsqueeze:* Only 1 dims are inserted, all other dims must be the same.* Converts these 1 dims to axes format.* @arg reshape Reshape operation.@@ -33,7 +36,7 @@ namespace {* @arg result_axes contains axes which will be unsqueezed.*/bool shape_to_unsqueeze_axes(const std::shared_ptr<Node>& reshape,- const std::shared_ptr<ov::op::v0::Constant>& reshape_to_shape,+ const std::shared_ptr<v0::Constant>& reshape_to_shape,std::vector<size_t>& result_axes) {result_axes.clear();auto reduction_axes_values = reshape_to_shape->cast_vector<int64_t>();@@ -73,7 +76,7 @@ bool shape_to_unsqueeze_axes(const std::shared_ptr<Node>& reshape,* @brief Converts unsqueeze_axes to actual shape (2nd input) for Reshape operation* using the shape of the 1st input to Reshape.* @arg input_node 1st input to Reshape op.- * @arg unsqueeze_axes In case of Reshape op is equal to ov::op::v0::Unsqueeze, these axes indicate the places where 1+ * @arg unsqueeze_axes In case of Reshape op is equal to v0::Unsqueeze, these axes indicate the places where 1* dims have to be inserted.*/bool unsqueeze_axes_to_shape(const Output<Node>& input_node,@@ -99,7 +102,7 @@ bool unsqueeze_axes_to_shape(const Output<Node>& input_node,return true;}-bool AreInputOutputShapesEqual(const std::shared_ptr<ov::op::v1::Reshape>& reshape) {+bool AreInputOutputShapesEqual(const std::shared_ptr<v1::Reshape>& reshape) {const auto input_shape = reshape->get_input_partial_shape(0);const auto output_shape = reshape->get_output_partial_shape(0);@@ -109,7 +112,7 @@ bool AreInputOutputShapesEqual(const std::shared_ptr<ov::op::v1::Reshape>& reshareturn input_shape == output_shape;}-bool HasSpecialOne(const std::shared_ptr<ov::op::v0::Constant>& reshape_const) {+bool HasSpecialOne(const std::shared_ptr<v0::Constant>& reshape_const) {auto const_value = reshape_const->cast_vector<int64_t>();return std::find(const_value.begin(), const_value.end(), -1) != const_value.end();}@@ -119,18 +122,18 @@ bool HasSpecialOne(const std::shared_ptr<ov::op::v0::Constant>& reshape_const) {TSUnsqueezeForward::TSUnsqueezeForward() {MATCHER_SCOPE(TSUnsqueezeForward);- create_pattern<ov::op::v0::Unsqueeze, ov::op::v1::Reshape>({0});+ create_pattern<v0::Unsqueeze, v1::Reshape>({0});auto sinking_transformation = [OV_CAPTURE_CPY_AND_THIS](const std::shared_ptr<Node>& main_node,const TransposeInputsInfo& transpose_info) -> bool {- auto unsqueeze_axes = as_type_ptr<ov::op::v0::Constant>(main_node->get_input_node_shared_ptr(1));+ auto unsqueeze_axes = as_type_ptr<v0::Constant>(main_node->get_input_node_shared_ptr(1));if (!unsqueeze_axes) {return false;}auto ts_order_values = transpose_info.transpose_const->cast_vector<size_t>();// if main_node does nothing, just swap them- auto reshape = as_type_ptr<ov::op::v1::Reshape>(main_node);+ auto reshape = as_type_ptr<v1::Reshape>(main_node);if (reshape && AreInputOutputShapesEqual(reshape) && !HasSpecialOne(unsqueeze_axes)) {TransposeInputsInfo transpose_input_info = {transpose_info.transpose, transpose_info.transpose_const, 0};// remove input Transpose@@ -141,7 +144,7 @@ TSUnsqueezeForward::TSUnsqueezeForward() {const auto reshape_order = ov::pass::transpose_sinking::utils::ReverseTransposeOrder(ts_order_values);// transpose reshape const with Gather operation- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);auto gather =ov::pass::transpose_sinking::utils::ChangeValuesOrder(reshape->input_value(1), reshape_order, axis);main_node->input(1).replace_source_output(gather);@@ -151,7 +154,7 @@ TSUnsqueezeForward::TSUnsqueezeForward() {}std::vector<size_t> non_negative_axes;- if (as_type_ptr<ov::op::v1::Reshape>(main_node)) {+ if (as_type_ptr<v1::Reshape>(main_node)) {auto success = shape_to_unsqueeze_axes(main_node, unsqueeze_axes, non_negative_axes);if (!success) {return false;@@ -163,19 +166,18 @@ TSUnsqueezeForward::TSUnsqueezeForward() {}ts_order_values = GetOrderBeforeReduction(non_negative_axes, ts_order_values);- auto new_transpose_order = ov::op::v0::Constant::create(transpose_info.transpose_const->get_element_type(),- {ts_order_values.size()},- ts_order_values);+ auto new_transpose_order = v0::Constant::create(transpose_info.transpose_const->get_element_type(),+ {ts_order_values.size()},+ ts_order_values);- if (as_type_ptr<ov::op::v1::Reshape>(main_node)) {+ if (as_type_ptr<v1::Reshape>(main_node)) {std::vector<size_t> new_values;auto success =unsqueeze_axes_to_shape(transpose_info.transpose->input_value(0), non_negative_axes, new_values);if (!success) {return false;}- auto new_const =- ov::op::v0::Constant::create(unsqueeze_axes->get_element_type(), {new_values.size()}, new_values);+ auto new_const = v0::Constant::create(unsqueeze_axes->get_element_type(), {new_values.size()}, new_values);main_node->input(1).replace_source_output(new_const);copy_runtime_info(unsqueeze_axes, new_const);}@@ -198,12 +200,12 @@ TSUnsqueezeBackward::TSUnsqueezeBackward() {MATCHER_SCOPE(TSUnsqueezeBackward);auto unsqueeze_label =- wrap_type<ov::op::v0::Unsqueeze, ov::op::v1::Reshape>({any_input(), wrap_type<ov::op::v0::Constant>()},- CheckTransposeConsumers);- auto transpose_label = wrap_type<ov::op::v1::Transpose>({unsqueeze_label, wrap_type<ov::op::v0::Constant>()},- [](const Output<Node>& output) -> bool {- return has_static_rank()(output);- });+ pattern::wrap_type<v0::Unsqueeze, v1::Reshape>({pattern::any_input(), pattern::wrap_type<v0::Constant>()},+ CheckTransposeConsumers);+ auto transpose_label = pattern::wrap_type<v1::Transpose>({unsqueeze_label, pattern::wrap_type<v0::Constant>()},+ [](const Output<Node>& output) -> bool {+ return pattern::has_static_rank()(output);+ });ov::matcher_pass_callback matcher_pass_callback = [OV_CAPTURE_CPY_AND_THIS](pattern::Matcher& m) {const auto& pattern_to_output = m.get_pattern_map();@@ -214,22 +216,22 @@ TSUnsqueezeBackward::TSUnsqueezeBackward() {return false;}- auto transpose_order = ov::as_type_ptr<ov::op::v0::Constant>(transpose->get_input_node_shared_ptr(1));- auto unsqueeze_axes = ov::as_type_ptr<ov::op::v0::Constant>(main_node->get_input_node_shared_ptr(1));+ auto transpose_order = ov::as_type_ptr<v0::Constant>(transpose->get_input_node_shared_ptr(1));+ auto unsqueeze_axes = ov::as_type_ptr<v0::Constant>(main_node->get_input_node_shared_ptr(1));if (!transpose_order || !unsqueeze_axes)return false;auto transpose_order_values = transpose_order->cast_vector<size_t>();// if main_node does nothing, just swap them- auto reshape = as_type_ptr<ov::op::v1::Reshape>(main_node);+ auto reshape = as_type_ptr<v1::Reshape>(main_node);if (reshape && AreInputOutputShapesEqual(reshape) && !HasSpecialOne(unsqueeze_axes)) {// insert Transpose before main_node on #0 inputfor (auto& new_node : sink_backward::InsertTransposeBeforeNode(main_node, transpose_order, {0})) {register_new_node(new_node);}// transpose reshape const with Gather operation- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);auto gather = ov::pass::transpose_sinking::utils::ChangeValuesOrder(reshape->input_value(1),transpose_order_values,axis);@@ -241,7 +243,7 @@ TSUnsqueezeBackward::TSUnsqueezeBackward() {}std::vector<size_t> non_negative_axes;- if (as_type_ptr<ov::op::v1::Reshape>(main_node)) {+ if (as_type_ptr<v1::Reshape>(main_node)) {auto success = shape_to_unsqueeze_axes(main_node, unsqueeze_axes, non_negative_axes);if (!success) {return false;@@ -280,14 +282,14 @@ TSUnsqueezeBackward::TSUnsqueezeBackward() {}transpose_order_values = GetOrderAfterReduction(new_values, transpose_order_values);- auto new_transpose_order = std::make_shared<ov::op::v0::Constant>(transpose_order->get_element_type(),- Shape{transpose_order_values.size()},- transpose_order_values);+ auto new_transpose_order = std::make_shared<v0::Constant>(transpose_order->get_element_type(),+ Shape{transpose_order_values.size()},+ transpose_order_values);for (auto& new_node : sink_backward::InsertTransposeBeforeNode(main_node, new_transpose_order, {0})) {register_new_node(new_node);}- if (as_type_ptr<ov::op::v1::Reshape>(main_node)) {+ if (as_type_ptr<v1::Reshape>(main_node)) {std::vector<size_t> to_shape;auto success = unsqueeze_axes_to_shape(main_node->input_value(0), new_values, to_shape);if (!success) {@@ -295,8 +297,7 @@ TSUnsqueezeBackward::TSUnsqueezeBackward() {}new_values = to_shape;}- auto new_const =- ov::op::v0::Constant::create(unsqueeze_axes->get_element_type(), {new_values.size()}, new_values);+ auto new_const = v0::Constant::create(unsqueeze_axes->get_element_type(), {new_values.size()}, new_values);main_node->input(1).replace_source_output(new_const);main_node->validate_and_infer_types();@@ -308,3 +309,5 @@ TSUnsqueezeBackward::TSUnsqueezeBackward() {auto m = std::make_shared<pattern::Matcher>(transpose_label, matcher_name);register_matcher(m, matcher_pass_callback);}++} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/transpose_sinking/ts_utils.cpp b/src/common/transformations/src/transformations/transpose_sinking/ts_utils.cppindex 78aa0ac2e90..ef146eb19a9 100644--- a/src/common/transformations/src/transformations/transpose_sinking/ts_utils.cpp+++ b/src/common/transformations/src/transformations/transpose_sinking/ts_utils.cpp@@ -32,44 +32,43 @@#include "transformations/rt_info/transpose_sinking_attr.hpp"#include "transformations/utils/utils.hpp"-namespace ov {-namespace pass {+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;+namespace ov::pass {namespace transpose_sinking {namespace utils {-using namespace ov;-using NodePtr = std::shared_ptr<Node>;using InsertBroadcastUnsqueezeT = std::function<NodePtr(const Output<Node>& node, size_t n_dims)>;Output<Node> ChangeValuesOrder(const Output<Node>& input,const AxisVector& transpose_axis_order,- const std::shared_ptr<ov::op::v0::Constant>& axis) {+ const std::shared_ptr<v0::Constant>& axis) {auto indices =- std::make_shared<ov::op::v0::Constant>(element::i32, Shape{transpose_axis_order.size()}, transpose_axis_order);- auto gather = std::make_shared<ov::op::v8::Gather>(input, indices, axis);+ std::make_shared<v0::Constant>(element::i32, Shape{transpose_axis_order.size()}, transpose_axis_order);+ auto gather = std::make_shared<v8::Gather>(input, indices, axis);copy_runtime_info(input.get_node_shared_ptr(), gather);return gather;}Output<Node> ChangeAxes(const Output<Node>& indices,- const std::shared_ptr<ov::op::v0::Constant>& data,- const std::shared_ptr<ov::op::v0::Constant>& axis) {- auto gather = std::make_shared<ov::op::v8::Gather>(data, indices, axis);+ const std::shared_ptr<v0::Constant>& data,+ const std::shared_ptr<v0::Constant>& axis) {+ auto gather = std::make_shared<v8::Gather>(data, indices, axis);copy_runtime_info(indices.get_node_shared_ptr(), gather);return gather;}Output<Node> ChangeAxes(const Output<Node>& indices,const AxisVector& transpose_axis_order,- const std::shared_ptr<ov::op::v0::Constant>& axis) {- auto data =- std::make_shared<ov::op::v0::Constant>(element::i32, Shape{transpose_axis_order.size()}, transpose_axis_order);+ const std::shared_ptr<v0::Constant>& axis) {+ auto data = std::make_shared<v0::Constant>(element::i32, Shape{transpose_axis_order.size()}, transpose_axis_order);return ChangeAxes(indices, data, axis);}-bool if_transpose_sinkable_default(const std::shared_ptr<ov::op::v1::Transpose>& transpose,- const std::shared_ptr<ov::op::v0::Constant>& transpose_order) {+bool if_transpose_sinkable_default(const std::shared_ptr<v1::Transpose>& transpose,+ const std::shared_ptr<v0::Constant>& transpose_order) {if (!transpose || !transpose_order)return false;const auto partial_shape_rank = transpose->get_input_partial_shape(0).rank();@@ -82,8 +81,8 @@ bool if_transpose_sinkable_default(const std::shared_ptr<ov::op::v1::Transpose>&TransposeInputsInfo GetFirstTransposeInput(const NodePtr& node,const std::vector<size_t>& indices,- const std::function<bool(const std::shared_ptr<ov::op::v1::Transpose>& transpose,- const std::shared_ptr<ov::op::v0::Constant>& transpose_order)>& if_transpose_sinkable) {+ const std::function<bool(const std::shared_ptr<v1::Transpose>& transpose,+ const std::shared_ptr<v0::Constant>& transpose_order)>& if_transpose_sinkable) {auto indices_to_check = indices;if (indices.empty()) {indices_to_check.resize(node->get_input_size());@@ -92,10 +91,10 @@ TransposeInputsInfo GetFirstTransposeInput(for (const auto& input_idx : indices_to_check) {NodePtr input_node = node->get_input_node_shared_ptr(input_idx);- auto transpose_node = as_type_ptr<ov::op::v1::Transpose>(input_node);+ auto transpose_node = as_type_ptr<v1::Transpose>(input_node);if (!transpose_node)continue;- auto constant_node = as_type_ptr<ov::op::v0::Constant>(transpose_node->input_value(1).get_node_shared_ptr());+ auto constant_node = as_type_ptr<v0::Constant>(transpose_node->input_value(1).get_node_shared_ptr());if (!if_transpose_sinkable(transpose_node, constant_node))continue;{@@ -137,8 +136,8 @@ NodePtr InsertBroadcastUnsqueeze(const Output<Node>& node, size_t n_dims) {std::vector<size_t> dims(n_dims);std::iota(dims.begin(), dims.end(), 0);- auto unsqueeze_const = std::make_shared<ov::op::v0::Constant>(ov::element::i64, Shape{dims.size()}, dims);- auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(node, unsqueeze_const);+ auto unsqueeze_const = std::make_shared<v0::Constant>(ov::element::i64, Shape{dims.size()}, dims);+ auto unsqueeze = std::make_shared<v0::Unsqueeze>(node, unsqueeze_const);copy_runtime_info(node.get_node_shared_ptr(), {unsqueeze, unsqueeze_const});return unsqueeze;}@@ -244,11 +243,10 @@ bool UpdateInputTransposes(const NodePtr& main_node,return false;}const auto reversed_transpose_axis_order = ReverseTransposeOrder(transpose_order);- auto new_transpose_const =- std::make_shared<ov::op::v0::Constant>(transpose_element_type,- Shape{reversed_transpose_axis_order.size()},- reversed_transpose_axis_order);- auto new_transpose = std::make_shared<ov::op::v1::Transpose>(input_node, new_transpose_const);+ auto new_transpose_const = std::make_shared<v0::Constant>(transpose_element_type,+ Shape{reversed_transpose_axis_order.size()},+ reversed_transpose_axis_order);+ auto new_transpose = std::make_shared<v1::Transpose>(input_node, new_transpose_const);main_node->input(i).replace_source_output(new_transpose->output(0));@@ -277,9 +275,9 @@ NodeVector InsertOutputTransposes(const NodePtr& main_node, const TransposeInputfor (size_t i = 0; i < main_node->get_output_size(); ++i) {auto aligned_order = AlignTransposeOrder(main_node->output(i), transpose_input_info);auto new_transpose_const =- std::make_shared<ov::op::v0::Constant>(transpose_element_type, Shape{aligned_order.size()}, aligned_order);+ std::make_shared<v0::Constant>(transpose_element_type, Shape{aligned_order.size()}, aligned_order);auto main_node_consumers = main_node->output(i).get_target_inputs();- auto new_transpose = std::make_shared<ov::op::v1::Transpose>(main_node->output(i), new_transpose_const);+ auto new_transpose = std::make_shared<v1::Transpose>(main_node->output(i), new_transpose_const);for (auto& consumer : main_node_consumers) {consumer.replace_source_output(new_transpose);}@@ -300,7 +298,7 @@ NodeVector InsertOutputTransposes(const NodePtr& main_node, const TransposeInputnamespace sink_backward {NodeVector InsertTransposeBeforeNode(const NodePtr& main_node,- const std::shared_ptr<ov::op::v0::Constant>& transpose_const,+ const std::shared_ptr<v0::Constant>& transpose_const,std::vector<size_t> input_indexes,InsertBroadcastUnsqueezeT InsertUnsqueeze) {if (input_indexes.empty()) {@@ -322,10 +320,10 @@ NodeVector InsertTransposeBeforeNode(const NodePtr& main_node,for (const auto& i : input_indexes) {auto input_node = FixInputNodeRank(main_node->input_value(i), max_input_rank, InsertUnsqueeze);- auto new_transpose_const = std::make_shared<ov::op::v0::Constant>(transpose_element_type,- Shape{transpose_axis_order.size()},- transpose_axis_order);- auto new_transpose = std::make_shared<ov::op::v1::Transpose>(input_node, new_transpose_const);+ auto new_transpose_const = std::make_shared<v0::Constant>(transpose_element_type,+ Shape{transpose_axis_order.size()},+ transpose_axis_order);+ auto new_transpose = std::make_shared<v1::Transpose>(input_node, new_transpose_const);main_node->input(i).replace_source_output(new_transpose->output(0));@@ -340,12 +338,12 @@ NodeVector InsertTransposeBeforeNode(const NodePtr& main_node,namespace {-std::shared_ptr<ov::op::v0::Constant> GetTransposeConstant(Node* node) {- auto transpose_node = ov::as_type<ov::op::v1::Transpose>(node);+std::shared_ptr<v0::Constant> GetTransposeConstant(Node* node) {+ auto transpose_node = ov::as_type<v1::Transpose>(node);if (!transpose_node)return {};- auto constant_node = as_type_ptr<ov::op::v0::Constant>(transpose_node->input_value(1).get_node_shared_ptr());+ auto constant_node = as_type_ptr<v0::Constant>(transpose_node->input_value(1).get_node_shared_ptr());if (!constant_node)return {};@@ -403,16 +401,16 @@ bool CheckTransposeConsumers(const Output<Node>& output) {}bool RemoveTransposeConsumers(const NodePtr& node) {- std::unordered_map<size_t, std::vector<ov::op::v1::Transpose*>> out_idx_to_redundant_transposes;+ std::unordered_map<size_t, std::vector<v1::Transpose*>> out_idx_to_redundant_transposes;// in case of multiple Transposes connected directly to Result ops,// we can't guarantee that friendly names are copied correctly,// we preserve only one of possible variants.// This note related to friendly names only, not to tensor names.- ov::op::v1::Transpose* transpose_connected_to_result = nullptr;+ v1::Transpose* transpose_connected_to_result = nullptr;for (size_t output_idx = 0; output_idx < node->get_output_size(); ++output_idx) {for (auto& consumer_input : node->get_output_target_inputs(output_idx)) {- auto transpose = ov::as_type<ov::op::v1::Transpose>(consumer_input.get_node());+ auto transpose = ov::as_type<v1::Transpose>(consumer_input.get_node());if (!transpose) {// should never happen// the check that all consumers of the main node are Transposes is added@@ -422,7 +420,7 @@ bool RemoveTransposeConsumers(const NodePtr& node) {out_idx_to_redundant_transposes[output_idx].push_back(transpose);for (const auto& transpose_consumer_input : transpose->output(0).get_target_inputs()) {- if (ov::as_type<ov::op::v0::Result>(transpose_consumer_input.get_node())) {+ if (ov::as_type<v0::Result>(transpose_consumer_input.get_node())) {transpose_connected_to_result = transpose;}}@@ -495,5 +493,4 @@ std::vector<size_t> GetOrderBeforeReduction(const std::vector<size_t>& axes_valu} // namespace utils} // namespace transpose_sinking-} // namespace pass-} // namespace ov+} // namespace ov::passdiff --git a/src/common/transformations/src/transformations/utils/utils.cpp b/src/common/transformations/src/transformations/utils/utils.cppindex 06d7a6c86bd..41bc0f1b220 100644--- a/src/common/transformations/src/transformations/utils/utils.cpp+++ b/src/common/transformations/src/transformations/utils/utils.cpp@@ -39,6 +39,15 @@#include "openvino/pass/pattern/op/wrap_type.hpp"#include "openvino/util/common_util.hpp"+using ov::pass::pattern::any_input;+using ov::pass::pattern::wrap_type;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v6 = ov::op::v6;+namespace v8 = ov::op::v8;+namespace op_util = ov::op::util;namespace ov {namespace op {namespace util {@@ -147,18 +156,16 @@ bool has_f16_constants(const std::shared_ptr<const ov::Model>& function) {}bool is_large_language_model(const ov::Model& model, std::function<bool(std::shared_ptr<ov::Node>)> func) {- using namespace ov::pass::pattern;-- const auto past = wrap_type<ov::op::v6::ReadValue>();- const auto convert_past = ov::pass::pattern::optional<ov::op::v0::Convert>(past);- const auto beam_idx = wrap_type<ov::op::v0::Parameter>();- const auto gather_past = wrap_type<ov::op::v8::Gather>({convert_past, beam_idx, wrap_type<ov::op::v0::Constant>()});- const auto gather_convert = ov::pass::pattern::optional<ov::op::v0::Convert>(gather_past);+ const auto past = wrap_type<v6::ReadValue>();+ const auto convert_past = ov::pass::pattern::optional<v0::Convert>(past);+ const auto beam_idx = wrap_type<v0::Parameter>();+ const auto gather_past = wrap_type<v8::Gather>({convert_past, beam_idx, wrap_type<v0::Constant>()});+ const auto gather_convert = ov::pass::pattern::optional<v0::Convert>(gather_past);const auto concat_past_input =std::make_shared<ov::pass::pattern::op::Or>(OutputVector{convert_past, gather_convert});- const auto concat = wrap_type<ov::op::v0::Concat>({concat_past_input, any_input()});- const auto convert_present = ov::pass::pattern::optional<ov::op::v0::Convert>(concat);- const auto present = wrap_type<ov::op::v6::Assign>({convert_present});+ const auto concat = wrap_type<v0::Concat>({concat_past_input, any_input()});+ const auto convert_present = ov::pass::pattern::optional<v0::Convert>(concat);+ const auto present = wrap_type<v6::Assign>({convert_present});const auto kvcache_matcher = std::make_shared<ov::pass::pattern::Matcher>(present, "KVCacheMatcher");for (const auto& op : model.get_ops()) {@@ -207,11 +214,11 @@ bool check_for_broadcast(const ov::PartialShape& ref_shape, const ov::PartialShastd::shared_ptr<ov::Node> activation(const std::string& activation_name, const ov::Output<ov::Node>& apply_to) {if (activation_name == "relu") {- return std::make_shared<ov::op::v0::Relu>(apply_to);+ return std::make_shared<v0::Relu>(apply_to);} else if (activation_name == "sigmoid") {- return std::make_shared<ov::op::v0::Sigmoid>(apply_to);+ return std::make_shared<v0::Sigmoid>(apply_to);} else if (activation_name == "tanh") {- return std::make_shared<ov::op::v0::Tanh>(apply_to);+ return std::make_shared<v0::Tanh>(apply_to);} else {OPENVINO_THROW("Unsupported activation function");}@@ -225,18 +232,18 @@ bool is_seq_len_provided(const std::shared_ptr<Node>& X, const std::shared_ptr<N// supported seq_len_input:// X -> ShapeOf -> Gather (max_seq_dim) -> Optional (Broadcast)std::shared_ptr<Node> input = seq_len_input;- auto broadcast = ov::as_type_ptr<ov::op::v3::Broadcast>(input);+ auto broadcast = ov::as_type_ptr<v3::Broadcast>(input);if (broadcast) {input = seq_len_input->input_value(0).get_node_shared_ptr();}- auto gather = ov::as_type_ptr<ov::op::util::GatherBase>(input);+ auto gather = ov::as_type_ptr<op_util::GatherBase>(input);bool valid_gather = false;if (gather) {auto indices = gather->input_value(1).get_node_shared_ptr();auto axis = gather->input_value(2).get_node_shared_ptr();- auto indices_const = ov::as_type_ptr<ov::op::v0::Constant>(indices);- auto axis_const = ov::as_type_ptr<ov::op::v0::Constant>(axis);+ auto indices_const = ov::as_type_ptr<v0::Constant>(indices);+ auto axis_const = ov::as_type_ptr<v0::Constant>(axis);if (indices_const && axis_const) {auto ind_values = indices_const->cast_vector<int64_t>();auto axis_values = axis_const->cast_vector<int64_t>();@@ -250,7 +257,7 @@ bool is_seq_len_provided(const std::shared_ptr<Node>& X, const std::shared_ptr<Nreturn true;}- auto shape_of = ov::as_type_ptr<ov::op::util::ShapeOfBase>(gather->input_value(0).get_node_shared_ptr());+ auto shape_of = ov::as_type_ptr<op_util::ShapeOfBase>(gather->input_value(0).get_node_shared_ptr());if (!shape_of) {return true;}@@ -333,22 +340,21 @@ bool shapes_equal_except_dynamic_expected_batch(const ov::PartialShape& expectedvoid visit_shape_path(Node* node, std::unordered_set<ov::Node*>& visited, std::function<void(ov::Node*)> func) {auto is_shapeof = [](ov::Node* node) {- return ov::is_type<ov::op::v0::ShapeOf>(node) || ov::is_type<ov::op::v3::ShapeOf>(node);+ return ov::is_type<v0::ShapeOf>(node) || ov::is_type<v3::ShapeOf>(node);};visit_path(node, visited, func, is_shapeof);}void visit_constant_path(ov::Node* node, std::unordered_set<ov::Node*>& visited, std::function<void(ov::Node*)> func) {auto check_parameter = [](ov::Node* node) {- OPENVINO_ASSERT(!ov::is_type<ov::op::v0::Parameter>(node),- "visit_constant_path is called for non-constant path.");+ OPENVINO_ASSERT(!ov::is_type<v0::Parameter>(node), "visit_constant_path is called for non-constant path.");return false;};visit_path(node, visited, func, check_parameter);}bool is_dequantization_subgraph(const Output<Node>& node) {- if (!is_type<ov::op::v1::Multiply>(node.get_node())) {+ if (!is_type<v1::Multiply>(node.get_node())) {return false;}@@ -356,9 +362,9 @@ bool is_dequantization_subgraph(const Output<Node>& node) {Node* sub = nullptr;Node* convert = nullptr;- if (is_type<ov::op::v1::Subtract>(mul_inputs[0].get_node())) {+ if (is_type<v1::Subtract>(mul_inputs[0].get_node())) {sub = mul_inputs[0].get_node();- } else if (is_type<ov::op::v0::Convert>(mul_inputs[0].get_node())) {+ } else if (is_type<v0::Convert>(mul_inputs[0].get_node())) {convert = mul_inputs[0].get_node();} else {return false;@@ -366,7 +372,7 @@ bool is_dequantization_subgraph(const Output<Node>& node) {if (sub) {auto sub_inputs = sub->input_values();- if (is_type<ov::op::v0::Convert>(sub_inputs[0].get_node())) {+ if (is_type<v0::Convert>(sub_inputs[0].get_node())) {convert = sub_inputs[0].get_node();}}@@ -383,8 +389,8 @@ bool is_dequantization_subgraph(const Output<Node>& node) {bool can_eliminate_eltwise_node(const std::shared_ptr<Node>& eltwise,const Output<Node>& constant,const Output<Node>& non_constant_input) {- if (!is_type<ov::op::v1::Add>(eltwise) && !is_type<ov::op::v1::Subtract>(eltwise) &&- !is_type<ov::op::v1::Multiply>(eltwise) && !is_type<ov::op::v1::Divide>(eltwise)) {+ if (!is_type<v1::Add>(eltwise) && !is_type<v1::Subtract>(eltwise) && !is_type<v1::Multiply>(eltwise) &&+ !is_type<v1::Divide>(eltwise)) {return false;}@@ -393,7 +399,7 @@ bool can_eliminate_eltwise_node(const std::shared_ptr<Node>& eltwise,}// check if constant has a single value with either 0 (for Add, Subtract) or 1 (for Multiply, Divide)- auto constant_ptr = ov::as_type_ptr<ov::op::v0::Constant>(constant.get_node_shared_ptr());+ auto constant_ptr = ov::as_type_ptr<v0::Constant>(constant.get_node_shared_ptr());if (!constant_ptr) {return false;}@@ -440,7 +446,7 @@ bool can_eliminate_eltwise_node(const std::shared_ptr<Node>& eltwise,return false;}float expected_const = 0;- if (is_type<ov::op::v1::Multiply>(eltwise) || is_type<ov::op::v1::Divide>(eltwise)) {+ if (is_type<v1::Multiply>(eltwise) || is_type<v1::Divide>(eltwise)) {expected_const = 1;}if (actual_const != expected_const) {@@ -546,12 +552,12 @@ std::shared_ptr<ov::Node> NewGenStridedSlice(const std::shared_ptr<ov::Node>& dabegin_mask[axis] = 0;end_mask[axis] = 0;- return ov::pass::pattern::wrap_type<ov::op::v1::StridedSlice>({data, start, stop, step},- {{"begin_mask", begin_mask},- {"end_mask", end_mask},- {"new_axis_mask", new_axis_mask},- {"shrink_axis_mask", shrink_axis_mask},- {"ellipsis_mask", ellipsis_mask}});+ return wrap_type<v1::StridedSlice>({data, start, stop, step},+ {{"begin_mask", begin_mask},+ {"end_mask", end_mask},+ {"new_axis_mask", new_axis_mask},+ {"shrink_axis_mask", shrink_axis_mask},+ {"ellipsis_mask", ellipsis_mask}});}std::shared_ptr<ov::Node> NewGenSlice(const std::shared_ptr<ov::Node>& data,@@ -565,8 +571,7 @@ std::shared_ptr<ov::Node> NewGenSlice(const std::shared_ptr<ov::Node>& data,auto slice_step = ParseSymbolVariant({step});auto slice_axis = ParseSymbolVariant({static_cast<int64_t>(axis)});- auto opt1 =- ov::pass::pattern::wrap_type<ov::op::v8::Slice>({data, slice_start, slice_stop, slice_step, slice_axis});+ auto opt1 = wrap_type<v8::Slice>({data, slice_start, slice_stop, slice_step, slice_axis});std::vector<symbol_variant> vbegin(axis + 1, 0);std::vector<symbol_variant> vend(axis + 1, 0);@@ -589,12 +594,12 @@ std::shared_ptr<ov::Node> NewGenSlice(const std::shared_ptr<ov::Node>& data,begin_mask[axis] = 0;end_mask[axis] = 0;- auto opt2 = pattern::wrap_type<ov::op::v1::StridedSlice>({data, begin, end, stride},- {{"begin_mask", begin_mask},- {"end_mask", end_mask},- {"new_axis_mask", new_axis_mask},- {"shrink_axis_mask", shrink_axis_mask},- {"ellipsis_mask", ellipsis_mask}});+ auto opt2 = wrap_type<v1::StridedSlice>({data, begin, end, stride},+ {{"begin_mask", begin_mask},+ {"end_mask", end_mask},+ {"new_axis_mask", new_axis_mask},+ {"shrink_axis_mask", shrink_axis_mask},+ {"ellipsis_mask", ellipsis_mask}});return opt1 | opt2;}@@ -607,13 +612,11 @@ std::tuple<std::shared_ptr<ov::Node>,std::shared_ptr<ov::Node>>match_multi_query_bcst(const std::shared_ptr<ov::Node>& kv) {using namespace ov::pass;- using namespace ov::pass::pattern;-- auto reshape_kv = wrap_type<ov::op::v1::Reshape>({kv, any_input()});- auto unsqueeze_kv = wrap_type<ov::op::v0::Unsqueeze>({kv, any_input()});+ auto reshape_kv = wrap_type<v1::Reshape>({kv, any_input()});+ auto unsqueeze_kv = wrap_type<v0::Unsqueeze>({kv, any_input()});auto check_one = [](const Output<Node>& output) -> bool {- auto node = ov::as_type_ptr<ov::op::v0::Constant>(output.get_node_shared_ptr());+ auto node = ov::as_type_ptr<v0::Constant>(output.get_node_shared_ptr());if (!node) {return false;}@@ -622,15 +625,14 @@ match_multi_query_bcst(const std::shared_ptr<ov::Node>& kv) {return i == 1.0F;});};- auto constant_bcst = wrap_type<ov::op::v0::Constant>(check_one);+ auto constant_bcst = wrap_type<v0::Constant>(check_one);- auto computed_bcst =- wrap_type<ov::op::v1::Broadcast>({constant_bcst, any_input(), any_input()}, {{"mode", "numpy"}});+ auto computed_bcst = wrap_type<v1::Broadcast>({constant_bcst, any_input(), any_input()}, {{"mode", "numpy"}});- auto multiply_kv = wrap_type<ov::op::v1::Multiply>({reshape_kv | unsqueeze_kv, constant_bcst | computed_bcst});- auto computed_bcst3 = wrap_type<ov::op::v3::Broadcast>({unsqueeze_kv, any_input()}, {{"mode", "bidirectional"}});+ auto multiply_kv = wrap_type<v1::Multiply>({reshape_kv | unsqueeze_kv, constant_bcst | computed_bcst});+ auto computed_bcst3 = wrap_type<v3::Broadcast>({unsqueeze_kv, any_input()}, {{"mode", "bidirectional"}});- auto result = wrap_type<ov::op::v1::Reshape>({multiply_kv | computed_bcst3, any_input()});+ auto result = wrap_type<v1::Reshape>({multiply_kv | computed_bcst3, any_input()});return std::make_tuple(result, reshape_kv, unsqueeze_kv, computed_bcst, multiply_kv, computed_bcst3);}diff --git a/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp b/src/common/transformations/tests/common_optimizations/activations_scaling_test.cppindex 2cdae52040a..4bf9f2d2a79 100644--- a/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp+++ b/src/common/transformations/tests/common_optimizations/activations_scaling_test.cpp@@ -27,43 +27,47 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v6 = ov::op::v6;+namespace v12 = ov::op::v12;TEST_F(TransformationTestsF, ScaleDownSingleLayerTest) {float scale_factor = 128.f;{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 16, 16});- auto weights_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3, 3, 3, 3}, {1});- auto conv = std::make_shared<ov::op::v1::Convolution>(input,- weights_const,- Strides{},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 3, 1, 1}, {2.3f});- auto add = std::make_shared<ov::op::v1::Add>(conv, bias_const);- auto convert = std::make_shared<ov::op::v0::Convert>(add, ov::element::f32);- auto result = std::make_shared<ov::op::v0::Result>(convert);+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 16, 16});+ auto weights_const = v0::Constant::create(ov::element::f16, ov::Shape{3, 3, 3, 3}, {1});+ auto conv = std::make_shared<v1::Convolution>(input,+ weights_const,+ Strides{},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto bias_const = v0::Constant::create(ov::element::f16, ov::Shape{1, 3, 1, 1}, {2.3f});+ auto add = std::make_shared<v1::Add>(conv, bias_const);+ auto convert = std::make_shared<v0::Convert>(add, ov::element::f32);+ auto result = std::make_shared<v0::Result>(convert);model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});manager.register_pass<ov::pass::activations_scaling::ScaleDownSingleLayer>(scale_factor, ov::element::f16);}{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 16, 16});- auto weights_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3, 3, 3, 3}, {1});- auto scale_down_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{}, {1.f / scale_factor});- auto scale_down = std::make_shared<ov::op::v1::Multiply>(input, scale_down_const);- auto conv = std::make_shared<ov::op::v1::Convolution>(scale_down,- weights_const,- Strides{},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1, 3, 1, 1}, {2.3f});- auto scale_down_bias = std::make_shared<ov::op::v1::Multiply>(bias_const, scale_down_const);- auto add = std::make_shared<ov::op::v1::Add>(conv, scale_down_bias);- auto scale_up_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{}, {scale_factor});- auto scale_up = std::make_shared<ov::op::v1::Multiply>(add, scale_up_const);- auto convert = std::make_shared<ov::op::v0::Convert>(scale_up, ov::element::f32);- auto result = std::make_shared<ov::op::v0::Result>(convert);+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 16, 16});+ auto weights_const = v0::Constant::create(ov::element::f16, ov::Shape{3, 3, 3, 3}, {1});+ auto scale_down_const = v0::Constant::create(ov::element::f16, ov::Shape{}, {1.f / scale_factor});+ auto scale_down = std::make_shared<v1::Multiply>(input, scale_down_const);+ auto conv = std::make_shared<v1::Convolution>(scale_down,+ weights_const,+ Strides{},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto bias_const = v0::Constant::create(ov::element::f16, ov::Shape{1, 3, 1, 1}, {2.3f});+ auto scale_down_bias = std::make_shared<v1::Multiply>(bias_const, scale_down_const);+ auto add = std::make_shared<v1::Add>(conv, scale_down_bias);+ auto scale_up_const = v0::Constant::create(ov::element::f16, ov::Shape{}, {scale_factor});+ auto scale_up = std::make_shared<v1::Multiply>(add, scale_up_const);+ auto convert = std::make_shared<v0::Convert>(scale_up, ov::element::f32);+ auto result = std::make_shared<v0::Result>(convert);model_ref = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});}@@ -73,28 +77,27 @@ TEST_F(TransformationTestsF, EliminateScalarMulTest) {double epsilon = 1.f;float scale_factor = 8.f;{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 4, 4});- auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {scale_factor});- auto mul = std::make_shared<ov::op::v1::Multiply>(input, scale_const);- auto norm_scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});- auto norm_bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});- auto group_norm =- std::make_shared<ov::op::v12::GroupNormalization>(mul, norm_scale_const, norm_bias_const, 1, epsilon);- auto convert = std::make_shared<ov::op::v0::Convert>(group_norm, ov::element::f32);- auto result = std::make_shared<ov::op::v0::Result>(convert);+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 4, 4});+ auto scale_const = v0::Constant::create(ov::element::f16, ov::Shape{1}, {scale_factor});+ auto mul = std::make_shared<v1::Multiply>(input, scale_const);+ auto norm_scale_const = v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});+ auto norm_bias_const = v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});+ auto group_norm = std::make_shared<v12::GroupNormalization>(mul, norm_scale_const, norm_bias_const, 1, epsilon);+ auto convert = std::make_shared<v0::Convert>(group_norm, ov::element::f32);+ auto result = std::make_shared<v0::Result>(convert);model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});manager.register_pass<ov::pass::activations_scaling::EliminateScalarMul>();}{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 4, 4});- auto norm_scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});- auto norm_bias_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 4, 4});+ auto norm_scale_const = v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});+ auto norm_bias_const = v0::Constant::create(ov::element::f16, ov::Shape{3}, {10});epsilon /= scale_factor;auto group_norm =- std::make_shared<ov::op::v12::GroupNormalization>(input, norm_scale_const, norm_bias_const, 1, epsilon);- auto convert = std::make_shared<ov::op::v0::Convert>(group_norm, ov::element::f32);- auto result = std::make_shared<ov::op::v0::Result>(convert);+ std::make_shared<v12::GroupNormalization>(input, norm_scale_const, norm_bias_const, 1, epsilon);+ auto convert = std::make_shared<v0::Convert>(group_norm, ov::element::f32);+ auto result = std::make_shared<v0::Result>(convert);model_ref = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input});}@@ -103,25 +106,25 @@ TEST_F(TransformationTestsF, EliminateScalarMulTest) {TEST_F(TransformationTestsF, MoveDownScalarMulTest) {{- auto input0 = std::make_shared<ov::op::v0::Parameter>(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<ov::op::v1::Multiply>(input0, scale_const0);- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});- auto mul1 = std::make_shared<ov::op::v1::Multiply>(input1, mul0);- auto convert = std::make_shared<ov::op::v0::Convert>(mul1, ov::element::f32);- auto result = std::make_shared<ov::op::v0::Result>(convert);+ auto input0 = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});+ auto scale_const0 = v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});+ auto mul0 = std::make_shared<v1::Multiply>(input0, scale_const0);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});+ auto mul1 = std::make_shared<v1::Multiply>(input1, mul0);+ auto convert = std::make_shared<v0::Convert>(mul1, ov::element::f32);+ auto result = std::make_shared<v0::Result>(convert);model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input0, input1});manager.register_pass<ov::pass::activations_scaling::MoveDownScalarMul>();}{- auto input0 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});- auto mul0 = std::make_shared<ov::op::v1::Multiply>(input0, input1);- auto scale_const0 = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});- auto mul1 = std::make_shared<ov::op::v1::Multiply>(mul0, scale_const0);- auto convert = std::make_shared<ov::op::v0::Convert>(mul1, ov::element::f32);- auto result = std::make_shared<ov::op::v0::Result>(convert);+ auto input0 = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});+ auto input1 = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{6, 12, 10, 24});+ auto mul0 = std::make_shared<v1::Multiply>(input0, input1);+ auto scale_const0 = v0::Constant::create(ov::element::f16, ov::Shape{1}, {10});+ auto mul1 = std::make_shared<v1::Multiply>(mul0, scale_const0);+ auto convert = std::make_shared<v0::Convert>(mul1, ov::element::f32);+ auto result = std::make_shared<v0::Result>(convert);model_ref = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input0, input1});}@@ -131,30 +134,30 @@ TEST_F(TransformationTestsF, MulShareTransformationTest) {float epsilon = 1.f;float scale_factor = 8.f;{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 4, 4});- auto mvn_axes = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 3});- auto mvn = std::make_shared<ov::op::v6::MVN>(input, mvn_axes, true, epsilon, ov::op::MVNEpsMode::INSIDE_SQRT);- auto convert0 = std::make_shared<ov::op::v0::Convert>(mvn, ov::element::f32);- auto result0 = std::make_shared<ov::op::v0::Result>(convert0);- auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {scale_factor});- auto mul = std::make_shared<ov::op::v1::Multiply>(input, scale_const);- auto convert1 = std::make_shared<ov::op::v0::Convert>(mul, ov::element::f32);- auto result1 = std::make_shared<ov::op::v0::Result>(convert1);+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 4, 4});+ auto mvn_axes = v0::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 3});+ auto mvn = std::make_shared<v6::MVN>(input, mvn_axes, true, epsilon, ov::op::MVNEpsMode::INSIDE_SQRT);+ auto convert0 = std::make_shared<v0::Convert>(mvn, ov::element::f32);+ auto result0 = std::make_shared<v0::Result>(convert0);+ auto scale_const = v0::Constant::create(ov::element::f16, ov::Shape{1}, {scale_factor});+ auto mul = std::make_shared<v1::Multiply>(input, scale_const);+ auto convert1 = std::make_shared<v0::Convert>(mul, ov::element::f32);+ auto result1 = std::make_shared<v0::Result>(convert1);model = std::make_shared<ov::Model>(ov::ResultVector{result0, result1}, ov::ParameterVector{input});manager.register_pass<ov::pass::activations_scaling::MulShareTransformation>();}{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 4, 4});- auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{1}, {scale_factor});- auto mul = std::make_shared<ov::op::v1::Multiply>(input, scale_const);- auto mvn_axes = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 3});+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{1, 3, 4, 4});+ auto scale_const = v0::Constant::create(ov::element::f16, ov::Shape{1}, {scale_factor});+ auto mul = std::make_shared<v1::Multiply>(input, scale_const);+ auto mvn_axes = v0::Constant::create(ov::element::i32, ov::Shape{3}, {0, 2, 3});epsilon *= scale_factor * scale_factor;- auto mvn = std::make_shared<ov::op::v6::MVN>(mul, mvn_axes, true, epsilon, ov::op::MVNEpsMode::INSIDE_SQRT);- auto convert0 = std::make_shared<ov::op::v0::Convert>(mvn, ov::element::f32);- auto result0 = std::make_shared<ov::op::v0::Result>(convert0);- auto convert1 = std::make_shared<ov::op::v0::Convert>(mul, ov::element::f32);- auto result1 = std::make_shared<ov::op::v0::Result>(convert1);+ auto mvn = std::make_shared<v6::MVN>(mul, mvn_axes, true, epsilon, ov::op::MVNEpsMode::INSIDE_SQRT);+ auto convert0 = std::make_shared<v0::Convert>(mvn, ov::element::f32);+ auto result0 = std::make_shared<v0::Result>(convert0);+ auto convert1 = std::make_shared<v0::Convert>(mul, ov::element::f32);+ auto result1 = std::make_shared<v0::Result>(convert1);model_ref = std::make_shared<ov::Model>(ov::ResultVector{result0, result1}, ov::ParameterVector{input});}diff --git a/src/common/transformations/tests/common_optimizations/augru_cell_fusion.cpp b/src/common/transformations/tests/common_optimizations/augru_cell_fusion.cppindex 13ef2852f34..d9b49acabe5 100644--- a/src/common/transformations/tests/common_optimizations/augru_cell_fusion.cpp+++ b/src/common/transformations/tests/common_optimizations/augru_cell_fusion.cpp@@ -32,6 +32,8 @@ using namespace ov;using namespace opset9;using namespace element;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;namespace {shared_ptr<Model> gen_model(size_t batch, size_t hidden_size, size_t input_size, bool use_dyn_shapes) {auto X = make_shared<Parameter>(f32, Shape{batch, input_size});@@ -187,19 +189,15 @@ TEST_F(TransformationTestsF, AUGRUFusionDiffParamShapes) {auto H = make_shared<Parameter>(f32, Shape{batch, hidden_size});auto WRzr = make_shared<Parameter>(f32, Shape{input_size + hidden_size, 2 * hidden_size});auto WRzr_transpose =- make_shared<ov::op::v1::Transpose>(WRzr,- ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0}));+ make_shared<v1::Transpose>(WRzr, v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0}));auto Bzr = make_shared<Parameter>(f32, Shape{2 * hidden_size});- auto Bzr_unsqz =- make_shared<ov::op::v0::Unsqueeze>(Bzr, ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {0}));+ auto Bzr_unsqz = make_shared<v0::Unsqueeze>(Bzr, v0::Constant::create(ov::element::i32, ov::Shape{}, {0}));auto WRh = make_shared<Parameter>(f32, Shape{input_size + hidden_size, hidden_size});auto WRh_transpose =- make_shared<ov::op::v1::Transpose>(WRh,- ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0}));+ make_shared<v1::Transpose>(WRh, v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 0}));auto Bh = make_shared<Parameter>(f32, Shape{hidden_size});- auto Bh_unsqz =- make_shared<ov::op::v0::Unsqueeze>(Bh, ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {0}));+ auto Bh_unsqz = make_shared<v0::Unsqueeze>(Bh, v0::Constant::create(ov::element::i32, ov::Shape{}, {0}));auto A = make_shared<Parameter>(f32, Shape{batch, 1});auto axis_0 = make_shared<Constant>(i64, Shape{}, 0);diff --git a/src/common/transformations/tests/common_optimizations/clamp_fusion.cpp b/src/common/transformations/tests/common_optimizations/clamp_fusion.cppindex 02933898f7a..62944fcec01 100644--- a/src/common/transformations/tests/common_optimizations/clamp_fusion.cpp+++ b/src/common/transformations/tests/common_optimizations/clamp_fusion.cpp@@ -24,6 +24,7 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;TEST_F(TransformationTestsF, ClampFusion) {{auto data = std::make_shared<opset5::Parameter>(element::f32, Shape{2, 2});@@ -37,7 +38,7 @@ TEST_F(TransformationTestsF, ClampFusion) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});auto clamp = std::make_shared<opset5::Clamp>(data, 0.1, 5);model_ref = std::make_shared<Model>(OutputVector{clamp}, ParameterVector{data});}@@ -56,7 +57,7 @@ TEST_F(TransformationTestsF, ClampFusionScalars) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});auto clamp = std::make_shared<opset5::Clamp>(data, 0.1, 5);model_ref = std::make_shared<Model>(OutputVector{clamp}, ParameterVector{data});}@@ -98,7 +99,7 @@ TEST_F(TransformationTestsF, ClampFusionMinMax) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});auto clamp = std::make_shared<opset5::Clamp>(data, 0.1, 5);model_ref = std::make_shared<Model>(OutputVector{clamp}, ParameterVector{data});}@@ -117,7 +118,7 @@ TEST_F(TransformationTestsF, ClampFusionMinMaxScalars) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});auto clamp = std::make_shared<opset5::Clamp>(data, 0.1, 5);model_ref = std::make_shared<Model>(OutputVector{clamp}, ParameterVector{data});}diff --git a/src/common/transformations/tests/common_optimizations/compress_float_constants_test.cpp b/src/common/transformations/tests/common_optimizations/compress_float_constants_test.cppindex 207fe9a2429..307b6607a29 100644--- a/src/common/transformations/tests/common_optimizations/compress_float_constants_test.cpp+++ b/src/common/transformations/tests/common_optimizations/compress_float_constants_test.cpp@@ -28,6 +28,8 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;TEST_F(TransformationTestsF, CompressConstants_f32) {{auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::Shape{1, 3, 12, 12});@@ -156,25 +158,25 @@ TEST_F(TransformationTestsF, CompressConstants_f32_If) {default_scales_node,axes_node,interpolate4_attr);- auto then_op_result = std::make_shared<ov::op::v0::Result>(resize);+ auto then_op_result = std::make_shared<v0::Result>(resize);auto body_then_function =std::make_shared<ov::Model>(ov::OutputVector{then_op_result}, ov::ParameterVector{input_then});// create else bodyauto input_else = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::Shape{1, 3, 12, 12});- auto else_op_result = std::make_shared<ov::op::v0::Result>(input_else);+ auto else_op_result = std::make_shared<v0::Result>(input_else);auto body_else_function =std::make_shared<ov::Model>(ov::OutputVector{else_op_result}, ov::ParameterVector{input_else});// create main graphauto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::Shape{1, 3, 12, 12});- auto cond = std::make_shared<ov::op::v0::Constant>(element::boolean, Shape{1}, true);+ auto cond = std::make_shared<v0::Constant>(element::boolean, Shape{1}, true);auto if_op = std::make_shared<ov::opset8::If>(cond);if_op->set_then_body(body_then_function);if_op->set_else_body(body_else_function);if_op->set_input(input, input_then, input_else);if_op->set_output(then_op_result, else_op_result);- auto if_result = std::make_shared<ov::op::v0::Result>(if_op);+ auto if_result = std::make_shared<v0::Result>(if_op);model = std::make_shared<ov::Model>(OutputVector{if_result}, ParameterVector{input});@@ -221,25 +223,25 @@ TEST_F(TransformationTestsF, CompressConstants_f32_If) {default_scales_node,axes_node,interpolate4_attr);- auto then_op_result = std::make_shared<ov::op::v0::Result>(resize);+ auto then_op_result = std::make_shared<v0::Result>(resize);auto body_then_function =std::make_shared<ov::Model>(ov::OutputVector{then_op_result}, ov::ParameterVector{input_then});// create else bodyauto input_else = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::Shape{1, 3, 12, 12});- auto else_op_result = std::make_shared<ov::op::v0::Result>(input_else);+ auto else_op_result = std::make_shared<v0::Result>(input_else);auto body_else_function =std::make_shared<ov::Model>(ov::OutputVector{else_op_result}, ov::ParameterVector{input_else});// create main graphauto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::Shape{1, 3, 12, 12});- auto cond = std::make_shared<ov::op::v0::Constant>(element::boolean, Shape{1}, true);+ auto cond = std::make_shared<v0::Constant>(element::boolean, Shape{1}, true);auto if_op = std::make_shared<ov::opset8::If>(cond);if_op->set_then_body(body_then_function);if_op->set_else_body(body_else_function);if_op->set_input(input, input_then, input_else);if_op->set_output(then_op_result, else_op_result);- auto if_result = std::make_shared<ov::op::v0::Result>(if_op);+ auto if_result = std::make_shared<v0::Result>(if_op);model_ref = std::make_shared<ov::Model>(OutputVector{if_result}, ParameterVector{input});}@@ -528,11 +530,10 @@ TEST_F(TransformationTestsF, CompressConstants_compress_to_f16_denormal_vals) {TEST_F(TransformationTestsF, KeepFWPrecisionForFP16Constants_test_1) {{auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::Shape{1, 3, 12, 12});- auto const_weights = ov::op::v0::Constant::create(- ov::element::f16,- ov::Shape{1, 3, 3, 3},- {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9});- auto convert_node = std::make_shared<ov::op::v0::Convert>(const_weights, element::f32);+ auto const_weights =+ v0::Constant::create(ov::element::f16, ov::Shape{1, 3, 3, 3}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5,+ 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9});+ auto convert_node = std::make_shared<v0::Convert>(const_weights, element::f32);auto conv = std::make_shared<ov::opset8::Convolution>(input,convert_node,@@ -553,7 +554,7 @@ TEST_F(TransformationTestsF, KeepFWPrecisionForFP16Constants_test_1) {ov::Shape{1, 3, 3, 3},{1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9});- auto convert_node = std::make_shared<ov::op::v0::Convert>(const_weights, element::f32);+ auto convert_node = std::make_shared<v0::Convert>(const_weights, element::f32);auto conv = std::make_shared<ov::opset8::Convolution>(input,convert_node,ov::Strides{1, 1},@@ -568,11 +569,10 @@ TEST_F(TransformationTestsF, KeepFWPrecisionForFP16Constants_test_1) {TEST_F(TransformationTestsF, KeepFWPrecisionForBF16Constants_test_1) {{auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::Shape{1, 3, 12, 12});- auto const_weights = ov::op::v0::Constant::create(- ov::element::bf16,- ov::Shape{1, 3, 3, 3},- {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9});- auto convert_node = std::make_shared<ov::op::v0::Convert>(const_weights, element::f32);+ auto const_weights =+ v0::Constant::create(ov::element::bf16, ov::Shape{1, 3, 3, 3}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5,+ 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9});+ auto convert_node = std::make_shared<v0::Convert>(const_weights, element::f32);auto conv = std::make_shared<ov::opset8::Convolution>(input,convert_node,@@ -593,7 +593,7 @@ TEST_F(TransformationTestsF, KeepFWPrecisionForBF16Constants_test_1) {ov::Shape{1, 3, 3, 3},{1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9});- auto convert_node = std::make_shared<ov::op::v0::Convert>(const_weights, element::f32);+ auto convert_node = std::make_shared<v0::Convert>(const_weights, element::f32);auto conv = std::make_shared<ov::opset8::Convolution>(input,convert_node,ov::Strides{1, 1},@@ -614,17 +614,17 @@ struct TestParams {auto build_model_DetectFakeQuantize = [](const TestParams&) -> std::shared_ptr<ov::Model> {auto input = std::make_shared<op::v0::Parameter>(element::f32, Shape{1, 2, 3});- auto input_low = ov::op::v0::Constant::create(element::u8, Shape{}, {1});- auto input_high = ov::op::v0::Constant::create(element::u8, Shape{}, {2});- auto output_low = ov::op::v0::Constant::create(element::u8, Shape{}, {1});- auto output_high = ov::op::v0::Constant::create(element::u8, Shape{}, {2});- auto fq = std::make_shared<ov::op::v0::FakeQuantize>(input, input_low, input_high, output_low, output_high, 1);+ auto input_low = v0::Constant::create(element::u8, Shape{}, {1});+ auto input_high = v0::Constant::create(element::u8, Shape{}, {2});+ auto output_low = v0::Constant::create(element::u8, Shape{}, {1});+ auto output_high = v0::Constant::create(element::u8, Shape{}, {2});+ auto fq = std::make_shared<v0::FakeQuantize>(input, input_low, input_high, output_low, output_high, 1);return std::make_shared<ov::Model>(ov::OutputVector{fq}, ov::ParameterVector{input});};auto build_model_DetectFakeConvert = [](const TestParams&) -> std::shared_ptr<ov::Model> {auto input = std::make_shared<op::v0::Parameter>(element::f32, Shape{1, 2, 3});- auto scale = ov::op::v0::Constant::create(element::f32, Shape{}, {1});+ auto scale = v0::Constant::create(element::f32, Shape{}, {1});auto convert = std::make_shared<ov::op::v13::FakeConvert>(input, scale);return std::make_shared<ov::Model>(ov::OutputVector{convert}, ov::ParameterVector{input});};@@ -632,20 +632,20 @@ auto build_model_DetectFakeConvert = [](const TestParams&) -> std::shared_ptr<ovauto build_model_DetectCompressedWeights = [](const TestParams& params) -> std::shared_ptr<ov::Model> {auto input = std::make_shared<op::v0::Parameter>(element::u8, Shape{2, 1});- auto weights = ov::op::v0::Constant::create(params.element_type, ov::Shape{1, 2}, {2});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, element::u8);+ auto weights = v0::Constant::create(params.element_type, ov::Shape{1, 2}, {2});+ auto convert = std::make_shared<v0::Convert>(weights, element::u8);std::shared_ptr<Node> tail_node = convert;if (params.has_subtract) {- auto zero_point_const = ov::op::v0::Constant::create(element::u8, ov::Shape{1, 2}, {2});- auto zero_point = std::make_shared<ov::op::v0::Convert>(weights, element::u8);- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point);+ auto zero_point_const = v0::Constant::create(element::u8, ov::Shape{1, 2}, {2});+ auto zero_point = std::make_shared<v0::Convert>(weights, element::u8);+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point);tail_node = subtract;}- auto multiply_const = ov::op::v0::Constant::create(element::u8, ov::Shape{1, 2}, {2});- auto multiply = std::make_shared<ov::op::v1::Multiply>(tail_node, multiply_const);+ auto multiply_const = v0::Constant::create(element::u8, ov::Shape{1, 2}, {2});+ auto multiply = std::make_shared<v1::Multiply>(tail_node, multiply_const);- auto out_multiply = std::make_shared<ov::op::v1::Multiply>(input, multiply);+ auto out_multiply = std::make_shared<v1::Multiply>(input, multiply);return std::make_shared<ov::Model>(ov::OutputVector{out_multiply}, ov::ParameterVector{input});};diff --git a/src/common/transformations/tests/common_optimizations/concat_reduce_fusion.cpp b/src/common/transformations/tests/common_optimizations/concat_reduce_fusion.cppindex 71ac3ddf642..3593de063c3 100644--- a/src/common/transformations/tests/common_optimizations/concat_reduce_fusion.cpp+++ b/src/common/transformations/tests/common_optimizations/concat_reduce_fusion.cpp@@ -24,33 +24,32 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;TEST_F(TransformationTestsF, ConcatReduceMaxFusionDynamicShape) {PartialShape shape{-1, -1, -1, -1};std::int64_t reduce_axis = 2;{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));- auto concat = std::make_shared<ov::op::v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);+ auto concat = std::make_shared<v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);auto reduce_max =- std::make_shared<ov::op::v1::ReduceMax>(concat,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v1::ReduceMax>(concat, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));model = std::make_shared<Model>(OutputVector{reduce_max}, ParameterVector{left_input, right_input});manager.register_pass<ov::pass::ConcatReduceFusion>();}{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto maximum = std::make_shared<ov::op::v1::Maximum>(left_input, right_input);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto maximum = std::make_shared<v1::Maximum>(left_input, right_input);model_ref = std::make_shared<Model>(OutputVector{maximum}, ParameterVector{left_input, right_input});}}@@ -59,37 +58,31 @@ TEST_F(TransformationTestsF, ConcatReduceMaxFusionKeepDimsDynamicShape) {PartialShape shape{-1, -1, -1, -1};std::int64_t reduce_axis = 2;{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));- auto concat = std::make_shared<ov::op::v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);+ auto concat = std::make_shared<v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);auto reduce_max =- std::make_shared<ov::op::v1::ReduceMax>(concat,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}),- true);+ std::make_shared<v1::ReduceMax>(concat, v0::Constant::create(element::i64, Shape{}, {reduce_axis}), true);model = std::make_shared<Model>(OutputVector{reduce_max}, ParameterVector{left_input, right_input});manager.register_pass<ov::pass::ConcatReduceFusion>();}{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));- auto maximum = std::make_shared<ov::op::v1::Maximum>(left_unsqueeze, right_unsqueeze);+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ auto maximum = std::make_shared<v1::Maximum>(left_unsqueeze, right_unsqueeze);model_ref = std::make_shared<Model>(OutputVector{maximum}, ParameterVector{left_input, right_input});}}@@ -98,29 +91,26 @@ TEST_F(TransformationTestsF, ConcatReduceMaxFusionDynamicRank) {PartialShape shape = PartialShape::dynamic();std::int64_t reduce_axis = 3;{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));- auto concat = std::make_shared<ov::op::v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);+ auto concat = std::make_shared<v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);auto reduce_max =- std::make_shared<ov::op::v1::ReduceMax>(concat,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v1::ReduceMax>(concat, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));model = std::make_shared<Model>(OutputVector{reduce_max}, ParameterVector{left_input, right_input});manager.register_pass<ov::pass::ConcatReduceFusion>();}{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto maximum = std::make_shared<ov::op::v1::Maximum>(left_input, right_input);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto maximum = std::make_shared<v1::Maximum>(left_input, right_input);model_ref = std::make_shared<Model>(OutputVector{maximum}, ParameterVector{left_input, right_input});}}@@ -129,29 +119,26 @@ TEST_F(TransformationTestsF, ConcatReduceMinFusionDynamicShape) {PartialShape shape{-1, -1, -1, -1};std::int64_t reduce_axis = 2;{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));- auto concat = std::make_shared<ov::op::v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);+ auto concat = std::make_shared<v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);auto reduce_max =- std::make_shared<ov::op::v1::ReduceMin>(concat,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v1::ReduceMin>(concat, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));model = std::make_shared<Model>(OutputVector{reduce_max}, ParameterVector{left_input, right_input});manager.register_pass<ov::pass::ConcatReduceFusion>();}{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto maximum = std::make_shared<ov::op::v1::Minimum>(left_input, right_input);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto maximum = std::make_shared<v1::Minimum>(left_input, right_input);model_ref = std::make_shared<Model>(OutputVector{maximum}, ParameterVector{left_input, right_input});}}@@ -160,29 +147,26 @@ TEST_F(TransformationTestsF, ConcatReduceMinFusionDynamicRank) {PartialShape shape = PartialShape::dynamic();std::int64_t reduce_axis = 3;{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));- auto concat = std::make_shared<ov::op::v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);+ auto concat = std::make_shared<v0::Concat>(NodeVector{left_unsqueeze, right_unsqueeze}, reduce_axis);auto reduce_max =- std::make_shared<ov::op::v1::ReduceMin>(concat,- ov::op::v0::Constant::create(element::i64, Shape{}, {reduce_axis}));+ std::make_shared<v1::ReduceMin>(concat, v0::Constant::create(element::i64, Shape{}, {reduce_axis}));model = std::make_shared<Model>(OutputVector{reduce_max}, ParameterVector{left_input, right_input});manager.register_pass<ov::pass::ConcatReduceFusion>();}{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto maximum = std::make_shared<ov::op::v1::Minimum>(left_input, right_input);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto maximum = std::make_shared<v1::Minimum>(left_input, right_input);model_ref = std::make_shared<Model>(OutputVector{maximum}, ParameterVector{left_input, right_input});}}@@ -190,43 +174,36 @@ TEST_F(TransformationTestsF, ConcatReduceMinFusionDynamicRank) {TEST_F(TransformationTestsF, PullSqueezeThroughEltwiseStaticShape) {PartialShape shape{224, 224, 1, 1};{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {0}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {0}));- auto add = std::make_shared<ov::op::v1::Add>(left_unsqueeze, right_unsqueeze);+ auto add = std::make_shared<v1::Add>(left_unsqueeze, right_unsqueeze);- auto squeeze =- std::make_shared<ov::op::v0::Squeeze>(add, ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ auto squeeze = std::make_shared<v0::Squeeze>(add, v0::Constant::create(element::i64, Shape{}, {0}));model = std::make_shared<Model>(OutputVector{squeeze}, ParameterVector{left_input, right_input});manager.register_pass<ov::pass::PullSqueezeThroughEltwise>();}{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {0}));auto left_squeeze =- std::make_shared<ov::op::v0::Squeeze>(left_unsqueeze,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Squeeze>(left_unsqueeze, v0::Constant::create(element::i64, Shape{}, {0}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {0}));auto right_squeeze =- std::make_shared<ov::op::v0::Squeeze>(right_unsqueeze,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Squeeze>(right_unsqueeze, v0::Constant::create(element::i64, Shape{}, {0}));- auto add = std::make_shared<ov::op::v1::Add>(left_squeeze, right_squeeze);+ auto add = std::make_shared<v1::Add>(left_squeeze, right_squeeze);model_ref = std::make_shared<Model>(OutputVector{add}, ParameterVector{left_input, right_input});}@@ -235,29 +212,26 @@ TEST_F(TransformationTestsF, PullSqueezeThroughEltwiseStaticShape) {TEST_F(TransformationTestsF, PullSqueezeThroughEltwiseSqueezeEliminationStaticShape) {PartialShape shape{224, 224, 1, 1};{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {0}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {0}));- auto add = std::make_shared<ov::op::v1::Add>(left_unsqueeze, right_unsqueeze);+ auto add = std::make_shared<v1::Add>(left_unsqueeze, right_unsqueeze);- auto squeeze =- std::make_shared<ov::op::v0::Squeeze>(add, ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ auto squeeze = std::make_shared<v0::Squeeze>(add, v0::Constant::create(element::i64, Shape{}, {0}));model = std::make_shared<Model>(OutputVector{squeeze}, ParameterVector{left_input, right_input});manager.register_pass<ov::pass::ConcatReduceFusion>();}{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);- auto add = std::make_shared<ov::op::v1::Add>(left_input, right_input);+ auto add = std::make_shared<v1::Add>(left_input, right_input);model_ref = std::make_shared<Model>(OutputVector{add}, ParameterVector{left_input, right_input});}@@ -266,29 +240,26 @@ TEST_F(TransformationTestsF, PullSqueezeThroughEltwiseSqueezeEliminationStaticShTEST_F(TransformationTestsF, PullSqueezeThroughEltwiseSqueezeEliminationDynamicShape) {PartialShape shape{-1, -1, -1, -1};{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {0}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {0}));- auto add = std::make_shared<ov::op::v1::Add>(left_unsqueeze, right_unsqueeze);+ auto add = std::make_shared<v1::Add>(left_unsqueeze, right_unsqueeze);- auto squeeze =- std::make_shared<ov::op::v0::Squeeze>(add, ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ auto squeeze = std::make_shared<v0::Squeeze>(add, v0::Constant::create(element::i64, Shape{}, {0}));model = std::make_shared<Model>(OutputVector{squeeze}, ParameterVector{left_input, right_input});manager.register_pass<ov::pass::ConcatReduceFusion>();}{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);- auto add = std::make_shared<ov::op::v1::Add>(left_input, right_input);+ auto add = std::make_shared<v1::Add>(left_input, right_input);model_ref = std::make_shared<Model>(OutputVector{add}, ParameterVector{left_input, right_input});}@@ -297,29 +268,26 @@ TEST_F(TransformationTestsF, PullSqueezeThroughEltwiseSqueezeEliminationDynamicSTEST_F(TransformationTestsF, PullSqueezeThroughEltwiseSqueezeEliminationDynamicRank) {PartialShape shape = PartialShape::dynamic();{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);auto left_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(left_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(left_input, v0::Constant::create(element::i64, Shape{}, {0}));auto right_unsqueeze =- std::make_shared<ov::op::v0::Unsqueeze>(right_input,- ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ std::make_shared<v0::Unsqueeze>(right_input, v0::Constant::create(element::i64, Shape{}, {0}));- auto add = std::make_shared<ov::op::v1::Add>(left_unsqueeze, right_unsqueeze);+ auto add = std::make_shared<v1::Add>(left_unsqueeze, right_unsqueeze);- auto squeeze =- std::make_shared<ov::op::v0::Squeeze>(add, ov::op::v0::Constant::create(element::i64, Shape{}, {0}));+ auto squeeze = std::make_shared<v0::Squeeze>(add, v0::Constant::create(element::i64, Shape{}, {0}));model = std::make_shared<Model>(OutputVector{squeeze}, ParameterVector{left_input, right_input});manager.register_pass<ov::pass::ConcatReduceFusion>();}{- auto left_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);- auto right_input = std::make_shared<ov::op::v0::Parameter>(element::f32, shape);+ auto left_input = std::make_shared<v0::Parameter>(element::f32, shape);+ auto right_input = std::make_shared<v0::Parameter>(element::f32, shape);- auto add = std::make_shared<ov::op::v1::Add>(left_input, right_input);+ auto add = std::make_shared<v1::Add>(left_input, right_input);model_ref = std::make_shared<Model>(OutputVector{add}, ParameterVector{left_input, right_input});}diff --git a/src/common/transformations/tests/common_optimizations/concat_to_broadcast_test.cpp b/src/common/transformations/tests/common_optimizations/concat_to_broadcast_test.cppindex 2c80dfd708a..a2531086cb1 100644--- a/src/common/transformations/tests/common_optimizations/concat_to_broadcast_test.cpp+++ b/src/common/transformations/tests/common_optimizations/concat_to_broadcast_test.cpp@@ -15,6 +15,7 @@using namespace testing;+namespace v0 = ov::op::v0;enum class ExpectedType {Broadcast,Tile,@@ -48,11 +49,11 @@ INSTANTIATE_TEST_SUITE_P(ConcatToBroadcastParams({-1, -1, -1, -1}, 2604, 0, ExpectedType::Concat)));TEST_P(ConcatToBroadcastTest, TestTransfromationExecuted) {- auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, data_shape);+ auto param = std::make_shared<v0::Parameter>(ov::element::i32, data_shape);std::vector<ov::Output<ov::Node>> concat_inputs(concat_num_inputs, param->output(0));- auto concat = std::make_shared<ov::op::v0::Concat>(concat_inputs, concat_axis);- auto result = std::make_shared<ov::op::v0::Result>(concat->output(0));+ auto concat = std::make_shared<v0::Concat>(concat_inputs, concat_axis);+ auto result = std::make_shared<v0::Result>(concat->output(0));auto model = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{param});@@ -70,9 +71,9 @@ TEST_P(ConcatToBroadcastTest, TestTransfromationExecuted) {std::cout << op << std::endl;if (ov::as_type_ptr<ov::op::v3::Broadcast>(op)) {++broadcast_count;- } else if (ov::as_type_ptr<ov::op::v0::Tile>(op)) {+ } else if (ov::as_type_ptr<v0::Tile>(op)) {++tile_count;- } else if (ov::as_type_ptr<ov::op::v0::Concat>(op)) {+ } else if (ov::as_type_ptr<v0::Concat>(op)) {++concat_count;}}diff --git a/src/common/transformations/tests/common_optimizations/constants_reduce.cpp b/src/common/transformations/tests/common_optimizations/constants_reduce.cppindex 675d132c567..711a0a1dec9 100644--- a/src/common/transformations/tests/common_optimizations/constants_reduce.cpp+++ b/src/common/transformations/tests/common_optimizations/constants_reduce.cpp@@ -19,6 +19,7 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;TEST(TransformationTests, ConstantsReduce) {auto param = std::make_shared<opset8::Parameter>(element::f32, Shape{1, 4});@@ -28,7 +29,7 @@ TEST(TransformationTests, ConstantsReduce) {auto add_1 = std::make_shared<opset8::Add>(param, add_constant_1);auto add_2 = std::make_shared<opset8::Add>(add_1, add_constant_2);- auto result = std::make_shared<ov::op::v0::Result>(add_2);+ auto result = std::make_shared<v0::Result>(add_2);auto f = std::make_shared<Model>(ResultVector{result}, ParameterVector{param});pass::Manager pass_manager;@@ -56,7 +57,7 @@ TEST(TransformationTests, ConstantsReduceChain) {auto add_4 = std::make_shared<opset8::Add>(add_3, add_constant_4);auto add_5 = std::make_shared<opset8::Add>(add_4, add_constant_5);- auto result = std::make_shared<ov::op::v0::Result>(add_5);+ auto result = std::make_shared<v0::Result>(add_5);auto f = std::make_shared<Model>(ResultVector{result}, ParameterVector{param});pass::Manager pass_manager;@@ -83,7 +84,7 @@ TEST(TransformationTests, ConstantsReduceChain2) {auto add_4 = std::make_shared<opset8::Add>(add_3, add_constant_4);auto add_5 = std::make_shared<opset8::Add>(add_4, add_constant_5);- auto result = std::make_shared<ov::op::v0::Result>(add_5);+ auto result = std::make_shared<v0::Result>(add_5);auto f = std::make_shared<Model>(ResultVector{result}, ParameterVector{param});pass::Manager pass_manager;@@ -103,7 +104,7 @@ TEST(TransformationTests, ConstantsReduceNeg) {auto add_1 = std::make_shared<opset8::Add>(param, add_constant_1);auto add_2 = std::make_shared<opset8::Add>(add_1, add_constant_2);- auto result = std::make_shared<ov::op::v0::Result>(add_2);+ auto result = std::make_shared<v0::Result>(add_2);auto f = std::make_shared<Model>(ResultVector{result}, ParameterVector{param});pass::Manager pass_manager;diff --git a/src/common/transformations/tests/common_optimizations/convert_divide.cpp b/src/common/transformations/tests/common_optimizations/convert_divide.cppindex 5f47573c0bf..61fd48bb42e 100644--- a/src/common/transformations/tests/common_optimizations/convert_divide.cpp+++ b/src/common/transformations/tests/common_optimizations/convert_divide.cpp@@ -29,6 +29,7 @@using namespace ov;using namespace testing;+namespace op_util = ov::op::util;TEST_F(TransformationTestsF, ConvertDivide) {{auto data = std::make_shared<opset1::Parameter>(element::f32, Shape{3, 1, 2});@@ -161,7 +162,7 @@ TEST_F(TransformationTestsF, ConvertDivideWithConstantNegative) {TEST_F(TransformationTestsF, ConvertDivideFP16ShapeOfSubgraphNegative) {{auto data = std::make_shared<opset1::Parameter>(element::f16, Shape{1, 3, 22, 22});- auto gather = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(data, {2, 3});+ auto gather = op_util::node_to_get_shape_value_of_indices_from_shape_source(data, {2, 3});auto convert = std::make_shared<opset1::Convert>(gather, element::f16);auto divide_constant = opset1::Constant::create(element::f16, Shape{1}, {0.5});auto divide = std::make_shared<opset1::Divide>(convert, divide_constant);@@ -238,7 +239,7 @@ TEST_F(TransformationTestsF, ConvertDivideFP16ShapeOfSubgraphNegative2) {// special visited set for precision sensitive nodes which needs to be tested as well. So in the worst case// we will traverse each node twice.auto data = std::make_shared<opset1::Parameter>(element::f16, Shape{1, 3, 22, 22});- auto gather = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(data, {2, 3});+ auto gather = op_util::node_to_get_shape_value_of_indices_from_shape_source(data, {2, 3});auto convert = std::make_shared<opset1::Convert>(gather, element::f16);auto divide_constant = opset1::Constant::create(element::f16, Shape{1}, {0.5});auto divide = std::make_shared<opset1::Divide>(convert, divide_constant);@@ -268,7 +269,7 @@ TEST_F(TransformationTestsF, ConvertDivideFP16ShapeOfSubgraphNegative2) {TEST_F(TransformationTestsF, ConvertDivideFP32ShapeOfSubgraphNegative) {{auto data = std::make_shared<opset1::Parameter>(element::f32, Shape{1, 3, 22, 22});- auto gather = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(data, {2, 3});+ auto gather = op_util::node_to_get_shape_value_of_indices_from_shape_source(data, {2, 3});auto convert = std::make_shared<opset1::Convert>(gather, element::f32);auto divide_constant = opset1::Constant::create(element::f32, Shape{1}, {0.5});auto divide = std::make_shared<opset1::Divide>(convert, divide_constant);diff --git a/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp b/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cppindex 607e7a1ce01..964151c7241 100644--- a/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp+++ b/src/common/transformations/tests/common_optimizations/convert_pagedattn_inputs.cpp@@ -14,7 +14,6 @@using namespace ov::test;using namespace ov;-using namespace ov::op;using namespace ov::gen_pattern;using ConvertPagedAttnInputsParams = std::tuple<std::vector<ov::element::Type>, // cache_precisionstd::vector<size_t>, // cache_group_size@@ -24,6 +23,8 @@ using ConvertPagedAttnInputsParams = std::tuple<std::vector<ov::element::Type>,bool, // accuracy_modebool // is_ir_kv_cache_f16>;++namespace v0 = ov::op::v0;namespace {class ConvertPagedAttnInputsTest : public TransformationTestsF,public testing::WithParamInterface<ConvertPagedAttnInputsParams> {diff --git a/src/common/transformations/tests/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp b/src/common/transformations/tests/common_optimizations/convert_u4_weights_zero_point_to_scalar.cppindex 532ab74ad94..739890e859d 100644--- a/src/common/transformations/tests/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp+++ b/src/common/transformations/tests/common_optimizations/convert_u4_weights_zero_point_to_scalar.cpp@@ -17,29 +17,32 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;TEST_F(TransformationTestsF, ConvertU4WeightsFloatZeroPointToScalar) {auto weights_precision = ov::element::u4;auto decompression_precision = ov::element::f32;ov::Shape weights_shape{32, 128, 64};ov::Shape decompression_shape{32, 1, 64};{- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {8.1f});- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(decompression_precision, decompression_shape, {8.1f});+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});manager.register_pass<ov::pass::ConvertU4WeightsZeroPointToScalar>();}{ov::Shape scalar_shape{};- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(decompression_precision, scalar_shape, {8.1f});- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(decompression_precision, scalar_shape, {8.1f});+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model_ref = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});}comparator.enable(FunctionsComparator::ACCURACY);@@ -52,25 +55,25 @@ TEST_F(TransformationTestsF, ConvertU4WeightsU4ZeroPointToScalar) {ov::Shape weights_shape{32, 128, 64};ov::Shape decompression_shape{32, 1, 64};{- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8});- auto zero_point_convert = std::make_shared<ov::op::v0::Convert>(zero_point, decompression_precision);- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point_convert);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(weights_precision, decompression_shape, {8});+ auto zero_point_convert = std::make_shared<v0::Convert>(zero_point, decompression_precision);+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point_convert);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});manager.register_pass<ov::pass::ConvertU4WeightsZeroPointToScalar>();}{ov::Shape scalar_shape{};- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(weights_precision, scalar_shape, {8});- auto zero_point_convert = std::make_shared<ov::op::v0::Convert>(zero_point, decompression_precision);- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point_convert);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(weights_precision, scalar_shape, {8});+ auto zero_point_convert = std::make_shared<v0::Convert>(zero_point, decompression_precision);+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point_convert);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model_ref = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});}comparator.enable(FunctionsComparator::ACCURACY);@@ -83,23 +86,23 @@ TEST_F(TransformationTestsF, ConvertU4WeightsFloatZeroPointToScalarWeightsWithBiov::Shape weights_shape{32, 128, 64};ov::Shape decompression_shape{64};{- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {8});- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(decompression_precision, decompression_shape, {8});+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});manager.register_pass<ov::pass::ConvertU4WeightsZeroPointToScalar>();}{ov::Shape scalar_shape{};- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(decompression_precision, scalar_shape, {8});- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(decompression_precision, scalar_shape, {8});+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model_ref = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});}comparator.enable(FunctionsComparator::ACCURACY);@@ -111,15 +114,15 @@ TEST_F(TransformationTestsF, FuseU4WeightsAndZeroPointNotScalarLikeZP) {auto decompression_precision = ov::element::f32;ov::Shape weights_shape{32, 128, 64};ov::Shape decompression_shape{32, 1, 64};- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);std::vector<int> zero_point_values(ov::shape_size(decompression_shape), 8);zero_point_values.back() = 6;- auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, zero_point_values);- auto zero_point_convert = std::make_shared<ov::op::v0::Convert>(zero_point, decompression_precision);- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point_convert);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto zero_point = v0::Constant::create(weights_precision, decompression_shape, zero_point_values);+ auto zero_point_convert = std::make_shared<v0::Convert>(zero_point, decompression_precision);+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point_convert);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});manager.register_pass<ov::pass::ConvertU4WeightsZeroPointToScalar>();}@@ -129,13 +132,13 @@ TEST_F(TransformationTestsF, FuseU4WeightsAndZeroPointNotU4Weights) {auto decompression_precision = ov::element::f32;ov::Shape weights_shape{32, 128, 64};ov::Shape decompression_shape{32, 1, 64};- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8});- auto zero_point_convert = std::make_shared<ov::op::v0::Convert>(zero_point, decompression_precision);- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point_convert);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(weights_precision, decompression_shape, {8});+ auto zero_point_convert = std::make_shared<v0::Convert>(zero_point, decompression_precision);+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point_convert);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model = std::make_shared<Model>(OutputVector{multiply}, ParameterVector{});manager.register_pass<ov::pass::ConvertU4WeightsZeroPointToScalar>();}@@ -145,13 +148,13 @@ TEST_F(TransformationTestsF, ConvertU4WeightsFloatZeroPointToScalarAdditionalZPCauto decompression_precision = ov::element::f32;ov::Shape weights_shape{32, 128, 64};ov::Shape decompression_shape{32, 1, 64};- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {8});- auto zero_point_consumer = std::make_shared<ov::op::v3::ShapeOf>(zero_point);- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(decompression_precision, decompression_shape, {8});+ auto zero_point_consumer = std::make_shared<v3::ShapeOf>(zero_point);+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model = std::make_shared<Model>(OutputVector{multiply, zero_point_consumer}, ParameterVector{});manager.register_pass<ov::pass::ConvertU4WeightsZeroPointToScalar>();}@@ -161,14 +164,14 @@ TEST_F(TransformationTestsF, ConvertU4WeightsU4ZeroPointToScalarAdditionalZPConsauto decompression_precision = ov::element::f32;ov::Shape weights_shape{32, 128, 64};ov::Shape decompression_shape{32, 1, 64};- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8});- auto zero_point_consumer = std::make_shared<ov::op::v3::ShapeOf>(zero_point);- auto zero_point_convert = std::make_shared<ov::op::v0::Convert>(zero_point, decompression_precision);- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point_convert);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(weights_precision, decompression_shape, {8});+ auto zero_point_consumer = std::make_shared<v3::ShapeOf>(zero_point);+ auto zero_point_convert = std::make_shared<v0::Convert>(zero_point, decompression_precision);+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point_convert);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model = std::make_shared<Model>(OutputVector{multiply, zero_point_consumer}, ParameterVector{});manager.register_pass<ov::pass::ConvertU4WeightsZeroPointToScalar>();}@@ -178,14 +181,14 @@ TEST_F(TransformationTestsF, ConvertU4WeightsU4ZeroPointToScalarAdditionalZPConvauto decompression_precision = ov::element::f32;ov::Shape weights_shape{32, 128, 64};ov::Shape decompression_shape{32, 1, 64};- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8});- auto zero_point_convert = std::make_shared<ov::op::v0::Convert>(zero_point, decompression_precision);- auto zero_point_convert_consumer = std::make_shared<ov::op::v3::ShapeOf>(zero_point_convert);- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point_convert);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(weights_precision, decompression_shape, {8});+ auto zero_point_convert = std::make_shared<v0::Convert>(zero_point, decompression_precision);+ auto zero_point_convert_consumer = std::make_shared<v3::ShapeOf>(zero_point_convert);+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point_convert);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model = std::make_shared<Model>(OutputVector{multiply, zero_point_convert_consumer}, ParameterVector{});manager.register_pass<ov::pass::ConvertU4WeightsZeroPointToScalar>();}@@ -195,14 +198,14 @@ TEST_F(TransformationTestsF, ConvertU4WeightsU4ZeroPointToScalarZPWithBiggerRankauto decompression_precision = ov::element::f32;ov::Shape weights_shape{32, 128, 64};ov::Shape decompression_shape{1, 32, 1, 64};- auto weights = ov::op::v0::Constant::create(weights_precision, weights_shape, {4});- auto convert = std::make_shared<ov::op::v0::Convert>(weights, decompression_precision);- auto zero_point = ov::op::v0::Constant::create(weights_precision, decompression_shape, {8});- auto zero_point_convert = std::make_shared<ov::op::v0::Convert>(zero_point, decompression_precision);- auto zero_point_convert_consumer = std::make_shared<ov::op::v3::ShapeOf>(zero_point_convert);- auto subtract = std::make_shared<ov::op::v1::Subtract>(convert, zero_point_convert);- auto scale = ov::op::v0::Constant::create(decompression_precision, decompression_shape, {3.f});- auto multiply = std::make_shared<ov::op::v1::Multiply>(subtract, scale);+ auto weights = v0::Constant::create(weights_precision, weights_shape, {4});+ auto convert = std::make_shared<v0::Convert>(weights, decompression_precision);+ auto zero_point = v0::Constant::create(weights_precision, decompression_shape, {8});+ auto zero_point_convert = std::make_shared<v0::Convert>(zero_point, decompression_precision);+ auto zero_point_convert_consumer = std::make_shared<v3::ShapeOf>(zero_point_convert);+ auto subtract = std::make_shared<v1::Subtract>(convert, zero_point_convert);+ auto scale = v0::Constant::create(decompression_precision, decompression_shape, {3.f});+ auto multiply = std::make_shared<v1::Multiply>(subtract, scale);model = std::make_shared<Model>(OutputVector{multiply, zero_point_convert_consumer}, ParameterVector{});manager.register_pass<ov::pass::ConvertU4WeightsZeroPointToScalar>();}diff --git a/src/common/transformations/tests/common_optimizations/eliminate_loop_inputs_outputs_test.cpp b/src/common/transformations/tests/common_optimizations/eliminate_loop_inputs_outputs_test.cppindex 39d63c3bae9..2fa45418365 100644--- a/src/common/transformations/tests/common_optimizations/eliminate_loop_inputs_outputs_test.cpp+++ b/src/common/transformations/tests/common_optimizations/eliminate_loop_inputs_outputs_test.cpp@@ -24,8 +24,10 @@using namespace testing;using namespace ov;-using namespace ov::op;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v5 = ov::op::v5;TEST_F(TransformationTestsF, LoopInputsInvariantAndOutput) {{auto main_param0 = std::make_shared<v0::Parameter>(element::i32, Shape{1});diff --git a/src/common/transformations/tests/common_optimizations/eliminate_unsqueeze_gather.cpp b/src/common/transformations/tests/common_optimizations/eliminate_unsqueeze_gather.cppindex 7f70824b909..16ecd278195 100644--- a/src/common/transformations/tests/common_optimizations/eliminate_unsqueeze_gather.cpp+++ b/src/common/transformations/tests/common_optimizations/eliminate_unsqueeze_gather.cpp@@ -18,8 +18,10 @@#include "transformations/common_optimizations/simplify_shape_of_sub_graph.hpp"using namespace ov;-using namespace ov::op;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;namespace {using TensorType = ov::element::Type_t;diff --git a/src/common/transformations/tests/common_optimizations/fuse_moe_test.cpp b/src/common/transformations/tests/common_optimizations/fuse_moe_test.cppindex 0d953d5390e..343ceaf79de 100644--- a/src/common/transformations/tests/common_optimizations/fuse_moe_test.cpp+++ b/src/common/transformations/tests/common_optimizations/fuse_moe_test.cpp@@ -24,6 +24,10 @@ using namespace testing;using namespace ov::gen_pattern;using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v12 = ov::op::v12;std::shared_ptr<ov::Model> BuildMOE(int expert_num, int topk) {ov::element::Type inType = ov::element::f32;// param1: [batch*seq, 2048]@@ -200,7 +204,7 @@ static std::shared_ptr<ov::Model> BuildFusedMOE(const int expert_num, const intauto weight_const = makeConst(elem_type, single_expert_shape, {0});expert_weights.push_back(weight_const);}- auto concat = std::make_shared<ov::op::v0::Concat>(expert_weights, 0);+ auto concat = std::make_shared<v0::Concat>(expert_weights, 0);concat->get_rt_info()["postponed_constant"] = true;return concat;};@@ -208,21 +212,21 @@ static std::shared_ptr<ov::Model> BuildFusedMOE(const int expert_num, const intauto fused_gate_weights_f16 =build_fused_weight(ov::element::f16,ov::Shape{1, static_cast<size_t>(intermediate_size), static_cast<size_t>(hidden_size)});- auto fused_gate_weights_convert = std::make_shared<ov::op::v0::Convert>(fused_gate_weights_f16, ov::element::f32);+ auto fused_gate_weights_convert = std::make_shared<v0::Convert>(fused_gate_weights_f16, ov::element::f32);ov::mark_as_decompression(fused_gate_weights_convert);auto fused_gate_weights = fused_gate_weights_convert;auto fused_up_weights_f16 =build_fused_weight(ov::element::f16,ov::Shape{1, static_cast<size_t>(intermediate_size), static_cast<size_t>(hidden_size)});- auto fused_up_weights_convert = std::make_shared<ov::op::v0::Convert>(fused_up_weights_f16, ov::element::f32);+ auto fused_up_weights_convert = std::make_shared<v0::Convert>(fused_up_weights_f16, ov::element::f32);ov::mark_as_decompression(fused_up_weights_convert);auto fused_up_weights = fused_up_weights_convert;auto fused_down_weights_f16 =build_fused_weight(ov::element::f16,ov::Shape{1, static_cast<size_t>(hidden_size), static_cast<size_t>(intermediate_size)});- auto fused_down_weights_convert = std::make_shared<ov::op::v0::Convert>(fused_down_weights_f16, ov::element::f32);+ auto fused_down_weights_convert = std::make_shared<v0::Convert>(fused_down_weights_f16, ov::element::f32);ov::mark_as_decompression(fused_down_weights_convert);auto fused_down_weights = fused_down_weights_convert;@@ -274,25 +278,21 @@ static std::shared_ptr<ov::Model> BuildFusedMOE(const int expert_num, const intauto normalized_topk =makeOP<opset1::Divide>({topk_values, sum_reduce}, {{"auto_broadcast", "numpy"}, {"m_pythondiv", true}});auto zeros_scalar = makeConst(ov::element::f32, ov::Shape{}, std::vector<float>{0.0f});- auto scatter_shape =- std::make_shared<ov::op::v0::Concat>(ov::OutputVector{batch_dim_unsqueeze, num_experts_unsqueeze}, 0);- auto zeros_tensor = std::make_shared<ov::op::v3::Broadcast>(zeros_scalar, scatter_shape);- auto scatter = std::make_shared<ov::op::v12::ScatterElementsUpdate>(zeros_tensor,- topk_TopK->output(1),- normalized_topk,- axis1_vector);- auto router_transpose = std::make_shared<ov::op::v1::Transpose>(scatter, transpose_axes);+ auto scatter_shape = std::make_shared<v0::Concat>(ov::OutputVector{batch_dim_unsqueeze, num_experts_unsqueeze}, 0);+ auto zeros_tensor = std::make_shared<v3::Broadcast>(zeros_scalar, scatter_shape);+ auto scatter =+ std::make_shared<v12::ScatterElementsUpdate>(zeros_tensor, topk_TopK->output(1), normalized_topk, axis1_vector);+ auto router_transpose = std::make_shared<v1::Transpose>(scatter, transpose_axes);auto router_shape =- std::make_shared<ov::op::v0::Concat>(ov::OutputVector{num_experts_unsqueeze, batch_dim_unsqueeze, minus_one},- 0);- auto router_reshape = std::make_shared<ov::op::v1::Reshape>(router_transpose, router_shape, true);- auto routing_unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(router_reshape, axis_minus_one_vector);+ std::make_shared<v0::Concat>(ov::OutputVector{num_experts_unsqueeze, batch_dim_unsqueeze, minus_one}, 0);+ auto router_reshape = std::make_shared<v1::Reshape>(router_transpose, router_shape, true);+ auto routing_unsqueeze = std::make_shared<v0::Unsqueeze>(router_reshape, axis_minus_one_vector);- auto weighted_outputs = std::make_shared<ov::op::v1::Multiply>(expert_outputs, routing_unsqueeze);- auto final_output = std::make_shared<ov::op::v1::ReduceSum>(weighted_outputs, axis0_vector, false);+ auto weighted_outputs = std::make_shared<v1::Multiply>(expert_outputs, routing_unsqueeze);+ auto final_output = std::make_shared<v1::ReduceSum>(weighted_outputs, axis0_vector, false);- auto final_reshape = std::make_shared<ov::op::v1::Reshape>(final_output, target_shape, false);- auto final_add = std::make_shared<ov::op::v1::Add>(residual_input, final_reshape);+ auto final_reshape = std::make_shared<v1::Reshape>(final_output, target_shape, false);+ auto final_add = std::make_shared<v1::Add>(residual_input, final_reshape);final_add->set_friendly_name("moe_decomposed");return std::make_shared<ov::Model>(final_add,@@ -342,19 +342,15 @@ static std::shared_ptr<ov::Model> BuildFusedMOEWithInternalOp(const int expert_nauto num_experts_unsqueeze = makeOP<opset1::Unsqueeze>({num_experts_const, axis0_vector});auto zeros_scalar = makeConst(ov::element::f32, ov::Shape{}, std::vector<float>{0.0f});- auto scatter_shape =- std::make_shared<ov::op::v0::Concat>(ov::OutputVector{batch_dim_unsqueeze, num_experts_unsqueeze}, 0);- auto zeros_tensor = std::make_shared<ov::op::v3::Broadcast>(zeros_scalar, scatter_shape);- auto scatter = std::make_shared<ov::op::v12::ScatterElementsUpdate>(zeros_tensor,- router_topk_indices,- normalized_topk,- axis1_vector);- auto router_transpose = std::make_shared<ov::op::v1::Transpose>(scatter, transpose_axes);+ auto scatter_shape = std::make_shared<v0::Concat>(ov::OutputVector{batch_dim_unsqueeze, num_experts_unsqueeze}, 0);+ auto zeros_tensor = std::make_shared<v3::Broadcast>(zeros_scalar, scatter_shape);+ auto scatter =+ std::make_shared<v12::ScatterElementsUpdate>(zeros_tensor, router_topk_indices, normalized_topk, axis1_vector);+ auto router_transpose = std::make_shared<v1::Transpose>(scatter, transpose_axes);auto router_shape =- std::make_shared<ov::op::v0::Concat>(ov::OutputVector{num_experts_unsqueeze, batch_dim_unsqueeze, minus_one},- 0);- auto router_reshape = std::make_shared<ov::op::v1::Reshape>(router_transpose, router_shape, true);- auto routing_weights = std::make_shared<ov::op::v0::Unsqueeze>(router_reshape, axis_minus_one_vector);+ std::make_shared<v0::Concat>(ov::OutputVector{num_experts_unsqueeze, batch_dim_unsqueeze, minus_one}, 0);+ auto router_reshape = std::make_shared<v1::Reshape>(router_transpose, router_shape, true);+ auto routing_weights = std::make_shared<v0::Unsqueeze>(router_reshape, axis_minus_one_vector);auto build_fused_weight = [&](ov::element::Type elem_type,const ov::Shape& single_expert_shape) -> std::shared_ptr<ov::Node> {@@ -363,7 +359,7 @@ static std::shared_ptr<ov::Model> BuildFusedMOEWithInternalOp(const int expert_nauto weight_const = makeConst(elem_type, single_expert_shape, {0});expert_weights.push_back(weight_const);}- auto concat = std::make_shared<ov::op::v0::Concat>(expert_weights, 0);+ auto concat = std::make_shared<v0::Concat>(expert_weights, 0);concat->get_rt_info()["postponed_constant"] = true;return concat;};@@ -397,8 +393,8 @@ static std::shared_ptr<ov::Model> BuildFusedMOEWithInternalOp(const int expert_nconfig.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;auto moe = std::make_shared<ov::op::internal::MOE>(moe_inputs, config);- auto final_reshape = std::make_shared<ov::op::v1::Reshape>(moe, target_shape, false);- auto final_add = std::make_shared<ov::op::v1::Add>(residual_input, final_reshape);+ auto final_reshape = std::make_shared<v1::Reshape>(moe, target_shape, false);+ auto final_add = std::make_shared<v1::Add>(residual_input, final_reshape);return std::make_shared<ov::Model>(ov::OutputVector{final_add},ov::ParameterVector{final_hidden_states_, router_logits, hidden_states_2d});diff --git a/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp b/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cppindex 7a0bc333be1..bc99418a508 100644--- a/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp+++ b/src/common/transformations/tests/common_optimizations/fuse_rotary_positional_embeddings.cpp@@ -36,6 +36,8 @@ using namespace ov::gen_pattern;const std::vector<int> MOCK_VALUE = {1};+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;static ov::OutputVector makeCosSinCache(size_t max_position_embeddings, size_t rotary_ndims) {std::vector<float> lut_sin(max_position_embeddings * rotary_ndims, 0.0f);std::vector<float> lut_cos(max_position_embeddings * rotary_ndims, 0.0f);@@ -1318,22 +1320,22 @@ TEST_F(TransformationTestsF, ConvertToROPE_Flux_mul) {auto t_sin = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{1, 1, -1, ndims});auto x1_shape = makeConst(ov::element::i64, ov::Shape({5}), {0, num_heads, 0, -1, 2});- auto x1 = std::make_shared<ov::op::v1::Reshape>(x, x1_shape, true);+ auto x1 = std::make_shared<v1::Reshape>(x, x1_shape, true);auto split_axis = makeConst(ov::element::i64, ov::Shape(), {-1});- auto split = std::make_shared<ov::op::v1::Split>(x1, split_axis, 2);+ auto split = std::make_shared<v1::Split>(x1, split_axis, 2);auto minus_one = makeConst(ov::element::f32, ov::Shape({}), {-1.0f});- auto x1_1_neg = std::make_shared<ov::op::v1::Multiply>(split->output(1), minus_one);+ auto x1_1_neg = std::make_shared<v1::Multiply>(split->output(1), minus_one);- auto x2 = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{x1_1_neg->output(0), split->output(0)}, -1);+ auto x2 = std::make_shared<v0::Concat>(ov::OutputVector{x1_1_neg->output(0), split->output(0)}, -1);auto x3_shape = makeConst(ov::element::i64, ov::Shape({4}), {0, num_heads, 0, ndims});- auto x3 = std::make_shared<ov::op::v1::Reshape>(x2, x3_shape, true);+ auto x3 = std::make_shared<v1::Reshape>(x2, x3_shape, true);- auto y1 = std::make_shared<ov::op::v1::Multiply>(x, t_cos);- auto y2 = std::make_shared<ov::op::v1::Multiply>(x3, t_sin);- auto y = std::make_shared<ov::op::v1::Add>(y1, y2);+ auto y1 = std::make_shared<v1::Multiply>(x, t_cos);+ auto y2 = std::make_shared<v1::Multiply>(x3, t_sin);+ auto y = std::make_shared<v1::Add>(y1, y2);model = std::make_shared<ov::Model>(ov::OutputVector{y}, ov::ParameterVector{x, t_cos, t_sin});}@@ -1366,28 +1368,28 @@ TEST_F(TransformationTestsF, ConvertToROPE_Flux_squeeze_mul_unsqueeze) {auto t_sin = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{1, 1, -1, ndims});auto x1_shape = makeConst(ov::element::i64, ov::Shape({5}), {0, num_heads, 0, -1, 2});- auto x1 = std::make_shared<ov::op::v1::Reshape>(x, x1_shape, true);+ auto x1 = std::make_shared<v1::Reshape>(x, x1_shape, true);auto split_axis = makeConst(ov::element::i64, ov::Shape(), {-1});- auto split = std::make_shared<ov::op::v1::Split>(x1, split_axis, 2);+ auto split = std::make_shared<v1::Split>(x1, split_axis, 2);auto squeeze_axis = makeConst(ov::element::i32, ov::Shape({}), {-1});- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(split->output(1), squeeze_axis);+ auto squeeze = std::make_shared<v0::Squeeze>(split->output(1), squeeze_axis);auto minus_one = makeConst(ov::element::f32, ov::Shape({}), {-1.0f});- auto x1_1_neg = std::make_shared<ov::op::v1::Multiply>(squeeze, minus_one);+ auto x1_1_neg = std::make_shared<v1::Multiply>(squeeze, minus_one);auto unsqueeze_axis = makeConst(ov::element::i32, ov::Shape({}), {-1});- auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(x1_1_neg, unsqueeze_axis);+ auto unsqueeze = std::make_shared<v0::Unsqueeze>(x1_1_neg, unsqueeze_axis);- auto x2 = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{unsqueeze->output(0), split->output(0)}, -1);+ auto x2 = std::make_shared<v0::Concat>(ov::OutputVector{unsqueeze->output(0), split->output(0)}, -1);auto x3_shape = makeConst(ov::element::i64, ov::Shape({4}), {0, num_heads, 0, ndims});- auto x3 = std::make_shared<ov::op::v1::Reshape>(x2, x3_shape, true);+ auto x3 = std::make_shared<v1::Reshape>(x2, x3_shape, true);- auto y1 = std::make_shared<ov::op::v1::Multiply>(x, t_cos);- auto y2 = std::make_shared<ov::op::v1::Multiply>(x3, t_sin);- auto y = std::make_shared<ov::op::v1::Add>(y1, y2);+ auto y1 = std::make_shared<v1::Multiply>(x, t_cos);+ auto y2 = std::make_shared<v1::Multiply>(x3, t_sin);+ auto y = std::make_shared<v1::Add>(y1, y2);model = std::make_shared<ov::Model>(ov::OutputVector{y}, ov::ParameterVector{x, t_cos, t_sin});}@@ -1420,28 +1422,28 @@ TEST_F(TransformationTestsF, ConvertToROPE_Flux_mul_squeeze_unsqueeze) {auto t_sin = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::PartialShape{1, 1, -1, ndims});auto x1_shape = makeConst(ov::element::i64, ov::Shape({5}), {0, num_heads, 0, -1, 2});- auto x1 = std::make_shared<ov::op::v1::Reshape>(x, x1_shape, true);+ auto x1 = std::make_shared<v1::Reshape>(x, x1_shape, true);auto split_axis = makeConst(ov::element::i64, ov::Shape(), {-1});- auto split = std::make_shared<ov::op::v1::Split>(x1, split_axis, 2);+ auto split = std::make_shared<v1::Split>(x1, split_axis, 2);auto minus_one = makeConst(ov::element::f32, ov::Shape({}), {-1.0f});- auto x1_1_neg = std::make_shared<ov::op::v1::Multiply>(split->output(1), minus_one);+ auto x1_1_neg = std::make_shared<v1::Multiply>(split->output(1), minus_one);auto squeeze_axis = makeConst(ov::element::i32, ov::Shape({}), {-1});- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(x1_1_neg, squeeze_axis);+ auto squeeze = std::make_shared<v0::Squeeze>(x1_1_neg, squeeze_axis);auto unsqueeze_axis = makeConst(ov::element::i32, ov::Shape({}), {-1});- auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(squeeze, unsqueeze_axis);+ auto unsqueeze = std::make_shared<v0::Unsqueeze>(squeeze, unsqueeze_axis);- auto x2 = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{unsqueeze->output(0), split->output(0)}, -1);+ auto x2 = std::make_shared<v0::Concat>(ov::OutputVector{unsqueeze->output(0), split->output(0)}, -1);auto x3_shape = makeConst(ov::element::i64, ov::Shape({4}), {0, num_heads, 0, ndims});- auto x3 = std::make_shared<ov::op::v1::Reshape>(x2, x3_shape, true);+ auto x3 = std::make_shared<v1::Reshape>(x2, x3_shape, true);- auto y1 = std::make_shared<ov::op::v1::Multiply>(x, t_cos);- auto y2 = std::make_shared<ov::op::v1::Multiply>(x3, t_sin);- auto y = std::make_shared<ov::op::v1::Add>(y1, y2);+ auto y1 = std::make_shared<v1::Multiply>(x, t_cos);+ auto y2 = std::make_shared<v1::Multiply>(x3, t_sin);+ auto y = std::make_shared<v1::Add>(y1, y2);model = std::make_shared<ov::Model>(ov::OutputVector{y}, ov::ParameterVector{x, t_cos, t_sin});}diff --git a/src/common/transformations/tests/common_optimizations/gelu_fusion.cpp b/src/common/transformations/tests/common_optimizations/gelu_fusion.cppindex 394964d4ca9..c9ef02e184f 100644--- a/src/common/transformations/tests/common_optimizations/gelu_fusion.cpp+++ b/src/common/transformations/tests/common_optimizations/gelu_fusion.cpp@@ -35,30 +35,33 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v7 = ov::op::v7;enum Mode { DIV, MUL };class GeluTestsP : public TransformationTestsF, public WithParamInterface<Mode> {};INSTANTIATE_TEST_SUITE_P(gelu_tests, GeluTestsP, Values(Mode::DIV, Mode::MUL));Output<Node> div_or_mul(const Mode& mode, const std::shared_ptr<Node>& input, element::Type type) {if (mode == Mode::MUL) {- auto mul_const = ov::op::v0::Constant::create(type, Shape{1}, {M_SQRT1_2});- return std::make_shared<ov::op::v1::Multiply>(input, mul_const);+ auto mul_const = v0::Constant::create(type, Shape{1}, {M_SQRT1_2});+ return std::make_shared<v1::Multiply>(input, mul_const);} else {- auto div_const = ov::op::v0::Constant::create(type, Shape{1}, {M_SQRT2});- return std::make_shared<ov::op::v1::Divide>(input, div_const);+ auto div_const = v0::Constant::create(type, Shape{1}, {M_SQRT2});+ return std::make_shared<v1::Divide>(input, div_const);}}TEST_P(GeluTestsP, GeluFusionPatternOne) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto add_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.0});- auto mul_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.5});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto add_const = v0::Constant::create(element::f32, Shape{1}, {1.0});+ auto mul_const = v0::Constant::create(element::f32, Shape{1}, {0.5});- auto erf = std::make_shared<ov::op::v0::Erf>(div_or_mul(GetParam(), data, element::f32));- auto add = std::make_shared<ov::op::v1::Add>(erf, add_const);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(data, mul_const);- auto mul = std::make_shared<ov::op::v1::Multiply>(mul_first, add);+ auto erf = std::make_shared<v0::Erf>(div_or_mul(GetParam(), data, element::f32));+ auto add = std::make_shared<v1::Add>(erf, add_const);+ auto mul_first = std::make_shared<v1::Multiply>(data, mul_const);+ auto mul = std::make_shared<v1::Multiply>(mul_first, add);model = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});@@ -66,23 +69,23 @@ TEST_P(GeluTestsP, GeluFusionPatternOne) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_P(GeluTestsP, GeluFusionPatternOneF16) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f16, Shape{2, 2});- auto add_const = ov::op::v0::Constant::create(element::f16, Shape{1}, {1.0});- auto mul_const = ov::op::v0::Constant::create(element::f16, Shape{1}, {0.5});+ auto add_const = v0::Constant::create(element::f16, Shape{1}, {1.0});+ auto mul_const = v0::Constant::create(element::f16, Shape{1}, {0.5});- auto erf = std::make_shared<ov::op::v0::Erf>(div_or_mul(GetParam(), data, element::f16));- auto add = std::make_shared<ov::op::v1::Add>(erf, add_const);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(data, mul_const);- auto mul = std::make_shared<ov::op::v1::Multiply>(mul_first, add);+ auto erf = std::make_shared<v0::Erf>(div_or_mul(GetParam(), data, element::f16));+ auto add = std::make_shared<v1::Add>(erf, add_const);+ auto mul_first = std::make_shared<v1::Multiply>(data, mul_const);+ auto mul = std::make_shared<v1::Multiply>(mul_first, add);model = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});@@ -90,23 +93,23 @@ TEST_P(GeluTestsP, GeluFusionPatternOneF16) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data);+ auto data = std::make_shared<v0::Parameter>(element::f16, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_P(GeluTestsP, GeluFusionPatternTwo) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});- auto add_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.0});- auto mul_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.5});+ auto add_const = v0::Constant::create(element::f32, Shape{1}, {1.0});+ auto mul_const = v0::Constant::create(element::f32, Shape{1}, {0.5});- auto erf = std::make_shared<ov::op::v0::Erf>(div_or_mul(GetParam(), data, element::f32));- auto add = std::make_shared<ov::op::v1::Add>(erf, add_const);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(data, add);- auto mul = std::make_shared<ov::op::v1::Multiply>(mul_first, mul_const);+ auto erf = std::make_shared<v0::Erf>(div_or_mul(GetParam(), data, element::f32));+ auto add = std::make_shared<v1::Add>(erf, add_const);+ auto mul_first = std::make_shared<v1::Multiply>(data, add);+ auto mul = std::make_shared<v1::Multiply>(mul_first, mul_const);model = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});@@ -114,23 +117,23 @@ TEST_P(GeluTestsP, GeluFusionPatternTwo) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_P(GeluTestsP, GeluFusionPatternTwoF16) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f16, Shape{2, 2});- auto add_const = ov::op::v0::Constant::create(element::f16, Shape{1}, {1.0});- auto mul_const = ov::op::v0::Constant::create(element::f16, Shape{1}, {0.5});+ auto add_const = v0::Constant::create(element::f16, Shape{1}, {1.0});+ auto mul_const = v0::Constant::create(element::f16, Shape{1}, {0.5});- auto erf = std::make_shared<ov::op::v0::Erf>(div_or_mul(GetParam(), data, element::f16));- auto add = std::make_shared<ov::op::v1::Add>(erf, add_const);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(data, add);- auto mul = std::make_shared<ov::op::v1::Multiply>(mul_first, mul_const);+ auto erf = std::make_shared<v0::Erf>(div_or_mul(GetParam(), data, element::f16));+ auto add = std::make_shared<v1::Add>(erf, add_const);+ auto mul_first = std::make_shared<v1::Multiply>(data, add);+ auto mul = std::make_shared<v1::Multiply>(mul_first, mul_const);model = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});@@ -138,23 +141,23 @@ TEST_P(GeluTestsP, GeluFusionPatternTwoF16) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data);+ auto data = std::make_shared<v0::Parameter>(element::f16, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_P(GeluTestsP, GeluFusionPatternThree) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});- auto add_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.0});- auto mul_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.5});+ auto add_const = v0::Constant::create(element::f32, Shape{1}, {1.0});+ auto mul_const = v0::Constant::create(element::f32, Shape{1}, {0.5});- auto erf = std::make_shared<ov::op::v0::Erf>(div_or_mul(GetParam(), data, element::f32));- auto add = std::make_shared<ov::op::v1::Add>(erf, add_const);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(add, mul_const);- auto mul = std::make_shared<ov::op::v1::Multiply>(data, mul_first);+ auto erf = std::make_shared<v0::Erf>(div_or_mul(GetParam(), data, element::f32));+ auto add = std::make_shared<v1::Add>(erf, add_const);+ auto mul_first = std::make_shared<v1::Multiply>(add, mul_const);+ auto mul = std::make_shared<v1::Multiply>(data, mul_first);model = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});@@ -162,23 +165,23 @@ TEST_P(GeluTestsP, GeluFusionPatternThree) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_P(GeluTestsP, GeluFusionPatternThreeF16) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f16, Shape{2, 2});- auto add_const = ov::op::v0::Constant::create(element::f16, Shape{1}, {1.0});- auto mul_const = ov::op::v0::Constant::create(element::f16, Shape{1}, {0.5});+ auto add_const = v0::Constant::create(element::f16, Shape{1}, {1.0});+ auto mul_const = v0::Constant::create(element::f16, Shape{1}, {0.5});- auto erf = std::make_shared<ov::op::v0::Erf>(div_or_mul(GetParam(), data, element::f16));- auto add = std::make_shared<ov::op::v1::Add>(erf, add_const);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(add, mul_const);- auto mul = std::make_shared<ov::op::v1::Multiply>(data, mul_first);+ auto erf = std::make_shared<v0::Erf>(div_or_mul(GetParam(), data, element::f16));+ auto add = std::make_shared<v1::Add>(erf, add_const);+ auto mul_first = std::make_shared<v1::Multiply>(add, mul_const);+ auto mul = std::make_shared<v1::Multiply>(data, mul_first);model = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});@@ -186,25 +189,25 @@ TEST_P(GeluTestsP, GeluFusionPatternThreeF16) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data);+ auto data = std::make_shared<v0::Parameter>(element::f16, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionPatternFour) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});- auto mul1_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.0f / M_SQRT2});- auto add_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.5f});- auto mul2_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.5f});+ auto mul1_const = v0::Constant::create(element::f32, Shape{1}, {1.0f / M_SQRT2});+ auto add_const = v0::Constant::create(element::f32, Shape{1}, {0.5f});+ auto mul2_const = v0::Constant::create(element::f32, Shape{1}, {0.5f});- auto mul1 = std::make_shared<ov::op::v1::Multiply>(data, mul1_const);- auto erf = std::make_shared<ov::op::v0::Erf>(mul1);- auto mul2 = std::make_shared<ov::op::v1::Multiply>(erf, mul2_const);- auto add = std::make_shared<ov::op::v1::Add>(mul2, add_const);- auto mul3 = std::make_shared<ov::op::v1::Multiply>(data, add);+ auto mul1 = std::make_shared<v1::Multiply>(data, mul1_const);+ auto erf = std::make_shared<v0::Erf>(mul1);+ auto mul2 = std::make_shared<v1::Multiply>(erf, mul2_const);+ auto add = std::make_shared<v1::Add>(mul2, add_const);+ auto mul3 = std::make_shared<v1::Multiply>(data, add);model = std::make_shared<Model>(OutputVector{mul3}, ParameterVector{data});@@ -212,25 +215,25 @@ TEST_F(TransformationTestsF, GeluFusionPatternFour) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionPatternFourF16) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f16, Shape{2, 2});- auto mul1_const = ov::op::v0::Constant::create(element::f16, Shape{1}, {1.0f / M_SQRT2});- auto add_const = ov::op::v0::Constant::create(element::f16, Shape{1}, {0.5f});- auto mul2_const = ov::op::v0::Constant::create(element::f16, Shape{1}, {0.5f});+ auto mul1_const = v0::Constant::create(element::f16, Shape{1}, {1.0f / M_SQRT2});+ auto add_const = v0::Constant::create(element::f16, Shape{1}, {0.5f});+ auto mul2_const = v0::Constant::create(element::f16, Shape{1}, {0.5f});- auto mul1 = std::make_shared<ov::op::v1::Multiply>(data, mul1_const);- auto erf = std::make_shared<ov::op::v0::Erf>(mul1);- auto mul2 = std::make_shared<ov::op::v1::Multiply>(erf, mul2_const);- auto add = std::make_shared<ov::op::v1::Add>(mul2, add_const);- auto mul3 = std::make_shared<ov::op::v1::Multiply>(data, add);+ auto mul1 = std::make_shared<v1::Multiply>(data, mul1_const);+ auto erf = std::make_shared<v0::Erf>(mul1);+ auto mul2 = std::make_shared<v1::Multiply>(erf, mul2_const);+ auto add = std::make_shared<v1::Add>(mul2, add_const);+ auto mul3 = std::make_shared<v1::Multiply>(data, add);model = std::make_shared<Model>(OutputVector{mul3}, ParameterVector{data});@@ -238,25 +241,25 @@ TEST_F(TransformationTestsF, GeluFusionPatternFourF16) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data);+ auto data = std::make_shared<v0::Parameter>(element::f16, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionPatternIncorrectDivConstValue) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});- auto div_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.4149});- auto add_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.0});- auto mul_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.5});+ auto div_const = v0::Constant::create(element::f32, Shape{1}, {1.4149});+ auto add_const = v0::Constant::create(element::f32, Shape{1}, {1.0});+ auto mul_const = v0::Constant::create(element::f32, Shape{1}, {0.5});- auto div = std::make_shared<ov::op::v1::Divide>(data, div_const);- auto erf = std::make_shared<ov::op::v0::Erf>(div);- auto add = std::make_shared<ov::op::v1::Add>(erf, add_const);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(data, add);- auto mul = std::make_shared<ov::op::v1::Multiply>(mul_first, mul_const);+ auto div = std::make_shared<v1::Divide>(data, div_const);+ auto erf = std::make_shared<v0::Erf>(div);+ auto add = std::make_shared<v1::Add>(erf, add_const);+ auto mul_first = std::make_shared<v1::Multiply>(data, add);+ auto mul = std::make_shared<v1::Multiply>(mul_first, mul_const);model = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});model_ref = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});@@ -267,17 +270,17 @@ TEST_F(TransformationTestsF, GeluFusionPatternIncorrectDivConstValue) {TEST_F(TransformationTestsF, GeluFusionPatternTooShortDivConstValue) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});- auto div_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.4142});- auto add_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.0});- auto mul_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.5});+ auto div_const = v0::Constant::create(element::f32, Shape{1}, {1.4142});+ auto add_const = v0::Constant::create(element::f32, Shape{1}, {1.0});+ auto mul_const = v0::Constant::create(element::f32, Shape{1}, {0.5});- auto div = std::make_shared<ov::op::v1::Divide>(data, div_const);- auto erf = std::make_shared<ov::op::v0::Erf>(div);- auto add = std::make_shared<ov::op::v1::Add>(erf, add_const);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(data, add);- auto mul = std::make_shared<ov::op::v1::Multiply>(mul_first, mul_const);+ auto div = std::make_shared<v1::Divide>(data, div_const);+ auto erf = std::make_shared<v0::Erf>(div);+ auto add = std::make_shared<v1::Add>(erf, add_const);+ auto mul_first = std::make_shared<v1::Multiply>(data, add);+ auto mul = std::make_shared<v1::Multiply>(mul_first, mul_const);model = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});model_ref = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});@@ -288,94 +291,93 @@ TEST_F(TransformationTestsF, GeluFusionPatternTooShortDivConstValue) {TEST_F(TransformationTestsF, GeluFusionPatternVariadicSplitAsInput) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, 512});- auto axis = std::make_shared<ov::op::v0::Constant>(element::i64, Shape{});- auto split_lengths = std::make_shared<ov::op::v0::Constant>(element::i64, Shape{2});- auto var_split = std::make_shared<ov::op::v1::VariadicSplit>(data, axis, split_lengths);+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, 512});+ auto axis = std::make_shared<v0::Constant>(element::i64, Shape{});+ auto split_lengths = std::make_shared<v0::Constant>(element::i64, Shape{2});+ auto var_split = std::make_shared<v1::VariadicSplit>(data, axis, split_lengths);- auto div_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.4142});- auto add_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {1.0});- auto mul_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.5});+ auto div_const = v0::Constant::create(element::f32, Shape{1}, {1.4142});+ auto add_const = v0::Constant::create(element::f32, Shape{1}, {1.0});+ auto mul_const = v0::Constant::create(element::f32, Shape{1}, {0.5});- auto div = std::make_shared<ov::op::v1::Divide>(var_split->output(1), div_const);- auto erf = std::make_shared<ov::op::v0::Erf>(div);- auto add = std::make_shared<ov::op::v1::Add>(erf, add_const);- auto mul_first = std::make_shared<ov::op::v1::Multiply>(var_split->output(1), add);- auto mul = std::make_shared<ov::op::v1::Multiply>(mul_first, mul_const);+ auto div = std::make_shared<v1::Divide>(var_split->output(1), div_const);+ auto erf = std::make_shared<v0::Erf>(div);+ auto add = std::make_shared<v1::Add>(erf, add_const);+ auto mul_first = std::make_shared<v1::Multiply>(var_split->output(1), add);+ auto mul = std::make_shared<v1::Multiply>(mul_first, mul_const);model = std::make_shared<Model>(OutputVector{mul}, ParameterVector{data});manager.register_pass<ov::pass::GeluFusionWithErfTwo>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, 512});- auto axis = std::make_shared<ov::op::v0::Constant>(element::i64, Shape{});- auto split_lengths = std::make_shared<ov::op::v0::Constant>(element::i64, Shape{2});- auto var_split = std::make_shared<ov::op::v1::VariadicSplit>(data, axis, split_lengths);+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, 512});+ auto axis = std::make_shared<v0::Constant>(element::i64, Shape{});+ auto split_lengths = std::make_shared<v0::Constant>(element::i64, Shape{2});+ auto var_split = std::make_shared<v1::VariadicSplit>(data, axis, split_lengths);- auto gelu = std::make_shared<ov::op::v7::Gelu>(var_split->output(1));+ auto gelu = std::make_shared<v7::Gelu>(var_split->output(1));model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_equal_const_values) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_params_no_conversion) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_param = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_param);- auto mul_0_param = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_param);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_param = std::make_shared<v0::Parameter>(element::f32, Shape{1});+ auto pow = std::make_shared<v1::Power>(input, pow_param);+ auto mul_0_param = std::make_shared<v0::Parameter>(element::f32, Shape{1});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_param);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);- auto mul_1_param = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_param);+ auto mul_1_param = std::make_shared<v0::Parameter>(element::f32, Shape{1});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_param);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_param = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_param);+ auto add_1_param = std::make_shared<v0::Parameter>(element::f32, Shape{1});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_param);- auto mul_2_param = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_param);+ auto mul_2_param = std::make_shared<v0::Parameter>(element::f32, Shape{1});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_param);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3},@@ -386,105 +388,100 @@ TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_params_no_conversion) {TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_epsilon_pow_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f + 1.0e-8f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f + 1.0e-8f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_epsilon_pow_value_2) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f + 1.0e-8f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f + 1.0e-8f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(input, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(input, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(add_1, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_pow_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{2.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{2.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();@@ -493,66 +490,64 @@ TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_pow_value) {TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_epsilon_mul_0_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.04515f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.04515f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_mul_0_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.4715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.4715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();@@ -561,64 +556,61 @@ TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_mul_0_value) {TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_epsilon_mul_1_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);- auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.7980868f});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ auto mul_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.7980868f});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_mul_1_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(10.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(10.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();@@ -627,67 +619,65 @@ TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_mul_1_value) {TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_epsilon_add_1_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);auto add_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f + 1.0e-8f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f + 1.0e-8f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_add_1_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{2.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{2.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();@@ -696,67 +686,65 @@ TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_add_1_value) {TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_epsilon_mul_2_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);auto mul_2_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f + 1.0e-8f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f + 1.0e-8f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_mul_2_value) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto pow_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});- auto pow = std::make_shared<ov::op::v1::Power>(input, pow_constant);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(pow, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto pow_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{3.0f});+ auto pow = std::make_shared<v1::Power>(input, pow_constant);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(pow, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{5.0f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{5.0f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanh>();@@ -765,134 +753,131 @@ TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_wrong_mul_2_value) {TEST_F(TransformationTestsF, FoldGeluOperation) {{- auto param = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1006, 2, 100, 3, 4096});- auto const1 = ov::op::v0::Constant::create(element::f32, Shape{1, 1, 1}, std::vector<float>{0.044715f});+ auto param = std::make_shared<v0::Parameter>(element::f32, Shape{1006, 2, 100, 3, 4096});+ auto const1 = v0::Constant::create(element::f32, Shape{1, 1, 1}, std::vector<float>{0.044715f});- auto mul1 = std::make_shared<ov::op::v1::Multiply>(param, const1);- auto mul2 = std::make_shared<ov::op::v1::Multiply>(mul1, param);+ auto mul1 = std::make_shared<v1::Multiply>(param, const1);+ auto mul2 = std::make_shared<v1::Multiply>(mul1, param);- auto const2 = ov::op::v0::Constant::create(element::f32, Shape{1, 1, 1}, std::vector<float>{1.0});- auto add1 = std::make_shared<ov::op::v1::Add>(const2, mul2);+ auto const2 = v0::Constant::create(element::f32, Shape{1, 1, 1}, std::vector<float>{1.0});+ auto add1 = std::make_shared<v1::Add>(const2, mul2);- auto const3 = ov::op::v0::Constant::create(element::f32,- Shape{1, 1, 1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul3 = std::make_shared<ov::op::v1::Multiply>(param, const3);+ auto const3 = v0::Constant::create(element::f32,+ Shape{1, 1, 1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul3 = std::make_shared<v1::Multiply>(param, const3);- auto mul4 = std::make_shared<ov::op::v1::Multiply>(add1, mul3);- auto tan = std::make_shared<ov::op::v0::Tanh>(mul4);+ auto mul4 = std::make_shared<v1::Multiply>(add1, mul3);+ auto tan = std::make_shared<v0::Tanh>(mul4);- auto const4 = ov::op::v0::Constant::create(element::f32, Shape{1, 1, 1}, std::vector<float>{1.0});- auto add2 = std::make_shared<ov::op::v1::Add>(tan, const4);+ auto const4 = v0::Constant::create(element::f32, Shape{1, 1, 1}, std::vector<float>{1.0});+ auto add2 = std::make_shared<v1::Add>(tan, const4);- auto const5 = ov::op::v0::Constant::create(element::f32, Shape{1, 1, 1}, std::vector<float>{0.5});- auto mul5 = std::make_shared<ov::op::v1::Multiply>(param, const5);+ auto const5 = v0::Constant::create(element::f32, Shape{1, 1, 1}, std::vector<float>{0.5});+ auto mul5 = std::make_shared<v1::Multiply>(param, const5);- auto mul6 = std::make_shared<ov::op::v1::Multiply>(add2, mul5);+ auto mul6 = std::make_shared<v1::Multiply>(add2, mul5);- auto result = std::make_shared<ov::op::v0::Result>(mul6);+ auto result = std::make_shared<v0::Result>(mul6);model = std::make_shared<Model>(OutputVector{result}, ParameterVector{param});manager.register_pass<ov::pass::GeluFusionWithTanhNoPower>();}{- auto param = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1006, 2, 100, 3, 4096});- auto gelu = std::make_shared<ov::op::v7::Gelu>(param, ov::op::GeluApproximationMode::TANH);- auto result = std::make_shared<ov::op::v0::Result>(gelu);+ auto param = std::make_shared<v0::Parameter>(element::f32, Shape{1006, 2, 100, 3, 4096});+ auto gelu = std::make_shared<v7::Gelu>(param, ov::op::GeluApproximationMode::TANH);+ auto result = std::make_shared<v0::Result>(gelu);model_ref = std::make_shared<Model>(OutputVector{result}, ParameterVector{param});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_epsilon_no_pow2_value1) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto mul_in2 = std::make_shared<ov::op::v1::Multiply>(input, input);- auto mul_in3 = std::make_shared<ov::op::v1::Multiply>(input, mul_in2);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(mul_in3, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto mul_in2 = std::make_shared<v1::Multiply>(input, input);+ auto mul_in3 = std::make_shared<v1::Multiply>(input, mul_in2);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(mul_in3, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(input, mul_2);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(add_1, mul_2_constant);+ auto mul_3 = std::make_shared<v1::Multiply>(input, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanhNoPower2>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_epsilon_no_pow2_value2) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto mul_in2 = std::make_shared<ov::op::v1::Multiply>(input, input);- auto mul_in3 = std::make_shared<ov::op::v1::Multiply>(input, mul_in2);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(mul_in3, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto mul_in2 = std::make_shared<v1::Multiply>(input, input);+ auto mul_in3 = std::make_shared<v1::Multiply>(input, mul_in2);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(mul_in3, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);- auto mul_2_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(input, mul_2_constant);- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(add_1, mul_2);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);+ auto mul_2_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_2 = std::make_shared<v1::Multiply>(input, mul_2_constant);+ auto mul_3 = std::make_shared<v1::Multiply>(add_1, mul_2);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanhNoPower2>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}TEST_F(TransformationTestsF, GeluFusionTanhWithTanh_epsilon_no_pow2_value3) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto mul_in2 = std::make_shared<ov::op::v1::Multiply>(input, input);- auto mul_in3 = std::make_shared<ov::op::v1::Multiply>(input, mul_in2);- auto mul_0_constant =- std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});- auto mul_0 = std::make_shared<ov::op::v1::Multiply>(mul_in3, mul_0_constant);- auto add_0 = std::make_shared<ov::op::v1::Add>(input, mul_0);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto mul_in2 = std::make_shared<v1::Multiply>(input, input);+ auto mul_in3 = std::make_shared<v1::Multiply>(input, mul_in2);+ auto mul_0_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.044715f});+ auto mul_0 = std::make_shared<v1::Multiply>(mul_in3, mul_0_constant);+ auto add_0 = std::make_shared<v1::Add>(input, mul_0);auto mul_1_constant =- std::make_shared<ov::op::v0::Constant>(element::f32,- Shape{1},- std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});- auto mul_1 = std::make_shared<ov::op::v1::Multiply>(add_0, mul_1_constant);- auto tanh = std::make_shared<ov::op::v0::Tanh>(mul_1);- auto add_1_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});- auto add_1 = std::make_shared<ov::op::v1::Add>(tanh, add_1_constant);- auto mul_2 = std::make_shared<ov::op::v1::Multiply>(input, add_1);- auto mul_3_constant = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});- auto mul_3 = std::make_shared<ov::op::v1::Multiply>(mul_2, mul_3_constant);+ std::make_shared<v0::Constant>(element::f32,+ Shape{1},+ std::vector<float>{static_cast<float>(std::sqrt(2.0 / M_PI))});+ auto mul_1 = std::make_shared<v1::Multiply>(add_0, mul_1_constant);+ auto tanh = std::make_shared<v0::Tanh>(mul_1);+ auto add_1_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{1.0f});+ auto add_1 = std::make_shared<v1::Add>(tanh, add_1_constant);+ auto mul_2 = std::make_shared<v1::Multiply>(input, add_1);+ auto mul_3_constant = std::make_shared<v0::Constant>(element::f32, Shape{1}, std::vector<float>{0.5f});+ auto mul_3 = std::make_shared<v1::Multiply>(mul_2, mul_3_constant);model = std::make_shared<Model>(OutputVector{mul_3}, ParameterVector{input});manager.register_pass<ov::pass::GeluFusionWithTanhNoPower2>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});- auto gelu = std::make_shared<ov::op::v7::Gelu>(data, op::GeluApproximationMode::TANH);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});+ auto gelu = std::make_shared<v7::Gelu>(data, op::GeluApproximationMode::TANH);model_ref = std::make_shared<Model>(OutputVector{gelu}, ParameterVector{data});}}diff --git a/src/common/transformations/tests/common_optimizations/glu_fusion_test.cpp b/src/common/transformations/tests/common_optimizations/glu_fusion_test.cppindex c66a5ed7fbb..ec63c34446b 100644--- a/src/common/transformations/tests/common_optimizations/glu_fusion_test.cpp+++ b/src/common/transformations/tests/common_optimizations/glu_fusion_test.cpp@@ -24,14 +24,17 @@using namespace testing;using namespace ov::pass;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;TEST_F(TransformationTestsF, GLUFusionTest1) {{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});- auto split_lengths_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});- auto variadic_split = std::make_shared<ov::op::v1::VariadicSplit>(input, axis_const, split_lengths_const);- auto swish = std::make_shared<ov::op::v4::Swish>(variadic_split->output(0));- auto mul = std::make_shared<ov::op::v1::Multiply>(swish, variadic_split->output(1));+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});+ auto axis_const = v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});+ auto split_lengths_const = v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});+ auto variadic_split = std::make_shared<v1::VariadicSplit>(input, axis_const, split_lengths_const);+ auto swish = std::make_shared<v4::Swish>(variadic_split->output(0));+ auto mul = std::make_shared<v1::Multiply>(swish, variadic_split->output(1));model = std::make_shared<ov::Model>(ov::OutputVector{mul}, ov::ParameterVector{input});manager.register_pass<GLUFusion>();@@ -39,7 +42,7 @@ TEST_F(TransformationTestsF, GLUFusionTest1) {{int64_t axis = -1;int64_t split_lenghts = 3;- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});auto swiglu = std::make_shared<ov::op::internal::GLU>(input,axis,split_lenghts,@@ -53,12 +56,12 @@ TEST_F(TransformationTestsF, GLUFusionTest1) {TEST_F(TransformationTestsF, GLUFusionTest2) {{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {0});- auto split_lengths_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, 3});- auto variadic_split = std::make_shared<ov::op::v1::VariadicSplit>(input, axis_const, split_lengths_const);- auto swish = std::make_shared<ov::op::v4::Swish>(variadic_split->output(0));- auto mul = std::make_shared<ov::op::v1::Multiply>(swish, variadic_split->output(1));+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});+ auto axis_const = v0::Constant::create(ov::element::i64, ov::Shape{}, {0});+ auto split_lengths_const = v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, 3});+ auto variadic_split = std::make_shared<v1::VariadicSplit>(input, axis_const, split_lengths_const);+ auto swish = std::make_shared<v4::Swish>(variadic_split->output(0));+ auto mul = std::make_shared<v1::Multiply>(swish, variadic_split->output(1));model = std::make_shared<ov::Model>(ov::OutputVector{mul}, ov::ParameterVector{input});manager.register_pass<GLUFusion>();@@ -67,12 +70,12 @@ TEST_F(TransformationTestsF, GLUFusionTest2) {TEST_F(TransformationTestsF, GLUFusionTest3) {{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});- auto split_lengths_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});- auto variadic_split = std::make_shared<ov::op::v1::VariadicSplit>(input, axis_const, split_lengths_const);- auto swish = std::make_shared<ov::op::v4::Swish>(variadic_split->output(0));- auto mul = std::make_shared<ov::op::v1::Multiply>(swish, variadic_split->output(1));+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});+ auto axis_const = v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});+ auto split_lengths_const = v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});+ auto variadic_split = std::make_shared<v1::VariadicSplit>(input, axis_const, split_lengths_const);+ auto swish = std::make_shared<v4::Swish>(variadic_split->output(0));+ auto mul = std::make_shared<v1::Multiply>(swish, variadic_split->output(1));model = std::make_shared<ov::Model>(ov::OutputVector{mul}, ov::ParameterVector{input});manager.register_pass<GLUFusion>();@@ -80,7 +83,7 @@ TEST_F(TransformationTestsF, GLUFusionTest3) {{int64_t axis = -1;int64_t split_lenghts = 3;- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});auto swiglu = std::make_shared<ov::op::internal::GLU>(input,axis,split_lenghts,@@ -94,12 +97,12 @@ TEST_F(TransformationTestsF, GLUFusionTest3) {TEST_F(TransformationTestsF, GLUFusionTest3ReverseOrder) {{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});- auto split_lengths_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});- auto variadic_split = std::make_shared<ov::op::v1::VariadicSplit>(input, axis_const, split_lengths_const);- auto swish = std::make_shared<ov::op::v4::Swish>(variadic_split->output(0));- auto mul = std::make_shared<ov::op::v1::Multiply>(variadic_split->output(1), swish);+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});+ auto axis_const = v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});+ auto split_lengths_const = v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});+ auto variadic_split = std::make_shared<v1::VariadicSplit>(input, axis_const, split_lengths_const);+ auto swish = std::make_shared<v4::Swish>(variadic_split->output(0));+ auto mul = std::make_shared<v1::Multiply>(variadic_split->output(1), swish);model = std::make_shared<ov::Model>(ov::OutputVector{mul}, ov::ParameterVector{input});manager.register_pass<GLUFusion>();@@ -107,7 +110,7 @@ TEST_F(TransformationTestsF, GLUFusionTest3ReverseOrder) {{int64_t axis = -1;int64_t split_lenghts = 3;- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});auto swiglu = std::make_shared<ov::op::internal::GLU>(input,axis,split_lenghts,@@ -121,12 +124,12 @@ TEST_F(TransformationTestsF, GLUFusionTest3ReverseOrder) {TEST_F(TransformationTestsF, GLUFusionTest4) {{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});- auto split_lengths_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});- auto variadic_split = std::make_shared<ov::op::v1::VariadicSplit>(input, axis_const, split_lengths_const);- auto swish = std::make_shared<ov::op::v4::Swish>(variadic_split->output(0));- auto mul = std::make_shared<ov::op::v1::Multiply>(swish, variadic_split->output(0));+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{-1, -1, 6});+ auto axis_const = v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});+ auto split_lengths_const = v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});+ auto variadic_split = std::make_shared<v1::VariadicSplit>(input, axis_const, split_lengths_const);+ auto swish = std::make_shared<v4::Swish>(variadic_split->output(0));+ auto mul = std::make_shared<v1::Multiply>(swish, variadic_split->output(0));model = std::make_shared<ov::Model>(ov::OutputVector{mul}, ov::ParameterVector{input});manager.register_pass<GLUFusion>();@@ -135,12 +138,12 @@ TEST_F(TransformationTestsF, GLUFusionTest4) {TEST_F(TransformationTestsF, GeGLUFusionTest1) {{- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});- auto split_lengths_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});- auto variadic_split = std::make_shared<ov::op::v1::VariadicSplit>(input, axis_const, split_lengths_const);+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});+ auto axis_const = v0::Constant::create(ov::element::i64, ov::Shape{}, {-1});+ auto split_lengths_const = v0::Constant::create(ov::element::i64, ov::Shape{2}, {3, -1});+ auto variadic_split = std::make_shared<v1::VariadicSplit>(input, axis_const, split_lengths_const);auto gelu = std::make_shared<ov::op::v7::Gelu>(variadic_split->output(1));- auto mul = std::make_shared<ov::op::v1::Multiply>(variadic_split->output(0), gelu);+ auto mul = std::make_shared<v1::Multiply>(variadic_split->output(0), gelu);model = std::make_shared<ov::Model>(ov::OutputVector{mul}, ov::ParameterVector{input});manager.register_pass<GLUFusion>();@@ -148,7 +151,7 @@ TEST_F(TransformationTestsF, GeGLUFusionTest1) {{int64_t axis = -1;int64_t split_lenghts = 3;- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});+ auto input = std::make_shared<v0::Parameter>(ov::element::f16, ov::PartialShape{2, 1, 6});auto swiglu = std::make_shared<ov::op::internal::GLU>(input,axis,split_lenghts,diff --git a/src/common/transformations/tests/common_optimizations/group_normalization_fusion_tests.cpp b/src/common/transformations/tests/common_optimizations/group_normalization_fusion_tests.cppindex a53d544e00d..882ddb56166 100644--- a/src/common/transformations/tests/common_optimizations/group_normalization_fusion_tests.cpp+++ b/src/common/transformations/tests/common_optimizations/group_normalization_fusion_tests.cpp@@ -19,6 +19,7 @@using namespace testing;+namespace v1 = ov::op::v1;namespace ov {namespace test {@@ -244,8 +245,8 @@ protected:std::make_shared<op::v8::Gather>(instance_norm_beta_1d, gather_indices_const, gather_axis_const);auto group_norm_beta_corr_multiply =- std::make_shared<ov::op::v1::Multiply>(group_norm_gamma_1d, instance_norm_beta_1d);- group_norm_beta_1d = std::make_shared<ov::op::v1::Add>(group_norm_beta_corr_multiply, group_norm_beta_1d);+ std::make_shared<v1::Multiply>(group_norm_gamma_1d, instance_norm_beta_1d);+ group_norm_beta_1d = std::make_shared<v1::Add>(group_norm_beta_corr_multiply, group_norm_beta_1d);}if (instance_norm_gamma_present) {@@ -260,7 +261,7 @@ protected:instance_norm_gamma_1d =std::make_shared<op::v8::Gather>(instance_norm_gamma_1d, gather_indices_const, gather_axis_const);- group_norm_gamma_1d = std::make_shared<ov::op::v1::Multiply>(group_norm_gamma_1d, instance_norm_gamma_1d);+ group_norm_gamma_1d = std::make_shared<v1::Multiply>(group_norm_gamma_1d, instance_norm_gamma_1d);}auto group_norm = std::make_shared<op::v12::GroupNormalization>(input,diff --git a/src/common/transformations/tests/common_optimizations/hsigmoid_fusion_test.cpp b/src/common/transformations/tests/common_optimizations/hsigmoid_fusion_test.cppindex f88ff1fb475..3e13ae508d7 100644--- a/src/common/transformations/tests/common_optimizations/hsigmoid_fusion_test.cpp+++ b/src/common/transformations/tests/common_optimizations/hsigmoid_fusion_test.cpp@@ -27,6 +27,8 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;TEST_F(TransformationTestsF, HSigmoidFusionWithReluDivF16) {{auto input = std::make_shared<opset7::Parameter>(element::f16, PartialShape::dynamic(1));@@ -148,12 +150,12 @@ TEST_F(TransformationTestsF, HSigmoidFusionWithClampMul) {TEST_F(TransformationTestsF, HSigmoidFusionWithClampDiv) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f16, PartialShape::dynamic(1));- auto add_constant = ov::op::v0::Constant::create(element::f16, Shape{}, {3.0});- auto add = std::make_shared<ov::op::v1::Add>(input, add_constant);- auto clamp = std::make_shared<ov::op::v0::Clamp>(add, 0.0f, 6.0f);- auto div_constant = ov::op::v0::Constant::create(element::f16, Shape{}, {6.0});- auto div = std::make_shared<ov::op::v1::Divide>(clamp, div_constant);+ auto input = std::make_shared<v0::Parameter>(element::f16, PartialShape::dynamic(1));+ auto add_constant = v0::Constant::create(element::f16, Shape{}, {3.0});+ auto add = std::make_shared<v1::Add>(input, add_constant);+ auto clamp = std::make_shared<v0::Clamp>(add, 0.0f, 6.0f);+ auto div_constant = v0::Constant::create(element::f16, Shape{}, {6.0});+ auto div = std::make_shared<v1::Divide>(clamp, div_constant);model = std::make_shared<ov::Model>(OutputVector{div}, ParameterVector{input});diff --git a/src/common/transformations/tests/common_optimizations/leaky_relu_fusion.cpp b/src/common/transformations/tests/common_optimizations/leaky_relu_fusion.cppindex cb85df52261..54ec9e78ff0 100644--- a/src/common/transformations/tests/common_optimizations/leaky_relu_fusion.cpp+++ b/src/common/transformations/tests/common_optimizations/leaky_relu_fusion.cpp@@ -24,6 +24,7 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;TEST_F(TransformationTestsF, LeakyReluFusionConstant) {{auto data = std::make_shared<opset8::Parameter>(element::f32, Shape{2, 2});@@ -36,7 +37,7 @@ TEST_F(TransformationTestsF, LeakyReluFusionConstant) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});auto alpha = opset8::Constant::create(element::f32, Shape{1}, {0.1});auto leaky_relu = std::make_shared<opset8::PRelu>(data, alpha);model_ref = std::make_shared<Model>(OutputVector{leaky_relu}, ParameterVector{data});@@ -71,7 +72,7 @@ TEST_F(TransformationTestsF, LeakyReluFusionConstantAlphaOnFirstInput) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});auto alpha = opset8::Constant::create(element::f32, Shape{1}, {0.1});auto leaky_relu = std::make_shared<opset8::PRelu>(data, alpha);model_ref = std::make_shared<Model>(OutputVector{leaky_relu}, ParameterVector{data});@@ -94,7 +95,7 @@ TEST_F(TransformationTestsF, LeakyReluFusionScalar) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 2});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{2, 2});auto alpha = opset8::Constant::create(element::f32, Shape{}, {0.1});auto leaky_relu = std::make_shared<opset8::PRelu>(data, alpha);model_ref = std::make_shared<Model>(OutputVector{leaky_relu}, ParameterVector{data});diff --git a/src/common/transformations/tests/common_optimizations/lora_subgraph_fusion.cpp b/src/common/transformations/tests/common_optimizations/lora_subgraph_fusion.cppindex be81d0e3acc..425fd9187ff 100644--- a/src/common/transformations/tests/common_optimizations/lora_subgraph_fusion.cpp+++ b/src/common/transformations/tests/common_optimizations/lora_subgraph_fusion.cpp@@ -21,6 +21,10 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v6 = ov::op::v6;+namespace op_util = ov::op::util;static constexpr auto netType = ov::element::f32;std::pair<ov::OutputVector, ov::SinkVector> create_states(const std::vector<ov::PartialShape>& shapes,@@ -29,15 +33,15 @@ std::pair<ov::OutputVector, ov::SinkVector> create_states(const std::vector<ov::ov::SinkVector assigns;size_t idx = 0;auto create_state = [&](const ov::PartialShape& shape) {- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{shape, states_precision, std::to_string(idx++)});- auto read_value = std::make_shared<ov::op::v6::ReadValue>(variable);- auto assign = std::make_shared<ov::op::v6::Assign>(read_value, variable);+ auto variable =+ std::make_shared<op_util::Variable>(op_util::VariableInfo{shape, states_precision, std::to_string(idx++)});+ auto read_value = std::make_shared<v6::ReadValue>(variable);+ auto assign = std::make_shared<v6::Assign>(read_value, variable);assigns.push_back(assign);if (states_precision == netType)state_outs.push_back(read_value);else- state_outs.push_back(std::make_shared<ov::op::v0::Convert>(read_value, netType));+ state_outs.push_back(std::make_shared<v0::Convert>(read_value, netType));};for (const auto& shape : shapes)create_state(shape);@@ -55,23 +59,23 @@ std::shared_ptr<ov::Node> create_lora_subgraph(const ov::Output<ov::Node>& main_OPENVINO_ASSERT(add_data_flow_idx == 0 || add_data_flow_idx == 1, "add_data_flow_idx must be 0 or 1");auto create_transpose = [](const ov::Output<ov::Node>& input) -> ov::Output<ov::Node> {- auto constant = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{4}, {2, 3, 0, 1});- return std::make_shared<ov::op::v1::Transpose>(input, constant);+ auto constant = v0::Constant::create(ov::element::i32, ov::Shape{4}, {2, 3, 0, 1});+ return std::make_shared<v1::Transpose>(input, constant);};const auto& mm1_input = add_transposes ? create_transpose(lora_input) : lora_input;- auto mm1 = std::make_shared<ov::op::v0::MatMul>(mm1_input, states[0], false, true);+ auto mm1 = std::make_shared<v0::MatMul>(mm1_input, states[0], false, true);const auto& mul_in_0 = mul_read_value_idx == 0 ? states[1] : mm1->output(0);const auto& mul_in_1 = mul_read_value_idx == 0 ? mm1->output(0) : states[1];- auto mul = std::make_shared<ov::op::v1::Multiply>(mul_in_0, mul_in_1);+ auto mul = std::make_shared<v1::Multiply>(mul_in_0, mul_in_1);- auto mm2 = std::make_shared<ov::op::v0::MatMul>(mul, states[2], false, true);+ auto mm2 = std::make_shared<v0::MatMul>(mul, states[2], false, true);const auto& add_sec_input = add_transposes ? create_transpose(mm2) : mm2;const auto& add_in_0 = add_data_flow_idx == 0 ? main_flow : add_sec_input;const auto& add_in_1 = add_data_flow_idx == 0 ? add_sec_input : main_flow;- return std::make_shared<ov::op::v1::Add>(add_in_0, add_in_1);+ return std::make_shared<v1::Add>(add_in_0, add_in_1);}class LoraSubgraphFusionTests : public TransformationTestsF {@@ -102,9 +106,9 @@ public:TEST_F(LoraSubgraphFusionMatMulTests, StandardPattern) {{- auto param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto param_w = std::make_shared<ov::op::v0::Parameter>(netType, shape_w);- auto main_mm = std::make_shared<ov::op::v0::MatMul>(param_lora, param_w, false, true);+ auto param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto param_w = std::make_shared<v0::Parameter>(netType, shape_w);+ auto main_mm = std::make_shared<v0::MatMul>(param_lora, param_w, false, true);main_mm->set_friendly_name("main_mm");auto states = create_states({shape_state_1, shape_state_2, shape_state_3});auto lora_subgraph = create_lora_subgraph(main_mm, param_lora, states.first, false);@@ -114,16 +118,16 @@ TEST_F(LoraSubgraphFusionMatMulTests, StandardPattern) {ParameterVector{param_lora, param_w});}{- auto param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto param_w = std::make_shared<ov::op::v0::Parameter>(netType, shape_w);- auto main_mm = std::make_shared<ov::op::v0::MatMul>(param_lora, param_w, false, true);+ auto param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto param_w = std::make_shared<v0::Parameter>(netType, shape_w);+ auto main_mm = std::make_shared<v0::MatMul>(param_lora, param_w, false, true);main_mm->set_friendly_name("main_mm");- auto inner_param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto inner_state_1 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_1);- auto inner_state_2 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_2);- auto inner_state_3 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_3);- auto inner_param_mm = std::make_shared<ov::op::v0::Parameter>(netType, main_mm->get_output_partial_shape(0));+ auto inner_param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto inner_state_1 = std::make_shared<v0::Parameter>(netType, shape_state_1);+ auto inner_state_2 = std::make_shared<v0::Parameter>(netType, shape_state_2);+ auto inner_state_3 = std::make_shared<v0::Parameter>(netType, shape_state_3);+ auto inner_param_mm = std::make_shared<v0::Parameter>(netType, main_mm->get_output_partial_shape(0));ov::OutputVector states_outs{inner_state_1, inner_state_2, inner_state_3};auto lora_subgraph = create_lora_subgraph(inner_param_mm, inner_param_lora, states_outs, false);@@ -143,9 +147,9 @@ TEST_F(LoraSubgraphFusionMatMulTests, StandardPattern) {TEST_F(LoraSubgraphFusionMatMulTests, StandardPatternWithConvert) {{- auto param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto param_w = std::make_shared<ov::op::v0::Parameter>(netType, shape_w);- auto main_mm = std::make_shared<ov::op::v0::MatMul>(param_lora, param_w, false, true);+ auto param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto param_w = std::make_shared<v0::Parameter>(netType, shape_w);+ auto main_mm = std::make_shared<v0::MatMul>(param_lora, param_w, false, true);main_mm->set_friendly_name("main_mm");auto states = create_states({shape_state_1, shape_state_2, shape_state_3}, ov::element::f16);auto lora_subgraph = create_lora_subgraph(main_mm, param_lora, states.first, false);@@ -155,16 +159,16 @@ TEST_F(LoraSubgraphFusionMatMulTests, StandardPatternWithConvert) {ParameterVector{param_lora, param_w});}{- auto param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto param_w = std::make_shared<ov::op::v0::Parameter>(netType, shape_w);- auto main_mm = std::make_shared<ov::op::v0::MatMul>(param_lora, param_w, false, true);+ auto param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto param_w = std::make_shared<v0::Parameter>(netType, shape_w);+ auto main_mm = std::make_shared<v0::MatMul>(param_lora, param_w, false, true);main_mm->set_friendly_name("main_mm");- auto inner_param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto inner_state_1 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_1);- auto inner_state_2 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_2);- auto inner_state_3 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_3);- auto inner_param_mm = std::make_shared<ov::op::v0::Parameter>(netType, main_mm->get_output_partial_shape(0));+ auto inner_param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto inner_state_1 = std::make_shared<v0::Parameter>(netType, shape_state_1);+ auto inner_state_2 = std::make_shared<v0::Parameter>(netType, shape_state_2);+ auto inner_state_3 = std::make_shared<v0::Parameter>(netType, shape_state_3);+ auto inner_param_mm = std::make_shared<v0::Parameter>(netType, main_mm->get_output_partial_shape(0));ov::OutputVector states_outs{inner_state_1, inner_state_2, inner_state_3};auto lora_subgraph = create_lora_subgraph(inner_param_mm, inner_param_lora, states_outs, false);@@ -184,9 +188,9 @@ TEST_F(LoraSubgraphFusionMatMulTests, StandardPatternWithConvert) {TEST_F(LoraSubgraphFusionMatMulTests, ReshaffledEltwiseInputs) {{- auto param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto param_w = std::make_shared<ov::op::v0::Parameter>(netType, shape_w);- auto main_mm = std::make_shared<ov::op::v0::MatMul>(param_lora, param_w, false, true);+ auto param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto param_w = std::make_shared<v0::Parameter>(netType, shape_w);+ auto main_mm = std::make_shared<v0::MatMul>(param_lora, param_w, false, true);main_mm->set_friendly_name("main_mm");auto states = create_states({shape_state_1, shape_state_2, shape_state_3});@@ -198,16 +202,16 @@ TEST_F(LoraSubgraphFusionMatMulTests, ReshaffledEltwiseInputs) {ParameterVector{param_lora, param_w});}{- auto param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto param_w = std::make_shared<ov::op::v0::Parameter>(netType, shape_w);- auto main_mm = std::make_shared<ov::op::v0::MatMul>(param_lora, param_w, false, true);+ auto param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto param_w = std::make_shared<v0::Parameter>(netType, shape_w);+ auto main_mm = std::make_shared<v0::MatMul>(param_lora, param_w, false, true);main_mm->set_friendly_name("main_mm");- auto inner_param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto inner_state_1 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_1);- auto inner_state_2 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_2);- auto inner_state_3 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_3);- auto inner_param_mm = std::make_shared<ov::op::v0::Parameter>(netType, main_mm->get_output_partial_shape(0));+ auto inner_param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto inner_state_1 = std::make_shared<v0::Parameter>(netType, shape_state_1);+ auto inner_state_2 = std::make_shared<v0::Parameter>(netType, shape_state_2);+ auto inner_state_3 = std::make_shared<v0::Parameter>(netType, shape_state_3);+ auto inner_param_mm = std::make_shared<v0::Parameter>(netType, main_mm->get_output_partial_shape(0));ov::OutputVector states_outs{inner_state_1, inner_state_2, inner_state_3};auto lora_subgraph = create_lora_subgraph(inner_param_mm, inner_param_lora, states_outs, false, 0, 1);@@ -236,7 +240,7 @@ public:TEST_F(LoraSubgraphFusionConvolutionTests, StandardPattern) {{- auto param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);+ auto param_lora = std::make_shared<v0::Parameter>(netType, shape_x);auto main_conv = ov::test::utils::make_convolution(param_lora,netType,{1, 1},@@ -254,7 +258,7 @@ TEST_F(LoraSubgraphFusionConvolutionTests, StandardPattern) {std::make_shared<Model>(OutputVector{lora_subgraph, main_conv}, states.second, ParameterVector{param_lora});}{- auto param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);+ auto param_lora = std::make_shared<v0::Parameter>(netType, shape_x);auto main_conv = ov::test::utils::make_convolution(param_lora,netType,{1, 1},@@ -266,12 +270,11 @@ TEST_F(LoraSubgraphFusionConvolutionTests, StandardPattern) {num_channels.get_length());main_conv->set_friendly_name("main_conv");- auto inner_param_lora = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);- auto inner_state_1 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_1);- auto inner_state_2 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_2);- auto inner_state_3 = std::make_shared<ov::op::v0::Parameter>(netType, shape_state_3);- auto inner_param_conv =- std::make_shared<ov::op::v0::Parameter>(netType, main_conv->get_output_partial_shape(0));+ auto inner_param_lora = std::make_shared<v0::Parameter>(netType, shape_x);+ auto inner_state_1 = std::make_shared<v0::Parameter>(netType, shape_state_1);+ auto inner_state_2 = std::make_shared<v0::Parameter>(netType, shape_state_2);+ auto inner_state_3 = std::make_shared<v0::Parameter>(netType, shape_state_3);+ auto inner_param_conv = std::make_shared<v0::Parameter>(netType, main_conv->get_output_partial_shape(0));ov::OutputVector states_outs{inner_state_1, inner_state_2, inner_state_3};auto lora_subgraph = create_lora_subgraph(inner_param_conv, inner_param_lora, states_outs, true);diff --git a/src/common/transformations/tests/common_optimizations/low_latency_v2_test.cpp b/src/common/transformations/tests/common_optimizations/low_latency_v2_test.cppindex 172015630d7..0a51daa913d 100644--- a/src/common/transformations/tests/common_optimizations/low_latency_v2_test.cpp+++ b/src/common/transformations/tests/common_optimizations/low_latency_v2_test.cpp@@ -34,6 +34,7 @@ using namespace ov;using namespace opset7;using namespace std;+namespace op_util = ov::op::util;Output<Node> create_init_subgraph(const Output<Node>& in_node) {auto const_zero = make_shared<Constant>(in_node.get_element_type(), Shape{1}, 0);auto shape_of = make_shared<ShapeOf>(in_node);@@ -122,10 +123,10 @@ TEST(TransformationTests, LowLatency2_LSTM) {const std::string variable_name_H("LSTMTensorIterator/H_t/variable_2");const std::string variable_name_C("LSTMTensorIterator/C_t/variable_0");- auto variable_H = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});- auto variable_C = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{C_t->get_shape(), C_t->get_element_type(), variable_name_C});+ auto variable_H = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});+ auto variable_C = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{C_t->get_shape(), C_t->get_element_type(), variable_name_C});auto read_value_H = std::make_shared<ReadValue>(create_init_subgraph(H_t), variable_H);auto read_value_C = std::make_shared<ReadValue>(create_init_subgraph(C_t), variable_C);// Body@@ -208,8 +209,8 @@ TEST(TransformationTests, LowLatency2_GRU) {auto H_t = std::make_shared<Parameter>(element::f32, Shape{1, 128});const std::string variable_name_H("GRUTensorIterator/Yi/variable");- auto variable_H = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});+ auto variable_H = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});auto read_value_H = std::make_shared<ReadValue>(create_init_subgraph(H_t), variable_H);// Bodyauto axis = Constant::create(element::i64, Shape{}, {0});@@ -289,8 +290,8 @@ TEST(TransformationTests, LowLatency2_RNN) {auto H_t = std::make_shared<Parameter>(element::f32, Shape{1, 128});const std::string variable_name_H("RNNTensorIterator/Yi/variable");- auto variable_H = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});+ auto variable_H = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});auto read_value_H = std::make_shared<ReadValue>(create_init_subgraph(H_t), variable_H);// Bodyauto axis = Constant::create(element::i64, Shape{}, {0});@@ -368,10 +369,10 @@ TEST(TransformationTests, LowLatency2_LSTMReshape) {const std::string variable_name_H("LSTMTensorIterator/H_t/variable_2");const std::string variable_name_C("LSTMTensorIterator/C_t/variable_0");- auto variable_H = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});- auto variable_C = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{C_t->get_shape(), C_t->get_element_type(), variable_name_C});+ auto variable_H = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});+ auto variable_C = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{C_t->get_shape(), C_t->get_element_type(), variable_name_C});auto read_value_H = std::make_shared<ReadValue>(create_init_subgraph(H_t), variable_H);auto read_value_C = std::make_shared<ReadValue>(create_init_subgraph(C_t), variable_C);// Body@@ -453,10 +454,10 @@ TEST(TransformationTests, LowLatency2_LSTM_Loop) {const std::string variable_name_H("LSTMLoop/H_t/variable_2");const std::string variable_name_C("LSTMLoop/C_t/variable_0");- auto variable_H = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});- auto variable_C = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{C_t->get_shape(), C_t->get_element_type(), variable_name_C});+ auto variable_H = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});+ auto variable_C = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{C_t->get_shape(), C_t->get_element_type(), variable_name_C});auto read_value_H = std::make_shared<ReadValue>(create_init_subgraph(H_t), variable_H);auto read_value_C = std::make_shared<ReadValue>(create_init_subgraph(C_t), variable_C);// Body@@ -534,10 +535,10 @@ TEST(TransformationTests, LowLatency2_LSTM_several_iterations) {const std::string variable_name_H("LSTMTensorIterator/H_t/variable_2");const std::string variable_name_C("LSTMTensorIterator/C_t/variable_0");- auto variable_H = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{H->get_shape(), H->get_element_type(), variable_name_H});- auto variable_C = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{C->get_shape(), C->get_element_type(), variable_name_C});+ auto variable_H = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{H->get_shape(), H->get_element_type(), variable_name_H});+ auto variable_C = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{C->get_shape(), C->get_element_type(), variable_name_C});auto read_value_H = std::make_shared<ReadValue>(create_init_subgraph(H), variable_H);auto read_value_C = std::make_shared<ReadValue>(create_init_subgraph(C), variable_C);@@ -647,10 +648,10 @@ TEST(TransformationTests, LowLatency2_LSTM_Loop_Reshape) {const std::string variable_name_H("LSTMLoop/H_t/variable_2");const std::string variable_name_C("LSTMLoop/C_t/variable_0");- auto variable_H = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});- auto variable_C = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{C_t->get_shape(), C_t->get_element_type(), variable_name_C});+ auto variable_H = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{H_t->get_shape(), H_t->get_element_type(), variable_name_H});+ auto variable_C = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{C_t->get_shape(), C_t->get_element_type(), variable_name_C});auto read_value_H = std::make_shared<ReadValue>(create_init_subgraph(H_t), variable_H);auto read_value_C = std::make_shared<ReadValue>(create_init_subgraph(C_t), variable_C);// Body@@ -728,10 +729,10 @@ TEST(TransformationTests, LowLatency2_LSTM_Loop_several_iterations) {const std::string variable_name_H("LSTMLoop/H_t/variable_2");const std::string variable_name_C("LSTMLoop/C_t/variable_0");- auto variable_H = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{H->get_shape(), H->get_element_type(), variable_name_H});- auto variable_C = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{C->get_shape(), C->get_element_type(), variable_name_C});+ auto variable_H = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{H->get_shape(), H->get_element_type(), variable_name_H});+ auto variable_C = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{C->get_shape(), C->get_element_type(), variable_name_C});auto read_value_H = std::make_shared<ReadValue>(create_init_subgraph(H), variable_H);auto read_value_C = std::make_shared<ReadValue>(create_init_subgraph(C), variable_C);@@ -857,7 +858,7 @@ OutputVector create_sequence(RNNType rnn_type, RNNAttributes attrs, const OutPtr}shared_ptr<ReadValue> create_read_value(const shared_ptr<Parameter>& param,- const shared_ptr<ov::op::util::Variable>& variable) {+ const shared_ptr<op_util::Variable>& variable) {auto const_zero = make_shared<Constant>(param->get_element_type(), ov::Shape{1}, 0);auto shape_of = make_shared<ShapeOf>(param);auto broadcast = make_shared<Broadcast>(const_zero, shape_of);@@ -942,10 +943,10 @@ TEST_P(LLT2Sequence, RNNLowLatency_v2) {auto X = make_shared<Parameter>(element::f32, Shape{attrs.batch, attrs.seq_len, attrs.input_size});auto H = make_shared<Parameter>(element::f32, Shape{attrs.batch, attrs.num_dir, attrs.hidden_size});auto C = make_shared<Parameter>(element::f32, Shape{attrs.batch, attrs.num_dir, attrs.hidden_size});- auto variable_h = make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{H->get_shape(), H->get_element_type(), "node_28/variable_0"});- auto variable_c = make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{C->get_shape(), C->get_element_type(), "node_28/variable_1"});+ auto variable_h = make_shared<op_util::Variable>(+ op_util::VariableInfo{H->get_shape(), H->get_element_type(), "node_28/variable_0"});+ auto variable_c = make_shared<op_util::Variable>(+ op_util::VariableInfo{C->get_shape(), C->get_element_type(), "node_28/variable_1"});auto read_val_H = create_read_value(H, variable_h);auto read_val_C = create_read_value(C, variable_c);diff --git a/src/common/transformations/tests/common_optimizations/lstm_cell_fusion.cpp b/src/common/transformations/tests/common_optimizations/lstm_cell_fusion.cppindex 17a8829725e..e124d4bd0e3 100644--- a/src/common/transformations/tests/common_optimizations/lstm_cell_fusion.cpp+++ b/src/common/transformations/tests/common_optimizations/lstm_cell_fusion.cpp@@ -29,6 +29,8 @@ using LSTMCellFusionParam = std::tuple<bool, // true if second input to matmulint, // rank of bias (B)int>; // split axis+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;class LSTMCellFusionTestSuite : public testing::WithParamInterface<LSTMCellFusionParam>, public TransformationTestsF {};TEST_P(LSTMCellFusionTestSuite, SubgraphFusedToLSTMCell) {@@ -191,18 +193,18 @@ ov::Output<ov::Node> prepare_weight_fico(const std::vector<float>& f_val,const std::vector<float>& c_val,const std::vector<float>& o_val,Shape w_shape) {- auto f = std::make_shared<ov::op::v0::Constant>(element::f32, w_shape, f_val);- auto i = std::make_shared<ov::op::v0::Constant>(element::f32, w_shape, i_val);- auto c = std::make_shared<ov::op::v0::Constant>(element::f32, w_shape, c_val);- auto o = std::make_shared<ov::op::v0::Constant>(element::f32, w_shape, o_val);-- auto tr_order = std::make_shared<ov::op::v0::Constant>(element::i32, ov::Shape{2}, std::vector<int32_t>{1, 0});- auto f_tr = std::make_shared<ov::op::v1::Transpose>(f, tr_order);- auto i_tr = std::make_shared<ov::op::v1::Transpose>(i, tr_order);- auto c_tr = std::make_shared<ov::op::v1::Transpose>(c, tr_order);- auto o_tr = std::make_shared<ov::op::v1::Transpose>(o, tr_order);-- ov::Output<ov::Node> w = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{f_tr, i_tr, c_tr, o_tr}, 0);+ auto f = std::make_shared<v0::Constant>(element::f32, w_shape, f_val);+ auto i = std::make_shared<v0::Constant>(element::f32, w_shape, i_val);+ auto c = std::make_shared<v0::Constant>(element::f32, w_shape, c_val);+ auto o = std::make_shared<v0::Constant>(element::f32, w_shape, o_val);++ auto tr_order = std::make_shared<v0::Constant>(element::i32, ov::Shape{2}, std::vector<int32_t>{1, 0});+ auto f_tr = std::make_shared<v1::Transpose>(f, tr_order);+ auto i_tr = std::make_shared<v1::Transpose>(i, tr_order);+ auto c_tr = std::make_shared<v1::Transpose>(c, tr_order);+ auto o_tr = std::make_shared<v1::Transpose>(o, tr_order);++ ov::Output<ov::Node> w = std::make_shared<v0::Concat>(ov::OutputVector{f_tr, i_tr, c_tr, o_tr}, 0);if (const auto& constant = ov::util::constantfold_subgraph(w)) {w = constant;}diff --git a/src/common/transformations/tests/common_optimizations/mark_rope_input_to_keep_in_mixed_precision_test.cpp b/src/common/transformations/tests/common_optimizations/mark_rope_input_to_keep_in_mixed_precision_test.cppindex 48299a5e7b6..1db0c22847e 100644--- a/src/common/transformations/tests/common_optimizations/mark_rope_input_to_keep_in_mixed_precision_test.cpp+++ b/src/common/transformations/tests/common_optimizations/mark_rope_input_to_keep_in_mixed_precision_test.cpp@@ -14,6 +14,7 @@#include "ov_ops/rotary_positional_embeddings.hpp"#include "transformations/rt_info/disable_fp16_compression.hpp"+namespace v0 = ov::op::v0;TEST_F(TransformationTestsF, MarkRopeInputsToKeepInMixedPrecisionTest) {/*The 2nd/3rd inputs of ROPE is marked as FP32@@ -38,8 +39,7 @@ TEST_F(TransformationTestsF, MarkRopeInputsToKeepInMixedPrecisionTest) {auto input_a = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 32, 1});auto input_b = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, 10});auto matmul = std::make_shared<ov::opset1::MatMul>(input_a, input_b);- auto transpose_order =- ov::op::v0::Constant::create(ov::element::i32, ov::Shape{3}, std::vector<int32_t>{0, 2, 1});+ auto transpose_order = v0::Constant::create(ov::element::i32, ov::Shape{3}, std::vector<int32_t>{0, 2, 1});auto transpose = std::make_shared<ov::opset1::Transpose>(matmul, transpose_order);auto concat = std::make_shared<ov::opset1::Concat>(ov::NodeVector{transpose, transpose}, -1);auto cos = std::make_shared<ov::opset1::Cos>(concat);@@ -58,8 +58,7 @@ TEST_F(TransformationTestsF, MarkRopeInputsToKeepInMixedPrecisionTest) {auto input_a = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 32, 1});auto input_b = std::make_shared<ov::opset1::Parameter>(ov::element::f32, ov::Shape{1, 1, 10});auto matmul = std::make_shared<ov::opset1::MatMul>(input_a, input_b);- auto transpose_order =- ov::op::v0::Constant::create(ov::element::i32, ov::Shape{3}, std::vector<int32_t>{0, 2, 1});+ auto transpose_order = v0::Constant::create(ov::element::i32, ov::Shape{3}, std::vector<int32_t>{0, 2, 1});auto transpose = std::make_shared<ov::opset1::Transpose>(matmul, transpose_order);auto concat = std::make_shared<ov::opset1::Concat>(ov::NodeVector{transpose, transpose}, -1);auto cos = std::make_shared<ov::opset1::Cos>(concat);diff --git a/src/common/transformations/tests/common_optimizations/mark_subgraph_to_keep_in_mixed_precision_test.cpp b/src/common/transformations/tests/common_optimizations/mark_subgraph_to_keep_in_mixed_precision_test.cppindex 1f6f92c8ecf..c3cf24cf708 100644--- a/src/common/transformations/tests/common_optimizations/mark_subgraph_to_keep_in_mixed_precision_test.cpp+++ b/src/common/transformations/tests/common_optimizations/mark_subgraph_to_keep_in_mixed_precision_test.cpp@@ -36,8 +36,8 @@ using namespace testing;using namespace ov;using namespace std;using namespace ov::opset10;-using namespace ov::op;+namespace v0 = ov::op::v0;TEST(TransformationTests, keep_precission_sensitive_fp32_1) {shared_ptr<Model> model, model_ref;pass::Manager manager;@@ -1369,11 +1369,11 @@ TEST(TransformationTests, MarkDivWithEpsToKeepInMixedPrecision_disable_for_quantTEST_F(TransformationTestsF, MarkRandomUniformAsPrecisionSensitive) {auto param = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{2});- auto random_uniform = std::make_shared<v8::RandomUniform>(param,- v0::Constant::create(element::f32, {}, {0}),- v0::Constant::create(element::f32, {}, {1}),- element::f32);- auto less = std::make_shared<v1::Less>(random_uniform, v0::Constant::create(element::f32, {1, 1}, {0.5}));+ auto random_uniform = std::make_shared<ov::op::v8::RandomUniform>(param,+ v0::Constant::create(element::f32, {}, {0}),+ v0::Constant::create(element::f32, {}, {1}),+ element::f32);+ auto less = std::make_shared<ov::op::v1::Less>(random_uniform, v0::Constant::create(element::f32, {1, 1}, {0.5}));auto res = std::make_shared<v0::Result>(less);model = std::make_shared<ov::Model>(OutputVector{res}, ParameterVector{param});diff --git a/src/common/transformations/tests/common_optimizations/moc_transformations.cpp b/src/common/transformations/tests/common_optimizations/moc_transformations.cppindex ef4d1379d8f..4c473d56ea3 100644--- a/src/common/transformations/tests/common_optimizations/moc_transformations.cpp+++ b/src/common/transformations/tests/common_optimizations/moc_transformations.cpp@@ -31,6 +31,8 @@ using namespace ov;using namespace ov::element;using namespace ov::opset12;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;namespace {std::shared_ptr<ov::Node> make_dq_weights(const ov::element::Type& quant_type,@@ -38,16 +40,16 @@ std::shared_ptr<ov::Node> make_dq_weights(const ov::element::Type& quant_type,float scale,float zp,bool dq_markup = false) {- auto w = ov::op::v0::Constant::create(quant_type, w_shape, {1.0f});- auto w_f = std::make_shared<ov::op::v0::Convert>(w, ov::element::f32);+ auto w = v0::Constant::create(quant_type, w_shape, {1.0f});+ auto w_f = std::make_shared<v0::Convert>(w, ov::element::f32);- auto zp_const = ov::op::v0::Constant::create(quant_type, {}, {zp});- auto zp_f = std::make_shared<ov::op::v0::Convert>(zp_const, ov::element::f32);- auto sub = std::make_shared<ov::op::v1::Subtract>(w_f, zp_f);+ auto zp_const = v0::Constant::create(quant_type, {}, {zp});+ auto zp_f = std::make_shared<v0::Convert>(zp_const, ov::element::f32);+ auto sub = std::make_shared<v1::Subtract>(w_f, zp_f);std::vector<size_t> scale_shape(w_shape.size(), 1);- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, scale_shape, {scale});- auto mul = std::make_shared<ov::op::v1::Multiply>(sub, scale_const);+ auto scale_const = v0::Constant::create(ov::element::f32, scale_shape, {scale});+ auto mul = std::make_shared<v1::Multiply>(sub, scale_const);if (dq_markup) {mark_as_dequantization_node(sub);@@ -121,7 +123,6 @@ TEST(TransformationTests, TestModelTensorsConsistencyUseShapesFalse) {TEST_F(TransformationTestsF, SqueezeRemainsSqueezeAfterMOC) {{- using namespace ov::op;auto input = std::make_shared<v0::Parameter>(element::f32, Shape{30});auto shape = v0::Constant::create(element::i64, Shape{5}, {2, 3, 1, 5, 1});auto reshape = std::make_shared<v1::Reshape>(input, shape, false);@@ -141,7 +142,6 @@ TEST_F(TransformationTestsF, MOCTest) {std::shared_ptr<ov::Node> weights;std::shared_ptr<ov::Node> weights_ref;{- using namespace ov::op;auto data = std::make_shared<v0::Parameter>(element::f32, ov::PartialShape{-1, -1, 5});auto data1 = std::make_shared<v0::Parameter>(element::f32, ov::PartialShape{-1, -1, 5});auto a_mul = std::make_shared<v1::Multiply>(data, data1);@@ -157,7 +157,6 @@ TEST_F(TransformationTestsF, MOCTest) {manager.register_pass<ov::pass::MOCTransformations>(false);}{- using namespace ov::op;auto data = std::make_shared<v0::Parameter>(element::f32, ov::PartialShape{-1, -1, 5});auto data1 = std::make_shared<v0::Parameter>(element::f32, ov::PartialShape{-1, -1, 5});auto a_mul = std::make_shared<v1::Multiply>(data, data1);@@ -207,19 +206,19 @@ TEST_P(QuantWeightsTestP, MatMul_Conv_QuantWeights) {const float matmul_scale = 0.02f, matmul_zp = 1.f;const float conv_scale = 0.05f, conv_zp = 2.f;- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 128});+ auto input = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{1, 128});auto matmul_weight = make_dq_weights(qtype, ov::Shape{128, 64}, matmul_scale, matmul_zp);- auto matmul = std::make_shared<ov::op::v0::MatMul>(input, matmul_weight, false, false);+ auto matmul = std::make_shared<v0::MatMul>(input, matmul_weight, false, false);- auto reshape_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {1, 64, 1, 1});- auto reshape = std::make_shared<ov::op::v1::Reshape>(matmul, reshape_const, false);+ auto reshape_const = v0::Constant::create(ov::element::i64, ov::Shape{4}, {1, 64, 1, 1});+ auto reshape = std::make_shared<v1::Reshape>(matmul, reshape_const, false);auto conv_weight = make_dq_weights(qtype, ov::Shape{8, 64, 1, 1}, conv_scale, conv_zp);- auto conv = std::make_shared<ov::op::v1::Convolution>(reshape,- conv_weight,- ov::Strides{1, 1},- ov::CoordinateDiff{1, 1},- ov::CoordinateDiff{1, 1},- ov::Strides{1, 1});+ auto conv = std::make_shared<v1::Convolution>(reshape,+ conv_weight,+ ov::Strides{1, 1},+ ov::CoordinateDiff{1, 1},+ ov::CoordinateDiff{1, 1},+ ov::Strides{1, 1});model = std::make_shared<ov::Model>(ov::OutputVector{conv}, ov::ParameterVector{input});@@ -234,19 +233,19 @@ TEST_P(QuantWeightsTestP, MatMul_Conv_QuantWeights) {const float matmul_scale = 0.02f, matmul_zp = 1.f;const float conv_scale = 0.05f, conv_zp = 2.f;- auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 128});+ auto input = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{1, 128});auto matmul_weight = make_dq_weights(qtype, ov::Shape{128, 64}, matmul_scale, matmul_zp, true);- auto matmul = std::make_shared<ov::op::v0::MatMul>(input, matmul_weight, false, false);+ auto matmul = std::make_shared<v0::MatMul>(input, matmul_weight, false, false);- auto reshape_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{4}, {1, 64, 1, 1});- auto reshape = std::make_shared<ov::op::v1::Reshape>(matmul, reshape_const, false);+ auto reshape_const = v0::Constant::create(ov::element::i64, ov::Shape{4}, {1, 64, 1, 1});+ auto reshape = std::make_shared<v1::Reshape>(matmul, reshape_const, false);auto conv_weight = make_dq_weights(qtype, ov::Shape{8, 64, 1, 1}, conv_scale, conv_zp, true);- auto conv = std::make_shared<ov::op::v1::Convolution>(reshape,- conv_weight,- ov::Strides{1, 1},- ov::CoordinateDiff{1, 1},- ov::CoordinateDiff{1, 1},- ov::Strides{1, 1});+ auto conv = std::make_shared<v1::Convolution>(reshape,+ conv_weight,+ ov::Strides{1, 1},+ ov::CoordinateDiff{1, 1},+ ov::CoordinateDiff{1, 1},+ ov::Strides{1, 1});model_ref = std::make_shared<ov::Model>(ov::OutputVector{conv}, ov::ParameterVector{input});}diff --git a/src/common/transformations/tests/common_optimizations/move_eltwise_up_data_movement_test.cpp b/src/common/transformations/tests/common_optimizations/move_eltwise_up_data_movement_test.cppindex 868f192a4c5..7090efd6c61 100644--- a/src/common/transformations/tests/common_optimizations/move_eltwise_up_data_movement_test.cpp+++ b/src/common/transformations/tests/common_optimizations/move_eltwise_up_data_movement_test.cpp@@ -27,6 +27,8 @@using namespace testing;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;class MoveEltwiseUpThroughDataMovTest : public TransformationTestsF {};TEST_F(MoveEltwiseUpThroughDataMovTest, SingleUnaryEltwise) {@@ -421,7 +423,7 @@ TEST_F(MoveEltwiseUpThroughDataMovTest, PerChannelEltwiseSqueeze) {auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, shape);auto squeeze_const = ov::opset8::Constant::create(ov::element::i64, ov::Shape{}, {2}); // {10, 20, 1}- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(input, squeeze_const);+ auto squeeze = std::make_shared<v0::Squeeze>(input, squeeze_const);auto per_channel_const = ov::opset8::Constant::create(ov::element::f32, {10, 1, 1}, {0.5});auto add = std::make_shared<ov::opset8::Add>(squeeze, per_channel_const);@@ -436,7 +438,7 @@ TEST_F(MoveEltwiseUpThroughDataMovTest, PerChannelEltwiseSqueeze) {auto add = std::make_shared<ov::opset8::Add>(input, per_channel_const);auto squeeze_const = ov::opset8::Constant::create(ov::element::i64, ov::Shape{}, {2}); // {10, 20, 1}- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(add, squeeze_const);+ auto squeeze = std::make_shared<v0::Squeeze>(add, squeeze_const);model_ref = std::make_shared<ov::Model>(ov::OutputVector{squeeze}, ov::ParameterVector{input});}@@ -448,7 +450,7 @@ TEST_F(MoveEltwiseUpThroughDataMovTest, PerChannelEltwiseSqueezeIllegal_1) {auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, shape);auto squeeze_const = ov::opset8::Constant::create(ov::element::i64, ov::Shape{}, {1}); // {10, 20}- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(input, squeeze_const);+ auto squeeze = std::make_shared<v0::Squeeze>(input, squeeze_const);auto per_channel_const = ov::opset8::Constant::create(ov::element::f32, {1, 1, 20}, {0.5});auto add = std::make_shared<ov::opset8::Add>(squeeze, per_channel_const);@@ -463,7 +465,7 @@ TEST_F(MoveEltwiseUpThroughDataMovTest, PerChannelEltwiseSqueezeIllegal_2) {auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, shape);auto squeeze_const = ov::opset8::Constant::create(ov::element::i64, ov::Shape{}, {2}); // {10, 20, 1}- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(input, squeeze_const);+ auto squeeze = std::make_shared<v0::Squeeze>(input, squeeze_const);auto per_channel_const1 = ov::opset8::Constant::create(ov::element::f32, {10, 1, 1}, {0.5});auto add1 = std::make_shared<ov::opset8::Add>(squeeze, per_channel_const1);@@ -484,11 +486,11 @@ TEST_F(MoveEltwiseUpThroughDataMovTest, PerChannelReshapeMultiply) {auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, shape);auto reshape_constant =- std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{target_shape.size()}, target_shape);- auto reshape = std::make_shared<ov::op::v1::Reshape>(input, reshape_constant, false);+ std::make_shared<v0::Constant>(ov::element::i64, ov::Shape{target_shape.size()}, target_shape);+ auto reshape = std::make_shared<v1::Reshape>(input, reshape_constant, false);auto per_channel_const = ov::opset8::Constant::create(ov::element::f32, {1, 3, 1, 1}, {0.5});- auto multiply = std::make_shared<ov::op::v1::Multiply>(reshape, per_channel_const);+ auto multiply = std::make_shared<v1::Multiply>(reshape, per_channel_const);model = std::make_shared<ov::Model>(ov::OutputVector{multiply}, ov::ParameterVector{input});manager.register_pass<ov::pass::MoveEltwiseUpThroughDataMov>();@@ -497,11 +499,11 @@ TEST_F(MoveEltwiseUpThroughDataMovTest, PerChannelReshapeMultiply) {auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, shape);auto per_channel_const = ov::opset8::Constant::create(ov::element::f32, {1, 3, 1}, {0.5});- auto multiply = std::make_shared<ov::op::v1::Multiply>(input, per_channel_const);+ auto multiply = std::make_shared<v1::Multiply>(input, per_channel_const);auto reshape_constant =- std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{target_shape.size()}, target_shape);- auto reshape = std::make_shared<ov::op::v1::Reshape>(multiply, reshape_constant, false);+ std::make_shared<v0::Constant>(ov::element::i64, ov::Shape{target_shape.size()}, target_shape);+ auto reshape = std::make_shared<v1::Reshape>(multiply, reshape_constant, false);model_ref = std::make_shared<ov::Model>(ov::OutputVector{reshape}, ov::ParameterVector{input});}diff --git a/src/common/transformations/tests/common_optimizations/ngraph_fq_transpose_test.cpp b/src/common/transformations/tests/common_optimizations/ngraph_fq_transpose_test.cppindex 52f2beccd92..8e69635d74e 100644--- a/src/common/transformations/tests/common_optimizations/ngraph_fq_transpose_test.cpp+++ b/src/common/transformations/tests/common_optimizations/ngraph_fq_transpose_test.cpp@@ -25,17 +25,19 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;TEST_F(TransformationTestsF, FQTransposeTest1) {{- auto data = ov::op::v0::Constant::create(element::f32, Shape{1, 1, 3}, {1, 2, 3});- auto input_low = ov::op::v0::Constant::create(element::f32, Shape{1}, {2});- auto input_high = ov::op::v0::Constant::create(element::f32, Shape{1}, {3});- auto output_low = ov::op::v0::Constant::create(element::f32, Shape{1}, {2});- auto output_high = ov::op::v0::Constant::create(element::f32, Shape{1}, {3});- auto transpose_order = ov::op::v0::Constant::create(element::i64, Shape{3}, {0, 2, 1});+ auto data = v0::Constant::create(element::f32, Shape{1, 1, 3}, {1, 2, 3});+ auto input_low = v0::Constant::create(element::f32, Shape{1}, {2});+ auto input_high = v0::Constant::create(element::f32, Shape{1}, {3});+ auto output_low = v0::Constant::create(element::f32, Shape{1}, {2});+ auto output_high = v0::Constant::create(element::f32, Shape{1}, {3});+ auto transpose_order = v0::Constant::create(element::i64, Shape{3}, {0, 2, 1});- auto fq = std::make_shared<ov::op::v0::FakeQuantize>(data, input_low, input_high, output_low, output_high, 1);- auto transpose = std::make_shared<ov::op::v1::Transpose>(fq, transpose_order);+ auto fq = std::make_shared<v0::FakeQuantize>(data, input_low, input_high, output_low, output_high, 1);+ auto transpose = std::make_shared<v1::Transpose>(fq, transpose_order);model = std::make_shared<ov::Model>(ov::OutputVector{transpose}, ParameterVector{});@@ -46,13 +48,13 @@ TEST_F(TransformationTestsF, FQTransposeTest1) {manager.register_pass<pass::ConstantFolding>();}{- auto data = ov::op::v0::Constant::create(element::f32, Shape{1, 3, 1}, {1, 2, 3});- auto input_low = ov::op::v0::Constant::create(element::f32, Shape{1, 1, 1}, {2});- auto input_high = ov::op::v0::Constant::create(element::f32, Shape{1, 1, 1}, {3});- auto output_low = ov::op::v0::Constant::create(element::f32, Shape{1, 1, 1}, {2});- auto output_high = ov::op::v0::Constant::create(element::f32, Shape{1, 1, 1}, {3});+ auto data = v0::Constant::create(element::f32, Shape{1, 3, 1}, {1, 2, 3});+ auto input_low = v0::Constant::create(element::f32, Shape{1, 1, 1}, {2});+ auto input_high = v0::Constant::create(element::f32, Shape{1, 1, 1}, {3});+ auto output_low = v0::Constant::create(element::f32, Shape{1, 1, 1}, {2});+ auto output_high = v0::Constant::create(element::f32, Shape{1, 1, 1}, {3});- auto fq = std::make_shared<ov::op::v0::FakeQuantize>(data, input_low, input_high, output_low, output_high, 1);+ auto fq = std::make_shared<v0::FakeQuantize>(data, input_low, input_high, output_low, output_high, 1);model_ref = std::make_shared<ov::Model>(ov::OutputVector{fq}, ParameterVector{});}@@ -60,17 +62,16 @@ TEST_F(TransformationTestsF, FQTransposeTest1) {TEST_F(TransformationTestsF, FQTransposeNegativeCase) {auto create_graph = []() -> std::shared_ptr<ov::Model> {- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{1, 3, 1});- auto sigmoid = std::make_shared<ov::op::v0::Sigmoid>(data);- auto input_low = ov::op::v0::Constant::create(element::f32, Shape{1}, {2});- auto input_high = ov::op::v0::Constant::create(element::f32, Shape{1}, {3});- auto output_low = ov::op::v0::Constant::create(element::f32, Shape{1}, {2});- auto output_high = ov::op::v0::Constant::create(element::f32, Shape{1}, {3});- auto transpose_order = ov::op::v0::Constant::create(element::i64, Shape{3}, {0, 2, 1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{1, 3, 1});+ auto sigmoid = std::make_shared<v0::Sigmoid>(data);+ auto input_low = v0::Constant::create(element::f32, Shape{1}, {2});+ auto input_high = v0::Constant::create(element::f32, Shape{1}, {3});+ auto output_low = v0::Constant::create(element::f32, Shape{1}, {2});+ auto output_high = v0::Constant::create(element::f32, Shape{1}, {3});+ auto transpose_order = v0::Constant::create(element::i64, Shape{3}, {0, 2, 1});- auto fq =- std::make_shared<ov::op::v0::FakeQuantize>(sigmoid, input_low, input_high, output_low, output_high, 1);- auto transpose = std::make_shared<ov::op::v1::Transpose>(fq, transpose_order);+ auto fq = std::make_shared<v0::FakeQuantize>(sigmoid, input_low, input_high, output_low, output_high, 1);+ auto transpose = std::make_shared<v1::Transpose>(fq, transpose_order);return std::make_shared<ov::Model>(ov::OutputVector{transpose}, ParameterVector{data});};diff --git a/src/common/transformations/tests/common_optimizations/nop_elimination.cpp b/src/common/transformations/tests/common_optimizations/nop_elimination.cppindex fdd3bc1667f..2201a73f43e 100644--- a/src/common/transformations/tests/common_optimizations/nop_elimination.cpp+++ b/src/common/transformations/tests/common_optimizations/nop_elimination.cpp@@ -27,6 +27,9 @@using namespace ov;using namespace std;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v5 = ov::op::v5;TEST(nop_elimination, shared_const_einsum_after_common_optimizations) {auto const_data = op::v0::Constant::create(element::f32, Shape{2, 2}, {1, 2, 3, 4});@@ -164,20 +167,20 @@ TEST(nop_elimination, reshape_v1_1D) {TEST(nop_elimination, squeeze_reshape_elimination_check_info) {std::shared_ptr<ov::Model> f;{- auto arg = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{8, 16, 1, 3});+ auto arg = std::make_shared<v0::Parameter>(element::f32, PartialShape{8, 16, 1, 3});- auto relu = std::make_shared<ov::op::v0::Relu>(arg);+ auto relu = std::make_shared<v0::Relu>(arg);relu->set_friendly_name("relu");- auto squeeze_axes = ov::op::v0::Constant::create(element::i64, Shape{1}, {2});- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(relu, squeeze_axes);+ auto squeeze_axes = v0::Constant::create(element::i64, Shape{1}, {2});+ auto squeeze = std::make_shared<v0::Squeeze>(relu, squeeze_axes);squeeze->set_friendly_name("squeeze");- auto reshape_shape = ov::op::v0::Constant::create(element::i64, Shape{4}, {8, 16, 1, 3});- auto reshape = std::make_shared<ov::op::v1::Reshape>(squeeze, reshape_shape, false);+ auto reshape_shape = v0::Constant::create(element::i64, Shape{4}, {8, 16, 1, 3});+ auto reshape = std::make_shared<v1::Reshape>(squeeze, reshape_shape, false);reshape->set_friendly_name("reshape");- auto abs = std::make_shared<ov::op::v0::Abs>(reshape);+ auto abs = std::make_shared<v0::Abs>(reshape);f = std::make_shared<ov::Model>(OutputVector{abs}, ParameterVector{arg});}@@ -199,20 +202,20 @@ TEST(nop_elimination, squeeze_reshape_elimination_check_info) {TEST(nop_elimination, squeeze_unsqueeze_elimination) {std::shared_ptr<ov::Model> f;{- auto arg = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{8, 16, 1, 3});+ auto arg = std::make_shared<v0::Parameter>(element::f32, PartialShape{8, 16, 1, 3});- auto relu = std::make_shared<ov::op::v0::Relu>(arg);+ auto relu = std::make_shared<v0::Relu>(arg);relu->set_friendly_name("relu");- auto squeeze_axes = ov::op::v0::Constant::create(element::i64, Shape{1}, {2});- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(relu, squeeze_axes);+ auto squeeze_axes = v0::Constant::create(element::i64, Shape{1}, {2});+ auto squeeze = std::make_shared<v0::Squeeze>(relu, squeeze_axes);squeeze->set_friendly_name("squeeze");- auto unsqueeze_axes = ov::op::v0::Constant::create(element::i64, Shape{1}, {2});- auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(squeeze, unsqueeze_axes);+ auto unsqueeze_axes = v0::Constant::create(element::i64, Shape{1}, {2});+ auto unsqueeze = std::make_shared<v0::Unsqueeze>(squeeze, unsqueeze_axes);unsqueeze->set_friendly_name("unsqueeze");- auto abs = std::make_shared<ov::op::v0::Abs>(unsqueeze);+ auto abs = std::make_shared<v0::Abs>(unsqueeze);f = std::make_shared<ov::Model>(OutputVector{abs}, ParameterVector{arg});}@@ -234,13 +237,13 @@ TEST(nop_elimination, squeeze_unsqueeze_elimination) {TEST(nop_elimination, squeeze_unsqueeze_elimination_dynamic_without_squeeze_axis) {std::shared_ptr<ov::Model> f;{- auto arg = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, 16, 1, 3});+ auto arg = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, 16, 1, 3});- auto squeeze = std::make_shared<ov::op::v0::Squeeze>(arg);+ auto squeeze = std::make_shared<v0::Squeeze>(arg);squeeze->set_friendly_name("squeeze");- auto unsqueeze_axes = ov::op::v0::Constant::create(element::i64, Shape{1}, {2});- auto unsqueeze = std::make_shared<ov::op::v0::Unsqueeze>(squeeze, unsqueeze_axes);+ auto unsqueeze_axes = v0::Constant::create(element::i64, Shape{1}, {2});+ auto unsqueeze = std::make_shared<v0::Unsqueeze>(squeeze, unsqueeze_axes);unsqueeze->set_friendly_name("unsqueeze");f = std::make_shared<ov::Model>(OutputVector{unsqueeze}, ParameterVector{arg});@@ -298,7 +301,7 @@ TEST(nop_elimination, reshape_elimination_v1_dynamic_negative) {TEST(nop_elimination, reshape_arithmetical_reduce_elimination_dynamic) {auto arg = std::make_shared<op::v0::Parameter>(element::i64, PartialShape({-1, 96, 100, 100}));- auto reduce_axes = ov::op::v0::Constant::create(element::i64, Shape{2}, {2, 3});+ auto reduce_axes = v0::Constant::create(element::i64, Shape{2}, {2, 3});auto reduce = std::make_shared<op::v1::ReduceMean>(arg, reduce_axes, true);auto pattern = op::v0::Constant::create(element::i64, Shape{4}, {0, 96, 1, 1});auto reshape_v1 = std::make_shared<op::v1::Reshape>(reduce, pattern, true);@@ -312,7 +315,7 @@ TEST(nop_elimination, reshape_arithmetical_reduce_elimination_dynamic) {TEST(nop_elimination, reshape_logical_reduce_elimination_dynamic) {auto arg = std::make_shared<op::v0::Parameter>(element::boolean, PartialShape({-1, 96, 100, 100}));- auto reduce_axes = ov::op::v0::Constant::create(element::i64, Shape{2}, {2, 3});+ auto reduce_axes = v0::Constant::create(element::i64, Shape{2}, {2, 3});auto reduce = std::make_shared<op::v1::ReduceLogicalAnd>(arg, reduce_axes, true);auto pattern = op::v0::Constant::create(element::i64, Shape{4}, {0, 96, 1, 1});auto reshape_v1 = std::make_shared<op::v1::Reshape>(reduce, pattern, true);@@ -327,17 +330,17 @@ TEST(nop_elimination, reshape_logical_reduce_elimination_dynamic) {TEST(nop_elimination, reshape_elimination_v1_check_consumer_count) {std::shared_ptr<ov::Model> f;{- auto arg = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{8, 16, 1, 3});+ auto arg = std::make_shared<v0::Parameter>(element::f32, PartialShape{8, 16, 1, 3});- auto reshape_1_shape = ov::op::v0::Constant::create(element::i64, Shape{2}, {128, 3});- auto reshape_1 = std::make_shared<ov::op::v1::Reshape>(arg, reshape_1_shape, false);+ auto reshape_1_shape = v0::Constant::create(element::i64, Shape{2}, {128, 3});+ auto reshape_1 = std::make_shared<v1::Reshape>(arg, reshape_1_shape, false);reshape_1->set_friendly_name("reshape_1");- auto reshape_2_shape = ov::op::v0::Constant::create(element::i64, Shape{4}, {8, 16, 1, 3});- auto reshape_2 = std::make_shared<ov::op::v1::Reshape>(reshape_1, reshape_2_shape, false);+ auto reshape_2_shape = v0::Constant::create(element::i64, Shape{4}, {8, 16, 1, 3});+ auto reshape_2 = std::make_shared<v1::Reshape>(reshape_1, reshape_2_shape, false);reshape_2->set_friendly_name("reshape_2");- auto relu = std::make_shared<ov::op::v0::Relu>(reshape_1);+ auto relu = std::make_shared<v0::Relu>(reshape_1);relu->set_friendly_name("relu");f = std::make_shared<ov::Model>(OutputVector{reshape_2, relu}, ParameterVector{arg});@@ -886,14 +889,14 @@ TEST(nop_elimination, squeeze_unsqueeze_elimination_negative) {auto check_usecase = [](const Shape& shape, const std::vector<int64_t>& indices_val) {auto indices = op::v0::Constant::create(element::i64, Shape{indices_val.size()}, indices_val);auto input = make_shared<op::v0::Parameter>(element::f32, shape);- auto squeeze = make_shared<ov::op::v0::Squeeze>(input, indices);+ auto squeeze = make_shared<v0::Squeeze>(input, indices);auto baseline_f = make_shared<ov::Model>(squeeze, ParameterVector{input});auto optimized_f = baseline_f->clone();pass::Manager manager;manager.register_pass<ov::pass::NopElimination>();manager.run_passes(optimized_f);- ASSERT_EQ(count_ops_of_type<ov::op::v0::Squeeze>(baseline_f), 1);- ASSERT_EQ(count_ops_of_type<ov::op::v0::Squeeze>(optimized_f), 1);+ ASSERT_EQ(count_ops_of_type<v0::Squeeze>(baseline_f), 1);+ ASSERT_EQ(count_ops_of_type<v0::Squeeze>(optimized_f), 1);};check_usecase(Shape{1, 1, 1}, std::vector<int64_t>{0, 1, 2});@@ -1121,7 +1124,7 @@ TEST_P(EliminateEltwiseTests, eliminate_eltwise) {}if (type_params.op_type == OpType::SUBTRACT_WITH_CONVERT) {- constant = std::make_shared<ov::op::v0::Convert>(constant, type);+ constant = std::make_shared<v0::Convert>(constant, type);}shared_ptr<Node> A = parameter;@@ -1137,28 +1140,28 @@ TEST_P(EliminateEltwiseTests, eliminate_eltwise) {shared_ptr<Node> node;switch (type_params.op_type) {case OpType::ADD:- node = make_shared<ov::op::v1::Add>(A, B);+ node = make_shared<v1::Add>(A, B);break;case OpType::SUBTRACT:case OpType::SUBTRACT_WITH_CONVERT:- node = make_shared<ov::op::v1::Subtract>(A, B);+ node = make_shared<v1::Subtract>(A, B);break;case OpType::MULTIPLY:- node = make_shared<ov::op::v1::Multiply>(A, B);+ node = make_shared<v1::Multiply>(A, B);break;case OpType::DIVIDE:- node = make_shared<ov::op::v1::Divide>(A, B);+ node = make_shared<v1::Divide>(A, B);break;default:ASSERT_FALSE(true) << "Invalid OpType";}- auto abs = make_shared<ov::op::v0::Abs>(node);+ auto abs = make_shared<v0::Abs>(node);model = make_shared<ov::Model>(abs, ParameterVector{parameter});manager.register_pass<ov::pass::NopElimination>();if (can_fuse) {- auto abs = make_shared<ov::op::v0::Abs>(parameter);+ auto abs = make_shared<v0::Abs>(parameter);model_ref = make_shared<ov::Model>(abs, ParameterVector{parameter});}@@ -1231,16 +1234,16 @@ INSTANTIATE_TEST_SUITE_P(EliminateEltwise,TEST_F(TransformationTestsF, eliminate_eltwise_dequantization_subgraph) {{- auto constant = ov::op::v0::Constant::create(element::i8, Shape{}, {2});- auto convert = make_shared<ov::op::v0::Convert>(constant, element::f32);- auto sub = make_shared<ov::op::v1::Subtract>(convert, ov::op::v0::Constant::create(element::f32, Shape{}, {0}));- auto mul = make_shared<ov::op::v1::Multiply>(sub, ov::op::v0::Constant::create(element::f32, Shape{}, {1}));+ auto constant = v0::Constant::create(element::i8, Shape{}, {2});+ auto convert = make_shared<v0::Convert>(constant, element::f32);+ auto sub = make_shared<v1::Subtract>(convert, v0::Constant::create(element::f32, Shape{}, {0}));+ auto mul = make_shared<v1::Multiply>(sub, v0::Constant::create(element::f32, Shape{}, {1}));model = make_shared<ov::Model>(mul, ParameterVector{});}{- auto constant = ov::op::v0::Constant::create(element::i8, Shape{}, {2});- auto convert = make_shared<ov::op::v0::Convert>(constant, element::f32);- auto mul = make_shared<ov::op::v1::Multiply>(convert, ov::op::v0::Constant::create(element::f32, Shape{}, {1}));+ auto constant = v0::Constant::create(element::i8, Shape{}, {2});+ auto convert = make_shared<v0::Convert>(constant, element::f32);+ auto mul = make_shared<v1::Multiply>(convert, v0::Constant::create(element::f32, Shape{}, {1}));model_ref = make_shared<ov::Model>(mul, ParameterVector{});}@@ -1282,51 +1285,51 @@ TEST_P(SplitConcatElimination, eliminate_split_concat_subgraph) {EXPECT_TRUE(seq_len % p.split_len == 0) << "Seq_len must be divisible by split_len.";ParameterVector params;- auto param = make_shared<ov::op::v0::Parameter>(element::f32, Shape{batch, seq_len, input_size});+ auto param = make_shared<v0::Parameter>(element::f32, Shape{batch, seq_len, input_size});shared_ptr<Node> data = param;shared_ptr<Node> sequence;auto gate = static_cast<size_t>(p.rnn_type);- auto axis_const = make_shared<ov::op::v0::Constant>(element::i64, Shape{}, p.split_axis);- auto H = make_shared<ov::op::v0::Parameter>(element::f32, Shape{batch, num_dir, hidden_size});- auto C = make_shared<ov::op::v0::Parameter>(element::f32, Shape{batch, num_dir, hidden_size});- auto seq_lengths = make_shared<ov::op::v0::Parameter>(element::i64, Shape{batch});- auto W = make_shared<ov::op::v0::Parameter>(element::f32, Shape{num_dir, gate * hidden_size, input_size});- auto R = make_shared<ov::op::v0::Parameter>(element::f32, Shape{num_dir, gate * hidden_size, hidden_size});- auto B = make_shared<ov::op::v0::Parameter>(element::f32, Shape{num_dir, gate * hidden_size});+ auto axis_const = make_shared<v0::Constant>(element::i64, Shape{}, p.split_axis);+ auto H = make_shared<v0::Parameter>(element::f32, Shape{batch, num_dir, hidden_size});+ auto C = make_shared<v0::Parameter>(element::f32, Shape{batch, num_dir, hidden_size});+ auto seq_lengths = make_shared<v0::Parameter>(element::i64, Shape{batch});+ auto W = make_shared<v0::Parameter>(element::f32, Shape{num_dir, gate * hidden_size, input_size});+ auto R = make_shared<v0::Parameter>(element::f32, Shape{num_dir, gate * hidden_size, hidden_size});+ auto B = make_shared<v0::Parameter>(element::f32, Shape{num_dir, gate * hidden_size});auto direction = op::RecurrentSequenceDirection::FORWARD;if (p.rnn_type == RNNType::RNN) {- sequence = make_shared<ov::op::v5::RNNSequence>(data, H, seq_lengths, W, R, B, hidden_size, direction);- data = make_shared<ov::op::v0::Squeeze>(sequence->output(0), axis_const);+ sequence = make_shared<v5::RNNSequence>(data, H, seq_lengths, W, R, B, hidden_size, direction);+ data = make_shared<v0::Squeeze>(sequence->output(0), axis_const);params = {H, seq_lengths, W, R, B};} else if (p.rnn_type == RNNType::GRU) {- sequence = make_shared<ov::op::v5::GRUSequence>(data, H, seq_lengths, W, R, B, hidden_size, direction);- data = make_shared<ov::op::v0::Squeeze>(sequence->output(0), axis_const);+ sequence = make_shared<v5::GRUSequence>(data, H, seq_lengths, W, R, B, hidden_size, direction);+ data = make_shared<v0::Squeeze>(sequence->output(0), axis_const);params = {H, seq_lengths, W, R, B};} else if (p.rnn_type == RNNType::LSTM) {- sequence = make_shared<ov::op::v5::LSTMSequence>(data, H, C, seq_lengths, W, R, B, hidden_size, direction);- data = make_shared<ov::op::v0::Squeeze>(sequence->output(0), axis_const);+ sequence = make_shared<v5::LSTMSequence>(data, H, C, seq_lengths, W, R, B, hidden_size, direction);+ data = make_shared<v0::Squeeze>(sequence->output(0), axis_const);params = {H, C, seq_lengths, W, R, B};}params.push_back(param);shared_ptr<ov::Node> split;if (p.split_type == SplitType::Split) {- split = make_shared<ov::op::v1::Split>(data->output(0), axis_const, p.seq_len / p.split_len);+ split = make_shared<v1::Split>(data->output(0), axis_const, p.seq_len / p.split_len);} else if (p.split_type == SplitType::VariadicSplit) {- auto split_lengths = make_shared<ov::op::v0::Constant>(element::i64,- Shape{seq_len / p.split_len},- std::vector<size_t>(seq_len / p.split_len, p.split_len));- split = make_shared<ov::op::v1::VariadicSplit>(data->output(0), axis_const, split_lengths);+ auto split_lengths = make_shared<v0::Constant>(element::i64,+ Shape{seq_len / p.split_len},+ std::vector<size_t>(seq_len / p.split_len, p.split_len));+ split = make_shared<v1::VariadicSplit>(data->output(0), axis_const, split_lengths);}auto outputs_to_concat = split->outputs();if (sequence) {outputs_to_concat[outputs_to_concat.size() - 1] = sequence->output(1);}- auto concat = make_shared<ov::op::v0::Concat>(outputs_to_concat, p.concat_axis);- auto sigmoid = make_shared<ov::op::v0::Sigmoid>(concat);- auto res = make_shared<ov::op::v0::Result>(sigmoid);+ auto concat = make_shared<v0::Concat>(outputs_to_concat, p.concat_axis);+ auto sigmoid = make_shared<v0::Sigmoid>(concat);+ auto res = make_shared<v0::Result>(sigmoid);auto model = make_shared<ov::Model>(ResultVector{res}, ParameterVector{params});pass::Manager pass_manager;@@ -1337,12 +1340,11 @@ TEST_P(SplitConcatElimination, eliminate_split_concat_subgraph) {// the transformation won't be applied if split_len is not equal to 1size_t expect_concat = p.split_len == 1 ? 0 : 1;size_t expect_split = p.split_len == 1 ? 0 : 1;- EXPECT_EQ(count_ops_of_type<ov::op::v0::Concat>(model), expect_concat)+ EXPECT_EQ(count_ops_of_type<v0::Concat>(model), expect_concat)<< "SplitConcatElimination transformation has failed. ""The number of Concat ops is not " +to_string(expect_concat);- EXPECT_EQ(count_ops_of_type<ov::op::v1::Split>(model) + count_ops_of_type<ov::op::v1::VariadicSplit>(model),- expect_split)+ EXPECT_EQ(count_ops_of_type<v1::Split>(model) + count_ops_of_type<v1::VariadicSplit>(model), expect_split)<< "SplitConcatElimination transformation has failed. ""The number of Split/VariadicSplit ops is not " +to_string(expect_split);@@ -1366,17 +1368,17 @@ INSTANTIATE_TEST_SUITE_P(SplitConcatElimination, SplitConcatElimination, testingTEST(SplitConcatElimination, split_inputs_not_in_order) {int64_t axis = 1;- auto axis_const = make_shared<ov::op::v0::Constant>(element::i64, Shape{}, axis);+ auto axis_const = make_shared<v0::Constant>(element::i64, Shape{}, axis);- auto param = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10});- auto split = make_shared<ov::op::v1::Split>(param->output(0), axis_const, 10);+ auto param = make_shared<v0::Parameter>(element::f32, Shape{2, 10});+ auto split = make_shared<v1::Split>(param->output(0), axis_const, 10);OutputVector outputs_to_concat = split->outputs();// change order of inputs to Concat, in this case the transformation won't be appliedstd::reverse(outputs_to_concat.begin(), outputs_to_concat.end());- auto concat = make_shared<ov::op::v0::Concat>(outputs_to_concat, axis);- auto sigmoid = make_shared<ov::op::v0::Sigmoid>(concat);- auto res = make_shared<ov::op::v0::Result>(sigmoid);+ auto concat = make_shared<v0::Concat>(outputs_to_concat, axis);+ auto sigmoid = make_shared<v0::Sigmoid>(concat);+ auto res = make_shared<v0::Result>(sigmoid);auto model = make_shared<ov::Model>(ResultVector{res}, ParameterVector{param});pass::Manager pass_manager;@@ -1384,25 +1386,25 @@ TEST(SplitConcatElimination, split_inputs_not_in_order) {pass_manager.register_pass<ov::pass::NopElimination>();pass_manager.run_passes(model);// the transformation shouldn't be applied- EXPECT_EQ(count_ops_of_type<ov::op::v0::Concat>(model), 1) << "SplitConcatElimination transformation has failed. "- "The number of Concat ops is not 1";- EXPECT_EQ(count_ops_of_type<ov::op::v1::Split>(model), 1) << "SplitConcatElimination transformation has failed. "- "The number of Split ops is not 1";+ EXPECT_EQ(count_ops_of_type<v0::Concat>(model), 1) << "SplitConcatElimination transformation has failed. "+ "The number of Concat ops is not 1";+ EXPECT_EQ(count_ops_of_type<v1::Split>(model), 1) << "SplitConcatElimination transformation has failed. "+ "The number of Split ops is not 1";}TEST(SplitConcatElimination, no_sequence_found) {int64_t axis = 1;- auto axis_const = make_shared<ov::op::v0::Constant>(element::i64, Shape{}, axis);+ auto axis_const = make_shared<v0::Constant>(element::i64, Shape{}, axis);- auto param = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10});- auto param_2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 1});- auto split = make_shared<ov::op::v1::Split>(param->output(0), axis_const, 10);+ auto param = make_shared<v0::Parameter>(element::f32, Shape{2, 10});+ auto param_2 = make_shared<v0::Parameter>(element::f32, Shape{2, 1});+ auto split = make_shared<v1::Split>(param->output(0), axis_const, 10);OutputVector outputs_to_concat = split->outputs();outputs_to_concat[outputs_to_concat.size() - 1] = param_2;- auto concat = make_shared<ov::op::v0::Concat>(outputs_to_concat, axis);- auto sigmoid = make_shared<ov::op::v0::Sigmoid>(concat);- auto res = make_shared<ov::op::v0::Result>(sigmoid);+ auto concat = make_shared<v0::Concat>(outputs_to_concat, axis);+ auto sigmoid = make_shared<v0::Sigmoid>(concat);+ auto res = make_shared<v0::Result>(sigmoid);auto model = make_shared<ov::Model>(ResultVector{res}, ParameterVector{param, param_2});pass::Manager pass_manager;@@ -1410,10 +1412,10 @@ TEST(SplitConcatElimination, no_sequence_found) {pass_manager.register_pass<ov::pass::NopElimination>();pass_manager.run_passes(model);// the transformation shouldn't be applied- EXPECT_EQ(count_ops_of_type<ov::op::v0::Concat>(model), 1) << "SplitConcatElimination transformation has failed. "- "The number of Concat ops is not 1";- EXPECT_EQ(count_ops_of_type<ov::op::v1::Split>(model), 1) << "SplitConcatElimination transformation has failed. "- "The number of Split ops is not 1";+ EXPECT_EQ(count_ops_of_type<v0::Concat>(model), 1) << "SplitConcatElimination transformation has failed. "+ "The number of Concat ops is not 1";+ EXPECT_EQ(count_ops_of_type<v1::Split>(model), 1) << "SplitConcatElimination transformation has failed. "+ "The number of Split ops is not 1";}TEST(nop_elimination, gather_to_squeeze) {@@ -1474,84 +1476,84 @@ TEST(nop_elimination, not_gather_to_squeeze_with_vector_indices) {TEST_F(TransformationTestsF, Nopv1Broadcast) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});- auto broadcast_shape = ov::op::v0::Constant::create(element::i32, Shape{4}, {1, 1, 1, 1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto broadcast_shape = v0::Constant::create(element::i32, Shape{4}, {1, 1, 1, 1});auto broadcast = std::make_shared<op::v1::Broadcast>(data, broadcast_shape);auto relu = std::make_shared<op::v0::Relu>(broadcast);- auto result = std::make_shared<ov::op::v0::Result>(relu);+ auto result = std::make_shared<v0::Result>(relu);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{data});manager.register_pass<ov::pass::EliminateNopBroadcast>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});auto relu = std::make_shared<op::v0::Relu>(data);- auto result = std::make_shared<ov::op::v0::Result>(relu);+ auto result = std::make_shared<v0::Result>(relu);model_ref = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{data});}}TEST_F(TransformationTestsF, Nopv3Broadcast) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});- auto broadcast_shape = ov::op::v0::Constant::create(element::i32, Shape{4}, {1, 1, 1, 1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto broadcast_shape = v0::Constant::create(element::i32, Shape{4}, {1, 1, 1, 1});auto broadcast = std::make_shared<op::v3::Broadcast>(data, broadcast_shape);auto relu = std::make_shared<op::v0::Relu>(broadcast);- auto result = std::make_shared<ov::op::v0::Result>(relu);+ auto result = std::make_shared<v0::Result>(relu);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{data});manager.register_pass<ov::pass::EliminateNopBroadcast>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});auto relu = std::make_shared<op::v0::Relu>(data);- auto result = std::make_shared<ov::op::v0::Result>(relu);+ auto result = std::make_shared<v0::Result>(relu);model_ref = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{data});}}TEST_F(TransformationTestsF, NopTile) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});- auto repeats = ov::op::v0::Constant::create(element::i32, Shape{4}, {1, 1, 1, 1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto repeats = v0::Constant::create(element::i32, Shape{4}, {1, 1, 1, 1});auto tile = std::make_shared<op::v0::Tile>(data, repeats);auto relu = std::make_shared<op::v0::Relu>(tile);- auto result = std::make_shared<ov::op::v0::Result>(relu);+ auto result = std::make_shared<v0::Result>(relu);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{data});manager.register_pass<ov::pass::EliminateNopBroadcast>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});auto relu = std::make_shared<op::v0::Relu>(data);- auto result = std::make_shared<ov::op::v0::Result>(relu);+ auto result = std::make_shared<v0::Result>(relu);model_ref = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{data});}}TEST_F(TransformationTestsF, EliminateSliceBeforeGatherElements) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});- auto start = ov::op::v0::Constant::create(element::i32, Shape{1}, {0});- auto stop = ov::op::v0::Constant::create(element::i32, Shape{1}, {2});- auto step = ov::op::v0::Constant::create(element::i32, Shape{1}, {1});- auto axis = ov::op::v0::Constant::create(element::i32, Shape{1}, {-1});+ auto start = v0::Constant::create(element::i32, Shape{1}, {0});+ auto stop = v0::Constant::create(element::i32, Shape{1}, {2});+ auto step = v0::Constant::create(element::i32, Shape{1}, {1});+ auto axis = v0::Constant::create(element::i32, Shape{1}, {-1});auto slice = std::make_shared<op::v8::Slice>(data, start, stop, step, axis);- auto indices = std::make_shared<ov::op::v0::Parameter>(element::i64, PartialShape{-1, -1, -1, -1});+ auto indices = std::make_shared<v0::Parameter>(element::i64, PartialShape{-1, -1, -1, -1});auto gather_elements = std::make_shared<op::v6::GatherElements>(slice, indices, 2);auto relu = std::make_shared<op::v0::Relu>(gather_elements);- auto result = std::make_shared<ov::op::v0::Result>(relu);+ auto result = std::make_shared<v0::Result>(relu);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{data, indices});manager.register_pass<ov::pass::EliminateSliceBeforeGatherElements>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});- auto indices = std::make_shared<ov::op::v0::Parameter>(element::i64, PartialShape{-1, -1, -1, -1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{-1, -1, -1, -1});+ auto indices = std::make_shared<v0::Parameter>(element::i64, PartialShape{-1, -1, -1, -1});auto gather_elements = std::make_shared<op::v6::GatherElements>(data, indices, 2);auto relu = std::make_shared<op::v0::Relu>(gather_elements);- auto result = std::make_shared<ov::op::v0::Result>(relu);+ auto result = std::make_shared<v0::Result>(relu);model_ref = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{data, indices});}}@@ -1559,31 +1561,31 @@ TEST_F(TransformationTestsF, EliminateSliceBeforeGatherElements) {TEST_F(TransformationTestsF, EliminateConcatStridedSlice) {{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 4});- auto param3 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 5});- auto param4 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 6});- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({param1, param2, param3, param4}), axis);-- auto begin_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});- auto end_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});- auto strided_slice1 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const1,- end_const1,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 4});+ auto param3 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 5});+ auto param4 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 6});+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({param1, param2, param3, param4}), axis);++ auto begin_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});+ auto end_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});+ auto strided_slice1 = std::make_shared<v1::StridedSlice>(concat,+ begin_const1,+ end_const1,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});auto add_param = make_shared<op::v0::Parameter>(element::f32, Shape{2, 10, 3});auto add = std::make_shared<op::v1::Add>(strided_slice1, add_param);auto result1 = std::make_shared<op::v0::Result>(add);- auto begin_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});- auto end_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 18});- auto strided_slice2 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const2,- end_const2,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});+ auto begin_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});+ auto end_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 18});+ auto strided_slice2 = std::make_shared<v1::StridedSlice>(concat,+ begin_const2,+ end_const2,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});auto relu = std::make_shared<op::v0::Relu>(strided_slice2);auto result2 = std::make_shared<op::v0::Result>(relu);@@ -1593,22 +1595,22 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSlice) {}{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 4});- auto param3 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 5});- auto param4 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 6});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 4});+ auto param3 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 5});+ auto param4 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 6});auto add_param = make_shared<op::v0::Parameter>(element::f32, Shape{2, 10, 3});auto add = std::make_shared<op::v1::Add>(param1, add_param);auto result1 = std::make_shared<op::v0::Result>(add);- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({param2, param3, param4}), axis);- auto begin_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});- auto end_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 15});- auto strided_slice2 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const2,- end_const2,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({param2, param3, param4}), axis);+ auto begin_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});+ auto end_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 15});+ auto strided_slice2 = std::make_shared<v1::StridedSlice>(concat,+ begin_const2,+ end_const2,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});auto relu = std::make_shared<op::v0::Relu>(strided_slice2);auto result2 = std::make_shared<op::v0::Result>(relu);@@ -1620,28 +1622,28 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSlice) {TEST_F(TransformationTestsF, EliminateConcatStridedSliceAll) {{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 1});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 1});- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({param1, param2}), axis);-- auto begin_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});- auto end_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 1});- auto strided_slice1 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const1,- end_const1,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 1});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 1});+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({param1, param2}), axis);++ auto begin_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});+ auto end_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 1});+ auto strided_slice1 = std::make_shared<v1::StridedSlice>(concat,+ begin_const1,+ end_const1,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});auto relu1 = std::make_shared<op::v0::Relu>(strided_slice1);auto result1 = std::make_shared<op::v0::Result>(relu1);- auto begin_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 1});- auto end_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 4});- auto strided_slice2 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const2,- end_const2,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});+ auto begin_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 1});+ auto end_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 4});+ auto strided_slice2 = std::make_shared<v1::StridedSlice>(concat,+ begin_const2,+ end_const2,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});auto relu2 = std::make_shared<op::v0::Relu>(strided_slice2);auto result2 = std::make_shared<op::v0::Result>(relu2);@@ -1649,8 +1651,8 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSliceAll) {manager.register_pass<ov::pass::EliminateConcatStridedSlice>();}{- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 1});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 1});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 1});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 1});auto relu1 = std::make_shared<op::v0::Relu>(param1);auto result1 = std::make_shared<op::v0::Result>(relu1);@@ -1665,28 +1667,28 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSliceAll) {TEST_F(TransformationTestsF, EliminateConcatStridedSliceConcat) {{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 4});- auto param3 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 5});- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);-- auto begin_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});- auto end_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});- auto strided_slice1 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const1,- end_const1,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 4});+ auto param3 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 5});+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);++ auto begin_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});+ auto end_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});+ auto strided_slice1 = std::make_shared<v1::StridedSlice>(concat,+ begin_const1,+ end_const1,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});auto relu = std::make_shared<op::v0::Relu>(strided_slice1);- auto begin_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});- auto end_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 12});- auto strided_slice2 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const2,- end_const2,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});- auto concat1 = make_shared<ov::op::v0::Concat>(ov::as_output_vector({relu, strided_slice2}), axis);+ auto begin_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});+ auto end_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 12});+ auto strided_slice2 = std::make_shared<v1::StridedSlice>(concat,+ begin_const2,+ end_const2,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});+ auto concat1 = make_shared<v0::Concat>(ov::as_output_vector({relu, strided_slice2}), axis);auto result = std::make_shared<op::v0::Result>(concat1);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{param1, param2, param3});@@ -1694,12 +1696,12 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSliceConcat) {}{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 4});- auto param3 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 5});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 4});+ auto param3 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 5});auto relu = std::make_shared<op::v0::Relu>(param1);- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({relu, param2, param3}), axis);+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({relu, param2, param3}), axis);auto result = std::make_shared<op::v0::Result>(concat);model_ref = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{param1, param2, param3});@@ -1709,28 +1711,28 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSliceConcat) {TEST_F(TransformationTestsF, EliminateConcatStridedSliceConcatMismatch) {{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 4});- auto param3 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 5});- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);-- auto begin_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});- auto end_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 4});- auto strided_slice1 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const1,- end_const1,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 4});+ auto param3 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 5});+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);++ auto begin_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});+ auto end_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 4});+ auto strided_slice1 = std::make_shared<v1::StridedSlice>(concat,+ begin_const1,+ end_const1,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});auto relu = std::make_shared<op::v0::Relu>(strided_slice1);- auto begin_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});- auto end_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 10});- auto strided_slice2 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const2,- end_const2,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});- auto concat1 = make_shared<ov::op::v0::Concat>(ov::as_output_vector({relu, strided_slice2}), axis);+ auto begin_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});+ auto end_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 10});+ auto strided_slice2 = std::make_shared<v1::StridedSlice>(concat,+ begin_const2,+ end_const2,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});+ auto concat1 = make_shared<v0::Concat>(ov::as_output_vector({relu, strided_slice2}), axis);auto result = std::make_shared<op::v0::Result>(concat1);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{param1, param2, param3});@@ -1738,28 +1740,28 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSliceConcatMismatch) {}{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 4});- auto param3 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 5});- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);-- auto begin_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});- auto end_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 4});- auto strided_slice1 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const1,- end_const1,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 4});+ auto param3 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 5});+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);++ auto begin_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});+ auto end_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 4});+ auto strided_slice1 = std::make_shared<v1::StridedSlice>(concat,+ begin_const1,+ end_const1,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});auto relu = std::make_shared<op::v0::Relu>(strided_slice1);- auto begin_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});- auto end_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 10});- auto strided_slice2 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const2,- end_const2,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});- auto concat1 = make_shared<ov::op::v0::Concat>(ov::as_output_vector({relu, strided_slice2}), axis);+ auto begin_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});+ auto end_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 10});+ auto strided_slice2 = std::make_shared<v1::StridedSlice>(concat,+ begin_const2,+ end_const2,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});+ auto concat1 = make_shared<v0::Concat>(ov::as_output_vector({relu, strided_slice2}), axis);auto result = std::make_shared<op::v0::Result>(concat1);model_ref = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{param1, param2, param3});@@ -1769,32 +1771,32 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSliceConcatMismatch) {TEST_F(TransformationTestsF, EliminateConcatStridedSliceTopKConcat) {{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 10, 4});- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({param1, param2}), axis);-- auto begin_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});- auto end_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});- auto strided_slice1 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const1,- end_const1,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});- auto topk = std::make_shared<ov::op::v1::TopK>(strided_slice1,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {1}),- axis,- op::v1::TopK::Mode::MAX,- op::v1::TopK::SortType::NONE);-- auto begin_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});- auto end_const2 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 7});- auto strided_slice2 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const2,- end_const2,- std::vector<int64_t>{1, 1, 0},- std::vector<int64_t>{1, 1, 0});- auto topk_values = std::make_shared<ov::op::v0::Result>(topk->output(0));- auto concat1 = make_shared<ov::op::v0::Concat>(ov::as_output_vector({topk_values, strided_slice2}), axis);+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{1, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{1, 10, 4});+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({param1, param2}), axis);++ auto begin_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});+ auto end_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});+ auto strided_slice1 = std::make_shared<v1::StridedSlice>(concat,+ begin_const1,+ end_const1,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});+ auto topk = std::make_shared<v1::TopK>(strided_slice1,+ v0::Constant::create(ov::element::i64, ov::Shape{}, {1}),+ axis,+ op::v1::TopK::Mode::MAX,+ op::v1::TopK::SortType::NONE);++ auto begin_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 3});+ auto end_const2 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 7});+ auto strided_slice2 = std::make_shared<v1::StridedSlice>(concat,+ begin_const2,+ end_const2,+ std::vector<int64_t>{1, 1, 0},+ std::vector<int64_t>{1, 1, 0});+ auto topk_values = std::make_shared<v0::Result>(topk->output(0));+ auto concat1 = make_shared<v0::Concat>(ov::as_output_vector({topk_values, strided_slice2}), axis);auto result = std::make_shared<op::v0::Result>(concat1);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{param1, param2});@@ -1802,16 +1804,16 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSliceTopKConcat) {}{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 10, 4});- auto axis_const = std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{}, axis);- auto topk = std::make_shared<ov::op::v1::TopK>(param1,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {1}),- axis,- op::v1::TopK::Mode::MAX,- op::v1::TopK::SortType::NONE);- auto topk_values = std::make_shared<ov::op::v0::Result>(topk->output(0));- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({topk_values, param2}), axis);+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{1, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{1, 10, 4});+ auto axis_const = std::make_shared<v0::Constant>(ov::element::i64, ov::Shape{}, axis);+ auto topk = std::make_shared<v1::TopK>(param1,+ v0::Constant::create(ov::element::i64, ov::Shape{}, {1}),+ axis,+ op::v1::TopK::Mode::MAX,+ op::v1::TopK::SortType::NONE);+ auto topk_values = std::make_shared<v0::Result>(topk->output(0));+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({topk_values, param2}), axis);auto result = std::make_shared<op::v0::Result>(concat);model_ref = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{param1, param2});}@@ -1820,18 +1822,18 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSliceTopKConcat) {TEST_F(TransformationTestsF, EliminateConcatStridedSliceConcatDiffAxis) {{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 4});- auto param3 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 5});- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);-- auto begin_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});- auto end_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 3, 0});- auto strided_slice1 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const1,- end_const1,- std::vector<int64_t>{1, 0, 1},- std::vector<int64_t>{1, 0, 1});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 4});+ auto param3 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 5});+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);++ auto begin_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});+ auto end_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 3, 0});+ auto strided_slice1 = std::make_shared<v1::StridedSlice>(concat,+ begin_const1,+ end_const1,+ std::vector<int64_t>{1, 0, 1},+ std::vector<int64_t>{1, 0, 1});auto relu = std::make_shared<op::v0::Relu>(strided_slice1);auto result = std::make_shared<op::v0::Result>(relu);@@ -1840,18 +1842,18 @@ TEST_F(TransformationTestsF, EliminateConcatStridedSliceConcatDiffAxis) {}{int64_t axis = 2;- auto param1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 3});- auto param2 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 4});- auto param3 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2, 10, 5});- auto concat = make_shared<ov::op::v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);-- auto begin_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});- auto end_const1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 3, 0});- auto strided_slice1 = std::make_shared<ov::op::v1::StridedSlice>(concat,- begin_const1,- end_const1,- std::vector<int64_t>{1, 0, 1},- std::vector<int64_t>{1, 0, 1});+ auto param1 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 3});+ auto param2 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 4});+ auto param3 = make_shared<v0::Parameter>(element::f32, Shape{2, 10, 5});+ auto concat = make_shared<v0::Concat>(ov::as_output_vector({param1, param2, param3}), axis);++ auto begin_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 0, 0});+ auto end_const1 = v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 3, 0});+ auto strided_slice1 = std::make_shared<v1::StridedSlice>(concat,+ begin_const1,+ end_const1,+ std::vector<int64_t>{1, 0, 1},+ std::vector<int64_t>{1, 0, 1});auto relu = std::make_shared<op::v0::Relu>(strided_slice1);auto result = std::make_shared<op::v0::Result>(relu);@@ -1872,12 +1874,12 @@ TEST_F(TransformationTestsF, EliminateStridedSlice) {std::vector<int64_t>{0, std::numeric_limits<int64_t>::max()});auto optional_stride_const =std::make_shared<op::v0::Constant>(ov::element::i32, ov::Shape{2}, std::vector<int>{1, 1});- auto strided_slice = std::make_shared<ov::op::v1::StridedSlice>(relu,- begin_const,- end_const,- optional_stride_const,- std::vector<int64_t>{1, 0, 1, 1},- std::vector<int64_t>{1, 0, 1, 1});+ auto strided_slice = std::make_shared<v1::StridedSlice>(relu,+ begin_const,+ end_const,+ optional_stride_const,+ std::vector<int64_t>{1, 0, 1, 1},+ std::vector<int64_t>{1, 0, 1, 1});auto result = std::make_shared<op::v0::Result>(strided_slice);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{input});@@ -1904,12 +1906,12 @@ TEST_F(TransformationTestsF, EliminateStridedSlice_int32max) {std::vector<int64_t>{0, std::numeric_limits<int32_t>::max()});auto optional_stride_const =std::make_shared<op::v0::Constant>(ov::element::i32, ov::Shape{2}, std::vector<int>{1, 1});- auto strided_slice = std::make_shared<ov::op::v1::StridedSlice>(relu,- begin_const,- end_const,- optional_stride_const,- std::vector<int64_t>{1, 0, 1, 1},- std::vector<int64_t>{1, 0, 1, 1});+ auto strided_slice = std::make_shared<v1::StridedSlice>(relu,+ begin_const,+ end_const,+ optional_stride_const,+ std::vector<int64_t>{1, 0, 1, 1},+ std::vector<int64_t>{1, 0, 1, 1});auto result = std::make_shared<op::v0::Result>(strided_slice);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{input});@@ -1935,11 +1937,11 @@ TEST_F(TransformationTestsF, EliminateStridedSliceWithoutStrides) {std::make_shared<op::v0::Constant>(ov::element::i64,ov::Shape{2},std::vector<int64_t>{0, std::numeric_limits<int64_t>::max()});- auto strided_slice = std::make_shared<ov::op::v1::StridedSlice>(relu,- begin_const,- end_const,- std::vector<int64_t>{1, 0},- std::vector<int64_t>{1, 0});+ auto strided_slice = std::make_shared<v1::StridedSlice>(relu,+ begin_const,+ end_const,+ std::vector<int64_t>{1, 0},+ std::vector<int64_t>{1, 0});auto result = std::make_shared<op::v0::Result>(strided_slice);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{input});@@ -1966,12 +1968,12 @@ TEST_F(TransformationTestsF, EliminateStridedSliceByShape) {std::vector<int64_t>{0, std::numeric_limits<int64_t>::max()});auto optional_stride_const =std::make_shared<op::v0::Constant>(ov::element::i32, ov::Shape{2}, std::vector<int>{1, 1});- auto strided_slice = std::make_shared<ov::op::v1::StridedSlice>(relu,- begin_const,- end_const,- optional_stride_const,- std::vector<int64_t>{1, 0, 1, 1},- std::vector<int64_t>{1, 0, 1, 1});+ auto strided_slice = std::make_shared<v1::StridedSlice>(relu,+ begin_const,+ end_const,+ optional_stride_const,+ std::vector<int64_t>{1, 0, 1, 1},+ std::vector<int64_t>{1, 0, 1, 1});auto result = std::make_shared<op::v0::Result>(strided_slice);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{input});@@ -1994,12 +1996,12 @@ TEST_F(TransformationTestsF, EliminateStridedSliceByShapeNegative) {auto end_const = std::make_shared<op::v0::Constant>(ov::element::i64, ov::Shape{2}, std::vector<int>{0, -1});auto optional_stride_const =std::make_shared<op::v0::Constant>(ov::element::i32, ov::Shape{2}, std::vector<int>{1, 1});- auto strided_slice = std::make_shared<ov::op::v1::StridedSlice>(relu,- begin_const,- end_const,- optional_stride_const,- std::vector<int64_t>{1, 0},- std::vector<int64_t>{1, 0});+ auto strided_slice = std::make_shared<v1::StridedSlice>(relu,+ begin_const,+ end_const,+ optional_stride_const,+ std::vector<int64_t>{1, 0},+ std::vector<int64_t>{1, 0});auto result = std::make_shared<op::v0::Result>(strided_slice);model = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{input});@@ -2012,12 +2014,12 @@ TEST_F(TransformationTestsF, EliminateStridedSliceByShapeNegative) {auto end_const = std::make_shared<op::v0::Constant>(ov::element::i64, ov::Shape{2}, std::vector<int>{0, -1});auto optional_stride_const =std::make_shared<op::v0::Constant>(ov::element::i32, ov::Shape{2}, std::vector<int>{1, 1});- auto strided_slice = std::make_shared<ov::op::v1::StridedSlice>(relu,- begin_const,- end_const,- optional_stride_const,- std::vector<int64_t>{1, 0},- std::vector<int64_t>{1, 0});+ auto strided_slice = std::make_shared<v1::StridedSlice>(relu,+ begin_const,+ end_const,+ optional_stride_const,+ std::vector<int64_t>{1, 0},+ std::vector<int64_t>{1, 0});auto result = std::make_shared<op::v0::Result>(strided_slice);model_ref = std::make_shared<ov::Model>(ResultVector{result}, ParameterVector{input});@@ -2042,7 +2044,7 @@ TEST_F(TransformationTestsF, SqueezeBinaryReshape) {manager.register_pass<ov::pass::NopElimination>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, PartialShape{1});+ auto data = std::make_shared<v0::Parameter>(element::f32, PartialShape{1});auto binary = std::make_shared<op::v1::Multiply>(data, op::v0::Constant::create(element::f32, Shape{1}, {0.2}));auto relu = std::make_shared<op::v0::Relu>(binary);model_ref = std::make_shared<ov::Model>(OutputVector{relu}, ParameterVector{data});diff --git a/src/common/transformations/tests/common_optimizations/optimize_strided_slice_test.cpp b/src/common/transformations/tests/common_optimizations/optimize_strided_slice_test.cppindex c0dcc39b220..e1645d70d59 100644--- a/src/common/transformations/tests/common_optimizations/optimize_strided_slice_test.cpp+++ b/src/common/transformations/tests/common_optimizations/optimize_strided_slice_test.cpp@@ -37,6 +37,8 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;+namespace v8 = ov::op::v8;TEST_F(TransformationTestsF, OptimizeSS_UselessDeletion_Negative1) {{auto data = std::make_shared<opset1::Parameter>(element::f32, Shape{5, 5, 5, 5});@@ -1042,11 +1044,11 @@ ov::Output<ov::Node> make_slice(const ov::Output<ov::Node>& out,const int64_t& step,const int64_t& axis,element::Type et = element::i64) {- return std::make_shared<ov::op::v8::Slice>(out,- ov::op::v0::Constant::create(et, ov::Shape{1}, {start}),- ov::op::v0::Constant::create(et, ov::Shape{1}, {stop}),- ov::op::v0::Constant::create(et, ov::Shape{1}, {step}),- ov::op::v0::Constant::create(et, ov::Shape{1}, {axis}));+ return std::make_shared<v8::Slice>(out,+ v0::Constant::create(et, ov::Shape{1}, {start}),+ v0::Constant::create(et, ov::Shape{1}, {stop}),+ v0::Constant::create(et, ov::Shape{1}, {step}),+ v0::Constant::create(et, ov::Shape{1}, {axis}));}ov::OutputVector make_vsplit(const ov::Output<ov::Node>& out,@@ -1054,8 +1056,8 @@ ov::OutputVector make_vsplit(const ov::Output<ov::Node>& out,const std::vector<int64_t>& split_length) {return std::make_shared<ov::op::v1::VariadicSplit>(out,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {axis}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{split_length.size()}, split_length))+ v0::Constant::create(ov::element::i64, ov::Shape{}, {axis}),+ v0::Constant::create(ov::element::i64, ov::Shape{split_length.size()}, split_length))->outputs();}@@ -1068,7 +1070,7 @@ TEST_F(TransformationTestsF, GroupedSliceToVSplit) {auto slice_1 = make_slice(relu, 1, 2, 1, 1);auto slice_2 = make_slice(relu, 2, 7, 1, 1);- auto concat = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{slice_0, slice_2, slice_1}, 1);+ auto concat = std::make_shared<v0::Concat>(ov::OutputVector{slice_0, slice_2, slice_1}, 1);model = std::make_shared<ov::Model>(ov::OutputVector{concat}, ov::ParameterVector{data});manager.register_pass<ov::pass::GroupedSliceToVSplitOptimization>();@@ -1079,7 +1081,7 @@ TEST_F(TransformationTestsF, GroupedSliceToVSplit) {auto vsplit = make_vsplit(relu, 1, {1, 1, 1});- auto concat = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{vsplit[0], vsplit[2], vsplit[1]}, 1);+ auto concat = std::make_shared<v0::Concat>(ov::OutputVector{vsplit[0], vsplit[2], vsplit[1]}, 1);model_ref = std::make_shared<ov::Model>(ov::OutputVector{concat}, ov::ParameterVector{data});}@@ -1109,19 +1111,19 @@ TEST_F(TransformationTestsF, GroupedSliceToVSplitChained) {auto slice_2_0_0 = make_slice(slice_2, 0, 3, 1, 1); // negative case as slices overlapauto slice_2_1_0 = make_slice(slice_2, 2, 10, 1, 1);- auto concat = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{slice_0,- slice_2,- slice_1,- slice_0_0,- slice_1_0,- slice_0_1,- slice_1_1,- slice_1_2,- slice_2_0,- slice_2_1,- slice_2_0_0,- slice_2_1_0},- 1);+ auto concat = std::make_shared<v0::Concat>(ov::OutputVector{slice_0,+ slice_2,+ slice_1,+ slice_0_0,+ slice_1_0,+ slice_0_1,+ slice_1_1,+ slice_1_2,+ slice_2_0,+ slice_2_1,+ slice_2_0_0,+ slice_2_1_0},+ 1);model = std::make_shared<ov::Model>(ov::OutputVector{concat}, ov::ParameterVector{data});manager.register_pass<ov::pass::GroupedSliceToVSplitOptimization>();@@ -1153,19 +1155,19 @@ TEST_F(TransformationTestsF, GroupedSliceToVSplitChained) {auto slice_2_0_0 = make_slice(slice_2, 0, 3, 1, 1); // negative case as slices overlapauto slice_2_1_0 = make_slice(slice_2, 2, 10, 1, 1);- auto concat = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{slice_0,- slice_2,- slice_1,- slice_0_0,- slice_1_0,- slice_0_1,- slice_1_1,- slice_1_2,- slice_2_0,- slice_2_1,- slice_2_0_0,- slice_2_1_0},- 1);+ auto concat = std::make_shared<v0::Concat>(ov::OutputVector{slice_0,+ slice_2,+ slice_1,+ slice_0_0,+ slice_1_0,+ slice_0_1,+ slice_1_1,+ slice_1_2,+ slice_2_0,+ slice_2_1,+ slice_2_0_0,+ slice_2_1_0},+ 1);model_ref = std::make_shared<ov::Model>(ov::OutputVector{concat}, ov::ParameterVector{data});}@@ -1184,10 +1186,10 @@ TEST_F(TransformationTestsF, GroupedSliceToVSplitSameSourceDifferentAxis) {auto slice_2 = make_slice(relu, 0, 5, 1, -2);auto slice_3 = make_slice(relu, 5, 10, 1, 2);- auto concat_0 = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{slice_1, slice_0}, 1);- auto concat_1 = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{slice_2, slice_3}, 2);+ auto concat_0 = std::make_shared<v0::Concat>(ov::OutputVector{slice_1, slice_0}, 1);+ auto concat_1 = std::make_shared<v0::Concat>(ov::OutputVector{slice_2, slice_3}, 2);- auto concat_2 = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{concat_0, concat_1}, 0);+ auto concat_2 = std::make_shared<v0::Concat>(ov::OutputVector{concat_0, concat_1}, 0);model = std::make_shared<ov::Model>(ov::OutputVector{concat_2}, ov::ParameterVector{data});manager.register_pass<ov::pass::GroupedSliceToVSplitOptimization>();@@ -1204,10 +1206,10 @@ TEST_F(TransformationTestsF, GroupedSliceToVSplitSameSourceDifferentAxis) {auto slice_2 = vsplit_1[0];auto slice_3 = vsplit_1[1];- auto concat_0 = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{slice_1, slice_0}, 1);- auto concat_1 = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{slice_2, slice_3}, 2);+ auto concat_0 = std::make_shared<v0::Concat>(ov::OutputVector{slice_1, slice_0}, 1);+ auto concat_1 = std::make_shared<v0::Concat>(ov::OutputVector{slice_2, slice_3}, 2);- auto concat_2 = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{concat_0, concat_1}, 0);+ auto concat_2 = std::make_shared<v0::Concat>(ov::OutputVector{concat_0, concat_1}, 0);model_ref = std::make_shared<ov::Model>(ov::OutputVector{concat_2}, ov::ParameterVector{data});}@@ -1222,7 +1224,7 @@ TEST_F(TransformationTestsF, GroupedSliceToVSplitNegativeStartStop) {auto slice_1 = make_slice(relu, -4, -2, 1, 1);auto slice_2 = make_slice(relu, -2, INT32_MAX, 1, 1);- auto concat = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{slice_0, slice_2, slice_1}, 1);+ auto concat = std::make_shared<v0::Concat>(ov::OutputVector{slice_0, slice_2, slice_1}, 1);model = std::make_shared<ov::Model>(ov::OutputVector{concat}, ov::ParameterVector{data});manager.register_pass<ov::pass::GroupedSliceToVSplitOptimization>();@@ -1233,7 +1235,7 @@ TEST_F(TransformationTestsF, GroupedSliceToVSplitNegativeStartStop) {auto vsplit = make_vsplit(relu, 1, {1, 2, 2});- auto concat = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{vsplit[0], vsplit[2], vsplit[1]}, 1);+ auto concat = std::make_shared<v0::Concat>(ov::OutputVector{vsplit[0], vsplit[2], vsplit[1]}, 1);model_ref = std::make_shared<ov::Model>(ov::OutputVector{concat}, ov::ParameterVector{data});}@@ -1254,12 +1256,12 @@ TEST_F(TransformationTestsF, SliceSequenceToSingleSlice) {}{auto data = std::make_shared<ov::opset8::Parameter>(data_type, data_pshape);- auto slice = std::make_shared<ov::op::v8::Slice>(- data,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, -7}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {10, 1, INT32_MAX}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, 2}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 1, 3}));+ auto slice =+ std::make_shared<v8::Slice>(data,+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, -7}),+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {10, 1, INT32_MAX}),+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, 2}),+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 1, 3}));model_ref = std::make_shared<ov::Model>(ov::OutputVector{slice}, ov::ParameterVector{data});}}@@ -1273,26 +1275,23 @@ TEST_F(TransformationTestsF, SliceSequenceToSingleSliceStartAsParameter) {auto start_0 = std::make_shared<ov::opset8::Parameter>(element::i64, ov::PartialShape{1});auto start_1 = std::make_shared<ov::opset8::Parameter>(element::i64, ov::PartialShape{1});auto start_2 = std::make_shared<ov::opset8::Parameter>(element::i64, ov::PartialShape{1});- auto slice_0 =- std::make_shared<ov::op::v8::Slice>(data,- start_0,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {10}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}));-- auto slice_1 =- std::make_shared<ov::op::v8::Slice>(slice_0,- start_1,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}));-- auto slice_2 = std::make_shared<ov::op::v8::Slice>(- slice_1,- start_2,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {INT32_MAX}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {3}));+ auto slice_0 = std::make_shared<v8::Slice>(data,+ start_0,+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {10}),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {0}));++ auto slice_1 = std::make_shared<v8::Slice>(slice_0,+ start_1,+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {-1}),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {1}));++ auto slice_2 = std::make_shared<v8::Slice>(slice_1,+ start_2,+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {INT32_MAX}),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {2}),+ v0::Constant::create(ov::element::i64, ov::Shape{1}, {3}));model = std::make_shared<ov::Model>(ov::OutputVector{slice_2},ov::ParameterVector{data, start_0, start_1, start_2});@@ -1305,12 +1304,12 @@ TEST_F(TransformationTestsF, SliceSequenceToSingleSliceStartAsParameter) {auto start_2 = std::make_shared<ov::opset8::Parameter>(element::i64, ov::PartialShape{1});auto concat_0_1 = std::make_shared<ov::opset8::Concat>(OutputVector{start_0, start_1}, 0);auto concat_1_2 = std::make_shared<ov::opset8::Concat>(OutputVector{concat_0_1, start_2}, 0);- auto slice = std::make_shared<ov::op::v8::Slice>(- data,- concat_1_2,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {10, 1, INT32_MAX}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, 2}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 1, 3}));+ auto slice =+ std::make_shared<v8::Slice>(data,+ concat_1_2,+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {10, 1, INT32_MAX}),+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, 2}),+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 1, 3}));model_ref =std::make_shared<ov::Model>(ov::OutputVector{slice}, ov::ParameterVector{data, start_0, start_1, start_2});}@@ -1320,7 +1319,7 @@ TEST_F(TransformationTestsF, SliceSequenceToSingleSliceMixedTypes) {auto data_pshape = ov::PartialShape{10, 5, 5, 10};auto data_type = ov::element::f32;{- auto data = std::make_shared<ov::op::v0::Parameter>(data_type, data_pshape);+ auto data = std::make_shared<v0::Parameter>(data_type, data_pshape);auto slice_0 = make_slice(data, 1, 10, 1, 0);auto slice_1 = make_slice(slice_0, -1, 1, -1, 1, element::i32);@@ -1330,13 +1329,13 @@ TEST_F(TransformationTestsF, SliceSequenceToSingleSliceMixedTypes) {manager.register_pass<ov::pass::SliceSequenceToSingleSlice>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(data_type, data_pshape);- auto slice = std::make_shared<ov::op::v8::Slice>(- data,- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, -7}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {10, 1, INT32_MAX}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, 2}),- ov::op::v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 1, 3}));+ auto data = std::make_shared<v0::Parameter>(data_type, data_pshape);+ auto slice =+ std::make_shared<v8::Slice>(data,+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, -7}),+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {10, 1, INT32_MAX}),+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {1, -1, 2}),+ v0::Constant::create(ov::element::i64, ov::Shape{3}, {0, 1, 3}));model_ref = std::make_shared<ov::Model>(ov::OutputVector{slice}, ov::ParameterVector{data});}}diff --git a/src/common/transformations/tests/common_optimizations/preprocessing_fusion_tests.cpp b/src/common/transformations/tests/common_optimizations/preprocessing_fusion_tests.cppindex 335afa16b68..46e4750bf5c 100644--- a/src/common/transformations/tests/common_optimizations/preprocessing_fusion_tests.cpp+++ b/src/common/transformations/tests/common_optimizations/preprocessing_fusion_tests.cpp@@ -39,6 +39,9 @@ using namespace testing;using namespace ov;using namespace opset8;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v12 = ov::op::v12;namespace {std::shared_ptr<Convolution> create_conv(Output<Node> input, Output<Node> weights) {return std::make_shared<Convolution>(input,@@ -231,7 +234,7 @@ TEST_F(TransformationTestsF, RICFusionHardNegativePad12) {auto pads_begin = Constant::create(element::i64, Shape{4}, {0, 0, 0, -1});auto pads_end = Constant::create(element::i64, Shape{4}, {0, 0, 0, -1});- auto pad = std::make_shared<ov::op::v12::Pad>(eltwise, pads_begin, pads_end, op::PadMode::CONSTANT);+ auto pad = std::make_shared<v12::Pad>(eltwise, pads_begin, pads_end, op::PadMode::CONSTANT);auto gconv = create_group_conv(pad, {3, 4, 1, 3, 3});@@ -258,7 +261,7 @@ TEST_F(TransformationTestsF, RICFusionHardNegativePad12) {auto pads_begin = Constant::create(element::i64, Shape{4}, {0, 0, 0, -1});auto pads_end = Constant::create(element::i64, Shape{4}, {0, 0, 0, -1});- auto pad = std::make_shared<ov::op::v12::Pad>(eltwise, pads_begin, pads_end, op::PadMode::CONSTANT);+ auto pad = std::make_shared<v12::Pad>(eltwise, pads_begin, pads_end, op::PadMode::CONSTANT);// 0 1 2 2 1 0// [0, 1, 2, 3]-[4, 5, 6, 7]-[8, 9, 10, 11] -> [8, 9, 10, 11]-[4, 5, 6, 7]-[0, 1, 2, 3]@@ -754,10 +757,10 @@ TEST_F(TransformationTestsF, RICFusionSplitConcatDetectionNegative3) {TEST_F(TransformationTestsF, FuseConvertLayout) {{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 64});- auto order = ov::op::v0::Constant::create(element::i64, Shape{3}, {1, 2, 0});- auto transpose = std::make_shared<ov::op::v1::Transpose>(input, order);- auto relu = std::make_shared<ov::op::v0::Relu>(transpose);+ auto input = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 64});+ auto order = v0::Constant::create(element::i64, Shape{3}, {1, 2, 0});+ auto transpose = std::make_shared<v1::Transpose>(input, order);+ auto relu = std::make_shared<v0::Relu>(transpose);model = std::make_shared<ov::Model>(OutputVector{relu}, ParameterVector{input});@@ -771,9 +774,9 @@ TEST_F(TransformationTestsF, FuseConvertLayout) {}{- auto input = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{3, 64, 1});- auto convert = std::make_shared<ov::op::v0::Convert>(input, element::f32);- auto relu = std::make_shared<ov::op::v0::Relu>(convert);+ auto input = std::make_shared<v0::Parameter>(element::f16, Shape{3, 64, 1});+ auto convert = std::make_shared<v0::Convert>(input, element::f32);+ auto relu = std::make_shared<v0::Relu>(convert);model_ref = std::make_shared<ov::Model>(OutputVector{relu}, ParameterVector{input});}@@ -782,8 +785,8 @@ TEST_F(TransformationTestsF, FuseConvertLayout) {TEST_F(TransformationTestsF, FuseScaleValue) {{auto input = create_param({1, 64, 64, 3});- auto order = ov::op::v0::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2});- auto transpose = std::make_shared<ov::op::v1::Transpose>(input, order);+ auto order = v0::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2});+ auto transpose = std::make_shared<v1::Transpose>(input, order);auto conv = create_conv(transpose, {6, 3, 3, 3});model = std::make_shared<Model>(OutputVector{conv}, ParameterVector{input});@@ -799,8 +802,8 @@ TEST_F(TransformationTestsF, FuseScaleValue) {{auto input = create_param({1, 64, 64, 3});- auto order = ov::op::v0::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2});- auto transpose = std::make_shared<ov::op::v1::Transpose>(input, order);+ auto order = v0::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2});+ auto transpose = std::make_shared<v1::Transpose>(input, order);auto conv = create_conv(transpose, {6, 3, 3, 3});model_ref = std::make_shared<Model>(OutputVector{conv}, ParameterVector{input});}@@ -811,8 +814,8 @@ TEST_F(TransformationTestsF, FuseScaleValue) {TEST_F(TransformationTestsF, FuseScaleValues) {{auto input = create_param({1, 64, 64, 3});- auto order = ov::op::v0::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2});- auto transpose = std::make_shared<ov::op::v1::Transpose>(input, order);+ auto order = v0::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2});+ auto transpose = std::make_shared<v1::Transpose>(input, order);auto conv = create_conv(transpose, {6, 3, 3, 3});model = std::make_shared<Model>(OutputVector{conv}, ParameterVector{input});@@ -828,8 +831,8 @@ TEST_F(TransformationTestsF, FuseScaleValues) {{auto input = create_param({1, 64, 64, 3});- auto order = ov::op::v0::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2});- auto transpose = std::make_shared<ov::op::v1::Transpose>(input, order);+ auto order = v0::Constant::create(element::i64, Shape{4}, {0, 3, 1, 2});+ auto transpose = std::make_shared<v1::Transpose>(input, order);auto conv = create_conv(transpose, {6, 3, 3, 3});model_ref = std::make_shared<Model>(OutputVector{conv}, ParameterVector{input});}diff --git a/src/common/transformations/tests/common_optimizations/reverse_shape_and_type_infer.cpp b/src/common/transformations/tests/common_optimizations/reverse_shape_and_type_infer.cppindex 4b71213e41e..043ce3f33c7 100644--- a/src/common/transformations/tests/common_optimizations/reverse_shape_and_type_infer.cpp+++ b/src/common/transformations/tests/common_optimizations/reverse_shape_and_type_infer.cpp@@ -26,6 +26,7 @@using namespace testing;using namespace ov;+namespace v12 = ov::op::v12;TEST_F(TransformationTestsF, ConvolutionReverseInfer) {{auto data = std::make_shared<opset10::Parameter>(element::dynamic, PartialShape::dynamic());@@ -244,7 +245,7 @@ TEST_F(TransformationTestsF, NegativePad12ReverseInfer) {auto pads_begin = opset10::Constant::create(element::i64, Shape{4}, {0, 0, 0, -1});auto pads_end = opset10::Constant::create(element::i64, Shape{4}, {0, 0, 0, -1});auto value = opset10::Constant::create(element::f32, Shape{}, {0});- auto pad = std::make_shared<ov::op::v12::Pad>(data, pads_begin, pads_end, value, op::PadMode::CONSTANT);+ auto pad = std::make_shared<v12::Pad>(data, pads_begin, pads_end, value, op::PadMode::CONSTANT);auto result = std::make_shared<opset10::Result>(pad);model = std::make_shared<Model>(ResultVector{result}, ParameterVector{data});manager.register_pass<pass::ReverseShapeAndTypeInfer>();@@ -254,7 +255,7 @@ TEST_F(TransformationTestsF, NegativePad12ReverseInfer) {auto pads_begin = opset10::Constant::create(element::i64, Shape{4}, {0, 0, 0, -1});auto pads_end = opset10::Constant::create(element::i64, Shape{4}, {0, 0, 0, -1});auto value = opset10::Constant::create(element::f32, Shape{}, {0});- auto pad = std::make_shared<ov::op::v12::Pad>(data, pads_begin, pads_end, value, op::PadMode::CONSTANT);+ auto pad = std::make_shared<v12::Pad>(data, pads_begin, pads_end, value, op::PadMode::CONSTANT);auto result = std::make_shared<opset10::Result>(pad);model_ref = std::make_shared<Model>(ResultVector{result}, ParameterVector{data});}diff --git a/src/common/transformations/tests/common_optimizations/sdpa_fusion_test.cpp b/src/common/transformations/tests/common_optimizations/sdpa_fusion_test.cppindex 173103b820d..da02810c57e 100644--- a/src/common/transformations/tests/common_optimizations/sdpa_fusion_test.cpp+++ b/src/common/transformations/tests/common_optimizations/sdpa_fusion_test.cpp@@ -33,10 +33,11 @@ using namespace std;using namespace testing;using namespace ov;-using namespace ov::op;using namespace ov::pass;using namespace ov::element;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;enum class InputType : int { Q, K, V, SDPA };enum class SinksSliceType : int { None, Slice, StridedSlice };@@ -75,7 +76,8 @@ public:auto broadcast_to_shape =v0::Constant::create(element::i32, Shape{sinks_broadcast_shape.size()}, broadcast_shape_value);auto sinks_param = make_shared<v0::Parameter>(element::f16, sinks_shape);- m_sinks = make_shared<v3::Broadcast>(sinks_param, broadcast_to_shape, BroadcastType::BIDIRECTIONAL);+ m_sinks =+ make_shared<ov::op::v3::Broadcast>(sinks_param, broadcast_to_shape, ov::op::BroadcastType::BIDIRECTIONAL);m_sinks_rank = sinks_broadcast_shape.size();params.push_back(sinks_param);}diff --git a/src/common/transformations/tests/common_optimizations/sdpa_scale_fusion_test.cpp b/src/common/transformations/tests/common_optimizations/sdpa_scale_fusion_test.cppindex 4cce3d8974d..8c7a945ca6f 100644--- a/src/common/transformations/tests/common_optimizations/sdpa_scale_fusion_test.cpp+++ b/src/common/transformations/tests/common_optimizations/sdpa_scale_fusion_test.cpp@@ -20,37 +20,39 @@ using namespace testing;using namespace ov::pass;using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v13 = ov::op::v13;TEST_F(TransformationTestsF, SDPAScaleFusionTest1) {const PartialShape query_shape{1, 32, -1, 32};const PartialShape key_shape{1, 32, -1, 32};const PartialShape value_shape{1, 32, -1, 32};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{8.0f});- const auto v_scaled = std::make_shared<ov::op::v1::Multiply>(value, scale_const);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{8.0f});+ const auto v_scaled = std::make_shared<v1::Multiply>(value, scale_const);const auto casual = false;{- const auto q_scaled = std::make_shared<ov::op::v1::Multiply>(query, scale_const);- const auto k_scaled = std::make_shared<ov::op::v1::Multiply>(key, scale_const);- const auto sdpa =- std::make_shared<ov::op::v13::ScaledDotProductAttention>(q_scaled, k_scaled, v_scaled, casual);+ const auto q_scaled = std::make_shared<v1::Multiply>(query, scale_const);+ const auto k_scaled = std::make_shared<v1::Multiply>(key, scale_const);+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(q_scaled, k_scaled, v_scaled, casual);model = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value});manager.register_pass<ov::pass::SDPAScaleFusion>();}{- const auto new_mask_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});+ const auto new_mask_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});const auto new_scale_const =- ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{64.0f / std::sqrt(32.0f)});- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(query,- key,- v_scaled,- new_mask_const,- new_scale_const,- casual);+ v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{64.0f / std::sqrt(32.0f)});+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(query,+ key,+ v_scaled,+ new_mask_const,+ new_scale_const,+ casual);model_ref = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value});}@@ -63,37 +65,36 @@ TEST_F(TransformationTestsF, SDPAScaleFusionTest2) {const PartialShape key_shape{1, 32, -1, 32};const PartialShape value_shape{1, 32, -1, 32};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto sdpa_mask_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});- const auto sdpa_scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{2.0f});- const auto scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{8.0f});- const auto v_scaled = std::make_shared<ov::op::v1::Multiply>(value, scale_const);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto sdpa_mask_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});+ const auto sdpa_scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{2.0f});+ const auto scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{8.0f});+ const auto v_scaled = std::make_shared<v1::Multiply>(value, scale_const);const auto casual = false;{- const auto q_scaled = std::make_shared<ov::op::v1::Multiply>(query, scale_const);- const auto k_scaled = std::make_shared<ov::op::v1::Multiply>(key, scale_const);- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(q_scaled,- k_scaled,- v_scaled,- sdpa_mask_const,- sdpa_scale_const,- casual);+ const auto q_scaled = std::make_shared<v1::Multiply>(query, scale_const);+ const auto k_scaled = std::make_shared<v1::Multiply>(key, scale_const);+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(q_scaled,+ k_scaled,+ v_scaled,+ sdpa_mask_const,+ sdpa_scale_const,+ casual);model = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value});manager.register_pass<ov::pass::SDPAScaleFusion>();}{- const auto new_scale_const =- ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{128.0f});- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(query,- key,- v_scaled,- sdpa_mask_const,- new_scale_const,- casual);+ const auto new_scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{128.0f});+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(query,+ key,+ v_scaled,+ sdpa_mask_const,+ new_scale_const,+ casual);model_ref = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value});}@@ -106,35 +107,35 @@ TEST_F(TransformationTestsF, SDPAScaleFusionTest3) {const PartialShape key_shape{1, 32, -1, 32};const PartialShape value_shape{1, 32, -1, 32};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto sdpa_mask_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});- const auto sdpa_scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{2.0f});- const auto scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{8.0f});- const auto v_scaled = std::make_shared<ov::op::v1::Multiply>(value, scale_const);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto sdpa_mask_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});+ const auto sdpa_scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{2.0f});+ const auto scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{8.0f});+ const auto v_scaled = std::make_shared<v1::Multiply>(value, scale_const);const auto casual = false;{- const auto q_scaled = std::make_shared<ov::op::v1::Multiply>(query, scale_const);- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(q_scaled,- key,- v_scaled,- sdpa_mask_const,- sdpa_scale_const,- casual);+ const auto q_scaled = std::make_shared<v1::Multiply>(query, scale_const);+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(q_scaled,+ key,+ v_scaled,+ sdpa_mask_const,+ sdpa_scale_const,+ casual);model = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value});manager.register_pass<ov::pass::SDPAScaleFusion>();}{- const auto new_scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{16.0f});- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(query,- key,- v_scaled,- sdpa_mask_const,- new_scale_const,- casual);+ const auto new_scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{16.0f});+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(query,+ key,+ v_scaled,+ sdpa_mask_const,+ new_scale_const,+ casual);model_ref = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value});}@@ -147,37 +148,37 @@ TEST_F(TransformationTestsF, SDPAScaleFusionTest4) {const PartialShape key_shape{1, 32, -1, 32};const PartialShape value_shape{1, 32, -1, 32};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto sdpa_mask_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});- const auto sdpa_scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{2.0f});- const auto scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{8.0f});- const auto scale_dyn = std::make_shared<ov::op::v0::Parameter>(element::f32, ov::Shape{});- const auto v_scaled = std::make_shared<ov::op::v1::Multiply>(value, scale_const);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto sdpa_mask_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});+ const auto sdpa_scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{2.0f});+ const auto scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{8.0f});+ const auto scale_dyn = std::make_shared<v0::Parameter>(element::f32, ov::Shape{});+ const auto v_scaled = std::make_shared<v1::Multiply>(value, scale_const);const auto casual = false;- const auto q_scaled = std::make_shared<ov::op::v1::Multiply>(query, scale_dyn);+ const auto q_scaled = std::make_shared<v1::Multiply>(query, scale_dyn);{- const auto k_scaled = std::make_shared<ov::op::v1::Multiply>(key, scale_const);- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(q_scaled,- k_scaled,- v_scaled,- sdpa_mask_const,- sdpa_scale_const,- casual);+ const auto k_scaled = std::make_shared<v1::Multiply>(key, scale_const);+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(q_scaled,+ k_scaled,+ v_scaled,+ sdpa_mask_const,+ sdpa_scale_const,+ casual);model = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value, scale_dyn});manager.register_pass<ov::pass::SDPAScaleFusion>();}{- const auto new_scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{16.0f});- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(q_scaled,- key,- v_scaled,- sdpa_mask_const,- new_scale_const,- casual);+ const auto new_scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{16.0f});+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(q_scaled,+ key,+ v_scaled,+ sdpa_mask_const,+ new_scale_const,+ casual);model_ref = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value, scale_dyn});}@@ -190,36 +191,32 @@ TEST_F(TransformationTestsF, SDPAScaleFusionTest5) {const PartialShape key_shape{1, 32, -1, 32};const PartialShape value_shape{1, 32, -1, 32};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto sdpa_mask_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});- const auto sdpa_scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{1.0f});- const auto scale_const = ov::op::v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{1.0f});- const auto scale_dyn = std::make_shared<ov::op::v0::Parameter>(element::f32, ov::Shape{});- const auto v_scaled = std::make_shared<ov::op::v1::Multiply>(value, scale_const);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto sdpa_mask_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{0.0f});+ const auto sdpa_scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{1.0f});+ const auto scale_const = v0::Constant::create(element::f32, ov::Shape{}, std::vector<float>{1.0f});+ const auto scale_dyn = std::make_shared<v0::Parameter>(element::f32, ov::Shape{});+ const auto v_scaled = std::make_shared<v1::Multiply>(value, scale_const);const auto casual = false;{- const auto q_scaled = std::make_shared<ov::op::v1::Multiply>(query, scale_dyn);- const auto k_scaled = std::make_shared<ov::op::v1::Multiply>(key, scale_const);- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(q_scaled,- k_scaled,- v_scaled,- sdpa_mask_const,- sdpa_scale_const,- casual);+ const auto q_scaled = std::make_shared<v1::Multiply>(query, scale_dyn);+ const auto k_scaled = std::make_shared<v1::Multiply>(key, scale_const);+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(q_scaled,+ k_scaled,+ v_scaled,+ sdpa_mask_const,+ sdpa_scale_const,+ casual);model = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value, scale_dyn});manager.register_pass<ov::pass::SDPAScaleFusion>();}{- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(query,- key,- v_scaled,- sdpa_mask_const,- scale_dyn,- casual);+ const auto sdpa =+ std::make_shared<v13::ScaledDotProductAttention>(query, key, v_scaled, sdpa_mask_const, scale_dyn, casual);model_ref = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value, scale_dyn});}@@ -232,41 +229,40 @@ TEST_F(TransformationTestsF, SDPAScaleFusionTest6) {const PartialShape key_shape{1, 32, -1, 32};const PartialShape value_shape{1, 32, -1, 32};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f16, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::i8, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f16, value_shape);- const auto scale_const = ov::op::v0::Constant::create(element::f16, ov::Shape{}, std::vector<float>{8.0f});- const auto v_scaled = std::make_shared<ov::op::v1::Multiply>(value, scale_const);+ const auto query = std::make_shared<v0::Parameter>(element::f16, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::i8, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f16, value_shape);+ const auto scale_const = v0::Constant::create(element::f16, ov::Shape{}, std::vector<float>{8.0f});+ const auto v_scaled = std::make_shared<v1::Multiply>(value, scale_const);const auto casual = false;{- const auto q_scaled = std::make_shared<ov::op::v1::Multiply>(query, scale_const);- const auto k_scaled = std::make_shared<ov::op::TypeRelaxed<ov::op::v1::Multiply>>(+ const auto q_scaled = std::make_shared<v1::Multiply>(query, scale_const);+ const auto k_scaled = std::make_shared<ov::op::TypeRelaxed<v1::Multiply>>(std::vector<element::Type>{element::f16, element::f16},std::vector<element::Type>{element::f16},ov::op::TemporaryReplaceOutputType(key, element::f16).get(),ov::op::TemporaryReplaceOutputType(scale_const, element::f16).get());- const auto sdpa =- std::make_shared<ov::op::v13::ScaledDotProductAttention>(q_scaled, k_scaled, v_scaled, casual);+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(q_scaled, k_scaled, v_scaled, casual);model = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value});manager.register_pass<ov::pass::SDPAScaleFusion>();}{- const auto k_scaled_ref = std::make_shared<ov::op::TypeRelaxed<ov::op::v1::Multiply>>(+ const auto k_scaled_ref = std::make_shared<ov::op::TypeRelaxed<v1::Multiply>>(std::vector<element::Type>{element::f16, element::f16},std::vector<element::Type>{element::f16},ov::op::TemporaryReplaceOutputType(key, element::f16).get(),ov::op::TemporaryReplaceOutputType(scale_const, element::f16).get());- const auto new_mask_const = ov::op::v0::Constant::create(element::f16, ov::Shape{}, std::vector<float>{0.0f});+ const auto new_mask_const = v0::Constant::create(element::f16, ov::Shape{}, std::vector<float>{0.0f});const auto new_scale_const =- ov::op::v0::Constant::create(element::f16, ov::Shape{}, std::vector<float>{8.0f / std::sqrt(32.0f)});- const auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(query,- k_scaled_ref,- v_scaled,- new_mask_const,- new_scale_const,- casual);+ v0::Constant::create(element::f16, ov::Shape{}, std::vector<float>{8.0f / std::sqrt(32.0f)});+ const auto sdpa = std::make_shared<v13::ScaledDotProductAttention>(query,+ k_scaled_ref,+ v_scaled,+ new_mask_const,+ new_scale_const,+ casual);model_ref = std::make_shared<ov::Model>(OutputVector{sdpa}, ParameterVector{query, key, value});}diff --git a/src/common/transformations/tests/common_optimizations/shared_ops_optimization.cpp b/src/common/transformations/tests/common_optimizations/shared_ops_optimization.cppindex 93ee2bf4c45..aaddbda97af 100644--- a/src/common/transformations/tests/common_optimizations/shared_ops_optimization.cpp+++ b/src/common/transformations/tests/common_optimizations/shared_ops_optimization.cpp@@ -28,8 +28,12 @@#include "openvino/op/unsqueeze.hpp"using namespace ov;-using namespace ov::op;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v8 = ov::op::v8;+namespace v12 = ov::op::v12;class SharedTransformationTestsF : public TransformationTestsF {public:void TearDown() override {@@ -357,7 +361,7 @@ TEST_F(SharedTransformationTestsF, Sharedv1Broadcasts) {auto input = std::make_shared<v0::Parameter>(element::f32, PartialShape::dynamic());auto target_shape = std::make_shared<v0::Parameter>(element::i64, PartialShape::dynamic());auto broadcast_v1_0 = std::make_shared<v1::Broadcast>(input, target_shape);- auto broadcast_v1_1 = std::make_shared<v1::Broadcast>(input, target_shape, AutoBroadcastType::PDPD);+ auto broadcast_v1_1 = std::make_shared<v1::Broadcast>(input, target_shape, ov::op::AutoBroadcastType::PDPD);auto broadcast_v1_2 = std::make_shared<v1::Broadcast>(input, target_shape);auto concat = std::make_shared<v0::Concat>(OutputVector{broadcast_v1_0, broadcast_v1_1, broadcast_v1_2}, 0);model = std::make_shared<Model>(OutputVector{concat}, ParameterVector{input, target_shape});@@ -367,7 +371,7 @@ TEST_F(SharedTransformationTestsF, Sharedv1Broadcasts) {auto input = std::make_shared<v0::Parameter>(element::f32, PartialShape::dynamic());auto target_shape = std::make_shared<v0::Parameter>(element::i64, PartialShape::dynamic());auto broadcast_v1_0 = std::make_shared<v1::Broadcast>(input, target_shape);- auto broadcast_v1_1 = std::make_shared<v1::Broadcast>(input, target_shape, AutoBroadcastType::PDPD);+ auto broadcast_v1_1 = std::make_shared<v1::Broadcast>(input, target_shape, ov::op::AutoBroadcastType::PDPD);auto concat = std::make_shared<v0::Concat>(OutputVector{broadcast_v1_0, broadcast_v1_1, broadcast_v1_0}, 0);model_ref = std::make_shared<Model>(OutputVector{concat}, ParameterVector{input, target_shape});}@@ -378,7 +382,8 @@ TEST_F(SharedTransformationTestsF, Sharedv3Broadcasts) {auto input = std::make_shared<v0::Parameter>(element::f32, PartialShape::dynamic());auto target_shape = std::make_shared<v0::Parameter>(element::i64, PartialShape::dynamic());auto broadcast_v1_0 = std::make_shared<v3::Broadcast>(input, target_shape);- auto broadcast_v1_1 = std::make_shared<v3::Broadcast>(input, target_shape, BroadcastType::BIDIRECTIONAL);+ auto broadcast_v1_1 =+ std::make_shared<v3::Broadcast>(input, target_shape, ov::op::BroadcastType::BIDIRECTIONAL);auto broadcast_v1_2 = std::make_shared<v3::Broadcast>(input, target_shape);auto concat = std::make_shared<v0::Concat>(OutputVector{broadcast_v1_0, broadcast_v1_1, broadcast_v1_2}, 0);model = std::make_shared<Model>(OutputVector{concat}, ParameterVector{input, target_shape});@@ -388,7 +393,8 @@ TEST_F(SharedTransformationTestsF, Sharedv3Broadcasts) {auto input = std::make_shared<v0::Parameter>(element::f32, PartialShape::dynamic());auto target_shape = std::make_shared<v0::Parameter>(element::i64, PartialShape::dynamic());auto broadcast_v1_0 = std::make_shared<v3::Broadcast>(input, target_shape);- auto broadcast_v1_1 = std::make_shared<v3::Broadcast>(input, target_shape, BroadcastType::BIDIRECTIONAL);+ auto broadcast_v1_1 =+ std::make_shared<v3::Broadcast>(input, target_shape, ov::op::BroadcastType::BIDIRECTIONAL);auto concat = std::make_shared<v0::Concat>(OutputVector{broadcast_v1_0, broadcast_v1_1, broadcast_v1_0}, 0);model_ref = std::make_shared<Model>(OutputVector{concat}, ParameterVector{input, target_shape});}@@ -675,8 +681,8 @@ TEST_F(SharedTransformationTestsF, SharedPad) {auto data_1 = std::make_shared<v0::Parameter>(element::i32, PartialShape{4});auto data_2 = std::make_shared<v0::Parameter>(element::i32, PartialShape{4});- auto op_1 = std::make_shared<v12::Pad>(data_0, data_1, data_2, PadMode::REFLECT);- auto op_2 = std::make_shared<v12::Pad>(data_0, data_1, data_2, PadMode::REFLECT);+ auto op_1 = std::make_shared<v12::Pad>(data_0, data_1, data_2, ov::op::PadMode::REFLECT);+ auto op_2 = std::make_shared<v12::Pad>(data_0, data_1, data_2, ov::op::PadMode::REFLECT);auto concat = std::make_shared<v0::Concat>(OutputVector{op_1, op_2}, 0);model = std::make_shared<ov::Model>(OutputVector{concat}, ParameterVector{data_0, data_1, data_2});@@ -687,7 +693,7 @@ TEST_F(SharedTransformationTestsF, SharedPad) {auto data_1 = std::make_shared<v0::Parameter>(element::i32, PartialShape{4});auto data_2 = std::make_shared<v0::Parameter>(element::i32, PartialShape{4});- auto op_1 = std::make_shared<v12::Pad>(data_0, data_1, data_2, PadMode::REFLECT);+ auto op_1 = std::make_shared<v12::Pad>(data_0, data_1, data_2, ov::op::PadMode::REFLECT);auto concat = std::make_shared<v0::Concat>(OutputVector{op_1, op_1}, 0);model_ref = std::make_shared<ov::Model>(OutputVector{concat}, ParameterVector{data_0, data_1, data_2});diff --git a/src/common/transformations/tests/common_optimizations/strides_optimization.cpp b/src/common/transformations/tests/common_optimizations/strides_optimization.cppindex 6dfc2144915..a0323d30616 100644--- a/src/common/transformations/tests/common_optimizations/strides_optimization.cpp+++ b/src/common/transformations/tests/common_optimizations/strides_optimization.cpp@@ -21,6 +21,8 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;// Tests are based on model-optimizer/mo/middle/passes/fusing/resnet_optimization_test.py// In description of unit tests below will be used next syntax: Operation(NxM,XxY), where NxM - kernel size, XxY -// stride@@ -28,41 +30,41 @@ using namespace testing;// Pl->Conv(1x1,1x1)->Conv(1x1,2x2) => Pl->Conv(1x1,2x2)->Conv(1x1,1x1)TEST_F(TransformationTestsF, StridesOptimization1) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model = std::make_shared<ov::Model>(OutputVector{conv_2}, ParameterVector{data});manager.register_pass<ov::pass::StridesOptimization>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model_ref = std::make_shared<ov::Model>(OutputVector{conv_2}, ParameterVector{data});}@@ -71,41 +73,41 @@ TEST_F(TransformationTestsF, StridesOptimization1) {// Pl->Conv(3x3,2x2)->Conv(1x1,2x2) => Pl->Conv(3x3,4x4)->Conv(1x1,1x1)TEST_F(TransformationTestsF, StridesOptimization2) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model = std::make_shared<ov::Model>(OutputVector{conv_2}, ParameterVector{data});manager.register_pass<ov::pass::StridesOptimization>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{4, 4},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{4, 4},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model_ref = std::make_shared<ov::Model>(OutputVector{conv_2}, ParameterVector{data});}@@ -114,41 +116,41 @@ TEST_F(TransformationTestsF, StridesOptimization2) {// Pl->Conv(3x3,2x2)->Conv(3x3,2x2) => SameTEST_F(TransformationTestsF, StridesOptimization3) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model = std::make_shared<ov::Model>(OutputVector{conv_2}, ParameterVector{data});manager.register_pass<ov::pass::StridesOptimization>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model_ref = std::make_shared<ov::Model>(OutputVector{conv_2}, ParameterVector{data});}@@ -158,61 +160,61 @@ TEST_F(TransformationTestsF, StridesOptimization3) {// `-->Conv(3x3,2x2)->ReLU---` `-->Conv(3x3,4x4)->ReLU---`TEST_F(TransformationTestsF, StridesOptimization4) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});auto relu_1 = std::make_shared<opset7::Relu>(conv_1);- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(data,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(data,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});auto relu_2 = std::make_shared<opset7::Relu>(conv_2);auto add = std::make_shared<opset7::Add>(relu_1, relu_2);- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(add,- weights_3,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(add,+ weights_3,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model = std::make_shared<ov::Model>(OutputVector{conv_3}, ParameterVector{data});manager.register_pass<ov::pass::StridesOptimization>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{4, 4},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{4, 4},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});auto relu_1 = std::make_shared<opset7::Relu>(conv_1);- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(data,- weights_2,- Strides{4, 4},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(data,+ weights_2,+ Strides{4, 4},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});auto relu_2 = std::make_shared<opset7::Relu>(conv_2);auto add = std::make_shared<opset7::Add>(relu_1, relu_2);- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(add,- weights_3,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(add,+ weights_3,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model_ref = std::make_shared<ov::Model>(OutputVector{conv_3}, ParameterVector{data});}@@ -222,48 +224,48 @@ TEST_F(TransformationTestsF, StridesOptimization4) {// `----------------->ReLU---` `-->Pool(1x1,2x2)->ReLU---`TEST_F(TransformationTestsF, StridesOptimization5) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{1, 1},- CoordinateDiff{0, 0},- CoordinateDiff{0, 0},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{1, 1},+ CoordinateDiff{0, 0},+ CoordinateDiff{0, 0},+ Strides{});auto relu_1 = std::make_shared<opset7::Relu>(conv_1);auto relu_2 = std::make_shared<opset7::Relu>(data);auto add = std::make_shared<opset7::Add>(relu_1, relu_2);- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(add,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(add,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model = std::make_shared<ov::Model>(OutputVector{conv_2}, ParameterVector{data});manager.register_pass<ov::pass::StridesOptimization>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});auto relu_1 = std::make_shared<opset7::Relu>(conv_1);auto pool = std::make_shared<opset7::MaxPool>(data, Strides{2, 2}, Shape{0, 0}, Shape{0, 0}, Shape{1, 1});auto relu_2 = std::make_shared<opset7::Relu>(pool);auto add = std::make_shared<opset7::Add>(relu_1, relu_2);- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(add,- weights_2,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(add,+ weights_2,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model_ref = std::make_shared<ov::Model>(OutputVector{conv_2}, ParameterVector{data});}@@ -274,69 +276,69 @@ TEST_F(TransformationTestsF, StridesOptimization5) {// Pl->Conv(1x1,2x2)->Conv(1x1,1x1)->Conv(3x3,2x2)->Conv(1x1,1x1)TEST_F(TransformationTestsF, StridesOptimization6) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(conv_2,- weights_3,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_4 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_4 = std::make_shared<ov::op::v1::Convolution>(conv_3,- weights_4,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(conv_2,+ weights_3,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_4 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_4 = std::make_shared<v1::Convolution>(conv_3,+ weights_4,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model = std::make_shared<ov::Model>(OutputVector{conv_4}, ParameterVector{data});manager.register_pass<ov::pass::StridesOptimization>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(conv_2,- weights_3,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_4 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_4 = std::make_shared<ov::op::v1::Convolution>(conv_3,- weights_4,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 3, 3}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(conv_2,+ weights_3,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_4 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_4 = std::make_shared<v1::Convolution>(conv_3,+ weights_4,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model_ref = std::make_shared<ov::Model>(OutputVector{conv_4}, ParameterVector{data});}@@ -349,72 +351,72 @@ TEST_F(TransformationTestsF, StridesOptimization6) {// `--> Pool(1x1, 2x2) -> Relu --> Conv(1x1,1x1)TEST_F(TransformationTestsF, StridesOptimization7) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(conv_2,- weights_3,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(conv_2,+ weights_3,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});auto relu = std::make_shared<opset7::Relu>(conv_1);- auto weights_4 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_4 = std::make_shared<ov::op::v1::Convolution>(relu,- weights_4,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_4 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_4 = std::make_shared<v1::Convolution>(relu,+ weights_4,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model = std::make_shared<ov::Model>(OutputVector{conv_3, conv_4}, ParameterVector{data});manager.register_pass<ov::pass::StridesOptimization>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(conv_1,- weights_2,- Strides{4, 4},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(conv_2,- weights_3,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(conv_1,+ weights_2,+ Strides{4, 4},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(conv_2,+ weights_3,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});auto pool = std::make_shared<opset7::MaxPool>(conv_1, Strides{2, 2}, Shape{0, 0}, Shape{0, 0}, Shape{1, 1});auto relu = std::make_shared<opset7::Relu>(pool);- auto weights_4 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_4 = std::make_shared<ov::op::v1::Convolution>(relu,- weights_4,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_4 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_4 = std::make_shared<v1::Convolution>(relu,+ weights_4,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model_ref = std::make_shared<ov::Model>(OutputVector{conv_3, conv_4}, ParameterVector{data});}@@ -427,61 +429,61 @@ TEST_F(TransformationTestsF, StridesOptimization7) {// Const-->MaxPool(1x1,4x4)-->Squeeze` Pl--->MaxPool(1x1,2x2)-->Squeeze`TEST_F(TransformationTestsF, StridesOptimization8) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{1, 1},- CoordinateDiff{0, 0},- CoordinateDiff{0, 0},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{1, 1},+ CoordinateDiff{0, 0},+ CoordinateDiff{0, 0},+ Strides{});auto relu_1 = std::make_shared<opset7::Relu>(conv_1);Shape const_shape{1, 3, 224, 224};auto constant =opset7::Constant::create(element::f32, const_shape, std::vector<float>(shape_size(const_shape), 1));auto add = std::make_shared<opset7::Add>(relu_1, constant);- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(add,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{3, 112, 112});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(add,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, Shape{3, 112, 112});auto add_2 = std::make_shared<opset7::Add>(conv_2, data_2);- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(add_2,- weights_3,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(add_2,+ weights_3,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model = std::make_shared<ov::Model>(OutputVector{conv_3}, ParameterVector{data, data_2});manager.register_pass<ov::pass::StridesOptimization>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{4, 4},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{4, 4},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});auto relu_1 = std::make_shared<opset7::Relu>(conv_1);Shape const_shape{1, 3, 56, 56};auto constant =opset7::Constant::create(element::f32, const_shape, std::vector<float>(shape_size(const_shape), 1));auto add = std::make_shared<opset7::Add>(relu_1, constant);- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(add,- weights_2,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{3, 112, 112});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(add,+ weights_2,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, Shape{3, 112, 112});auto reshape =std::make_shared<opset7::Reshape>(data_2,opset7::Constant::create(element::i64, Shape{4}, {1, 3, 112, 112}),@@ -489,13 +491,13 @@ TEST_F(TransformationTestsF, StridesOptimization8) {auto pool_2 = std::make_shared<opset7::MaxPool>(reshape, Strides{2, 2}, Shape{0, 0}, Shape{0, 0}, Shape{1, 1});auto squeeze = std::make_shared<opset7::Squeeze>(pool_2, op::v0::Constant::create(element::u64, Shape{1}, {0}));auto add_2 = std::make_shared<opset7::Add>(conv_2, squeeze);- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(add_2,- weights_3,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(add_2,+ weights_3,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model_ref = std::make_shared<ov::Model>(OutputVector{conv_3}, ParameterVector{data, data_2});}@@ -510,58 +512,58 @@ TEST_F(TransformationTestsF, StridesOptimization8) {// Const--` Const-` Const--` Const-`TEST_F(TransformationTestsF, StridesOptimization9) {{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{1, 1},- CoordinateDiff{0, 0},- CoordinateDiff{0, 0},- Strides{});-- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{224});- auto add_const = ov::op::v0::Constant::create(element::f32, Shape{224}, {128});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{1, 1},+ CoordinateDiff{0, 0},+ CoordinateDiff{0, 0},+ Strides{});++ auto data_2 = std::make_shared<v0::Parameter>(element::f32, Shape{224});+ auto add_const = v0::Constant::create(element::f32, Shape{224}, {128});auto add = std::make_shared<opset7::Add>(data_2, add_const);- auto add_2_const = ov::op::v0::Constant::create(element::f32, Shape{224}, {128});+ auto add_2_const = v0::Constant::create(element::f32, Shape{224}, {128});auto add_2 = std::make_shared<opset7::Add>(add, add_2_const);auto add_3 = std::make_shared<opset7::Add>(conv_1, add_2);- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(add_3,- weights_2,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});-- auto data_3 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{});- auto add_4_const = ov::op::v0::Constant::create(element::f32, Shape{}, {128});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(add_3,+ weights_2,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});++ auto data_3 = std::make_shared<v0::Parameter>(element::f32, Shape{});+ auto add_4_const = v0::Constant::create(element::f32, Shape{}, {128});auto add_4 = std::make_shared<opset7::Add>(data_3, add_4_const);- auto add_5_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {128});+ auto add_5_const = v0::Constant::create(element::f32, Shape{1}, {128});auto add_5 = std::make_shared<opset7::Add>(add_4, add_5_const);auto add_6 = std::make_shared<opset7::Add>(conv_2, add_5);- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(add_6,- weights_3,- Strides{2, 2},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(add_6,+ weights_3,+ Strides{2, 2},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model = std::make_shared<ov::Model>(OutputVector{conv_3}, ParameterVector{data, data_2, data_3});manager.register_pass<ov::pass::StridesOptimization>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto weights_1 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_1 = std::make_shared<ov::op::v1::Convolution>(data,- weights_1,- Strides{4, 4},- CoordinateDiff{0, 0},- CoordinateDiff{0, 0},- Strides{});-- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{224});+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto weights_1 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_1 = std::make_shared<v1::Convolution>(data,+ weights_1,+ Strides{4, 4},+ CoordinateDiff{0, 0},+ CoordinateDiff{0, 0},+ Strides{});++ auto data_2 = std::make_shared<v0::Parameter>(element::f32, Shape{224});auto reshape =std::make_shared<opset7::Reshape>(data_2,opset7::Constant::create(element::i64, Shape{4}, {1, 1, 1, 224}),@@ -569,39 +571,39 @@ TEST_F(TransformationTestsF, StridesOptimization9) {auto pool = std::make_shared<opset7::MaxPool>(reshape, Strides{4, 4}, Shape{0, 0}, Shape{0, 0}, Shape{1, 1});auto squeeze =std::make_shared<opset7::Squeeze>(pool, op::v0::Constant::create(element::u64, Shape{3}, {0, 1, 2}));- auto add_const = ov::op::v0::Constant::create(element::f32, Shape{56}, {128});+ auto add_const = v0::Constant::create(element::f32, Shape{56}, {128});auto add = std::make_shared<opset7::Add>(squeeze, add_const);- auto add_2_const = ov::op::v0::Constant::create(element::f32, Shape{56}, {128});+ auto add_2_const = v0::Constant::create(element::f32, Shape{56}, {128});auto add_2 = std::make_shared<opset7::Add>(add, add_2_const);auto add_3 = std::make_shared<opset7::Add>(conv_1, add_2);- auto weights_2 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_2 = std::make_shared<ov::op::v1::Convolution>(add_3,- weights_2,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});-- auto data_3 = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{});- auto new_shape = ov::op::v0::Constant::create(element::i64, Shape{4}, {1, 1, 1, 1});+ auto weights_2 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_2 = std::make_shared<v1::Convolution>(add_3,+ weights_2,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});++ auto data_3 = std::make_shared<v0::Parameter>(element::f32, Shape{});+ auto new_shape = v0::Constant::create(element::i64, Shape{4}, {1, 1, 1, 1});auto reshape_2 = std::make_shared<opset7::Reshape>(data_3, new_shape, false);auto pool_2 =std::make_shared<opset7::MaxPool>(reshape_2, Strides{2, 2}, Shape{0, 0}, Shape{0, 0}, Shape{1, 1});auto squeeze_2 =std::make_shared<opset7::Squeeze>(pool_2, op::v0::Constant::create(element::u64, Shape{4}, {0, 1, 2, 3}));- auto add_4_const = ov::op::v0::Constant::create(element::f32, Shape{}, {128});+ auto add_4_const = v0::Constant::create(element::f32, Shape{}, {128});auto add_4 = std::make_shared<opset7::Add>(squeeze_2, add_4_const);- auto add_5_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {128});+ auto add_5_const = v0::Constant::create(element::f32, Shape{1}, {128});auto add_5 = std::make_shared<opset7::Add>(add_4, add_5_const);auto add_6 = std::make_shared<opset7::Add>(conv_2, add_5);- auto weights_3 = ov::op::v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});- auto conv_3 = std::make_shared<ov::op::v1::Convolution>(add_6,- weights_3,- Strides{1, 1},- CoordinateDiff{},- CoordinateDiff{},- Strides{});+ auto weights_3 = v0::Constant::create(element::f32, Shape{3, 3, 1, 1}, {128});+ auto conv_3 = std::make_shared<v1::Convolution>(add_6,+ weights_3,+ Strides{1, 1},+ CoordinateDiff{},+ CoordinateDiff{},+ Strides{});model_ref = std::make_shared<ov::Model>(OutputVector{conv_3}, ParameterVector{data, data_2, data_3});}diff --git a/src/common/transformations/tests/common_optimizations/transpose_reshape_elimination_for_matmul.cpp b/src/common/transformations/tests/common_optimizations/transpose_reshape_elimination_for_matmul.cppindex 5e75ce3aae1..18c19d0c8db 100644--- a/src/common/transformations/tests/common_optimizations/transpose_reshape_elimination_for_matmul.cpp+++ b/src/common/transformations/tests/common_optimizations/transpose_reshape_elimination_for_matmul.cpp@@ -24,29 +24,32 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;TEST_F(TransformationTestsF, TransposeReshapeEliminationForMatMul) {Shape data_shape_1{10, 2};Shape data_shape_2{10, 2, 25};{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto const_transpose_before = ov::op::v0::Constant::create(element::i32, Shape{3}, {1, 2, 0});- auto transpose_before = std::make_shared<ov::op::v1::Transpose>(data_2, const_transpose_before);- auto const_reshape_before = ov::op::v0::Constant::create(element::i32, Shape{2}, {2, 250});- auto reshape_before = std::make_shared<ov::op::v1::Reshape>(transpose_before, const_reshape_before, false);- auto matmul = std::make_shared<ov::op::v0::MatMul>(data_1, reshape_before);- auto const_reshape_after = ov::op::v0::Constant::create(element::i32, Shape{3}, {10, 10, 25});- auto reshape_after = std::make_shared<ov::op::v1::Reshape>(matmul, const_reshape_after, false);- auto const_tranpose_after = ov::op::v0::Constant::create(element::i32, Shape{3}, {2, 0, 1});- auto tranpose_after = std::make_shared<ov::op::v1::Transpose>(reshape_after, const_tranpose_after);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto const_transpose_before = v0::Constant::create(element::i32, Shape{3}, {1, 2, 0});+ auto transpose_before = std::make_shared<v1::Transpose>(data_2, const_transpose_before);+ auto const_reshape_before = v0::Constant::create(element::i32, Shape{2}, {2, 250});+ auto reshape_before = std::make_shared<v1::Reshape>(transpose_before, const_reshape_before, false);+ auto matmul = std::make_shared<v0::MatMul>(data_1, reshape_before);+ auto const_reshape_after = v0::Constant::create(element::i32, Shape{3}, {10, 10, 25});+ auto reshape_after = std::make_shared<v1::Reshape>(matmul, const_reshape_after, false);+ auto const_tranpose_after = v0::Constant::create(element::i32, Shape{3}, {2, 0, 1});+ auto tranpose_after = std::make_shared<v1::Transpose>(reshape_after, const_tranpose_after);model = std::make_shared<Model>(OutputVector{tranpose_after}, ParameterVector{data_1, data_2});manager.register_pass<ov::pass::InitNodeInfo>();manager.register_pass<ov::pass::TransposeReshapeEliminationForMatmul>();}{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto matmul = std::make_shared<ov::op::v0::MatMul>(data_1, data_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto matmul = std::make_shared<v0::MatMul>(data_1, data_2);model_ref = std::make_shared<Model>(OutputVector{matmul}, ParameterVector{data_1, data_2});}}@@ -55,24 +58,24 @@ TEST_F(TransformationTestsF, TransposeReshapeEliminationForMatMul_TransposedA) {Shape data_shape_1{2, 10};Shape data_shape_2{10, 2, 25};{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto const_transpose_before = ov::op::v0::Constant::create(element::i32, Shape{3}, {1, 2, 0});- auto transpose_before = std::make_shared<ov::op::v1::Transpose>(data_2, const_transpose_before);- auto const_reshape_before = ov::op::v0::Constant::create(element::i32, Shape{2}, {2, 250});- auto reshape_before = std::make_shared<ov::op::v1::Reshape>(transpose_before, const_reshape_before, false);- auto matmul = std::make_shared<ov::op::v0::MatMul>(data_1, reshape_before, true, false);- auto const_reshape_after = ov::op::v0::Constant::create(element::i32, Shape{3}, {10, 10, 25});- auto reshape_after = std::make_shared<ov::op::v1::Reshape>(matmul, const_reshape_after, false);- auto const_tranpose_after = ov::op::v0::Constant::create(element::i32, Shape{3}, {2, 0, 1});- auto tranpose_after = std::make_shared<ov::op::v1::Transpose>(reshape_after, const_tranpose_after);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto const_transpose_before = v0::Constant::create(element::i32, Shape{3}, {1, 2, 0});+ auto transpose_before = std::make_shared<v1::Transpose>(data_2, const_transpose_before);+ auto const_reshape_before = v0::Constant::create(element::i32, Shape{2}, {2, 250});+ auto reshape_before = std::make_shared<v1::Reshape>(transpose_before, const_reshape_before, false);+ auto matmul = std::make_shared<v0::MatMul>(data_1, reshape_before, true, false);+ auto const_reshape_after = v0::Constant::create(element::i32, Shape{3}, {10, 10, 25});+ auto reshape_after = std::make_shared<v1::Reshape>(matmul, const_reshape_after, false);+ auto const_tranpose_after = v0::Constant::create(element::i32, Shape{3}, {2, 0, 1});+ auto tranpose_after = std::make_shared<v1::Transpose>(reshape_after, const_tranpose_after);model = std::make_shared<Model>(OutputVector{tranpose_after}, ParameterVector{data_1, data_2});manager.register_pass<ov::pass::TransposeReshapeEliminationForMatmul>();}{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto matmul = std::make_shared<ov::op::v0::MatMul>(data_1, data_2, true, false);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto matmul = std::make_shared<v0::MatMul>(data_1, data_2, true, false);model_ref = std::make_shared<Model>(OutputVector{matmul}, ParameterVector{data_1, data_2});}}@@ -81,24 +84,24 @@ TEST_F(TransformationTestsF, TransposeReshapeEliminationForMatMul_TransposedB) {Shape data_shape_1{10, 2};Shape data_shape_2{10, 2, 25};{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto const_transpose_before = ov::op::v0::Constant::create(element::i32, Shape{3}, {0, 2, 1});- auto transpose_before = std::make_shared<ov::op::v1::Transpose>(data_2, const_transpose_before);- auto const_reshape_before = ov::op::v0::Constant::create(element::i32, Shape{2}, {250, 2});- auto reshape_before = std::make_shared<ov::op::v1::Reshape>(transpose_before, const_reshape_before, false);- auto matmul = std::make_shared<ov::op::v0::MatMul>(data_1, reshape_before, false, true);- auto const_reshape_after = ov::op::v0::Constant::create(element::i32, Shape{3}, {10, 10, 25});- auto reshape_after = std::make_shared<ov::op::v1::Reshape>(matmul, const_reshape_after, false);- auto const_tranpose_after = ov::op::v0::Constant::create(element::i32, Shape{3}, {1, 0, 2});- auto tranpose_after = std::make_shared<ov::op::v1::Transpose>(reshape_after, const_tranpose_after);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto const_transpose_before = v0::Constant::create(element::i32, Shape{3}, {0, 2, 1});+ auto transpose_before = std::make_shared<v1::Transpose>(data_2, const_transpose_before);+ auto const_reshape_before = v0::Constant::create(element::i32, Shape{2}, {250, 2});+ auto reshape_before = std::make_shared<v1::Reshape>(transpose_before, const_reshape_before, false);+ auto matmul = std::make_shared<v0::MatMul>(data_1, reshape_before, false, true);+ auto const_reshape_after = v0::Constant::create(element::i32, Shape{3}, {10, 10, 25});+ auto reshape_after = std::make_shared<v1::Reshape>(matmul, const_reshape_after, false);+ auto const_tranpose_after = v0::Constant::create(element::i32, Shape{3}, {1, 0, 2});+ auto tranpose_after = std::make_shared<v1::Transpose>(reshape_after, const_tranpose_after);model = std::make_shared<Model>(OutputVector{tranpose_after}, ParameterVector{data_1, data_2});manager.register_pass<ov::pass::TransposeReshapeEliminationForMatmul>();}{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto matmul = std::make_shared<ov::op::v0::MatMul>(data_1, data_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto matmul = std::make_shared<v0::MatMul>(data_1, data_2);model_ref = std::make_shared<Model>(OutputVector{matmul}, ParameterVector{data_1, data_2});}}@@ -107,24 +110,24 @@ TEST_F(TransformationTestsF, TransposeReshapeEliminationForMatMul_TransposedAB)Shape data_shape_1{2, 10};Shape data_shape_2{10, 2, 25};{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto const_transpose_before = ov::op::v0::Constant::create(element::i32, Shape{3}, {0, 2, 1});- auto transpose_before = std::make_shared<ov::op::v1::Transpose>(data_2, const_transpose_before);- auto const_reshape_before = ov::op::v0::Constant::create(element::i32, Shape{2}, {250, 2});- auto reshape_before = std::make_shared<ov::op::v1::Reshape>(transpose_before, const_reshape_before, false);- auto matmul = std::make_shared<ov::op::v0::MatMul>(data_1, reshape_before, true, true);- auto const_reshape_after = ov::op::v0::Constant::create(element::i32, Shape{3}, {10, 10, 25});- auto reshape_after = std::make_shared<ov::op::v1::Reshape>(matmul, const_reshape_after, false);- auto const_tranpose_after = ov::op::v0::Constant::create(element::i32, Shape{3}, {1, 0, 2});- auto tranpose_after = std::make_shared<ov::op::v1::Transpose>(reshape_after, const_tranpose_after);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto const_transpose_before = v0::Constant::create(element::i32, Shape{3}, {0, 2, 1});+ auto transpose_before = std::make_shared<v1::Transpose>(data_2, const_transpose_before);+ auto const_reshape_before = v0::Constant::create(element::i32, Shape{2}, {250, 2});+ auto reshape_before = std::make_shared<v1::Reshape>(transpose_before, const_reshape_before, false);+ auto matmul = std::make_shared<v0::MatMul>(data_1, reshape_before, true, true);+ auto const_reshape_after = v0::Constant::create(element::i32, Shape{3}, {10, 10, 25});+ auto reshape_after = std::make_shared<v1::Reshape>(matmul, const_reshape_after, false);+ auto const_tranpose_after = v0::Constant::create(element::i32, Shape{3}, {1, 0, 2});+ auto tranpose_after = std::make_shared<v1::Transpose>(reshape_after, const_tranpose_after);model = std::make_shared<Model>(OutputVector{tranpose_after}, ParameterVector{data_1, data_2});manager.register_pass<ov::pass::TransposeReshapeEliminationForMatmul>();}{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto matmul = std::make_shared<ov::op::v0::MatMul>(data_1, data_2, true, false);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto matmul = std::make_shared<v0::MatMul>(data_1, data_2, true, false);model_ref = std::make_shared<Model>(OutputVector{matmul}, ParameterVector{data_1, data_2});}}@@ -133,31 +136,28 @@ TEST_F(TransformationTestsF, TransposeReshapeEliminationForMatMul_Einsum) {Shape data_shape_1{5, 2};Shape data_shape_2{10, 2, 25};{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);auto einsum = std::make_shared<opset7::Einsum>(OutputVector{data_1, data_2}, "kl,mlj->mkj");model = std::make_shared<Model>(OutputVector{einsum}, ParameterVector{data_1, data_2});manager.register_pass<ov::pass::EinsumDecomposition>();manager.register_pass<ov::pass::TransposeReshapeEliminationForMatmul>();}{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);auto broadcast_shape_constant_1 =- std::make_shared<ov::op::v0::Constant>(element::i64, Shape{data_shape_1.size()}, data_shape_1);+ std::make_shared<v0::Constant>(element::i64, Shape{data_shape_1.size()}, data_shape_1);auto broadcast_shape_constant_2 =- std::make_shared<ov::op::v0::Constant>(element::i64, Shape{data_shape_2.size()}, data_shape_2);- auto broadcast_1 = std::make_shared<ov::op::v3::Broadcast>(data_1,- broadcast_shape_constant_1,- ov::op::BroadcastType::BIDIRECTIONAL);- auto broadcast_2 = std::make_shared<ov::op::v3::Broadcast>(data_2,- broadcast_shape_constant_2,- ov::op::BroadcastType::BIDIRECTIONAL);+ std::make_shared<v0::Constant>(element::i64, Shape{data_shape_2.size()}, data_shape_2);+ auto broadcast_1 =+ std::make_shared<v3::Broadcast>(data_1, broadcast_shape_constant_1, ov::op::BroadcastType::BIDIRECTIONAL);+ auto broadcast_2 =+ std::make_shared<v3::Broadcast>(data_2, broadcast_shape_constant_2, ov::op::BroadcastType::BIDIRECTIONAL);// for some cases Reshape may be first input for Matmul- auto shape_constant =- std::make_shared<ov::op::v0::Constant>(element::i64, Shape{data_shape_1.size()}, data_shape_1);- auto reshape = std::make_shared<ov::op::v1::Reshape>(broadcast_1, shape_constant, false);- auto matmul = std::make_shared<ov::op::v0::MatMul>(reshape, broadcast_2, false, false);+ auto shape_constant = std::make_shared<v0::Constant>(element::i64, Shape{data_shape_1.size()}, data_shape_1);+ auto reshape = std::make_shared<v1::Reshape>(broadcast_1, shape_constant, false);+ auto matmul = std::make_shared<v0::MatMul>(reshape, broadcast_2, false, false);model_ref = std::make_shared<Model>(OutputVector{matmul}, ParameterVector{data_1, data_2});}}diff --git a/src/common/transformations/tests/control_flow/unroll_if_test.cpp b/src/common/transformations/tests/control_flow/unroll_if_test.cppindex dbe7492eadb..99e14810674 100644--- a/src/common/transformations/tests/control_flow/unroll_if_test.cpp+++ b/src/common/transformations/tests/control_flow/unroll_if_test.cpp@@ -33,6 +33,9 @@using namespace testing;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;namespace ov {namespace test {using op::v0::Constant;@@ -41,13 +44,13 @@ 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});+ auto Xt = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});Xt->set_friendly_name("Xt");- auto Yt = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Yt = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});Yt->set_friendly_name("Yt");- auto add_op = std::make_shared<ov::op::v1::Add>(Xt, Yt);+ auto add_op = std::make_shared<v1::Add>(Xt, Yt);add_op->set_friendly_name("add_op");- auto then_op_result = std::make_shared<ov::op::v0::Result>(add_op);+ auto then_op_result = std::make_shared<v0::Result>(add_op);then_op_result->set_friendly_name("then_op_result");auto then_body = std::make_shared<ov::Model>(ov::OutputVector{then_op_result}, ov::ParameterVector{Xt, Yt});ov::pass::InitNodeInfo().run_on_model(then_body);@@ -55,13 +58,13 @@ std::shared_ptr<ov::Model> get_then_body() {}std::shared_ptr<ov::Model> get_else_body() {- auto Xe = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Xe = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});Xe->set_friendly_name("Xe");- auto Ye = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Ye = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});Ye->set_friendly_name("Ye");- auto mul_op = std::make_shared<ov::op::v1::Multiply>(Xe, Ye);+ auto mul_op = std::make_shared<v1::Multiply>(Xe, Ye);mul_op->set_friendly_name("mul_op");- auto else_op_result = std::make_shared<ov::op::v0::Result>(mul_op);+ auto else_op_result = std::make_shared<v0::Result>(mul_op);else_op_result->set_friendly_name("else_op_result");auto else_body = std::make_shared<ov::Model>(ov::OutputVector{else_op_result}, ov::ParameterVector{Xe, Ye});ov::pass::InitNodeInfo().run_on_model(else_body);@@ -107,13 +110,13 @@ std::shared_ptr<ov::Model> get_else_body_i64() {}std::shared_ptr<ov::Model> create_if_model(bool condition) {- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});X->set_friendly_name("X");- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});Y->set_friendly_name("y");- auto cond = std::make_shared<ov::op::v0::Constant>(ov::element::boolean, ov::Shape{1}, condition);+ auto cond = std::make_shared<v0::Constant>(ov::element::boolean, ov::Shape{1}, condition);cond->set_friendly_name("cond");- auto if_op = std::make_shared<ov::op::v8::If>(cond);+ auto if_op = std::make_shared<v8::If>(cond);if_op->set_friendly_name("if_op");const auto& then_body = get_then_body();const auto& else_body = get_else_body();@@ -125,7 +128,7 @@ std::shared_ptr<ov::Model> create_if_model(bool condition) {if_op->set_input(X, then_p[0], else_p[0]);if_op->set_input(Y, then_p[1], else_p[1]);if_op->set_output(then_body->get_results()[0], else_body->get_results()[0]);- auto if_result = std::make_shared<ov::op::v0::Result>(if_op);+ auto if_result = std::make_shared<v0::Result>(if_op);if_result->set_friendly_name("if_result");return std::make_shared<ov::Model>(ov::OutputVector{if_result}, ov::ParameterVector{X, Y});@@ -151,7 +154,7 @@ TEST(TransformationTests, UnrollIfCondIsTrue) {for (auto& op : f->get_ops()) {std::vector<std::string> fused_names = ov::getFusedNamesVector(op);- if (ov::is_type<ov::op::v1::Add>(op)) {+ if (ov::is_type<v1::Add>(op)) {ASSERT_EQ(2, fused_names.size());ASSERT_TRUE(ov::util::contains(fused_names, "add_op"));ASSERT_TRUE(ov::util::contains(fused_names, "if_op"));@@ -182,7 +185,7 @@ TEST(TransformationTests, UnrollIfCondIsFalse) {for (auto& op : f->get_ops()) {std::vector<std::string> fused_names = ov::getFusedNamesVector(op);- if (ov::is_type<ov::op::v1::Multiply>(op)) {+ if (ov::is_type<v1::Multiply>(op)) {ASSERT_EQ(2, fused_names.size());ASSERT_TRUE(ov::util::contains(fused_names, "mul_op"));ASSERT_TRUE(ov::util::contains(fused_names, "if_op"));@@ -196,12 +199,11 @@ TEST(TransformationTests, UnrollIfCondIsFalse) {TEST(TransformationTests, UnrollIfWithSplitInput) {std::shared_ptr<ov::Model> f(nullptr), f_ref(nullptr);{- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{2, 3});- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto split =- std::make_shared<ov::op::v1::Split>(X, ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {0}), 2);- auto cond = std::make_shared<ov::op::v0::Constant>(ov::element::boolean, ov::Shape{1}, false);- auto if_op = std::make_shared<ov::op::v8::If>(cond);+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{2, 3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto split = std::make_shared<v1::Split>(X, v0::Constant::create(ov::element::i32, ov::Shape{}, {0}), 2);+ auto cond = std::make_shared<v0::Constant>(ov::element::boolean, ov::Shape{1}, false);+ auto if_op = std::make_shared<v8::If>(cond);const auto& then_body = get_then_body();const auto& else_body = get_else_body();@@ -214,7 +216,7 @@ TEST(TransformationTests, UnrollIfWithSplitInput) {if_op->set_input(split->output(1), nullptr, else_p[0]);if_op->set_input(Y, then_p[1], else_p[1]);if_op->set_output(then_body->get_results()[0], else_body->get_results()[0]);- auto if_result = std::make_shared<ov::op::v0::Result>(if_op);+ auto if_result = std::make_shared<v0::Result>(if_op);f = std::make_shared<ov::Model>(ov::OutputVector{if_result}, ov::ParameterVector{X, Y});@@ -227,12 +229,11 @@ TEST(TransformationTests, UnrollIfWithSplitInput) {}{- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{2, 3});- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto split =- std::make_shared<ov::op::v1::Split>(X, ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {0}), 2);- auto mul_op = std::make_shared<ov::op::v1::Multiply>(split->output(1), Y);- auto if_result = std::make_shared<ov::op::v0::Result>(mul_op);+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{2, 3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto split = std::make_shared<v1::Split>(X, v0::Constant::create(ov::element::i32, ov::Shape{}, {0}), 2);+ auto mul_op = std::make_shared<v1::Multiply>(split->output(1), Y);+ auto if_result = std::make_shared<v0::Result>(mul_op);f_ref = std::make_shared<ov::Model>(ov::OutputVector{if_result}, ov::ParameterVector{X, Y});}@@ -243,14 +244,14 @@ TEST(TransformationTests, UnrollIfWithSplitInput) {TEST(TransformationTests, UnrollNestedIfThenBody) {std::shared_ptr<ov::Model> f(nullptr), f_ref(nullptr);{- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});auto then_body = create_if_model(true);auto else_body = create_if_model(false);- auto cond = std::make_shared<ov::op::v0::Constant>(ov::element::boolean, ov::Shape{1}, true);- auto if_op = std::make_shared<ov::op::v8::If>(cond);+ auto cond = std::make_shared<v0::Constant>(ov::element::boolean, ov::Shape{1}, true);+ auto if_op = std::make_shared<v8::If>(cond);if_op->set_then_body(then_body);if_op->set_else_body(else_body);@@ -259,7 +260,7 @@ TEST(TransformationTests, UnrollNestedIfThenBody) {if_op->set_input(X, then_p[0], else_p[0]);if_op->set_input(Y, then_p[1], else_p[1]);if_op->set_output(then_body->get_results()[0], else_body->get_results()[0]);- auto if_result = std::make_shared<ov::op::v0::Result>(if_op);+ auto if_result = std::make_shared<v0::Result>(if_op);f = std::make_shared<ov::Model>(ov::OutputVector{if_result}, ov::ParameterVector{X, Y});ov::pass::Manager manager;@@ -278,25 +279,25 @@ TEST(TransformationTests, UnrollNestedIfThenBody) {TEST(TransformationTests, UnrollIfCondIsTrueMultiOutput) {std::shared_ptr<ov::Model> f(nullptr), f_ref(nullptr);{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{3});- auto X = std::make_shared<ov::op::v1::VariadicSplit>(data,- ov::op::v0::Constant::create(element::i32, {1}, {0}),- ov::op::v0::Constant::create(element::i32, {2}, {1, 2}));- auto cond = std::make_shared<ov::op::v0::Constant>(element::boolean, Shape{1}, true);- auto if_op = std::make_shared<ov::op::v8::If>(cond);- auto Xt = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2});- auto then_op_result = std::make_shared<ov::op::v0::Result>(Xt);+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{3});+ auto X = std::make_shared<v1::VariadicSplit>(data,+ v0::Constant::create(element::i32, {1}, {0}),+ v0::Constant::create(element::i32, {2}, {1, 2}));+ auto cond = std::make_shared<v0::Constant>(element::boolean, Shape{1}, true);+ auto if_op = std::make_shared<v8::If>(cond);+ auto Xt = std::make_shared<v0::Parameter>(element::f32, Shape{2});+ auto then_op_result = std::make_shared<v0::Result>(Xt);auto then_body = std::make_shared<ov::Model>(OutputVector{then_op_result}, ParameterVector{Xt});- auto Xe = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{2});- auto else_op_result = std::make_shared<ov::op::v0::Result>(Xe);+ auto Xe = std::make_shared<v0::Parameter>(element::f32, Shape{2});+ auto else_op_result = std::make_shared<v0::Result>(Xe);auto else_body = std::make_shared<ov::Model>(OutputVector{else_op_result}, ParameterVector{Xe});if_op->set_then_body(then_body);if_op->set_else_body(else_body);if_op->set_input(X->output(1), Xt, Xe);if_op->set_output(then_op_result, else_op_result);- auto if_result = std::make_shared<ov::op::v0::Result>(if_op);+ auto if_result = std::make_shared<v0::Result>(if_op);f = std::make_shared<ov::Model>(OutputVector{if_result}, ParameterVector{data});@@ -309,11 +310,11 @@ TEST(TransformationTests, UnrollIfCondIsTrueMultiOutput) {}{- auto data = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{3});- auto X = std::make_shared<ov::op::v1::VariadicSplit>(data,- ov::op::v0::Constant::create(element::i32, {1}, {0}),- ov::op::v0::Constant::create(element::i32, {2}, {1, 2}));- auto if_result = std::make_shared<ov::op::v0::Result>(X->output(1));+ auto data = std::make_shared<v0::Parameter>(element::f32, Shape{3});+ auto X = std::make_shared<v1::VariadicSplit>(data,+ v0::Constant::create(element::i32, {1}, {0}),+ v0::Constant::create(element::i32, {2}, {1, 2}));+ auto if_result = std::make_shared<v0::Result>(X->output(1));f_ref = std::make_shared<ov::Model>(OutputVector{if_result}, ParameterVector{data});}@@ -324,32 +325,32 @@ TEST(TransformationTests, UnrollIfCondIsTrueMultiOutput) {TEST(TransformationTests, UnrollIfInsideIf) {std::shared_ptr<ov::Model> f(nullptr), f_ref(nullptr);{- auto cond = std::make_shared<ov::op::v0::Constant>(ov::element::boolean, ov::Shape{1}, true);- auto not_cond = std::make_shared<ov::op::v1::LogicalNot>(cond);- auto if_op = std::make_shared<ov::op::v8::If>(cond);+ auto cond = std::make_shared<v0::Constant>(ov::element::boolean, ov::Shape{1}, true);+ auto not_cond = std::make_shared<v1::LogicalNot>(cond);+ auto if_op = std::make_shared<v8::If>(cond);std::shared_ptr<ov::Model> then_body;{- auto cond_inside = std::make_shared<ov::op::v0::Parameter>(ov::element::boolean, ov::Shape{1});- auto if_inside = std::make_shared<ov::op::v8::If>(cond_inside);+ auto cond_inside = std::make_shared<v0::Parameter>(ov::element::boolean, ov::Shape{1});+ auto if_inside = std::make_shared<v8::If>(cond_inside);std::shared_ptr<ov::Model> then_body_inside;{- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto add = std::make_shared<ov::op::v1::Add>(X, Y);+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto add = std::make_shared<v1::Add>(X, Y);then_body_inside = std::make_shared<ov::Model>(add, ov::ParameterVector{X, Y});}std::shared_ptr<ov::Model> else_body_inside;{- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto mul = std::make_shared<ov::op::v1::Multiply>(X, Y);+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto mul = std::make_shared<v1::Multiply>(X, Y);else_body_inside = std::make_shared<ov::Model>(mul, ov::ParameterVector{X, Y});}- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});if_inside->set_then_body(then_body_inside);if_inside->set_else_body(else_body_inside);auto then_p = then_body_inside->get_parameters();@@ -357,21 +358,21 @@ TEST(TransformationTests, UnrollIfInsideIf) {if_inside->set_input(X, then_p[0], else_p[0]);if_inside->set_input(Y, then_p[1], else_p[1]);if_inside->set_output(then_body_inside->get_results()[0], else_body_inside->get_results()[0]);- auto if_result = std::make_shared<ov::op::v0::Result>(if_inside);+ auto if_result = std::make_shared<v0::Result>(if_inside);then_body = std::make_shared<ov::Model>(if_result, ov::ParameterVector{cond_inside, X, Y});}std::shared_ptr<ov::Model> else_body;{- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto sub = std::make_shared<ov::op::v1::Subtract>(X, Y);+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto sub = std::make_shared<v1::Subtract>(X, Y);else_body = std::make_shared<ov::Model>(sub, ov::ParameterVector{X, Y});}- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});if_op->set_then_body(then_body);if_op->set_else_body(else_body);auto then_p = then_body->get_parameters();@@ -380,7 +381,7 @@ TEST(TransformationTests, UnrollIfInsideIf) {if_op->set_input(X, then_p[1], else_p[0]);if_op->set_input(Y, then_p[2], else_p[1]);if_op->set_output(then_body->get_results()[0], else_body->get_results()[0]);- auto if_result = std::make_shared<ov::op::v0::Result>(if_op);+ auto if_result = std::make_shared<v0::Result>(if_op);f = std::make_shared<ov::Model>(ov::OutputVector{if_result}, ov::ParameterVector{X, Y});ov::pass::Manager manager;@@ -393,9 +394,9 @@ TEST(TransformationTests, UnrollIfInsideIf) {}{- auto X = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto Y = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{3});- auto mul = std::make_shared<ov::op::v1::Multiply>(X, Y);+ auto X = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto Y = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{3});+ auto mul = std::make_shared<v1::Multiply>(X, Y);f_ref = std::make_shared<ov::Model>(mul, ov::ParameterVector{X, Y});}diff --git a/src/common/transformations/tests/hash_tests.cpp b/src/common/transformations/tests/hash_tests.cppindex 3b4f97f2af5..3e5e8be8b33 100644--- a/src/common/transformations/tests/hash_tests.cpp+++ b/src/common/transformations/tests/hash_tests.cpp@@ -10,8 +10,9 @@#include "openvino/op/parameter.hpp"#include "transformations/hash.hpp"+namespace v0 = ov::op::v0;namespace ov::test {-using ov::op::v0::Parameter, ov::op::v0::Constant, ov::op::v1::Add;+using v0::Parameter, v0::Constant, ov::op::v1::Add;TEST(HashTest, same_model_hashed_without_weights) {uint64_t hash1 = 0, hash2 = 0;diff --git a/src/common/transformations/tests/make_stateful_test.cpp b/src/common/transformations/tests/make_stateful_test.cppindex de4a42e418c..41a2f1f64a7 100644--- a/src/common/transformations/tests/make_stateful_test.cpp+++ b/src/common/transformations/tests/make_stateful_test.cpp@@ -23,6 +23,7 @@ using namespace ov;using namespace opset8;using namespace std;+namespace op_util = ov::op::util;std::shared_ptr<ov::Model> get_test_model(bool insert_squeeze, bool use_friendly_names) {std::shared_ptr<ov::Model> model;auto X = make_shared<Parameter>(element::f32, Shape{32, 1, 10});@@ -63,12 +64,12 @@ std::shared_ptr<ov::Model> get_ref_model(bool insert_squeeze, bool use_friendly_std::shared_ptr<ov::Model> model;// create ReadValue for Xauto variable_x =- std::make_shared<ov::op::util::Variable>(ov::op::util::VariableInfo{Shape{32, 1, 10}, element::f32, "xres0"});+ std::make_shared<op_util::Variable>(op_util::VariableInfo{Shape{32, 1, 10}, element::f32, "xres0"});auto read_val_x = make_shared<ReadValue>(variable_x);// create ReadValue for Yauto variable_y =- std::make_shared<ov::op::util::Variable>(ov::op::util::VariableInfo{Shape{32, 1, 10}, element::f32, "yres1"});+ std::make_shared<op_util::Variable>(op_util::VariableInfo{Shape{32, 1, 10}, element::f32, "yres1"});auto read_val_y = make_shared<ReadValue>(variable_y);if (!use_friendly_names) {diff --git a/src/common/transformations/tests/offline_transformations/pruning_test.cpp b/src/common/transformations/tests/offline_transformations/pruning_test.cppindex 6c95ad61d85..9d67e77c136 100644--- a/src/common/transformations/tests/offline_transformations/pruning_test.cpp+++ b/src/common/transformations/tests/offline_transformations/pruning_test.cpp@@ -47,6 +47,8 @@#include "openvino/util/env_util.hpp"#include "transformations/init_node_info.hpp"+namespace v1 = ov::op::v1;+namespace v12 = ov::op::v12;#define VISUALIZE_TESTS_TREE false#define VISUALIZE_TREE_ROOT "/tmp/"@@ -179,7 +181,7 @@ TEST_F(TransformationTestsF, PropagateMasksBasic) {auto sub = std::make_shared<opset10::Subtract>(add, sub_const);auto mul_const = create_constant_with_zeros(Shape{1, 6, 1, 1}, {{}, {3}, {}, {}});- auto mul = std::make_shared<ov::op::v1::Multiply>(sub, mul_const);+ auto mul = std::make_shared<v1::Multiply>(sub, mul_const);auto weights2 = create_constant_with_zeros(weights_shape2, {{1, 2}, {1, 2, 3}, {}, {}});auto conv2 = std::make_shared<opset10::Convolution>(mul,@@ -212,7 +214,7 @@ TEST_F(TransformationTestsF, PropagateMasksBasic) {auto sub = std::make_shared<opset10::Subtract>(add, sub_const);auto mul_const = opset10::Constant::create(element::f32, Shape{1, 3, 1, 1}, {1});- auto mul = std::make_shared<ov::op::v1::Multiply>(sub, mul_const);+ auto mul = std::make_shared<v1::Multiply>(sub, mul_const);auto weights2 =opset10::Constant::create(element::f32,@@ -586,7 +588,7 @@ TEST_F(TransformationTestsF, NegativePad12PropagateMaskPassThrough) {auto pads_begin = Constant::create(element::i32, Shape{4}, {0, 0, 1, -1});auto pads_end = Constant::create(element::i32, Shape{4}, {0, 0, 2, -2});- auto pad = std::make_shared<ov::op::v12::Pad>(clamp, pads_begin, pads_end, op::PadMode::CONSTANT);+ auto pad = std::make_shared<v12::Pad>(clamp, pads_begin, pads_end, op::PadMode::CONSTANT);auto max_pool = std::make_shared<MaxPool>(pad, Strides{1, 1}, Strides{1, 1}, Shape{0, 0}, Shape{1, 1}, Shape{4, 4});max_pool->set_friendly_name("max_pool");@@ -618,7 +620,7 @@ TEST_F(TransformationTestsF, NegativePad12PropagateMaskPassThrough) {auto pads_begin = Constant::create(element::i32, Shape{4}, {0, 0, 1, -1});auto pads_end = Constant::create(element::i32, Shape{4}, {0, 0, 2, -2});- auto pad = std::make_shared<ov::op::v12::Pad>(clamp, pads_begin, pads_end, op::PadMode::CONSTANT);+ auto pad = std::make_shared<v12::Pad>(clamp, pads_begin, pads_end, op::PadMode::CONSTANT);auto max_pool =std::make_shared<MaxPool>(pad, Strides{1, 1}, Strides{1, 1}, Shape{0, 0}, Shape{1, 1}, Shape{4, 4});diff --git a/src/common/transformations/tests/op_conversions/batch_norm_decomposition_test.cpp b/src/common/transformations/tests/op_conversions/batch_norm_decomposition_test.cppindex c8cbbad1ba9..e6a0a69bf01 100644--- a/src/common/transformations/tests/op_conversions/batch_norm_decomposition_test.cpp+++ b/src/common/transformations/tests/op_conversions/batch_norm_decomposition_test.cpp@@ -27,6 +27,9 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;std::shared_ptr<ov::Model> get_ref_model_with_dyn_shapes(ov::element::Type precision, const PartialShape& input_shape) {auto input = std::make_shared<opset1::Parameter>(precision, input_shape);auto gamma = std::make_shared<opset1::Parameter>(precision, PartialShape{-1});@@ -34,34 +37,33 @@ std::shared_ptr<ov::Model> get_ref_model_with_dyn_shapes(ov::element::Type preciauto mean = std::make_shared<opset1::Parameter>(precision, PartialShape{-1});auto var = std::make_shared<opset1::Parameter>(precision, PartialShape{-1});// scale_add = variance + eps- auto scale_add = std::make_shared<ov::op::v1::Add>(var, ov::op::v0::Constant::create(precision, Shape{}, {0.001}));+ auto scale_add = std::make_shared<v1::Add>(var, v0::Constant::create(precision, Shape{}, {0.001}));// scale = sqrt(variance + eps)- auto scale = std::make_shared<ov::op::v0::Sqrt>(scale_add);+ auto scale = std::make_shared<v0::Sqrt>(scale_add);// Divide `gamma` by `sqrt(variance + eps)`- auto gamma_div_scale = std::make_shared<ov::op::v1::Divide>(gamma, scale);+ auto gamma_div_scale = std::make_shared<v1::Divide>(gamma, scale);int64_t dims_to_add = input->get_partial_shape().rank().get_length() - 2;- const auto one = ov::op::v0::Constant::create(element::i64, Shape{1}, {1});- const auto tail_shape_rank = ov::op::v0::Constant::create(element::i64, Shape{1}, {dims_to_add});- const auto tail_shape = std::make_shared<ov::op::v3::Broadcast>(one, tail_shape_rank);- const auto C_dim = std::make_shared<ov::op::v3::ShapeOf>(gamma);+ const auto one = v0::Constant::create(element::i64, Shape{1}, {1});+ const auto tail_shape_rank = v0::Constant::create(element::i64, Shape{1}, {dims_to_add});+ const auto tail_shape = std::make_shared<v3::Broadcast>(one, tail_shape_rank);+ const auto C_dim = std::make_shared<v3::ShapeOf>(gamma);// create new shape [1, C, 1, 1, ...]- const auto new_shape = std::make_shared<ov::op::v0::Concat>(OutputVector{one, C_dim, tail_shape}, 0);+ const auto new_shape = std::make_shared<v0::Concat>(OutputVector{one, C_dim, tail_shape}, 0);- std::shared_ptr<Node> gamma_div_scale_aligned =- std::make_shared<ov::op::v1::Reshape>(gamma_div_scale, new_shape, true);- std::shared_ptr<Node> beta_aligned = std::make_shared<ov::op::v1::Reshape>(beta, new_shape, true);- std::shared_ptr<Node> mean_aligned = std::make_shared<ov::op::v1::Reshape>(mean, new_shape, true);- std::shared_ptr<Node> mean_negative = std::make_shared<ov::op::v1::Multiply>(- mean_aligned,- ov::op::v0::Constant::create(mean_aligned->get_output_element_type(0), Shape{}, {-1}));+ std::shared_ptr<Node> gamma_div_scale_aligned = std::make_shared<v1::Reshape>(gamma_div_scale, new_shape, true);+ std::shared_ptr<Node> beta_aligned = std::make_shared<v1::Reshape>(beta, new_shape, true);+ std::shared_ptr<Node> mean_aligned = std::make_shared<v1::Reshape>(mean, new_shape, true);+ std::shared_ptr<Node> mean_negative =+ std::make_shared<v1::Multiply>(mean_aligned,+ v0::Constant::create(mean_aligned->get_output_element_type(0), Shape{}, {-1}));// input_sub_mean = input + mean * -1- auto input_sub_mean = std::make_shared<ov::op::v1::Add>(input, mean_negative);+ auto input_sub_mean = std::make_shared<v1::Add>(input, mean_negative);// Multiply `input - mean` and `gamma / sqrt(variance + eps)`- auto mul = std::make_shared<ov::op::v1::Multiply>(input_sub_mean, gamma_div_scale_aligned);+ auto mul = std::make_shared<v1::Multiply>(input_sub_mean, gamma_div_scale_aligned);// Add `(input - mean) * gamma / sqrt(variance + eps)` and `beta`- auto add = std::make_shared<ov::op::v1::Add>(mul, beta_aligned);+ auto add = std::make_shared<v1::Add>(mul, beta_aligned);return std::make_shared<ov::Model>(OutputVector{add}, ParameterVector{input, gamma, beta, mean, var});}diff --git a/src/common/transformations/tests/op_conversions/convert_avgpool_downgrade.cpp b/src/common/transformations/tests/op_conversions/convert_avgpool_downgrade.cppindex b3a54eb5025..df4767670f7 100644--- a/src/common/transformations/tests/op_conversions/convert_avgpool_downgrade.cpp+++ b/src/common/transformations/tests/op_conversions/convert_avgpool_downgrade.cpp@@ -18,10 +18,13 @@#include "openvino/pass/manager.hpp"#include "openvino/pass/visualize_tree.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;namespace {std::shared_ptr<ov::Model> create_v14_model(const ov::op::RoundingType rounding_type, const bool exclude_pad = true) {- const auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 64, 64});+ const auto input = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 64, 64});const ov::Strides strides{1, 1}, dilations{1, 1};const ov::Shape pads_begin{1, 1}, pads_end{1, 1}, kernel{2, 2};@@ -40,18 +43,18 @@ std::shared_ptr<ov::Model> create_v14_model(const ov::op::RoundingType rounding_}std::shared_ptr<ov::Model> create_v1_model(const ov::op::RoundingType rounding_type) {- const auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 64, 64});+ const auto input = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 64, 64});const ov::Strides strides{1, 1}, dilations{1, 1};const ov::Shape pads_begin{1, 1}, pads_end{1, 1}, kernel{2, 2};- const auto avg_pool_v1 = std::make_shared<ov::op::v1::AvgPool>(input,- strides,- pads_begin,- pads_end,- kernel,- true,- rounding_type,- ov::op::PadType::EXPLICIT);+ const auto avg_pool_v1 = std::make_shared<v1::AvgPool>(input,+ strides,+ pads_begin,+ pads_end,+ kernel,+ true,+ rounding_type,+ ov::op::PadType::EXPLICIT);avg_pool_v1->set_friendly_name("avg_pool_v1");@@ -59,15 +62,15 @@ std::shared_ptr<ov::Model> create_v1_model(const ov::op::RoundingType rounding_t}std::shared_ptr<ov::Model> create_exclude_pad_workaround_model() {- using ov::op::v0::Concat;- using ov::op::v0::Constant;- using ov::op::v1::ConvertLike;- using ov::op::v1::Pad;- using ov::op::v1::Subtract;- using ov::op::v3::Broadcast;- using ov::op::v3::ShapeOf;-- const auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 64, 64});+ using v0::Concat;+ using v0::Constant;+ using v1::ConvertLike;+ using v1::Pad;+ using v1::Subtract;+ using v3::Broadcast;+ using v3::ShapeOf;++ const auto input = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 64, 64});const ov::Strides strides{1, 1}, dilations{1, 1};const ov::Shape pads_begin{1, 1}, pads_end{1, 1}, kernel{2, 2};@@ -89,14 +92,14 @@ std::shared_ptr<ov::Model> create_exclude_pad_workaround_model() {std::make_shared<Pad>(input, pads_begin_v1, pads_end_v1, zero_node, ov::op::PadMode::CONSTANT);const auto pads_begin_zeros = ov::Shape{0, 0};const auto pads_end_zeros = ov::Shape{0, 0};- const auto avg_pool_v1 = std::make_shared<ov::op::v1::AvgPool>(pad_node,- strides,- pads_begin_zeros,- pads_end_zeros,- kernel,- false,- ov::op::RoundingType::CEIL,- ov::op::PadType::EXPLICIT);+ const auto avg_pool_v1 = std::make_shared<v1::AvgPool>(pad_node,+ strides,+ pads_begin_zeros,+ pads_end_zeros,+ kernel,+ false,+ ov::op::RoundingType::CEIL,+ ov::op::PadType::EXPLICIT);avg_pool_v1->set_friendly_name("avg_pool_v1");diff --git a/src/common/transformations/tests/op_conversions/convert_convertpromotetypes_test.cpp b/src/common/transformations/tests/op_conversions/convert_convertpromotetypes_test.cppindex 20a9971bbb5..2b5b4975915 100644--- a/src/common/transformations/tests/op_conversions/convert_convertpromotetypes_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_convertpromotetypes_test.cpp@@ -10,6 +10,7 @@#include "openvino/op/parameter.hpp"#include "openvino/pass/manager.hpp"+namespace v0 = ov::op::v0;namespace {struct ConvertPromoteTypesTestParams {@@ -41,8 +42,8 @@ protected:const ov::element::Type& lhsType,const ov::PartialShape& rhsShape,const ov::element::Type& rhsType) {- const auto lhs = std::make_shared<ov::op::v0::Parameter>(lhsType, lhsShape);- const auto rhs = std::make_shared<ov::op::v0::Parameter>(rhsType, rhsShape);+ const auto lhs = std::make_shared<v0::Parameter>(lhsType, lhsShape);+ const auto rhs = std::make_shared<v0::Parameter>(rhsType, rhsShape);const auto convert_promote_types = std::make_shared<ov::op::v14::ConvertPromoteTypes>(lhs, rhs, true);return std::make_shared<ov::Model>(convert_promote_types->outputs(), ov::ParameterVector{lhs, rhs}, "Actual");}@@ -52,10 +53,10 @@ protected:const ov::PartialShape& rhsShape,const ov::element::Type& rhsType,const ov::element::Type& alignType) {- const auto lhs = std::make_shared<ov::op::v0::Parameter>(lhsType, lhsShape);- const auto rhs = std::make_shared<ov::op::v0::Parameter>(rhsType, rhsShape);- const auto lhs_converted = std::make_shared<ov::op::v0::Convert>(lhs, alignType);- const auto rhs_converted = std::make_shared<ov::op::v0::Convert>(rhs, alignType);+ const auto lhs = std::make_shared<v0::Parameter>(lhsType, lhsShape);+ const auto rhs = std::make_shared<v0::Parameter>(rhsType, rhsShape);+ const auto lhs_converted = std::make_shared<v0::Convert>(lhs, alignType);+ const auto rhs_converted = std::make_shared<v0::Convert>(rhs, alignType);return std::make_shared<ov::Model>(ov::OutputVector{lhs_converted, rhs_converted},ov::ParameterVector{lhs, rhs},"Reference");diff --git a/src/common/transformations/tests/op_conversions/convert_gather_to_compressed_test.cpp b/src/common/transformations/tests/op_conversions/convert_gather_to_compressed_test.cppindex 06c1a82cc0c..309710edca8 100644--- a/src/common/transformations/tests/op_conversions/convert_gather_to_compressed_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_gather_to_compressed_test.cpp@@ -23,24 +23,28 @@using namespace testing;using namespace ov::pass;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;+namespace v11 = ov::op::v11;TEST_F(TransformationTestsF, ConvertGatherToCompressed1) {{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});- auto convert = std::make_shared<ov::op::v0::Convert>(weights_const, ov::element::f32);- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});- auto scale = std::make_shared<ov::op::v1::Multiply>(convert, scale_const);- auto gather = std::make_shared<ov::op::v8::Gather>(scale, input1, axis_const);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});+ auto convert = std::make_shared<v0::Convert>(weights_const, ov::element::f32);+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});+ auto scale = std::make_shared<v1::Multiply>(convert, scale_const);+ auto gather = std::make_shared<v8::Gather>(scale, input1, axis_const);model = std::make_shared<ov::Model>(ov::OutputVector{gather}, ov::ParameterVector{input1});manager.register_pass<ConvertGatherToGatherCompressed>();}{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});auto gather_compressed =std::make_shared<ov::op::internal::GatherCompressed>(weights_const, input1, axis_const, 0, scale_const);@@ -50,25 +54,25 @@ TEST_F(TransformationTestsF, ConvertGatherToCompressed1) {TEST_F(TransformationTestsF, ConvertGatherToCompressed2) {{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});- auto convert = std::make_shared<ov::op::v0::Convert>(weights_const, ov::element::f32);- auto zp_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});- auto sub = std::make_shared<ov::op::v1::Subtract>(convert, zp_const);- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});- auto scale = std::make_shared<ov::op::v1::Multiply>(sub, scale_const);- auto gather = std::make_shared<ov::op::v8::Gather>(scale, input1, axis_const);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});+ auto convert = std::make_shared<v0::Convert>(weights_const, ov::element::f32);+ auto zp_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});+ auto sub = std::make_shared<v1::Subtract>(convert, zp_const);+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});+ auto scale = std::make_shared<v1::Multiply>(sub, scale_const);+ auto gather = std::make_shared<v8::Gather>(scale, input1, axis_const);model = std::make_shared<ov::Model>(ov::OutputVector{gather}, ov::ParameterVector{input1});manager.register_pass<ConvertGatherToGatherCompressed>();}{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});- auto zp_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});+ auto zp_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});auto gather_compressed = std::make_shared<ov::op::internal::GatherCompressed>(weights_const,input1,axis_const,@@ -82,27 +86,27 @@ TEST_F(TransformationTestsF, ConvertGatherToCompressed2) {TEST_F(TransformationTestsF, ConvertGatherToCompressed3) {{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 4, 4}, {1});- auto convert = std::make_shared<ov::op::v0::Convert>(weights_const, ov::element::f32);- auto zp_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 4, 1}, {1});- auto sub = std::make_shared<ov::op::v1::Subtract>(convert, zp_const);- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 4, 1}, {1});- auto scale = std::make_shared<ov::op::v1::Multiply>(sub, scale_const);- auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {-1, 16});- auto reshape = std::make_shared<ov::op::v1::Reshape>(scale, reshape_const, false);- auto gather = std::make_shared<ov::op::v8::Gather>(reshape, input1, axis_const);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 4, 4}, {1});+ auto convert = std::make_shared<v0::Convert>(weights_const, ov::element::f32);+ auto zp_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 4, 1}, {1});+ auto sub = std::make_shared<v1::Subtract>(convert, zp_const);+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 4, 1}, {1});+ auto scale = std::make_shared<v1::Multiply>(sub, scale_const);+ auto reshape_const = v0::Constant::create(ov::element::i32, ov::Shape{2}, {-1, 16});+ auto reshape = std::make_shared<v1::Reshape>(scale, reshape_const, false);+ auto gather = std::make_shared<v8::Gather>(reshape, input1, axis_const);model = std::make_shared<ov::Model>(ov::OutputVector{gather}, ov::ParameterVector{input1});manager.register_pass<ConvertGatherToGatherCompressed>();}{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 4}, {1});- auto zp_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 4}, {1});+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 4}, {1});+ auto zp_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 4}, {1});auto gather_compressed = std::make_shared<ov::op::internal::GatherCompressed>(weights_const,input1,axis_const,@@ -116,27 +120,27 @@ TEST_F(TransformationTestsF, ConvertGatherToCompressed3) {TEST_F(TransformationTestsF, ConvertGatherToCompressed4) {{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u4, ov::Shape{32, 4, 4}, {1});- auto convert = std::make_shared<ov::op::v0::Convert>(weights_const, ov::element::f32);- auto zp_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1, 1, 1}, {1});- auto sub = std::make_shared<ov::op::v1::Subtract>(convert, zp_const);- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 4, 1}, {1});- auto scale = std::make_shared<ov::op::v1::Multiply>(sub, scale_const);- auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {-1, 16});- auto reshape = std::make_shared<ov::op::v1::Reshape>(scale, reshape_const, false);- auto gather = std::make_shared<ov::op::v8::Gather>(reshape, input1, axis_const);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u4, ov::Shape{32, 4, 4}, {1});+ auto convert = std::make_shared<v0::Convert>(weights_const, ov::element::f32);+ auto zp_const = v0::Constant::create(ov::element::f32, ov::Shape{1, 1, 1}, {1});+ auto sub = std::make_shared<v1::Subtract>(convert, zp_const);+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 4, 1}, {1});+ auto scale = std::make_shared<v1::Multiply>(sub, scale_const);+ auto reshape_const = v0::Constant::create(ov::element::i32, ov::Shape{2}, {-1, 16});+ auto reshape = std::make_shared<v1::Reshape>(scale, reshape_const, false);+ auto gather = std::make_shared<v8::Gather>(reshape, input1, axis_const);model = std::make_shared<ov::Model>(ov::OutputVector{gather}, ov::ParameterVector{input1});manager.register_pass<ConvertGatherToGatherCompressed>();}{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u4, ov::Shape{32, 16}, {1});- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 4}, {1});- auto zp_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1, 1}, {1});+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u4, ov::Shape{32, 16}, {1});+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 4}, {1});+ auto zp_const = v0::Constant::create(ov::element::f32, ov::Shape{1, 1}, {1});auto gather_compressed = std::make_shared<ov::op::internal::GatherCompressed>(weights_const,input1,axis_const,@@ -150,27 +154,27 @@ TEST_F(TransformationTestsF, ConvertGatherToCompressed4) {TEST_F(TransformationTestsF, ConvertGatherToCompressedFP16) {{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});- auto convert = std::make_shared<ov::op::v0::Convert>(weights_const, ov::element::f16);- auto zp_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});- auto sub = std::make_shared<ov::op::v1::Subtract>(convert, zp_const);- auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});- auto scale = std::make_shared<ov::op::v1::Multiply>(sub, scale_const);- auto scale_convert = std::make_shared<ov::op::v0::Convert>(scale, ov::element::f32);- auto gather = std::make_shared<ov::op::v8::Gather>(scale_convert, input1, axis_const);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});+ auto convert = std::make_shared<v0::Convert>(weights_const, ov::element::f16);+ auto zp_const = v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});+ auto sub = std::make_shared<v1::Subtract>(convert, zp_const);+ auto scale_const = v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});+ auto scale = std::make_shared<v1::Multiply>(sub, scale_const);+ auto scale_convert = std::make_shared<v0::Convert>(scale, ov::element::f32);+ auto gather = std::make_shared<v8::Gather>(scale_convert, input1, axis_const);model = std::make_shared<ov::Model>(ov::OutputVector{gather}, ov::ParameterVector{input1});manager.register_pass<ConvertGatherToGatherCompressed>();}{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});- auto scale_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});- auto scale_convert = std::make_shared<ov::op::v0::Convert>(scale_const, ov::element::f32);- auto zp_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});+ auto scale_const = v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});+ auto scale_convert = std::make_shared<v0::Convert>(scale_const, ov::element::f32);+ auto zp_const = v0::Constant::create(ov::element::f16, ov::Shape{32, 1}, {1});auto gather_compressed = std::make_shared<ov::op::internal::GatherCompressed>(weights_const,input1,axis_const,@@ -184,38 +188,32 @@ TEST_F(TransformationTestsF, ConvertGatherToCompressedFP16) {TEST_F(TransformationTestsF, ConvertGatherToCompressedMultiOutput) {{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});-- auto input2 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{});- auto topk = std::make_shared<ov::op::v11::TopK>(input1,- input2,- 0,- ov::op::v11::TopK::Mode::MAX,- ov::op::v11::TopK::SortType::SORT_VALUES);-- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});- auto convert = std::make_shared<ov::op::v0::Convert>(weights_const, ov::element::f32);- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});- auto scale = std::make_shared<ov::op::v1::Multiply>(convert, scale_const);- auto gather = std::make_shared<ov::op::v8::Gather>(scale, topk->output(1), axis_const);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});++ auto input2 = std::make_shared<v0::Parameter>(ov::element::i32, ov::Shape{});+ auto topk =+ std::make_shared<v11::TopK>(input1, input2, 0, v11::TopK::Mode::MAX, v11::TopK::SortType::SORT_VALUES);++ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});+ auto convert = std::make_shared<v0::Convert>(weights_const, ov::element::f32);+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});+ auto scale = std::make_shared<v1::Multiply>(convert, scale_const);+ auto gather = std::make_shared<v8::Gather>(scale, topk->output(1), axis_const);model = std::make_shared<ov::Model>(ov::OutputVector{gather}, ov::ParameterVector{input1, input2});manager.register_pass<ConvertGatherToGatherCompressed>();}{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});-- auto input2 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::Shape{});- auto topk = std::make_shared<ov::op::v11::TopK>(input1,- input2,- 0,- ov::op::v11::TopK::Mode::MAX,- ov::op::v11::TopK::SortType::SORT_VALUES);-- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});- auto scale_const = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});++ auto input2 = std::make_shared<v0::Parameter>(ov::element::i32, ov::Shape{});+ auto topk =+ std::make_shared<v11::TopK>(input1, input2, 0, v11::TopK::Mode::MAX, v11::TopK::SortType::SORT_VALUES);++ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});+ auto scale_const = v0::Constant::create(ov::element::f32, ov::Shape{32, 1}, {1});auto gather_compressed = std::make_shared<ov::op::internal::GatherCompressed>(weights_const,topk->output(1),axis_const,@@ -232,21 +230,21 @@ TEST_F(TransformationTestsF, ConvertGatherToCompressedMultiOutput) {// after gather node, so GatherCompressed node should not be generated.TEST_F(TransformationTestsF, MoveDecompressionAfterGatherFP16Weight) {{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{32, 16}, {1});- auto convert = std::make_shared<ov::op::v0::Convert>(weights_const, ov::element::f32);- auto gather = std::make_shared<ov::op::v8::Gather>(convert, input1, axis_const);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::f16, ov::Shape{32, 16}, {1});+ auto convert = std::make_shared<v0::Convert>(weights_const, ov::element::f32);+ auto gather = std::make_shared<v8::Gather>(convert, input1, axis_const);model = std::make_shared<ov::Model>(ov::OutputVector{gather}, ov::ParameterVector{input1});manager.register_pass<MoveDecompressionAfterGather>();}{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{32, 16}, {1});- auto gather = std::make_shared<ov::op::v8::Gather>(weights_const, input1, axis_const);- auto convert = std::make_shared<ov::op::v0::Convert>(gather, ov::element::f32);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::f16, ov::Shape{32, 16}, {1});+ auto gather = std::make_shared<v8::Gather>(weights_const, input1, axis_const);+ auto convert = std::make_shared<v0::Convert>(gather, ov::element::f32);model_ref = std::make_shared<ov::Model>(ov::OutputVector{convert}, ov::ParameterVector{input1});}@@ -254,21 +252,21 @@ TEST_F(TransformationTestsF, MoveDecompressionAfterGatherFP16Weight) {TEST_F(TransformationTestsF, MoveDecompressionAfterGatherBF16Weight) {{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::bf16, ov::Shape{32, 16}, {1});- auto convert = std::make_shared<ov::op::v0::Convert>(weights_const, ov::element::f32);- auto gather = std::make_shared<ov::op::v8::Gather>(convert, input1, axis_const);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::bf16, ov::Shape{32, 16}, {1});+ auto convert = std::make_shared<v0::Convert>(weights_const, ov::element::f32);+ auto gather = std::make_shared<v8::Gather>(convert, input1, axis_const);model = std::make_shared<ov::Model>(ov::OutputVector{gather}, ov::ParameterVector{input1});manager.register_pass<MoveDecompressionAfterGather>();}{- auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});- auto axis_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});- auto weights_const = ov::op::v0::Constant::create(ov::element::bf16, ov::Shape{32, 16}, {1});- auto gather = std::make_shared<ov::op::v8::Gather>(weights_const, input1, axis_const);- auto convert = std::make_shared<ov::op::v0::Convert>(gather, ov::element::f32);+ auto input1 = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1, 16});+ auto axis_const = v0::Constant::create(ov::element::i32, ov::Shape{1}, {1});+ auto weights_const = v0::Constant::create(ov::element::bf16, ov::Shape{32, 16}, {1});+ auto gather = std::make_shared<v8::Gather>(weights_const, input1, axis_const);+ auto convert = std::make_shared<v0::Convert>(gather, ov::element::f32);model_ref = std::make_shared<ov::Model>(ov::OutputVector{convert}, ov::ParameterVector{input1});}diff --git a/src/common/transformations/tests/op_conversions/convert_interpolate11_downgrade_test.cpp b/src/common/transformations/tests/op_conversions/convert_interpolate11_downgrade_test.cppindex 73dbf0c8a4c..45f27325742 100644--- a/src/common/transformations/tests/op_conversions/convert_interpolate11_downgrade_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_interpolate11_downgrade_test.cpp@@ -19,6 +19,7 @@using namespace ov;using namespace testing;+namespace op_util = ov::op::util;namespace {constexpr bool WITH_AXES = true;constexpr bool WITHOUT_AXES = false;@@ -78,28 +79,25 @@ std::shared_ptr<ov::Model> create_v4_model(const bool with_axes,model_params.push_back(ov::as_type_ptr<ov::opset4::Parameter>(scales));output_shape = ov::opset4::Constant::create(ov::element::i32, ov::Shape{}, {1});if (with_axes) {- output_shape = ov::op::util::make_try_fold<ov::opset4::Broadcast>(- output_shape,- ov::op::util::make_try_fold<ov::opset4::ShapeOf>(axes));+ output_shape =+ op_util::make_try_fold<ov::opset4::Broadcast>(output_shape,+ op_util::make_try_fold<ov::opset4::ShapeOf>(axes));} else {- output_shape = ov::op::util::make_try_fold<ov::opset4::Broadcast>(+ output_shape = op_util::make_try_fold<ov::opset4::Broadcast>(output_shape,- ov::op::util::make_try_fold<ov::opset4::ShapeOf>(- ov::op::util::make_try_fold<ov::opset4::ShapeOf>(input)));+ op_util::make_try_fold<ov::opset4::ShapeOf>(op_util::make_try_fold<ov::opset4::ShapeOf>(input)));}} else {output_shape = std::make_shared<ov::opset4::Parameter>(ov::element::i32, ov::Shape{num_scales_or_sizes});model_params.push_back(ov::as_type_ptr<ov::opset4::Parameter>(output_shape));scales = ov::opset4::Constant::create(ov::element::f32, ov::Shape{}, {1.0f});if (with_axes) {- scales = ov::op::util::make_try_fold<ov::opset4::Broadcast>(- scales,- ov::op::util::make_try_fold<ov::opset4::ShapeOf>(axes));+ scales = op_util::make_try_fold<ov::opset4::Broadcast>(scales,+ op_util::make_try_fold<ov::opset4::ShapeOf>(axes));} else {- scales = ov::op::util::make_try_fold<ov::opset4::Broadcast>(+ scales = op_util::make_try_fold<ov::opset4::Broadcast>(scales,- ov::op::util::make_try_fold<ov::opset4::ShapeOf>(- ov::op::util::make_try_fold<ov::opset4::ShapeOf>(input)));+ op_util::make_try_fold<ov::opset4::ShapeOf>(op_util::make_try_fold<ov::opset4::ShapeOf>(input)));}}diff --git a/src/common/transformations/tests/op_conversions/convert_maxpool_downgrade_test.cpp b/src/common/transformations/tests/op_conversions/convert_maxpool_downgrade_test.cppindex c2dd60a5580..778273d80e5 100644--- a/src/common/transformations/tests/op_conversions/convert_maxpool_downgrade_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_maxpool_downgrade_test.cpp@@ -23,11 +23,14 @@#include "openvino/op/subtract.hpp"#include "openvino/pass/manager.hpp"+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v8 = ov::op::v8;namespace {std::shared_ptr<ov::Model> create_v14_model(const ov::op::RoundingType rounding_type,const ov::PartialShape input_shape) {- const auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, input_shape);+ const auto input = std::make_shared<v0::Parameter>(ov::element::f32, input_shape);const ov::Strides strides{2, 2}, dilations{1, 1};const ov::Shape pads_begin{1, 1}, pads_end{1, 1}, kernel{2, 2};@@ -48,20 +51,20 @@ std::shared_ptr<ov::Model> create_v14_model(const ov::op::RoundingType rounding_}std::shared_ptr<ov::Model> create_v8_model(const ov::op::RoundingType rounding_type) {- const auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 64, 64});+ const auto input = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{1, 3, 64, 64});const ov::Strides strides{2, 2}, dilations{1, 1};const ov::Shape pads_begin{1, 1}, pads_end{1, 1}, kernel{2, 2};- const auto max_pool_v8 = std::make_shared<ov::op::v8::MaxPool>(input,- strides,- dilations,- pads_begin,- pads_end,- kernel,- rounding_type,- ov::op::PadType::EXPLICIT,- ov::element::i64,- 2);+ const auto max_pool_v8 = std::make_shared<v8::MaxPool>(input,+ strides,+ dilations,+ pads_begin,+ pads_end,+ kernel,+ rounding_type,+ ov::op::PadType::EXPLICIT,+ ov::element::i64,+ 2);max_pool_v8->set_friendly_name("max_pool_v8");@@ -70,19 +73,19 @@ std::shared_ptr<ov::Model> create_v8_model(const ov::op::RoundingType rounding_tstd::shared_ptr<ov::Model> create_ceil_torch_workaround_model(const ov::op::RoundingType rounding_type,const bool dynamic_input = false) {- using ov::op::v0::Concat;- using ov::op::v0::Constant;- using ov::op::v0::Parameter;- using ov::op::v1::Add;- using ov::op::v1::ConvertLike;- using ov::op::v1::Greater;- using ov::op::v1::Multiply;- using ov::op::v1::Select;- using ov::op::v1::Subtract;using ov::op::v12::Pad;using ov::op::v3::ShapeOf;using ov::op::v4::Range;- using ov::op::v8::Gather;+ using v0::Concat;+ using v0::Constant;+ using v0::Parameter;+ using v1::Add;+ using v1::ConvertLike;+ using v1::Greater;+ using v1::Multiply;+ using v1::Select;+ using v1::Subtract;+ using v8::Gather;const auto& input_shape =dynamic_input? ov::PartialShape{ov::Dimension::dynamic(), 3, ov::Dimension::dynamic(), ov::Dimension::dynamic()}@@ -109,13 +112,13 @@ std::shared_ptr<ov::Model> create_ceil_torch_workaround_model(const ov::op::Rounconst auto in_left_padded = std::make_shared<Add>(gth_in_dims, padding_begin_node);// gather output spatial dims and prepare it for compare as values (out_dim - 1) * stride- const auto mp = std::make_shared<ov::op::v8::MaxPool>(input,- strides,- dilations,- pads_begin,- pads_end,- kernel,- ov::op::RoundingType::CEIL);+ const auto mp = std::make_shared<v8::MaxPool>(input,+ strides,+ dilations,+ pads_begin,+ pads_end,+ kernel,+ ov::op::RoundingType::CEIL);const auto shape_of_mp = std::make_shared<ShapeOf>(mp, ov::element::i32);const auto gth_out_dims = std::make_shared<Gather>(shape_of_mp, dim_idxs, zero);const auto out_sub_one = std::make_shared<Subtract>(gth_out_dims, one);@@ -135,16 +138,16 @@ std::shared_ptr<ov::Model> create_ceil_torch_workaround_model(const ov::op::Rounstd::fill_n(pads_begin.begin(), pads_begin.size(), 0);std::fill_n(pads_end.begin(), pads_end.size(), 0);- const auto max_pool_v8 = std::make_shared<ov::op::v8::MaxPool>(pad_node,- strides,- dilations,- pads_begin,- pads_end,- kernel,- ov::op::RoundingType::CEIL,- ov::op::PadType::EXPLICIT,- ov::element::i64,- 2);+ const auto max_pool_v8 = std::make_shared<v8::MaxPool>(pad_node,+ strides,+ dilations,+ pads_begin,+ pads_end,+ kernel,+ ov::op::RoundingType::CEIL,+ ov::op::PadType::EXPLICIT,+ ov::element::i64,+ 2);max_pool_v8->set_friendly_name("max_pool_v8_ceil_torch_workaround");return std::make_shared<ov::Model>(max_pool_v8->outputs(), ov::ParameterVector{input});@@ -154,21 +157,21 @@ std::shared_ptr<ov::Model> create_ceil_torch_workaround_model(const ov::op::RounTEST_F(TransformationTestsF, ConvertMaxPool8ToMaxPool1) {{- auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 2, 3});+ auto data = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{1, 2, 3});ov::Strides strides{1}, dilations{1};ov::Shape pads_begin{0}, pads_end{0}, kernel{1};- auto maxpool_8 = std::make_shared<ov::op::v8::MaxPool>(data, strides, dilations, pads_begin, pads_end, kernel);- auto result = std::make_shared<ov::op::v0::Result>(maxpool_8->output(0));+ auto maxpool_8 = std::make_shared<v8::MaxPool>(data, strides, dilations, pads_begin, pads_end, kernel);+ auto result = std::make_shared<v0::Result>(maxpool_8->output(0));model = std::make_shared<ov::Model>(ov::OutputVector{result}, ov::ParameterVector{data});manager.register_pass<ov::pass::ConvertMaxPool8ToMaxPool1>();}{- auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 2, 3});+ auto data = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{1, 2, 3});ov::Strides strides{1};ov::Shape pads_begin{0}, pads_end{0}, kernel{1};- auto maxpool_1 = std::make_shared<ov::op::v1::MaxPool>(data, strides, pads_begin, pads_end, kernel);- auto result = std::make_shared<ov::op::v0::Result>(maxpool_1->output(0));+ auto maxpool_1 = std::make_shared<v1::MaxPool>(data, strides, pads_begin, pads_end, kernel);+ auto result = std::make_shared<v0::Result>(maxpool_1->output(0));model_ref = std::make_shared<ov::Model>(ov::OutputVector{result}, ov::ParameterVector{data});}}diff --git a/src/common/transformations/tests/op_conversions/convert_nms9_to_nms_ie_internal_test.cpp b/src/common/transformations/tests/op_conversions/convert_nms9_to_nms_ie_internal_test.cppindex 7293059b5a0..88f37c18a10 100644--- a/src/common/transformations/tests/op_conversions/convert_nms9_to_nms_ie_internal_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_nms9_to_nms_ie_internal_test.cpp@@ -24,13 +24,14 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;TEST_F(TransformationTestsF, ConvertPreviousNMSToNMSIEInternal) {{- auto boxes = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 1000, 4});- auto scores = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 1, 1000});- auto max_output_boxes_per_class = ov::op::v0::Constant::create(element::i64, Shape{}, {10});- auto iou_threshold = ov::op::v0::Constant::create(element::f32, Shape{}, {0.75});- auto score_threshold = ov::op::v0::Constant::create(element::f32, Shape{}, {0.7});+ auto boxes = std::make_shared<v0::Parameter>(element::f32, Shape{1, 1000, 4});+ auto scores = std::make_shared<v0::Parameter>(element::f32, Shape{1, 1, 1000});+ auto max_output_boxes_per_class = v0::Constant::create(element::i64, Shape{}, {10});+ auto iou_threshold = v0::Constant::create(element::f32, Shape{}, {0.75});+ auto score_threshold = v0::Constant::create(element::f32, Shape{}, {0.7});auto nms = std::make_shared<ov::op::v1::NonMaxSuppression>(boxes,scores,max_output_boxes_per_class,@@ -52,11 +53,11 @@ TEST_F(TransformationTestsF, ConvertPreviousNMSToNMSIEInternal) {}{- auto boxes = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 1000, 4});- auto scores = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 1, 1000});- auto max_output_boxes_per_class = ov::op::v0::Constant::create(element::i64, Shape{1}, {10});- auto iou_threshold = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.75});- auto score_threshold = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.7});+ auto boxes = std::make_shared<v0::Parameter>(element::f32, Shape{1, 1000, 4});+ auto scores = std::make_shared<v0::Parameter>(element::f32, Shape{1, 1, 1000});+ auto max_output_boxes_per_class = v0::Constant::create(element::i64, Shape{1}, {10});+ auto iou_threshold = v0::Constant::create(element::f32, Shape{1}, {0.75});+ auto score_threshold = v0::Constant::create(element::f32, Shape{1}, {0.7});auto nms = std::make_shared<ov::op::internal::NonMaxSuppressionIEInternal>(boxes,scores,max_output_boxes_per_class,@@ -65,7 +66,7 @@ TEST_F(TransformationTestsF, ConvertPreviousNMSToNMSIEInternal) {0,true,element::i32);- auto convert = std::make_shared<ov::op::v0::Convert>(nms->output(0), element::i64);+ auto convert = std::make_shared<v0::Convert>(nms->output(0), element::i64);convert->set_friendly_name("nms:0");model_ref = std::make_shared<Model>(OutputVector{convert}, ParameterVector{boxes, scores});@@ -74,12 +75,12 @@ TEST_F(TransformationTestsF, ConvertPreviousNMSToNMSIEInternal) {TEST_F(TransformationTestsF, ConvertNMS9ToNMSIEInternal) {{- auto boxes = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 1000, 4});- auto scores = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 1, 1000});- auto max_output_boxes_per_class = ov::op::v0::Constant::create(element::i32, Shape{}, {10});- auto iou_threshold = ov::op::v0::Constant::create(element::f32, Shape{}, {0.75});- auto score_threshold = ov::op::v0::Constant::create(element::f32, Shape{}, {0.7});- auto soft_nms_sigma = ov::op::v0::Constant::create(element::f32, Shape{}, {0.5});+ auto boxes = std::make_shared<v0::Parameter>(element::f32, Shape{1, 1000, 4});+ auto scores = std::make_shared<v0::Parameter>(element::f32, Shape{1, 1, 1000});+ auto max_output_boxes_per_class = v0::Constant::create(element::i32, Shape{}, {10});+ auto iou_threshold = v0::Constant::create(element::f32, Shape{}, {0.75});+ auto score_threshold = v0::Constant::create(element::f32, Shape{}, {0.7});+ auto soft_nms_sigma = v0::Constant::create(element::f32, Shape{}, {0.5});auto nms = std::make_shared<opset9::NonMaxSuppression>(boxes,scores,max_output_boxes_per_class,@@ -97,12 +98,12 @@ TEST_F(TransformationTestsF, ConvertNMS9ToNMSIEInternal) {}{- auto boxes = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 1000, 4});- auto scores = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 1, 1000});- auto max_output_boxes_per_class = ov::op::v0::Constant::create(element::i32, Shape{1}, {10});- auto iou_threshold = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.75});- auto score_threshold = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.7});- auto soft_nms_sigma = ov::op::v0::Constant::create(element::f32, Shape{1}, {0.5});+ auto boxes = std::make_shared<v0::Parameter>(element::f32, Shape{1, 1000, 4});+ auto scores = std::make_shared<v0::Parameter>(element::f32, Shape{1, 1, 1000});+ auto max_output_boxes_per_class = v0::Constant::create(element::i32, Shape{1}, {10});+ auto iou_threshold = v0::Constant::create(element::f32, Shape{1}, {0.75});+ auto score_threshold = v0::Constant::create(element::f32, Shape{1}, {0.7});+ auto soft_nms_sigma = v0::Constant::create(element::f32, Shape{1}, {0.5});auto nms = std::make_shared<ov::op::internal::NonMaxSuppressionIEInternal>(boxes,scores,max_output_boxes_per_class,diff --git a/src/common/transformations/tests/op_conversions/convert_onehot16_downgrade_test.cpp b/src/common/transformations/tests/op_conversions/convert_onehot16_downgrade_test.cppindex 7dc32f9800f..60724114553 100644--- a/src/common/transformations/tests/op_conversions/convert_onehot16_downgrade_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_onehot16_downgrade_test.cpp@@ -14,6 +14,7 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;namespace {template <typename TOpFunc>std::shared_ptr<ov::Model> create_model(const TOpFunc& op_func) {@@ -21,10 +22,10 @@ std::shared_ptr<ov::Model> create_model(const TOpFunc& op_func) {const float on_value = 1.123f;const float off_value = 0.321f;- const auto indices_const = ov::op::v0::Constant::create(element::i64, Shape{3}, indices);- const auto depth_const = ov::op::v0::Constant::create(element::i64, Shape{}, {3});- const auto on_const = ov::op::v0::Constant::create(element::f32, Shape{}, {on_value});- const auto off_const = ov::op::v0::Constant::create(element::f32, Shape{}, {off_value});+ const auto indices_const = v0::Constant::create(element::i64, Shape{3}, indices);+ const auto depth_const = v0::Constant::create(element::i64, Shape{}, {3});+ const auto on_const = v0::Constant::create(element::f32, Shape{}, {on_value});+ const auto off_const = v0::Constant::create(element::f32, Shape{}, {off_value});auto one_hot = op_func(indices_const, depth_const, on_const, off_const, -1);diff --git a/src/common/transformations/tests/op_conversions/convert_pad12_downgrade_test.cpp b/src/common/transformations/tests/op_conversions/convert_pad12_downgrade_test.cppindex 62654446b3e..b94d73753ec 100644--- a/src/common/transformations/tests/op_conversions/convert_pad12_downgrade_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_pad12_downgrade_test.cpp@@ -17,18 +17,19 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;namespace {std::shared_ptr<ov::Model> create_v12_model(const ov::op::PadMode pad_mode, const int16_t pad_v = -1) {const auto input = std::make_shared<ov::opset12::Parameter>(ov::element::i16, ov::Shape{1, 3, 100, 100});const auto pads_begin =- std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int64_t>{0, 2, 1, 0});+ std::make_shared<v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int64_t>{0, 2, 1, 0});const auto pads_end =- std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int64_t>{0, 1, 1, 0});+ std::make_shared<v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int64_t>{0, 1, 1, 0});std::shared_ptr<ov::opset12::Pad> pad;if (pad_v != -1) {const auto pad_value =- std::make_shared<ov::op::v0::Constant>(ov::element::i16, ov::Shape{}, std::vector<int16_t>{pad_v});+ std::make_shared<v0::Constant>(ov::element::i16, ov::Shape{}, std::vector<int16_t>{pad_v});pad = std::make_shared<ov::opset12::Pad>(input, pads_begin, pads_end, pad_value, pad_mode);} else {pad = std::make_shared<ov::opset12::Pad>(input, pads_begin, pads_end, pad_mode);@@ -41,11 +42,10 @@ std::shared_ptr<ov::Model> create_v12_model(const ov::op::PadMode pad_mode, consstd::shared_ptr<ov::Model> create_v1_model(const ov::op::PadMode pad_mode, const int16_t pad_v) {const auto input = std::make_shared<ov::opset1::Parameter>(ov::element::i16, ov::Shape{1, 3, 100, 100});const auto pads_begin =- std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int64_t>{0, 2, 1, 0});+ std::make_shared<v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int64_t>{0, 2, 1, 0});const auto pads_end =- std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int64_t>{0, 1, 1, 0});- const auto pad_value =- std::make_shared<ov::op::v0::Constant>(ov::element::i16, ov::Shape{}, std::vector<int16_t>{pad_v});+ std::make_shared<v0::Constant>(ov::element::i64, ov::Shape{4}, std::vector<int64_t>{0, 1, 1, 0});+ const auto pad_value = std::make_shared<v0::Constant>(ov::element::i16, ov::Shape{}, std::vector<int16_t>{pad_v});const auto pad = std::make_shared<ov::opset1::Pad>(input, pads_begin, pads_end, pad_value, pad_mode);pad->set_friendly_name("pad1");diff --git a/src/common/transformations/tests/op_conversions/convert_sequences_to_ti_test.cpp b/src/common/transformations/tests/op_conversions/convert_sequences_to_ti_test.cppindex a04ffb4b57f..2311706af6a 100644--- a/src/common/transformations/tests/op_conversions/convert_sequences_to_ti_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_sequences_to_ti_test.cpp@@ -32,6 +32,8 @@using namespace testing;using namespace ov;+namespace v0 = ov::op::v0;+namespace v5 = ov::op::v5;TEST(TransformationTests, ConvertLSTMSequenceToTensorIterator) {std::shared_ptr<ov::Model> f(nullptr), f_ref(nullptr);{@@ -813,26 +815,24 @@ TEST(TransformationTests, ConvertQuantizedGRUSequenceToTensorIterator) {}TEST(TransformationTests, convert_lstm_seq_to_ti_with_enabled_mask) {- auto param_x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1});- auto param_init_cell_state =- std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, 1, 256});- auto param_hidden_cell_state =- std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{-1, 1, 256});- auto param_seq_len = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, ov::PartialShape{-1});- auto param_w = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 1024, 40});- auto param_r = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 1024, 256});- auto param_b = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{1, 1024});+ auto param_x = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{-1, -1, -1});+ auto param_init_cell_state = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{-1, 1, 256});+ auto param_hidden_cell_state = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{-1, 1, 256});+ auto param_seq_len = std::make_shared<v0::Parameter>(ov::element::i32, ov::PartialShape{-1});+ auto param_w = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{1, 1024, 40});+ auto param_r = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{1, 1024, 256});+ auto param_b = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{1, 1024});std::int64_t hidden_size = 256;- ov::op::v5::LSTMSequence::direction lstm_direction = ov::op::v5::LSTMSequence::direction::FORWARD;- auto lstm_cell = std::make_shared<ov::op::v5::LSTMSequence>(param_x,- param_init_cell_state,- param_hidden_cell_state,- param_seq_len,- param_w,- param_r,- param_b,- hidden_size,- lstm_direction);+ v5::LSTMSequence::direction lstm_direction = v5::LSTMSequence::direction::FORWARD;+ auto lstm_cell = std::make_shared<v5::LSTMSequence>(param_x,+ param_init_cell_state,+ param_hidden_cell_state,+ param_seq_len,+ param_w,+ param_r,+ param_b,+ hidden_size,+ lstm_direction);auto model = std::make_shared<ov::Model>(lstm_cell->outputs(),ov::ParameterVector{param_x,param_init_cell_state,diff --git a/src/common/transformations/tests/op_conversions/convert_slicescatter_decomposition_test.cpp b/src/common/transformations/tests/op_conversions/convert_slicescatter_decomposition_test.cppindex 904956a7792..d703ddb68b9 100644--- a/src/common/transformations/tests/op_conversions/convert_slicescatter_decomposition_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_slicescatter_decomposition_test.cpp@@ -20,6 +20,8 @@#include "openvino/pass/manager.hpp"#include "transformations/op_conversions/convert_slicescatter.hpp"#include "transformations/utils/utils.hpp"++namespace v0 = ov::op::v0;namespace {class ConvertSliceScatterTest : public TransformationTestsF, public testing::WithParamInterface<ov::NodeVector> {private:@@ -43,7 +45,7 @@ protected:const auto& step = inputs.at(4);ov::ParameterVector params{};for (const auto& inp : inputs) {- const auto& param = ov::as_type_ptr<ov::op::v0::Parameter>(inp);+ const auto& param = ov::as_type_ptr<v0::Parameter>(inp);if (param) {params.push_back(param);}@@ -66,15 +68,15 @@ protected:const auto& step = inputs.at(4);ov::ParameterVector params{};for (const auto& inp : inputs) {- const auto& param = ov::as_type_ptr<ov::op::v0::Parameter>(inp);+ const auto& param = ov::as_type_ptr<v0::Parameter>(inp);if (param) {params.push_back(param);}}- const auto& const_0 = ov::op::v0::Constant::create(ov::element::i64, {}, {0});- const auto& const_1 = ov::op::v0::Constant::create(ov::element::i64, {}, {1});- const auto& const_1d_neg_1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});- const auto& const_scatter_indices_shape = ov::op::v0::Constant::create(ov::element::i64, {2}, {-1, 1});+ const auto& const_0 = v0::Constant::create(ov::element::i64, {}, {0});+ const auto& const_1 = v0::Constant::create(ov::element::i64, {}, {1});+ const auto& const_1d_neg_1 = v0::Constant::create(ov::element::i64, {1}, {-1});+ const auto& const_scatter_indices_shape = v0::Constant::create(ov::element::i64, {2}, {-1, 1});const auto& data_shape = std::make_shared<ov::opset8::ShapeOf>(data, ov::element::i64);const auto& num_elements_data = std::make_shared<ov::opset8::ReduceProd>(data_shape, const_0, false);const auto& data_indices_flatten =@@ -105,32 +107,32 @@ INSTANTIATE_TEST_SUITE_P(ov::NodeVector{std::make_shared<ov::opset15::Parameter>(ov::element::f32, ov::Shape{256, 10, 15}),std::make_shared<ov::opset15::Parameter>(ov::element::f32, ov::Shape{4, 7, 2}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {2, -15, 25}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {9, 7, -3}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {2, 1, -1}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {0, 1, -1}),+ v0::Constant::create(ov::element::i32, {3}, {2, -15, 25}),+ v0::Constant::create(ov::element::i32, {3}, {9, 7, -3}),+ v0::Constant::create(ov::element::i32, {3}, {2, 1, -1}),+ v0::Constant::create(ov::element::i32, {3}, {0, 1, -1}),},ov::NodeVector{std::make_shared<ov::opset15::Parameter>(ov::element::f32, ov::Shape{256, 10, 15}),std::make_shared<ov::opset15::Parameter>(ov::element::f32, ov::Shape{4, 7, 2}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {2, -15, 25}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {9, 7, -3}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {2, 1, -1}),+ v0::Constant::create(ov::element::i32, {3}, {2, -15, 25}),+ v0::Constant::create(ov::element::i32, {3}, {9, 7, -3}),+ v0::Constant::create(ov::element::i32, {3}, {2, 1, -1}),},ov::NodeVector{std::make_shared<ov::opset15::Parameter>(ov::element::i32, ov::PartialShape::dynamic()),std::make_shared<ov::opset15::Parameter>(ov::element::i32, ov::PartialShape::dynamic()),- ov::op::v0::Constant::create(ov::element::i32, {3}, {2, -15, 25}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {9, 7, -3}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {2, 1, -1}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {0, 1, -1}),+ v0::Constant::create(ov::element::i32, {3}, {2, -15, 25}),+ v0::Constant::create(ov::element::i32, {3}, {9, 7, -3}),+ v0::Constant::create(ov::element::i32, {3}, {2, 1, -1}),+ v0::Constant::create(ov::element::i32, {3}, {0, 1, -1}),},ov::NodeVector{std::make_shared<ov::opset15::Parameter>(ov::element::i32, ov::PartialShape::dynamic()),std::make_shared<ov::opset15::Parameter>(ov::element::i32, ov::PartialShape::dynamic()),- ov::op::v0::Constant::create(ov::element::i32, {3}, {2, -15, 25}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {9, 7, -3}),- ov::op::v0::Constant::create(ov::element::i32, {3}, {2, 1, -1}),+ v0::Constant::create(ov::element::i32, {3}, {2, -15, 25}),+ v0::Constant::create(ov::element::i32, {3}, {9, 7, -3}),+ v0::Constant::create(ov::element::i32, {3}, {2, 1, -1}),},ov::NodeVector{std::make_shared<ov::opset15::Parameter>(ov::element::i32, ov::PartialShape::dynamic()),diff --git a/src/common/transformations/tests/op_conversions/convert_ti_to_sequences_test.cpp b/src/common/transformations/tests/op_conversions/convert_ti_to_sequences_test.cppindex 1af81d8e341..6b01cd70167 100644--- a/src/common/transformations/tests/op_conversions/convert_ti_to_sequences_test.cpp+++ b/src/common/transformations/tests/op_conversions/convert_ti_to_sequences_test.cpp@@ -45,6 +45,7 @@using namespace testing;using namespace ov;+namespace v5 = ov::op::v5;namespace {std::shared_ptr<ov::Node> create_seq_len(const std::shared_ptr<ov::Node>& X) {@@ -1405,7 +1406,7 @@ TEST_P(LoopWithLSTMCellToLSTMSequenceFusionTest, FusionTest) {auto loop_node = std::make_shared<op::v5::Loop>(max_iter, execution_cond);loop_node->set_function(body_graph);- loop_node->set_special_body_ports(ov::op::v5::Loop::SpecialBodyPorts{-1, 3});+ loop_node->set_special_body_ports(v5::Loop::SpecialBodyPorts{-1, 3});// set inputs for Loop// x input will be sliced for each time step@@ -1466,20 +1467,20 @@ TEST_P(LoopWithLSTMCellToLSTMSequenceFusionTest, FusionTest) {auto b = std::make_shared<op::v0::Unsqueeze>(b_const, unsqueeze_axis2);// create LSTMSequence- auto lstm_sequence = std::make_shared<ov::op::v5::LSTMSequence>(- tr_x,- h_init_unsqueeze,- c_init_unsqueeze,- seq_lens,- w,- r,- b,- hidden_size,- ov::op::RecurrentSequenceDirection::FORWARD,- std::vector<float>{},- std::vector<float>{},- std::vector<std::string>{f_activation, g_activation, h_activation},- 0.0f);+ auto lstm_sequence =+ std::make_shared<v5::LSTMSequence>(tr_x,+ h_init_unsqueeze,+ c_init_unsqueeze,+ seq_lens,+ w,+ r,+ b,+ hidden_size,+ ov::op::RecurrentSequenceDirection::FORWARD,+ std::vector<float>{},+ std::vector<float>{},+ std::vector<std::string>{f_activation, g_activation, h_activation},+ 0.0f);// prepare outputauto squeeze_axis = std::make_shared<op::v0::Constant>(ov::element::i32, ov::Shape{1}, 1);diff --git a/src/common/transformations/tests/op_conversions/einsum_decomposition_test.cpp b/src/common/transformations/tests/op_conversions/einsum_decomposition_test.cppindex 41d1b2bcc40..6ca0ccad22f 100644--- a/src/common/transformations/tests/op_conversions/einsum_decomposition_test.cpp+++ b/src/common/transformations/tests/op_conversions/einsum_decomposition_test.cpp@@ -30,6 +30,11 @@#include "transformations/utils/gen_pattern.hpp"using namespace ov;++namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v7 = ov::op::v7;namespace {using namespace ov::gen_pattern;std::shared_ptr<ov::Node> extract_subshape_from_shape(const std::shared_ptr<ov::Node>& shape_node,@@ -85,13 +90,13 @@ std::shared_ptr<ov::Node> extract_diagonal(const std::shared_ptr<ov::Node>& data// Transpose the input tensor to group repeated and unrepeated labelsauto const_transpose_group_labels_target =makeConst(element::i64, ov::Shape({transpose_group_labels_target.size()}), transpose_group_labels_target);- auto transpose_group_labels = std::make_shared<ov::op::v1::Transpose>(data, const_transpose_group_labels_target);+ auto transpose_group_labels = std::make_shared<v1::Transpose>(data, const_transpose_group_labels_target);// Get the shape of the transposed tensor- auto shapeof_transposed_data = std::make_shared<ov::op::v3::ShapeOf>(transpose_group_labels);+ auto shapeof_transposed_data = std::make_shared<v3::ShapeOf>(transpose_group_labels);- auto const_0 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape({1}), {0});- auto const_1 = ov::op::v0::Constant::create(ov::element::i64, ov::Shape({1}), {1});+ auto const_0 = v0::Constant::create(ov::element::i64, ov::Shape({1}), {0});+ auto const_1 = v0::Constant::create(ov::element::i64, ov::Shape({1}), {1});ov::NodeVector flattened_shapes;ov::NodeVector unflattened_shapes;@@ -108,21 +113,20 @@ std::shared_ptr<ov::Node> extract_diagonal(const std::shared_ptr<ov::Node>& dataauto num_repeats = repeated_label.size();std::vector<size_t> label_indices = {dim_iota.begin() + dimension_iter,dim_iota.begin() + dimension_iter + num_repeats};- auto repeated_label_indices_len = ov::op::v0::Constant::create(ov::element::i64, {}, {num_repeats});- auto repeated_label_indices =- ov::op::v0::Constant::create(ov::element::i64, ov::Shape({num_repeats}), label_indices);+ auto repeated_label_indices_len = v0::Constant::create(ov::element::i64, {}, {num_repeats});+ auto repeated_label_indices = v0::Constant::create(ov::element::i64, ov::Shape({num_repeats}), label_indices);auto repeated_dimensions =- std::make_shared<ov::op::v7::Gather>(shapeof_transposed_data, repeated_label_indices, const_0);- auto repeated_dimension = std::make_shared<ov::op::v7::Gather>(repeated_dimensions, const_0, const_0);- auto range_max_val = std::make_shared<ov::op::v1::Power>(repeated_dimension, repeated_label_indices_len);- auto step_numerator = std::make_shared<ov::op::v1::Subtract>(range_max_val, const_1);- auto step_denominator = std::make_shared<ov::op::v1::Subtract>(repeated_dimension, const_1);- auto step_denominator_but_not_0 = std::make_shared<ov::op::v1::Maximum>(step_denominator, const_1);- auto step_numerator_but_not_0 = std::make_shared<ov::op::v1::Maximum>(step_numerator, const_1);- auto step = std::make_shared<ov::op::v1::Divide>(step_numerator_but_not_0, step_denominator_but_not_0);- auto end = std::make_shared<ov::op::v1::Subtract>(step, const_1);+ std::make_shared<v7::Gather>(shapeof_transposed_data, repeated_label_indices, const_0);+ auto repeated_dimension = std::make_shared<v7::Gather>(repeated_dimensions, const_0, const_0);+ auto range_max_val = std::make_shared<v1::Power>(repeated_dimension, repeated_label_indices_len);+ auto step_numerator = std::make_shared<v1::Subtract>(range_max_val, const_1);+ auto step_denominator = std::make_shared<v1::Subtract>(repeated_dimension, const_1);+ auto step_denominator_but_not_0 = std::make_shared<v1::Maximum>(step_denominator, const_1);+ auto step_numerator_but_not_0 = std::make_shared<v1::Maximum>(step_numerator, const_1);+ auto step = std::make_shared<v1::Divide>(step_numerator_but_not_0, step_denominator_but_not_0);+ auto end = std::make_shared<v1::Subtract>(step, const_1);// Flatten all dimensions of single repeated label.- auto reduced_size = std::make_shared<ov::op::v1::ReduceProd>(repeated_dimensions, const_0, true);+ auto reduced_size = std::make_shared<v1::ReduceProd>(repeated_dimensions, const_0, true);flattened_shapes.push_back(reduced_size);// Reshape the tensor to restore the original shape with diagonal elements isolated and remainder.unflattened_shapes.push_back(repeated_dimension);@@ -134,42 +138,39 @@ std::shared_ptr<ov::Node> extract_diagonal(const std::shared_ptr<ov::Node>& data// Process unrepeated labels, do not perform flatten or pads on dimensions.std::vector<size_t> unrepeated_indices_after_transpose = {dim_iota.begin() + dimension_iter, dim_iota.end()};- const auto& unrepeated_dimensions_indices =- ov::op::v0::Constant::create(ov::element::i64,- {unrepeated_indices_after_transpose.size()},- unrepeated_indices_after_transpose);+ const auto& unrepeated_dimensions_indices = v0::Constant::create(ov::element::i64,+ {unrepeated_indices_after_transpose.size()},+ unrepeated_indices_after_transpose);const auto unrepeated_dimensions =- std::make_shared<ov::op::v7::Gather>(shapeof_transposed_data, unrepeated_dimensions_indices, const_0);+ std::make_shared<v7::Gather>(shapeof_transposed_data, unrepeated_dimensions_indices, const_0);begins.insert(begins.end(), unrepeated_indices_after_transpose.size(), const_0);ends.insert(ends.end(), unrepeated_indices_after_transpose.size(), const_0);flattened_shapes.push_back(unrepeated_dimensions);unflattened_shapes.push_back(unrepeated_dimensions);// Flatten the tensor to isolate diagonal elements- auto flatten_labels_shape_target = std::make_shared<ov::op::v0::Concat>(flattened_shapes, 0);- auto flatten_labels =- std::make_shared<ov::op::v1::Reshape>(transpose_group_labels, flatten_labels_shape_target, false);+ auto flatten_labels_shape_target = std::make_shared<v0::Concat>(flattened_shapes, 0);+ auto flatten_labels = std::make_shared<v1::Reshape>(transpose_group_labels, flatten_labels_shape_target, false);// Pad the tensor to prepare for gathering diagonal elements- auto pad_begin = std::make_shared<ov::op::v0::Concat>(begins, 0);- auto pad_end = std::make_shared<ov::op::v0::Concat>(ends, 0);- auto pad = std::make_shared<ov::op::v1::Pad>(flatten_labels, pad_begin, pad_end, ov::op::PadMode::CONSTANT);+ auto pad_begin = std::make_shared<v0::Concat>(begins, 0);+ auto pad_end = std::make_shared<v0::Concat>(ends, 0);+ auto pad = std::make_shared<v1::Pad>(flatten_labels, pad_begin, pad_end, ov::op::PadMode::CONSTANT);// Unflatten the tensor to restore the original shape with diagonal elements isolated- auto unflatten_labels_shape_target = std::make_shared<ov::op::v0::Concat>(unflattened_shapes, 0);- auto unflatten_labels = std::make_shared<ov::op::v1::Reshape>(pad, unflatten_labels_shape_target, false);+ auto unflatten_labels_shape_target = std::make_shared<v0::Concat>(unflattened_shapes, 0);+ auto unflatten_labels = std::make_shared<v1::Reshape>(pad, unflatten_labels_shape_target, false);// Gather the diagonal elementsstd::shared_ptr<ov::Node> gather = unflatten_labels;for (auto axis : reduced_axes) {- auto axis_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape({1}), {axis});- gather = std::make_shared<ov::op::v7::Gather>(gather, const_0, axis_const);+ auto axis_const = v0::Constant::create(ov::element::i64, ov::Shape({1}), {axis});+ gather = std::make_shared<v7::Gather>(gather, const_0, axis_const);}// Squeeze the tensor to remove the reduced dimensions- auto squeeze_reduced_axes =- ov::op::v0::Constant::create(ov::element::i64, ov::Shape({reduced_axes.size()}), reduced_axes);- auto diagonal = std::make_shared<ov::op::v0::Squeeze>(gather, squeeze_reduced_axes);+ auto squeeze_reduced_axes = v0::Constant::create(ov::element::i64, ov::Shape({reduced_axes.size()}), reduced_axes);+ auto diagonal = std::make_shared<v0::Squeeze>(gather, squeeze_reduced_axes);return diagonal;}@@ -181,47 +182,44 @@ TEST_F(TransformationTestsF, Einsum_2in_matmul) {PartialShape data_shape_2{10, 1, 25};comparator.enable(FunctionsComparator::CmpValues::ACCURACY);{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);auto einsum = std::make_shared<opset7::Einsum>(OutputVector{data_1, data_2}, "kl,mlj->mkj");model = std::make_shared<Model>(OutputVector{einsum}, ParameterVector{data_1, data_2});manager.register_pass<ov::pass::EinsumDecomposition>();}{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);// Transpose data_2 so that common labels, separated and reduced labels are grouped for both operands.- auto order_2 = ov::op::v0::Constant::create(element::i64, {3}, {0, 2, 1});- auto transpose_2 = std::make_shared<ov::op::v1::Transpose>(data_2, order_2);+ auto order_2 = v0::Constant::create(element::i64, {3}, {0, 2, 1});+ auto transpose_2 = std::make_shared<v1::Transpose>(data_2, order_2);// Broadcast data_1 and data_2 to common broadcasted shapes for common and reduced subshapes.// Subgraphes are constant-folded, target subshapes are calculated broadcast_merge_shapes function.- auto broadcast_shape_constant_1 =- ov::op::v0::Constant::create(element::i64, Shape{data_shape_1.size()}, {5, 2});- auto broadcast_shape_constant_2 =- ov::op::v0::Constant::create(element::i64, Shape{data_shape_2.size()}, {10, 25, 2});- auto broadcast_1 = std::make_shared<ov::op::v3::Broadcast>(data_1,- broadcast_shape_constant_1,- ov::op::BroadcastType::BIDIRECTIONAL);- auto broadcast_2 = std::make_shared<ov::op::v3::Broadcast>(transpose_2,- broadcast_shape_constant_2,- ov::op::BroadcastType::BIDIRECTIONAL);+ auto broadcast_shape_constant_1 = v0::Constant::create(element::i64, Shape{data_shape_1.size()}, {5, 2});+ auto broadcast_shape_constant_2 = v0::Constant::create(element::i64, Shape{data_shape_2.size()}, {10, 25, 2});+ auto broadcast_1 =+ std::make_shared<v3::Broadcast>(data_1, broadcast_shape_constant_1, ov::op::BroadcastType::BIDIRECTIONAL);+ auto broadcast_2 = std::make_shared<v3::Broadcast>(transpose_2,+ broadcast_shape_constant_2,+ ov::op::BroadcastType::BIDIRECTIONAL);// Optionally reshape broadcasted data_1 and data_2 so separate and reduced labels are represented by one// dimension. Subgraphes are constant-folded, target subshapes are calculated broadcast_merge_shapes function.- auto shape_constant_1 = ov::op::v0::Constant::create(element::i64, Shape{2}, {5, 2});- auto shape_constant_2 = ov::op::v0::Constant::create(element::i64, Shape{2}, {250, 2});- auto reshape_1 = std::make_shared<ov::op::v1::Reshape>(broadcast_1, shape_constant_1, false);- auto reshape_2 = std::make_shared<ov::op::v1::Reshape>(broadcast_2, shape_constant_2, false);+ auto shape_constant_1 = v0::Constant::create(element::i64, Shape{2}, {5, 2});+ auto shape_constant_2 = v0::Constant::create(element::i64, Shape{2}, {250, 2});+ auto reshape_1 = std::make_shared<v1::Reshape>(broadcast_1, shape_constant_1, false);+ auto reshape_2 = std::make_shared<v1::Reshape>(broadcast_2, shape_constant_2, false);// Apply MatMul operation for formatted inputs.- auto matmul = std::make_shared<ov::op::v0::MatMul>(reshape_1, reshape_2, false, true);+ auto matmul = std::make_shared<v0::MatMul>(reshape_1, reshape_2, false, true);// Optionally reshape back by unrolling dimensions corresponding to separate labels if needed.// Subgraphes are constant-folded, target subshapes are calculated broadcast_merge_shapes function.- auto shape_out = ov::op::v0::Constant::create(element::i64, {3}, {5, 10, 25});- auto reshape_out = std::make_shared<ov::op::v1::Reshape>(matmul, shape_out, false);+ auto shape_out = v0::Constant::create(element::i64, {3}, {5, 10, 25});+ auto reshape_out = std::make_shared<v1::Reshape>(matmul, shape_out, false);// Transpose to the original order of output labels.- auto order_out = ov::op::v0::Constant::create(element::i64, {3}, {1, 0, 2});- auto transpose_out = std::make_shared<ov::op::v1::Transpose>(reshape_out, order_out);+ auto order_out = v0::Constant::create(element::i64, {3}, {1, 0, 2});+ auto transpose_out = std::make_shared<v1::Transpose>(reshape_out, order_out);model_ref = std::make_shared<Model>(OutputVector{transpose_out}, ParameterVector{data_1, data_2});}@@ -232,16 +230,16 @@ TEST_F(TransformationTestsF, Einsum_2in_matmul_dynamic) {PartialShape data_shape_2 = PartialShape::dynamic(3);comparator.enable(FunctionsComparator::CmpValues::ACCURACY);{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);auto einsum = std::make_shared<opset7::Einsum>(OutputVector{data_1, data_2}, "kl,mlj->mkj");model = std::make_shared<Model>(OutputVector{einsum}, ParameterVector{data_1, data_2});manager.register_pass<ov::pass::EinsumDecomposition>();}{using namespace ov::gen_pattern;- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);// Transpose data_2 so that common labels, separated and reduced labels are grouped for both operands.auto Constant_485 = makeConst(element::i64, ov::Shape({3}), {0, 2, 1});auto Transpose_486 = makeOP<opset1::Transpose>({data_2, Constant_485});@@ -296,15 +294,15 @@ TEST_F(TransformationTestsF, Einsum_2in_matmul_dynamic) {auto Reshape_2 = makeOP<opset1::Reshape>({Broadcast_data_2, reshape_subshape2}, {{"special_zero", false}});// Apply MatMul operation for formatted inputs.- auto matmul = std::make_shared<ov::op::v0::MatMul>(Reshape_1, Reshape_2, false, true);+ auto matmul = std::make_shared<v0::MatMul>(Reshape_1, Reshape_2, false, true);// Optionally reshape back by unrolling dimensions corresponding to separate labels if needed.// Target subshapes are calculated broadcast_merge_shapes function and concatenated.auto shape_out = makeOP<opset1::Concat>({separate1_subshape, separate2_subshape}, {{"axis", 0}});- auto reshape_out = std::make_shared<ov::op::v1::Reshape>(matmul, shape_out, false);+ auto reshape_out = std::make_shared<v1::Reshape>(matmul, shape_out, false);// Transpose to the original order of output labels.- auto order_out = ov::op::v0::Constant::create(element::i64, {3}, {1, 0, 2});- auto transpose_out = std::make_shared<ov::op::v1::Transpose>(reshape_out, order_out);+ auto order_out = v0::Constant::create(element::i64, {3}, {1, 0, 2});+ auto transpose_out = std::make_shared<v1::Transpose>(reshape_out, order_out);model_ref = std::make_shared<Model>(OutputVector{transpose_out}, ParameterVector{data_1, data_2});}@@ -315,16 +313,16 @@ TEST_F(TransformationTestsF, Einsum_2in_matmul_ellipsis_dynamic) {PartialShape data_shape_2 = PartialShape::dynamic(5);comparator.enable(FunctionsComparator::CmpValues::ACCURACY);{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);auto einsum = std::make_shared<opset7::Einsum>(OutputVector{data_1, data_2}, "kl...,m...lj->mkj");model = std::make_shared<Model>(OutputVector{einsum}, ParameterVector{data_1, data_2});manager.register_pass<ov::pass::EinsumDecomposition>();}{using namespace ov::gen_pattern;- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);// Process data_1// data_1 contains no dimensions at ellipsis label, unsqueeze to allow for broadcastingauto Constant_1200 = makeConst(element::i64, ov::Shape({1}), {2});@@ -400,7 +398,7 @@ TEST_F(TransformationTestsF, Einsum_1in_repeated_labels_ellipsis_static_cf) {Shape data_shape_1 = {1, 3, 2, 1, 3, 1};comparator.enable(FunctionsComparator::CmpValues::ACCURACY);{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);auto einsum = std::make_shared<opset7::Einsum>(OutputVector{data_1}, "ij...iji->j...i");model = std::make_shared<Model>(OutputVector{einsum}, ParameterVector{data_1});manager.register_pass<ov::pass::EinsumDecomposition>();@@ -408,7 +406,7 @@ TEST_F(TransformationTestsF, Einsum_1in_repeated_labels_ellipsis_static_cf) {}{using namespace ov::gen_pattern;- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);auto const_0 = makeConst(element::i64, ov::Shape({1}), {0});auto const_1 = makeConst(element::i64, ov::Shape({1}), {1});auto const_3 = makeConst(element::i64, ov::Shape({1}), {3});@@ -448,14 +446,14 @@ TEST_F(TransformationTestsF, Einsum_1in_repeated_labels_empty_ellipsis_dynamic)PartialShape data_shape_1 = PartialShape::dynamic(5);comparator.enable(FunctionsComparator::CmpValues::ACCURACY);{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);auto einsum = std::make_shared<opset7::Einsum>(OutputVector{data_1}, "ij...iji->j...i");model = std::make_shared<Model>(OutputVector{einsum}, ParameterVector{data_1});manager.register_pass<ov::pass::EinsumDecomposition>();}{using namespace ov::gen_pattern;- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);// Extract diagonalauto data_1_diagonal = extract_diagonal(data_1,@@ -477,9 +475,9 @@ TEST_F(TransformationTestsF, Einsum_3in_broadcast_duplicated_ellipsis_repeated_sPartialShape data_shape_3 = {3, 1, 3, 3};comparator.enable(FunctionsComparator::CmpValues::ACCURACY);{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto data_3 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_3);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto data_3 = std::make_shared<v0::Parameter>(element::f32, data_shape_3);auto einsum =std::make_shared<opset7::Einsum>(OutputVector{data_1, data_2, data_3}, "ba...b,bcccdd,...dbcc->c...b");model = std::make_shared<Model>(OutputVector{einsum}, ParameterVector{data_1, data_2, data_3});@@ -488,9 +486,9 @@ TEST_F(TransformationTestsF, Einsum_3in_broadcast_duplicated_ellipsis_repeated_s}{using namespace ov::gen_pattern;- auto node_0 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_3);- auto node_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto node_4 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);+ auto node_0 = std::make_shared<v0::Parameter>(element::f32, data_shape_3);+ auto node_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto node_4 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);auto Constant_8230 = makeConst(element::i64, ov::Shape({6}), {1, 2, 3, 4, 5, 0});auto Transpose_8231 = makeOP<opset1::Transpose>({node_2, Constant_8230});auto Concat_8261 = makeConst(element::i64, ov::Shape({3}), {1, 1, 4});@@ -577,9 +575,9 @@ TEST_F(TransformationTestsF, Einsum_3in_broadcast_duplicated_ellipsis_repeated_dPartialShape data_shape_3 = PartialShape::dynamic(4);comparator.enable(FunctionsComparator::CmpValues::ACCURACY);{- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto data_3 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_3);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto data_3 = std::make_shared<v0::Parameter>(element::f32, data_shape_3);auto einsum =std::make_shared<opset7::Einsum>(OutputVector{data_1, data_2, data_3}, "a...b,bcccdd,...dbcc->c...b");model = std::make_shared<Model>(OutputVector{einsum}, ParameterVector{data_1, data_2, data_3});@@ -587,9 +585,9 @@ TEST_F(TransformationTestsF, Einsum_3in_broadcast_duplicated_ellipsis_repeated_d}{using namespace ov::gen_pattern;- auto data_1 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_1);- auto data_2 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_2);- auto data_3 = std::make_shared<ov::op::v0::Parameter>(element::f32, data_shape_3);+ auto data_1 = std::make_shared<v0::Parameter>(element::f32, data_shape_1);+ auto data_2 = std::make_shared<v0::Parameter>(element::f32, data_shape_2);+ auto data_3 = std::make_shared<v0::Parameter>(element::f32, data_shape_3);// First pair of einsum inputs - data_1 and data_3// data_1 - label `a` can be reduced by reduce_input()diff --git a/src/common/transformations/tests/op_conversions/fake_convert_decomposition_test.cpp b/src/common/transformations/tests/op_conversions/fake_convert_decomposition_test.cppindex 3645e4126e2..138cb9c109c 100644--- a/src/common/transformations/tests/op_conversions/fake_convert_decomposition_test.cpp+++ b/src/common/transformations/tests/op_conversions/fake_convert_decomposition_test.cpp@@ -20,6 +20,8 @@using namespace ov;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;class FakeConvertDecompositionTestBase : public TransformationTestsF {protected:void SetUp() override {@@ -86,23 +88,23 @@ protected:: static_cast<float>(std::numeric_limits<ov::float8_e5m2>::max());std::shared_ptr<Node> result;- const auto scale = std::make_shared<ov::op::v1::Multiply>(data, input_scale);+ const auto scale = std::make_shared<v1::Multiply>(data, input_scale);if (default_shift) {- const auto clamp = std::make_shared<ov::op::v0::Clamp>(scale, lower_bound, upper_bound);- const auto downconvert = std::make_shared<ov::op::v0::Convert>(clamp, dst_prec);- result = std::make_shared<ov::op::v0::Convert>(downconvert, data_prec);+ const auto clamp = std::make_shared<v0::Clamp>(scale, lower_bound, upper_bound);+ const auto downconvert = std::make_shared<v0::Convert>(clamp, dst_prec);+ result = std::make_shared<v0::Convert>(downconvert, data_prec);} else {- const auto shift = std::make_shared<ov::op::v1::Subtract>(scale, input_shift);+ const auto shift = std::make_shared<v1::Subtract>(scale, input_shift);- const auto clamp = std::make_shared<ov::op::v0::Clamp>(shift, lower_bound, upper_bound);- const auto downconvert = std::make_shared<ov::op::v0::Convert>(clamp, dst_prec);- const auto upconvert = std::make_shared<ov::op::v0::Convert>(downconvert, data_prec);+ const auto clamp = std::make_shared<v0::Clamp>(shift, lower_bound, upper_bound);+ const auto downconvert = std::make_shared<v0::Convert>(clamp, dst_prec);+ const auto upconvert = std::make_shared<v0::Convert>(downconvert, data_prec);- const auto output_shift = std::make_shared<ov::op::v0::Constant>(data_prec, shift_shape, -12.f);- result = std::make_shared<ov::op::v1::Subtract>(upconvert, output_shift);+ const auto output_shift = std::make_shared<v0::Constant>(data_prec, shift_shape, -12.f);+ result = std::make_shared<v1::Subtract>(upconvert, output_shift);}const auto output_scale = std::make_shared<opset1::Constant>(data_prec, scale_shape, 1.f / 4.f);- result = std::make_shared<ov::op::v1::Multiply>(result, output_scale);+ result = std::make_shared<v1::Multiply>(result, output_scale);model_ref = std::make_shared<ov::Model>(OutputVector{result}, ParameterVector{data});}}@@ -174,12 +176,12 @@ TEST_F(FakeConvertDecompositionTestBase, FakeConvert_Decomposition_TrivialShift)const auto lower_bound = static_cast<float>(std::numeric_limits<ov::float8_e4m3>::lowest());const auto upper_bound = static_cast<float>(std::numeric_limits<ov::float8_e4m3>::max());- const auto scale = std::make_shared<ov::op::v1::Multiply>(data, input_scale);- const auto clamp = std::make_shared<ov::op::v0::Clamp>(scale, lower_bound, upper_bound);- const auto downconvert = std::make_shared<ov::op::v0::Convert>(clamp, dst_prec);- const auto upconvert = std::make_shared<ov::op::v0::Convert>(downconvert, data_prec);+ const auto scale = std::make_shared<v1::Multiply>(data, input_scale);+ const auto clamp = std::make_shared<v0::Clamp>(scale, lower_bound, upper_bound);+ const auto downconvert = std::make_shared<v0::Convert>(clamp, dst_prec);+ const auto upconvert = std::make_shared<v0::Convert>(downconvert, data_prec);const auto output_scale = std::make_shared<opset1::Constant>(data_prec, Shape{}, 1.f / 4.f);- const auto out_multiply = std::make_shared<ov::op::v1::Multiply>(upconvert, output_scale);+ const auto out_multiply = std::make_shared<v1::Multiply>(upconvert, output_scale);model_ref = std::make_shared<ov::Model>(OutputVector{out_multiply}, ParameterVector{data});}}diff --git a/src/common/transformations/tests/op_conversions/ngraph_depth_to_space_transform_test.cpp b/src/common/transformations/tests/op_conversions/ngraph_depth_to_space_transform_test.cppindex 0ad227cfea2..4d74865a662 100644--- a/src/common/transformations/tests/op_conversions/ngraph_depth_to_space_transform_test.cpp+++ b/src/common/transformations/tests/op_conversions/ngraph_depth_to_space_transform_test.cpp@@ -22,6 +22,7 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;TEST(TransformationTests, TestDepthToSpaceTransformBlockFirst) {auto input = std::make_shared<op::v0::Parameter>(element::f32, Shape{1, 12, 1080, 1616});std::shared_ptr<ov::Model> f(nullptr);@@ -41,8 +42,7 @@ TEST(TransformationTests, TestDepthToSpaceTransformBlockFirst) {ASSERT_EQ(consumers.size(), 1);auto reshape_begin = consumers.begin()->get_node();- auto shape_begin =- ov::as_type_ptr<ov::op::v0::Constant>(reshape_begin->input(1).get_source_output().get_node_shared_ptr());+ auto shape_begin = ov::as_type_ptr<v0::Constant>(reshape_begin->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> shape_begin_value = shape_begin->get_vector<int64_t>();std::vector<int64_t> shape_begin_value_ref{1, 2, 2, 3, 1080, 1616};ASSERT_EQ(shape_begin_value, shape_begin_value_ref);@@ -51,15 +51,14 @@ TEST(TransformationTests, TestDepthToSpaceTransformBlockFirst) {ASSERT_EQ(consumers.size(), 1);auto transpose = consumers.begin()->get_node();- auto order = ov::as_type_ptr<ov::op::v0::Constant>(transpose->input(1).get_source_output().get_node_shared_ptr());+ auto order = ov::as_type_ptr<v0::Constant>(transpose->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> order_value = order->get_vector<int64_t>();std::vector<int64_t> order_value_ref{0, 3, 4, 1, 5, 2};ASSERT_EQ(order_value, order_value_ref);consumers = transpose->output(0).get_target_inputs();auto reshape_end = consumers.begin()->get_node();- auto shape_end =- ov::as_type_ptr<ov::op::v0::Constant>(reshape_end->input(1).get_source_output().get_node_shared_ptr());+ auto shape_end = ov::as_type_ptr<v0::Constant>(reshape_end->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> shape_end_value = shape_end->get_vector<int64_t>();std::vector<int64_t> shape_end_value_ref{1, 3, 2 * 1080, 2 * 1616};ASSERT_EQ(shape_end_value, shape_end_value_ref);@@ -84,8 +83,7 @@ TEST(TransformationTests, TestDepthToSpaceTransformDepthFirst) {ASSERT_EQ(consumers.size(), 1);auto reshape_begin = consumers.begin()->get_node();- auto shape_begin =- ov::as_type_ptr<ov::op::v0::Constant>(reshape_begin->input(1).get_source_output().get_node_shared_ptr());+ auto shape_begin = ov::as_type_ptr<v0::Constant>(reshape_begin->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> shape_begin_value = shape_begin->get_vector<int64_t>();std::vector<int64_t> shape_begin_value_ref{1, 3, 2, 2, 1080, 1616};ASSERT_EQ(shape_begin_value, shape_begin_value_ref);@@ -94,15 +92,14 @@ TEST(TransformationTests, TestDepthToSpaceTransformDepthFirst) {ASSERT_EQ(consumers.size(), 1);auto transpose = consumers.begin()->get_node();- auto order = ov::as_type_ptr<ov::op::v0::Constant>(transpose->input(1).get_source_output().get_node_shared_ptr());+ auto order = ov::as_type_ptr<v0::Constant>(transpose->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> order_value = order->get_vector<int64_t>();std::vector<int64_t> order_value_ref{0, 1, 4, 2, 5, 3};ASSERT_EQ(order_value, order_value_ref);consumers = transpose->output(0).get_target_inputs();auto reshape_end = consumers.begin()->get_node();- auto shape_end =- ov::as_type_ptr<ov::op::v0::Constant>(reshape_end->input(1).get_source_output().get_node_shared_ptr());+ auto shape_end = ov::as_type_ptr<v0::Constant>(reshape_end->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> shape_end_value = shape_end->get_vector<int64_t>();std::vector<int64_t> shape_end_value_ref{1, 3, 2 * 1080, 2 * 1616};ASSERT_EQ(shape_end_value, shape_end_value_ref);@@ -127,8 +124,7 @@ TEST(TransformationTests, TestSpaceToDepthTransformBlockFirst) {ASSERT_EQ(consumers.size(), 1);auto reshape_begin = consumers.begin()->get_node();- auto shape_begin =- ov::as_type_ptr<ov::op::v0::Constant>(reshape_begin->input(1).get_source_output().get_node_shared_ptr());+ auto shape_begin = ov::as_type_ptr<v0::Constant>(reshape_begin->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> shape_begin_value = shape_begin->get_vector<int64_t>();std::vector<int64_t> shape_begin_value_ref{1, 12, 1080 / 2, 2, 1616 / 2, 2};ASSERT_EQ(shape_begin_value, shape_begin_value_ref);@@ -137,15 +133,14 @@ TEST(TransformationTests, TestSpaceToDepthTransformBlockFirst) {ASSERT_EQ(consumers.size(), 1);auto transpose = consumers.begin()->get_node();- auto order = ov::as_type_ptr<ov::op::v0::Constant>(transpose->input(1).get_source_output().get_node_shared_ptr());+ auto order = ov::as_type_ptr<v0::Constant>(transpose->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> order_value = order->get_vector<int64_t>();std::vector<int64_t> order_value_ref{0, 3, 5, 1, 2, 4};ASSERT_EQ(order_value, order_value_ref);consumers = transpose->output(0).get_target_inputs();auto reshape_end = consumers.begin()->get_node();- auto shape_end =- ov::as_type_ptr<ov::op::v0::Constant>(reshape_end->input(1).get_source_output().get_node_shared_ptr());+ auto shape_end = ov::as_type_ptr<v0::Constant>(reshape_end->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> shape_end_value = shape_end->get_vector<int64_t>();std::vector<int64_t> shape_end_value_ref{1, 12 * 4, 1080 / 2, 1616 / 2};ASSERT_EQ(shape_end_value, shape_end_value_ref);@@ -170,8 +165,7 @@ TEST(TransformationTests, TestSpaceToDepthTransformDepthFirst) {ASSERT_EQ(consumers.size(), 1);auto reshape_begin = consumers.begin()->get_node();- auto shape_begin =- ov::as_type_ptr<ov::op::v0::Constant>(reshape_begin->input(1).get_source_output().get_node_shared_ptr());+ auto shape_begin = ov::as_type_ptr<v0::Constant>(reshape_begin->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> shape_begin_value = shape_begin->get_vector<int64_t>();std::vector<int64_t> shape_begin_value_ref{1, 12, 1080 / 2, 2, 1616 / 2, 2};ASSERT_EQ(shape_begin_value, shape_begin_value_ref);@@ -180,15 +174,14 @@ TEST(TransformationTests, TestSpaceToDepthTransformDepthFirst) {ASSERT_EQ(consumers.size(), 1);auto transpose = consumers.begin()->get_node();- auto order = ov::as_type_ptr<ov::op::v0::Constant>(transpose->input(1).get_source_output().get_node_shared_ptr());+ auto order = ov::as_type_ptr<v0::Constant>(transpose->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> order_value = order->get_vector<int64_t>();std::vector<int64_t> order_value_ref{0, 1, 3, 5, 2, 4};ASSERT_EQ(order_value, order_value_ref);consumers = transpose->output(0).get_target_inputs();auto reshape_end = consumers.begin()->get_node();- auto shape_end =- ov::as_type_ptr<ov::op::v0::Constant>(reshape_end->input(1).get_source_output().get_node_shared_ptr());+ auto shape_end = ov::as_type_ptr<v0::Constant>(reshape_end->input(1).get_source_output().get_node_shared_ptr());std::vector<int64_t> shape_end_value = shape_end->get_vector<int64_t>();std::vector<int64_t> shape_end_value_ref{1, 12 * 4, 1080 / 2, 1616 / 2};ASSERT_EQ(shape_end_value, shape_end_value_ref);diff --git a/src/common/transformations/tests/op_conversions/scaled_dot_product_decomposition_test.cpp b/src/common/transformations/tests/op_conversions/scaled_dot_product_decomposition_test.cppindex 1d1990503d8..7ef98a33aa1 100644--- a/src/common/transformations/tests/op_conversions/scaled_dot_product_decomposition_test.cpp+++ b/src/common/transformations/tests/op_conversions/scaled_dot_product_decomposition_test.cpp@@ -34,6 +34,12 @@using namespace ov;using namespace testing;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v8 = ov::op::v8;+namespace v13 = ov::op::v13;const std::shared_ptr<ov::Node> scaled_dot_product_attention_decomposition(std::shared_ptr<ov::Node> query,std::shared_ptr<ov::Node> key,std::shared_ptr<ov::Node> value,@@ -50,15 +56,15 @@ TEST_F(TransformationTestsF, ScaledDotProductAttentionDecompositionStaticBasic)const PartialShape attention_mask_shape{1, 32, 32};const PartialShape scale_shape{1};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto attention_mask = std::make_shared<ov::op::v0::Parameter>(element::f32, attention_mask_shape);- const auto scale = std::make_shared<ov::op::v0::Parameter>(element::f32, scale_shape);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto attention_mask = std::make_shared<v0::Parameter>(element::f32, attention_mask_shape);+ const auto scale = std::make_shared<v0::Parameter>(element::f32, scale_shape);const auto casual = false;{const auto scaled_dot_product_attention =- std::make_shared<ov::op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);+ std::make_shared<v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);model = std::make_shared<ov::Model>(OutputVector{scaled_dot_product_attention},ParameterVector{query, key, value, attention_mask, scale});@@ -80,15 +86,15 @@ TEST_F(TransformationTestsF, ScaledDotProductAttentionDecompositionStaticBroadcaconst PartialShape attention_mask_shape{1, 1, 3, 4};const PartialShape scale_shape{1};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto attention_mask = std::make_shared<ov::op::v0::Parameter>(element::f32, attention_mask_shape);- const auto scale = std::make_shared<ov::op::v0::Parameter>(element::f32, scale_shape);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto attention_mask = std::make_shared<v0::Parameter>(element::f32, attention_mask_shape);+ const auto scale = std::make_shared<v0::Parameter>(element::f32, scale_shape);const auto casual = false;{const auto scaled_dot_product_attention =- std::make_shared<ov::op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);+ std::make_shared<v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);model = std::make_shared<ov::Model>(OutputVector{scaled_dot_product_attention},ParameterVector{query, key, value, attention_mask, scale});@@ -110,15 +116,15 @@ TEST_F(TransformationTestsF, ScaledDotProductAttentionDecompositionStaticBroadcaconst PartialShape attention_mask_shape{1, 1, 3, 1};const PartialShape scale_shape{};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto attention_mask = std::make_shared<ov::op::v0::Parameter>(element::f32, attention_mask_shape);- const auto scale = std::make_shared<ov::op::v0::Parameter>(element::f32, scale_shape);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto attention_mask = std::make_shared<v0::Parameter>(element::f32, attention_mask_shape);+ const auto scale = std::make_shared<v0::Parameter>(element::f32, scale_shape);const auto casual = false;{const auto scaled_dot_product_attention =- std::make_shared<ov::op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);+ std::make_shared<v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);model = std::make_shared<ov::Model>(OutputVector{scaled_dot_product_attention},ParameterVector{query, key, value, attention_mask, scale});@@ -140,13 +146,13 @@ TEST_F(TransformationTestsF, ScaledDotProductAttentionCasualPartiallyDynamic) {const PartialShape attention_mask_shape{-1, -1, -1, -1};const auto casual = true;- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto attention_mask = std::make_shared<ov::op::v0::Parameter>(element::f32, attention_mask_shape);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto attention_mask = std::make_shared<v0::Parameter>(element::f32, attention_mask_shape);{const auto scaled_dot_product_attention =- std::make_shared<ov::op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, casual);+ std::make_shared<v13::ScaledDotProductAttention>(query, key, value, attention_mask, casual);model = std::make_shared<ov::Model>(OutputVector{scaled_dot_product_attention},ParameterVector{query, key, value, attention_mask});@@ -168,15 +174,15 @@ TEST_F(TransformationTestsF, ScaledDotProductAttentionDecompositionDynamic) {const PartialShape attention_mask_shape{-1, -1, -1};const PartialShape scale_shape{};- const auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- const auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- const auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- const auto attention_mask = std::make_shared<ov::op::v0::Parameter>(element::f32, attention_mask_shape);- const auto scale = std::make_shared<ov::op::v0::Parameter>(element::f32, scale_shape);+ const auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ const auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ const auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ const auto attention_mask = std::make_shared<v0::Parameter>(element::f32, attention_mask_shape);+ const auto scale = std::make_shared<v0::Parameter>(element::f32, scale_shape);const auto casual = false;{const auto scaled_dot_product_attention =- std::make_shared<ov::op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);+ std::make_shared<v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);model = std::make_shared<ov::Model>(OutputVector{scaled_dot_product_attention},ParameterVector{query, key, value, attention_mask, scale});@@ -198,18 +204,17 @@ TEST_F(TransformationTestsF, ScaledDotProductAttentionDecomposition_ScalarScale_const PartialShape attention_mask_shape{1, 32, 32};// Constant scalar scale- auto scale = ov::op::v0::Constant::create(element::f32, Shape{}, {0.125f});+ auto scale = v0::Constant::create(element::f32, Shape{}, {0.125f});- auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- auto attention_mask = std::make_shared<ov::op::v0::Parameter>(element::f32, attention_mask_shape);+ auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ auto attention_mask = std::make_shared<v0::Parameter>(element::f32, attention_mask_shape);const bool casual = false;{- auto sdp =- std::make_shared<ov::op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);+ auto sdp = std::make_shared<v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);model = std::make_shared<ov::Model>(OutputVector{sdp}, ParameterVector{query, key, value, attention_mask});manager.register_pass<ov::pass::ScaledDotProductAttentionDecomposition>();}@@ -227,17 +232,16 @@ TEST_F(TransformationTestsF, ScaledDotProductAttentionDecomposition_DynamicScaleconst PartialShape attention_mask_shape{-1, -1, -1};const PartialShape scale_shape{1};- auto scale = std::make_shared<ov::op::v0::Parameter>(element::f32, scale_shape);- auto query = std::make_shared<ov::op::v0::Parameter>(element::f32, query_shape);- auto key = std::make_shared<ov::op::v0::Parameter>(element::f32, key_shape);- auto value = std::make_shared<ov::op::v0::Parameter>(element::f32, value_shape);- auto attention_mask = std::make_shared<ov::op::v0::Parameter>(element::f32, attention_mask_shape);+ auto scale = std::make_shared<v0::Parameter>(element::f32, scale_shape);+ auto query = std::make_shared<v0::Parameter>(element::f32, query_shape);+ auto key = std::make_shared<v0::Parameter>(element::f32, key_shape);+ auto value = std::make_shared<v0::Parameter>(element::f32, value_shape);+ auto attention_mask = std::make_shared<v0::Parameter>(element::f32, attention_mask_shape);const bool casual = false;{- auto sdp =- std::make_shared<ov::op::v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);+ auto sdp = std::make_shared<v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, casual);model =std::make_shared<ov::Model>(OutputVector{sdp}, ParameterVector{query, key, value, attention_mask, scale});manager.register_pass<ov::pass::ScaledDotProductAttentionDecomposition>();@@ -258,106 +262,102 @@ const std::shared_ptr<ov::Node> scaled_dot_product_attention_decomposition(std::bool casual,bool scale_after_matmul,std::shared_ptr<ov::Node> sinks) {- const auto q_shape = std::make_shared<ov::op::v3::ShapeOf>(query, element::i32);- const auto k_shape = std::make_shared<ov::op::v3::ShapeOf>(key, element::i32);- const auto minus_one = ov::op::v0::Constant::create(element::i32, Shape{}, {-1});- const auto minus_two = ov::op::v0::Constant::create(element::i32, Shape{}, {-2});- const auto zero_i = ov::op::v0::Constant::create(element::i32, Shape{}, {0});- const auto one_i = ov::op::v0::Constant::create(element::i32, Shape{}, {1});- const auto one_f = std::make_shared<ov::op::v1::ConvertLike>(one_i, query);- const auto zero_f = std::make_shared<ov::op::v1::ConvertLike>(zero_i, query);-- auto extract_dim = [&zero_i](const std::shared_ptr<ov::op::v3::ShapeOf>& shape_of,+ const auto q_shape = std::make_shared<v3::ShapeOf>(query, element::i32);+ const auto k_shape = std::make_shared<v3::ShapeOf>(key, element::i32);+ const auto minus_one = v0::Constant::create(element::i32, Shape{}, {-1});+ const auto minus_two = v0::Constant::create(element::i32, Shape{}, {-2});+ const auto zero_i = v0::Constant::create(element::i32, Shape{}, {0});+ const auto one_i = v0::Constant::create(element::i32, Shape{}, {1});+ const auto one_f = std::make_shared<v1::ConvertLike>(one_i, query);+ const auto zero_f = std::make_shared<v1::ConvertLike>(zero_i, query);++ auto extract_dim = [&zero_i](const std::shared_ptr<v3::ShapeOf>& shape_of,const int64_t idx) -> std::shared_ptr<ov::Node> {const auto& shape = shape_of->get_input_partial_shape(0);const auto& dim = shape[idx];if (dim.is_static()) {- return ov::op::v0::Constant::create(element::i32, Shape{}, {dim.get_length()});+ return v0::Constant::create(element::i32, Shape{}, {dim.get_length()});}- const auto dim_to_extract_const = ov::op::v0::Constant::create(element::i32, Shape{}, {idx});- return std::make_shared<ov::op::v8::Gather>(shape_of, dim_to_extract_const, zero_i);+ const auto dim_to_extract_const = v0::Constant::create(element::i32, Shape{}, {idx});+ return std::make_shared<v8::Gather>(shape_of, dim_to_extract_const, zero_i);};if (scale == nullptr) {scale = extract_dim(q_shape, -1);- scale = std::make_shared<ov::op::v1::ConvertLike>(scale, query);- auto sqrt_scale = std::make_shared<ov::op::v0::Sqrt>(scale);- scale = std::make_shared<ov::op::v1::Divide>(one_f, sqrt_scale);+ scale = std::make_shared<v1::ConvertLike>(scale, query);+ auto sqrt_scale = std::make_shared<v0::Sqrt>(scale);+ scale = std::make_shared<v1::Divide>(one_f, sqrt_scale);}- auto k_rank = std::make_shared<ov::op::v3::ShapeOf>(k_shape, element::i32)->output(0);- const auto k_last_dim = std::make_shared<ov::op::v1::Add>(k_rank, minus_one);- const auto k_next_dim = std::make_shared<ov::op::v1::Add>(k_rank, minus_two)->output(0);- k_rank = std::make_shared<ov::op::v0::Squeeze>(k_rank, zero_i);- auto minus_inf =- ov::op::v0::Constant::create(element::f32, Shape{}, {-std::numeric_limits<float>::infinity()})->output(0);- const auto keep_dim_last = std::make_shared<ov::op::v0::Squeeze>(k_next_dim, zero_i);- const auto k_dims_before_transpose =- std::make_shared<ov::op::v4::Range>(zero_i, keep_dim_last, one_i, element::i32);+ auto k_rank = std::make_shared<v3::ShapeOf>(k_shape, element::i32)->output(0);+ const auto k_last_dim = std::make_shared<v1::Add>(k_rank, minus_one);+ const auto k_next_dim = std::make_shared<v1::Add>(k_rank, minus_two)->output(0);+ k_rank = std::make_shared<v0::Squeeze>(k_rank, zero_i);+ auto minus_inf = v0::Constant::create(element::f32, Shape{}, {-std::numeric_limits<float>::infinity()})->output(0);+ const auto keep_dim_last = std::make_shared<v0::Squeeze>(k_next_dim, zero_i);+ const auto k_dims_before_transpose = std::make_shared<v4::Range>(zero_i, keep_dim_last, one_i, element::i32);const auto transpose_dims =- std::make_shared<ov::op::v0::Concat>(OutputVector{k_dims_before_transpose, k_last_dim, k_next_dim}, 0);- const auto k_transposed = std::make_shared<ov::op::v1::Transpose>(key, transpose_dims);+ std::make_shared<v0::Concat>(OutputVector{k_dims_before_transpose, k_last_dim, k_next_dim}, 0);+ const auto k_transposed = std::make_shared<v1::Transpose>(key, transpose_dims);Output<Node> scaled_atten;if (scale_after_matmul) {- const auto atten = std::make_shared<ov::op::v0::MatMul>(query, k_transposed)->output(0);- scaled_atten = std::make_shared<ov::op::v1::Multiply>(atten, scale);+ const auto atten = std::make_shared<v0::MatMul>(query, k_transposed)->output(0);+ scaled_atten = std::make_shared<v1::Multiply>(atten, scale);} else {- const auto q_scaled = std::make_shared<ov::op::v1::Multiply>(query, scale);- scaled_atten = std::make_shared<ov::op::v0::MatMul>(q_scaled, k_transposed)->output(0);+ const auto q_scaled = std::make_shared<v1::Multiply>(query, scale);+ scaled_atten = std::make_shared<v0::MatMul>(q_scaled, k_transposed)->output(0);}- minus_inf = std::make_shared<ov::op::v1::ConvertLike>(minus_inf, scaled_atten);+ minus_inf = std::make_shared<v1::ConvertLike>(minus_inf, scaled_atten);Output<Node> mask;Output<Node> atten_mask;if (!casual) {mask = attention_mask;if (mask.get_element_type() == element::boolean) {- atten_mask = std::make_shared<ov::op::v1::Select>(mask, zero_f, minus_inf);+ atten_mask = std::make_shared<v1::Select>(mask, zero_f, minus_inf);} else {atten_mask = mask;}} else {const auto target_s_len = extract_dim(q_shape, -2);const auto source_s_len = extract_dim(k_shape, -2);- const auto ssl = std::make_shared<ov::op::v0::Unsqueeze>(source_s_len, zero_i);- const auto tsl = std::make_shared<ov::op::v0::Unsqueeze>(target_s_len, zero_i);- const auto mask_shape = std::make_shared<ov::op::v0::Concat>(OutputVector{tsl, ssl}, 0);- mask = std::make_shared<ov::op::v1::Broadcast>(minus_inf, mask_shape);- auto horizontal_range =- std::make_shared<ov::op::v4::Range>(zero_i, source_s_len, one_i, element::i32)->output(0);- horizontal_range = std::make_shared<ov::op::v0::Unsqueeze>(horizontal_range, zero_i);- const auto stop = std::make_shared<ov::op::v1::Add>(target_s_len, one_i);- auto vertical_range = std::make_shared<ov::op::v4::Range>(one_i, stop, one_i, element::i32)->output(0);- vertical_range = std::make_shared<ov::op::v0::Unsqueeze>(vertical_range, one_i);- const auto triu = std::make_shared<ov::op::v1::GreaterEqual>(horizontal_range, vertical_range);- atten_mask = std::make_shared<ov::op::v1::Select>(triu, mask, zero_f);+ const auto ssl = std::make_shared<v0::Unsqueeze>(source_s_len, zero_i);+ const auto tsl = std::make_shared<v0::Unsqueeze>(target_s_len, zero_i);+ const auto mask_shape = std::make_shared<v0::Concat>(OutputVector{tsl, ssl}, 0);+ mask = std::make_shared<v1::Broadcast>(minus_inf, mask_shape);+ auto horizontal_range = std::make_shared<v4::Range>(zero_i, source_s_len, one_i, element::i32)->output(0);+ horizontal_range = std::make_shared<v0::Unsqueeze>(horizontal_range, zero_i);+ const auto stop = std::make_shared<v1::Add>(target_s_len, one_i);+ auto vertical_range = std::make_shared<v4::Range>(one_i, stop, one_i, element::i32)->output(0);+ vertical_range = std::make_shared<v0::Unsqueeze>(vertical_range, one_i);+ const auto triu = std::make_shared<v1::GreaterEqual>(horizontal_range, vertical_range);+ atten_mask = std::make_shared<v1::Select>(triu, mask, zero_f);}- scaled_atten = std::make_shared<ov::op::v1::Add>(scaled_atten, atten_mask);+ scaled_atten = std::make_shared<v1::Add>(scaled_atten, atten_mask);if (sinks) {- auto minus_two = ov::op::v0::Constant::create(element::i32, Shape{1}, {-2});- auto minus_one = ov::op::v0::Constant::create(element::i32, Shape{1}, {-1});- auto zero_i = ov::op::v0::Constant::create(element::i32, Shape{1}, {0});- auto one_i = ov::op::v0::Constant::create(element::i32, Shape{1}, {1});-- auto q_last_but_one_dim =- std::make_shared<ov::op::v1::Subtract>(std::make_shared<ov::op::v0::ShapeOf>(q_shape),- ov::op::v0::Constant::create(ov::element::i64, Shape{}, {1}));- auto sinks_target_shape_1 = std::make_shared<ov::op::v8::Slice>(q_shape, zero_i, q_last_but_one_dim, one_i);- auto sinks_target_shape = std::make_shared<ov::op::v0::Concat>(OutputVector{sinks_target_shape_1, one_i}, 0);- auto sinks_broadcast = std::make_shared<ov::op::v1::Broadcast>(sinks, sinks_target_shape);-- auto scaled_attn_sink = std::make_shared<ov::op::v0::Concat>(OutputVector{scaled_atten, sinks_broadcast}, -1);- scaled_atten = std::make_shared<ov::op::v8::Softmax>(scaled_attn_sink, -1);-- auto prev_seq_len = std::make_shared<ov::op::v8::Gather>(k_shape, minus_two, zero_i);- scaled_atten = std::make_shared<ov::op::v8::Slice>(scaled_atten, zero_i, prev_seq_len, one_i, minus_one);+ auto minus_two = v0::Constant::create(element::i32, Shape{1}, {-2});+ auto minus_one = v0::Constant::create(element::i32, Shape{1}, {-1});+ auto zero_i = v0::Constant::create(element::i32, Shape{1}, {0});+ auto one_i = v0::Constant::create(element::i32, Shape{1}, {1});++ auto q_last_but_one_dim = std::make_shared<v1::Subtract>(std::make_shared<v0::ShapeOf>(q_shape),+ v0::Constant::create(ov::element::i64, Shape{}, {1}));+ auto sinks_target_shape_1 = std::make_shared<v8::Slice>(q_shape, zero_i, q_last_but_one_dim, one_i);+ auto sinks_target_shape = std::make_shared<v0::Concat>(OutputVector{sinks_target_shape_1, one_i}, 0);+ auto sinks_broadcast = std::make_shared<v1::Broadcast>(sinks, sinks_target_shape);++ auto scaled_attn_sink = std::make_shared<v0::Concat>(OutputVector{scaled_atten, sinks_broadcast}, -1);+ scaled_atten = std::make_shared<v8::Softmax>(scaled_attn_sink, -1);++ auto prev_seq_len = std::make_shared<v8::Gather>(k_shape, minus_two, zero_i);+ scaled_atten = std::make_shared<v8::Slice>(scaled_atten, zero_i, prev_seq_len, one_i, minus_one);} else {- scaled_atten = std::make_shared<ov::op::v8::Softmax>(scaled_atten, -1);+ scaled_atten = std::make_shared<v8::Softmax>(scaled_atten, -1);}- const std::shared_ptr<ov::Node> result = std::make_shared<ov::op::v0::MatMul>(scaled_atten, value);+ const std::shared_ptr<ov::Node> result = std::make_shared<v0::MatMul>(scaled_atten, value);return result;}@@ -369,23 +369,18 @@ TEST_F(TransformationTestsF, ScaledDotProductAttentionDecomposition_Sinks) {const PartialShape scale_shape{1};const PartialShape sinks_shape{1, 64, 1, 1};- auto scale = std::make_shared<ov::op::v0::Parameter>(element::f16, scale_shape);- auto query = std::make_shared<ov::op::v0::Parameter>(element::f16, query_shape);- auto key = std::make_shared<ov::op::v0::Parameter>(element::f16, key_shape);- auto value = std::make_shared<ov::op::v0::Parameter>(element::f16, value_shape);- auto attention_mask = std::make_shared<ov::op::v0::Parameter>(element::f16, attention_mask_shape);- auto sinks = std::make_shared<ov::op::v0::Parameter>(element::f16, sinks_shape);+ auto scale = std::make_shared<v0::Parameter>(element::f16, scale_shape);+ auto query = std::make_shared<v0::Parameter>(element::f16, query_shape);+ auto key = std::make_shared<v0::Parameter>(element::f16, key_shape);+ auto value = std::make_shared<v0::Parameter>(element::f16, value_shape);+ auto attention_mask = std::make_shared<v0::Parameter>(element::f16, attention_mask_shape);+ auto sinks = std::make_shared<v0::Parameter>(element::f16, sinks_shape);const bool casual = false;{- auto sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(query,- key,- value,- attention_mask,- scale,- sinks,- casual);+ auto sdpa =+ std::make_shared<v13::ScaledDotProductAttention>(query, key, value, attention_mask, scale, sinks, casual);model = std::make_shared<ov::Model>(OutputVector{sdpa},ParameterVector{query, key, value, attention_mask, scale, sinks});manager.register_pass<ov::pass::ScaledDotProductAttentionDecomposition>();diff --git a/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp b/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cppindex be4a5de8b35..3ad5cfa4b29 100644--- a/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp+++ b/src/common/transformations/tests/op_conversions/sdpa_to_paged_attention_test.cpp@@ -58,9 +58,15 @@using namespace ov;using namespace std;using namespace testing;-using namespace ov::op;using namespace ov::gen_pattern;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v6 = ov::op::v6;+namespace v8 = ov::op::v8;+namespace v13 = ov::op::v13;namespace {// Constants and Parameters attributes:@@ -2692,7 +2698,7 @@ TEST_F(SDPAToPATest, SDPAToPA_gpt_oss_General) {MOCK_VALUE);auto sliding_window_neg = makeConst(element::f32, ov::Shape({1, 1, 1, 1}), {-128.0f});- auto Squeeze2 = makeOP<v15::Squeeze>({sliding_window_neg}, {{"allow_axis_skip", false}});+ auto Squeeze2 = makeOP<ov::op::v15::Squeeze>({sliding_window_neg}, {{"allow_axis_skip", false}});auto Convert16 = makeOP<v0::Convert>({Squeeze2}, {{"destination_type", "i32"}});auto sliding_window = makeOP<v1::Multiply>({Convert16, -1}, {{"auto_broadcast", "numpy"}});auto scale = v0::Constant::create(element::f32, {}, {0.1250f});diff --git a/src/common/transformations/tests/sdpa_to_paged_attention_test.cpp b/src/common/transformations/tests/sdpa_to_paged_attention_test.cppindex bd9e7770cce..ee6b23c4cc6 100644--- a/src/common/transformations/tests/sdpa_to_paged_attention_test.cpp+++ b/src/common/transformations/tests/sdpa_to_paged_attention_test.cpp@@ -22,6 +22,7 @@using namespace ov;+namespace op_util = ov::op::util;TEST(SDPATOPATest, SDPANotPresent) {const auto p0 = std::make_shared<op::v0::Parameter>(element::f32, Shape{1, 32, 32});const auto p1 = std::make_shared<op::v0::Parameter>(element::f32, Shape{1, 32, 32});@@ -41,8 +42,8 @@ TEST(SDPATOPATest, GatherIdx_ConcatAxis_EQ) {const int GATHER_IDX = 1;const auto input = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{PartialShape::dynamic(), element::i32, "variable"});+ auto variable =+ std::make_shared<op_util::Variable>(op_util::VariableInfo{PartialShape::dynamic(), element::i32, "variable"});const auto read_value = std::make_shared<op::v6::ReadValue>(input, variable);const auto beam_idx = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});@@ -84,8 +85,8 @@ TEST(SDPATOPATest, GatherIdx_ConcatAxis_NOTEQ_STATIC) {const int GATHER_IDX = 0;const auto input = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{PartialShape::dynamic(), element::i32, "variable"});+ auto variable =+ std::make_shared<op_util::Variable>(op_util::VariableInfo{PartialShape::dynamic(), element::i32, "variable"});const auto read_value = std::make_shared<op::v6::ReadValue>(input, variable);const auto beam_idx = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});@@ -123,8 +124,8 @@ TEST(SDPATOPATest, GatherIdx_ConcatAxis_NOTEQ_DYNAMIC) {const int GATHER_IDX = 0;const auto input = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{PartialShape::dynamic(), element::i32, "variable"});+ auto variable =+ std::make_shared<op_util::Variable>(op_util::VariableInfo{PartialShape::dynamic(), element::i32, "variable"});const auto read_value = std::make_shared<op::v6::ReadValue>(input, variable);const auto beam_idx = std::make_shared<op::v0::Parameter>(element::i32, PartialShape{});diff --git a/src/common/transformations/tests/smart_reshape/lstm_states_broadcast.cpp b/src/common/transformations/tests/smart_reshape/lstm_states_broadcast.cppindex 83d0875f931..2b80338cbc8 100644--- a/src/common/transformations/tests/smart_reshape/lstm_states_broadcast.cpp+++ b/src/common/transformations/tests/smart_reshape/lstm_states_broadcast.cpp@@ -15,6 +15,7 @@using namespace std;using namespace ov::opset9;+namespace v0 = ov::op::v0;struct LSTMStatesAttributes {ov::element::Type_t data_et;ov::Dimension data_batch_size, new_batch_size;@@ -30,14 +31,10 @@ TEST_P(LSTMStatesBroadcastTest, BareLSTM) {shared_ptr<ov::Model> model(nullptr);{auto parameter = make_shared<Parameter>(p.data_et, ov::PartialShape{p.data_batch_size, p.input_size});- auto initial_hidden_state =- ov::op::v0::Constant::create(p.data_et, ov::PartialShape{1, p.hidden_size}.to_shape(), {0});- auto initial_cell_state =- ov::op::v0::Constant::create(p.data_et, ov::PartialShape{1, p.hidden_size}.to_shape(), {0});- auto W =- ov::op::v0::Constant::create(p.data_et, ov::PartialShape{p.hidden_size * 4, p.input_size}.to_shape(), {0});- auto R =- ov::op::v0::Constant::create(p.data_et, ov::PartialShape{p.hidden_size * 4, p.hidden_size}.to_shape(), {0});+ auto initial_hidden_state = v0::Constant::create(p.data_et, ov::PartialShape{1, p.hidden_size}.to_shape(), {0});+ auto initial_cell_state = v0::Constant::create(p.data_et, ov::PartialShape{1, p.hidden_size}.to_shape(), {0});+ auto W = v0::Constant::create(p.data_et, ov::PartialShape{p.hidden_size * 4, p.input_size}.to_shape(), {0});+ auto R = v0::Constant::create(p.data_et, ov::PartialShape{p.hidden_size * 4, p.hidden_size}.to_shape(), {0});auto cell = make_shared<LSTMCell>(parameter,initial_hidden_state,@@ -60,10 +57,8 @@ TEST_P(LSTMStatesBroadcastTestWithTI, TI_With_LSTM) {shared_ptr<ov::Model> model(nullptr);{auto X = make_shared<Parameter>(p.data_et, ov::PartialShape{p.data_batch_size, 1, p.input_size});- auto H_init =- ov::op::v0::Constant::create(ov::element::i64, ov::PartialShape{1, p.hidden_size}.to_shape(), {0});- auto C_init =- ov::op::v0::Constant::create(ov::element::i64, ov::PartialShape{1, p.hidden_size}.to_shape(), {0});+ auto H_init = v0::Constant::create(ov::element::i64, ov::PartialShape{1, p.hidden_size}.to_shape(), {0});+ auto C_init = v0::Constant::create(ov::element::i64, ov::PartialShape{1, p.hidden_size}.to_shape(), {0});auto Xi = make_shared<Parameter>(p.data_et, ov::PartialShape{1, 1, p.input_size});auto H_t = make_shared<Parameter>(p.data_et, ov::PartialShape{1, p.hidden_size});@@ -71,10 +66,8 @@ TEST_P(LSTMStatesBroadcastTestWithTI, TI_With_LSTM) {// Bodyauto squeeze = make_shared<Squeeze>(Xi, create_constant<int64_t>({1}));- auto W =- ov::op::v0::Constant::create(p.data_et, ov::PartialShape{p.hidden_size * 4, p.input_size}.to_shape(), {0});- auto R =- ov::op::v0::Constant::create(p.data_et, ov::PartialShape{p.hidden_size * 4, p.hidden_size}.to_shape(), {0});+ auto W = v0::Constant::create(p.data_et, ov::PartialShape{p.hidden_size * 4, p.input_size}.to_shape(), {0});+ auto R = v0::Constant::create(p.data_et, ov::PartialShape{p.hidden_size * 4, p.hidden_size}.to_shape(), {0});auto lstm_cell =make_shared<LSTMCell>(squeeze, H_t, C_t, W, R, static_cast<size_t>(p.hidden_size.get_length()));diff --git a/src/common/transformations/tests/smart_reshape/reshape_sinking.cpp b/src/common/transformations/tests/smart_reshape/reshape_sinking.cppindex d8df097c2f2..845e8cbd3ee 100644--- a/src/common/transformations/tests/smart_reshape/reshape_sinking.cpp+++ b/src/common/transformations/tests/smart_reshape/reshape_sinking.cpp@@ -11,6 +11,7 @@#include "openvino/op/reshape.hpp"#include "openvino/opsets/opset9_decl.hpp"+namespace v0 = ov::op::v0;struct ReshapeSinkingAttributes {ov::element::Type_t data_et;ov::PartialShape input_shape;@@ -33,7 +34,7 @@ TEST_P(ReshapeSinkingTest, ReshapeSinkingOnlyMatMul) {auto reshape = std::make_shared<ov::opset9::Reshape>(parameter, create_constant(p.output_pattern), false);auto matmul =std::make_shared<ov::opset9::MatMul>(reshape,- ov::op::v0::Constant::create(p.data_et, p.mm_second_input_shape, {0}),+ v0::Constant::create(p.data_et, p.mm_second_input_shape, {0}),p.transpose_a,p.transpose_b);auto reshape_back =@@ -55,10 +56,10 @@ TEST_P(ReshapeSinkingTestWithAdd, ReshapeSinkingMatMulAdd) {auto reshape = std::make_shared<ov::opset9::Reshape>(parameter, create_constant(p.output_pattern), false);auto matmul =std::make_shared<ov::opset9::MatMul>(reshape,- ov::op::v0::Constant::create(p.data_et, p.mm_second_input_shape, {0}),+ v0::Constant::create(p.data_et, p.mm_second_input_shape, {0}),p.transpose_a,p.transpose_b);- auto add = std::make_shared<ov::opset9::Add>(matmul, ov::op::v0::Constant::create(p.data_et, {1, 37}, {0}));+ auto add = std::make_shared<ov::opset9::Add>(matmul, v0::Constant::create(p.data_et, {1, 37}, {0}));auto reshape_back = std::make_shared<ov::opset9::Reshape>(add, create_constant(p.output_pattern_back), false);model = std::make_shared<ov::Model>(ov::OutputVector{reshape_back}, ov::ParameterVector{parameter});}diff --git a/src/common/transformations/tests/symbolic_transformations/chained_maximum.cpp b/src/common/transformations/tests/symbolic_transformations/chained_maximum.cppindex 3d6f6f62db8..f89dbf35886 100644--- a/src/common/transformations/tests/symbolic_transformations/chained_maximum.cpp+++ b/src/common/transformations/tests/symbolic_transformations/chained_maximum.cpp@@ -15,9 +15,11 @@#include "transformations/symbolic_transformations/symbolic_optimizations.hpp"using namespace ov;-using namespace ov::op;using namespace std;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;TEST_F(TransformationTestsF, ChainedMaximumAC) {// A == C// Maximum(Maximum(A, B), C) -> Maximum(B, C)diff --git a/src/common/transformations/tests/symbolic_transformations/dereshape_fullyconnected.cpp b/src/common/transformations/tests/symbolic_transformations/dereshape_fullyconnected.cppindex 2bd2f02fc85..7b00aa9064f 100644--- a/src/common/transformations/tests/symbolic_transformations/dereshape_fullyconnected.cpp+++ b/src/common/transformations/tests/symbolic_transformations/dereshape_fullyconnected.cpp@@ -16,9 +16,11 @@#include "transformations/utils/utils.hpp"using namespace ov;-using namespace ov::op;using namespace std;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;TEST_F(TransformationTestsF, DeReshapeFC) {auto shape = PartialShape{-1, -1, 40};set_shape_symbols(shape); // we label shape with consecutive labels: A, B, C@@ -30,7 +32,7 @@ TEST_F(TransformationTestsF, DeReshapeFC) {auto matmul = make_shared<v0::MatMul>(in_reshape, second_input);- auto batch_dims = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(data, {0, 1});+ auto batch_dims = op_util::node_to_get_shape_value_of_indices_from_shape_source(data, {0, 1});auto pattern =make_shared<v0::Concat>(OutputVector{batch_dims, v0::Constant::create(element::i64, {1}, {80})}, 0);auto out_reshape = make_shared<v1::Reshape>(matmul, pattern, false);@@ -58,7 +60,7 @@ TEST_F(TransformationTestsF, DeReshapeFCWithConvert) {auto matmul = make_shared<v0::MatMul>(convert, second_input);- auto batch_dims = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(data, {0, 1});+ auto batch_dims = op_util::node_to_get_shape_value_of_indices_from_shape_source(data, {0, 1});auto pattern =make_shared<v0::Concat>(OutputVector{batch_dims, v0::Constant::create(element::i64, {1}, {80})}, 0);auto out_reshape = make_shared<v1::Reshape>(matmul, pattern, false);diff --git a/src/common/transformations/tests/symbolic_transformations/dereshape_matmul.cpp b/src/common/transformations/tests/symbolic_transformations/dereshape_matmul.cppindex 5204b02821e..366cf9fe3c9 100644--- a/src/common/transformations/tests/symbolic_transformations/dereshape_matmul.cpp+++ b/src/common/transformations/tests/symbolic_transformations/dereshape_matmul.cpp@@ -21,9 +21,11 @@#include "transformations/utils/utils.hpp"using namespace ov;-using namespace ov::op;using namespace std;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace op_util = ov::op::util;namespace {/* Helps to organize dimension representation in the following tests:* 1. Creates requested amount of dimensions@@ -95,7 +97,7 @@ shared_ptr<Node> reshape(const Output<Node>& source,void get_dims(const ov::Output<ov::Node>& source, const size_t& from, const size_t& to, ov::NodeVector& dims) {std::vector<size_t> non_constant_ids;for (size_t i = from; i < to; ++i) {- auto node = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(source, {i});+ auto node = op_util::node_to_get_shape_value_of_indices_from_shape_source(source, {i});if (auto constant = ov::util::get_constant_from_source(node)) {node = constant;} else {@@ -118,20 +120,20 @@ ov::Output<ov::Node> get_target_shape_from_sources(const ov::Output<ov::Node>& bsize_t num_non_const_nodes = 0; // candidates for becoming a Constant -1 -- special value for Reshape patternfor (size_t curr_i = 0; curr_i + 1 < dims.size(); ++curr_i) {auto curr_node = dims[curr_i], next_node = dims[curr_i + 1];- bool curr_is_const = ov::op::util::is_constant(curr_node), next_is_const = ov::op::util::is_constant(next_node);+ bool curr_is_const = op_util::is_constant(curr_node), next_is_const = op_util::is_constant(next_node);if (num_non_const_nodes == 0 && !curr_is_const && next_is_const) {- curr_node = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});+ curr_node = v0::Constant::create(ov::element::i64, {1}, {-1});curr_is_const = true;num_non_const_nodes += 1;}if (num_non_const_nodes == 0 && !next_is_const && curr_is_const) {- next_node = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});+ next_node = v0::Constant::create(ov::element::i64, {1}, {-1});next_is_const = true;num_non_const_nodes += 1;}if (curr_is_const && next_is_const) {dims[curr_i] = nullptr;- dims[curr_i + 1] = ov::op::util::make_try_fold<ov::op::v0::Concat>(ov::NodeVector{curr_node, next_node}, 0);+ dims[curr_i + 1] = op_util::make_try_fold<v0::Concat>(ov::NodeVector{curr_node, next_node}, 0);}}dims.erase(std::remove_if(dims.begin(),@@ -140,7 +142,7 @@ ov::Output<ov::Node> get_target_shape_from_sources(const ov::Output<ov::Node>& breturn node == nullptr;}),dims.end());- auto target_shape = ov::op::util::make_try_fold<ov::op::v0::Concat>(dims, 0);+ auto target_shape = op_util::make_try_fold<v0::Concat>(dims, 0);return target_shape->output(0);}@@ -379,16 +381,13 @@ public:if (final_add_mode > 0) {const auto original_add_in = v0::Constant::create(element::f32, Shape(lhs_reshape_idx.size(), 1), {1});- auto divisor = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(lhs_input, {1});+ auto divisor = op_util::node_to_get_shape_value_of_indices_from_shape_source(lhs_input, {1});auto first_batch_dim =- std::make_shared<ov::op::v1::Divide>(ov::op::v0::Constant::create(element::i64, {1}, {1}),- divisor,- true);- auto minus_one = ov::op::v0::Constant::create(element::i64, {1}, {-1});- auto non_batch_dims = ov::op::v0::Constant::create(element::i64, {2}, {1, 1});- auto pattern =- std::make_shared<ov::op::v0::Concat>(OutputVector{first_batch_dim, minus_one, non_batch_dims}, 0);- auto other_input_reshape = op::util::make_try_fold<ov::op::v1::Reshape>(original_add_in, pattern, true);+ std::make_shared<v1::Divide>(v0::Constant::create(element::i64, {1}, {1}), divisor, true);+ auto minus_one = v0::Constant::create(element::i64, {1}, {-1});+ auto non_batch_dims = v0::Constant::create(element::i64, {2}, {1, 1});+ auto pattern = std::make_shared<v0::Concat>(OutputVector{first_batch_dim, minus_one, non_batch_dims}, 0);+ auto other_input_reshape = op::util::make_try_fold<v1::Reshape>(original_add_in, pattern, true);if (final_add_mode == 1) { // 1 - add has matmul on lhsmatmul = make_shared<v1::Add>(matmul, other_input_reshape);diff --git a/src/common/transformations/tests/symbolic_transformations/nop_broadcast.cpp b/src/common/transformations/tests/symbolic_transformations/nop_broadcast.cppindex 4d2b463095b..e2598ee63d2 100644--- a/src/common/transformations/tests/symbolic_transformations/nop_broadcast.cpp+++ b/src/common/transformations/tests/symbolic_transformations/nop_broadcast.cpp@@ -16,9 +16,11 @@#include "openvino/op/shape_of.hpp"using namespace ov;-using namespace ov::op;using namespace std;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;TEST_F(TransformationTestsF, NopBroadcastOpset1) {auto shape = PartialShape::dynamic(4);set_shape_symbols(shape); // we set unique symbols to the shape: A, B, C, D@@ -28,7 +30,7 @@ TEST_F(TransformationTestsF, NopBroadcastOpset1) {auto symbol_input = make_shared<v0::Parameter>(element::f32, shape);auto shape_of = make_shared<v3::ShapeOf>(symbol_input);- auto ones = ov::op::v0::Constant::create(element::i64, {}, {1});+ auto ones = v0::Constant::create(element::i64, {}, {1});auto maximum = make_shared<v1::Maximum>(shape_of, ones);auto broadcast = make_shared<v1::Broadcast>(data, maximum);@@ -56,7 +58,7 @@ TEST_F(TransformationTestsF, NopBroadcastOpset3) {auto symbol_input = make_shared<v0::Parameter>(element::f32, shape);auto shape_of = make_shared<v3::ShapeOf>(symbol_input);- auto ones = ov::op::v0::Constant::create(element::i64, {4}, {1, 1, 1, 1});+ auto ones = v0::Constant::create(element::i64, {4}, {1, 1, 1, 1});auto maximum = make_shared<v1::Maximum>(shape_of, ones);auto broadcast = make_shared<v3::Broadcast>(data, maximum);@@ -84,7 +86,7 @@ TEST_F(TransformationTestsF, NopBroadcastNegative) {auto symbol_input = make_shared<v0::Parameter>(element::f32, shape);auto shape_of = make_shared<v3::ShapeOf>(symbol_input);- auto ones = ov::op::v0::Constant::create(element::i64, {2}, {1, 1});+ auto ones = v0::Constant::create(element::i64, {2}, {1, 1});auto maximum = make_shared<v1::Maximum>(shape_of, ones);auto broadcast = make_shared<v1::Broadcast>(data, maximum);diff --git a/src/common/transformations/tests/symbolic_transformations/reshape_optimizations.cpp b/src/common/transformations/tests/symbolic_transformations/reshape_optimizations.cppindex fcad8e23309..783e784e7de 100644--- a/src/common/transformations/tests/symbolic_transformations/reshape_optimizations.cpp+++ b/src/common/transformations/tests/symbolic_transformations/reshape_optimizations.cpp@@ -18,9 +18,11 @@#include "openvino/op/shape_of.hpp"using namespace ov;-using namespace ov::op;using namespace std;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;TEST_F(TransformationTestsF, FlattenOptimization) {// [A, B, C, D] -> [A, B, C*D]@@ -31,14 +33,14 @@ TEST_F(TransformationTestsF, FlattenOptimization) {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, {2}, {0, 1});- auto axis = ov::op::v0::Constant::create(element::i64, {}, {0});+ auto indices = v0::Constant::create(element::i64, {2}, {0, 1});+ auto axis = v0::Constant::create(element::i64, {}, {0});auto as_is_dims = make_shared<v1::Gather>(shape_of, indices, axis);auto merged_dim = make_shared<v1::Multiply>(- make_shared<v1::Gather>(shape_of, ov::op::v0::Constant::create(element::i64, {1}, {2}), axis),- make_shared<v1::Gather>(shape_of, ov::op::v0::Constant::create(element::i64, {1}, {3}), axis));+ make_shared<v1::Gather>(shape_of, v0::Constant::create(element::i64, {1}, {2}), axis),+ make_shared<v1::Gather>(shape_of, v0::Constant::create(element::i64, {1}, {3}), axis));auto pattern = make_shared<v0::Concat>(OutputVector{as_is_dims, merged_dim}, 0);@@ -49,7 +51,7 @@ TEST_F(TransformationTestsF, FlattenOptimization) {}{auto data = make_shared<v0::Parameter>(element::f32, shape);- auto pattern = ov::op::v0::Constant::create(element::i64, {3}, {0, 0, -1});+ auto pattern = v0::Constant::create(element::i64, {3}, {0, 0, -1});auto reshape = make_shared<v1::Reshape>(data, pattern, true);@@ -67,11 +69,11 @@ TEST_F(TransformationTestsF, LastDimSplitStaticLast) {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 indices = v0::Constant::create(element::i64, {3}, {0, 1, 2});+ auto axis = 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 splited_dim = v0::Constant::create(element::i64, {2}, {-1, 8});auto pattern = make_shared<v0::Concat>(OutputVector{as_is_dims, splited_dim}, 0);@@ -82,7 +84,7 @@ TEST_F(TransformationTestsF, LastDimSplitStaticLast) {}{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 pattern = v0::Constant::create(element::i64, {5}, {0, 0, 0, -1, 8});auto reshape = make_shared<v1::Reshape>(data, pattern, true);@@ -100,11 +102,11 @@ TEST_F(TransformationTestsF, LastDimSplitDymanicLast) {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 indices = v0::Constant::create(element::i64, {3}, {0, 1, 2});+ auto axis = 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 splited_dim = v0::Constant::create(element::i64, {2}, {8, -1});auto pattern = make_shared<v0::Concat>(OutputVector{as_is_dims, splited_dim}, 0);@@ -115,7 +117,7 @@ TEST_F(TransformationTestsF, LastDimSplitDymanicLast) {}{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 pattern = v0::Constant::create(element::i64, {5}, {0, 0, 0, 8, -1});auto reshape = make_shared<v1::Reshape>(data, pattern, true);@@ -132,14 +134,14 @@ TEST_F(TransformationTestsF, NegativeTest) {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 indices = v0::Constant::create(element::i64, {3}, {0, 1, 2});+ auto axis = 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 D = make_shared<v1::Gather>(shape_of, v0::Constant::create(element::i64, {1}, {3}), axis);+ auto D_2 = make_shared<v1::Divide>(D, v0::Constant::create(element::i64, {}, {2}));+ auto D_3 = make_shared<v1::Divide>(D, v0::Constant::create(element::i64, {}, {3}));+ auto six = v0::Constant::create(element::i64, {1}, {6});auto pattern = make_shared<v0::Concat>(OutputVector{as_is_dims, D_2, D_3, six}, 0);@@ -157,11 +159,11 @@ TEST_F(TransformationTestsF, ZeroDimsInOutputShape) {auto data = make_shared<v0::Parameter>(element::f32, shape);auto b = make_shared<v0::Parameter>(element::f32, PartialShape{-1});- auto a = ov::op::v0::Constant::create(element::i64, Shape{1}, {0});+ auto a = v0::Constant::create(element::i64, Shape{1}, {0});auto shape_of = make_shared<v3::ShapeOf>(b);- auto indices = ov::op::v0::Constant::create(element::i64, {1}, {0});- auto axis = ov::op::v0::Constant::create(element::i64, {}, {0});+ auto indices = v0::Constant::create(element::i64, {1}, {0});+ auto axis = v0::Constant::create(element::i64, {}, {0});auto b_dim = make_shared<v1::Gather>(shape_of, indices, axis);auto pattern = make_shared<v0::Concat>(OutputVector{a, b_dim}, 0);diff --git a/src/common/transformations/tests/symbolic_transformations/symbol_optimization.cpp b/src/common/transformations/tests/symbolic_transformations/symbol_optimization.cppindex d80d69c6e50..a8f7459034f 100644--- a/src/common/transformations/tests/symbolic_transformations/symbol_optimization.cpp+++ b/src/common/transformations/tests/symbolic_transformations/symbol_optimization.cpp@@ -22,9 +22,13 @@#include "transformations/symbolic_transformations/utils.hpp"using namespace ov;-using namespace ov::op;using namespace std;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v3 = ov::op::v3;+namespace v4 = ov::op::v4;+namespace v8 = ov::op::v8;TEST(TransformationTests, ApplySymbolEquivalence_Concat) {auto input_1 = make_shared<v0::Parameter>(element::f32, PartialShape::dynamic(4));auto input_2 = make_shared<v0::Parameter>(element::f32, PartialShape::dynamic(4));diff --git a/src/common/transformations/tests/transpose_sinking/ts_common_test.cpp b/src/common/transformations/tests/transpose_sinking/ts_common_test.cppindex b689292c5ea..7e02c73aefa 100644--- a/src/common/transformations/tests/transpose_sinking/ts_common_test.cpp+++ b/src/common/transformations/tests/transpose_sinking/ts_common_test.cpp@@ -28,6 +28,8 @@ using namespace ov::pass::transpose_sinking;using namespace transpose_sinking::testing;using namespace transpose_sinking::testing::utils;+namespace v0 = ov::op::v0;+namespace v8 = ov::op::v8;namespace transpose_sinking {namespace testing {namespace common {@@ -1697,9 +1699,9 @@ TEST_F(TransformationTestsF, TransposeSinkingCommonReshapeUnsqueezeBackwardSameSauto X = std::make_shared<Parameter>(element::f32, input_shape);auto transpose = create_transpose(X);auto reshape_const = std::make_shared<Constant>(element::u64, Shape{3}, Shape{4, 5, 6});- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);auto indices = std::make_shared<Constant>(element::i32, Shape{3}, Shape{1, 0, 2});- auto gather = std::make_shared<ov::op::v8::Gather>(reshape_const, indices, axis);+ auto gather = std::make_shared<v8::Gather>(reshape_const, indices, axis);auto reshape = std::make_shared<Reshape>(transpose, gather, false);model_ref = std::make_shared<Model>(ov::OutputVector{reshape}, ov::ParameterVector{X});}@@ -1744,9 +1746,9 @@ TEST_F(TransformationTestsF, TransposeSinkingCommonReshapeUnsqueezeForwardSameSh{auto X = std::make_shared<Parameter>(element::f32, input_shape);auto reshape_const = std::make_shared<Constant>(element::u64, Shape{4}, Shape{5, 7, 4, 6});- auto axis = std::make_shared<ov::op::v0::Constant>(element::i32, Shape{}, 0);+ auto axis = std::make_shared<v0::Constant>(element::i32, Shape{}, 0);auto indices = std::make_shared<Constant>(element::i32, Shape{4}, Shape{2, 0, 3, 1});- auto gather = std::make_shared<ov::op::v8::Gather>(reshape_const, indices, axis);+ auto gather = std::make_shared<v8::Gather>(reshape_const, indices, axis);auto reshape = std::make_shared<Reshape>(X, gather, false);auto transpose = create_transpose(reshape);model_ref = std::make_shared<Model>(ov::OutputVector{transpose}, ov::ParameterVector{X});diff --git a/src/common/transformations/tests/utils/convert_precision.cpp b/src/common/transformations/tests/utils/convert_precision.cppindex fea219d5e2e..c6d782f2b40 100644--- a/src/common/transformations/tests/utils/convert_precision.cpp+++ b/src/common/transformations/tests/utils/convert_precision.cpp@@ -85,6 +85,10 @@ using namespace testing;using namespace ov;using namespace std;+namespace v0 = ov::op::v0;+namespace v1 = ov::op::v1;+namespace v4 = ov::op::v4;+namespace op_util = ov::op::util;template <element::Type_t T>bool has_type(std::shared_ptr<Model> f) {for (auto& node : f->get_ordered_ops()) {@@ -360,17 +364,17 @@ TEST(TransformationTests, ConvertPrecision_Range) {TEST(TransformationTests, ConvertPrecision_Range_i32_to_i64) {std::shared_ptr<Model> model;{- auto param = std::make_shared<ov::op::v0::Parameter>(element::i64, Shape{1});- auto reduction_axes = ov::op::v0::Constant::create(element::i32, {1}, {0});- auto stop = std::make_shared<ov::op::v1::ReduceMax>(param, reduction_axes);- auto start = ov::op::v0::Constant::create(element::i32, Shape{}, {0});- auto step = ov::op::v0::Constant::create(element::i32, {}, {1});- auto range = std::make_shared<ov::op::v4::Range>(start, stop, step, element::i64);- auto target_shape = ov::op::v0::Constant::create(element::i64, {2}, {1, -1});- auto reshape = std::make_shared<ov::op::v1::Reshape>(range, target_shape, false);- auto add_const = ov::op::v0::Constant::create(element::i64, {1, 1}, {1});- auto add = std::make_shared<ov::op::v1::Add>(reshape, add_const);- auto res = std::make_shared<ov::op::v0::Result>(add);+ auto param = std::make_shared<v0::Parameter>(element::i64, Shape{1});+ auto reduction_axes = v0::Constant::create(element::i32, {1}, {0});+ auto stop = std::make_shared<v1::ReduceMax>(param, reduction_axes);+ auto start = v0::Constant::create(element::i32, Shape{}, {0});+ auto step = v0::Constant::create(element::i32, {}, {1});+ auto range = std::make_shared<v4::Range>(start, stop, step, element::i64);+ auto target_shape = v0::Constant::create(element::i64, {2}, {1, -1});+ auto reshape = std::make_shared<v1::Reshape>(range, target_shape, false);+ auto add_const = v0::Constant::create(element::i64, {1, 1}, {1});+ auto add = std::make_shared<v1::Add>(reshape, add_const);+ auto res = std::make_shared<v0::Result>(add);ov::disable_fp16_compression(start);ov::disable_fp16_compression(reduction_axes);@@ -392,17 +396,17 @@ TEST(TransformationTests, ConvertPrecision_Range_i32_to_i64) {std::shared_ptr<Model> model_ref;{- auto param = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{1});- auto reduction_axes = ov::op::v0::Constant::create(element::i32, {1}, {0});- auto stop = std::make_shared<ov::op::v1::ReduceMax>(param, reduction_axes);- auto start = ov::op::v0::Constant::create(element::i32, Shape{}, {0});- auto step = ov::op::v0::Constant::create(element::i32, {}, {1});- auto range = std::make_shared<ov::op::v4::Range>(start, stop, step, element::i32);- auto target_shape = ov::op::v0::Constant::create(element::i32, {2}, {1, -1});- auto reshape = std::make_shared<ov::op::v1::Reshape>(range, target_shape, false);- auto add_const = ov::op::v0::Constant::create(element::i32, {1, 1}, {1});- auto add = std::make_shared<ov::op::v1::Add>(reshape, add_const);- auto res = std::make_shared<ov::op::v0::Result>(add);+ auto param = std::make_shared<v0::Parameter>(element::i32, Shape{1});+ auto reduction_axes = v0::Constant::create(element::i32, {1}, {0});+ auto stop = std::make_shared<v1::ReduceMax>(param, reduction_axes);+ auto start = v0::Constant::create(element::i32, Shape{}, {0});+ auto step = v0::Constant::create(element::i32, {}, {1});+ auto range = std::make_shared<v4::Range>(start, stop, step, element::i32);+ auto target_shape = v0::Constant::create(element::i32, {2}, {1, -1});+ auto reshape = std::make_shared<v1::Reshape>(range, target_shape, false);+ auto add_const = v0::Constant::create(element::i32, {1, 1}, {1});+ auto add = std::make_shared<v1::Add>(reshape, add_const);+ auto res = std::make_shared<v0::Result>(add);model_ref = std::make_shared<Model>(OutputVector{res}, ParameterVector{param});}const auto fc = FunctionsComparator::with_default()@@ -2135,9 +2139,9 @@ TEST(TransformationTests, Convert_Precision_If_Body) {auto else_res = else_body->get_results()[0];auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f32, ov::Shape{1, 112, 112, 24});- auto cond = std::make_shared<ov::op::v0::Constant>(element::boolean, Shape{1}, true);+ auto cond = std::make_shared<v0::Constant>(element::boolean, Shape{1}, true);auto if_op = std::make_shared<ov::opset8::If>(cond);- auto if_result = std::make_shared<ov::op::v0::Result>(if_op);+ auto if_result = std::make_shared<v0::Result>(if_op);if_op->set_then_body(then_body);if_op->set_else_body(else_body);@@ -2164,9 +2168,9 @@ TEST(TransformationTests, Convert_Precision_If_Body) {auto else_res = else_body->get_results()[0];auto input = std::make_shared<ov::opset8::Parameter>(ov::element::f16, ov::Shape{1, 112, 112, 24});- auto cond = std::make_shared<ov::op::v0::Constant>(element::boolean, Shape{1}, true);+ auto cond = std::make_shared<v0::Constant>(element::boolean, Shape{1}, true);auto if_op = std::make_shared<ov::opset8::If>(cond);- auto if_result = std::make_shared<ov::op::v0::Result>(if_op);+ auto if_result = std::make_shared<v0::Result>(if_op);if_op->set_then_body(then_body);if_op->set_else_body(else_body);@@ -2688,15 +2692,15 @@ TEST(TransformationTests, align_mixed_fp16_fp32_with_parameter_for_shape_1) {shared_ptr<Model> model, model_ref;pass::Manager manager;{- auto input_1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto shape_input = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2});+ auto input_1 = make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto shape_input = make_shared<v0::Parameter>(element::f32, Shape{2});- auto upscale_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {2.0f});- auto mul_1 = make_shared<ov::op::v1::Multiply>(shape_input, upscale_const);- auto axis_const = ov::op::v0::Constant::create(element::i64, Shape{1}, {0});- auto final_float_shape = make_shared<ov::op::v1::ReduceProd>(mul_1, axis_const, true);- auto final_int_shape = make_shared<ov::op::v0::Convert>(final_float_shape, element::i64);- auto reshape_1 = make_shared<ov::op::v1::Reshape>(input_1, final_int_shape, false);+ auto upscale_const = v0::Constant::create(element::f32, Shape{1}, {2.0f});+ auto mul_1 = make_shared<v1::Multiply>(shape_input, upscale_const);+ auto axis_const = v0::Constant::create(element::i64, Shape{1}, {0});+ auto final_float_shape = make_shared<v1::ReduceProd>(mul_1, axis_const, true);+ auto final_int_shape = make_shared<v0::Convert>(final_float_shape, element::i64);+ auto reshape_1 = make_shared<v1::Reshape>(input_1, final_int_shape, false);model = make_shared<Model>(OutputVector{reshape_1}, ParameterVector{input_1, shape_input});@@ -2709,16 +2713,16 @@ TEST(TransformationTests, align_mixed_fp16_fp32_with_parameter_for_shape_1) {}{- auto input_1 = make_shared<ov::op::v0::Parameter>(element::f16, Shape{1, 3, 224, 224});- auto shape_input = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2});+ auto input_1 = make_shared<v0::Parameter>(element::f16, Shape{1, 3, 224, 224});+ auto shape_input = make_shared<v0::Parameter>(element::f32, Shape{2});// even for FP16 compressed model shape subgraph should be kept in fp32- auto upscale_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {2.0f});- auto mul_1 = make_shared<ov::op::v1::Multiply>(shape_input, upscale_const);- auto axis_const = ov::op::v0::Constant::create(element::i64, Shape{1}, {0});- auto final_float_shape = make_shared<ov::op::v1::ReduceProd>(mul_1, axis_const, true);- auto final_int_shape = make_shared<ov::op::v0::Convert>(final_float_shape, element::i64);- auto reshape_1 = make_shared<ov::op::v1::Reshape>(input_1, final_int_shape, false);+ auto upscale_const = v0::Constant::create(element::f32, Shape{1}, {2.0f});+ auto mul_1 = make_shared<v1::Multiply>(shape_input, upscale_const);+ auto axis_const = v0::Constant::create(element::i64, Shape{1}, {0});+ auto final_float_shape = make_shared<v1::ReduceProd>(mul_1, axis_const, true);+ auto final_int_shape = make_shared<v0::Convert>(final_float_shape, element::i64);+ auto reshape_1 = make_shared<v1::Reshape>(input_1, final_int_shape, false);model_ref = make_shared<Model>(OutputVector{reshape_1}, ParameterVector{input_1, shape_input});}@@ -2731,15 +2735,15 @@ TEST(TransformationTests, align_mixed_fp16_fp32_with_parameter_for_shape_2) {shared_ptr<Model> model, model_ref;pass::Manager manager;{- auto input_1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto shape_input = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2});+ auto input_1 = make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto shape_input = make_shared<v0::Parameter>(element::f32, Shape{2});- auto upscale_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {2.0f});- auto mul_1 = make_shared<ov::op::v1::Multiply>(shape_input, upscale_const);- auto axis_const = ov::op::v0::Constant::create(element::i64, Shape{1}, {0});- auto final_float_shape = make_shared<ov::op::v1::ReduceProd>(mul_1, axis_const, true);- auto final_int_shape = make_shared<ov::op::v0::Convert>(final_float_shape, element::i64);- auto reshape_1 = make_shared<ov::op::v1::Reshape>(input_1, final_int_shape, false);+ auto upscale_const = v0::Constant::create(element::f32, Shape{1}, {2.0f});+ auto mul_1 = make_shared<v1::Multiply>(shape_input, upscale_const);+ auto axis_const = v0::Constant::create(element::i64, Shape{1}, {0});+ auto final_float_shape = make_shared<v1::ReduceProd>(mul_1, axis_const, true);+ auto final_int_shape = make_shared<v0::Convert>(final_float_shape, element::i64);+ auto reshape_1 = make_shared<v1::Reshape>(input_1, final_int_shape, false);model = make_shared<Model>(OutputVector{reshape_1}, ParameterVector{input_1, shape_input});@@ -2754,18 +2758,18 @@ TEST(TransformationTests, align_mixed_fp16_fp32_with_parameter_for_shape_2) {}{- auto input_1 = make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 224, 224});- auto convert_to_f16 = make_shared<ov::op::v0::Convert>(input_1, element::f16);- auto shape_input = make_shared<ov::op::v0::Parameter>(element::f32, Shape{2});+ auto input_1 = make_shared<v0::Parameter>(element::f32, Shape{1, 3, 224, 224});+ auto convert_to_f16 = make_shared<v0::Convert>(input_1, element::f16);+ auto shape_input = make_shared<v0::Parameter>(element::f32, Shape{2});// even for FP16 compressed model shape subgraph should be kept in fp32- auto upscale_const = ov::op::v0::Constant::create(element::f32, Shape{1}, {2.0f});- auto mul_1 = make_shared<ov::op::v1::Multiply>(shape_input, upscale_const);- auto axis_const = ov::op::v0::Constant::create(element::i64, Shape{1}, {0});- auto final_float_shape = make_shared<ov::op::v1::ReduceProd>(mul_1, axis_const, true);- auto final_int_shape = make_shared<ov::op::v0::Convert>(final_float_shape, element::i64);- auto reshape_1 = make_shared<ov::op::v1::Reshape>(convert_to_f16, final_int_shape, false);- auto convert_to_f32 = make_shared<ov::op::v0::Convert>(reshape_1, element::f32);+ auto upscale_const = v0::Constant::create(element::f32, Shape{1}, {2.0f});+ auto mul_1 = make_shared<v1::Multiply>(shape_input, upscale_const);+ auto axis_const = v0::Constant::create(element::i64, Shape{1}, {0});+ auto final_float_shape = make_shared<v1::ReduceProd>(mul_1, axis_const, true);+ auto final_int_shape = make_shared<v0::Convert>(final_float_shape, element::i64);+ auto reshape_1 = make_shared<v1::Reshape>(convert_to_f16, final_int_shape, false);+ auto convert_to_f32 = make_shared<v0::Convert>(reshape_1, element::f32);model_ref = make_shared<Model>(OutputVector{convert_to_f32}, ParameterVector{input_1, shape_input});}@@ -2779,8 +2783,8 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_orig_typespass::Manager manager;{- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f32, "variable_name"});+ auto variable = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f32, "variable_name"});auto input = make_shared<opset10::Parameter>(element::f32, Shape{10, 10});auto read_value = make_shared<opset10::ReadValue>(input, variable);@@ -2803,8 +2807,8 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_orig_types}{- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f32, "variable_name"});+ auto variable = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f32, "variable_name"});auto input = make_shared<opset10::Parameter>(element::f32, Shape{10, 10});auto convert_1 = make_shared<opset10::Convert>(input, element::f16);@@ -2834,8 +2838,8 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_change_variable_typpass::Manager manager;{- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f32, "variable_name"});+ auto variable = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f32, "variable_name"});auto input = make_shared<opset10::Parameter>(element::f32, Shape{10, 10});auto read_value = make_shared<opset10::ReadValue>(input, variable);@@ -2858,8 +2862,8 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_change_variable_typ}{- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f16, "variable_name"});+ auto variable = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f16, "variable_name"});auto input = make_shared<opset10::Parameter>(element::f16, Shape{10, 10});auto read_value = make_shared<opset10::ReadValue>(input, variable);@@ -2882,8 +2886,8 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_orig_typespass::Manager manager;{- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f32, "variable_name"});+ auto variable = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f32, "variable_name"});auto input = make_shared<opset10::Parameter>(element::f32, Shape{10, 10});auto read_value = make_shared<opset10::ReadValue>(input, variable);@@ -2910,8 +2914,8 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_orig_types}{- auto variable = std::make_shared<ov::op::util::Variable>(- ov::op::util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f16, "variable_name"});+ auto variable = std::make_shared<op_util::Variable>(+ op_util::VariableInfo{ov::PartialShape{10, 10}, ov::element::f16, "variable_name"});auto input = make_shared<opset10::Parameter>(element::f32, Shape{10, 10});auto convert_1 = make_shared<opset10::Convert>(input, element::f16);@@ -2941,7 +2945,7 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_weightlessov::ParameterVector inputParams;ov::ResultVector results;- results.push_back(std::make_shared<ov::op::v0::Result>(some_value->output(0)));+ results.push_back(std::make_shared<v0::Result>(some_value->output(0)));auto model = std::make_shared<ov::Model>(results, inputParams);type_to_fuse_map empty_type_to_fuse_map = {};@@ -2957,7 +2961,7 @@ TEST(TransformationTests, ConvertPrecision_assign_read_value_preserve_weightlessconst auto& ops = model->get_ops();auto it = std::find_if(ops.begin(), ops.end(), [](const std::shared_ptr<Node>& node) {- return ov::op::util::is_constant(node);+ return op_util::is_constant(node);});ASSERT_TRUE(it != ops.end());diff --git a/src/common/transformations/tests/utils/utils_test.cpp b/src/common/transformations/tests/utils/utils_test.cppindex 0c30d465cc2..98d941db00d 100644--- a/src/common/transformations/tests/utils/utils_test.cpp+++ b/src/common/transformations/tests/utils/utils_test.cpp@@ -14,6 +14,7 @@using namespace ov;+namespace op_util = ov::op::util;namespace ov {namespace op {namespace util {@@ -47,30 +48,30 @@ bool has_constant_value<bool>(const std::shared_ptr<Node>& node, const bool valuTEST(TransformationTests, HasConstantValueHelper) {auto float32_scalar = opset4::Constant::create(element::f32, Shape{}, {1.234f});- ASSERT_TRUE(ov::op::util::has_constant_value<float>(float32_scalar, 1.234f));- ASSERT_TRUE(ov::op::util::has_constant_value<float>(float32_scalar, 1.23f, 0.005f));- ASSERT_FALSE(ov::op::util::has_constant_value<float>(float32_scalar, 1.23f, 0.003f));+ ASSERT_TRUE(op_util::has_constant_value<float>(float32_scalar, 1.234f));+ ASSERT_TRUE(op_util::has_constant_value<float>(float32_scalar, 1.23f, 0.005f));+ ASSERT_FALSE(op_util::has_constant_value<float>(float32_scalar, 1.23f, 0.003f));auto float32_1D = opset4::Constant::create(element::f32, Shape{1}, {1.234f});- ASSERT_TRUE(ov::op::util::has_constant_value<float>(float32_scalar, 1.234f));+ ASSERT_TRUE(op_util::has_constant_value<float>(float32_scalar, 1.234f));auto int64_scalar = opset4::Constant::create(element::i64, Shape{}, {12});- ASSERT_TRUE(ov::op::util::has_constant_value<int64_t>(int64_scalar, 12));+ ASSERT_TRUE(op_util::has_constant_value<int64_t>(int64_scalar, 12));auto bool_scalar = opset4::Constant::create(element::boolean, Shape{}, {true});- ASSERT_TRUE(ov::op::util::has_constant_value<bool>(bool_scalar, true));+ ASSERT_TRUE(op_util::has_constant_value<bool>(bool_scalar, true));- ASSERT_FALSE(ov::op::util::has_constant_value<int8_t>(nullptr, 0));+ ASSERT_FALSE(op_util::has_constant_value<int8_t>(nullptr, 0));auto float32_2D = opset4::Constant::create(element::f32, Shape{2}, {1.2f, 3.4f});- ASSERT_FALSE(ov::op::util::has_constant_value<float>(float32_2D, 1.2f));+ ASSERT_FALSE(op_util::has_constant_value<float>(float32_2D, 1.2f));float32_scalar = opset4::Constant::create(element::f32, Shape{}, {1.234f});- ASSERT_FALSE(ov::op::util::has_constant_value<float>(float32_scalar, 1.235f));+ ASSERT_FALSE(op_util::has_constant_value<float>(float32_scalar, 1.235f));float32_1D = opset4::Constant::create(element::f32, Shape{1}, {1.234f});- ASSERT_FALSE(ov::op::util::has_constant_value<float>(float32_scalar, 1.235f));+ ASSERT_FALSE(op_util::has_constant_value<float>(float32_scalar, 1.235f));int64_scalar = opset4::Constant::create(element::i64, Shape{}, {12});- ASSERT_FALSE(ov::op::util::has_constant_value<int64_t>(int64_scalar, 13));+ ASSERT_FALSE(op_util::has_constant_value<int64_t>(int64_scalar, 13));}