Fused indexer top_k (CPU only)#2098
Merged
Merged
Conversation
We do save memory, but it is somehow much slower than what we have on main.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a dedicated op for computing the DSA indexer
top_kKV cache entries. The PR only provides CPU implementation, so usage of the fusedtop_kcomputation is guarded by a flag that is off by default. It can be enabled on the command line using(Note: not implemented yet in
llama-bench, so usellama-sweep-benchorllama-serverorllama-clito see the effect).The fused indexer
top_kcomputation 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-benchgraphs for GLM-5.2-Q4_K_M running on a Ryzen-3995WX CPU withf16KV cache.Prompt processing
Token generation (no MTP)
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_ktokens, 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.