Skip to content

Fused indexer top_k (CPU only)#2098

Merged
ikawrakow merged 2 commits into
mainfrom
ik/indexer_topk
Jul 9, 2026
Merged

Fused indexer top_k (CPU only)#2098
ikawrakow merged 2 commits into
mainfrom
ik/indexer_topk

Conversation

@ikawrakow

Copy link
Copy Markdown
Owner

This PR adds a dedicated op for computing the DSA indexer top_k KV cache entries. The PR only provides CPU implementation, so usage of the fused top_k computation is guarded by a flag that is off by default. It can be enabled on the command line using

-fidx | --fused-indexer-topk

(Note: not implemented yet in llama-bench, so use llama-sweep-bench or llama-server or llama-cli to see the effect).

The fused indexer top_k computation brings some compute buffer savings, a massive increase in prompt processing performance for long context, and more modest but still noticeable TG performance improvement.

Below are CPU-only sweep-bench graphs for GLM-5.2-Q4_K_M running on a Ryzen-3995WX CPU with f16 KV cache.

Prompt processing

dsa_pp

Token generation (no MTP)

dsa_tg

I have lost the TG results for the original DSA implementation and didn't feel like rerunning them as it takes a very long time.

In any case, PP and TG performance are now nearly flat with context length. The TG performance drop between no context and a context of 4096 tokens is due to the indexer kicking in (indexer is not invoked until context reaches top_k tokens, which is 2048 for GLM-5.2). The nearly 20% TG performance drop seems a bit too large, so possibly there is still room for improvement left in the indexer implementation.

ikawrakow added 2 commits July 7, 2026 16:38
We do save memory, but it is somehow much slower than what we have on
main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant