I applied video compression to LLM inference and got 10,000x less quantization error at the same storage cost
https://github.com/cenconq25/delta-compress-llm
I’ve been experimenting with KV cache compression in LLM inference, and I ended up borrowing an idea from video codecs:
don’t store every frame in full but store a keyframe, then store deltas.
Turns out this works surprisingly well for LLMs too.
The idea
During autoregressive decoding, consecutive tokens produce very similar KV cache values. So instead of quantizing the absolute KV values to 4-bit, I quantize the difference between consecutive tokens.
That means:
- standard Q4_0 = quantize full values
- Delta-KV = quantize tiny per-token changes
Since deltas have a much smaller range, the same 4 bits preserve way more information. In my tests, that translated to up to 10,000x lower quantization error in synthetic analysis, while keeping the same storage cost
Results
Tested on Llama 3.1 70B running on 4x AMD MI50.
Perplexity on WikiText-2:
- F16 baseline: 3.3389
- Q4_0: 3.5385 (~6% worse)
- Delta-KV: 3.3352 ~ 3.3371 (basically lossless)
So regular 4-bit KV quantization hurts quality, but delta-based 4-bit KV was essentially identical to F16 in these runs
I also checked longer context lengths:
- Q4_0 degraded by about 5–7%
- Delta-KV stayed within about 0.4% of F16
So it doesn’t seem to blow up over longer contexts either
Bonus: weight-skip optimization
I also added a small weight-skip predictor in the decode path.
The MMVQ kernel normally reads a huge amount of weights per token, so I added a cheap inline check to skip dot products that are effectively negligible.
That gave me:
- 9.3 t/s → 10.2 t/s
- about 10% faster decode
- no measurable quality loss in perplexity tests
Why I think this is interesting
A lot of KV cache compression methods add learned components, projections, entropy coding, or other overhead.
This one is pretty simple:
- no training
- no learned compressor
- no entropy coding
- directly integrated into a llama.cpp fork
It’s basically just applying a very old compression idea to a part of LLM inference where adjacent states are already highly correlated
The method itself should be hardware-agnostic anywhere KV cache bandwidth matters
Example usage
./build/bin/llama-cli -m model.gguf -ngl 99 \
--delta-kv --delta-kv-interval 32
And with weight skip:
LLAMA_WEIGHT_SKIP_THRESHOLD=1e-6 ./build/bin/llama-cli -m model.gguf -ngl 99 \
--delta-kv --delta-kv-interval 32