UPSTREAM PR #19183: [RFC] implementing Expected Attention in llama.cpp?#1090
Open
UPSTREAM PR #19183: [RFC] implementing Expected Attention in llama.cpp?#1090
Conversation
|
No meaningful performance changes were detected across 115123 analyzed functions in the following binaries: build.bin.libllama.so, build.bin.libmtmd.so, build.bin.llama-tts, build.bin.llama-cvector-generator, build.bin.libggml-base.so, build.bin.libggml-cpu.so, build.bin.libggml.so, build.bin.llama-tokenize, build.bin.llama-quantize, build.bin.llama-qwen2vl-cli, build.bin.llama-bench, build.bin.llama-gemma3-cli, build.bin.llama-gguf-split, build.bin.llama-llava-cli, build.bin.llama-minicpmv-cli. 🔎 Full breakdown: Loci Inspector. |
7077d25 to
62123f6
Compare
048ad94 to
6c1fde6
Compare
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.
Note
Source pull request: ggml-org/llama.cpp#19183
Recently, NVIDIA put out a paper describing a method to reduce the size of the KV cache. They call their preferred method Expected Attention.
Expected Attention: KV Cache Compression by Estimating Attention from Future Queries Distribution
From my reading of the paper, the thought process is like this:
cur) at each layer follow a gaussian distribution (and they re-confirmed this here too)wq) can be thought of as a linear transformation oncur, which maintains this same distribution for the resultingQcurprojectioncb(), we can observe the query projectionsQcurin all layers over an interval, in order to model a distribution of the expected future queries (the paper also takes into account RoPE / positional encoding for future positions, but I could not figure out how to do that, so I skipped it for now)So for example if the user specified a "compression ratio" of 20%, we would discard the 20% of KV entries that are expected to have the least impact on the hidden state in the future.
I had hoped to be able to get this working and submit a PR for it on my own, but there are some problems that I don't know how to solve:
llama_context? Thellama_memorystructure abstracts away the implementation of the different cache types, so this is not straightforward.defraglogic for this?I am posting this thread in hopes of starting a discussion to see if this method will even be feasible to implement in llama.cpp, or if it would be too complicated. The code is certainly NOT in a state that is ready for use, or even guaranteed to work at all. I am just including my demo code as a starting point. I would be pleasantly surprised if this PR ever leaves the draft stage. :)
Make sure to read the contributing guidelines before submitting a PR