Skip to content

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

[CPU][ARM] Up to 2x faster GQA decode attention: share u8 key/value rows across query heads (#39424)

Clémence Lesné33c6a789908a
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/common.hpp b/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/common.hpp
index d11d790f019..0bfb70a2fc1 100644
--- a/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/common.hpp
+++ b/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/common.hpp
@@ -1007,6 +1007,11 @@ float dot_product(const TA* a,
float group_sum = 0.0F;
float32x4_t v_group_zp = vdupq_n_f32(group_zp);
+ // Independent vector accumulators, reduced once per group.
+ float32x4_t v_sum0 = vdupq_n_f32(0.0F);
+ float32x4_t v_sum1 = vdupq_n_f32(0.0F);
+ float32x4_t v_sum2 = vdupq_n_f32(0.0F);
+ float32x4_t v_sum3 = vdupq_n_f32(0.0F);
for (; i + 16 <= group_size; i += 16) {
uint8x16_t v_u8 = vld1q_u8(b + i + offset);
@@ -1035,15 +1040,10 @@ float dot_product(const TA* a,
float32x4_t v_a2 = vld1q_f32(a + i + offset + 8);
float32x4_t v_a3 = vld1q_f32(a + i + offset + 12);
- v_f0 = vmulq_f32(v_f0, v_a0);
- v_f1 = vmulq_f32(v_f1, v_a1);
- v_f2 = vmulq_f32(v_f2, v_a2);
- v_f3 = vmulq_f32(v_f3, v_a3);
-
- group_sum += vaddvq_f32(v_f0);
- group_sum += vaddvq_f32(v_f1);
- group_sum += vaddvq_f32(v_f2);
- group_sum += vaddvq_f32(v_f3);
+ v_sum0 = vfmaq_f32(v_sum0, v_f0, v_a0);
+ v_sum1 = vfmaq_f32(v_sum1, v_f1, v_a1);
+ v_sum2 = vfmaq_f32(v_sum2, v_f2, v_a2);
+ v_sum3 = vfmaq_f32(v_sum3, v_f3, v_a3);
} else if constexpr (std::is_same_v<TA, ov::float16>) {
float16x8_t v_la0 = vld1q_f16(reinterpret_cast<const float16_t*>(a) + i + offset + 0);
@@ -1054,17 +1054,13 @@ float dot_product(const TA* a,
float32x4_t v_a2 = vcvt_f32_f16(vget_low_f16(v_la1));
float32x4_t v_a3 = vcvt_f32_f16(vget_high_f16(v_la1));
- v_f0 = vmulq_f32(v_f0, v_a0);
- v_f1 = vmulq_f32(v_f1, v_a1);
- v_f2 = vmulq_f32(v_f2, v_a2);
- v_f3 = vmulq_f32(v_f3, v_a3);
-
- group_sum += vaddvq_f32(v_f0);
- group_sum += vaddvq_f32(v_f1);
- group_sum += vaddvq_f32(v_f2);
- group_sum += vaddvq_f32(v_f3);
+ v_sum0 = vfmaq_f32(v_sum0, v_f0, v_a0);
+ v_sum1 = vfmaq_f32(v_sum1, v_f1, v_a1);
+ v_sum2 = vfmaq_f32(v_sum2, v_f2, v_a2);
+ v_sum3 = vfmaq_f32(v_sum3, v_f3, v_a3);
}
}
+ group_sum += vaddvq_f32(vaddq_f32(vaddq_f32(v_sum0, v_sum1), vaddq_f32(v_sum2, v_sum3)));
for (; i < group_size; i++) {
group_sum += a[i + offset] * (static_cast<float>(b[i + offset]) - group_zp);
}
diff --git a/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/mha_single_token.cpp b/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/mha_single_token.cpp
index 95c4132e137..c770a58d623 100644
--- a/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/mha_single_token.cpp
+++ b/src/plugins/intel_cpu/src/nodes/kernels/scaled_attn/mha_single_token.cpp
@@ -25,6 +25,8 @@
#if defined(OPENVINO_ARCH_ARM64)
# include <arm_neon.h>
+
+# include <array>
#endif
namespace ov::Extensions::Cpu::XARCH {
@@ -770,6 +772,11 @@ dot_product_fp16(ov::float16* a, void* b, size_t n, float* scale, float* zp, flo
float group_sum = 0.0f;
auto v_group_zp = vdupq_n_f16(group_zp);
+ // Independent vector accumulators, reduced once per group.
+ float32x4_t v_sum0 = vdupq_n_f32(0.0F);
+ float32x4_t v_sum1 = vdupq_n_f32(0.0F);
+ float32x4_t v_sum2 = vdupq_n_f32(0.0F);
+ float32x4_t v_sum3 = vdupq_n_f32(0.0F);
for (; i + 16 <= group_size; i += 16) {
float16x8_t v_a_lo = vld1q_f16(_a + offset + i);
@@ -794,11 +801,12 @@ dot_product_fp16(ov::float16* a, void* b, size_t n, float* scale, float* zp, flo
float32x4_t v_f2 = vcvt_f32_f16(vget_low_f16(v_b_hi));
float32x4_t v_f3 = vcvt_f32_f16(vget_high_f16(v_b_hi));
- group_sum += vaddvq_f32(v_f0);
- group_sum += vaddvq_f32(v_f1);
- group_sum += vaddvq_f32(v_f2);
- group_sum += vaddvq_f32(v_f3);
+ v_sum0 = vaddq_f32(v_sum0, v_f0);
+ v_sum1 = vaddq_f32(v_sum1, v_f1);
+ v_sum2 = vaddq_f32(v_sum2, v_f2);
+ v_sum3 = vaddq_f32(v_sum3, v_f3);
}
+ group_sum += vaddvq_f32(vaddq_f32(vaddq_f32(v_sum0, v_sum1), vaddq_f32(v_sum2, v_sum3)));
for (; i < group_size; i++) {
group_sum += _a[i + offset] * (_b[i + offset] - group_zp);
}
@@ -1212,6 +1220,199 @@ static void attn_reduce(ov::float16* dst, ov::float16* temp, size_t M, size_t S,
}
#endif
+#if defined(OPENVINO_ARCH_ARM64)
+// Grouped-query attention: the h_each_group_len query heads of a key/value head, and its q_len query tokens, read
+// the same key and value rows. The helpers below dequantize each row once for a tile of up to 4 (token, head) rows:
+// 4 rows x 4 f32x4 accumulators plus the 4 dequantized vectors fit in the 32 NEON registers.
+
+// Loads 16 u8 values as 4 f32 vectors and subtracts the zero point.
+static inline void dequant_u8x16(const uint8_t* src, float32x4_t zp, float32x4_t* out) {
+ const uint8x16_t v_u8 = vld1q_u8(src);
+ const uint16x8_t v_u16_lo = vmovl_u8(vget_low_u8(v_u8));
+ const uint16x8_t v_u16_hi = vmovl_u8(vget_high_u8(v_u8));
+ out[0] = vsubq_f32(vcvtq_f32_u32(vmovl_u16(vget_low_u16(v_u16_lo))), zp);
+ out[1] = vsubq_f32(vcvtq_f32_u32(vmovl_u16(vget_high_u16(v_u16_lo))), zp);
+ out[2] = vsubq_f32(vcvtq_f32_u32(vmovl_u16(vget_low_u16(v_u16_hi))), zp);
+ out[3] = vsubq_f32(vcvtq_f32_u32(vmovl_u16(vget_high_u16(v_u16_hi))), zp);
+}
+
+// Dot products of R f32 query rows with one u8 key row, with the operations and summation order of the ARM64 u8
+// dot_product of common.hpp, so each result equals that function's for the same row.
+// scale_zp holds interleaved {scale, zero point} pairs, one per group of group_size elements.
+template <size_t R>
+static void dot_product_u8_rows(const float* const* q,
+ const uint8_t* k,
+ size_t n,
+ const float* scale_zp,
+ size_t group_size,
+ float* out) {
+ float sum[R] = {};
+ for (size_t group_id = 0; group_id < n / group_size; group_id++) {
+ const float group_scale = scale_zp[group_id * 2];
+ const float group_zp = scale_zp[group_id * 2 + 1];
+ const size_t offset = group_id * group_size;
+ float32x4_t acc[R][4];
+ for (size_t r = 0; r < R; r++) {
+ for (size_t j = 0; j < 4; j++) {
+ acc[r][j] = vdupq_n_f32(0.0F);
+ }
+ }
+ size_t i = 0;
+ for (; i + 16 <= group_size; i += 16) {
+ float32x4_t v_k[4];
+ dequant_u8x16(k + offset + i, vdupq_n_f32(group_zp), v_k);
+ for (size_t r = 0; r < R; r++) {
+ for (size_t j = 0; j < 4; j++) {
+ acc[r][j] = vfmaq_f32(acc[r][j], v_k[j], vld1q_f32(q[r] + offset + i + 4 * j));
+ }
+ }
+ }
+ for (size_t r = 0; r < R; r++) {
+ float group_sum = vaddvq_f32(vaddq_f32(vaddq_f32(acc[r][0], acc[r][1]), vaddq_f32(acc[r][2], acc[r][3])));
+ for (size_t j = i; j < group_size; j++) {
+ group_sum += q[r][offset + j] * (static_cast<float>(k[offset + j]) - group_zp);
+ }
+ sum[r] += group_scale * group_sum;
+ }
+ }
+ for (size_t r = 0; r < R; r++) {
+ out[r] = sum[r];
+ }
+}
+
+// Accumulates one u8 value row into R output rows, out[r] += weight[r] * dequant(v), with the operations, order and
+// 16-element step of attn_acc_value(float*, float, uint8_t*, ...), so each row's result equals that function's.
+// scale_zp holds interleaved {scale, zero point} pairs.
+template <size_t R>
+static void attn_acc_value_u8_rows(float* const* out,
+ const float* weight,
+ const uint8_t* v,
+ size_t S,
+ const float* scale_zp,
+ size_t group_size) {
+ for (size_t group_id = 0; group_id < S / group_size; group_id++) {
+ const float group_scale = scale_zp[group_id * 2];
+ const float group_zp = scale_zp[group_id * 2 + 1];
+ const size_t offset = group_id * group_size;
+ float32x4_t v_scaled_weight[R];
+ for (size_t r = 0; r < R; r++) {
+ v_scaled_weight[r] = vdupq_n_f32(group_scale * weight[r]);
+ }
+ size_t i = 0;
+ for (; i + 16 <= group_size; i += 16) {
+ float32x4_t v_f[4];
+ dequant_u8x16(v + offset + i, vdupq_n_f32(group_zp), v_f);
+ for (size_t r = 0; r < R; r++) {
+ float* dst = out[r] + offset + i;
+ for (size_t j = 0; j < 4; j++) {
+ vst1q_f32(dst + 4 * j, vaddq_f32(vmulq_f32(v_f[j], v_scaled_weight[r]), vld1q_f32(dst + 4 * j)));
+ }
+ }
+ }
+ for (size_t r = 0; r < R; r++) {
+ for (size_t j = i; j < group_size; j++) {
+ out[r][offset + j] += weight[r] * (static_cast<float>(v[offset + j]) - group_zp) * group_scale;
+ }
+ }
+ }
+}
+
+# if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+// f16 outputs, with the per-element operations of attn_acc_value(ov::float16*, ov::float16, uint8_t*, ...) and its
+// step (svcntb() with SVE, 16 with NEON_FP16), so each element takes the same vector or scalar path on every vector
+// length. One difference: the vector loop rounds weight * group_scale to f16 with the hardware conversion, while
+// attn_acc_value uses ov::float16(float), which mis-rounds some f16 subnormals (#38797).
+template <size_t R>
+static void attn_acc_value_u8_rows(ov::float16* const* out,
+ const ov::float16* weight,
+ const uint8_t* v,
+ size_t S,
+ const float* scale_zp,
+ size_t group_size) {
+ for (size_t group_id = 0; group_id < S / group_size; group_id++) {
+ const auto group_scale = static_cast<float16_t>(scale_zp[group_id * 2]);
+ const auto group_zp = static_cast<float16_t>(scale_zp[group_id * 2 + 1]);
+ const size_t offset = group_id * group_size;
+ size_t i = 0;
+# if defined(HAVE_SVE) || defined(HAVE_NEON_FP16)
+ // weight * group_scale per row, rounded in hardware; memcpy reads the ov::float16 bits without type punning.
+ float16_t weighed_group_scale[R]{};
+ for (size_t r = 0; r < R; r++) {
+ float16_t w{};
+ std::memcpy(&w, weight + r, sizeof(w));
+ weighed_group_scale[r] = static_cast<float16_t>(static_cast<float>(w) * static_cast<float>(group_scale));
+ }
+# endif
+# if defined(HAVE_SVE)
+ const svbool_t pg_b08 = svptrue_b8();
+ const svfloat16_t v_group_zp = svdup_n_f16(group_zp);
+ for (; i + svcntb() <= group_size; i += svcntb()) {
+ const svuint8_t v_u8 = svld1_u8(pg_b08, v + offset + i);
+ const svfloat16_t v_f16_lo = svsub_f16_x(pg_b08, svcvt_f16_u16_x(pg_b08, svunpklo_u16(v_u8)), v_group_zp);
+ const svfloat16_t v_f16_hi = svsub_f16_x(pg_b08, svcvt_f16_u16_x(pg_b08, svunpkhi_u16(v_u8)), v_group_zp);
+ for (size_t r = 0; r < R; r++) {
+ // SVE vectors are sizeless and cannot be array elements, so the scale is broadcast per row.
+ const svfloat16_t v_scale = svdup_n_f16(weighed_group_scale[r]);
+ auto* dst = reinterpret_cast<float16_t*>(out[r]) + offset + i;
+ const svfloat16_t v_out_lo = svld1_f16(pg_b08, dst);
+ const svfloat16_t v_out_hi = svld1_f16(pg_b08, dst + svcnth());
+ svst1_f16(pg_b08, dst, svadd_f16_x(pg_b08, v_out_lo, svmul_f16_x(pg_b08, v_f16_lo, v_scale)));
+ svst1_f16(pg_b08,
+ dst + svcnth(),
+ svadd_f16_x(pg_b08, v_out_hi, svmul_f16_x(pg_b08, v_f16_hi, v_scale)));
+ }
+ }
+# elif defined(HAVE_NEON_FP16)
+ const float16x8_t v_group_zp = vdupq_n_f16(group_zp);
+ float16x8_t v_weighed_group_scale[R];
+ for (size_t r = 0; r < R; r++) {
+ v_weighed_group_scale[r] = vdupq_n_f16(weighed_group_scale[r]);
+ }
+ for (; i + 16 <= group_size; i += 16) {
+ const uint8x16_t v_u8 = vld1q_u8(v + offset + i);
+ const float16x8_t v_f16_lo = vsubq_f16(vcvtq_f16_u16(vmovl_u8(vget_low_u8(v_u8))), v_group_zp);
+ const float16x8_t v_f16_hi = vsubq_f16(vcvtq_f16_u16(vmovl_u8(vget_high_u8(v_u8))), v_group_zp);
+ for (size_t r = 0; r < R; r++) {
+ auto* dst = reinterpret_cast<float16_t*>(out[r]) + offset + i;
+ vst1q_f16(dst, vaddq_f16(vld1q_f16(dst), vmulq_f16(v_f16_lo, v_weighed_group_scale[r])));
+ vst1q_f16(dst + 8, vaddq_f16(vld1q_f16(dst + 8), vmulq_f16(v_f16_hi, v_weighed_group_scale[r])));
+ }
+ }
+# endif
+ for (size_t r = 0; r < R; r++) {
+ for (size_t j = i; j < group_size; j++) {
+ out[r][offset + j] += weight[r] * (static_cast<float>(v[offset + j]) - group_zp) * group_scale;
+ }
+ }
+ }
+}
+# endif
+
+// Calls f(std::integral_constant<size_t, R>{}, m) for consecutive tiles [m, m + R) of R <= 4 of the rows = q_len x G
+// (token, head) rows, token-major (row m is query token m / G, head m % G in the group, G = h_each_group_len); a tile
+// may span query tokens.
+template <typename F>
+static void for_each_row_tile(size_t rows, const F& f) {
+ size_t m = 0;
+ for (; m + 4 <= rows; m += 4) {
+ f(std::integral_constant<size_t, 4>{}, m);
+ }
+ switch (rows - m) {
+ case 3:
+ f(std::integral_constant<size_t, 3>{}, m);
+ break;
+ case 2:
+ f(std::integral_constant<size_t, 2>{}, m);
+ break;
+ case 1:
+ f(std::integral_constant<size_t, 1>{}, m);
+ break;
+ default:
+ break;
+ }
+}
+#endif
+
template <typename T, typename T2, typename T3>
static void mha_single_token_kernel(const ov::intel_cpu::PlainTensor& query,
const ov::intel_cpu::PlainTensor& present_key,
@@ -1269,6 +1470,22 @@ static void mha_single_token_kernel(const ov::intel_cpu::PlainTensor& query,
}
#endif
+#if defined(OPENVINO_ARCH_ARM64)
+ // dot_product_u8_rows reads f32 query rows, so grouped key scoring converts other query types once here, into
+ // buf_attn_score, instead of once per key row; with f16 kernels it thus replaces dot_product_fp16's f16 products
+ // by f32 ones. query_f32 aliases buf_attn_score, which the value phase resizes and clears: it is valid only in
+ // the key phase, and the buffer keeps the larger of the two sizes.
+ const bool group_heads = std::is_same_v<T2, uint8_t> && !quant_key_by_channel && h_each_group_len > 1;
+ if constexpr (!std::is_same_v<T, float>) {
+ if (group_heads) {
+ buf_attn_score.resize<float>({B, H, q_len, S});
+ cpu_parallel->parallel_for3d(B, H, q_len, [&](size_t b, size_t h, size_t pq) {
+ cvt_copy(buf_attn_score.ptr<float>(b, h, pq), query.ptr<T>(b, h, pq), S);
+ });
+ }
+ }
+#endif
+
parallel_nt_static(nthr, [&](const size_t ithr, const size_t nthr) {
size_t start{0};
size_t end{0};
@@ -1386,6 +1603,49 @@ static void mha_single_token_kernel(const ov::intel_cpu::PlainTensor& query,
}
}
} else {
+#if defined(OPENVINO_ARCH_ARM64)
+ if constexpr (std::is_same_v<T2, uint8_t>) {
+ if (group_heads) {
+ const ov::intel_cpu::PlainTensor& query_f32 = std::is_same_v<T, float> ? query : buf_attn_score;
+ for (size_t iwork = start; iwork < end; ++iwork) {
+ auto b_kv = beams ? beams.ptr<int32_t>(b)[pk] : b;
+ const auto* p = past_k_scale_zp.ptr<float>(pk, b_kv, h_group);
+ const auto* k = present_key.ptr<uint8_t>(b_kv, h_group, pk);
+ const size_t h0 = h_group * h_each_group_len;
+ for_each_row_tile(q_len * h_each_group_len, [&](auto tile, size_t m) {
+ constexpr size_t R = decltype(tile)::value;
+ std::array<const float*, R> q_rows{};
+ std::array<T3*, R> dst_rows{};
+ for (size_t r = 0; r < R; r++) {
+ const size_t pq = (m + r) / h_each_group_len;
+ const size_t h = h0 + (m + r) % h_each_group_len;
+ q_rows[r] = query_f32.ptr<float>(b, h, pq);
+ dst_rows[r] = buf_attn_w.ptr<T3>(b, h, pq) + pk;
+ }
+ std::array<float, R> qk{};
+ dot_product_u8_rows<R>(q_rows.data(), k, S, p, key_group_size, qk.data());
+ for (size_t r = 0; r < R; r++) {
+ T3* dst = dst_rows[r];
+# if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+ if constexpr (std::is_same_v<T3, ov::float16>) {
+ // Hardware rounding, not the out-of-line ov::float16 constructor (they differ
+ // only for f16 subnormals, #38797). float16_t takes this file's usual guard,
+ // and memcpy stores its bits into ov::float16 without type punning (the
+ // void* cast keeps GCC's -Wclass-memaccess quiet).
+ const auto qk_f16 = static_cast<float16_t>(qk[r]);
+ std::memcpy(static_cast<void*>(dst), &qk_f16, sizeof(qk_f16));
+ continue;
+ }
+# endif
+ *dst = static_cast<T3>(qk[r]);
+ }
+ });
+ parallel_it_step(pk, kv_len, b, B, h_group, h_group_num);
+ }
+ return;
+ }
+ }
+#endif
for (size_t iwork = start; iwork < end; ++iwork) {
auto b_kv = beams ? beams.ptr<int32_t>(b)[pk] : b;
for (size_t pq = 0; pq < q_len; pq++) {
@@ -1484,6 +1744,28 @@ static void mha_single_token_kernel(const ov::intel_cpu::PlainTensor& query,
auto b_kv = beams ? beams.ptr<int32_t>(b)[pv] : b;
auto* v = present_value.ptr<T2>(b_kv, h_group, pv);
auto* p = past_v_scale_zp.ptr<float>(pv, b_kv, h_group);
+#if defined(OPENVINO_ARCH_ARM64)
+ // Values are quantized per token whatever quant_key_by_channel, so both value paths group heads on
+ // h_each_group_len alone, unlike group_heads.
+ if constexpr (std::is_same_v<T2, uint8_t>) {
+ if (h_each_group_len > 1) {
+ const size_t h0 = h_group * h_each_group_len;
+ for_each_row_tile(q_len * h_each_group_len, [&](auto tile, size_t m) {
+ constexpr size_t R = decltype(tile)::value;
+ std::array<T3*, R> out{};
+ std::array<T3, R> w{};
+ for (size_t r = 0; r < R; r++) {
+ const size_t pq = (m + r) / h_each_group_len;
+ const size_t g = (m + r) % h_each_group_len;
+ out[r] = buf_attn_score.ptr<T3>(ithr, pq, g);
+ w[r] = buf_attn_w.ptr<T3>(b, h0 + g, pq)[pv];
+ }
+ attn_acc_value_u8_rows<R>(out.data(), w.data(), v, SV, p, value_group_size);
+ });
+ continue;
+ }
+ }
+#endif
for (size_t pq = 0; pq < q_len; pq++) {
for (size_t h = h_group * h_each_group_len, group_idx = 0; h < (h_group + 1) * h_each_group_len;
h++, group_idx++) {
@@ -1542,6 +1824,27 @@ static void mha_single_token_kernel(const ov::intel_cpu::PlainTensor& query,
auto b_kv = beams ? beams.ptr<int32_t>(b)[pv] : b;
auto* v = present_value.ptr<T2>(b_kv, h_group, pv);
auto* p = past_v_scale_zp.ptr<float>(pv, b_kv, h_group);
+#if defined(OPENVINO_ARCH_ARM64)
+ if constexpr (std::is_same_v<T2, uint8_t>) {
+ if (h_each_group_len > 1) {
+ const size_t h0 = h_group * h_each_group_len;
+ for_each_row_tile(q_len * h_each_group_len, [&](auto tile, size_t m) {
+ constexpr size_t R = decltype(tile)::value;
+ std::array<T3*, R> out{};
+ std::array<T3, R> w{};
+ for (size_t r = 0; r < R; r++) {
+ const size_t pq = (m + r) / h_each_group_len;
+ const size_t g = (m + r) % h_each_group_len;
+ out[r] = buf_attn_score.ptr<T3>(ithr, b, pq, h0 + g);
+ w[r] = buf_attn_w.ptr<T3>(b, h0 + g, pq)[pv];
+ }
+ attn_acc_value_u8_rows<R>(out.data(), w.data(), v, SV, p, value_group_size);
+ });
+ parallel_it_step(pv, kv_len, b, B, h_group, h_group_num);
+ continue;
+ }
+ }
+#endif
for (size_t pq = 0; pq < q_len; pq++) {
for (size_t h = h_group * h_each_group_len; h < (h_group + 1) * h_each_group_len; h++) {
attn_acc_value(buf_attn_score.ptr<T3>(ithr, b, pq, h),
diff --git a/src/plugins/intel_cpu/src/nodes/scaled_attn.cpp b/src/plugins/intel_cpu/src/nodes/scaled_attn.cpp
index 4eac33eea3c..137d79476d0 100644
--- a/src/plugins/intel_cpu/src/nodes/scaled_attn.cpp
+++ b/src/plugins/intel_cpu/src/nodes/scaled_attn.cpp
@@ -1599,7 +1599,7 @@ struct ScaledDotProductAttention::AttentionExecutor : public ScaledDotProductAtt
// Use mha_kv_cache pipeline for all single-token decoding.
// This unifies quantized (u8/u4) and raw paths through a single codec-generic pipeline.
- // temporary OV_TURBOQ_LEGACY_ATTN=1 reverts to the old per-type dispatch.
+ // temporary OV_CPU_LEGACY_ATTN=1 reverts to the old per-type dispatch.
// ARM SIMD abstraction not yet wired through mha_kv_cache — fall back to legacy.
#if defined(OPENVINO_ARCH_ARM) || defined(OPENVINO_ARCH_ARM64)
const bool use_new_pipeline = false;
diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/arm/concat_sdp_gqa.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/arm/concat_sdp_gqa.cpp
new file mode 100644
index 00000000000..69f5d61ee53
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/arm/concat_sdp_gqa.cpp
@@ -0,0 +1,165 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+#include "custom/subgraph_tests/src/classes/concat_sdp.hpp"
+#include "openvino/runtime/exec_model_info.hpp"
+#include "openvino/runtime/system_conf.hpp"
+#include "utils/cpu_test_utils.hpp"
+
+namespace ov {
+namespace test {
+namespace {
+
+// Grouped-query attention (several query heads per key/value head) through the stateful SDPA node, with the
+// default u8 cache, plus an MHA control in the f16 suite. The grouped-query kernel paths are ARM64 only.
+#if defined(OPENVINO_ARCH_ARM64)
+
+const std::vector<std::vector<InputShape>> input_shapes = {
+ // greedy search, with a 20-token prompt continuation over a past
+ {
+ {{1, 8, -1, 64}, {{1, 8, 10, 64}, {1, 8, 1, 64}, {1, 8, 1, 64}, {1, 8, 20, 64}, {1, 8, 1, 64}}},
+ {{1, 8, -1, 64}, {{1, 8, 0, 64}, {1, 8, 10, 64}, {1, 8, 11, 64}, {1, 8, 12, 64}, {1, 8, 32, 64}}},
+ },
+ // beam search
+ {
+ {{-1, 8, -1, 64}, {{4, 8, 10, 64}, {4, 8, 1, 64}, {4, 8, 1, 64}, {4, 8, 1, 64}, {4, 8, 1, 64}}},
+ {{-1, 8, -1, 64}, {{4, 8, 0, 64}, {4, 8, 10, 64}, {4, 8, 11, 64}, {4, 8, 12, 64}, {4, 8, 13, 64}}},
+ },
+ // big batch: 129 sequences, at least the thread count of usual hosts, for the per-sequence value path
+ {
+ {{-1, 8, -1, 64}, {{129, 8, 10, 64}, {129, 8, 1, 64}, {129, 8, 1, 64}, {129, 8, 1, 64}, {129, 8, 1, 64}}},
+ {{-1, 8, -1, 64}, {{129, 8, 0, 64}, {129, 8, 10, 64}, {129, 8, 11, 64}, {129, 8, 12, 64}, {129, 8, 13, 64}}},
+ },
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_ConcatSDPTest_GQA,
+ ConcatSDPTest,
+ ::testing::Combine(::testing::Values(ElementType::f32),
+ ::testing::ValuesIn(input_shapes),
+ ::testing::Values(ov::AnyMap{}),
+ ::testing::Values(false),
+ ::testing::Values<int64_t>(8),
+ ::testing::Values<int64_t>(2, 1)),
+ ConcatSDPTest::getTestCaseName);
+
+// The same subgraph with f16 inference precision on f32 inputs, so the node runs its f16 kernels. ConcatSDPTest's
+// own f16 instances skip without x86 AVX512-FP16, so on every ARM host.
+class ConcatSDPGQAF16Test : public ConcatSDPTest {
+protected:
+ void SetUp() override {
+ if (!ov::with_cpu_neon_fp16()) {
+ GTEST_SKIP() << "Host has no f16 vector arithmetic.";
+ }
+ ConcatSDPTest::SetUp();
+ configuration[ov::hint::inference_precision.name()] = ov::element::f16;
+ // Both the node and the decomposed reference run in f16.
+ abs_threshold = 0.03;
+ }
+
+ void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
+ ConcatSDPTest::generate_inputs(targetInputStaticShapes);
+ if (!m_scale_query) {
+ return;
+ }
+ // With q and k ~ N(0, 0.2), q.k / sqrt(S) has a deviation of 0.04: the softmax is nearly uniform and the
+ // outputs hardly depend on the key scores. A 25 times larger query gives logits of unit deviation.
+ auto& q = inputs.at(function->get_parameters()[0]);
+ auto* data = q.data<float>();
+ for (size_t i = 0; i < q.get_size(); ++i) {
+ data[i] *= 25.0F;
+ }
+ }
+
+ void run() override {
+ // f16 kernels against the f32 ones on the same model and cache, where the cache quantization noise mostly
+ // cancels, with key scores that matter; then against the decomposed reference with the base inputs, whose
+ // larger tolerance covers the cache quantization.
+ auto f32_config = configuration;
+ f32_config[ov::hint::inference_precision.name()] = ov::element::f32;
+ m_scale_query = true;
+ const auto expected = run_test(function, f32_config);
+ const auto actual = run_test(function, configuration);
+ m_scale_query = false;
+ const auto abs = abs_threshold;
+ const auto rel = rel_threshold;
+ abs_threshold = F16_VS_F32_ABS;
+ rel_threshold = 0.0;
+ for (size_t i = 0; i < actual.size(); ++i) {
+ compare(expected[i], actual[i]);
+ }
+ abs_threshold = abs;
+ rel_threshold = rel;
+ ConcatSDPTest::run();
+ }
+
+ // About 10 f16 ulps for outputs in [1, 2) (the subgraph adds 1 to the attention). Largest difference measured over
+ // all inference steps on Apple M5 with the scaled query: 4.9e-3 (GQA) and 4.3e-3 (MHA); breaking the f16 key loop
+ // gives 0.16 to 0.24.
+ static constexpr double F16_VS_F32_ABS = 1e-2;
+ bool m_scale_query = false;
+};
+
+TEST_P(ConcatSDPGQAF16Test, CompareWithRefs) {
+ SKIP_IF_CURRENT_TEST_IS_DISABLED();
+ run();
+ // The stateful fusion must keep the cache in the node, as ConcatSDPTest checks, and the node must run in f16:
+ // with an f32 fallback both runs above would use the same kernels.
+ CheckNumberOfNodesWithType(compiledModel, "ScaledDotProductAttention", 1);
+ CheckNumberOfNodesWithType(compiledModel, "Concatenation", 0);
+ CheckNumberOfNodesWithType(compiledModel, "Gather", 0);
+ for (const auto& node : GetNodesWithTypes(compiledModel.get_runtime_model(), {"ScaledDotProductAttention"})) {
+ EXPECT_EQ(node->get_rt_info().at(ov::exec_model_info::RUNTIME_PRECISION).as<ov::element::Type>(),
+ ov::element::f16);
+ }
+}
+
+INSTANTIATE_TEST_SUITE_P(smoke_ConcatSDPGQAF16Test,
+ ConcatSDPGQAF16Test,
+ ::testing::Combine(::testing::Values(ElementType::f32),
+ ::testing::ValuesIn(input_shapes),
+ ::testing::Values(ov::AnyMap{}),
+ ::testing::Values(false),
+ ::testing::Values<int64_t>(8),
+ ::testing::Values<int64_t>(2)),
+ ConcatSDPTest::getTestCaseName);
+
+// MHA control: with one query head per key/value head, scores take dot_product_fp16<u8> (f16 products) and values
+// accumulate per head, instead of the grouped paths; its NEON_FP16 loop runs on hosts without SVE. Greedy (B = 1,
+// with a 20-token continuation) and beam search (B = 4).
+INSTANTIATE_TEST_SUITE_P(smoke_ConcatSDPGQAF16Test_MHAControl,
+ ConcatSDPGQAF16Test,
+ ::testing::Combine(::testing::Values(ElementType::f32),
+ ::testing::Values(input_shapes[0], input_shapes[1]),
+ ::testing::Values(ov::AnyMap{}),
+ ::testing::Values(false),
+ ::testing::Values<int64_t>(8),
+ ::testing::Values<int64_t>(8)),
+ ConcatSDPTest::getTestCaseName);
+
+// Head size 80 in key and value quantization groups of 40. For the f16 value rows, per group: 2 steps of 16 and a
+// tail of 8 with NEON_FP16 and 128-bit SVE, 1 step of 32 and a tail of 8 with 256-bit SVE, only the scalar loop at
+// 512 bits; the key loops also run 2 steps of 16 and a tail of 8 per group. 6 query heads over 2 or 1 key/value heads
+// give tiles of 3, and of 4 and 2, query heads; over 6, the per-head key path (dot_product_fp16<u8>).
+const std::vector<std::vector<InputShape>> input_shapes_head80 = {
+ {
+ {{-1, 6, -1, 80}, {{4, 6, 10, 80}, {4, 6, 1, 80}, {4, 6, 1, 80}, {4, 6, 1, 80}, {4, 6, 1, 80}}},
+ {{-1, 6, -1, 80}, {{4, 6, 0, 80}, {4, 6, 10, 80}, {4, 6, 11, 80}, {4, 6, 12, 80}, {4, 6, 13, 80}}},
+ },
+};
+
+INSTANTIATE_TEST_SUITE_P(smoke_ConcatSDPGQAF16Test_ValueGroups,
+ ConcatSDPGQAF16Test,
+ ::testing::Combine(::testing::Values(ElementType::f32),
+ ::testing::ValuesIn(input_shapes_head80),
+ ::testing::Values(ov::AnyMap{{ov::value_cache_group_size.name(), "40"},
+ {ov::key_cache_group_size.name(), "40"}}),
+ ::testing::Values(false),
+ ::testing::Values<int64_t>(6),
+ ::testing::Values<int64_t>(6, 2, 1)),
+ ConcatSDPTest::getTestCaseName);
+
+#endif // OPENVINO_ARCH_ARM64
+
+} // namespace
+} // namespace test
+} // namespace ov
diff --git a/src/plugins/intel_cpu/tests/functional/sources.cmake b/src/plugins/intel_cpu/tests/functional/sources.cmake
index 21a614222d3..60aa4a2b500 100644
--- a/src/plugins/intel_cpu/tests/functional/sources.cmake
+++ b/src/plugins/intel_cpu/tests/functional/sources.cmake
@@ -755,6 +755,7 @@ set(TMP_LIST_OF_ARM_TEST_INSTANCES
set(TMP_LIST_OF_ARM_SUBGRAPH_TESTS
${CMAKE_CURRENT_LIST_DIR}/custom/subgraph_tests/src/arm/concat_sdp.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/custom/subgraph_tests/src/arm/concat_sdp_gqa.cpp
${CMAKE_CURRENT_LIST_DIR}/custom/subgraph_tests/src/arm/conv_fq.cpp
${CMAKE_CURRENT_LIST_DIR}/custom/subgraph_tests/src/arm/convert_group_conv.cpp
${CMAKE_CURRENT_LIST_DIR}/custom/subgraph_tests/src/arm/convert_group_conv1d.cpp
diff --git a/src/plugins/intel_cpu/tests/unit/scaled_attn_mha_single_token_gqa_test.cpp b/src/plugins/intel_cpu/tests/unit/scaled_attn_mha_single_token_gqa_test.cpp
new file mode 100644
index 00000000000..70b90c852d9
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/unit/scaled_attn_mha_single_token_gqa_test.cpp
@@ -0,0 +1,282 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+// Checks the single-token SDPA kernel with a u8 cache against a scalar double-precision reference, for
+// grouped-query attention (several query heads per key/value head). Runs the baseline build of the kernel.
+
+#include <gtest/gtest.h>
+
+#include <algorithm>
+#include <cmath>
+#include <cstddef>
+#include <cstdint>
+#include <memory>
+#include <random>
+#include <string>
+#include <vector>
+
+#include "cpu_parallel.hpp"
+#include "nodes/kernels/scaled_attn/mha_single_token.hpp"
+#include "openvino/core/parallel.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "openvino/core/type/float16.hpp"
+#include "utils/plain_tensor.hpp"
+
+using ov::intel_cpu::PlainTensor;
+
+namespace {
+
+struct Case {
+ ov::element::Type q_prec;
+ size_t B, H, Hk, q_len, kv_len, S;
+ size_t group; // quantization group, in channels (in tokens for by_channel keys)
+ bool beams;
+ bool causal;
+ bool by_channel;
+};
+
+std::string case_name(const ::testing::TestParamInfo<Case>& info) {
+ const auto& c = info.param;
+ return c.q_prec.get_type_name() + "_B" + std::to_string(c.B) + "_H" + std::to_string(c.H) + "_Hk" +
+ std::to_string(c.Hk) + "_q" + std::to_string(c.q_len) + "_kv" + std::to_string(c.kv_len) + "_S" +
+ std::to_string(c.S) + "_grp" + std::to_string(c.group) + (c.beams ? "_beams" : "") +
+ (c.causal ? "_causal" : "") + (c.by_channel ? "_bychannel" : "");
+}
+
+class MhaSingleTokenGqaTest : public ::testing::TestWithParam<Case> {
+protected:
+ void SetUp() override {
+ c = GetParam();
+ std::mt19937 rng(42);
+ std::uniform_real_distribution<float> unit(-1.0F, 1.0F);
+ std::uniform_int_distribution<int> byte(0, 255);
+ std::uniform_real_distribution<float> scale(0.004F, 0.012F);
+ std::uniform_real_distribution<float> zp(96.0F, 160.0F);
+
+ // Layouts of the node: the query is a permuted [B, L, H, S] tensor and the caches are views into
+ // buffers with room for more tokens.
+ q_full.resize({c.B, c.q_len, c.H, c.S}, c.q_prec.size(), c.q_prec);
+ query = q_full.permute({0, 2, 1, 3});
+ for (size_t i = 0; i < c.B * c.q_len * c.H * c.S; i++) {
+ const float v = unit(rng);
+ if (c.q_prec == ov::element::f16) {
+ q_full.ptr<ov::float16>()[i] = ov::float16(v);
+ } else {
+ q_full.ptr<float>()[i] = v;
+ }
+ }
+ k_full.resize<uint8_t>({c.B, c.Hk, c.kv_len + 8, c.S});
+ v_full.resize<uint8_t>({c.B, c.Hk, c.kv_len + 8, c.S});
+ for (size_t i = 0; i < c.B * c.Hk * (c.kv_len + 8) * c.S; i++) {
+ k_full.ptr<uint8_t>()[i] = static_cast<uint8_t>(byte(rng));
+ v_full.ptr<uint8_t>()[i] = static_cast<uint8_t>(byte(rng));
+ }
+ present_key = k_full.slice(2, 0, static_cast<int>(c.kv_len));
+ present_value = v_full.slice(2, 0, static_cast<int>(c.kv_len));
+
+ // Interleaved {scale, zero point} per token and channel group; by-channel keys instead keep a row of
+ // per-channel scales and a row of zero points per token group.
+ if (c.by_channel) {
+ k_scale_zp.resize<float>({2 * ((c.kv_len + c.group - 1) / c.group), c.B, c.Hk, c.S});
+ } else {
+ k_scale_zp.resize<float>({c.kv_len, c.B, c.Hk, 2 * (c.S / c.group)});
+ }
+ v_scale_zp.resize<float>({c.kv_len, c.B, c.Hk, 2 * (c.S / c.group)});
+ for (size_t i = 0; i < k_scale_zp.size(0) * k_scale_zp.stride(0); i++) {
+ const bool is_zp = c.by_channel ? (i / k_scale_zp.stride(0)) % 2 : i % 2;
+ k_scale_zp.ptr<float>()[i] = is_zp ? zp(rng) : scale(rng);
+ }
+ for (size_t i = 0; i < v_scale_zp.size(0) * v_scale_zp.stride(0); i++) {
+ v_scale_zp.ptr<float>()[i] = i % 2 ? zp(rng) : scale(rng);
+ }
+ if (c.beams) {
+ beams.resize<int32_t>({c.B, c.kv_len});
+ std::uniform_int_distribution<int32_t> pick(0, static_cast<int32_t>(c.B) - 1);
+ for (size_t i = 0; i < c.B * c.kv_len; i++) {
+ beams.ptr<int32_t>()[i] = pick(rng);
+ }
+ }
+ }
+
+ double query_at(size_t b, size_t h, size_t l, size_t s) const {
+ return c.q_prec == ov::element::f16 ? static_cast<float>(*query.ptr<ov::float16>(b, h, l, s))
+ : *query.ptr<float>(b, h, l, s);
+ }
+ double key_at(size_t b, size_t hk, size_t t, size_t s) const {
+ double scale = 0.0;
+ double zero_point = 0.0;
+ if (c.by_channel) {
+ scale = *k_scale_zp.ptr<float>(t / c.group * 2, b, hk, s);
+ zero_point = *k_scale_zp.ptr<float>(t / c.group * 2 + 1, b, hk, s);
+ } else {
+ scale = k_scale_zp.ptr<float>(t, b, hk)[s / c.group * 2];
+ zero_point = k_scale_zp.ptr<float>(t, b, hk)[s / c.group * 2 + 1];
+ }
+ return (present_key.ptr<uint8_t>(b, hk, t)[s] - zero_point) * scale;
+ }
+ double value_at(size_t b, size_t hk, size_t t, size_t s) const {
+ const float* p = v_scale_zp.ptr<float>(t, b, hk) + s / c.group * 2;
+ return (present_value.ptr<uint8_t>(b, hk, t)[s] - static_cast<double>(p[1])) * p[0];
+ }
+
+ // Attention in double precision: query head h reads key/value head h / G, as the repeated key/value heads of a
+ // GQA model do. With causal, the q_len tokens are the last ones of the cache (the node's fused past).
+ std::vector<double> reference() const {
+ const size_t G = c.H / c.Hk;
+ std::vector<double> out(c.B * c.H * c.q_len * c.S, 0.0);
+ std::vector<double> w(c.kv_len);
+ for (size_t b = 0; b < c.B; b++) {
+ for (size_t h = 0; h < c.H; h++) {
+ for (size_t l = 0; l < c.q_len; l++) {
+ const size_t valid = c.causal ? c.kv_len - c.q_len + l + 1 : c.kv_len;
+ double max = -INFINITY;
+ double sum = 0.0;
+ for (size_t t = 0; t < valid; t++) {
+ const size_t bk = c.beams ? beams.ptr<int32_t>(b)[t] : b;
+ double dot = 0.0;
+ for (size_t s = 0; s < c.S; s++) {
+ dot += query_at(b, h, l, s) * key_at(bk, h / G, t, s);
+ }
+ w[t] = dot / std::sqrt(static_cast<double>(c.S));
+ max = std::max(max, w[t]);
+ }
+ for (size_t t = 0; t < valid; t++) {
+ w[t] = std::exp(w[t] - max);
+ sum += w[t];
+ }
+ for (size_t t = 0; t < valid; t++) {
+ const size_t bk = c.beams ? beams.ptr<int32_t>(b)[t] : b;
+ for (size_t s = 0; s < c.S; s++) {
+ out[((b * c.H + h) * c.q_len + l) * c.S + s] += w[t] / sum * value_at(bk, h / G, t, s);
+ }
+ }
+ }
+ }
+ }
+ return out;
+ }
+
+ // Runs the kernel with the given number of threads; returns out[b][h][l][s].
+ std::vector<float> run(int threads) {
+ PlainTensor output;
+ output.resize({c.B, c.H, c.q_len, c.S}, c.q_prec.size(), c.q_prec);
+ // The node allocates the score buffer as f32 rows padded to 16, whatever the kernel's score type.
+ PlainTensor attn_w;
+ attn_w.resize<float>({c.B, c.H, c.q_len, (c.kv_len + 15) / 16 * 16});
+ PlainTensor attn_score;
+ PlainTensor head_sum;
+ PlainTensor none;
+ auto cpu_parallel = std::make_shared<ov::intel_cpu::CpuParallel>(ov::intel_cpu::TbbPartitioner::STATIC);
+ auto call = [&]() {
+ ov::Extensions::Cpu::XARCH::mha_single_token(query,
+ present_key,
+ present_value,
+ none,
+ none,
+ beams,
+ output,
+ attn_w,
+ attn_score,
+ false,
+ c.causal,
+ 1.0F / std::sqrt(static_cast<float>(c.S)),
+ k_scale_zp,
+ v_scale_zp,
+ head_sum,
+ c.group,
+ c.group,
+ c.by_channel,
+ none,
+ cpu_parallel);
+ };
+#if OV_THREAD_USE_TBB
+ tbb::task_arena(threads).execute([&]() {
+ ASSERT_EQ(parallel_get_max_threads(), threads);
+ call();
+ });
+#else
+ (void)threads; // without TBB the host's thread count is used, so only one value path may run
+ call();
+#endif
+ std::vector<float> out(c.B * c.H * c.q_len * c.S);
+ for (size_t i = 0; i < out.size(); i++) {
+ out[i] = c.q_prec == ov::element::f16 ? static_cast<float>(output.ptr<ov::float16>()[i])
+ : output.ptr<float>()[i];
+ }
+ return out;
+ }
+
+ Case c{};
+ PlainTensor q_full, query, k_full, v_full, present_key, present_value, k_scale_zp, v_scale_zp, beams;
+};
+
+TEST_P(MhaSingleTokenGqaTest, MatchesReference) {
+ const auto ref = reference();
+ // The plugin object library compiles the kernel once with the default ISA flags, as this file is compiled, so the
+ // macro below tells which kernel instantiation runs for f16 queries.
+#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
+ // f16 scores, weights and value accumulators, without the NEON_FP16 / SVE f16 loops in this build.
+ constexpr double f16_tol = 5e-3;
+#else
+ // f32 scores and accumulators; only the output is rounded to f16.
+ constexpr double f16_tol = 2e-3;
+#endif
+ // Absolute tolerances on outputs of magnitude below 1: several times the largest error measured on Apple M5, and
+ // with f32 accumulators several times the f16 rounding of the output (at most 2.4e-4).
+ const double tol = c.q_prec == ov::element::f16 ? f16_tol : 1e-5;
+ // With 1 thread every batch has at least as many sequences as threads, which selects the per-sequence value
+ // path; with 3 threads, batches of 1 and 2 take the path that splits the cache across threads.
+ for (const int threads : {1, 3}) {
+ const auto out = run(threads);
+ for (size_t i = 0; i < out.size(); i++) {
+ ASSERT_NEAR(out[i], ref[i], tol) << threads << " threads, index " << i;
+ }
+ }
+}
+
+const auto f32 = ov::element::f32;
+const auto f16 = ov::element::f16;
+
+// clang-format off
+const std::vector<Case> cases = {
+ // q B H Hk q_len kv_len S group beams causal by_channel
+ // G = H / Hk of 1-5 and 7: tiles of up to 4 heads with remainders of 1, 2 and 3; G = 1 does not group.
+ {f32, 1, 2, 2, 1, 129, 128, 128, false, false, false},
+ {f32, 1, 4, 2, 1, 129, 128, 128, false, false, false},
+ {f32, 1, 6, 2, 1, 129, 128, 128, false, false, false},
+ {f32, 1, 8, 2, 1, 129, 128, 128, false, false, false},
+ {f32, 1, 10, 2, 1, 129, 128, 128, false, false, false},
+ {f32, 1, 14, 2, 1, 129, 128, 128, false, false, false},
+ // Several quantization groups, and a group size that leaves a scalar tail.
+ {f32, 1, 8, 2, 1, 33, 64, 32, false, false, false},
+ {f32, 1, 8, 2, 1, 33, 80, 40, false, false, false},
+ // One query head per key/value head over several key groups with a tail: the per-head key path.
+ {f32, 1, 2, 2, 1, 33, 80, 40, false, false, false},
+ // A single cached token.
+ {f32, 1, 14, 2, 1, 1, 64, 64, false, false, false},
+ // Query tokens with a past (rows are token and head pairs), beams, and causal truncation.
+ {f32, 2, 6, 2, 3, 33, 64, 64, true, false, false},
+ {f32, 4, 6, 2, 3, 33, 64, 64, true, false, false},
+ {f32, 2, 8, 2, 3, 40, 64, 64, false, true, false},
+ // Causal truncation with tiles that span query tokens (G = 3).
+ {f32, 2, 6, 2, 3, 40, 64, 64, false, true, false},
+ // Keys quantized per channel keep the per-head key path; values still use the grouped path.
+ {f32, 1, 8, 2, 1, 64, 64, 32, false, false, true},
+ // f16 queries: converted to f32 for the grouped key path (G = 1 in the third case, which does not group and, with
+ // GCC, is the only test of common.hpp's f16 u8 dot product); f16 scores and value rows when the macro above is
+ // defined (as with Apple clang), else the f32 path.
+ {f16, 2, 6, 2, 3, 33, 64, 64, false, false, false},
+ {f16, 4, 6, 2, 3, 33, 64, 64, true, false, false},
+ {f16, 1, 2, 2, 1, 33, 64, 64, false, false, false},
+ {f16, 2, 6, 2, 3, 40, 64, 64, false, true, false},
+ // f16 queries over several quantization groups, with an 8-element tail in the 16-wide NEON loops; the f16 value
+ // loops of the NEON_FP16 and SVE builds are covered by smoke_ConcatSDPGQAF16Test_ValueGroups.
+ {f16, 1, 8, 2, 1, 33, 80, 40, false, false, false},
+ {f16, 1, 2, 2, 1, 33, 80, 40, false, false, false},
+};
+// clang-format on
+
+INSTANTIATE_TEST_SUITE_P(smoke_MhaSingleTokenGqa, MhaSingleTokenGqaTest, ::testing::ValuesIn(cases), case_name);
+
+} // namespace
diff --git a/src/plugins/intel_cpu/tests/unit/sources.cmake b/src/plugins/intel_cpu/tests/unit/sources.cmake
index bb6e7312c85..2c2ca0a5b04 100644
--- a/src/plugins/intel_cpu/tests/unit/sources.cmake
+++ b/src/plugins/intel_cpu/tests/unit/sources.cmake
@@ -220,6 +220,7 @@ set(CPU_UNIT_TESTS_AARCH64_SRCS
${CMAKE_CURRENT_LIST_DIR}/snippets_transformations/aarch64/snipptes_mark_skipped.cpp
${CMAKE_CURRENT_LIST_DIR}/snippets_transformations/aarch64/lowered/adjust_gemm_copy_b_loop_ports.cpp
${CMAKE_CURRENT_LIST_DIR}/snippets_transformations/aarch64/lowered/gemm_blocking.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/scaled_attn_mha_single_token_gqa_test.cpp
)
set(CPU_UNIT_TESTS_MLAS_SRCS