From eb7ba47c5c41b0700201a1e7fe3fbd9ad8309ac7 Mon Sep 17 00:00:00 2001 From: Sam McLeod Date: Fri, 4 Sep 2026 08:52:43 +1000 Subject: [PATCH] qwen4exp : enable sparse flash attention in build_attn_qsa Pass the indexer top-k width as n_kv_max so backends with a sparse FA path (Metal, CUDA) gather the selected KV rows instead of masking the full cache. --- src/models/qwen4exp.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/models/qwen4exp.cpp b/src/models/qwen4exp.cpp index 1484c9b07bda..02142d0f8381 100644 --- a/src/models/qwen4exp.cpp +++ b/src/models/qwen4exp.cpp @@ -744,10 +744,7 @@ ggml_tensor * llama_model_qwen4exp::graph::build_attn_qsa( ggml_tensor * k = mctx_cur->get_k(ctx0, il); ggml_tensor * v = mctx_cur->get_v(ctx0, il); - // TODO: enable sparse attention when we are ready - // ref: https://github.com/ggml-org/llama.cpp/pull/27970 - //ggml_tensor * cur = build_attn_mha(q, k, v, nullptr, kq_mask_top_k, nullptr, nullptr, top_k->ne[0], kq_scale, il); - ggml_tensor * cur = build_attn_mha(q, k, v, nullptr, kq_mask_top_k, nullptr, nullptr, 0, kq_scale, il); + ggml_tensor * cur = build_attn_mha(q, k, v, nullptr, kq_mask_top_k, nullptr, nullptr, top_k->ne[0], kq_scale, il); cb(cur, "kqv_out", il); // the rotation is its own inverse, so undo it on the value side of the output