Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU]Add separated pass for shared expert fusion (#34896)

River Li4571746bba1d
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/convert_moe_to_compressed.cpp b/src/plugins/intel_gpu/src/plugin/transformations/convert_moe_to_compressed.cpp
index 6bb2e473369..c296a9b2c1c 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations/convert_moe_to_compressed.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations/convert_moe_to_compressed.cpp
@@ -12,9 +12,6 @@
#include "openvino/core/rt_info.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
-#include "openvino/op/swish.hpp"
-#include "openvino/op/matmul.hpp"
-#include "openvino/op/add.hpp"
#include "openvino/op/moe.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/reshape.hpp"
@@ -22,7 +19,6 @@
#include "openvino/op/slice.hpp"
#include "openvino/op/softmax.hpp"
#include "openvino/op/subtract.hpp"
-#include "openvino/op/sigmoid.hpp"
#include "openvino/op/topk.hpp"
#include "openvino/op/transpose.hpp"
#include "openvino/op/unsqueeze.hpp"
@@ -130,12 +126,13 @@ namespace ov::intel_gpu {
auto gemm3_transpose_zp_##SUFFIX = std::make_shared<ov::op::v1::Transpose>(gemm3_zp_reshape_##SUFFIX, gemm3_transpose_const_##SUFFIX);
ConvertMOEToMOECompressed::ConvertMOEToMOECompressed(bool is_pa) {
- // gemm3 pattern start
+ // gemm3 pattern start — MOE expert weight decompression chains
MOE_COMPRESSED_WEIGHT_GEMM3_PATTERN(gate);
MOE_COMPRESSED_WEIGHT_GEMM3_PATTERN(up);
MOE_COMPRESSED_WEIGHT_GEMM3_PATTERN(down);
- // shared expert pattern
+ // Shared expert weight decompression chains (present when FuseMOESharedExpert
+ // has already absorbed the shared expert subgraph into the MOE node)
MOE_COMPRESSED_WEIGHT_GEMM3_PATTERN(shared_gate);
MOE_COMPRESSED_WEIGHT_GEMM3_PATTERN(shared_up);
MOE_COMPRESSED_WEIGHT_GEMM3_PATTERN(shared_down);
@@ -144,54 +141,28 @@ ConvertMOEToMOECompressed::ConvertMOEToMOECompressed(bool is_pa) {
auto routing_weights_m = any_input();
auto topk_m = any_input();
- auto moe_root_gemm3_no_shared_expert_bare =
- wrap_type<ov::op::internal::MOE>({hidden_states_m, routing_weights_m, topk_m, gemm3_convert_m_gate, gemm3_convert_m_up, gemm3_convert_m_down},
- [](const ov::Output<ov::Node>& output) {
- auto moe = ov::as_type_ptr<ov::op::internal::MOE>(output.get_node_shared_ptr());
- return moe && moe->get_config().expert_type == ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
- });
-
- auto moe_root_gemm3_no_shared_expert =
- wrap_type<ov::op::internal::MOE>({hidden_states_m, routing_weights_m, topk_m, gemm3_convert_m_gate, gemm3_convert_m_up, gemm3_convert_m_down},
- [](const ov::Output<ov::Node>& output) {
- auto moe = ov::as_type_ptr<ov::op::internal::MOE>(output.get_node_shared_ptr());
- if (!moe || moe->get_config().expert_type != ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU) return false;
- for (auto& tg : output.get_target_inputs()) {
- if (ov::is_type<ov::op::v1::Add>(tg.get_node())) {
- auto add = tg.get_node();
- // Check both Add inputs; follow through Reshape to detect shared expert
- for (size_t i = 0; i < add->get_input_size(); i++) {
- auto n = add->get_input_node_ptr(i);
- if (n && ov::is_type<ov::op::v1::Reshape>(n))
- n = n->get_input_node_ptr(0);
- if (n && ov::is_type<ov::op::v1::Multiply>(n)) return false;
- }
- }
- }
- return true;
- });
+ auto moe_gemm3_predicate = [](const ov::Output<ov::Node>& output) {
+ auto moe = ov::as_type_ptr<ov::op::internal::MOE>(output.get_node_shared_ptr());
+ return moe && moe->get_config().expert_type == ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
+ };
- // Shared expert uses a separate hidden_states input because in the actual model,
- // MOE's hidden_states is the node BEFORE a Reshape (matmul_experts_fusion extracts input_value(0)),
- // while shared expert MatMuls take the node AFTER that Reshape.
- auto shared_hidden_states_m = any_input();
- auto shared_gate_m = wrap_type<ov::op::v0::MatMul>({shared_hidden_states_m, gemm3_convert_m_shared_gate});
- auto shared_swish_m = wrap_type<ov::op::v4::Swish>({shared_gate_m});
- auto shared_up_m = wrap_type<ov::op::v0::MatMul>({shared_hidden_states_m, gemm3_convert_m_shared_up});
- auto shared_mul_m = wrap_type<ov::op::v1::Multiply>({shared_swish_m, shared_up_m});
- auto shared_down_m = wrap_type<ov::op::v0::MatMul>({shared_mul_m, gemm3_convert_m_shared_down});
+ // 6-input MOE (no shared expert)
+ auto moe_root_gemm3_no_shared =
+ wrap_type<ov::op::internal::MOE>({hidden_states_m, routing_weights_m, topk_m,
+ gemm3_convert_m_gate, gemm3_convert_m_up, gemm3_convert_m_down},
+ moe_gemm3_predicate);
+ // 10-input MOE (with shared expert weights absorbed by FuseMOESharedExpert)
auto shared_gate_gate_wei_m = any_input();
- auto shared_gate_gate_m = wrap_type<ov::op::v0::MatMul>({shared_hidden_states_m, shared_gate_gate_wei_m});
- auto shared_gate_sigmoid_m = wrap_type<ov::op::v0::Sigmoid>({shared_gate_gate_m});
- auto shared_expert_gated_m = wrap_type<ov::op::v1::Multiply>({shared_gate_sigmoid_m, shared_down_m});
- auto shared_expert_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{shared_down_m, shared_expert_gated_m});
- auto shared_expert_reshaped_m = optional<ov::op::v1::Reshape>({shared_expert_m, any_input()});
-
- auto add_1 = wrap_type<ov::op::v1::Add>({moe_root_gemm3_no_shared_expert_bare, shared_expert_reshaped_m});
- auto add_2 = wrap_type<ov::op::v1::Add>({shared_expert_reshaped_m, moe_root_gemm3_no_shared_expert_bare});
- auto moe_root_gemm3_shared_expert = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{add_1, add_2});
- auto moe_root_gemm3 = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{moe_root_gemm3_no_shared_expert, moe_root_gemm3_shared_expert});
+ auto moe_root_gemm3_with_shared =
+ wrap_type<ov::op::internal::MOE>({hidden_states_m, routing_weights_m, topk_m,
+ gemm3_convert_m_gate, gemm3_convert_m_up, gemm3_convert_m_down,
+ gemm3_convert_m_shared_gate, gemm3_convert_m_shared_up, gemm3_convert_m_shared_down,
+ shared_gate_gate_wei_m},
+ moe_gemm3_predicate);
+
+ auto moe_root_gemm3 = std::make_shared<ov::pass::pattern::op::Or>(
+ OutputVector{moe_root_gemm3_no_shared, moe_root_gemm3_with_shared});
// gemm3 pattern finished
// =========================================================================================
// gemm2 pattern start
@@ -235,12 +206,7 @@ ConvertMOEToMOECompressed::ConvertMOEToMOECompressed(bool is_pa) {
const auto& pattern_map = m.get_pattern_value_map();
auto root_node = pattern_map.at(moe_root).get_node_shared_ptr();
- std::shared_ptr<ov::op::internal::MOE> moe;
- if (auto add_op = ov::as_type_ptr<ov::op::v1::Add>(root_node)) {
- moe = ov::as_type_ptr<ov::op::internal::MOE>(pattern_map.count(moe_root_gemm3_no_shared_expert_bare) ? pattern_map.at(moe_root_gemm3_no_shared_expert_bare).get_node_shared_ptr() : pattern_map.at(moe_root_gemm3_no_shared_expert).get_node_shared_ptr());
- } else {
- moe = ov::as_type_ptr<ov::op::internal::MOE>(root_node);
- }
+ auto moe = ov::as_type_ptr<ov::op::internal::MOE>(root_node);
if (!moe || transformation_callback(root_node)) {
return false;
}
@@ -415,13 +381,7 @@ ConvertMOEToMOECompressed::ConvertMOEToMOECompressed(bool is_pa) {
moe_compressed->set_friendly_name(moe->get_friendly_name());
ov::copy_runtime_info(moe, moe_compressed);
}
- if (has_shared_expert) {
- moe_compressed->set_friendly_name(root_node->get_friendly_name());
- ov::copy_runtime_info(root_node, moe_compressed);
- ov::replace_node(root_node, moe_compressed);
- } else {
- ov::replace_node(moe, moe_compressed);
- }
+ ov::replace_node(moe, moe_compressed);
} else if (moe->get_config().expert_type == ov::op::internal::MOE::Expert_type::GEMM2_BIAS_SWIGLU_CLAMP) {
OutputVector args;
auto topk_indice_node = pattern_map.at(topk_indices_gemm2_m);
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/fuse_moe_shared_expert.cpp b/src/plugins/intel_gpu/src/plugin/transformations/fuse_moe_shared_expert.cpp
new file mode 100644
index 00000000000..134e118c2fc
--- /dev/null
+++ b/src/plugins/intel_gpu/src/plugin/transformations/fuse_moe_shared_expert.cpp
@@ -0,0 +1,128 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "fuse_moe_shared_expert.hpp"
+
+#include <memory>
+
+#include "openvino/core/graph_util.hpp"
+#include "openvino/core/rt_info.hpp"
+#include "openvino/op/add.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/matmul.hpp"
+#include "openvino/op/moe.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/sigmoid.hpp"
+#include "openvino/op/swish.hpp"
+#include "openvino/pass/pattern/op/optional.hpp"
+#include "openvino/pass/pattern/op/or.hpp"
+#include "openvino/pass/pattern/op/wrap_type.hpp"
+#include "transformations/utils/utils.hpp"
+
+namespace ov::intel_gpu {
+
+FuseMOESharedExpert::FuseMOESharedExpert() {
+ using namespace ov::pass::pattern;
+
+ // Match the MOE node (GEMM3_SWIGLU type, 6 inputs: hidden, routing, topk, gate, up, down)
+ auto hidden_states_m = any_input();
+ auto routing_weights_m = any_input();
+ auto topk_m = any_input();
+ auto gate_weight_m = any_input();
+ auto up_weight_m = any_input();
+ auto down_weight_m = any_input();
+
+ auto moe_m = wrap_type<ov::op::internal::MOE>({hidden_states_m, routing_weights_m, topk_m, gate_weight_m, up_weight_m, down_weight_m},
+ [](const ov::Output<ov::Node>& output) {
+ auto moe = ov::as_type_ptr<ov::op::internal::MOE>(output.get_node_shared_ptr());
+ return moe && moe->get_config().expert_type == ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
+ });
+
+ // Shared expert subgraph:
+ // shared_gate = MatMul(shared_hidden, shared_gate_weight)
+ // shared_swish = Swish(shared_gate)
+ // shared_up = MatMul(shared_hidden, shared_up_weight)
+ // shared_mul = Mul(shared_swish, shared_up)
+ // shared_down = MatMul(shared_mul, shared_down_weight)
+ // Optional gating: sigmoid(MatMul(shared_hidden, gate_gate_weight)) * shared_down
+ // Optional reshape before Add
+ auto shared_hidden_states_m = any_input();
+ auto shared_gate_weight_m = any_input();
+ auto shared_gate_m = wrap_type<ov::op::v0::MatMul>({shared_hidden_states_m, shared_gate_weight_m});
+ auto shared_swish_m = wrap_type<ov::op::v4::Swish>({shared_gate_m});
+ auto shared_up_weight_m = any_input();
+ auto shared_up_m = wrap_type<ov::op::v0::MatMul>({shared_hidden_states_m, shared_up_weight_m});
+ // Multiply is commutative: handle both input orders
+ auto shared_mul_m_1 = wrap_type<ov::op::v1::Multiply>({shared_swish_m, shared_up_m});
+ auto shared_mul_m_2 = wrap_type<ov::op::v1::Multiply>({shared_up_m, shared_swish_m});
+ auto shared_mul_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{shared_mul_m_1, shared_mul_m_2});
+ auto shared_down_weight_m = any_input();
+ auto shared_down_m = wrap_type<ov::op::v0::MatMul>({shared_mul_m, shared_down_weight_m});
+
+ // Optional sigmoid gating: sigmoid(MatMul(hidden, gate_gate)) * down
+ auto shared_gate_gate_wei_m = any_input();
+ auto shared_gate_gate_m = wrap_type<ov::op::v0::MatMul>({shared_hidden_states_m, shared_gate_gate_wei_m});
+ auto shared_gate_sigmoid_m = wrap_type<ov::op::v0::Sigmoid>({shared_gate_gate_m});
+ // Multiply is commutative: handle both input orders
+ auto shared_expert_gated_m_1 = wrap_type<ov::op::v1::Multiply>({shared_gate_sigmoid_m, shared_down_m});
+ auto shared_expert_gated_m_2 = wrap_type<ov::op::v1::Multiply>({shared_down_m, shared_gate_sigmoid_m});
+ auto shared_expert_gated_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{shared_expert_gated_m_1, shared_expert_gated_m_2});
+ auto shared_expert_m = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{shared_down_m, shared_expert_gated_m});
+ auto shared_expert_reshaped_m = optional<ov::op::v1::Reshape>({shared_expert_m, any_input()});
+
+ // Root: Add(MOE, SharedExpert) or Add(SharedExpert, MOE)
+ auto add_1 = wrap_type<ov::op::v1::Add>({moe_m, shared_expert_reshaped_m});
+ auto add_2 = wrap_type<ov::op::v1::Add>({shared_expert_reshaped_m, moe_m});
+ auto root = std::make_shared<ov::pass::pattern::op::Or>(OutputVector{add_1, add_2});
+
+ ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& m) {
+ const auto& pattern_map = m.get_pattern_value_map();
+
+ auto root_node = pattern_map.at(root).get_node_shared_ptr();
+ auto moe = ov::as_type_ptr<ov::op::internal::MOE>(pattern_map.at(moe_m).get_node_shared_ptr());
+ if (!moe || transformation_callback(root_node)) {
+ return false;
+ }
+
+ // Build new MOE with shared expert weights as additional inputs:
+ // {hidden, routing, topk, gate, up, down, sh_gate, sh_up, sh_down, gate_gate}
+ OutputVector new_inputs = {
+ moe->input_value(0), // hidden_states
+ moe->input_value(1), // routing_weights
+ moe->input_value(2), // topk_indices
+ moe->input_value(3), // gate weight (decompressed)
+ moe->input_value(4), // up weight (decompressed)
+ moe->input_value(5), // down weight (decompressed)
+ pattern_map.at(shared_gate_weight_m), // shared gate weight
+ pattern_map.at(shared_up_weight_m), // shared up weight
+ pattern_map.at(shared_down_weight_m), // shared down weight
+ };
+
+ // Use shared_gate_sigmoid_m to reliably detect whether the gating branch matched.
+ // shared_gate_gate_wei_m is any_input() and may be spuriously bound even when
+ // the Or pattern took the non-gating (shared_down_m) branch.
+ bool has_gating = pattern_map.count(shared_gate_sigmoid_m) > 0;
+ if (has_gating) {
+ new_inputs.push_back(pattern_map.at(shared_gate_gate_wei_m));
+ } else {
+ // Models without gate_gate: insert a dummy so input count is always 10
+ size_t hidden_size = moe->get_output_partial_shape(0).rbegin()->get_length();
+ new_inputs.push_back(
+ ov::op::v0::Constant::create(ov::element::f16, ov::Shape{hidden_size, 1}, std::vector<float>(hidden_size, 0.0f)));
+ }
+
+ auto new_moe = std::make_shared<ov::op::internal::MOE>(new_inputs, moe->get_config());
+ new_moe->set_friendly_name(root_node->get_friendly_name());
+ ov::copy_runtime_info({moe, root_node}, new_moe);
+ ov::replace_node(root_node, new_moe);
+
+ return true;
+ };
+
+ auto m = std::make_shared<ov::pass::pattern::Matcher>(root, "FuseMOESharedExpert");
+ this->register_matcher(m, callback);
+}
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/fuse_moe_shared_expert.hpp b/src/plugins/intel_gpu/src/plugin/transformations/fuse_moe_shared_expert.hpp
new file mode 100644
index 00000000000..b28cf20d1d6
--- /dev/null
+++ b/src/plugins/intel_gpu/src/plugin/transformations/fuse_moe_shared_expert.hpp
@@ -0,0 +1,29 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "openvino/pass/graph_rewrite.hpp"
+
+namespace ov::intel_gpu {
+
+/// Fuse shared expert subgraph (gate/up/down MatMuls + optional sigmoid gating)
+/// into the MOE node as additional inputs, absorbing the surrounding Add.
+///
+/// Before:
+/// Add(MOE(hidden, routing, topk, gate, up, down),
+/// Reshape?(Mul?(Sigmoid(MatMul(x, gate_gate)), MatMul(Mul(Swish(MatMul(x, sh_gate)), MatMul(x, sh_up)), sh_down))))
+///
+/// After:
+/// MOE(hidden, routing, topk, gate, up, down, sh_gate, sh_up, sh_down, gate_gate)
+///
+/// This pass should run BEFORE ConvertMOEToMOECompressed so that the compressed
+/// conversion pass handles weight extraction uniformly for all MOE weight inputs.
+class FuseMOESharedExpert : public ov::pass::MatcherPass {
+public:
+ OPENVINO_MATCHER_PASS_RTTI("FuseMOESharedExpert");
+ FuseMOESharedExpert();
+};
+
+} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
index ab112a0d40c..c247c52f01f 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations_pipeline.cpp
@@ -79,6 +79,7 @@
#include "plugin/transformations/convert_fc_to_compressed.hpp"
#include "plugin/transformations/convert_matmul_to_fc.hpp"
#include "plugin/transformations/convert_moe_to_compressed.hpp"
+#include "plugin/transformations/fuse_moe_shared_expert.hpp"
#include "plugin/transformations/convert_stridedslices_to_variadicsplit.hpp"
#include "plugin/transformations/decompose_reduce_scalar_output.hpp"
#include "plugin/transformations/dynamic_quantize_fully_connected.hpp"
@@ -500,6 +501,7 @@ void TransformationsPipeline::apply(std::shared_ptr<ov::Model> func) {
break;
}
}
+ manager.register_pass<ov::intel_gpu::FuseMOESharedExpert>();
manager.register_pass<ov::intel_gpu::ConvertMOEToMOECompressed>(is_pa);
manager.register_pass<ov::intel_gpu::FuseMOE3GemmCompressed>();
}
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/convert_moe_to_compressed_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/convert_moe_to_compressed_test.cpp
index 5ec82cca7d2..bb45e051a24 100644
--- a/src/plugins/intel_gpu/tests/unit/transformations/convert_moe_to_compressed_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/transformations/convert_moe_to_compressed_test.cpp
@@ -7,26 +7,14 @@
#include "common_test_utils/ov_test_utils.hpp"
#include "intel_gpu/op/moe_compressed.hpp"
#include "intel_gpu/op/placeholder.hpp"
-#include "openvino/op/add.hpp"
-#include "openvino/op/concat.hpp"
+#include "openvino/op/constant.hpp"
#include "openvino/op/convert.hpp"
-#include "openvino/op/matmul.hpp"
#include "openvino/op/moe.hpp"
#include "openvino/op/multiply.hpp"
#include "openvino/op/reshape.hpp"
-#include "openvino/op/shape_of.hpp"
-#include "openvino/op/split.hpp"
#include "openvino/op/subtract.hpp"
#include "openvino/op/transpose.hpp"
-#include "openvino/op/variadic_split.hpp"
#include "plugin/transformations/convert_moe_to_compressed.hpp"
-#include "openvino/op/swish.hpp"
-#include "openvino/op/matmul.hpp"
-#include "openvino/op/constant.hpp"
-#include "openvino/op/multiply.hpp"
-#include "openvino/op/add.hpp"
-
-#include "openvino/op/sigmoid.hpp"
using namespace testing;
using namespace ov::intel_gpu;
@@ -290,17 +278,17 @@ INSTANTIATE_TEST_SUITE_P(smoke,
TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertCompressedTest) {
disable_rt_info_check();
{
- // tokens:32, hidden_size:2048, iter_size:768, experts:128, topk:8
+ // Input: 10-input MOE (shared expert weights already absorbed by FuseMOESharedExpert)
+ // tokens:32, hidden_size:2048, inter_size:768, experts:128, topk:8
auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
- // Gate projection
+ // Gate projection decompression chain
auto wei_gate = op::v0::Constant::create(element::u4, Shape{128, 768, 16, 128}, {1});
auto zp_gate = op::v0::Constant::create(element::u4, Shape{128, 768, 16, 1}, {0});
auto scale_gate = op::v0::Constant::create(element::f16, Shape{128, 768, 16, 1}, {0.01f});
auto reshape_const_gate = op::v0::Constant::create(element::i32, Shape{3}, {128, 768, 2048});
-
auto w_gate_f16 = std::make_shared<op::v0::Convert>(wei_gate, element::f16);
auto zp_gate_f16 = std::make_shared<op::v0::Convert>(zp_gate, element::f16);
auto sub_gate = std::make_shared<op::v1::Subtract>(w_gate_f16, zp_gate_f16);
@@ -308,12 +296,11 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertCompressedTest) {
auto reshape_gate = std::make_shared<op::v1::Reshape>(mul_gate, reshape_const_gate, false);
auto convert_gate = std::make_shared<op::v0::Convert>(reshape_gate, element::f32);
- // Up projection
+ // Up projection decompression chain
auto wei_up = op::v0::Constant::create(element::u4, Shape{128, 768, 16, 128}, {1});
auto zp_up = op::v0::Constant::create(element::u4, Shape{128, 768, 16, 1}, {0});
auto scale_up = op::v0::Constant::create(element::f16, Shape{128, 768, 16, 1}, {0.01f});
auto reshape_const_up = op::v0::Constant::create(element::i32, Shape{3}, {128, 768, 2048});
-
auto w_up_f16 = std::make_shared<op::v0::Convert>(wei_up, element::f16);
auto zp_up_f16 = std::make_shared<op::v0::Convert>(zp_up, element::f16);
auto sub_up = std::make_shared<op::v1::Subtract>(w_up_f16, zp_up_f16);
@@ -321,12 +308,11 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertCompressedTest) {
auto reshape_up = std::make_shared<op::v1::Reshape>(mul_up, reshape_const_up, false);
auto convert_up = std::make_shared<op::v0::Convert>(reshape_up, element::f32);
- // Down projection
+ // Down projection decompression chain
auto wei_down = op::v0::Constant::create(element::u4, Shape{128, 2048, 6, 128}, {1});
auto zp_down = op::v0::Constant::create(element::u4, Shape{128, 2048, 6, 1}, {0});
auto scale_down = op::v0::Constant::create(element::f16, Shape{128, 2048, 6, 1}, {0.01f});
auto reshape_const_down = op::v0::Constant::create(element::i32, Shape{3}, {128, 2048, 768});
-
auto wei_down_f16 = std::make_shared<op::v0::Convert>(wei_down, element::f16);
auto zp_down_f16 = std::make_shared<op::v0::Convert>(zp_down, element::f16);
auto sub_down = std::make_shared<op::v1::Subtract>(wei_down_f16, zp_down_f16);
@@ -334,7 +320,7 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertCompressedTest) {
auto reshape_down = std::make_shared<op::v1::Reshape>(mul_down, reshape_const_down, false);
auto convert_down = std::make_shared<op::v0::Convert>(reshape_down, element::f32);
- // Shared expert Gate projection (separate weights, 3D without num_experts dim)
+ // Shared expert decompression chains (3D without num_experts dim)
auto sh_wei_gate = op::v0::Constant::create(element::u4, Shape{768, 16, 128}, {2});
auto sh_zp_gate = op::v0::Constant::create(element::u4, Shape{768, 16, 1}, {1});
auto sh_scale_gate = op::v0::Constant::create(element::f16, Shape{768, 16, 1}, {0.02f});
@@ -346,7 +332,6 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertCompressedTest) {
auto sh_reshape_gate = std::make_shared<op::v1::Reshape>(sh_mul_gate, sh_reshape_const_gate, false);
auto sh_convert_gate = std::make_shared<op::v0::Convert>(sh_reshape_gate, element::f32);
- // Shared expert Up projection (separate weights, 3D without num_experts dim)
auto sh_wei_up = op::v0::Constant::create(element::u4, Shape{768, 16, 128}, {2});
auto sh_zp_up = op::v0::Constant::create(element::u4, Shape{768, 16, 1}, {1});
auto sh_scale_up = op::v0::Constant::create(element::f16, Shape{768, 16, 1}, {0.02f});
@@ -358,7 +343,6 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertCompressedTest) {
auto sh_reshape_up = std::make_shared<op::v1::Reshape>(sh_mul_up, sh_reshape_const_up, false);
auto sh_convert_up = std::make_shared<op::v0::Convert>(sh_reshape_up, element::f32);
- // Shared expert Down projection (separate weights, 3D without num_experts dim)
auto sh_wei_down = op::v0::Constant::create(element::u4, Shape{2048, 6, 128}, {2});
auto sh_zp_down = op::v0::Constant::create(element::u4, Shape{2048, 6, 1}, {1});
auto sh_scale_down = op::v0::Constant::create(element::f16, Shape{2048, 6, 1}, {0.02f});
@@ -370,39 +354,19 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertCompressedTest) {
auto sh_reshape_down = std::make_shared<op::v1::Reshape>(sh_mul_down, sh_reshape_const_down, false);
auto sh_convert_down = std::make_shared<op::v0::Convert>(sh_reshape_down, element::f32);
- // Construct MOE node
+ // Gate_gate weight (passed through as-is by FuseMOESharedExpert)
+ auto shared_gate_gate_wei_m = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
+
+ // Construct 10-input MOE node (as produced by FuseMOESharedExpert)
ov::op::internal::MOE::Config config;
config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
- auto moe =
- std::make_shared<ov::op::internal::MOE>(ov::OutputVector{hidden_states_f32, routing_weights, routing_idx, convert_gate, convert_up, convert_down},
- config);
-
- // In the actual model (Qwen3-Next), shared expert MatMuls use hidden_states
- // from a different node (after a Reshape) than MOE's hidden_states input.
- // matmul_experts_fusion extracts input_value(0) of the Reshape as MOE's hidden_states,
- // while the shared expert MatMuls take the Reshape output directly.
- auto reshape_const_hs = op::v0::Constant::create(element::i64, Shape{2}, {32, 2048});
- auto hidden_states_reshaped = std::make_shared<ov::op::v1::Reshape>(hidden_states_f32, reshape_const_hs, false);
-
- // Shared expert computation (using separate weights and reshaped hidden_states)
- auto shared_gate_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_convert_gate, false, true);
- auto shared_swish_m = std::make_shared<ov::op::v4::Swish>(shared_gate_m);
- auto shared_up_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_convert_up, false, true);
- auto shared_mul_m = std::make_shared<ov::op::v1::Multiply>(shared_swish_m, shared_up_m);
- auto shared_down_m = std::make_shared<ov::op::v0::MatMul>(shared_mul_m, sh_convert_down, false, true);
- auto shared_gate_gate_wei_m = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
- auto shared_gate_gate_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, shared_gate_gate_wei_m);
- auto shared_gate_sigmoid_m = std::make_shared<ov::op::v0::Sigmoid>(shared_gate_gate_m);
- auto shared_expert_gated_m = std::make_shared<ov::op::v1::Multiply>(shared_gate_sigmoid_m, shared_down_m);
-
- // In the actual model, there's a Reshape between the gated shared expert output and the Add
- auto reshape_const_output = op::v0::Constant::create(element::i64, Shape{2}, {32, 2048});
- auto shared_expert_reshaped = std::make_shared<ov::op::v1::Reshape>(shared_expert_gated_m, reshape_const_output, false);
-
- auto add_m = std::make_shared<ov::op::v1::Add>(shared_expert_reshaped, moe);
-
- model = std::make_shared<ov::Model>(add_m, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ auto moe = std::make_shared<ov::op::internal::MOE>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ convert_gate, convert_up, convert_down,
+ sh_convert_gate, sh_convert_up, sh_convert_down,
+ shared_gate_gate_wei_m}, config);
+ model = std::make_shared<ov::Model>(moe, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
manager.register_pass<ConvertMOEToMOECompressed>(0);
}
{
@@ -482,30 +446,16 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertCompressedTest) {
config.out_type = ov::element::f16;
auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
auto shared_gate_gate_wei_m = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
- std::shared_ptr<ov::Node> moe_compressed = std::make_shared<ov::intel_gpu::op::MOECompressed>(ov::OutputVector{hidden_states_f32,
- routing_weights,
- routing_idx,
- wei_gate,
- scale_transpose_gate,
- zp_transpose_gate,
- wei_up,
- scale_transpose_up,
- zp_transpose_up,
- wei_down,
- scale_transpose_down,
- zp_transpose_down,
- sh_wei_gate,
- sh_scale_transpose_gate,
- sh_zp_transpose_gate,
- sh_wei_up,
- sh_scale_transpose_up,
- sh_zp_transpose_up,
- sh_wei_down,
- sh_scale_transpose_down,
- sh_zp_transpose_down,
- shared_gate_gate_wei_m},
- config);
- // MOECompressed outputs f16, but the input model outputs f32 (Add of f32 MOE + f32 shared expert),
+ std::shared_ptr<ov::Node> moe_compressed = std::make_shared<ov::intel_gpu::op::MOECompressed>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ wei_gate, scale_transpose_gate, zp_transpose_gate,
+ wei_up, scale_transpose_up, zp_transpose_up,
+ wei_down, scale_transpose_down, zp_transpose_down,
+ sh_wei_gate, sh_scale_transpose_gate, sh_zp_transpose_gate,
+ sh_wei_up, sh_scale_transpose_up, sh_zp_transpose_up,
+ sh_wei_down, sh_scale_transpose_down, sh_zp_transpose_down,
+ shared_gate_gate_wei_m}, config);
+ // MOECompressed outputs f16, but the input MOE outputs f32,
// so the transformation inserts a Convert(f16->f32) to preserve the original output type.
moe_compressed = std::make_shared<ov::op::v0::Convert>(moe_compressed, element::f32);
model_ref = std::make_shared<ov::Model>(moe_compressed, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
@@ -645,15 +595,16 @@ INSTANTIATE_TEST_SUITE_P(smoke,
Values(element::f16, element::f32),
ConvertMOEToMOE3GemmAsymmetricU8CompressedTest::get_test_case_name);
-// Test asymmetric u8 weight compression with shared expert
+// Test asymmetric u8 weight compression with shared expert (10-input MOE, post-FuseMOESharedExpert)
TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertAsymU8CompressedTest) {
disable_rt_info_check();
{
+ // Input: 10-input MOE (shared expert weights already absorbed by FuseMOESharedExpert)
auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
- // Gate projection (asymmetric u8)
+ // Expert gate projection (asymmetric u8)
auto wei_gate = op::v0::Constant::create(element::u8, Shape{128, 768, 16, 128}, {1});
auto zp_gate = op::v0::Constant::create(element::u8, Shape{128, 768, 16, 1}, {0});
auto scale_gate = op::v0::Constant::create(element::f16, Shape{128, 768, 16, 1}, {0.01f});
@@ -665,7 +616,7 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertAsymU8CompressedTes
auto reshape_gate = std::make_shared<op::v1::Reshape>(mul_gate, reshape_const_gate, false);
auto convert_gate = std::make_shared<op::v0::Convert>(reshape_gate, element::f32);
- // Up projection (asymmetric u8)
+ // Expert up projection (asymmetric u8)
auto wei_up = op::v0::Constant::create(element::u8, Shape{128, 768, 16, 128}, {1});
auto zp_up = op::v0::Constant::create(element::u8, Shape{128, 768, 16, 1}, {0});
auto scale_up = op::v0::Constant::create(element::f16, Shape{128, 768, 16, 1}, {0.01f});
@@ -677,7 +628,7 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertAsymU8CompressedTes
auto reshape_up = std::make_shared<op::v1::Reshape>(mul_up, reshape_const_up, false);
auto convert_up = std::make_shared<op::v0::Convert>(reshape_up, element::f32);
- // Down projection (asymmetric u8)
+ // Expert down projection (asymmetric u8)
auto wei_down = op::v0::Constant::create(element::u8, Shape{128, 2048, 6, 128}, {1});
auto zp_down = op::v0::Constant::create(element::u8, Shape{128, 2048, 6, 1}, {0});
auto scale_down = op::v0::Constant::create(element::f16, Shape{128, 2048, 6, 1}, {0.01f});
@@ -689,7 +640,7 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertAsymU8CompressedTes
auto reshape_down = std::make_shared<op::v1::Reshape>(mul_down, reshape_const_down, false);
auto convert_down = std::make_shared<op::v0::Convert>(reshape_down, element::f32);
- // Shared expert projections (asymmetric u8, 3D without num_experts dim)
+ // Shared expert decompression chains (asymmetric u8, 3D without num_experts dim)
auto sh_wei_gate = op::v0::Constant::create(element::u8, Shape{768, 16, 128}, {2});
auto sh_zp_gate = op::v0::Constant::create(element::u8, Shape{768, 16, 1}, {1});
auto sh_scale_gate = op::v0::Constant::create(element::f16, Shape{768, 16, 1}, {0.02f});
@@ -723,31 +674,19 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertAsymU8CompressedTes
auto sh_reshape_down = std::make_shared<op::v1::Reshape>(sh_mul_down, sh_reshape_const_down, false);
auto sh_convert_down = std::make_shared<op::v0::Convert>(sh_reshape_down, element::f32);
+ // Gate_gate weight
+ auto shared_gate_gate_wei_m = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
+
+ // Construct 10-input MOE node (as produced by FuseMOESharedExpert)
ov::op::internal::MOE::Config config;
config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
- auto moe =
- std::make_shared<ov::op::internal::MOE>(ov::OutputVector{hidden_states_f32, routing_weights, routing_idx, convert_gate, convert_up, convert_down},
- config);
-
- auto reshape_const_hs = op::v0::Constant::create(element::i64, Shape{2}, {32, 2048});
- auto hidden_states_reshaped = std::make_shared<ov::op::v1::Reshape>(hidden_states_f32, reshape_const_hs, false);
-
- auto shared_gate_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_convert_gate, false, true);
- auto shared_swish_m = std::make_shared<ov::op::v4::Swish>(shared_gate_m);
- auto shared_up_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_convert_up, false, true);
- auto shared_mul_m = std::make_shared<ov::op::v1::Multiply>(shared_swish_m, shared_up_m);
- auto shared_down_m = std::make_shared<ov::op::v0::MatMul>(shared_mul_m, sh_convert_down, false, true);
- auto shared_gate_gate_wei_m = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
- auto shared_gate_gate_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, shared_gate_gate_wei_m);
- auto shared_gate_sigmoid_m = std::make_shared<ov::op::v0::Sigmoid>(shared_gate_gate_m);
- auto shared_expert_gated_m = std::make_shared<ov::op::v1::Multiply>(shared_gate_sigmoid_m, shared_down_m);
-
- auto reshape_const_output = op::v0::Constant::create(element::i64, Shape{2}, {32, 2048});
- auto shared_expert_reshaped = std::make_shared<ov::op::v1::Reshape>(shared_expert_gated_m, reshape_const_output, false);
- auto add_m = std::make_shared<ov::op::v1::Add>(shared_expert_reshaped, moe);
-
- model = std::make_shared<ov::Model>(add_m, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ auto moe = std::make_shared<ov::op::internal::MOE>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ convert_gate, convert_up, convert_down,
+ sh_convert_gate, sh_convert_up, sh_convert_down,
+ shared_gate_gate_wei_m}, config);
+ model = std::make_shared<ov::Model>(moe, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
manager.register_pass<ConvertMOEToMOECompressed>(0);
}
{
@@ -824,29 +763,169 @@ TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertAsymU8CompressedTes
config.out_type = ov::element::f16;
auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
auto shared_gate_gate_wei_m = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
- std::shared_ptr<ov::Node> moe_compressed = std::make_shared<ov::intel_gpu::op::MOECompressed>(ov::OutputVector{hidden_states_f32,
- routing_weights,
- routing_idx,
- wei_gate,
- scale_transpose_gate,
- zp_transpose_gate,
- wei_up,
- scale_transpose_up,
- zp_transpose_up,
- wei_down,
- scale_transpose_down,
- zp_transpose_down,
- sh_wei_gate,
- sh_scale_transpose_gate,
- sh_zp_transpose_gate,
- sh_wei_up,
- sh_scale_transpose_up,
- sh_zp_transpose_up,
- sh_wei_down,
- sh_scale_transpose_down,
- sh_zp_transpose_down,
- shared_gate_gate_wei_m},
- config);
+ std::shared_ptr<ov::Node> moe_compressed = std::make_shared<ov::intel_gpu::op::MOECompressed>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ wei_gate, scale_transpose_gate, zp_transpose_gate,
+ wei_up, scale_transpose_up, zp_transpose_up,
+ wei_down, scale_transpose_down, zp_transpose_down,
+ sh_wei_gate, sh_scale_transpose_gate, sh_zp_transpose_gate,
+ sh_wei_up, sh_scale_transpose_up, sh_zp_transpose_up,
+ sh_wei_down, sh_scale_transpose_down, sh_zp_transpose_down,
+ shared_gate_gate_wei_m}, config);
+ moe_compressed = std::make_shared<ov::op::v0::Convert>(moe_compressed, element::f32);
+ model_ref = std::make_shared<ov::Model>(moe_compressed, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ }
+}
+
+// Test symmetric i4 weight compression with shared expert (10-input MOE, post-FuseMOESharedExpert)
+TEST_F(TransformationTestsF, ConvertMOEToMOE3GemmSharedExpertSymmetricCompressedTest) {
+ disable_rt_info_check();
+ {
+ // Input: 10-input MOE with sym-quant expert weights (Convert -> Mul, no Subtract)
+ auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
+ auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
+ auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
+
+ // Expert gate (symmetric i4: Convert -> Multiply(scale), no Subtract)
+ auto wei_gate = op::v0::Constant::create(element::i4, Shape{128, 768, 16, 128}, {1});
+ auto scale_gate = op::v0::Constant::create(element::f16, Shape{128, 768, 16, 1}, {0.01f});
+ auto reshape_const_gate = op::v0::Constant::create(element::i32, Shape{3}, {128, 768, 2048});
+ auto w_gate_f16 = std::make_shared<op::v0::Convert>(wei_gate, element::f16);
+ auto mul_gate = std::make_shared<op::v1::Multiply>(w_gate_f16, scale_gate);
+ auto reshape_gate = std::make_shared<op::v1::Reshape>(mul_gate, reshape_const_gate, false);
+ auto convert_gate = std::make_shared<op::v0::Convert>(reshape_gate, element::f32);
+
+ // Expert up (symmetric i4)
+ auto wei_up = op::v0::Constant::create(element::i4, Shape{128, 768, 16, 128}, {1});
+ auto scale_up = op::v0::Constant::create(element::f16, Shape{128, 768, 16, 1}, {0.01f});
+ auto reshape_const_up = op::v0::Constant::create(element::i32, Shape{3}, {128, 768, 2048});
+ auto w_up_f16 = std::make_shared<op::v0::Convert>(wei_up, element::f16);
+ auto mul_up = std::make_shared<op::v1::Multiply>(w_up_f16, scale_up);
+ auto reshape_up = std::make_shared<op::v1::Reshape>(mul_up, reshape_const_up, false);
+ auto convert_up = std::make_shared<op::v0::Convert>(reshape_up, element::f32);
+
+ // Expert down (symmetric i4)
+ auto wei_down = op::v0::Constant::create(element::i4, Shape{128, 2048, 6, 128}, {1});
+ auto scale_down = op::v0::Constant::create(element::f16, Shape{128, 2048, 6, 1}, {0.01f});
+ auto reshape_const_down = op::v0::Constant::create(element::i32, Shape{3}, {128, 2048, 768});
+ auto wei_down_f16 = std::make_shared<op::v0::Convert>(wei_down, element::f16);
+ auto mul_down = std::make_shared<op::v1::Multiply>(wei_down_f16, scale_down);
+ auto reshape_down = std::make_shared<op::v1::Reshape>(mul_down, reshape_const_down, false);
+ auto convert_down = std::make_shared<op::v0::Convert>(reshape_down, element::f32);
+
+ // Shared expert (symmetric i4, 3D without num_experts dim)
+ auto sh_wei_gate = op::v0::Constant::create(element::i4, Shape{768, 16, 128}, {2});
+ auto sh_scale_gate = op::v0::Constant::create(element::f16, Shape{768, 16, 1}, {0.02f});
+ auto sh_reshape_const_gate = op::v0::Constant::create(element::i32, Shape{2}, {768, 2048});
+ auto sh_w_gate_f16 = std::make_shared<op::v0::Convert>(sh_wei_gate, element::f16);
+ auto sh_mul_gate = std::make_shared<op::v1::Multiply>(sh_w_gate_f16, sh_scale_gate);
+ auto sh_reshape_gate = std::make_shared<op::v1::Reshape>(sh_mul_gate, sh_reshape_const_gate, false);
+ auto sh_convert_gate = std::make_shared<op::v0::Convert>(sh_reshape_gate, element::f32);
+
+ auto sh_wei_up = op::v0::Constant::create(element::i4, Shape{768, 16, 128}, {2});
+ auto sh_scale_up = op::v0::Constant::create(element::f16, Shape{768, 16, 1}, {0.02f});
+ auto sh_reshape_const_up = op::v0::Constant::create(element::i32, Shape{2}, {768, 2048});
+ auto sh_w_up_f16 = std::make_shared<op::v0::Convert>(sh_wei_up, element::f16);
+ auto sh_mul_up = std::make_shared<op::v1::Multiply>(sh_w_up_f16, sh_scale_up);
+ auto sh_reshape_up = std::make_shared<op::v1::Reshape>(sh_mul_up, sh_reshape_const_up, false);
+ auto sh_convert_up = std::make_shared<op::v0::Convert>(sh_reshape_up, element::f32);
+
+ auto sh_wei_down = op::v0::Constant::create(element::i4, Shape{2048, 6, 128}, {2});
+ auto sh_scale_down = op::v0::Constant::create(element::f16, Shape{2048, 6, 1}, {0.02f});
+ auto sh_reshape_const_down = op::v0::Constant::create(element::i32, Shape{2}, {2048, 768});
+ auto sh_w_down_f16 = std::make_shared<op::v0::Convert>(sh_wei_down, element::f16);
+ auto sh_mul_down = std::make_shared<op::v1::Multiply>(sh_w_down_f16, sh_scale_down);
+ auto sh_reshape_down = std::make_shared<op::v1::Reshape>(sh_mul_down, sh_reshape_const_down, false);
+ auto sh_convert_down = std::make_shared<op::v0::Convert>(sh_reshape_down, element::f32);
+
+ // Gate_gate weight
+ auto shared_gate_gate_wei_m = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
+
+ // Construct 10-input MOE node
+ ov::op::internal::MOE::Config config;
+ config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
+ auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
+ auto moe = std::make_shared<ov::op::internal::MOE>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ convert_gate, convert_up, convert_down,
+ sh_convert_gate, sh_convert_up, sh_convert_down,
+ shared_gate_gate_wei_m}, config);
+ model = std::make_shared<ov::Model>(moe, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ manager.register_pass<ConvertMOEToMOECompressed>(0);
+ }
+ {
+ auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
+ auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
+ auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
+
+ auto reshape_const_gate_up = op::v0::Constant::create(element::i32, Shape{3}, {128, 768, 16});
+ auto transpose_const_gate_up = op::v0::Constant::create(element::i32, Shape{3}, {0, 2, 1});
+
+ // Expert weights (sym: no ZP, dummy scalar ZP inserted)
+ auto wei_gate = op::v0::Constant::create(element::i4, Shape{128, 768, 16, 128}, {1});
+ auto scale_gate = op::v0::Constant::create(element::f16, Shape{128, 768, 16, 1}, {0.01f});
+ auto scale_reshape_gate = std::make_shared<op::v1::Reshape>(scale_gate, reshape_const_gate_up, false);
+ auto scale_transpose_gate = std::make_shared<ov::op::v1::Transpose>(scale_reshape_gate, transpose_const_gate_up);
+ auto zp_gate_dummy = op::v0::Constant::create(element::i4, Shape{1}, {0});
+
+ auto wei_up = op::v0::Constant::create(element::i4, Shape{128, 768, 16, 128}, {1});
+ auto scale_up = op::v0::Constant::create(element::f16, Shape{128, 768, 16, 1}, {0.01f});
+ auto scale_reshape_up = std::make_shared<op::v1::Reshape>(scale_up, reshape_const_gate_up, false);
+ auto scale_transpose_up = std::make_shared<ov::op::v1::Transpose>(scale_reshape_up, transpose_const_gate_up);
+ auto zp_up_dummy = op::v0::Constant::create(element::i4, Shape{1}, {0});
+
+ auto wei_down = op::v0::Constant::create(element::i4, Shape{128, 2048, 6, 128}, {1});
+ auto scale_down = op::v0::Constant::create(element::f16, Shape{128, 2048, 6, 1}, {0.01f});
+ auto reshape_const_down = op::v0::Constant::create(element::i32, Shape{3}, {128, 2048, 6});
+ auto transpose_const_down = op::v0::Constant::create(element::i32, Shape{3}, {0, 2, 1});
+ auto scale_reshape_down = std::make_shared<op::v1::Reshape>(scale_down, reshape_const_down, false);
+ auto scale_transpose_down = std::make_shared<ov::op::v1::Transpose>(scale_reshape_down, transpose_const_down);
+ auto zp_down_dummy = op::v0::Constant::create(element::i4, Shape{1}, {0});
+
+ // Shared expert weights (sym, 3D)
+ auto sh_reshape_const_gate_up = op::v0::Constant::create(element::i32, Shape{2}, {768, 16});
+ auto sh_transpose_const_gate_up = op::v0::Constant::create(element::i32, Shape{2}, {1, 0});
+
+ auto sh_wei_gate = op::v0::Constant::create(element::i4, Shape{768, 16, 128}, {2});
+ auto sh_scale_gate = op::v0::Constant::create(element::f16, Shape{768, 16, 1}, {0.02f});
+ auto sh_scale_reshape_gate = std::make_shared<op::v1::Reshape>(sh_scale_gate, sh_reshape_const_gate_up, false);
+ auto sh_scale_transpose_gate = std::make_shared<ov::op::v1::Transpose>(sh_scale_reshape_gate, sh_transpose_const_gate_up);
+ auto sh_zp_gate_dummy = op::v0::Constant::create(element::i4, Shape{1}, {0});
+
+ auto sh_wei_up = op::v0::Constant::create(element::i4, Shape{768, 16, 128}, {2});
+ auto sh_scale_up = op::v0::Constant::create(element::f16, Shape{768, 16, 1}, {0.02f});
+ auto sh_scale_reshape_up = std::make_shared<op::v1::Reshape>(sh_scale_up, sh_reshape_const_gate_up, false);
+ auto sh_scale_transpose_up = std::make_shared<ov::op::v1::Transpose>(sh_scale_reshape_up, sh_transpose_const_gate_up);
+ auto sh_zp_up_dummy = op::v0::Constant::create(element::i4, Shape{1}, {0});
+
+ auto sh_reshape_const_down = op::v0::Constant::create(element::i32, Shape{2}, {2048, 6});
+ auto sh_transpose_const_down = op::v0::Constant::create(element::i32, Shape{2}, {1, 0});
+ auto sh_wei_down = op::v0::Constant::create(element::i4, Shape{2048, 6, 128}, {2});
+ auto sh_scale_down = op::v0::Constant::create(element::f16, Shape{2048, 6, 1}, {0.02f});
+ auto sh_scale_reshape_down = std::make_shared<op::v1::Reshape>(sh_scale_down, sh_reshape_const_down, false);
+ auto sh_scale_transpose_down = std::make_shared<ov::op::v1::Transpose>(sh_scale_reshape_down, sh_transpose_const_down);
+ auto sh_zp_down_dummy = op::v0::Constant::create(element::i4, Shape{1}, {0});
+
+ ov::intel_gpu::op::MOECompressed::Config config;
+ config.hidden_size = 2048;
+ config.inter_size = 768;
+ config.num_expert = 128;
+ config.num_shared_expert = 1;
+ config.top_k = 8;
+ config.group_size = 128;
+ config.out_type = ov::element::f16;
+ config.has_zp = false;
+ auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
+ auto shared_gate_gate_wei_m = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
+ std::shared_ptr<ov::Node> moe_compressed = std::make_shared<ov::intel_gpu::op::MOECompressed>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ wei_gate, scale_transpose_gate, zp_gate_dummy,
+ wei_up, scale_transpose_up, zp_up_dummy,
+ wei_down, scale_transpose_down, zp_down_dummy,
+ sh_wei_gate, sh_scale_transpose_gate, sh_zp_gate_dummy,
+ sh_wei_up, sh_scale_transpose_up, sh_zp_up_dummy,
+ sh_wei_down, sh_scale_transpose_down, sh_zp_down_dummy,
+ shared_gate_gate_wei_m}, config);
moe_compressed = std::make_shared<ov::op::v0::Convert>(moe_compressed, element::f32);
model_ref = std::make_shared<ov::Model>(moe_compressed, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
}
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/fuse_moe_shared_expert_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/fuse_moe_shared_expert_test.cpp
new file mode 100644
index 00000000000..fc70a12cda6
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/unit/transformations/fuse_moe_shared_expert_test.cpp
@@ -0,0 +1,332 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <gtest/gtest.h>
+
+#include "common_test_utils/ov_test_utils.hpp"
+#include "openvino/op/add.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/matmul.hpp"
+#include "openvino/op/moe.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/reshape.hpp"
+#include "openvino/op/sigmoid.hpp"
+#include "openvino/op/subtract.hpp"
+#include "openvino/op/swish.hpp"
+#include "plugin/transformations/fuse_moe_shared_expert.hpp"
+
+using namespace testing;
+using namespace ov::intel_gpu;
+
+namespace ov {
+namespace test {
+namespace intel_gpu {
+
+// Helper to create a weight decompression chain: Const(u4) -> Convert(f16) -> Sub(zp) -> Mul(scale) -> Reshape -> Convert(f32)
+static ov::Output<ov::Node> create_decompression_chain(
+ ov::element::Type wei_type,
+ const ov::Shape& wei_shape,
+ const ov::Shape& zp_shape,
+ const ov::Shape& scale_shape,
+ const ov::Shape& reshape_target,
+ float wei_val = 1.0f,
+ float zp_val = 0.0f,
+ float scale_val = 0.01f) {
+ auto wei = op::v0::Constant::create(wei_type, wei_shape, {wei_val});
+ auto zp = op::v0::Constant::create(wei_type, zp_shape, {zp_val});
+ auto scale = op::v0::Constant::create(element::f16, scale_shape, {scale_val});
+ auto reshape_const = op::v0::Constant::create(element::i32, Shape{reshape_target.size()}, reshape_target);
+
+ auto w_f16 = std::make_shared<op::v0::Convert>(wei, element::f16);
+ auto zp_f16 = std::make_shared<op::v0::Convert>(zp, element::f16);
+ auto sub = std::make_shared<op::v1::Subtract>(w_f16, zp_f16);
+ auto mul = std::make_shared<op::v1::Multiply>(sub, scale);
+ auto reshape = std::make_shared<op::v1::Reshape>(mul, reshape_const, false);
+ auto convert = std::make_shared<op::v0::Convert>(reshape, element::f32);
+ return convert;
+}
+
+// Helper to create a symmetric weight decompression chain: Const -> Convert(f16) -> Mul(scale) -> Reshape -> Convert(f32)
+static ov::Output<ov::Node> create_sym_decompression_chain(
+ ov::element::Type wei_type,
+ const ov::Shape& wei_shape,
+ const ov::Shape& scale_shape,
+ const ov::Shape& reshape_target,
+ float wei_val = 1.0f,
+ float scale_val = 0.01f) {
+ auto wei = op::v0::Constant::create(wei_type, wei_shape, {wei_val});
+ auto scale = op::v0::Constant::create(element::f16, scale_shape, {scale_val});
+ auto reshape_const = op::v0::Constant::create(element::i32, Shape{reshape_target.size()}, reshape_target);
+
+ auto w_f16 = std::make_shared<op::v0::Convert>(wei, element::f16);
+ auto mul = std::make_shared<op::v1::Multiply>(w_f16, scale);
+ auto reshape = std::make_shared<op::v1::Reshape>(mul, reshape_const, false);
+ auto convert = std::make_shared<op::v0::Convert>(reshape, element::f32);
+ return convert;
+}
+
+TEST_F(TransformationTestsF, FuseMOESharedExpertWithSigmoidGating) {
+ disable_rt_info_check();
+ {
+ // tokens:32, hidden_size:2048, inter_size:768, experts:128, topk:8
+ auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
+ auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
+ auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
+
+ // MOE expert decompression chains
+ auto gate_decompressed = create_decompression_chain(
+ element::u4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto up_decompressed = create_decompression_chain(
+ element::u4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto down_decompressed = create_decompression_chain(
+ element::u4, {128, 2048, 6, 128}, {128, 2048, 6, 1}, {128, 2048, 6, 1}, {128, 2048, 768});
+
+ // MOE node
+ ov::op::internal::MOE::Config config;
+ config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
+ auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
+ auto moe = std::make_shared<ov::op::internal::MOE>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ gate_decompressed, up_decompressed, down_decompressed}, config);
+
+ // Shared expert (uses reshaped hidden_states, separate from MOE's input)
+ auto reshape_const_hs = op::v0::Constant::create(element::i64, Shape{2}, {32, 2048});
+ auto hidden_states_reshaped = std::make_shared<ov::op::v1::Reshape>(hidden_states_f32, reshape_const_hs, false);
+
+ auto sh_gate_decompressed = create_decompression_chain(
+ element::u4, {768, 16, 128}, {768, 16, 1}, {768, 16, 1}, {768, 2048}, 2.0f, 1.0f, 0.02f);
+ auto sh_up_decompressed = create_decompression_chain(
+ element::u4, {768, 16, 128}, {768, 16, 1}, {768, 16, 1}, {768, 2048}, 2.0f, 1.0f, 0.02f);
+ auto sh_down_decompressed = create_decompression_chain(
+ element::u4, {2048, 6, 128}, {2048, 6, 1}, {2048, 6, 1}, {2048, 768}, 2.0f, 1.0f, 0.02f);
+
+ auto shared_gate_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_gate_decompressed, false, true);
+ auto shared_swish_m = std::make_shared<ov::op::v4::Swish>(shared_gate_m);
+ auto shared_up_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_up_decompressed, false, true);
+ auto shared_mul_m = std::make_shared<ov::op::v1::Multiply>(shared_swish_m, shared_up_m);
+ auto shared_down_m = std::make_shared<ov::op::v0::MatMul>(shared_mul_m, sh_down_decompressed, false, true);
+
+ // Sigmoid gating
+ auto gate_gate_wei = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
+ auto gate_gate_mm = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, gate_gate_wei);
+ auto gate_sigmoid = std::make_shared<ov::op::v0::Sigmoid>(gate_gate_mm);
+ auto shared_gated = std::make_shared<ov::op::v1::Multiply>(gate_sigmoid, shared_down_m);
+
+ // Reshape + Add
+ auto reshape_const_output = op::v0::Constant::create(element::i64, Shape{2}, {32, 2048});
+ auto shared_reshaped = std::make_shared<ov::op::v1::Reshape>(shared_gated, reshape_const_output, false);
+ auto add_m = std::make_shared<ov::op::v1::Add>(shared_reshaped, moe);
+
+ model = std::make_shared<ov::Model>(add_m, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ manager.register_pass<FuseMOESharedExpert>();
+ }
+ {
+ // Expected: MOE with 10 inputs (shared expert weights absorbed)
+ auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
+ auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
+ auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
+
+ auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
+
+ // Same decompression chains as input — FuseMOESharedExpert doesn't modify them
+ auto gate_decompressed = create_decompression_chain(
+ element::u4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto up_decompressed = create_decompression_chain(
+ element::u4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto down_decompressed = create_decompression_chain(
+ element::u4, {128, 2048, 6, 128}, {128, 2048, 6, 1}, {128, 2048, 6, 1}, {128, 2048, 768});
+
+ auto sh_gate_decompressed = create_decompression_chain(
+ element::u4, {768, 16, 128}, {768, 16, 1}, {768, 16, 1}, {768, 2048}, 2.0f, 1.0f, 0.02f);
+ auto sh_up_decompressed = create_decompression_chain(
+ element::u4, {768, 16, 128}, {768, 16, 1}, {768, 16, 1}, {768, 2048}, 2.0f, 1.0f, 0.02f);
+ auto sh_down_decompressed = create_decompression_chain(
+ element::u4, {2048, 6, 128}, {2048, 6, 1}, {2048, 6, 1}, {2048, 768}, 2.0f, 1.0f, 0.02f);
+
+ auto gate_gate_wei = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
+
+ ov::op::internal::MOE::Config config;
+ config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
+ auto moe_expected = std::make_shared<ov::op::internal::MOE>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ gate_decompressed, up_decompressed, down_decompressed,
+ sh_gate_decompressed, sh_up_decompressed, sh_down_decompressed,
+ gate_gate_wei}, config);
+
+ model_ref = std::make_shared<ov::Model>(moe_expected, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ }
+}
+
+TEST_F(TransformationTestsF, FuseMOESharedExpertWithoutGating) {
+ disable_rt_info_check();
+ {
+ // Same as above but without sigmoid gating (shared_down output goes through Add directly)
+ auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
+ auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
+ auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
+
+ auto gate_decompressed = create_decompression_chain(
+ element::u4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto up_decompressed = create_decompression_chain(
+ element::u4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto down_decompressed = create_decompression_chain(
+ element::u4, {128, 2048, 6, 128}, {128, 2048, 6, 1}, {128, 2048, 6, 1}, {128, 2048, 768});
+
+ ov::op::internal::MOE::Config config;
+ config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
+ auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
+ auto moe = std::make_shared<ov::op::internal::MOE>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ gate_decompressed, up_decompressed, down_decompressed}, config);
+
+ auto reshape_const_hs = op::v0::Constant::create(element::i64, Shape{2}, {32, 2048});
+ auto hidden_states_reshaped = std::make_shared<ov::op::v1::Reshape>(hidden_states_f32, reshape_const_hs, false);
+
+ auto sh_gate_decompressed = create_decompression_chain(
+ element::u4, {768, 16, 128}, {768, 16, 1}, {768, 16, 1}, {768, 2048}, 2.0f, 1.0f, 0.02f);
+ auto sh_up_decompressed = create_decompression_chain(
+ element::u4, {768, 16, 128}, {768, 16, 1}, {768, 16, 1}, {768, 2048}, 2.0f, 1.0f, 0.02f);
+ auto sh_down_decompressed = create_decompression_chain(
+ element::u4, {2048, 6, 128}, {2048, 6, 1}, {2048, 6, 1}, {2048, 768}, 2.0f, 1.0f, 0.02f);
+
+ auto shared_gate_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_gate_decompressed, false, true);
+ auto shared_swish_m = std::make_shared<ov::op::v4::Swish>(shared_gate_m);
+ auto shared_up_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_up_decompressed, false, true);
+ auto shared_mul_m = std::make_shared<ov::op::v1::Multiply>(shared_swish_m, shared_up_m);
+ auto shared_down_m = std::make_shared<ov::op::v0::MatMul>(shared_mul_m, sh_down_decompressed, false, true);
+
+ // No sigmoid gating — shared_down goes directly to Add
+ auto add_m = std::make_shared<ov::op::v1::Add>(moe, shared_down_m);
+
+ model = std::make_shared<ov::Model>(add_m, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ manager.register_pass<FuseMOESharedExpert>();
+ }
+ {
+ auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
+ auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
+ auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
+
+ auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
+
+ auto gate_decompressed = create_decompression_chain(
+ element::u4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto up_decompressed = create_decompression_chain(
+ element::u4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto down_decompressed = create_decompression_chain(
+ element::u4, {128, 2048, 6, 128}, {128, 2048, 6, 1}, {128, 2048, 6, 1}, {128, 2048, 768});
+
+ auto sh_gate_decompressed = create_decompression_chain(
+ element::u4, {768, 16, 128}, {768, 16, 1}, {768, 16, 1}, {768, 2048}, 2.0f, 1.0f, 0.02f);
+ auto sh_up_decompressed = create_decompression_chain(
+ element::u4, {768, 16, 128}, {768, 16, 1}, {768, 16, 1}, {768, 2048}, 2.0f, 1.0f, 0.02f);
+ auto sh_down_decompressed = create_decompression_chain(
+ element::u4, {2048, 6, 128}, {2048, 6, 1}, {2048, 6, 1}, {2048, 768}, 2.0f, 1.0f, 0.02f);
+
+ // Without gating, FuseMOESharedExpert inserts a dummy gate_gate constant (f16 to match ConvertMOEToMOECompressed)
+ auto dummy_gate_gate = ov::op::v0::Constant::create(element::f16, Shape{2048, 1}, std::vector<float>(2048, 0.0f));
+
+ ov::op::internal::MOE::Config config;
+ config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
+ auto moe_expected = std::make_shared<ov::op::internal::MOE>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ gate_decompressed, up_decompressed, down_decompressed,
+ sh_gate_decompressed, sh_up_decompressed, sh_down_decompressed,
+ dummy_gate_gate}, config);
+
+ model_ref = std::make_shared<ov::Model>(moe_expected, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ }
+}
+
+// Test FuseMOESharedExpert with symmetric quantization (Convert -> Multiply, no Subtract)
+TEST_F(TransformationTestsF, FuseMOESharedExpertSymmetricWithGating) {
+ disable_rt_info_check();
+ {
+ auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
+ auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
+ auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
+
+ // MOE expert sym-quant decompression chains (no Subtract)
+ auto gate_decompressed = create_sym_decompression_chain(
+ element::i4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto up_decompressed = create_sym_decompression_chain(
+ element::i4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto down_decompressed = create_sym_decompression_chain(
+ element::i4, {128, 2048, 6, 128}, {128, 2048, 6, 1}, {128, 2048, 768});
+
+ ov::op::internal::MOE::Config config;
+ config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
+ auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
+ auto moe = std::make_shared<ov::op::internal::MOE>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ gate_decompressed, up_decompressed, down_decompressed}, config);
+
+ // Shared expert with sym-quant decompression chains
+ auto reshape_const_hs = op::v0::Constant::create(element::i64, Shape{2}, {32, 2048});
+ auto hidden_states_reshaped = std::make_shared<ov::op::v1::Reshape>(hidden_states_f32, reshape_const_hs, false);
+
+ auto sh_gate_decompressed = create_sym_decompression_chain(
+ element::i4, {768, 16, 128}, {768, 16, 1}, {768, 2048}, 2.0f, 0.02f);
+ auto sh_up_decompressed = create_sym_decompression_chain(
+ element::i4, {768, 16, 128}, {768, 16, 1}, {768, 2048}, 2.0f, 0.02f);
+ auto sh_down_decompressed = create_sym_decompression_chain(
+ element::i4, {2048, 6, 128}, {2048, 6, 1}, {2048, 768}, 2.0f, 0.02f);
+
+ auto shared_gate_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_gate_decompressed, false, true);
+ auto shared_swish_m = std::make_shared<ov::op::v4::Swish>(shared_gate_m);
+ auto shared_up_m = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, sh_up_decompressed, false, true);
+ auto shared_mul_m = std::make_shared<ov::op::v1::Multiply>(shared_swish_m, shared_up_m);
+ auto shared_down_m = std::make_shared<ov::op::v0::MatMul>(shared_mul_m, sh_down_decompressed, false, true);
+
+ // Sigmoid gating
+ auto gate_gate_wei = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
+ auto gate_gate_mm = std::make_shared<ov::op::v0::MatMul>(hidden_states_reshaped, gate_gate_wei);
+ auto gate_sigmoid = std::make_shared<ov::op::v0::Sigmoid>(gate_gate_mm);
+ auto shared_gated = std::make_shared<ov::op::v1::Multiply>(gate_sigmoid, shared_down_m);
+
+ auto reshape_const_output = op::v0::Constant::create(element::i64, Shape{2}, {32, 2048});
+ auto shared_reshaped = std::make_shared<ov::op::v1::Reshape>(shared_gated, reshape_const_output, false);
+ auto add_m = std::make_shared<ov::op::v1::Add>(moe, shared_reshaped);
+
+ model = std::make_shared<ov::Model>(add_m, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ manager.register_pass<FuseMOESharedExpert>();
+ }
+ {
+ auto hidden_states = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{32, 2048});
+ auto routing_weights = std::make_shared<ov::op::v0::Parameter>(element::f16, Shape{128, 1, 32, 1});
+ auto routing_idx = std::make_shared<ov::op::v0::Parameter>(element::i32, Shape{32, 8});
+
+ auto hidden_states_f32 = std::make_shared<ov::op::v0::Convert>(hidden_states, element::f32);
+
+ auto gate_decompressed = create_sym_decompression_chain(
+ element::i4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto up_decompressed = create_sym_decompression_chain(
+ element::i4, {128, 768, 16, 128}, {128, 768, 16, 1}, {128, 768, 2048});
+ auto down_decompressed = create_sym_decompression_chain(
+ element::i4, {128, 2048, 6, 128}, {128, 2048, 6, 1}, {128, 2048, 768});
+
+ auto sh_gate_decompressed = create_sym_decompression_chain(
+ element::i4, {768, 16, 128}, {768, 16, 1}, {768, 2048}, 2.0f, 0.02f);
+ auto sh_up_decompressed = create_sym_decompression_chain(
+ element::i4, {768, 16, 128}, {768, 16, 1}, {768, 2048}, 2.0f, 0.02f);
+ auto sh_down_decompressed = create_sym_decompression_chain(
+ element::i4, {2048, 6, 128}, {2048, 6, 1}, {2048, 768}, 2.0f, 0.02f);
+
+ auto gate_gate_wei = std::make_shared<ov::op::v0::Constant>(element::f32, Shape{2048, 1}, std::vector<float>(2048, 1.0f));
+
+ ov::op::internal::MOE::Config config;
+ config.expert_type = ov::op::internal::MOE::Expert_type::GEMM3_SWIGLU;
+ auto moe_expected = std::make_shared<ov::op::internal::MOE>(
+ ov::OutputVector{hidden_states_f32, routing_weights, routing_idx,
+ gate_decompressed, up_decompressed, down_decompressed,
+ sh_gate_decompressed, sh_up_decompressed, sh_down_decompressed,
+ gate_gate_wei}, config);
+
+ model_ref = std::make_shared<ov::Model>(moe_expected, ov::ParameterVector{hidden_states, routing_weights, routing_idx});
+ }
+}
+
+} // namespace intel_gpu
+} // namespace test
+} // namespace ov