Applied AI & Models · Failure-Mode Anatomy

Why INT4 KV Caches Lose Exact Recall Before Perplexity

INT4 can preserve average token loss while perturbing a few retrieval-critical attention heads enough to corrupt exact citations and identifiers.

Key Thesis

INT4 KV-cache quantization saves memory, but small key errors can change which distant token wins attention, while value errors can blur the selected content. Perplexity averages across tokens and can miss failures on rare UUIDs or citations, so gate deployment on exact retrieval tests by context length and head. Keep sensitive heads or cache regions at higher precision when the measured retrieval benefit justifies the memory cost.

The failure starts in the cache, not the language model

A key-value cache stores the keys and values computed for earlier tokens, so decoding does not have to recompute them. With grouped-query attention, many query heads share a smaller set of key-value heads. That lowers cache size, but it also means quantization error in one shared cache can affect several query heads.

INT4 compression maps values to a small discrete range, usually with a scale and sometimes a zero point for each group. The exact format varies by implementation. The important change is that each stored key and value is now an approximation, and the approximation error is not equally consequential at every position or head.

For a query (q) and key (k_i), attention compares scores proportional to (q \cdot k_i / \sqrt{d}). A modest perturbation to (k_i) can change the ranking when two candidate scores are close. If a distant UUID or citation is represented by a few tokens whose scores sit near a competitor, the model may attend to the wrong token even though the average perturbation across the cache is small.

Value error creates a related problem after selection. The model can assign attention to the correct position but retrieve a distorted representation of its content. These are distinct failure paths: key error changes where attention goes. Value error changes what arrives after it gets there.

Why perplexity misses the damage

Perplexity summarizes average next-token prediction loss over a dataset. Common words and predictable continuations contribute many observations, while an exact identifier may appear once in a long prompt. A model can make a wrong choice on that one identifier and barely move its average loss.

Exact retrieval also has a sharp boundary. A citation such as “Smith et al., 2021” is wrong if one digit changes. A UUID is wrong if one character changes. A small logit shift that would be harmless for a paraphrase can therefore fail the application’s contract.

The weak points need not be the heads with the largest average quantization error. A head that rarely activates may carry a decisive retrieval signal on a particular prompt. Averaging error over tokens, layers, or heads can hide that tail behavior, especially when most evaluation examples ask for summaries rather than exact strings.

The memory savings can still be substantial. As an illustration, assume 32 layers, 8 key-value heads, head dimension 128, and a context of 131,072 tokens. For keys and values stored at two bytes each, the raw cache is about 16 GiB. At four bits per element, the nominal payload is about 4 GiB before scales, alignment, and allocator overhead. Real savings depend on the quantizer and runtime.

The first useful alarm is a retrieval invariant

Perplexity belongs in the evaluation suite, but it is not a release gate for exact recall. Add a test that plants a known string at controlled positions, requests it verbatim, and checks exact output equality. Sweep context length, position, distractor count, and identifier type, then report accuracy by bucket rather than only as one aggregate number.

Instrument the attention path during a smaller diagnostic run. For each relevant head and query, compare the top attended position and score margin between the unquantized and quantized caches. A position flip on an exact-retrieval prompt is an early warning even if the final answer happens to be correct in that sample.

A practical invariant is that quantization must not change exact-match accuracy beyond a chosen tolerance at any supported context-length bucket. The threshold is a product decision, not a universal constant. For a system that returns legal citations or database identifiers, one missed exact match may cost more than several GiB of cache.

for length in context_buckets:
    prompts = retrieval_cases[length]
    fp16 = exact_match(model, prompts, cache="fp16")
    int4 = exact_match(model, prompts, cache="int4")

    assert int4 >= fp16 - allowed_drop
    log(length, fp16, int4, head_margin_flips)

The margin diagnostic helps explain a failure, but it is not a substitute for output checks. Attention weights are not a complete explanation of model behavior, and a changed attended position does not always produce a changed answer. Use the diagnostic to locate sensitivity, then reproduce the user-visible error with the full decoding path.

Mitigate by where information matters

MitigationWhat it protectsCost or limitation
Per-group or per-channel scalesReduces error from uneven value rangesMore metadata and kernel complexity
Keep sensitive heads at 8-bit or 16-bitPreserves measured retrieval-critical pathsGives back some cache savings
Retain recent tokens at higher precisionProtects near-context operations and mixed workloadsDoes not automatically protect distant needles
Retrieval-aware evaluation gatesDetects exact-match regressions by length and positionRequires representative test cases
Selective cache promotionRaises precision for identified regions or requestsAdds runtime policy and memory accounting

Do not assume that preserving recent tokens solves distant retrieval. The right policy depends on where errors appear in your own model and workload. If errors cluster in a few heads, selective precision may preserve most of the memory reduction. If they track context position or identifier type, head-only policies may miss them.

Treat the memory target and the retrieval target as one optimization problem. Benchmark the actual serving kernel, since scales and dequantization can affect latency, and measure peak resident memory under concurrent requests. A cache that saves 12 GiB per request on paper may deliver less capacity if metadata, temporary buffers, or allocator fragmentation dominate.

The operational rule is plain: do not ship INT4 because perplexity stayed flat. Ship it when exact-match tests hold across supported context lengths, the failure cases have been traced, and the measured memory or throughput gain pays for the remaining precision exceptions. That is the difference between compressing a tensor and preserving a service contract.

References

Discussion (0)

No reader notes yet.