Llama.cpp / GGUF Server KV-Cache Quantization: Why does q4_0 KV cache degrade tool-calling JSON accuracy compared to q8_0 on 32k contexts?
We serve Qwen2.5-Coder-14B-Instruct-Q4_K_M.gguf locally using llama-server on an RTX 4080 16GB.
The 32k VRAM Squeeze
With default f16 KV cache, 32k context pushes VRAM past 16GB and spills layers onto slow system RAM.
So we enabled 4-bit KV-cache quantization on both Keys and Values:
bashllama-server -m qwen2.5-coder-14b-q4_k_m.gguf -c 32768 -ngl 99 -fa -ctk q4_0 -ctv q4_0
VRAM dropped to a comfortable 12.8GB! However, once agent trajectories cross ~16k tokens:
- Exact tool parameter names from the system prompt start getting misspelled (
file_path->filepath_id). - Multi-line JSON tool calls drop closing braces or repeat keys.
Why does q4_0 KV quantization break exact token copying in long contexts, and can we use asymmetric KV settings (q8_0 vs q4_0) to recover accuracy within 16GB VRAM?