-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ggml: implement quantized KV cache for FA #7372
Merged
JohannesGaessler
merged 1 commit into
ggerganov:master
from
JohannesGaessler:fa-quantize-3
May 19, 2024
Merged
ggml: implement quantized KV cache for FA #7372
JohannesGaessler
merged 1 commit into
ggerganov:master
from
JohannesGaessler:fa-quantize-3
May 19, 2024
Conversation
This file contains 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
It would be preferable to use the more generic function pointers in |
JohannesGaessler
force-pushed
the
fa-quantize-3
branch
from
May 19, 2024 11:39
c1c6d84
to
d7168fd
Compare
I tested using the same FP32 code for both FP16 and quantized V cache but the performance was worse. |
ggerganov
approved these changes
May 19, 2024
ggml.c
Outdated
GGML_ASSERT(nbq0 == sizeof(float)); | ||
GGML_ASSERT(nbk0 == sizeof(ggml_fp16_t)); | ||
GGML_ASSERT(nbv0 == sizeof(ggml_fp16_t)); | ||
// input tensors must be contiguous |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs just contiguous rows, not the entire tensors
JohannesGaessler
force-pushed
the
fa-quantize-3
branch
from
May 19, 2024 14:46
d7168fd
to
b7da2e8
Compare
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 implements the use of quantized KV caches for the CPU backend when using FlashAttention. This is done via switch statements in
ggml_compute_forward_flash_attn_ext_f16
; from what I can tell this does not significantly affect performance. I also added comments and did some small performance optimizations such as converting Q only once to FP16/q8_0/q8_1 and using multiplications for scaling rather than divisions. The amount ofwdata
has been increased but only on the order of kiB which should be negligible. On my desktop with a Ryzen 5950X power limited to 95W the performance changes as follows:When benchmarking, be mindful of the order in which you run the tests since a hot CPU will perform worse and this difference can easily be larger than the performance difference from this PR. I did a warmup run prior to the actual measurements.