The llama.cpp project released version b10532, introducing a preprocessing pass on the Metal backend that dequantizes quantized Key-Value (KV) caches to F16 before executing Flash Attention.

  • The new kernel dequantizes Q8_0 KV tensors into a contiguous F16 scratch buffer, allowing the use of existing F16 Flash Attention kernels instead of in-kernel dequantization.
  • Support was extended to cover all quantized KV types supported by Metal, including Q4_0, Q4_1, Q5_0, and Q5_1.
  • For MLA-based models where V is a view of K, the implementation skips redundant V dequantization and reads V from the K F16 buffer.
  • Verification on an M2 Ultra showed that perplexity for Qwen2.5-0.5B with q8_0 KV matches the F16 reference exactly (PPL 1.0008).

This change enables efficient Flash Attention execution on Metal devices by leveraging contiguous F16 buffers for quantized KV caches, ensuring accuracy parity with standard F16 implementations.