Faster MLA prompt processing#205
Merged
Merged
Conversation
added 6 commits
February 12, 2025 07:41
It is either the standard KV cache or MLA cache, not both.
Much easier to follow, at least for my brain, when we have X_rope : rotational position encoding X_nope : no position encoding instead of X_pe and X_nope, where I was wondering wtf is 'pe' and 'nope'.
saood06
reviewed
Feb 12, 2025
| @@ -3178,33 +3178,30 @@ static bool llama_kv_cache_init( | |||
| ggml_tensor * k; | |||
| ggml_tensor * v; | |||
| if (cparams.mla_attn && model.layers[i].wk_b && model.layers[i].wv_b) { | |||
Collaborator
There was a problem hiding this comment.
We might want to print something if mla_attn is requested but not able to be run instead of just silently failing over to standard attention, I just saw a report of a user not realizing that this was happening and not sure why MLA was not giving any performance difference.
Owner
Author
There was a problem hiding this comment.
Thanks. Added a hopefully visible warning.
Cuts KV cache size in nearly half at the expense of slower TG performance for long contexts (it becomes similar to no-MLA).
Owner
Author
|
The PR also adds a compile time option to disable the transposed KV cache when using MLA (simple look for
|
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 speeds up prompt processing (PP) when MLA is enabled. It is still slower than no-MLA, so I'm making this a draft for now to try some more. Still it would be great if somebody else tested to confirm that a) I did not introduce bugs and b) It is indeed faster on their systems.
The PR also adds the changes suggested by @saood06 in the review of #188
Speedup is achieved by concatenating the no- and rotational position encoding parts of
KandQ(this also eliminates thek_rcache), which allows us to combine the formerkq_nopeandkq_pematrix multiplications into a single matrix multiplication. This also eliminates the fairly expensive addition ofkq_nopeandkq_pe.Here is a comparison between PP performance on the main branch and this PR for DeepSeek-Lite quantized with
IQ4_XSand running on a Ryzen-7950X usingQ8_0for K-cacheTG performance (the whole point of MLA) is not sacrificed. Here the results of
llama-bench -gp -Np,64for different prompt lengthsNpNot sure if the ~9% improvement at 16k tokens is real. It may be just due to less thermal trottling because of the prompt processing part finishing quicker.