Skip to content

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

[TESTS] GroupedMatMul plugin tests (#36588)

Vladislav Golubev4b24b8c2ff19
diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/grouped_matmul.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/grouped_matmul.cpp
new file mode 100644
index 00000000000..b9f25c742e6
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/single_layer_tests/grouped_matmul.cpp
@@ -0,0 +1,85 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "single_op_tests/grouped_matmul.hpp"
+
+#include <vector>
+
+#include "common_test_utils/test_constants.hpp"
+
+namespace {
+using ov::test::GroupedMatMulCompressedLayerTest;
+using ov::test::GroupedMatMulLayerTest;
+using ov::test::GroupedMatMulShapeParams;
+using ov::test::TokensPerExpert;
+using ov::test::utils::DecompressionType;
+
+const std::vector<GroupedMatMulShapeParams> shapes = {
+ // 3D x 3D: A:[G,M,K] x B:[G,N,K] -> [G,M,N], dynamic M dim.
+ {{ov::PartialShape{4, -1, 128}, {{4, 8, 128}, {4, 1, 128}, {4, 16, 128}}}, {4, 256, 128}, {}},
+ {{ov::PartialShape{8, -1, 256}, {{8, 4, 256}, {8, 1, 256}}}, {8, 512, 256}, {}},
+ // 2D x 3D: A:[T,K] x B:[G,N,K] -> [T,N], dynamic T dim.
+ {{ov::PartialShape{-1, 128}, {{16, 128}, {32, 128}, {8, 128}}}, {4, 256, 128}, TokensPerExpert{{8, 0, 8, 0}, {0, 16, 0, 16}, {4, 4, 0, 0}}},
+ {{ov::PartialShape{-1, 128}, {{12, 128}, {20, 128}}}, {4, 256, 128}, TokensPerExpert{{4, 5, 3, 0}, {0, 7, 6, 7}}},
+ {{ov::PartialShape{-1, 256}, {{16, 256}, {32, 256}}}, {8, 512, 256}, TokensPerExpert{{4, 2, 2, 2, 2, 2, 1, 1}, {2, 6, 4, 4, 4, 4, 4, 4}}},
+};
+
+const std::vector<ov::element::Type> weights_precisions = {ov::element::u8, ov::element::i8,
+ ov::element::u4, ov::element::i4};
+const std::vector<ov::element::Type> decompression_precisions = {ov::element::f32};
+
+INSTANTIATE_TEST_SUITE_P(smoke_GroupedMatMul,
+ GroupedMatMulLayerTest,
+ ::testing::Combine(::testing::ValuesIn(shapes),
+ ::testing::Values(ov::element::f16),
+ ::testing::Values(ov::test::utils::DEVICE_CPU),
+ ::testing::Values("GatherMatmul")),
+ GroupedMatMulLayerTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_GroupedMatMul_Compressed,
+ GroupedMatMulCompressedLayerTest,
+ ::testing::Combine(::testing::ValuesIn(shapes),
+ ::testing::Values(ov::element::f16),
+ ::testing::ValuesIn(weights_precisions),
+ ::testing::ValuesIn(decompression_precisions),
+ ::testing::Values(ov::element::f32),
+ ::testing::Values(DecompressionType::empty, DecompressionType::full),
+ ::testing::Values(DecompressionType::full),
+ ::testing::Values(false),
+ ::testing::Values(-1, 16),
+ ::testing::Values(ov::test::utils::DEVICE_CPU),
+ ::testing::Values("GatherMatmul")),
+ GroupedMatMulCompressedLayerTest::getTestCaseName);
+
+
+// Corner cases: odd K, non-power-of-2 N
+const std::vector<GroupedMatMulShapeParams> shapes_corner_cases = {
+ {{ov::PartialShape{4, -1, 77}, {{4, 8, 77}, {4, 1, 77}, {4, 8, 77}}}, {4, 123, 77}, {}},
+ {{ov::PartialShape{-1, 77}, {{12, 77}, {20, 77}}}, {4, 123, 77}, TokensPerExpert{{4, 5, 3, 0}, {0, 7, 6, 7}}},
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_GroupedMatMul_CornerCases,
+ GroupedMatMulLayerTest,
+ ::testing::Combine(::testing::ValuesIn(shapes_corner_cases),
+ ::testing::Values(ov::element::f16),
+ ::testing::Values(ov::test::utils::DEVICE_CPU),
+ ::testing::Values("GatherMatmul")),
+ GroupedMatMulLayerTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_GroupedMatMul_Compressed_CornerCases,
+ GroupedMatMulCompressedLayerTest,
+ ::testing::Combine(::testing::ValuesIn(shapes_corner_cases),
+ ::testing::Values(ov::element::f16),
+ ::testing::ValuesIn(weights_precisions),
+ ::testing::ValuesIn(decompression_precisions),
+ ::testing::Values(ov::element::f32),
+ ::testing::Values(DecompressionType::empty, DecompressionType::full),
+ ::testing::Values(DecompressionType::full),
+ ::testing::Values(false),
+ ::testing::Values(-1),
+ ::testing::Values(ov::test::utils::DEVICE_CPU),
+ ::testing::Values("GatherMatmul")),
+ GroupedMatMulCompressedLayerTest::getTestCaseName);
+
+} // namespace
diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
index 5680276248c..194d8299202 100644
--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
@@ -336,6 +336,8 @@ const std::vector<std::regex>& disabled_test_patterns() {
std::regex(R"(.*WeightlessCacheAccuracy.*)"),
#endif
#if defined(OPENVINO_ARCH_ARM)
+ // GatherMatmul is not supported on 32-bit ARM
+ std::regex(R"(.*smoke_GroupedMatMul.*)"),
// Issue: 144998
std::regex(R"(.*smoke_CachingSupportCase_CPU.*_(i8|u8).*)"),
std::regex(R"(.*smoke_Hetero_CachingSupportCase.*_(i8|u8).*)"),
@@ -673,6 +675,9 @@ const std::vector<std::regex>& disabled_test_patterns() {
if (!ov::intel_cpu::hasArmISASupport(ov::intel_cpu::ArmISA::DOTPROD)) {
patterns.emplace_back(std::regex(R"(.*smoke_MatMulCompressedWeights_Kleidiai.*)"));
}
+ if (!ov::with_cpu_arm_dotprod() && !ov::with_cpu_arm_i8mm()) {
+ patterns.emplace_back(std::regex(R"(.*smoke_GroupedMatMul_Compressed.*)"));
+ }
if (!ov::intel_cpu::hasHardwareSupport(ov::element::f16)) {
// Skip fp16 tests for paltforms that don't support fp16 precision
patterns.emplace_back(std::regex(R"(.*INFERENCE_PRECISION_HINT=(F|f)16.*)"));
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/grouped_matmul.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/grouped_matmul.cpp
new file mode 100644
index 00000000000..a6c421e7f15
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/single_layer_tests/grouped_matmul.cpp
@@ -0,0 +1,54 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "single_op_tests/grouped_matmul.hpp"
+
+#include <vector>
+
+#include "common_test_utils/test_constants.hpp"
+
+namespace {
+using ov::test::GroupedMatMulCompressedLayerTest;
+using ov::test::GroupedMatMulLayerTest;
+using ov::test::GroupedMatMulShapeParams;
+using ov::test::TokensPerExpert;
+using ov::test::utils::DecompressionType;
+
+const std::vector<GroupedMatMulShapeParams> shapes = {
+ // 3D x 3D: A:[G,M,K] x B:[G,N,K] -> [G,M,N], dynamic M dim.
+ {{ov::PartialShape{4, -1, 128}, {{4, 8, 128}, {4, 1, 128}, {4, 16, 128}}}, {4, 256, 128}, {}},
+ {{ov::PartialShape{8, -1, 256}, {{8, 4, 256}, {8, 1, 256}}}, {8, 512, 256}, {}},
+ // 2D x 3D: A:[T,K] x B:[G,N,K] -> [T,N], dynamic T dim.
+ {{ov::PartialShape{-1, 128}, {{16, 128}, {32, 128}, {8, 128}}}, {4, 256, 128}, TokensPerExpert{{8, 0, 8, 0}, {0, 16, 0, 16}, {4, 4, 0, 0}}},
+ {{ov::PartialShape{-1, 128}, {{12, 128}, {20, 128}}}, {4, 256, 128}, TokensPerExpert{{4, 5, 3, 0}, {0, 7, 6, 7}}},
+ {{ov::PartialShape{-1, 256}, {{16, 256}, {32, 256}}}, {8, 512, 256}, TokensPerExpert{{4, 2, 2, 2, 2, 2, 1, 1}, {2, 6, 4, 4, 4, 4, 4, 4}}},
+};
+
+const std::vector<ov::element::Type> weights_precisions = {ov::element::u8, ov::element::u4};
+const std::vector<ov::element::Type> decompression_precisions = {ov::element::f16};
+const std::vector<DecompressionType> subtract_types = {DecompressionType::full, DecompressionType::empty};
+
+INSTANTIATE_TEST_SUITE_P(smoke_GroupedMatMul,
+ GroupedMatMulLayerTest,
+ ::testing::Combine(::testing::ValuesIn(shapes),
+ ::testing::Values(ov::element::f16),
+ ::testing::Values(ov::test::utils::DEVICE_GPU),
+ ::testing::Values("gather_matmul")),
+ GroupedMatMulLayerTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(smoke_GroupedMatMul_Compressed,
+ GroupedMatMulCompressedLayerTest,
+ ::testing::Combine(::testing::ValuesIn(shapes),
+ ::testing::Values(ov::element::f16),
+ ::testing::ValuesIn(weights_precisions),
+ ::testing::ValuesIn(decompression_precisions),
+ ::testing::Values(ov::element::f16),
+ ::testing::Values(DecompressionType::full),
+ ::testing::ValuesIn(subtract_types),
+ ::testing::Values(true),
+ ::testing::Values(-1, 128),
+ ::testing::Values(ov::test::utils::DEVICE_GPU),
+ ::testing::Values("gather_matmul")),
+ GroupedMatMulCompressedLayerTest::getTestCaseName);
+} // namespace
diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
index 13e155eac6e..62030ff531d 100644
--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp
@@ -247,6 +247,8 @@ const std::vector<std::regex>& disabled_test_patterns() {
patterns.push_back(std::regex(R"(.*smoke_MatMulCompressedWeights_3D_weight.*)"));
// MoE patterns are not supported on the platforms without immad (fusion transformation are disabled)
patterns.push_back(std::regex(R"(.*smoke_MoE3GemmCompressedFusion.*)"));
+ // Ticket 183099: enable after GroupedMatMul support on GPU
+ patterns.push_back(std::regex(R"(.*smoke_GroupedMatMul.*)"));
// Dynamic quantization of fp8 and mxfp8 models supported only through oneDNN (disabled for non-systolic platforms)
patterns.push_back(std::regex(R"(.*smoke_MatMulCompressedWeights_dyn_quan_.*fp8.*)"));
}
diff --git a/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/grouped_matmul.hpp b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/grouped_matmul.hpp
new file mode 100644
index 00000000000..de163596c67
--- /dev/null
+++ b/src/tests/functional/plugin/shared/include/shared_test_classes/single_op/grouped_matmul.hpp
@@ -0,0 +1,101 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <string>
+#include <tuple>
+#include <vector>
+
+#include "shared_test_classes/base/ov_subgraph.hpp"
+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"
+
+namespace ov {
+namespace test {
+
+// Per-iteration token allocation for the 2D×3D case.
+// tokens_per_expert[iter][g] = number of rows (tokens) assigned to expert g in iteration iter.
+// The values are converted to cumulative end-offsets passed to GroupedMatMul:
+// offsets[g] = sum(tokens_per_expert[iter][0..g]) (exclusive row end for expert g).
+// Sum over g must equal T (total token count) for that iteration.
+// Zeros mean the expert is inactive (gets no tokens) — exercises sparse MoE routing.
+// Empty vector → even distribution across experts.
+using TokensPerExpert = std::vector<std::vector<size_t>>;
+
+/// Bundles the shape-related parameters that are always specified together.
+/// rank of a_input_shape.first selects the case:
+/// rank 2 → 2D×3D: A:[T,K] x B:[G,N,K] → [T,N] (with runtime offsets)
+/// rank 3 → 3D×3D: A:[G,M,K] x B:[G,N,K] → [G,M,N] (no offsets)
+struct GroupedMatMulShapeParams {
+ ov::test::InputShape a_input_shape; ///< Dynamic shape + static test shapes
+ ov::Shape b_shape; ///< Pre-transposed weight shape [G, N, K]
+ TokensPerExpert tokens_per_expert; ///< Per-iter routing; empty = even
+};
+
+class GroupedMatMulTestBase : virtual public ov::test::SubgraphBaseTest {
+protected:
+ GroupedMatMulShapeParams shape_params_;
+ ov::element::Type act_type_;
+ std::string model_name_;
+ std::string expected_primitive_;
+
+ void SetUp() override;
+ void validate() override;
+ virtual std::shared_ptr<ov::Node> build_weights() = 0;
+ void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override;
+};
+
+using GroupedMatMulParams = std::tuple<
+ GroupedMatMulShapeParams, // shape bundle
+ ov::element::Type, // element type
+ std::string, // target device
+ std::string // expected primitive type (empty = skip check)
+>;
+
+class GroupedMatMulLayerTest : public testing::WithParamInterface<GroupedMatMulParams>,
+ virtual public GroupedMatMulTestBase {
+public:
+ static std::string getTestCaseName(const testing::TestParamInfo<GroupedMatMulParams>& obj);
+
+protected:
+ void SetUp() override;
+ std::shared_ptr<ov::Node> build_weights() override;
+};
+
+using GroupedMatMulCompressedParams = std::tuple<
+ GroupedMatMulShapeParams, // shape bundle
+ ov::element::Type, // activation element type
+ ov::element::Type, // weights (compressed) precision
+ ov::element::Type, // decompression precision
+ ov::element::Type, // scale precision
+ ov::test::utils::DecompressionType, // multiply type (full/empty/scalar)
+ ov::test::utils::DecompressionType, // subtract type (full/empty/scalar)
+ bool, // reshape_on_decompression
+ int, // decompression_group_size (-1 = per-OC)
+ std::string, // target device
+ std::string // expected primitive type (empty = skip check)
+>;
+
+class GroupedMatMulCompressedLayerTest
+ : public testing::WithParamInterface<GroupedMatMulCompressedParams>,
+ virtual public GroupedMatMulTestBase {
+public:
+ static std::string getTestCaseName(const testing::TestParamInfo<GroupedMatMulCompressedParams>& obj);
+
+protected:
+ void SetUp() override;
+ std::shared_ptr<ov::Node> build_weights() override;
+
+private:
+ ov::element::Type weights_prec_;
+ ov::element::Type decomp_prec_;
+ ov::element::Type scale_prec_;
+ ov::test::utils::DecompressionType multiply_type_;
+ ov::test::utils::DecompressionType subtract_type_;
+ bool reshape_on_decomp_;
+ int group_size_;
+};
+
+} // namespace test
+} // namespace ov
diff --git a/src/tests/functional/plugin/shared/include/single_op_tests/grouped_matmul.hpp b/src/tests/functional/plugin/shared/include/single_op_tests/grouped_matmul.hpp
new file mode 100644
index 00000000000..0778adc9a87
--- /dev/null
+++ b/src/tests/functional/plugin/shared/include/single_op_tests/grouped_matmul.hpp
@@ -0,0 +1,18 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "shared_test_classes/single_op/grouped_matmul.hpp"
+
+namespace ov {
+namespace test {
+TEST_P(GroupedMatMulLayerTest, Inference) {
+ run();
+}
+TEST_P(GroupedMatMulCompressedLayerTest, Inference) {
+ run();
+}
+} // namespace test
+} // namespace ov
diff --git a/src/tests/functional/plugin/shared/src/single_op/group_convolution.cpp b/src/tests/functional/plugin/shared/src/single_op/group_convolution.cpp
index d7d45af5a59..6d445dec4ba 100644
--- a/src/tests/functional/plugin/shared/src/single_op/group_convolution.cpp
+++ b/src/tests/functional/plugin/shared/src/single_op/group_convolution.cpp
@@ -40,7 +40,7 @@ std::string GroupConvolutionLayerTest::getTestCaseName(const testing::TestParamI
result << "G=" << num_groups << "_";
result << "AP=" << pad_type << "_";
result << "modelType=" << model_type.get_type_name() << "_";
- result << "trgDev=" << target_device;
+ result << "targetDevice=" << target_device;
return result.str();
}
diff --git a/src/tests/functional/plugin/shared/src/single_op/grouped_matmul.cpp b/src/tests/functional/plugin/shared/src/single_op/grouped_matmul.cpp
new file mode 100644
index 00000000000..c2981733651
--- /dev/null
+++ b/src/tests/functional/plugin/shared/src/single_op/grouped_matmul.cpp
@@ -0,0 +1,236 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "shared_test_classes/single_op/grouped_matmul.hpp"
+
+#include <algorithm>
+#include <sstream>
+
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "common_test_utils/subgraph_builders/weights_decompression_builders.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/grouped_matmul.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/result.hpp"
+
+namespace ov {
+namespace test {
+
+void GroupedMatMulTestBase::SetUp() {
+ const auto& [a_input_shape, b_shape, tokens_per_expert] = shape_params_;
+
+ OPENVINO_ASSERT(a_input_shape.first.rank().is_static(),
+ "GroupedMatMul test: mat_a PartialShape must have static rank");
+ const auto a_rank = a_input_shape.first.rank().get_length();
+ OPENVINO_ASSERT(a_rank == 2 || a_rank == 3,
+ "GroupedMatMul test: mat_a rank must be 2 or 3, got ", a_rank);
+ OPENVINO_ASSERT(b_shape.size() == 3,
+ "GroupedMatMul test: b_shape must be 3D [G,N,K], got rank ", b_shape.size());
+ const bool is_2d_3d = (a_rank == 2);
+ const size_t G = b_shape[0];
+ const size_t num_iters = a_input_shape.second.size();
+
+ if (is_2d_3d) {
+ init_input_shapes({
+ a_input_shape,
+ {ov::PartialShape{static_cast<ov::Dimension::value_type>(G)},
+ std::vector<ov::Shape>(num_iters, ov::Shape{G})}
+ });
+ } else {
+ init_input_shapes({a_input_shape});
+ }
+
+ auto param_a = std::make_shared<ov::op::v0::Parameter>(act_type_, inputDynamicShapes[0]);
+ auto const_b = build_weights();
+
+ std::shared_ptr<ov::Node> gm_op;
+ ov::ParameterVector params = {param_a};
+
+ if (is_2d_3d) {
+ auto param_offsets = std::make_shared<ov::op::v0::Parameter>(
+ ov::element::i32, inputDynamicShapes[1]);
+ params.push_back(param_offsets);
+ gm_op = std::make_shared<ov::op::v17::GroupedMatMul>(param_a, const_b, param_offsets);
+ } else {
+ gm_op = std::make_shared<ov::op::v17::GroupedMatMul>(param_a, const_b);
+ }
+
+ function = std::make_shared<ov::Model>(
+ ov::ResultVector{std::make_shared<ov::op::v0::Result>(gm_op)},
+ params,
+ model_name_);
+
+ abs_threshold = 0.05f;
+ rel_threshold = 0.01f;
+}
+
+void GroupedMatMulTestBase::validate() {
+ SubgraphBaseTest::validate();
+ if (!expected_primitive_.empty()) {
+ CheckNumberOfNodesWithType(compiledModel, expected_primitive_, 1);
+ }
+}
+
+void GroupedMatMulTestBase::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {
+ inputs.clear();
+ const auto& [a_input_shape, b_shape, tokens_per_expert] = shape_params_;
+
+ OPENVINO_ASSERT(a_input_shape.first.rank().is_static());
+ const bool is_2d_3d = (a_input_shape.first.rank().get_length() == 2);
+ const auto& a_static_shapes = a_input_shape.second;
+ const auto& target_shape = targetInputStaticShapes[0];
+ const auto it = std::find(a_static_shapes.begin(), a_static_shapes.end(), target_shape);
+ OPENVINO_ASSERT(it != a_static_shapes.end(),
+ "GroupedMatMul test: target shape not found in a_static_shapes");
+ const size_t iter = static_cast<size_t>(std::distance(a_static_shapes.begin(), it));
+
+ ov::test::utils::InputGenerateData gen_data;
+ gen_data.range = 2;
+ gen_data.resolution = 128;
+ gen_data.start_from = -1;
+
+ inputs.insert({function->get_parameters()[0],
+ ov::test::utils::create_and_fill_tensor(act_type_, targetInputStaticShapes[0], gen_data)});
+
+ if (is_2d_3d) {
+ const size_t G = b_shape[0];
+ const size_t T = targetInputStaticShapes[0][0];
+
+ std::vector<int32_t> offsets(G);
+ if (!tokens_per_expert.empty()) {
+ OPENVINO_ASSERT(iter < tokens_per_expert.size(),
+ "GroupedMatMul test: iter ", iter,
+ " out of range for tokens_per_expert of size ", tokens_per_expert.size());
+ const auto& tpe = tokens_per_expert[iter];
+ OPENVINO_ASSERT(tpe.size() == G,
+ "tokens_per_expert[", iter, "] must have G=", G,
+ " entries, got ", tpe.size());
+ int32_t cum = 0;
+ for (size_t g = 0; g < G; ++g) {
+ cum += static_cast<int32_t>(tpe[g]);
+ offsets[g] = cum;
+ }
+ OPENVINO_ASSERT(offsets[G - 1] == static_cast<int32_t>(T),
+ "tokens_per_expert[", iter, "] sums to ", offsets[G - 1],
+ " but T=", T);
+ } else {
+ // Even distribution: offsets[g] = ceil(T*(g+1)/G), last clamped to T.
+ for (size_t g = 0; g < G; ++g) {
+ offsets[g] = static_cast<int32_t>((T * (g + 1) + G - 1) / G);
+ }
+ offsets[G - 1] = static_cast<int32_t>(T);
+ }
+
+ ov::Tensor offsets_tensor(ov::element::i32, ov::Shape{G});
+ auto* dst = offsets_tensor.data<int32_t>();
+ for (size_t g = 0; g < G; ++g)
+ dst[g] = offsets[g];
+
+ inputs.insert({function->get_parameters()[1], offsets_tensor});
+ }
+}
+
+std::string GroupedMatMulLayerTest::getTestCaseName(const testing::TestParamInfo<GroupedMatMulParams>& obj) {
+ const auto& [shape_params, elem_type, target_device, expected_primitive] = obj.param;
+ const auto& [a_input_shape, b_shape, tokens_per_expert] = shape_params;
+
+ OPENVINO_ASSERT(a_input_shape.first.rank().is_static(),
+ "GroupedMatMul test: mat_a PartialShape must have static rank");
+
+ std::ostringstream result;
+ result << "A_shape=" << a_input_shape << "_";
+ result << "B_shape=" << ov::test::utils::vec2str(b_shape) << "_";
+ result << "ET=" << elem_type << "_";
+ result << "targetDevice=" << target_device;
+ return result.str();
+}
+
+void GroupedMatMulLayerTest::SetUp() {
+ const auto& [shape_params, elem_type, _targetDevice, expected_primitive] = GetParam();
+ shape_params_ = shape_params;
+ act_type_ = elem_type;
+ model_name_ = "GroupedMatMul";
+ expected_primitive_ = expected_primitive;
+ targetDevice = _targetDevice;
+ GroupedMatMulTestBase::SetUp();
+}
+
+std::shared_ptr<ov::Node> GroupedMatMulLayerTest::build_weights() {
+ ov::test::utils::InputGenerateData b_data;
+ b_data.range = 2;
+ b_data.resolution = 128;
+ b_data.start_from = -1;
+ auto b_tensor = ov::test::utils::create_and_fill_tensor(act_type_, shape_params_.b_shape, b_data);
+ return std::make_shared<ov::op::v0::Constant>(b_tensor);
+}
+
+std::string GroupedMatMulCompressedLayerTest::getTestCaseName(
+ const testing::TestParamInfo<GroupedMatMulCompressedParams>& obj) {
+ const auto& [shape_params, act_type, weights_prec, decomp_prec, scale_prec,
+ multiply_type, subtract_type, reshape_on_decomp, group_size,
+ target_device, expected_primitive] = obj.param;
+ const auto& [a_input_shape, b_shape, tokens_per_expert] = shape_params;
+
+ OPENVINO_ASSERT(a_input_shape.first.rank().is_static());
+
+ std::ostringstream result;
+ result << "A_shape=" << a_input_shape << "_";
+ result << "B_shape=" << ov::test::utils::vec2str(b_shape) << "_";
+ result << "ActET=" << act_type << "_";
+ result << "WET=" << weights_prec << "_";
+ result << "DecompPrec=" << decomp_prec << "_";
+ result << "ScalePrec=" << scale_prec << "_";
+ result << "Mul=" << multiply_type << "_Sub=" << subtract_type << "_";
+ result << "Reshape=" << reshape_on_decomp << "_";
+ result << "GrpSz=" << group_size << "_";
+ result << "targetDevice=" << target_device;
+ return result.str();
+}
+
+void GroupedMatMulCompressedLayerTest::SetUp() {
+ const auto& [shape_params, act_type, weights_prec, decomp_prec, scale_prec,
+ multiply_type, subtract_type, reshape_on_decomp, group_size,
+ _targetDevice, expected_primitive] = GetParam();
+ shape_params_ = shape_params;
+ act_type_ = act_type;
+ model_name_ = "GroupedMatMulCompressed";
+ expected_primitive_ = expected_primitive;
+ weights_prec_ = weights_prec;
+ decomp_prec_ = decomp_prec;
+ scale_prec_ = scale_prec;
+ multiply_type_ = multiply_type;
+ subtract_type_ = subtract_type;
+ reshape_on_decomp_ = reshape_on_decomp;
+ group_size_ = group_size;
+ targetDevice = _targetDevice;
+ GroupedMatMulTestBase::SetUp();
+}
+
+std::shared_ptr<ov::Node> GroupedMatMulCompressedLayerTest::build_weights() {
+ // b_shape is the pre-transposed weight shape [G, N, K].
+ // We pass the PLANAR shape [G, K, N] to initMatMulDecompressionSubgraphQuantization
+ // with transpose_weights=true so the internal constant is laid out as [G, N, K]
+ // (per-N scales ≡ per-OC). Passing insert_transpose_node=false suppresses the
+ // trailing Transpose node, leaving the decompressed output in [G, N, K] form
+ // ready for GroupedMatMul.
+ ov::Shape b_planar = shape_params_.b_shape;
+ std::swap(b_planar[b_planar.size() - 2], b_planar[b_planar.size() - 1]); // [G, K, N]
+
+ return ov::test::utils::initMatMulDecompressionSubgraphQuantization(
+ b_planar,
+ group_size_,
+ act_type_,
+ weights_prec_,
+ decomp_prec_,
+ scale_prec_,
+ true, // transpose_weights: constant stored as [G, N, K]
+ multiply_type_,
+ subtract_type_,
+ reshape_on_decomp_,
+ false, // insert_transpose_node: omit trailing Transpose → output [G, N, K]
+ 1); // seed
+}
+
+} // namespace test
+} // namespace ov