Skip to content

kv-cache : improve defrag logic #13497

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

Open
ggerganov opened this issue May 13, 2025 · 0 comments
Open

kv-cache : improve defrag logic #13497

ggerganov opened this issue May 13, 2025 · 0 comments
Labels
enhancement New feature or request performance Speed related topics roadmap Part of a roadmap project

Comments

@ggerganov
Copy link
Member

Following the optimization in #13493, I realized that the defragmentation can become much better so that it can further improve the Flash Attention masking.

Currently we defrag the following cache like this:

# before defrag
00000000...11111.......2222222....2010212012012....

# after defrag
000000001111122222222010212012012..................

I.e. we only "fill" the holes, but the sequences remain scattered. We can do better like this:

# new defrag
000000000000111111111222222222222..................

By doing so, the FA-vec masking logic will remain effective even after many generations.

@ggerganov ggerganov added enhancement New feature or request performance Speed related topics roadmap Part of a roadmap project labels May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance Speed related topics roadmap Part of a roadmap project
Projects
None yet
Development

No branches or pull requests

1 participant