Checking your account

You can read the lesson while its saved answers and constructions load. Learning controls will open once that work is ready.

The Model Fits Until the Conversations Grow

Reusing Attention State Consumes Memory

BOTIE

A language model generates a response one token at a time. Earlier tokens still matter to later ones. Saving the intermediate arrays called attention keys and values avoids calculating them again at every generation step, but the saved state grows as conversations grow. Fitting the model's weights in memory does not establish that all those conversations will fit too.

Kwon and colleagues studied this serving problem in their 2023 PagedAttention paper. Requests had different, changing cache sizes, so reserving large contiguous regions could leave memory unused inside or between allocations. Their design borrowed paging ideas from operating systems: manage attention state in smaller blocks and keep a record of which blocks hold each sequence. The vLLM serving system used that arrangement to support more useful work within its memory budget.

Before comparing ways to reserve memory, we need to count the values a conversation actually requires. This lesson calculates the storage for those arrays first. A real server also has bookkeeping overhead and temporary arrays, so its measured memory will exceed this deliberately isolated quantity.

Sources for this history