Skip to content

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

[GPU] Enable GatherMatmul tests (#35675)

Egor Duplenskii96d1621e8729
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/gather_matmul/gather_matmul_gen_micro.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/gather_matmul/gather_matmul_gen_micro.cpp
index edeca7fc1fb..8fc07afc082 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/gather_matmul/gather_matmul_gen_micro.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/gather_matmul/gather_matmul_gen_micro.cpp
@@ -10,7 +10,6 @@
#include "intel_gpu/primitives/gather_matmul.hpp"
#include "intel_gpu/primitives/swiglu.hpp"
#include "ocl_v2/utils/jitter.hpp"
-#include "gather_matmul_inst.h"
#include "../utils/kernel_generator.hpp"
#include "gemmstone/kernel_selector.hpp"
@@ -63,9 +62,6 @@ gathermatmul_config GatherMatmulMicroGenerator::get_config(const kernel_impl_par
cfg.weight_zp_idx = gather_matmul::BGMInputIdx::WEIGHT_ZP;
const auto& weight_shape = params.input_layouts[gather_matmul::BGMInputIdx::WEIGHT].get_shape();
auto k = (weight_shape.size() == 4) ? weight_shape[2] * weight_shape[3] : weight_shape[2];
- // Scale layout [E, N, G]; gemmstone A_scale.layout=T with leading_dim=NUM_GROUPS.
- // Strided SIMD reads are a minor perf ceiling — upstream Transpose to [E, G, N] hits
- // CL_OUT_OF_RESOURCES in microkernel selection.
const auto& scale_shape_for_groups = params.input_layouts[cfg.weight_scale_idx].get_shape();
OPENVINO_ASSERT(scale_shape_for_groups.size() > 2 && scale_shape_for_groups[2] > 0,
"GatherMatmul: weight scale shape must have a positive group dim at index 2, got ",
@@ -120,6 +116,9 @@ JitConstants GatherMatmulMicroGenerator::get_jit_constants(const kernel_impl_par
else
jit.make("NUM_GROUPS", 1);
+ // Scales are physically [E, G, N]; must match GatherMatmulBatchedGemmGenerator.
+ jit.make("SCALE_ZP_NO_TRANSPOSE", 1);
+
size_t expert_stride = weight_shape.size() == 4 ? (weight_shape[1] * weight_shape[2] * weight_shape[3]) : (weight_shape[1] * weight_shape[2]);
if (is_u4_i4) {
jit.make("EXPERT_STRIDE", expert_stride / 2);
@@ -245,8 +244,8 @@ void GatherMatmulMicroGenerator::init_microkernels(const kernel_impl_params& par
problem.Ta_scale = convert_type(params.get_input_layout(bgm_cfg.weight_scale_idx).data_type);
problem.A_scale.setAlignment(2);
- // Scales [E, G, N] (transposed in ConvertGatherMatmulToGatherMatmulCompressed) → gemmstone T layout.
- problem.A_scale.layout = micro::MatrixLayout::T;
+ // Per-expert scales are physically [G, N]; N + leading_dim=m_gemm reads them as-is.
+ problem.A_scale.layout = micro::MatrixLayout::N;
problem.asPtrDims = static_cast<int>(MICRO_DIMENSIONALITY::MATRIX);
problem.aqGroupM = 1;
diff --git a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/gather_matmul/gathermatmul_batched_gemm_gen.cpp b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/gather_matmul/gathermatmul_batched_gemm_gen.cpp
index c1095cd5563..6113615e6cc 100644
--- a/src/plugins/intel_gpu/src/graph/impls/ocl_v2/gather_matmul/gathermatmul_batched_gemm_gen.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/ocl_v2/gather_matmul/gathermatmul_batched_gemm_gen.cpp
@@ -74,6 +74,9 @@ JitConstants GatherMatmulBatchedGemmGenerator::get_jit_constants(const kernel_im
else
jit.make("NUM_GROUPS", 1);
+ // Scales are physically [E, G, N]; must match GatherMatmulMicroGenerator.
+ jit.make("SCALE_ZP_NO_TRANSPOSE", 1);
+
size_t expert_stride = weight_shape.size() == 4 ? (weight_shape[1] * weight_shape[2] * weight_shape[3]) : (weight_shape[1] * weight_shape[2]);
if (is_u4_i4) {
jit.make("EXPERT_STRIDE", expert_stride / 2);
diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/moe.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/moe.cpp
index 40fbd23133f..754898f729d 100644
--- a/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/moe.cpp
+++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/dynamic/moe.cpp
@@ -250,13 +250,13 @@ TEST_P(MoEGatherMatmulTest, Inference) {
run();
}
-// DISABLED: u8 prefill kernel missing; u4 has accuracy divergence (Δ ≈ 5–45).
-INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_MoEGatherMatmul,
+// u8 excluded: GatherMatmul prefill micro-kernel for u8 is not selectable yet.
+INSTANTIATE_TEST_SUITE_P(smoke_MoEGatherMatmul,
MoEGatherMatmulTest,
::testing::Combine(::testing::ValuesIn(moe_params_smoke),
::testing::Values(MoePatternType::GEMM3),
::testing::ValuesIn(routing_types),
- ::testing::ValuesIn(weights_precisions),
+ ::testing::Values(ov::element::u4),
::testing::Values(ov::element::f16), // decompression_precision
::testing::Values(ov::element::f16), // scale_precision
::testing::Values(ov::test::utils::DecompressionType::full),
@@ -267,13 +267,12 @@ INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_MoEGatherMatmul,
MoEGatherMatmulTest::getTestCaseName);
// 2-GEMM unfused: covers GatherMatmul OCL clamp/bias/swiglu compile path.
-// DISABLED: same u8/u4 issues as above.
-INSTANTIATE_TEST_SUITE_P(DISABLED_smoke_MoE2GemmGatherMatmul,
+INSTANTIATE_TEST_SUITE_P(smoke_MoE2GemmGatherMatmul,
MoEGatherMatmulTest,
::testing::Combine(::testing::ValuesIn(moe_params_smoke),
::testing::Values(MoePatternType::GEMM2),
::testing::Values(MoERoutingType::SOFTMAX),
- ::testing::ValuesIn(weights_precisions),
+ ::testing::Values(ov::element::u4),
::testing::Values(ov::element::f16), // decompression_precision
::testing::Values(ov::element::f16), // scale_precision
::testing::Values(ov::test::utils::DecompressionType::full),