Skip to content

llama : move the indexer key rotation choice into the model classes - #32653

Merged
am17an merged 2 commits into
masterfrom
aman/model-indexer-k-rot
Nov 20, 2026
Merged

am17an merged 2 commits into
masterfrom
aman/model-indexer-k-rot

Conversation

@am17an

@am17an am17an commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Follow-up to #32648. The KV cache forced a Hadamard rotation for the lightning indexer keys based on a list of architectures. The virtual llama_model::lid_k_hdmd() now returns true for the same models: deepseek32, deepseek4, glm_dsa, dots3note, mistral_large4.

No behavior change.

Additional information

deepseek41 inherits from deepseek4 but was not in the list, so it overrides lid_k_hdmd() back to false. Its indexer KV cache does pass the size check, so this may be an omission from when DeepSeek4.1 was added. If so, the fix is to delete that override; I left that for a separate change.

Checked the same way as #32648: with the old list kept next to the new code and an assert on equality, test-llama-archs on CPU passed for all architectures it runs (593 KV caches across 142 architectures).

Requirements

The KV cache forced a Hadamard rotation for the lightning indexer keys
based on a list of architectures. The virtual llama_model::indexer_k_rot()
now returns true for the same models. DeepSeek4.1 inherits from DeepSeek4
but was not in the list, so it overrides it back to false.
@am17an
am17an requested review from a team and CISC as code owners November 20, 2026 09:24
@am17an am17an added the refactoring Refactoring label Nov 20, 2026
@github-actions github-actions Bot added the model Model specific label Nov 20, 2026
@am17an

am17an commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

I guess this should also be part of memory? @ggerganov

@ggerganov

Copy link
Copy Markdown
Member

I guess this should also be part of memory? @ggerganov

I have to check, but I think that the Hadamard transform for the lightning indexer is technically a property of the model - it is how it is trained. So if this is the case, then it should be OK as currently proposed.

Comment thread src/llama-model.h Outdated
Comment on lines +1058 to +1059
// always rotate the lightning indexer keys with a Hadamard transform
virtual bool indexer_k_rot() const { return false; }

@ggerganov ggerganov Nov 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// always rotate the lightning indexer keys with a Hadamard transform
virtual bool indexer_k_rot() const { return false; }
// apply Hadamard transform to the lightning indexer keys
virtual bool lid_k_hdmd() const { return false; }

@am17an

am17an commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

yes it is a property of the model

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deepseek41 inherits from deepseek4 but was not in the list, so it overrides lid_k_hdmd() back to false. Its indexer KV cache does pass the size check, so this may be an omission from when DeepSeek4.1 was added. If so, the fix is to delete that override; I left that for a separate change.

Hm, interesting. Definitely need to check what's the case here.

@am17an

am17an commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

Hm, interesting. Definitely need to check what's the case here.

It's not relevant. I checked it

@am17an
am17an merged commit 4783b11 into master Nov 20, 2026
23 checks passed
Kidplayer666 pushed a commit to Kidplayer666/llama.cpp that referenced this pull request Nov 20, 2026
…gml-org#32653)

* llama : move the indexer key rotation choice into the model classes

The KV cache forced a Hadamard rotation for the lightning indexer keys
based on a list of architectures. The virtual llama_model::indexer_k_rot()
now returns true for the same models. DeepSeek4.1 inherits from DeepSeek4
but was not in the list, so it overrides it back to false.

* llama : rename indexer_k_rot() to lid_k_hdmd()
Annieren pushed a commit to Annieren/llama.cpp-upstream that referenced this pull request Nov 23, 2026
…gml-org#32653)

* llama : move the indexer key rotation choice into the model classes

The KV cache forced a Hadamard rotation for the lightning indexer keys
based on a list of architectures. The virtual llama_model::indexer_k_rot()
now returns true for the same models. DeepSeek4.1 inherits from DeepSeek4
but was not in the list, so it overrides it back to false.

* llama : rename indexer_k_rot() to lid_k_hdmd()
Mr-J-369 pushed a commit to Mr-J-369/llama.cpp-Android that referenced this pull request Nov 25, 2026
…gml-org#32653)

* llama : move the indexer key rotation choice into the model classes

The KV cache forced a Hadamard rotation for the lightning indexer keys
based on a list of architectures. The virtual llama_model::indexer_k_rot()
now returns true for the same models. DeepSeek4.1 inherits from DeepSeek4
but was not in the list, so it overrides it back to false.

* llama : rename indexer_k_rot() to lid_k_hdmd()

(cherry picked from commit 4783b11)
Nindaleth pushed a commit to Nindaleth/llama.cpp that referenced this pull request Nov 26, 2026
…gml-org#32653)

* llama : move the indexer key rotation choice into the model classes

The KV cache forced a Hadamard rotation for the lightning indexer keys
based on a list of architectures. The virtual llama_model::indexer_k_rot()
now returns true for the same models. DeepSeek4.1 inherits from DeepSeek4
but was not in the list, so it overrides it back to false.

* llama : rename indexer_k_rot() to lid_k_hdmd()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Model specific refactoring Refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants