llama : build the k-pool sparse selection independently of the kq_mask shape (#31243)

* llama : build the k-pool sparse selection independently of the kq_mask shape

qwen4exp (QSA) and glm5-next pick cache cells by index and no longer read the kq_mask values, but they still shaped the selection like the dense kq_mask. Build the selection as [n_kv, n_tokens] over the cache cells instead, and split it into the streams of the K view right before the attention.

This lets the dense mask change its layout (e.g. per-sequence row lists) without touching the sparse layers.

* improve comment

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* llama : drop the unused build_fused_top_k_mask args, review nits

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
This commit is contained in:
Aman GuptaandGeorgi Gerganov authored and GitHub committed 2026-10-27 21:57:45 +08:00
1 parent 7ecb57f7ad
commit 27b7a8a009
6 files changed
+41 -57

No files matched your search

+1 -1
View File
@@ -686,7 +686,7 @@ ggml_tensor * llama_model_deepseek4::graph::build_top_k_mask(
GGML_ASSERT(top_k);
if (cparams.fused_top_k_mask) {
ggml_tensor * kq_mask_top_k = build_fused_top_k_mask(kq_mask, top_k, nullptr, nullptr, nullptr, nullptr, il);
ggml_tensor * kq_mask_top_k = build_fused_top_k_mask(kq_mask, top_k, il);
cb(kq_mask_top_k, name, il);
return kq_mask_top_k;