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
[CPU] MoEMatMulsFusion: added consumers number checks (#32805)
Vladislav Golubev5cdc470e7c48
diff --git a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/moe_matmuls_fusion.cpp b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/moe_matmuls_fusion.cppindex 57c6e0ba308..e62f377860c 100644--- a/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/moe_matmuls_fusion.cpp+++ b/src/plugins/intel_cpu/src/transformations/cpu_opset/common/pass/moe_matmuls_fusion.cpp@@ -62,36 +62,45 @@ ov::intel_cpu::MoE2GeMMFusion::MoE2GeMMFusion() {auto data_input = pattern::any_input(pattern::rank_equals(3) && pattern::has_static_rank());auto experts_input = pattern::wrap_type<ov::op::v1::Reshape>({data_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 tile =+ pattern::wrap_type<ov::op::v0::Tile>({experts_input, pattern::any_input()}, pattern::consumers_count(1));+ auto after_tile_reshape =+ pattern::wrap_type<ov::op::v1::Reshape>({tile, pattern::any_input()}, pattern::consumers_count(1));auto gate_up_matmul = pattern::wrap_type<ov::op::v0::MatMul>({after_tile_reshape, pattern::any_input()},+ pattern::consumers_count(1),{{"transpose_a", false}, {"transpose_b", true}});auto gate_up_bias = pattern::wrap_const();- auto gate_up_add = pattern::wrap_type<ov::op::v1::Add>({gate_up_matmul, gate_up_bias});+ auto gate_up_add = pattern::wrap_type<ov::op::v1::Add>({gate_up_matmul, gate_up_bias}, pattern::consumers_count(2));// Branch 1: Slice_1 -> Clamp -> Add_1auto 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()});+ {gate_up_add, pattern::any_input(), pattern::any_input(), pattern::any_input(), pattern::any_input()},+ pattern::consumers_count(1));+ auto clamp = pattern::wrap_type<ov::op::v0::Clamp>({slice1}, pattern::consumers_count(1));+ auto add1 = pattern::wrap_type<ov::op::v1::Add>({clamp, pattern::wrap_const()}, pattern::consumers_count(1));// Branch 2: Slice_2 -> Minimum_1 -> Swishauto 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()});+ {gate_up_add, pattern::any_input(), pattern::any_input(), pattern::any_input(), pattern::any_input()},+ pattern::consumers_count(1));+ auto minimum1 =+ pattern::wrap_type<ov::op::v1::Minimum>({slice2, pattern::wrap_const()}, pattern::consumers_count(1));auto swish_beta = pattern::wrap_const();- auto swish = pattern::wrap_type<ov::op::v4::Swish>({minimum1, swish_beta});+ auto swish = pattern::wrap_type<ov::op::v4::Swish>({minimum1, swish_beta}, pattern::consumers_count(1));// Join: Multiply_2- auto multiply2 = pattern::wrap_type<ov::op::v1::Multiply>({add1, swish});+ auto multiply2 = pattern::wrap_type<ov::op::v1::Multiply>({add1, swish}, pattern::consumers_count(1));// Down projectionauto down_proj_matmul = pattern::wrap_type<ov::op::v0::MatMul>({multiply2, pattern::any_input()},+ pattern::consumers_count(1),{{"transpose_a", false}, {"transpose_b", true}});auto down_proj_bias = pattern::wrap_const();- auto down_proj_add = pattern::wrap_type<ov::op::v1::Add>({down_proj_matmul, down_proj_bias});+ auto down_proj_add =+ pattern::wrap_type<ov::op::v1::Add>({down_proj_matmul, down_proj_bias}, pattern::consumers_count(1));auto end_reshape_target_shape = pattern::any_input();- auto end_reshape = pattern::wrap_type<ov::op::v1::Reshape>({down_proj_add, end_reshape_target_shape});+ auto end_reshape =+ pattern::wrap_type<ov::op::v1::Reshape>({down_proj_add, end_reshape_target_shape}, pattern::consumers_count(1));// Routing weights/maskauto zero_constant = pattern::wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"));@@ -123,8 +132,11 @@ ov::intel_cpu::MoE2GeMMFusion::MoE2GeMMFusion() {auto unsqueeze_routing_weights =pattern::optional<ov::op::v0::Unsqueeze>({router_reshape, unsqueeze_axis}, ov::pass::pattern::rank_equals(4));- 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<ov::op::v1::Multiply>({end_reshape, unsqueeze_routing_weights}, pattern::consumers_count(1));+ auto reduce_sum = pattern::wrap_type<ov::op::v1::ReduceSum>({mul3, pattern::any_input()},+ pattern::consumers_count(1),+ {{"keep_dims", false}});ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -153,23 +165,33 @@ ov::intel_cpu::MoE2GeMMFusion::MoE2GeMMFusion() {down_proj_mm_node->input_value(1),active_indices,down_proj_bias_node);+ ov::copy_runtime_info(down_proj_mm_node, down_gathered_mm);+ down_gathered_mm->set_friendly_name(down_proj_mm_node->get_friendly_name());+const auto& chosen_experts_input = pattern_map.at(chosen_experts);const auto router_transpose_node = pattern_map.at(router_transpose).get_node_shared_ptr();const auto new_router_transpose =router_transpose_node->clone_with_new_inputs({chosen_experts_input, router_transpose_node->input_value(1)});+ ov::copy_runtime_info(router_transpose_node, new_router_transpose);+ new_router_transpose->set_friendly_name(router_transpose_node->get_friendly_name());const auto router_unsqueeze_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {-1});const auto router_unsqueeze =std::make_shared<ov::op::v0::Unsqueeze>(new_router_transpose, router_unsqueeze_const);+ ov::copy_runtime_info(router_transpose_node, {router_unsqueeze_const, router_unsqueeze});const auto final_mul_node = pattern_map.at(mul3).get_node_shared_ptr();const auto new_final_mul =final_mul_node->clone_with_new_inputs({down_gathered_mm->output(0), router_unsqueeze->output(0)});- ov::replace_node_update_name(final_mul_node, new_final_mul);+ ov::copy_runtime_info(final_mul_node, new_final_mul);+ new_final_mul->set_friendly_name(final_mul_node->get_friendly_name());- validate_nodes(pattern_map, {reduce_sum});+ const auto reduce_sum_node = pattern_map.at(reduce_sum).get_node_shared_ptr();+ const auto new_reduce_sum =+ reduce_sum_node->clone_with_new_inputs({new_final_mul->output(0), reduce_sum_node->input_value(1)});+ ov::copy_runtime_info(reduce_sum_node, new_reduce_sum);+ new_reduce_sum->set_friendly_name(reduce_sum_node->get_friendly_name());- const auto& reduce_sum_out = pattern_map.at(reduce_sum);const auto& end_reshape_out = pattern_map.at(end_reshape);const auto end_reshape_rank = end_reshape_out.get_partial_shape().rank();const auto& end_reshape_shape = pattern_map.at(end_reshape_target_shape);@@ -180,10 +202,17 @@ ov::intel_cpu::MoE2GeMMFusion::MoE2GeMMFusion() {ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {end_reshape_rank.get_length()}),ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1}),ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {0}));-- const auto reshape = std::make_shared<ov::op::v1::Reshape>(reduce_sum_out, slice, true);- ov::replace_output_update_name(reduce_sum_out, reshape->output(0));-+ ov::copy_runtime_info(end_reshape_out.get_node_shared_ptr(),+ {slice,+ slice->get_input_node_shared_ptr(1),+ slice->get_input_node_shared_ptr(2),+ slice->get_input_node_shared_ptr(3),+ slice->get_input_node_shared_ptr(4)});++ const auto reshape = std::make_shared<ov::op::v1::Reshape>(new_reduce_sum, slice, true);+ ov::replace_output_update_name(pattern_map.at(reduce_sum), reshape->output(0));+ // To avoid friendly name duplication+ reshape->set_friendly_name(reshape->get_friendly_name() + "_Reshape");return true;};@@ -197,24 +226,30 @@ ov::intel_cpu::MoE3GeMMFusion::MoE3GeMMFusion() {auto data_input = pattern::any_input(pattern::rank_equals(3) && pattern::has_static_rank());auto experts_input =pattern::wrap_type<ov::op::v1::Reshape>({data_input, pattern::any_input()}, pattern::rank_equals(2));- 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 tile =+ pattern::wrap_type<ov::op::v0::Tile>({experts_input, pattern::any_input()}, pattern::consumers_count(1));+ auto after_tile_reshape =+ pattern::wrap_type<ov::op::v1::Reshape>({tile, pattern::any_input()}, pattern::consumers_count(2));// First GEMM (activation gate)auto gate_matmul = pattern::wrap_type<ov::op::v0::MatMul>({after_tile_reshape, pattern::any_input()},+ pattern::consumers_count(1),{{"transpose_a", false}, {"transpose_b", true}});- auto swish = pattern::wrap_type<ov::op::v4::Swish>({gate_matmul});+ auto swish = pattern::wrap_type<ov::op::v4::Swish>({gate_matmul}, pattern::consumers_count(1));// Second GEMM (up_projection)auto up_matmul = pattern::wrap_type<ov::op::v0::MatMul>({after_tile_reshape, pattern::any_input()},+ pattern::consumers_count(1),{{"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<ov::op::v1::Multiply>({swish, up_matmul}, pattern::consumers_count(1));// Third GEMM (down_projection)auto down_matmul = pattern::wrap_type<ov::op::v0::MatMul>({swiglu, pattern::any_input()},+ pattern::consumers_count(1),{{"transpose_a", false}, {"transpose_b", true}});auto end_reshape_target_shape = pattern::any_input();- auto end_reshape = pattern::wrap_type<ov::op::v1::Reshape>({down_matmul, end_reshape_target_shape});+ auto end_reshape =+ pattern::wrap_type<ov::op::v1::Reshape>({down_matmul, end_reshape_target_shape}, pattern::consumers_count(1));auto zero_constant = pattern::wrap_type<ov::op::v0::Constant>(pattern::value_matches("0"));auto broadcasted_const = pattern::wrap_type<ov::op::v3::Broadcast>({zero_constant, pattern::any_input()}) |@@ -239,8 +274,11 @@ ov::intel_cpu::MoE3GeMMFusion::MoE3GeMMFusion() {auto unsqueeze_routing_weights =pattern::optional<ov::op::v0::Unsqueeze>({router_reshape, unsqueeze_axis}, ov::pass::pattern::rank_equals(4));- 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<ov::op::v1::Multiply>({end_reshape, unsqueeze_routing_weights}, pattern::consumers_count(1));+ auto reduce_sum = pattern::wrap_type<ov::op::v1::ReduceSum>({mul3, pattern::any_input()},+ pattern::consumers_count(1),+ {{"keep_dims", false}});ov::matcher_pass_callback callback = [=](ov::pass::pattern::Matcher& m) {const auto& pattern_map = m.get_pattern_value_map();@@ -265,23 +303,32 @@ ov::intel_cpu::MoE3GeMMFusion::MoE3GeMMFusion() {const auto down_gathered_mm =std::make_shared<BatchGatherMatmul>(pattern_map.at(swiglu), down_mm_node->input_value(1), active_indices);+ ov::copy_runtime_info(down_mm_node, down_gathered_mm);+ down_gathered_mm->set_friendly_name(down_mm_node->get_friendly_name());+const auto& chosen_experts_input = pattern_map.at(chosen_experts);const auto router_transpose_node = pattern_map.at(router_transpose).get_node_shared_ptr();const auto new_router_transpose =router_transpose_node->clone_with_new_inputs({chosen_experts_input, router_transpose_node->input_value(1)});+ ov::copy_runtime_info(router_transpose_node, new_router_transpose);+ new_router_transpose->set_friendly_name(router_transpose_node->get_friendly_name());const auto router_unsqueeze_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {-1});const auto router_unsqueeze =std::make_shared<ov::op::v0::Unsqueeze>(new_router_transpose, router_unsqueeze_const);+ ov::copy_runtime_info(router_transpose_node, {router_unsqueeze_const, router_unsqueeze});const auto final_mul_node = pattern_map.at(mul3).get_node_shared_ptr();const auto new_final_mul =final_mul_node->clone_with_new_inputs({down_gathered_mm->output(0), router_unsqueeze->output(0)});- ov::replace_node_update_name(final_mul_node, new_final_mul);-- validate_nodes(pattern_map, {reduce_sum});+ ov::copy_runtime_info(final_mul_node, new_final_mul);+ new_final_mul->set_friendly_name(final_mul_node->get_friendly_name());+ const auto reduce_sum_node = pattern_map.at(reduce_sum).get_node_shared_ptr();+ const auto new_reduce_sum =+ reduce_sum_node->clone_with_new_inputs({new_final_mul->output(0), reduce_sum_node->input_value(1)});+ ov::copy_runtime_info(reduce_sum_node, new_reduce_sum);+ new_reduce_sum->set_friendly_name(reduce_sum_node->get_friendly_name());- const auto& reduce_sum_out = pattern_map.at(reduce_sum);const auto& end_reshape_out = pattern_map.at(end_reshape);const auto end_reshape_rank = end_reshape_out.get_partial_shape().rank();const auto& end_reshape_shape = pattern_map.at(end_reshape_target_shape);@@ -292,9 +339,16 @@ ov::intel_cpu::MoE3GeMMFusion::MoE3GeMMFusion() {ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {end_reshape_rank.get_length()}),ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1}),ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {0}));-- const auto reshape = std::make_shared<ov::op::v1::Reshape>(reduce_sum_out, slice, true);- ov::replace_output_update_name(reduce_sum_out, reshape->output(0));+ ov::copy_runtime_info(end_reshape_out.get_node_shared_ptr(),+ {slice,+ slice->get_input_node_shared_ptr(1),+ slice->get_input_node_shared_ptr(2),+ slice->get_input_node_shared_ptr(3),+ slice->get_input_node_shared_ptr(4)});++ const auto reshape = std::make_shared<ov::op::v1::Reshape>(new_reduce_sum, slice, true);+ ov::replace_output_update_name(pattern_map.at(reduce_sum), reshape->output(0));+ reshape->set_friendly_name(new_reduce_sum->get_friendly_name() + "_Reshape");return true;};diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/arm/matmul_weights_decompression.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/arm/matmul_weights_decompression.cppindex 24a7e549cf8..d4cae2a80f9 100644--- a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/arm/matmul_weights_decompression.cpp+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/arm/matmul_weights_decompression.cpp@@ -12,6 +12,7 @@ namespace ov {namespace test {namespace {+using namespace ov::test::utils;const ov::AnyMap enable_dyn_quant_config_kleidiai = {ov::hint::dynamic_quantization_group_size(UINT64_MAX)};const std::vector<ov::test::ElementType> decompression_precisions = {ov::element::f32};diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/matmul_weights_decompression.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/matmul_weights_decompression.cppindex 616e140a40e..afcbc7701e1 100644--- a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/matmul_weights_decompression.cpp+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/matmul_weights_decompression.cpp@@ -3,6 +3,7 @@//#include "matmul_weights_decompression.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include "openvino/runtime/intel_cpu/properties.hpp"using namespace CPUTestUtils;@@ -43,8 +44,8 @@ std::shared_ptr<ov::Model> MatmulWeightsDecompression::initSubgraph(const ov::Paconst ov::element::Type decompression_precision,const ov::element::Type scale_precision,const bool transpose_weights,- const DecompressionType decompression_multiply_type,- const DecompressionType decompression_subtract_type,+ const ov::test::utils::DecompressionType decompression_multiply_type,+ const ov::test::utils::DecompressionType decompression_subtract_type,const bool reshape_on_decompression) {ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(data_precision, data_shape)};const auto weights_subgraph = initMatMulDecompressionSubgraph(weights_shape,diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/matmul_weights_decompression.hpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/matmul_weights_decompression.hppindex 1142c95e0e3..6613468ef3e 100644--- a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/matmul_weights_decompression.hpp+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/classes/matmul_weights_decompression.hpp@@ -4,7 +4,8 @@#include "common_test_utils/ov_tensor_utils.hpp"#include "shared_test_classes/base/ov_subgraph.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include "utils/cpu_test_utils.hpp"#include "utils/fusing_test_utils.hpp"@@ -45,8 +46,8 @@ typedef std::tuple<MatMulDecompressionShapeParams,ov::test::ElementType, // decompression precisionov::test::ElementType, // scale precisionbool, // transpose on weights- DecompressionType, // decompression multiply type- DecompressionType, // decompression subtract type+ ov::test::utils::DecompressionType, // decompression multiply type+ ov::test::utils::DecompressionType, // decompression subtract typebool, // reshape on decompression constantsov::AnyMap, // additional configfusingSpecificParams,@@ -68,8 +69,8 @@ protected:const ov::element::Type decompression_precision,const ov::element::Type scale_precision,const bool transpose_weights,- const DecompressionType decompression_multiply_type,- const DecompressionType decompression_subtract_type,+ const ov::test::utils::DecompressionType decompression_multiply_type,+ const ov::test::utils::DecompressionType decompression_subtract_type,const bool reshape_on_decompression);void SetUp() override;diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/matmul_weights_decompression.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/matmul_weights_decompression.cppindex e89c83e2b0e..2c2dc113192 100644--- a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/matmul_weights_decompression.cpp+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/matmul_weights_decompression.cpp@@ -4,12 +4,15 @@#include "custom/subgraph_tests/src/classes/matmul_weights_decompression.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"+using namespace CPUTestUtils;namespace ov {namespace test {namespace {+using namespace ov::test::utils;std::vector<ov::AnyMap> filter_additional_config_basic() {std::vector<ov::AnyMap> additional_config = {{ov::hint::dynamic_quantization_group_size(0)}};@@ -71,8 +74,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_basic,::testing::ValuesIn(decompression_precisions),::testing::Values(ov::element::dynamic),::testing::Values(true),- ::testing::Values(DecompressionType::full),- ::testing::Values(DecompressionType::full),+ ::testing::Values(ov::test::utils::DecompressionType::full),+ ::testing::Values(ov::test::utils::DecompressionType::full),// todo: zero points converted to fp32 for reshape == true case::testing::Values(false),::testing::ValuesIn(filter_additional_config_basic()),@@ -191,9 +194,10 @@ const std::vector<MatMulDecompressionShapeParams> input_shapes_corner_cases_amx};const std::vector<bool> transpose_weights = {true, false};-const std::vector<DecompressionType> decompression_subtract_type = {DecompressionType::full,- DecompressionType::scalar,- DecompressionType::empty};+const std::vector<ov::test::utils::DecompressionType> decompression_subtract_type = {+ ov::test::utils::DecompressionType::full,+ ov::test::utils::DecompressionType::scalar,+ ov::test::utils::DecompressionType::empty};const std::vector<bool> reshape_on_decompression = {true, false};const std::vector<ov::test::ElementType> decompression_precisions_corner_cases = {ov::element::f16, ov::element::f32};@@ -285,8 +289,8 @@ const std::vector<MatMulDecompressionShapeParams> input_shapes_basic_dyn_quant_uconst std::vector<ov::test::ElementType> weights_precisions_dyn_quant = {ov::element::u8, ov::element::u4};const std::vector<fusingSpecificParams> fusing_params_dyn_quant{emptyFusingSpec,- fusingBias, // bias is hanlded in separate code-path with post-ops- fusingSwish // max amount of post-op regs (which reduces available accum regs)+ fusingBias, // bias is hanlded in separate code-path with post-ops+ fusingSwish // max amount of post-op regs (which reduces available accum regs)};std::vector<ov::AnyMap> filter_additional_config_dyn_quant() {@@ -368,10 +372,8 @@ const std::vector<MatMulDecompressionShapeParams> input_shapes_scalar_scale = {};std::vector<ov::AnyMap> filter_additional_config_scalar_scale() {- std::vector<ov::AnyMap> additional_config = {- {{ov::hint::dynamic_quantization_group_size(0)}},- {{ov::hint::dynamic_quantization_group_size(16)}}- };+ std::vector<ov::AnyMap> additional_config = {{{ov::hint::dynamic_quantization_group_size(0)}},+ {{ov::hint::dynamic_quantization_group_size(16)}}};return additional_config;}@@ -390,7 +392,6 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulCompressedWeights_scalar_scale,::testing::Values(true)),MatmulWeightsDecompression::getTestCaseName);-const std::vector<MatMulDecompressionShapeParams> input_shapes_non_multiples_groups = {{{{}, {{4, 2, 8}}}, {8, 8}, 8lu},{{{}, {{1, 3, 192}}}, {192, 128}, 96lu},diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/moe.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/moe.cppindex 4c71b6d9ada..d09e3fe87a0 100644--- a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/moe.cpp+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/moe.cpp@@ -8,9 +8,10 @@#include <sstream>#include <vector>+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include "shared_test_classes/base/ov_subgraph.hpp"#include "shared_test_classes/subgraph/moe_builders.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"#include "utils/cpu_test_utils.hpp"#include "utils/fusing_test_utils.hpp"@@ -36,16 +37,16 @@ using MoeTestParams = std::tuple<MoePatternParams,ov::AnyMap>; // additional configusing MoeCompressedWeightsTestParams = std::tuple<MoePatternParams,- MoEType, // MoE builder type- ov::test::ElementType, // weights precision- ov::test::ElementType, // decompression precision- ov::test::ElementType, // scale precision- DecompressionType, // decompression multiply type- DecompressionType, // decompression subtract type- bool, // reshape on decompression constants- int, // decompression_group_size- ov::AnyMap, // additional config- bool>; // use_matmul_decompression_impl+ MoEType, // MoE builder type+ ov::test::ElementType, // weights precision+ ov::test::ElementType, // decompression precision+ ov::test::ElementType, // scale precision+ ov::test::utils::DecompressionType, // decompression multiply type+ ov::test::utils::DecompressionType, // decompression subtract type+ bool, // reshape on decompression constants+ int, // decompression_group_size+ ov::AnyMap, // additional config+ bool>; // use_matmul_decompression_implclass MoESubgraphTest : public testing::WithParamInterface<MoeTestParams>,virtual public SubgraphBaseTest,@@ -315,8 +316,8 @@ INSTANTIATE_TEST_SUITE_P(smoke_MoeCompressedWeights,::testing::ValuesIn(weights_precisions),::testing::ValuesIn(decompression_precisions),::testing::Values(ov::element::f32),- ::testing::Values(DecompressionType::full),- ::testing::Values(DecompressionType::full),+ ::testing::Values(ov::test::utils::DecompressionType::full),+ ::testing::Values(ov::test::utils::DecompressionType::full),::testing::Values(false), // reshape on decompression::testing::Values(16), // decompression group size::testing::ValuesIn(generate_additional_config()),diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/shared_matmul_weights_decompression.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/shared_matmul_weights_decompression.cppindex 60c3748664a..a640df40b94 100644--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/shared_matmul_weights_decompression.cpp+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/shared_matmul_weights_decompression.cpp@@ -3,6 +3,7 @@//#include "shared_test_classes/subgraph/shared_matmul_weights_decompression.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include "common_test_utils/test_constants.hpp"#include "internal_properties.hpp"@@ -31,7 +32,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulSharedCompressedWeights,::testing::ValuesIn(weights_precisions),::testing::ValuesIn(decompression_precisions),::testing::ValuesIn(transpose_weights),- ::testing::Values(DecompressionType::full),+ ::testing::Values(ov::test::utils::DecompressionType::full),::testing::Values(true),::testing::Values(additional_config)),SharedMatmulWeightsDecompression::getTestCaseName);@@ -48,7 +49,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_Model_Distribution_MatMulSharedCompressedWeights,::testing::ValuesIn(weights_precisions),::testing::ValuesIn(decompression_precisions),::testing::Values(true),- ::testing::Values(DecompressionType::full),+ ::testing::Values(ov::test::utils::DecompressionType::full),::testing::Values(true),::testing::Values(model_distribution_config)),SharedMatmulWeightsDecompression::getTestCaseName);diff --git a/src/plugins/intel_cpu/tests/unit/transformations/moe_matmuls_fusion_test.cpp b/src/plugins/intel_cpu/tests/unit/transformations/moe_matmuls_fusion_test.cppnew file mode 100644index 00000000000..f29e5f02606--- /dev/null+++ b/src/plugins/intel_cpu/tests/unit/transformations/moe_matmuls_fusion_test.cpp@@ -0,0 +1,859 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "transformations/cpu_opset/common/pass/moe_matmuls_fusion.hpp"++#include <gtest/gtest.h>++#include <memory>+#include <sstream>+#include <string>++#include "common_test_utils/node_builders/constant.hpp"+#include "common_test_utils/ov_test_utils.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"+#include "openvino/core/model.hpp"+#include "openvino/op/add.hpp"+#include "openvino/op/broadcast.hpp"+#include "openvino/op/clamp.hpp"+#include "openvino/op/concat.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/divide.hpp"+#include "openvino/op/gather.hpp"+#include "openvino/op/matmul.hpp"+#include "openvino/op/minimum.hpp"+#include "openvino/op/multiply.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/reduce_sum.hpp"+#include "openvino/op/reshape.hpp"+#include "openvino/op/result.hpp"+#include "openvino/op/scatter_elements_update.hpp"+#include "openvino/op/shape_of.hpp"+#include "openvino/op/slice.hpp"+#include "openvino/op/softmax.hpp"+#include "openvino/op/swish.hpp"+#include "openvino/op/tile.hpp"+#include "openvino/op/topk.hpp"+#include "openvino/op/transpose.hpp"+#include "openvino/op/unsqueeze.hpp"+#include "openvino/pass/manager.hpp"+#include "transformations/cpu_opset/common/op/batch_gather_matmul.hpp"+#include "transformations/utils/utils.hpp"++using namespace testing;+using namespace ov::intel_cpu;++namespace {++enum class MoEType { MoE2GeMM, MoE3GeMM };++inline std::ostream& operator<<(std::ostream& os, const MoEType& type) {+ switch (type) {+ case MoEType::MoE2GeMM:+ return os << "MoE2GeMM";+ case MoEType::MoE3GeMM:+ return os << "MoE3GeMM";+ default:+ OPENVINO_THROW("Unsupported MoEType");+ }+}++using MoEMatMulsFusionParams = std::tuple<MoEType, // moe_type+ bool, // use_scatter_v12+ bool, // use_broadcast_v3+ bool, // skip_unsqueeze+ bool, // matmul_transpose_b+ bool, // additional_node_consumers+ bool>; // transformation_should_be_applied++inline std::shared_ptr<ov::Node> build_matmul_weights(const ov::Shape& weights_shape,+ const ov::element::Type& weights_precision,+ size_t seed,+ bool transpose_b) {+ // Note: builder takes planar weights shape, but it is transposed here+ // only if transpose_b=true (which is the default case for MoE matmuls)+ auto final_weights_shape = weights_shape;+ if (transpose_b) {+ std::swap(*final_weights_shape.rbegin(), *(final_weights_shape.rbegin() + 1));+ }+ return ov::test::utils::make_constant(weights_precision,+ final_weights_shape,+ ov::test::utils::InputGenerateData(0, 10, 1, seed));+}++inline std::shared_ptr<ov::Model> initMoE2GeMMSubgraph(bool use_scatter_v12,+ bool use_broadcast_v3,+ bool skip_unsqueeze,+ bool matmul_transpose_b,+ bool additional_node_consumers) {+ // Fixed values that don't affect pass behavior+ const auto expert_alpha = 1.625f;+ const auto expert_beta = 7.0f;+ const ov::PartialShape input_shape = {-1, -1, 256};+ const size_t topk = 4;+ const size_t number_of_experts = 8;+ const size_t intermediate_size = 512;+ const ov::element::Type data_precision = ov::element::f32;+ const ov::element::Type weights_precision = ov::element::f32;+ constexpr int64_t fusion_factor = 2;++ auto input = std::make_shared<ov::op::v0::Parameter>(data_precision, input_shape);+ const auto hidden_size = static_cast<size_t>(input_shape[2].get_length());++ auto experts_reshape = std::make_shared<ov::op::v1::Reshape>(+ input,+ ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{2},+ std::vector<int64_t>{-1, static_cast<int64_t>(hidden_size)}),+ false);++ auto tile = std::make_shared<ov::op::v0::Tile>(+ experts_reshape,+ ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{2},+ std::vector<int64_t>{static_cast<int64_t>(number_of_experts), 1}));++ auto after_tile_reshape = std::make_shared<ov::op::v1::Reshape>(+ tile,+ ov::op::v0::Constant::create(+ ov::element::i64,+ ov::Shape{3},+ std::vector<int64_t>{static_cast<int64_t>(number_of_experts), -1, static_cast<int64_t>(hidden_size)}),+ false);++ // Note: we need to use different seed to avoid the exact weights generation for the MatMuls with the same shape+ size_t seed = 1;+ auto gate_up_weights =+ build_matmul_weights(ov::Shape{number_of_experts, hidden_size, intermediate_size * fusion_factor},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto gate_up_matmul =+ std::make_shared<ov::op::v0::MatMul>(after_tile_reshape, gate_up_weights, false, matmul_transpose_b);++ gate_up_matmul->set_friendly_name("GateUpMatMul");++ auto gate_up_add = std::make_shared<ov::op::v1::Add>(+ gate_up_matmul,+ ov::test::utils::make_constant(data_precision,+ ov::Shape{number_of_experts, 1, intermediate_size * fusion_factor}));++ auto slice1 = std::make_shared<ov::op::v8::Slice>(+ gate_up_add,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{0}),+ ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{1},+ std::vector<int64_t>{std::numeric_limits<int64_t>::max()}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{2}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{2}));+ auto clamp = std::make_shared<ov::op::v0::Clamp>(slice1, -expert_beta, expert_beta);+ auto add1 = std::make_shared<ov::op::v1::Add>(clamp, ov::test::utils::make_constant(data_precision, ov::Shape{1}));++ auto slice2 = std::make_shared<ov::op::v8::Slice>(+ gate_up_add,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{1}),+ ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{1},+ std::vector<int64_t>{std::numeric_limits<int64_t>::max()}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{2}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{2}));+ auto minimum1 =+ std::make_shared<ov::op::v1::Minimum>(slice2,+ ov::op::v0::Constant::create(data_precision, ov::Shape{1}, {10.0f}));+ auto swish_beta = ov::op::v0::Constant::create(data_precision, ov::Shape{}, std::vector<float>{expert_alpha});+ auto swish = std::make_shared<ov::op::v4::Swish>(minimum1, swish_beta);++ auto multiply2 = std::make_shared<ov::op::v1::Multiply>(add1, swish);++ auto down_proj_weights = build_matmul_weights(ov::Shape{number_of_experts, intermediate_size, hidden_size},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto down_proj_matmul =+ std::make_shared<ov::op::v0::MatMul>(multiply2, down_proj_weights, false, matmul_transpose_b);++ down_proj_matmul->set_friendly_name("DownProjMatMul");++ auto down_proj_add = std::make_shared<ov::op::v1::Add>(+ down_proj_matmul,+ ov::test::utils::make_constant(data_precision, ov::Shape{number_of_experts, 1, hidden_size}));++ auto router_weights =+ build_matmul_weights(ov::Shape{hidden_size, number_of_experts}, weights_precision, seed++, matmul_transpose_b);++ auto reshape_2nd_consumer_router_matmul =+ std::make_shared<ov::op::v0::MatMul>(experts_reshape, router_weights, false, matmul_transpose_b);++ auto router_bias = std::make_shared<ov::op::v1::Add>(+ reshape_2nd_consumer_router_matmul,+ ov::test::utils::make_constant(data_precision, ov::Shape{1, number_of_experts}));++ auto router_topk_values_and_indices =+ std::make_shared<ov::op::v11::TopK>(router_bias,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {topk}),+ -1,+ ov::op::v11::TopK::Mode::MAX,+ ov::op::v11::TopK::SortType::SORT_VALUES,+ ov::element::i64);++ auto router_topk_values = router_topk_values_and_indices->output(0);+ auto router_topk_values_softmax = std::make_shared<ov::op::v1::Softmax>(router_topk_values, 1);+ auto router_topk_indices = router_topk_values_and_indices->output(1);+ auto slice3 = std::make_shared<ov::op::v8::Slice>(+ router_topk_values_softmax,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{0, 0}),+ std::make_shared<ov::op::v3::ShapeOf>(router_topk_indices),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{1, 1}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{0, 1}));++ auto shape_of = std::make_shared<ov::op::v0::ShapeOf>(router_bias);+ auto zero_const = ov::op::v0::Constant::create(slice3->get_output_element_type(0), ov::Shape{1}, {0});++ std::shared_ptr<ov::Node> broadcast_zero;+ if (use_broadcast_v3) {+ broadcast_zero = std::make_shared<ov::op::v3::Broadcast>(zero_const, shape_of);+ } else {+ broadcast_zero = std::make_shared<ov::op::v1::Broadcast>(zero_const, shape_of);+ }++ std::shared_ptr<ov::Node> scatter_elements_update;+ if (use_scatter_v12) {+ scatter_elements_update = std::make_shared<ov::op::v12::ScatterElementsUpdate>(+ broadcast_zero,+ router_topk_indices,+ slice3,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{1}));+ } else {+ scatter_elements_update = std::make_shared<ov::op::v3::ScatterElementsUpdate>(+ broadcast_zero,+ router_topk_indices,+ slice3,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{1}));+ }++ auto router_transpose = std::make_shared<ov::op::v1::Transpose>(+ scatter_elements_update,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{1, 0}));++ const auto number_of_experts_const =+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {static_cast<int64_t>(number_of_experts)});+ auto first_in_dim = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(input, {0});+ auto last_in_dim = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(input, {2});+ auto minus_one = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{-1});++ std::shared_ptr<ov::op::v0::Concat> router_shape;+ if (skip_unsqueeze) {+ auto one_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{1});+ router_shape = std::make_shared<ov::op::v0::Concat>(+ ov::OutputVector{number_of_experts_const, first_in_dim, minus_one, one_const},+ 0);+ } else {+ router_shape =+ std::make_shared<ov::op::v0::Concat>(ov::OutputVector{number_of_experts_const, first_in_dim, minus_one}, 0);+ }++ auto router_reshape = std::make_shared<ov::op::v1::Reshape>(router_transpose, router_shape, true);++ std::shared_ptr<ov::Node> routing_weights_final;+ if (skip_unsqueeze) {+ routing_weights_final = router_reshape;+ } else {+ auto unsqueeze_routing_weights = std::make_shared<ov::op::v0::Unsqueeze>(+ router_reshape,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{3}));+ routing_weights_final = unsqueeze_routing_weights;+ }++ auto end_shape = std::make_shared<ov::op::v0::Concat>(+ ov::OutputVector{number_of_experts_const, first_in_dim, minus_one, last_in_dim},+ 0);+ auto end_reshape = std::make_shared<ov::op::v1::Reshape>(down_proj_add, end_shape, true);++ auto mul3 = std::make_shared<ov::op::v1::Multiply>(end_reshape, routing_weights_final);++ auto reduce_sum = std::make_shared<ov::op::v1::ReduceSum>(+ mul3,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{0}),+ false);++ ov::ParameterVector params = {input};+ ov::ResultVector results = {std::make_shared<ov::op::v0::Result>(reduce_sum)};++ if (additional_node_consumers) {+ results.push_back(std::make_shared<ov::op::v0::Result>(after_tile_reshape));+ results.push_back(std::make_shared<ov::op::v0::Result>(gate_up_add));+ results.push_back(std::make_shared<ov::op::v0::Result>(multiply2));+ results.push_back(std::make_shared<ov::op::v0::Result>(down_proj_add));+ }++ return std::make_shared<ov::Model>(results, params);+}++inline std::shared_ptr<ov::Model> initMoE2GeMMSubgraphRef(bool use_scatter_v12,+ bool use_broadcast_v3,+ bool skip_unsqueeze,+ bool matmul_transpose_b) {+ // Fixed values that don't affect pass behavior+ const auto expert_alpha = 1.625f;+ const auto expert_beta = 7.0f;+ const ov::PartialShape input_shape = {-1, -1, 256};+ const size_t topk = 4;+ const size_t number_of_experts = 8;+ const size_t intermediate_size = 512;+ const ov::element::Type data_precision = ov::element::f32;+ const ov::element::Type weights_precision = ov::element::f32;+ constexpr int64_t fusion_factor = 2;++ auto input = std::make_shared<ov::op::v0::Parameter>(data_precision, input_shape);++ const auto hidden_size = static_cast<size_t>(input_shape[2].get_length());++ auto experts_reshape = std::make_shared<ov::op::v1::Reshape>(+ input,+ ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{2},+ std::vector<int64_t>{-1, static_cast<int64_t>(hidden_size)}),+ false);++ auto unsqueeze_experts =+ std::make_shared<ov::op::v0::Unsqueeze>(experts_reshape,+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {0}));++ auto router_weights =+ build_matmul_weights(ov::Shape{hidden_size, number_of_experts}, weights_precision, 4, matmul_transpose_b);++ auto reshape_2nd_consumer_router_matmul =+ std::make_shared<ov::op::v0::MatMul>(experts_reshape, router_weights, false, matmul_transpose_b);++ auto router_bias = std::make_shared<ov::op::v1::Add>(+ reshape_2nd_consumer_router_matmul,+ ov::test::utils::make_constant(data_precision, ov::Shape{1, number_of_experts}));++ auto router_topk_values_and_indices =+ std::make_shared<ov::op::v11::TopK>(router_bias,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {topk}),+ -1,+ ov::op::v11::TopK::Mode::MAX,+ ov::op::v11::TopK::SortType::SORT_VALUES,+ ov::element::i64);++ auto router_topk_values = router_topk_values_and_indices->output(0);+ auto router_topk_values_softmax = std::make_shared<ov::op::v1::Softmax>(router_topk_values, 1);+ auto router_topk_indices = router_topk_values_and_indices->output(1);+ auto slice3 = std::make_shared<ov::op::v8::Slice>(+ router_topk_values_softmax,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{0, 0}),+ std::make_shared<ov::op::v3::ShapeOf>(router_topk_indices),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{1, 1}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{0, 1}));++ // Note: we need to use different seed to avoid the exact weights generation for the MatMuls with the same shape+ size_t seed = 1;+ auto gate_up_weights =+ build_matmul_weights(ov::Shape{number_of_experts, hidden_size, intermediate_size * fusion_factor},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto gate_up_bias =+ ov::test::utils::make_constant(data_precision,+ ov::Shape{number_of_experts, 1, intermediate_size * fusion_factor});++ auto gate_up_gathered_mm =+ std::make_shared<BatchGatherMatmul>(unsqueeze_experts, gate_up_weights, router_topk_indices, gate_up_bias);++ auto slice1 = std::make_shared<ov::op::v8::Slice>(+ gate_up_gathered_mm,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{0}),+ ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{1},+ std::vector<int64_t>{std::numeric_limits<int64_t>::max()}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{2}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{2}));+ auto clamp = std::make_shared<ov::op::v0::Clamp>(slice1, -expert_beta, expert_beta);+ auto add1 = std::make_shared<ov::op::v1::Add>(clamp, ov::test::utils::make_constant(data_precision, ov::Shape{1}));++ auto slice2 = std::make_shared<ov::op::v8::Slice>(+ gate_up_gathered_mm,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{1}),+ ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{1},+ std::vector<int64_t>{std::numeric_limits<int64_t>::max()}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{2}),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{2}));+ auto minimum1 =+ std::make_shared<ov::op::v1::Minimum>(slice2,+ ov::op::v0::Constant::create(data_precision, ov::Shape{1}, {10.0f}));+ auto swish_beta = ov::op::v0::Constant::create(data_precision, ov::Shape{}, std::vector<float>{expert_alpha});+ auto swish = std::make_shared<ov::op::v4::Swish>(minimum1, swish_beta);++ auto multiply2 = std::make_shared<ov::op::v1::Multiply>(add1, swish);++ auto down_proj_weights = build_matmul_weights(ov::Shape{number_of_experts, intermediate_size, hidden_size},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto down_proj_bias = ov::test::utils::make_constant(data_precision, ov::Shape{number_of_experts, 1, hidden_size});++ auto down_gathered_mm =+ std::make_shared<BatchGatherMatmul>(multiply2, down_proj_weights, router_topk_indices, down_proj_bias);++ auto router_transpose = std::make_shared<ov::op::v1::Transpose>(+ slice3,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{1, 0}));++ auto router_unsqueeze =+ std::make_shared<ov::op::v0::Unsqueeze>(router_transpose,+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {-1}));++ auto mul3 = std::make_shared<ov::op::v1::Multiply>(down_gathered_mm, router_unsqueeze);++ auto reduce_sum = std::make_shared<ov::op::v1::ReduceSum>(+ mul3,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{0}),+ false);++ const auto number_of_experts_const =+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {static_cast<int64_t>(number_of_experts)});+ auto first_in_dim = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(input, {0});+ auto last_in_dim = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(input, {2});+ auto minus_one = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{-1});++ auto end_shape = std::make_shared<ov::op::v0::Concat>(+ ov::OutputVector{number_of_experts_const, first_in_dim, minus_one, last_in_dim},+ 0);++ auto slice_shape =+ std::make_shared<ov::op::v8::Slice>(end_shape,+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1}),+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {4}),+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1}),+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {0}));++ auto final_reshape = std::make_shared<ov::op::v1::Reshape>(reduce_sum, slice_shape, true);++ ov::ParameterVector params = {input};+ return std::make_shared<ov::Model>(ov::OutputVector{final_reshape}, params);+}++inline std::shared_ptr<ov::Model> initMoE3GeMMSubgraph(bool use_scatter_v12,+ bool use_broadcast_v3,+ bool skip_unsqueeze,+ bool matmul_transpose_b,+ bool additional_node_consumers) {+ // Fixed values that don't affect pass behavior+ const ov::PartialShape input_shape = {-1, -1, 256};+ const size_t topk = 4;+ const size_t number_of_experts = 8;+ const size_t intermediate_size = 512;+ const ov::element::Type data_precision = ov::element::f32;+ const ov::element::Type weights_precision = ov::element::f32;++ auto input = std::make_shared<ov::op::v0::Parameter>(data_precision, input_shape);+ const auto hidden_size = static_cast<size_t>(input_shape[2].get_length());++ auto experts_reshape = std::make_shared<ov::op::v1::Reshape>(+ input,+ ov::op::v0::Constant::create(+ ov::element::i64,+ ov::Shape{2},+ std::vector<int64_t>{-1, static_cast<int64_t>(hidden_size)}), // -1 flattens batch*seq_len+ false);++ auto tile = std::make_shared<ov::op::v0::Tile>(+ experts_reshape,+ ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{2},+ std::vector<int64_t>{static_cast<int64_t>(number_of_experts), 1}));++ auto after_tile_reshape = std::make_shared<ov::op::v1::Reshape>(+ tile,+ ov::op::v0::Constant::create(+ ov::element::i64,+ ov::Shape{3},+ std::vector<int64_t>{static_cast<int64_t>(number_of_experts), -1, static_cast<int64_t>(hidden_size)}),+ false);++ // Note: we need to use different seed to avoid the exact weights generation for the MatMuls with the same shape+ size_t seed = 1;+ auto gate_weights = build_matmul_weights(ov::Shape{number_of_experts, hidden_size, intermediate_size},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto gate_matmul =+ std::make_shared<ov::op::v0::MatMul>(after_tile_reshape, gate_weights, false, matmul_transpose_b);++ gate_matmul->set_friendly_name("GateMatMul");++ auto swish = std::make_shared<ov::op::v4::Swish>(gate_matmul);+ auto up_weights = build_matmul_weights(ov::Shape{number_of_experts, hidden_size, intermediate_size},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto up_matmul = std::make_shared<ov::op::v0::MatMul>(after_tile_reshape, up_weights, false, matmul_transpose_b);++ up_matmul->set_friendly_name("UpMatMul");++ auto swiglu = std::make_shared<ov::op::v1::Multiply>(swish, up_matmul);++ auto down_weights = build_matmul_weights(ov::Shape{number_of_experts, intermediate_size, hidden_size},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto down_matmul = std::make_shared<ov::op::v0::MatMul>(swiglu, down_weights, false, matmul_transpose_b);++ down_matmul->set_friendly_name("DownMatMul");++ auto router_weights =+ build_matmul_weights(ov::Shape{hidden_size, number_of_experts}, weights_precision, seed++, matmul_transpose_b);++ auto reshape_2nd_consumer_router_matmul =+ std::make_shared<ov::op::v0::MatMul>(experts_reshape, router_weights, false, matmul_transpose_b);++ auto router_softmax = std::make_shared<ov::op::v1::Softmax>(reshape_2nd_consumer_router_matmul, 1);++ auto router_topk_values_and_indices =+ std::make_shared<ov::op::v11::TopK>(router_softmax,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {topk}),+ -1,+ ov::op::v11::TopK::Mode::MAX,+ ov::op::v11::TopK::SortType::SORT_VALUES,+ ov::element::i64);++ auto router_topk_values_reduce = std::make_shared<ov::op::v1::ReduceSum>(+ router_topk_values_and_indices->output(0),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{-1}),+ true);+ auto router_topk_values_normalization =+ std::make_shared<ov::op::v1::Divide>(router_topk_values_and_indices->output(0), router_topk_values_reduce);+ auto router_topk_indices = router_topk_values_and_indices->output(1);++ const auto number_of_experts_const =+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {static_cast<int64_t>(number_of_experts)});++ auto zero_const =+ ov::op::v0::Constant::create(router_topk_values_normalization->get_output_element_type(0), ov::Shape{1}, {0});+ auto first_topk_dim = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(router_topk_indices, {0});+ auto bcast_target_shape =+ std::make_shared<ov::op::v0::Concat>(ov::OutputVector{first_topk_dim, number_of_experts_const}, 0);++ std::shared_ptr<ov::Node> broadcast_zero;+ if (use_broadcast_v3) {+ broadcast_zero = std::make_shared<ov::op::v3::Broadcast>(zero_const, bcast_target_shape);+ } else {+ broadcast_zero = std::make_shared<ov::op::v1::Broadcast>(zero_const, bcast_target_shape);+ }++ std::shared_ptr<ov::Node> scatter_elements_update;+ if (use_scatter_v12) {+ scatter_elements_update = std::make_shared<ov::op::v12::ScatterElementsUpdate>(+ broadcast_zero,+ router_topk_indices,+ router_topk_values_normalization,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{1}));+ } else {+ scatter_elements_update = std::make_shared<ov::op::v3::ScatterElementsUpdate>(+ broadcast_zero,+ router_topk_indices,+ router_topk_values_normalization,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{1}));+ }++ auto router_transpose = std::make_shared<ov::op::v1::Transpose>(+ scatter_elements_update,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{1, 0}));++ auto minus_one = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{-1});+ std::shared_ptr<ov::op::v0::Concat> router_shape;+ if (skip_unsqueeze) {+ auto one_const = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{1});+ router_shape = std::make_shared<ov::op::v0::Concat>(+ ov::OutputVector{number_of_experts_const, first_topk_dim, minus_one, one_const},+ 0);+ } else {+ router_shape =+ std::make_shared<ov::op::v0::Concat>(ov::OutputVector{number_of_experts_const, first_topk_dim, minus_one},+ 0);+ }++ auto router_reshape = std::make_shared<ov::op::v1::Reshape>(router_transpose, router_shape, true);++ std::shared_ptr<ov::Node> routing_weights_final;+ if (skip_unsqueeze) {+ routing_weights_final = router_reshape;+ } else {+ auto unsqueeze_routing_weights = std::make_shared<ov::op::v0::Unsqueeze>(+ router_reshape,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{3}));+ routing_weights_final = unsqueeze_routing_weights;+ }++ auto last_in_dim = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(input, {2});+ auto end_shape = std::make_shared<ov::op::v0::Concat>(+ ov::OutputVector{number_of_experts_const, first_topk_dim, minus_one, last_in_dim},+ 0);+ auto end_reshape = std::make_shared<ov::op::v1::Reshape>(down_matmul, end_shape, true);++ auto mul3 = std::make_shared<ov::op::v1::Multiply>(end_reshape, routing_weights_final);++ auto reduce_sum = std::make_shared<ov::op::v1::ReduceSum>(+ mul3,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{0}),+ false);++ auto final_reshape_const = ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{2},+ std::vector<int64_t>{0, static_cast<int64_t>(hidden_size)});+ auto final_reshape = std::make_shared<ov::op::v1::Reshape>(reduce_sum, final_reshape_const, true);++ ov::ParameterVector params = {input};+ ov::ResultVector results = {std::make_shared<ov::op::v0::Result>(final_reshape)};++ if (additional_node_consumers) {+ results.push_back(std::make_shared<ov::op::v0::Result>(after_tile_reshape));+ results.push_back(std::make_shared<ov::op::v0::Result>(gate_matmul));+ results.push_back(std::make_shared<ov::op::v0::Result>(swish));+ results.push_back(std::make_shared<ov::op::v0::Result>(up_matmul));+ results.push_back(std::make_shared<ov::op::v0::Result>(swiglu));+ results.push_back(std::make_shared<ov::op::v0::Result>(down_matmul));+ }++ return std::make_shared<ov::Model>(results, params);+}++inline std::shared_ptr<ov::Model> initMoE3GeMMSubgraphRef(bool use_scatter_v12,+ bool use_broadcast_v3,+ bool skip_unsqueeze,+ bool matmul_transpose_b) {+ // Fixed values that don't affect pass behavior+ const ov::PartialShape input_shape = {-1, -1, 256};+ const size_t topk = 4;+ const size_t number_of_experts = 8;+ const size_t intermediate_size = 512;+ const ov::element::Type data_precision = ov::element::f32;+ const ov::element::Type weights_precision = ov::element::f32;++ auto input = std::make_shared<ov::op::v0::Parameter>(data_precision, input_shape);++ const auto hidden_size = static_cast<size_t>(input_shape[2].get_length());++ auto experts_reshape = std::make_shared<ov::op::v1::Reshape>(+ input,+ ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{2},+ std::vector<int64_t>{-1, static_cast<int64_t>(hidden_size)}),+ false);++ auto unsqueeze_experts =+ std::make_shared<ov::op::v0::Unsqueeze>(experts_reshape,+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {0}));++ auto router_weights =+ build_matmul_weights(ov::Shape{hidden_size, number_of_experts}, weights_precision, 4, matmul_transpose_b);++ auto reshape_2nd_consumer_router_matmul =+ std::make_shared<ov::op::v0::MatMul>(experts_reshape, router_weights, false, matmul_transpose_b);++ auto router_softmax = std::make_shared<ov::op::v1::Softmax>(reshape_2nd_consumer_router_matmul, 1);++ auto router_topk_values_and_indices =+ std::make_shared<ov::op::v11::TopK>(router_softmax,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {topk}),+ -1,+ ov::op::v11::TopK::Mode::MAX,+ ov::op::v11::TopK::SortType::SORT_VALUES,+ ov::element::i64);++ auto router_topk_values_reduce = std::make_shared<ov::op::v1::ReduceSum>(+ router_topk_values_and_indices->output(0),+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{-1}),+ true);+ auto router_topk_values_normalization =+ std::make_shared<ov::op::v1::Divide>(router_topk_values_and_indices->output(0), router_topk_values_reduce);+ auto router_topk_indices = router_topk_values_and_indices->output(1);++ // Note: we need to use different seed to avoid the exact weights generation for the MatMuls with the same shape+ size_t seed = 1;+ auto gate_weights = build_matmul_weights(ov::Shape{number_of_experts, hidden_size, intermediate_size},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto gate_gathered_mm = std::make_shared<BatchGatherMatmul>(unsqueeze_experts, gate_weights, router_topk_indices);++ auto swish = std::make_shared<ov::op::v4::Swish>(gate_gathered_mm);++ auto up_weights = build_matmul_weights(ov::Shape{number_of_experts, hidden_size, intermediate_size},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto up_gathered_mm = std::make_shared<BatchGatherMatmul>(unsqueeze_experts, up_weights, router_topk_indices);++ auto swiglu = std::make_shared<ov::op::v1::Multiply>(swish, up_gathered_mm);++ auto down_weights = build_matmul_weights(ov::Shape{number_of_experts, intermediate_size, hidden_size},+ weights_precision,+ seed++,+ matmul_transpose_b);++ auto down_gathered_mm = std::make_shared<BatchGatherMatmul>(swiglu, down_weights, router_topk_indices);++ auto router_transpose = std::make_shared<ov::op::v1::Transpose>(+ router_topk_values_normalization,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{2}, std::vector<int64_t>{1, 0}));++ auto router_unsqueeze =+ std::make_shared<ov::op::v0::Unsqueeze>(router_transpose,+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{}, {-1}));++ auto mul3 = std::make_shared<ov::op::v1::Multiply>(down_gathered_mm, router_unsqueeze);++ auto reduce_sum = std::make_shared<ov::op::v1::ReduceSum>(+ mul3,+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{0}),+ false);++ const auto number_of_experts_const =+ ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, {static_cast<int64_t>(number_of_experts)});+ auto first_topk_dim = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(router_topk_indices, {0});+ auto last_in_dim = ov::op::util::node_to_get_shape_value_of_indices_from_shape_source(input, {2});+ auto minus_one = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{1}, std::vector<int64_t>{-1});++ auto end_shape = std::make_shared<ov::op::v0::Concat>(+ ov::OutputVector{number_of_experts_const, first_topk_dim, minus_one, last_in_dim},+ 0);++ auto slice_shape =+ std::make_shared<ov::op::v8::Slice>(end_shape,+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1}),+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {4}),+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {1}),+ ov::op::v0::Constant::create(ov::element::i32, ov::Shape{1}, {0}));++ auto final_reshape = std::make_shared<ov::op::v1::Reshape>(reduce_sum, slice_shape, true);++ auto final_reshape_const = ov::op::v0::Constant::create(ov::element::i64,+ ov::Shape{2},+ std::vector<int64_t>{0, static_cast<int64_t>(hidden_size)});+ auto original_final_reshape = std::make_shared<ov::op::v1::Reshape>(final_reshape, final_reshape_const, true);++ ov::ParameterVector params = {input};+ return std::make_shared<ov::Model>(ov::OutputVector{original_final_reshape}, params);+}++class MoEMatMulsFusionTest : public TransformationTestsF, public WithParamInterface<MoEMatMulsFusionParams> {+public:+ static std::string getTestCaseName(const testing::TestParamInfo<MoEMatMulsFusionParams>& obj) {+ const auto& [moe_type,+ use_scatter_v12,+ use_broadcast_v3,+ skip_unsqueeze,+ matmul_transpose_b,+ additional_node_consumers,+ should_be_applied] = obj.param;+ std::ostringstream result;+ result << "MoEType_" << moe_type << "_ScatterV" << (use_scatter_v12 ? "12" : "3") << "_BroadcastV"+ << (use_broadcast_v3 ? "3" : "1") << "_SkipUnsqueeze_" << (skip_unsqueeze ? "true" : "false")+ << "_MatMulTransposeB_" << (matmul_transpose_b ? "true" : "false") << "_AdditionalConsumers_"+ << (additional_node_consumers ? "true" : "false") << "_shouldBeApplied_"+ << (should_be_applied ? "true" : "false");+ return result.str();+ }++protected:+ void SetUp() override {+ TransformationTestsF::SetUp();+ const auto& [moe_type,+ use_scatter_v12,+ use_broadcast_v3,+ skip_unsqueeze,+ matmul_transpose_b,+ additional_node_consumers,+ should_be_applied] = this->GetParam();++ switch (moe_type) {+ case MoEType::MoE2GeMM:+ model = initMoE2GeMMSubgraph(use_scatter_v12,+ use_broadcast_v3,+ skip_unsqueeze,+ matmul_transpose_b,+ additional_node_consumers);+ break;+ case MoEType::MoE3GeMM:+ model = initMoE3GeMMSubgraph(use_scatter_v12,+ use_broadcast_v3,+ skip_unsqueeze,+ matmul_transpose_b,+ additional_node_consumers);+ break;+ default:+ OPENVINO_THROW("Unexpected MoEType value");+ }++ manager.register_pass<MoEMatMulsFusion>();++ if (should_be_applied) {+ switch (moe_type) {+ case MoEType::MoE2GeMM:+ model_ref =+ initMoE2GeMMSubgraphRef(use_scatter_v12, use_broadcast_v3, skip_unsqueeze, matmul_transpose_b);+ break;+ case MoEType::MoE3GeMM:+ model_ref =+ initMoE3GeMMSubgraphRef(use_scatter_v12, use_broadcast_v3, skip_unsqueeze, matmul_transpose_b);+ break;+ default:+ OPENVINO_THROW("Unexpected MoEType value");+ }+ }+ }+};++TEST_P(MoEMatMulsFusionTest, CompareFunctions) {}++const std::vector<MoEType> moe_types = {MoEType::MoE2GeMM, MoEType::MoE3GeMM};+const std::vector<bool> scatter_versions = {false, true}; // false = v3, true = v12+const std::vector<bool> broadcast_versions = {false, true}; // false = v1, true = v3+const std::vector<bool> skip_unsqueeze_versions = {false, true};++INSTANTIATE_TEST_SUITE_P(MoEMatMulsFusionTest_positive_cases,+ MoEMatMulsFusionTest,+ ::testing::Combine(::testing::ValuesIn(moe_types),+ ::testing::ValuesIn(scatter_versions),+ ::testing::ValuesIn(broadcast_versions),+ ::testing::ValuesIn(skip_unsqueeze_versions),+ ::testing::Values(true),+ ::testing::Values(false),+ ::testing::Values(true)),+ MoEMatMulsFusionTest::getTestCaseName);++INSTANTIATE_TEST_SUITE_P(MoEMatMulsFusionTest_negative_cases_no_transpose,+ MoEMatMulsFusionTest,+ ::testing::Combine(::testing::ValuesIn(moe_types),+ ::testing::ValuesIn(scatter_versions),+ ::testing::ValuesIn(broadcast_versions),+ ::testing::ValuesIn(skip_unsqueeze_versions),+ ::testing::Values(false),+ ::testing::Values(false),+ ::testing::Values(false)),+ MoEMatMulsFusionTest::getTestCaseName);++INSTANTIATE_TEST_SUITE_P(MoEMatMulsFusionTest_negative_cases_additional_consumers,+ MoEMatMulsFusionTest,+ ::testing::Combine(::testing::ValuesIn(moe_types),+ ::testing::Values(false),+ ::testing::Values(false),+ ::testing::Values(false),+ ::testing::Values(true),+ ::testing::Values(true),+ ::testing::Values(false)),+ MoEMatMulsFusionTest::getTestCaseName);+} // namespace\ No newline at end of filediff --git a/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp b/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cppindex 33f03274361..447abb37889 100644--- a/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp+++ b/src/plugins/intel_gpu/tests/functional/behavior/model_cache.cpp@@ -24,7 +24,8 @@#include "openvino/runtime/weightless_properties_utils.hpp"#include "openvino/util/codec_xor.hpp"#include "shared_test_classes/base/ov_behavior_test_utils.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#ifndef WIN32# include <unistd.h>#endif@@ -255,16 +256,16 @@ TEST_P(CheckWeightlessCacheAccuracyLowPrecision, MatmulWeightsDecompression) {dynShape = shape_params.data_shape.second.front();}ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ov::element::f32, dynShape)};- const auto weights_subgraph = ov::test::initMatMulDecompressionSubgraph(shape_params.weights_shape,- shape_params.decompression_group_size,- ov::element::f32,- model_dtype,- ov::element::f32,- ov::element::dynamic,- true,- ov::test::DecompressionType::full,- ov::test::DecompressionType::full,- false);+ const auto weights_subgraph = ov::test::utils::initMatMulDecompressionSubgraph(shape_params.weights_shape,+ shape_params.decompression_group_size,+ ov::element::f32,+ model_dtype,+ ov::element::f32,+ ov::element::dynamic,+ true,+ ov::test::utils::DecompressionType::full,+ ov::test::utils::DecompressionType::full,+ false);auto matmul = std::make_shared<ov::op::v0::MatMul>(params[0], weights_subgraph);ov::ResultVector results;diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/shared_matmul_weights_decompression.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/shared_matmul_weights_decompression.cppindex 7e7846c36b8..5f7f5e5e979 100644--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/shared_matmul_weights_decompression.cpp+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/subgraph_tests/shared_matmul_weights_decompression.cpp@@ -42,7 +42,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_MatMulSharedCompressedWeights,::testing::ValuesIn(weights_precisions),::testing::ValuesIn(decompression_precisions),::testing::ValuesIn(transpose_weights),- ::testing::Values(DecompressionType::full),+ ::testing::Values(ov::test::utils::DecompressionType::full),::testing::Values(true),::testing::Values(additional_config)),SharedMatmulWeightsDecompression::getTestCaseName);diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/gather_weights_decompression.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/gather_weights_decompression.hppindex 191f6f24c3c..d77e8ae74b2 100644--- a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/gather_weights_decompression.hpp+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/gather_weights_decompression.hpp@@ -6,7 +6,8 @@#include "common_test_utils/ov_tensor_utils.hpp"#include "shared_test_classes/base/ov_subgraph.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"namespace ov {namespace test {diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/moe_builders.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/moe_builders.hppindex dbd3cbfb623..8c4ae87c5e0 100644--- a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/moe_builders.hpp+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/moe_builders.hpp@@ -10,7 +10,8 @@#include "openvino/core/model.hpp"#include "openvino/core/type/element_type.hpp"#include "shared_test_classes/base/ov_subgraph.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"namespace ov {namespace test {@@ -28,8 +29,8 @@ std::shared_ptr<ov::Model> initMoE2GeMMSubgraph(const MoePatternParams& moe_paraconst bool use_weight_decompression = false,const std::optional<ov::element::Type> decompression_precision = std::nullopt,const std::optional<ov::element::Type> scale_precision = std::nullopt,- const std::optional<DecompressionType> decompression_multiply_type = std::nullopt,- const std::optional<DecompressionType> decompression_subtract_type = std::nullopt,+ const std::optional<ov::test::utils::DecompressionType> decompression_multiply_type = std::nullopt,+ const std::optional<ov::test::utils::DecompressionType> decompression_subtract_type = std::nullopt,const std::optional<bool> reshape_on_decompression = std::nullopt,const std::optional<int> decompression_group_size = std::nullopt);@@ -39,8 +40,8 @@ std::shared_ptr<ov::Model> initMoE3GeMMSubgraph(const MoePatternParams& moe_paraconst bool use_weight_decompression = false,const std::optional<ov::element::Type> decompression_precision = std::nullopt,const std::optional<ov::element::Type> scale_precision = std::nullopt,- const std::optional<DecompressionType> decompression_multiply_type = std::nullopt,- const std::optional<DecompressionType> decompression_subtract_type = std::nullopt,+ const std::optional<ov::test::utils::DecompressionType> decompression_multiply_type = std::nullopt,+ const std::optional<ov::test::utils::DecompressionType> decompression_subtract_type = std::nullopt,const std::optional<bool> reshape_on_decompression = std::nullopt,const std::optional<int> decompression_group_size = std::nullopt);diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/shared_matmul_gather_weights_decompression.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/shared_matmul_gather_weights_decompression.hppindex 6e5df033838..15627a1121f 100644--- a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/shared_matmul_gather_weights_decompression.hpp+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/shared_matmul_gather_weights_decompression.hpp@@ -5,7 +5,8 @@#pragma once#include "shared_test_classes/base/ov_subgraph.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"namespace ov {namespace test {diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/shared_matmul_weights_decompression.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/shared_matmul_weights_decompression.hppindex 10170d782d5..c1f71240a86 100644--- a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/shared_matmul_weights_decompression.hpp+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/shared_matmul_weights_decompression.hpp@@ -5,7 +5,8 @@#pragma once#include "shared_test_classes/base/ov_subgraph.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include "openvino/runtime/intel_cpu/properties.hpp"namespace ov {@@ -39,7 +40,7 @@ using MatmulSharedWeightsDecompressionParams =ElementType, // weights precisionElementType, // decompression precisionbool, // transpose on weights- DecompressionType, // decompression subtract type+ ov::test::utils::DecompressionType, // decompression subtract typebool, // use matmul decompression implementationstd::map<std::string, std::string>>; // additional configeration@@ -56,7 +57,7 @@ protected:const ov::element::Type weights_precision,const ov::element::Type decompression_precision,const bool transpose_weights,- const DecompressionType decompression_subtract_type);+ const ov::test::utils::DecompressionType decompression_subtract_type);void SetUp() override;void check_results();};diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/weights_decompression_params.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/weights_decompression_params.hppnew file mode 100644index 00000000000..acd07cca515--- /dev/null+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/weights_decompression_params.hpp@@ -0,0 +1,52 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <iostream>++#include "shared_test_classes/base/ov_subgraph.hpp"++namespace ov {+namespace test {+struct MatMulDecompressionShapeParams {+ MatMulDecompressionShapeParams() = default;+ MatMulDecompressionShapeParams(InputShape data_shape, ov::Shape weights_shape, int decompression_group_size = -1)+ : data_shape(std::move(data_shape)),+ weights_shape(std::move(weights_shape)),+ decompression_group_size(decompression_group_size) {}++ InputShape data_shape;+ ov::Shape weights_shape;+ // Decompression group size. If the value is equal to -1, ordinary decompression is used+ int decompression_group_size;+};++std::ostream& operator<<(std::ostream& os, MatMulDecompressionShapeParams type);++struct GatherDecompressionShapeParams {+ GatherDecompressionShapeParams() = default;+ GatherDecompressionShapeParams(ov::Shape data_shape,+ InputShape indices_shape,+ int axis,+ int64_t batch_dims,+ int decompression_group_size = -1)+ : data_shape(std::move(data_shape)),+ indices_shape(std::move(indices_shape)),+ axis(axis),+ batch_dims(batch_dims),+ decompression_group_size(decompression_group_size) {}++ ov::Shape data_shape;+ InputShape indices_shape;+ int axis;+ int64_t batch_dims;+ // Decompression group size. If the value is equal to -1, ordinary decompression is used+ int decompression_group_size;+};++std::ostream& operator<<(std::ostream& os, GatherDecompressionShapeParams type);++} // namespace test+} // namespace ovdiff --git a/src/tests/functional/plugin/shared/src/behavior/compiled_model/model_cache.cpp b/src/tests/functional/plugin/shared/src/behavior/compiled_model/model_cache.cppindex e2fbc03cc9e..6f1e3a34e5b 100644--- a/src/tests/functional/plugin/shared/src/behavior/compiled_model/model_cache.cpp+++ b/src/tests/functional/plugin/shared/src/behavior/compiled_model/model_cache.cpp@@ -11,7 +11,8 @@#include "openvino/op/matmul.hpp"#include "openvino/runtime/weightless_properties_utils.hpp"#include "openvino/util/codec_xor.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"namespace ov {namespace test {@@ -174,16 +175,17 @@ TEST_P(WeightlessCacheAccuracyLowPrecision, MatmulWeightsDecompression) {dynShape = shape_params.data_shape.second.front();}ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ov::element::f32, dynShape)};- const auto weights_subgraph = ov::test::initMatMulDecompressionSubgraph(shape_params.weights_shape,- shape_params.decompression_group_size,- ov::element::f32,- m_model_dtype,- ov::element::f32,- ov::element::dynamic,- true,- ov::test::DecompressionType::full,- ov::test::DecompressionType::full,- false);+ const auto weights_subgraph =+ ov::test::utils::initMatMulDecompressionSubgraph(shape_params.weights_shape,+ shape_params.decompression_group_size,+ ov::element::f32,+ m_model_dtype,+ ov::element::f32,+ ov::element::dynamic,+ true,+ ov::test::utils::DecompressionType::full,+ ov::test::utils::DecompressionType::full,+ false);auto matmul = std::make_shared<ov::op::v0::MatMul>(params[0], weights_subgraph);ov::ResultVector results;diff --git a/src/tests/functional/plugin/shared/src/subgraph/gather_weights_decompression.cpp b/src/tests/functional/plugin/shared/src/subgraph/gather_weights_decompression.cppindex d709b3f3298..6cd3cabcc92 100644--- a/src/tests/functional/plugin/shared/src/subgraph/gather_weights_decompression.cpp+++ b/src/tests/functional/plugin/shared/src/subgraph/gather_weights_decompression.cpp@@ -5,7 +5,8 @@#include "shared_test_classes/subgraph/gather_weights_decompression.hpp"#include "ov_ops/gather_compressed.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include "openvino/op/convert.hpp"namespace ov {@@ -78,14 +79,14 @@ std::shared_ptr<ov::Model> GatherWeightsDecompression::init_subgraph(const ov::Sconst bool per_tensor_scale) {ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ov::element::i32, indices_shape)};auto axis_const = ov::op::v0::Constant::create(ov::element::i32, {1}, {axis});- const auto data_subgraph = initGatherDecompressionSubgraph(data_shape,- group_size,- data_precision,- output_precision,- add_subtract,- reshape_on_decompression,- per_tensor_zp,- per_tensor_scale);+ const auto data_subgraph = ov::test::utils::initGatherDecompressionSubgraph(data_shape,+ group_size,+ data_precision,+ output_precision,+ add_subtract,+ reshape_on_decompression,+ per_tensor_zp,+ per_tensor_scale);auto gather = std::make_shared<ov::op::v8::Gather>(data_subgraph, params[0], axis_const, batch_dims);gather->set_friendly_name("gather_node");diff --git a/src/tests/functional/plugin/shared/src/subgraph/moe_builders.cpp b/src/tests/functional/plugin/shared/src/subgraph/moe_builders.cppindex ea9a5e713e4..7fa7ca820dc 100644--- a/src/tests/functional/plugin/shared/src/subgraph/moe_builders.cpp+++ b/src/tests/functional/plugin/shared/src/subgraph/moe_builders.cpp@@ -9,6 +9,7 @@#include <vector>#include "common_test_utils/node_builders/constant.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include "openvino/core/model.hpp"#include "openvino/core/node_vector.hpp"#include "openvino/op/add.hpp"@@ -34,7 +35,7 @@#include "openvino/op/topk.hpp"#include "openvino/op/transpose.hpp"#include "openvino/op/unsqueeze.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"#include "transformations/utils/utils.hpp"namespace ov {@@ -48,8 +49,8 @@ std::shared_ptr<ov::Node> build_matmul_weights(bool use_weight_decompression,const std::optional<ov::element::Type>& decompression_precision = std::nullopt,const std::optional<ov::element::Type>& scale_precision = std::nullopt,- const std::optional<DecompressionType>& decompression_multiply_type = std::nullopt,- const std::optional<DecompressionType>& decompression_subtract_type = std::nullopt,+ const std::optional<ov::test::utils::DecompressionType>& decompression_multiply_type = std::nullopt,+ const std::optional<ov::test::utils::DecompressionType>& decompression_subtract_type = std::nullopt,const std::optional<bool>& reshape_on_decompression = std::nullopt,const std::optional<int>& decompression_group_size = std::nullopt) {if (!use_weight_decompression) {@@ -73,31 +74,32 @@ std::shared_ptr<ov::Node> build_matmul_weights("reshape_on_decompression must be set when use_weight_decompression is true");OPENVINO_ASSERT(decompression_group_size.has_value(),"decompression_group_size must be set when use_weight_decompression is true");- return initMatMulDecompressionSubgraphQuantization(weights_shape,- decompression_group_size.value(),- data_precision,- weights_precision,- decompression_precision.value(),- scale_precision.value(),- true,- decompression_multiply_type.value(),- decompression_subtract_type.value(),- reshape_on_decompression.value(),- false,- seed);+ return ov::test::utils::initMatMulDecompressionSubgraphQuantization(weights_shape,+ decompression_group_size.value(),+ data_precision,+ weights_precision,+ decompression_precision.value(),+ scale_precision.value(),+ true,+ decompression_multiply_type.value(),+ decompression_subtract_type.value(),+ reshape_on_decompression.value(),+ false,+ seed);}}-std::shared_ptr<ov::Model> initMoE2GeMMSubgraph(const MoePatternParams& moe_params,- const ov::element::Type data_precision,- const ov::element::Type weights_precision,- const bool use_weight_decompression,- const std::optional<ov::element::Type> decompression_precision,- const std::optional<ov::element::Type> scale_precision,- const std::optional<DecompressionType> decompression_multiply_type,- const std::optional<DecompressionType> decompression_subtract_type,- const std::optional<bool> reshape_on_decompression,- const std::optional<int> decompression_group_size) {+std::shared_ptr<ov::Model> initMoE2GeMMSubgraph(+ const MoePatternParams& moe_params,+ const ov::element::Type data_precision,+ const ov::element::Type weights_precision,+ const bool use_weight_decompression,+ const std::optional<ov::element::Type> decompression_precision,+ const std::optional<ov::element::Type> scale_precision,+ const std::optional<ov::test::utils::DecompressionType> decompression_multiply_type,+ const std::optional<ov::test::utils::DecompressionType> decompression_subtract_type,+ const std::optional<bool> reshape_on_decompression,+ const std::optional<int> decompression_group_size) {// Use parameters from shape_params - static shapes onlyconst auto& data_shape = moe_params.data_shape;const size_t intermediate_size = moe_params.intermediate_size;@@ -297,16 +299,17 @@ std::shared_ptr<ov::Model> initMoE2GeMMSubgraph(const MoePatternParams& moe_para"MoeSubgraph");}-std::shared_ptr<ov::Model> initMoE3GeMMSubgraph(const MoePatternParams& moe_params,- const ov::element::Type data_precision,- const ov::element::Type weights_precision,- const bool use_weight_decompression,- const std::optional<ov::element::Type> decompression_precision,- const std::optional<ov::element::Type> scale_precision,- const std::optional<DecompressionType> decompression_multiply_type,- const std::optional<DecompressionType> decompression_subtract_type,- const std::optional<bool> reshape_on_decompression,- const std::optional<int> decompression_group_size) {+std::shared_ptr<ov::Model> initMoE3GeMMSubgraph(+ const MoePatternParams& moe_params,+ const ov::element::Type data_precision,+ const ov::element::Type weights_precision,+ const bool use_weight_decompression,+ const std::optional<ov::element::Type> decompression_precision,+ const std::optional<ov::element::Type> scale_precision,+ const std::optional<ov::test::utils::DecompressionType> decompression_multiply_type,+ const std::optional<ov::test::utils::DecompressionType> decompression_subtract_type,+ const std::optional<bool> reshape_on_decompression,+ const std::optional<int> decompression_group_size) {// Use parameters from shape_params - static shapes onlyconst auto& data_shape = moe_params.data_shape;const size_t intermediate_size = moe_params.intermediate_size;diff --git a/src/tests/functional/plugin/shared/src/subgraph/shared_matmul_gather_weights_decompression.cpp b/src/tests/functional/plugin/shared/src/subgraph/shared_matmul_gather_weights_decompression.cppindex 6e3b0a105f2..ec568279ff1 100644--- a/src/tests/functional/plugin/shared/src/subgraph/shared_matmul_gather_weights_decompression.cpp+++ b/src/tests/functional/plugin/shared/src/subgraph/shared_matmul_gather_weights_decompression.cpp@@ -6,7 +6,8 @@#include "common_test_utils/ov_tensor_utils.hpp"#include "openvino/runtime/exec_model_info.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include "openvino/op/gather.hpp"#include "openvino/op/matmul.hpp"@@ -40,14 +41,14 @@ std::shared_ptr<ov::Model> SharedMatmulAndGatherWeightsDecompression::initSubgraconst bool add_subtract) {const auto indices_data = std::make_shared<ov::op::v0::Parameter>(ov::element::i32, indices_shape);const auto axis_const = ov::op::v0::Constant::create(ov::element::i32, {1}, {axis});- const auto decompression_subgraph = initGatherDecompressionSubgraph(data_shape,- group_size,- data_precision,- output_precision,- add_subtract,- false,- false,- false);+ const auto decompression_subgraph = ov::test::utils::initGatherDecompressionSubgraph(data_shape,+ group_size,+ data_precision,+ output_precision,+ add_subtract,+ false,+ false,+ false);const auto gather = std::make_shared<ov::op::v8::Gather>(decompression_subgraph, indices_data, axis_const, batch_dims);const auto fc_data = std::make_shared<ov::op::v0::Parameter>(output_precision, indices_shape);diff --git a/src/tests/functional/plugin/shared/src/subgraph/shared_matmul_weights_decompression.cpp b/src/tests/functional/plugin/shared/src/subgraph/shared_matmul_weights_decompression.cppindex 46f5b03edd9..677349fa466 100644--- a/src/tests/functional/plugin/shared/src/subgraph/shared_matmul_weights_decompression.cpp+++ b/src/tests/functional/plugin/shared/src/subgraph/shared_matmul_weights_decompression.cpp@@ -6,7 +6,8 @@#include "common_test_utils/ov_tensor_utils.hpp"#include "openvino/runtime/exec_model_info.hpp"-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "shared_test_classes/subgraph/weights_decompression_params.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include "openvino/opsets/opset10_decl.hpp"#include "openvino/op/matmul.hpp"#include "openvino/op/transpose.hpp"@@ -46,17 +47,18 @@ std::shared_ptr<ov::Model> SharedMatmulWeightsDecompression::initSubgraph(const ov::element::Type weights_precision,const ov::element::Type decompression_precision,const bool transpose_weights,- const DecompressionType decompression_subtract_type) {- const auto weights_subgraph = initMatMulDecompressionSubgraph(weights_shape,- group_size,- data_precision,- weights_precision,- decompression_precision,- ov::element::dynamic,- transpose_weights,- DecompressionType::full,- decompression_subtract_type,- false);+ const ov::test::utils::DecompressionType decompression_subtract_type) {+ const auto weights_subgraph =+ ov::test::utils::initMatMulDecompressionSubgraph(weights_shape,+ group_size,+ data_precision,+ weights_precision,+ decompression_precision,+ ov::element::dynamic,+ transpose_weights,+ ov::test::utils::DecompressionType::full,+ decompression_subtract_type,+ false);ov::ParameterVector params;ov::OutputVector last_layers;for (size_t i = 0; i < 2; ++i) {diff --git a/src/tests/functional/plugin/shared/src/subgraph/weights_decompression_params.cpp b/src/tests/functional/plugin/shared/src/subgraph/weights_decompression_params.cppnew file mode 100644index 00000000000..d1ff4e2309f--- /dev/null+++ b/src/tests/functional/plugin/shared/src/subgraph/weights_decompression_params.cpp@@ -0,0 +1,25 @@+// Copyright (C) 2018-2025 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "shared_test_classes/subgraph/weights_decompression_params.hpp"++namespace ov {+namespace test {+std::ostream& operator<<(std::ostream& os, MatMulDecompressionShapeParams shape_params) {+ os << "data_shape=" << shape_params.data_shape << "_weights_shape=" << shape_params.weights_shape;+ if (shape_params.decompression_group_size != -1)+ os << "_group_size=" << shape_params.decompression_group_size;+ return os;+}++std::ostream& operator<<(std::ostream& os, GatherDecompressionShapeParams shape_params) {+ os << "data_shape=" << shape_params.data_shape << "_indices_shape=" << shape_params.indices_shape;+ if (shape_params.decompression_group_size != -1)+ os << "_group_size=" << shape_params.decompression_group_size;+ os << "_axis=" << shape_params.axis << "_batch_dims=" << shape_params.batch_dims;+ return os;+}++} // namespace test+} // namespace ovdiff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/weights_decompression_builders.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/weights_decompression_builders.hppsimilarity index 61%rename from src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/weights_decompression_builders.hpprename to src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/weights_decompression_builders.hppindex 323e0aedad4..742abd43793 100644--- a/src/tests/functional/plugin/shared/include/shared_test_classes/subgraph/weights_decompression_builders.hpp+++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/weights_decompression_builders.hpp@@ -9,47 +9,10 @@#include <optional>#include "openvino/core/node.hpp"-#include "shared_test_classes/base/ov_subgraph.hpp"namespace ov {namespace test {-struct MatMulDecompressionShapeParams {- MatMulDecompressionShapeParams() = default;- MatMulDecompressionShapeParams(InputShape data_shape, ov::Shape weights_shape, int decompression_group_size = -1)- : data_shape(std::move(data_shape)),- weights_shape(std::move(weights_shape)),- decompression_group_size(decompression_group_size) {}-- InputShape data_shape;- ov::Shape weights_shape;- // Decompression group size. If the value is equal to -1, ordinary decompression is used- int decompression_group_size;-};--std::ostream& operator<<(std::ostream& os, MatMulDecompressionShapeParams type);--struct GatherDecompressionShapeParams {- GatherDecompressionShapeParams() = default;- GatherDecompressionShapeParams(ov::Shape data_shape,- InputShape indices_shape,- int axis,- int64_t batch_dims,- int decompression_group_size = -1)- : data_shape(std::move(data_shape)),- indices_shape(std::move(indices_shape)),- axis(axis),- batch_dims(batch_dims),- decompression_group_size(decompression_group_size) {}-- ov::Shape data_shape;- InputShape indices_shape;- int axis;- int64_t batch_dims;- // Decompression group size. If the value is equal to -1, ordinary decompression is used- int decompression_group_size;-};--std::ostream& operator<<(std::ostream& os, GatherDecompressionShapeParams type);+namespace utils {enum class DecompressionType {empty, // no decompression@@ -98,5 +61,6 @@ std::shared_ptr<ov::Node> initGatherDecompressionSubgraph(const ov::Shape& data_const bool per_tensor_zp,const bool per_tensor_scale);+} // namespace utils} // namespace test-} // namespace ov+} // namespace ov\ No newline at end of filediff --git a/src/tests/functional/plugin/shared/src/subgraph/weights_decompression_builders.cpp b/src/tests/test_utils/common_test_utils/src/subgraph_builders/weights_decompression_builders.cppsimilarity index 97%rename from src/tests/functional/plugin/shared/src/subgraph/weights_decompression_builders.cpprename to src/tests/test_utils/common_test_utils/src/subgraph_builders/weights_decompression_builders.cppindex a0570e09838..ffcfd0f00d7 100644--- a/src/tests/functional/plugin/shared/src/subgraph/weights_decompression_builders.cpp+++ b/src/tests/test_utils/common_test_utils/src/subgraph_builders/weights_decompression_builders.cpp@@ -2,7 +2,7 @@// SPDX-License-Identifier: Apache-2.0//-#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"#include <algorithm>#include <limits>@@ -19,20 +19,7 @@namespace ov {namespace test {-std::ostream& operator<<(std::ostream& os, MatMulDecompressionShapeParams shape_params) {- os << "data_shape=" << shape_params.data_shape << "_weights_shape=" << shape_params.weights_shape;- if (shape_params.decompression_group_size != -1)- os << "_group_size=" << shape_params.decompression_group_size;- return os;-}--std::ostream& operator<<(std::ostream& os, GatherDecompressionShapeParams shape_params) {- os << "data_shape=" << shape_params.data_shape << "_indices_shape=" << shape_params.indices_shape;- if (shape_params.decompression_group_size != -1)- os << "_group_size=" << shape_params.decompression_group_size;- os << "_axis=" << shape_params.axis << "_batch_dims=" << shape_params.batch_dims;- return os;-}+namespace utils {std::ostream& operator<<(std::ostream& os, DecompressionType type) {switch (type) {@@ -652,5 +639,6 @@ std::shared_ptr<ov::Node> initGatherDecompressionSubgraph(const ov::Shape& data_return last_node;}+} // namespace utils} // namespace test-} // namespace ov+} // namespace ov\ No newline at end of file