KV compression saves representation bytes under a separately tested quality contract
Count packed values and metadata, distinguish quantization from lossless state recovery, and evaluate attention and generation quality across contexts and workloads.
On this page
The question for today
What you’ll understand
- Calculate a stated packed-cache footprint including group metadata.
- Explain how quantization error can affect attention and generated continuations.
- Design reference comparisons without equating byte savings to speed or universal quality preservation.
Reducing the bits used by retained keys and values can admit more context or more requests, but fewer representation bytes do not establish equivalent model behavior. Scales, zero points, outliers, alignment, and conversion workspace also consume memory. A compression design therefore needs two contracts: what it stores and how its approximation affects the intended tasks. Keep the original weight model fixed when evaluating KV changes, and compare both numerical state fidelity and useful generation behavior rather than treating a nominal bit width as the complete result.
Packed scalar bits are only part of the format
A uniform affine quantizer maps a range of real values to integer codes and reconstructs an approximation using a scale and zero point. Finite ranges can clip outliers, and rounding loses detail even when no clipping occurs. Quantization granularity matters: one scale per tensor, channel, token, or group exposes different dynamic-range tradeoffs and metadata costs. KIVI studies asymmetric low-bit KV quantization, reflecting that keys and values need not behave identically. Its method and evaluated results should not be replaced by the unsupported assumption that any two-bit format is interchangeable.
The vLLM 0.9.1 quantized-KV documentation describes FP8 cache formats and its then-current scalar scaling support; those version-specific features are distinct from the illustrative integer format used below. A weight-quantization setting does not automatically choose the KV representation. Count keys and values, scale storage, any retained full-precision residual, padding, block tables, and conversion buffers under the actual implementation. If prefix caches share compressed blocks, their effective format and scale interpretation must be compatible; token equality does not authorize reading one representation through another decoder.
Measure the whole footprint and the actual execution path
For a specified packed format, add code bytes and group metadata rather than dividing the original footprint by the nominal bit ratio alone. Small groups can improve local range fit while making metadata significant. Padding and temporary dequantization can further reduce peak-memory savings. The toy calculation assumes tightly packed codes and a fixed metadata record per group; real kernels may impose extra alignment or keep selected values at higher precision. Report both persistent-cache bytes and transient peak bytes so a compact stored representation does not hide a large conversion allocation.
Capacity improvement is also different from latency improvement. A compressed cache can permit a larger batch yet require extra conversion, metadata reads, or kernels. Conversely, fused quantized attention may reduce traffic when supported. The cited vLLM documentation describes its particular release's performance limitations, so avoid extrapolating them into a claim about every future or alternative implementation. Benchmark the exact engine, hardware, context lengths, and concurrency with the same output and quality criteria, including host-transfer effects if compressed state is offloaded.
Test long-context behavior and closed-loop error effects
Compare reconstructed tensors and attention outputs against a fixed higher-precision reference, then evaluate actual tasks across long contexts, rare tokens, retrieval positions, languages, and generation lengths. A small elementwise error can interact with attention scores and normalization, and an early changed output token alters later inputs. Teacher-forced comparisons isolate numerical effects on a fixed token history; free-running generation measures the resulting closed loop. Neither exact token agreement on a few prompts nor one aggregate benchmark proves quality preservation across every workload. State the allowed degradation and sampling uncertainty.
The network lab illustrates only a nonlinear response to an altered scalar. Reset, explicitly set BOTH x=1 and w=1, predict sigmoid(0.5)≈0.6225, then Play or Step. Reset and re-set BOTH x=1 and w=0.95; predict sigmoid(0.45)≈0.6106. Edits retain t and the bias remains −0.5. This fixed unit does not quantize KV, run attention, or estimate language-model quality. Its reachable parameter change shows that a small representation perturbation can change a nonlinear output; the magnitude and acceptability of real cache errors require the actual reference tests.
Work it through
Include the metadata in a four-bit toy cache
An illustrative cache stores 4096 scalar values originally in two bytes each. Its custom replacement uses four packed bits per value and groups of sixty-four values, with four metadata bytes per group. Ignore every other overhead and do not identify this toy format with KIVI or FP8.
Original payload is 4096×2=8192 bytes. Four-bit codes occupy 4096×4/8=2048 bytes before metadata.
There are 4096/64=64 groups. Metadata uses 64×4=256 bytes, so total packed storage is 2048+256=2304 bytes.
The actual stated-format ratio is 8192/2304≈3.5556, below the nominal fourfold payload ratio. Memory savings do not prove preserved output quality or a 3.5556-fold speedup.
Bit width, persistent format overhead, runtime peak, quality, and speed require separate accounting and measurements.
The living notebook
Explore the model
Interactive lab · network
A small scalar change can alter a nonlinear output
For EACH run Reset, set BOTH x and w, predict, then Play or Step. At x=1 with fixed bias −0.5, w=1 gives≈0.6225 and w=0.95 gives≈0.6106. Edits retain t. This one-unit model performs no quantization, attention, KV storage, quality evaluation, or compression benchmark.
- Product · wx
- 1.2
- Logit · wx − 0.5
- 0.7
- Sigmoid output
- 0.6682
One inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA byte-saving representation needs reference-based quality tests; a toy output perturbation cannot establish its real error budget.
Pause & reason
Check your understanding
Your turn
Try it yourself
A toy format stores 2048 scalar values with eight-bit codes, groups of thirty-two, and four metadata bytes per group. Original storage is two bytes per value. Calculate total packed bytes and the reduction ratio, excluding all other overhead.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Count groups before comparing with the original 4096-byte payload.
Compare with the solution
Codes use 2048 bytes. Sixty-four groups use 64×4=256 metadata bytes, giving 2304 bytes total. The stated-format reduction ratio is 4096/2304≈1.7778, below the nominal factor two; quality and execution speed remain separate questions.
Keep the idea
Take it with you
- KV compression formats include scales, metadata, and sometimes residual or alignment costs.
- Representation approximation and exact eviction/recomputation have different correctness contracts.
- Persistent memory, runtime peak, throughput, and task quality must be evaluated separately.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.