TECHNOLOGY

llama.cpp quantized KV: reserve attention workspace before generation

In this article
THE QUICK TAKE

The repeated-turn log measures an early local patch; the merged change reserves backend attention workspace and does not establish universal VRAM savings.

A llama.cpp report about VRAM growing between conversation turns illustrates why quantized KV storage does not fully describe runtime memory. The case includes an early user patch and a later merged CUDA change. Their evidence should remain separate: the user’s repeated-turn log is not a benchmark of the subsequently merged implementation.

The observed workload

The original issue describes CUDA serving with Flash Attention, quantized KV and long output. The opening reporter used a modified-capacity GPU and a particular Qwen model configuration. Other participants tested different launch settings. Combining their observations into a single hardware benchmark would obscure which configuration produced each result.

A multi-turn conversation is also different from repeatedly launching an empty request. Its input grows as messages accumulate, potentially changing temporary tensor sizes. Track the effective context and prompt history along with memory. A rising graph needs that workload description before it can distinguish an allocation problem from legitimate additional state.

What the early patch actually demonstrated

In a participant’s May 23 report, a local patch produced a first-turn change from 28734 to 30772 MiB, a 2038 MiB increase. The following conversation turns showed no further increase in the posted log. The participant explicitly disclosed AI-generated code that had not been well reviewed.

These figures support a limited statement about that user’s local test. They do not establish a universal startup penalty, prove all leaks were removed or measure the final merged change. A successful finite run is evidence over its tested history and output lengths; extending it to arbitrary contexts requires another observation.

The merged change accounts for backend workspace

The later pull request was merged on June 3. Its explanation says that quantized KV can need backend allocations not known to the automatic fit calculation. Other temporary buffers are explicitly mentioned as remaining work, so this should not be presented as complete elimination of all attention workspace.

The actual diff reserves additional space associated with the Flash Attention output allocation when the selected kernel needs half-precision K or V working representations. It replaces the relevant pool allocations with addresses into that reserved region and extends the allocation-size calculation. The change concerns accounting and workspace placement, rather than turning all KV computation into permanently quantized arithmetic.

Interpret a higher initial allocation

A larger reservation can make a capacity estimate more truthful while reducing surprises during generation. That is different from reducing the mathematical size of cached keys and values. Report startup, first request, subsequent requests and the longest supported conversation separately, following the active-request memory guide.

Do not compare two runs after changing KV precision and context simultaneously and attribute the entire difference to precision. Keep concurrency, speculative decoding, model revision and output lengths fixed where possible. Save both the source revision and launch settings so that a subsequent result can be associated with the actual implementation.

Validate the relevant capacity boundary

For a local acceptance test, include prompt processing as well as decoding, and observe the process through repeated turns. Record successful completion and allocation failures alongside the memory series. The benchmark methodology explains why a stable short run and maximum reliable capacity answer different questions. This historical fix provides a concrete hypothesis to test, not a current blanket diagnosis for every llama.cpp memory increase.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles