llama : fix Gemma3 SWA KV cache shift#12373
Merged
Conversation
ggerganov
commented
Mar 13, 2025
Comment on lines
+540
to
+550
| float freq_base_l = cparams.rope_freq_base; | ||
| float freq_scale_l = cparams.rope_freq_scale; | ||
|
|
||
| // TODO: improve | ||
| if (model.arch == LLM_ARCH_GEMMA3) { | ||
| const bool is_sliding = hparams.is_sliding(il); | ||
|
|
||
| freq_base_l = is_sliding ? 10000.0f : cparams.rope_freq_base; | ||
| freq_scale_l = is_sliding ? 1.0f : cparams.rope_freq_scale; | ||
| } | ||
|
|
Member
Author
There was a problem hiding this comment.
Not sure how to avoid this special-casing here. It does not look great.
Contributor
There was a problem hiding this comment.
I think we can extend the llama_layer to hold this info in the near future.
Member
Author
There was a problem hiding this comment.
For now, I've pushed the following version, which should be a bit cleaner: #12374
Will see if there is a better way to do it with the upcoming model implementation refactoring.
5 tasks
arthw
pushed a commit
to arthw/llama.cpp
that referenced
this pull request
Mar 19, 2025
* llama : fix Gemma3 SWA KV cache shift ggml-ci * hparams : add comment [no ci]
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.
fix #12357
This should fix the KV cache shift for Gemma3 models. Testing: