AlgoViz

Attention kernels, KV heads and long context

hard 6 min

Long contexts increase both the work of mixing positions and the size of retained decoding state.

Trace the example

Follow the evidence through each stage, then test a change in the case.

Estimate the KV cache before doubling context

Estimate the KV cache before doubling context. Selected component: Active sequence inside Request budget.
Open full-size diagram

Request budget

2,048 positions

A single sequence is active. The model has 32 layers, 8 KV heads and head dimension 128. Stored cache elements use two bytes.

The model has 32 query heads and 8 KV heads. Which count enters this cache estimate?

Size one sequence’s cache

256 MiB of cached keys and values

32 layers, dimension 128 per head, two bytes per element and one active sequence. Allocator overhead is excluded.