Commit bb5aacd61 for llama.cpp
commit bb5aacd61dd8e3dd3ab500e8ea5ecdae40b25823
Author: thelittlefireman <5165783+thelittlefireman@users.noreply.github.com>
Date: Mon Nov 30 00:02:48 2026 +0100
ggml-cuda: Add GCN HIP sparse fattn (#30370)
Assisted-by: ChatGPT
diff --git a/ggml/src/ggml-cuda/fattn-tile.cuh b/ggml/src/ggml-cuda/fattn-tile.cuh
index 2b962552b..d224c1561 100644
--- a/ggml/src/ggml-cuda/fattn-tile.cuh
+++ b/ggml/src/ggml-cuda/fattn-tile.cuh
@@ -373,9 +373,21 @@ static constexpr __device__ int ggml_cuda_fattn_tile_get_nbatch_K(const int DKQ,
return (ggml_cuda_fattn_tile_get_config(DKQ, DV, ncols) >> 23) & ((1 << 9) - 1);
}
+#ifdef GGML_USE_HIP
+// The sparse launch pins ncols1 == 1, so the ncols2 parameter is the total number of Q columns per block.
+static constexpr bool ggml_cuda_flash_attn_ext_tile_may_use_sparse(
+ const int DKQ, const int DV, const int ncols2, const bool use_logit_softcap) {
+ return DKQ > 64 && ncols2 > 1 && !use_logit_softcap &&
+ ggml_cuda_fattn_tile_get_config_amd(DKQ, DV, ncols2) != 0 &&
+ ggml_cuda_fattn_tile_get_config_amd_rdna(DKQ, DV, ncols2) != 0;
+}
+
+bool ggml_cuda_flash_attn_ext_tile_shall_use_sparse(const int cc, const ggml_tensor * dst, const int DKQ, const int DV);
+#endif // GGML_USE_HIP
+
// Function that performs a single iteration in for the KQ matrix multiplication:
template <int warp_size, int nwarps, int ncols1, int ncols2, int DKQ, int nbatch_fa, int nbatch_K,
- bool use_logit_softcap, bool oob_check, bool indexed_bias, typename T_vec_dot, typename T_K>
+ bool use_logit_softcap, bool oob_check, bool indexed_bias, bool use_sparse, typename T_vec_dot, typename T_K>
static __device__ __forceinline__ void flash_attn_tile_iter_KQ(
T_vec_dot * const Q_tmp,
const T_K * const __restrict__ K_h2,
@@ -394,7 +406,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter_KQ(
constexpr int np = nwarps > ncols ? nwarps/ncols : 1; // number of parallel warps per Q column
constexpr int stride_tile_K = std::is_same_v<T_vec_dot, half2> ? nbatch_K/2 + cpy_ne : nbatch_K + cpy_ne;
- flash_attn_load_tile<warp_size, nwarps, nbatch_fa, nbatch_K, stride_tile_K, false, oob_check, false, indexed_bias, false, T_K, T_vec_dot>
+ flash_attn_load_tile<warp_size, nwarps, nbatch_fa, nbatch_K, stride_tile_K, false, oob_check, use_sparse, indexed_bias || use_sparse, false, T_K, T_vec_dot>
(K_h2 + k_KQ_0/2, KV_tmp, nbatch_K/2, stride_K2, k_VKQ_0, k_VKQ_sup, rows);
__syncthreads();
@@ -452,7 +464,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter_KQ(
// Function that performs a single iteration of the main loop over up to nbatch_fa tokens.
template <int warp_size, int nwarps, int ncols1, int ncols2, int DKQ, int DV, int nbatch_fa, int nbatch_K,
- bool use_logit_softcap, bool oob_check, bool indexed_bias, typename T_vec_dot, typename T_KQ, typename T_acc, typename T_K, typename T_V>
+ bool use_logit_softcap, bool oob_check, bool indexed_bias, bool use_sparse, typename T_vec_dot, typename T_KQ, typename T_acc, typename T_K, typename T_V>
static __device__ __forceinline__ void flash_attn_tile_iter(
T_vec_dot * const Q_tmp,
const T_K * const __restrict__ K_h2,
@@ -505,12 +517,12 @@ static __device__ __forceinline__ void flash_attn_tile_iter(
constexpr int nbatch_K_last = DKQ % nbatch_K;
#pragma unroll
for (int k_KQ_0 = 0; k_KQ_0 < DKQ - nbatch_K_last; k_KQ_0 += nbatch_K) {
- flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias>(
+ flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias, use_sparse>(
Q_tmp, K_h2, KV_tmp, stride_K2, k_VKQ_0, k_VKQ_sup, k_KQ_0, KQ_acc, rows);
}
if (nbatch_K_last > 0) {
constexpr int k_KQ_0 = DKQ - nbatch_K_last;
- flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K_last, use_logit_softcap, oob_check, indexed_bias>(
+ flash_attn_tile_iter_KQ<warp_size, nwarps, ncols1, ncols2, DKQ, nbatch_fa, nbatch_K_last, use_logit_softcap, oob_check, indexed_bias, use_sparse>(
Q_tmp, K_h2, KV_tmp, stride_K2, k_VKQ_0, k_VKQ_sup, k_KQ_0, KQ_acc, rows);
}
@@ -535,7 +547,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter(
if (!oob_check || i_KQ < k_VKQ_sup) {
if (indexed_bias || ncols2 > 1 || mask) {
- const int k = k_VKQ_0 + i_KQ;
+ const int k = use_sparse ? rows[k_VKQ_0 + i_KQ] : k_VKQ_0 + i_KQ;
__builtin_assume(k >= 0); // avoid sign extension and register spills on RDNA
const float m = __half2float(mask[int64_t(j)*stride_mask + k]);
KQ_acc[(i_KQ_0/(np*warp_size))*cpw + jc0] += slope*(indexed_bias ? bias.add(m, j, k) : m);
@@ -621,7 +633,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter(
constexpr int stride_tile_V = std::is_same_v<T_vec_dot, half2> ? DV/2 : DV;
#pragma unroll
for (int k0 = 0; k0 < nbatch_fa; k0 += nbatch_V) {
- flash_attn_load_tile<warp_size, nwarps, nbatch_V, DV, stride_tile_V, false, oob_check, false, indexed_bias, false, T_V, T_vec_dot>
+ flash_attn_load_tile<warp_size, nwarps, nbatch_V, DV, stride_tile_V, false, oob_check, use_sparse, indexed_bias || use_sparse, false, T_V, T_vec_dot>
(V_h2, KV_tmp, DV/2, stride_V2, k_VKQ_0 + k0, k_VKQ_sup - k0, rows);
__syncthreads();
@@ -691,7 +703,7 @@ static __device__ __forceinline__ void flash_attn_tile_iter(
}
}
-template<int DKQ, int DV, int ncols1, int ncols2, bool use_logit_softcap, bool indexed_bias, ggml_type type_K, ggml_type type_V, bool use_kv_rows> // D == head size
+template<int DKQ, int DV, int ncols1, int ncols2, bool use_logit_softcap, bool indexed_bias, ggml_type type_K, ggml_type type_V, bool use_kv_rows, bool use_sparse = false> // D == head size
__launch_bounds__(ggml_cuda_fattn_tile_get_nthreads(DKQ, DV, ncols1*ncols2), ggml_cuda_fattn_tile_get_occupancy(DKQ, DV, ncols1*ncols2))
static __global__ void flash_attn_tile(
const float2 * Q_ptr,
@@ -732,6 +744,15 @@ static __global__ void flash_attn_tile(
// Skip unused kernel variants for faster compilation:
+#ifndef GCN
+ if constexpr (use_sparse) {
+ NO_DEVICE_CODE;
+ return;
+ }
+#endif // GCN
+
+ static_assert(!use_sparse || (ncols1 == 1 && !indexed_bias && !use_kv_rows), "bad sparse configuration");
+
if ((use_logit_softcap && !(DV == 128 || DV == 256 || DV == 512))) {
GGML_UNUSED_VARS(Q, K, V, mask, sinks, KV_max, dst, dst_meta, scale,
max_bias, m0, m1, n_head_log2, logit_softcap,
@@ -767,7 +788,10 @@ static __global__ void flash_attn_tile(
const int sequence = blockIdx.z / (ne02/ncols2);
const int head0 = blockIdx.z*ncols2 - sequence*ne02; // == blockIdx.z % (ne02/ncols2)
- const int32_t * rows = use_kv_rows ? KV_rows_ptr + int64_t(sequence)*ne11 : nullptr;
+ // For sparse attention, ne11 is the capacity of each index list, not the KV cache length.
+ const int64_t list = use_sparse ? int64_t(sequence % ne33)*gridDim.x + blockIdx.x : 0;
+ const int32_t * rows = use_sparse ? KV_max + list*ne11 :
+ use_kv_rows ? KV_rows_ptr + int64_t(sequence)*ne11 : nullptr;
__builtin_assume(!use_kv_rows || rows != nullptr);
const fattn_indexed_bias head_bias = indexed_bias ? bias.for_head(int64_t(sequence)*ne01.z, head0) : bias;
const int gqa_ratio = ne02 / ne12; // With grouped query attention there are > 1 Q matrices per K, V matrix.
@@ -868,20 +892,21 @@ static __global__ void flash_attn_tile(
__syncthreads();
// Main loop over KV cache:
- const int k_VKQ_max = KV_max ? KV_max[sequence*gridDim.x + blockIdx.x] : ne11;
- if (ncols2 == 1) {
+ const int k_VKQ_max = use_sparse ? KV_max[int64_t(gridDim.x)*ne33*ne11 + list] :
+ KV_max ? KV_max[sequence*gridDim.x + blockIdx.x] : ne11;
+ if (ncols2 == 1 || use_sparse) {
// Branch with out-of-bounds checks.
int k_VKQ_0 = blockIdx.y*nbatch_fa;
while (k_VKQ_0 <= k_VKQ_max - nbatch_fa) {
constexpr bool oob_check = false;
- flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias>
+ flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias, use_sparse>
(Q_tmp, K_h2, V_h2, maskh, ne01, logit_softcap, slope, KQ, KV_tmp,
stride_K2, stride_V2, stride_mask, KQ_max, KQ_sum, VKQ, k_VKQ_0, k_VKQ_max, col_Q_0, head_bias, rows);
k_VKQ_0 += gridDim.y*nbatch_fa;
}
if (k_VKQ_0 < k_VKQ_max) {
constexpr bool oob_check = true;
- flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias>
+ flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias, use_sparse>
(Q_tmp, K_h2, V_h2, maskh, ne01, logit_softcap, slope, KQ, KV_tmp,
stride_K2, stride_V2, stride_mask, KQ_max, KQ_sum, VKQ, k_VKQ_0, k_VKQ_max, col_Q_0, head_bias, rows);
}
@@ -889,7 +914,7 @@ static __global__ void flash_attn_tile(
// Branch without out-of-bounds checks.
for (int k_VKQ_0 = blockIdx.y*nbatch_fa; k_VKQ_0 < k_VKQ_max; k_VKQ_0 += gridDim.y*nbatch_fa) {
constexpr bool oob_check = false;
- flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias>
+ flash_attn_tile_iter<warp_size, nwarps, ncols1, ncols2, DKQ, DV, nbatch_fa, nbatch_K, use_logit_softcap, oob_check, indexed_bias, use_sparse>
(Q_tmp, K_h2, V_h2, maskh, ne01, logit_softcap, slope, KQ, KV_tmp,
stride_K2, stride_V2, stride_mask, KQ_max, KQ_sum, VKQ, k_VKQ_0, k_VKQ_max, col_Q_0, head_bias, rows);
}
@@ -1077,6 +1102,17 @@ static void launch_fattn_tile_switch_ncols1(ggml_backend_cuda_context & ctx, ggm
constexpr size_t nbytes_shared = 0;
#ifdef GGML_USE_HIP
+ if constexpr (!indexed_bias && !use_kv_rows && ggml_cuda_flash_attn_ext_tile_may_use_sparse(DKQ, DV, ncols2, use_logit_softcap)) {
+ if (ggml_cuda_flash_attn_ext_tile_shall_use_sparse(cc, dst, DKQ, DV)) {
+ const int nwarps = ggml_cuda_fattn_tile_get_nthreads(DKQ, DV, ncols2, cc) / warp_size;
+ const int nbatch_fa = ggml_cuda_fattn_tile_get_nbatch_fa(DKQ, DV, ncols2, cc);
+ fattn_kernel_t fattn_kernel = flash_attn_tile<DKQ, DV, 1, ncols2, use_logit_softcap, false, type_K, type_V, false, true>;
+ launch_fattn<DV, 1, ncols2, T_K, T_V>
+ (ctx, dst, fattn_kernel, nwarps, nbytes_shared, nbatch_fa, true, true, false, true, warp_size);
+ return;
+ }
+ }
+
// Limit indexed bias tile widths to avoid spilling registers on AMD.
// TODO: select the tile width in one function.
constexpr int max_cols = !indexed_bias ? 64 : DKQ == 64 ? 32 : use_kv_rows ? 16 : 8;
diff --git a/ggml/src/ggml-cuda/fattn.cu b/ggml/src/ggml-cuda/fattn.cu
index b1afc3387..f53881d58 100644
--- a/ggml/src/ggml-cuda/fattn.cu
+++ b/ggml/src/ggml-cuda/fattn.cu
@@ -127,6 +127,71 @@ void ggml_cuda_flash_attn_ext_compact_mask(
#endif // !defined(GGML_USE_MUSA)
}
+#ifdef GGML_USE_HIP
+bool ggml_cuda_flash_attn_ext_tile_shall_use_sparse(const int cc, const ggml_tensor * dst, const int DKQ, const int DV) {
+ const ggml_tensor * Q = dst->src[0];
+ const ggml_tensor * K = dst->src[1];
+ const ggml_tensor * mask = dst->src[3];
+
+ const int n_kv_max = ggml_get_op_params_i32(dst, 4);
+ const int64_t n_kv = K->ne[1];
+
+ float max_bias = 0.0f;
+ memcpy(&max_bias, (const float *) dst->op_params + 1, sizeof(float));
+
+ if (!mask || mask->ne[0] != n_kv || mask->ne[1] < Q->ne[1] ||
+ mask->ne[2] != 1 || dst->src[5] || n_kv_max <= 0 || max_bias != 0.0f) {
+ return false;
+ }
+
+ if (GGML_CUDA_CC_IS_GCN(cc)) {
+ // Sparse compaction is not beneficial when the selected positions exceed 25% of the KV cache.
+ if (n_kv_max > n_kv/4) {
+ return false;
+ }
+
+ const int gqa_ratio = Q->ne[2] / K->ne[2];
+
+ if (DKQ == 72 && DV == 72) {
+ return n_kv >= 8192;
+ }
+ if (DKQ == 80 && DV == 80) {
+ return n_kv >= 16384;
+ }
+ if (DKQ == 96 && DV == 96) {
+ return n_kv >= 16384;
+ }
+ if (DKQ == 112 && DV == 112) {
+ return n_kv >= 16384;
+ }
+ if (DKQ == 128 && DV == 128) {
+ return n_kv >= 8192;
+ }
+ if (DKQ == 192 && DV == 128) {
+ return n_kv >= 16384;
+ }
+ if (DKQ == 256 && DV == 256) {
+ if (gqa_ratio == 2) {
+ return (n_kv_max <= DKQ && n_kv >= 16384) ||
+ (n_kv >= 32768 && (Q->ne[1] == 1 || n_kv_max <= 2*DKQ));
+ }
+ return n_kv >= 4096 && (Q->ne[1] == 1 || n_kv_max < n_kv/8);
+ }
+ if (DKQ == 320 && DV == 256) {
+ return n_kv >= 65536 && gqa_ratio >= 64;
+ }
+ if (DKQ == 512 && DV == 512) {
+ return n_kv >= 16384 && gqa_ratio >= 16;
+ }
+ if (DKQ == 576 && DV == 512) {
+ return n_kv >= 32768 && gqa_ratio >= 32;
+ }
+ }
+
+ return false;
+}
+#endif // GGML_USE_HIP
+
bool ggml_cuda_flash_attn_ext_mma_f16_shall_use_sparse(const int cc, const ggml_tensor * dst, const int ncols1, const int ncols2) {
#ifdef GGML_USE_MUSA
GGML_UNUSED_VARS(cc, dst, ncols1, ncols2);
diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp
index 0d0d020fe..ec61bb60b 100644
--- a/tests/test-backend-ops.cpp
+++ b/tests/test-backend-ops.cpp
@@ -15053,6 +15053,30 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
// KV not a multiple of the compaction workgroup size.
test_cases.emplace_back(new test_flash_attn_ext(128, 128, 1, { 8, 1}, 5003, 4, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 512));
+ // Long-context sparse attention selection: sparse tiles and dense fallbacks.
+ test_cases.emplace_back(new test_flash_attn_ext( 72, 72, 2, {12, 1}, 32768, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext( 80, 80, 2, {12, 1}, 16384, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(128, 128, 2, {12, 1}, 16384, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(128, 128, 2, {12, 1}, 32768, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(192, 128, 2, {32, 1}, 32768, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, {12, 1}, 4096, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 256));
+ test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, { 2, 1}, 16384, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, { 2, 1}, 32768, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(320, 256, 1, {32, 1}, 65536, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(320, 256, 1, {64, 1}, 65536, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(512, 512, 1, {16, 1}, 65536, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 512));
+ test_cases.emplace_back(new test_flash_attn_ext(576, 512, 1, {32, 1}, 65536, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, true, 512));
+ test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, {12, 2}, 4096, 1, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 256));
+
+ // GCN sparse attention with independent masks for multiple query tokens.
+ for (int64_t nq : {2, 4, 8, 9, 16}) {
+ test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, {12, 1}, 16384, nq, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ }
+ test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, {12, 1}, 8192, 8, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, {12, 1}, 4096, 8, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(128, 128, 2, {12, 1}, 32768, 8, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, {12, 2}, 16384, 4, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+
// Sparse gather: native block sizes, padded slots, and head/batch strides.
for (ggml_type type : {GGML_TYPE_F32, GGML_TYPE_F16, GGML_TYPE_BF16, GGML_TYPE_Q4_0, GGML_TYPE_Q4_1, GGML_TYPE_Q5_0, GGML_TYPE_Q5_1, GGML_TYPE_Q8_0, GGML_TYPE_IQ4_NL}) {
test_cases.emplace_back(new test_flash_attn_ext(128, 96, 2, {8, 2}, 5003, 3, true, false, 0, 0, GGML_PREC_F32, type, type, {0, 1, 2, 3}, true, false, 257));
@@ -15870,6 +15894,13 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_perf() {
// Same non-causal vision-encoder shape for the other head size padded in-kernel by the CUDA MMA kernels
test_cases.emplace_back(new test_flash_attn_ext(40, 40, 16, {1, 1}, 5776, 5776, false, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16));
+ // GCN sparse attention break-even for multiple query tokens.
+ for (int64_t kv : {16384, 32768, 65536}) {
+ for (int64_t nq : {1, 2, 4, 8, 16, 32, 64}) {
+ test_cases.emplace_back(new test_flash_attn_ext(256, 256, 2, {12, 1}, kv, nq, true, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16, {0, 1, 2, 3}, true, false, 2048));
+ }
+ }
+
// Sparse flash attention (n_kv_max hint) decode across KV depths.
// Shapes: 576/512 DeepSeek MLA, 512/512 DeepSeek-V4/GLM-5.2, 256/256 gqa12 Qwen QSA.
for (int64_t kv : {4096, 16384, 32768}) {