Back to engineering

4ROUTER / Performance

The anatomy of a KV cache

The state behind generation, and how it uses memory.

Engineering note

What the cache holds

Autoregressive generation repeatedly attends to previous context. A KV cache retains attention keys and values so later steps can reuse earlier work. It is request state, separate from model weights, and consumes device memory as context grows.

Why block allocation matters

Requests vary in length and completion time. Reserving one large contiguous region can waste space. Block-based allocation maps a logically continuous context onto physical blocks. Block size, reclamation and reuse depend on the serving implementation and workload.

Reuse needs boundaries

A shared prefix is not the only condition for safe reuse. Model versions, token inputs, positions and execution settings must be compatible. Multi-tenant systems also need an isolation policy. Evaluate cache behavior alongside memory use and request delay.

Before implementation

  • Context-length distribution
  • Memory budget and reclamation
  • Prefix reuse and isolation

Further reading

vLLM · Paged attention

4ROUTER / SYSTEMS RESEARCH

Mechanisms and experiment design

Understand how operators, KV state and scheduling shape an inference path.

Read the systems notes in Resources
STATE / CAPACITY

KV cache: from tensor shapes to capacity budgets

Context length is a state budget that grows with concurrency.

ATTENTION / MEMORY

FlashAttention & PagedAttention: different memory problems

One optimizes data movement; the other organizes persistent state.

PREFIX / REUSE

RadixAttention: reuse prefixes, not answers

Reuse a prefix state with compatible computational history.

Let’s talk infrastructure.

Connect to the platform, or discuss models, performance and deployment.