Skip to content
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

[Feat]: quantized KV cache and flash attention #79

Closed
mseri opened this issue Nov 3, 2024 · 2 comments · Fixed by #148
Closed

[Feat]: quantized KV cache and flash attention #79

mseri opened this issue Nov 3, 2024 · 2 comments · Fixed by #148
Labels
enhancement New feature or request

Comments

@mseri
Copy link

mseri commented Nov 3, 2024

Description
Flash attention and quantized kv stores are both supported by llama.cpp.

These features allow for much larger contexts with drastically reduced memory footprints. These could be quite convenient for the limited resources on the phone.

Quantized kv cache, with q8, means half of the memory for the context with barely any effect on the quality (q4 is 1/4 memory but you notice degradation in my tests).

The feature could be implemented adding two optional parameters: a checkbox for flash attention (required for the KV quantization) and a dropdown to select a quantization for both the k and v store, f16 — (current) default, f8 and f4.

@mseri mseri added the enhancement New feature or request label Nov 3, 2024
@mseri mseri changed the title [Feat]: quantized KV cache and/or flash attention [Feat]: quantized KV cache and flash attention Nov 8, 2024
@a-ghorbani
Copy link
Owner

Adding the options should be straightforward i guess. But I was wondering which mobile devices support flash attention?

@sammcj
Copy link

sammcj commented Dec 7, 2024

This would make a significant improvement to the experience of running models on edge devices as it would unlock either larger, more useful context sizes or larger parameter models with the same context size at around the same memory usage.

I recently wrote a little blog post about qKV after getting it enabled in Ollama (which uses llama.cpp), there is an estimation calculator of the memory savings which you might find interesting: https://smcleod.net/2024/12/bringing-k/v-context-quantisation-to-ollama

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants