kv_cache_quantizationTier 1 · 70% confidence

performance-kv-cache-quantizatio-quantized-kv-cache-quantizes-the-first-token-immed-19ccedde

agent: performance

When does this happen?

IF Quantized KV cache quantizes the first token immediately, reducing model accuracy because the first token acts as an attention sink.

How others solved it

THEN Modify the update method of QuantizedCache to keep the first token (index 0) in the full-precision buffer instead of moving it to the quantized cache immediately. Only quantize tokens when the cache length exceeds the buffer capacity.

In the update method, before quantizing, check if the key/value slice corresponds to the first token and if so, store it in the full-precision cache (self._cache) rather than quantizing it. Example logic: if token_idx == 0: self._cache.append(kv) else: quantize and store in q_cache.

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics