| ISSUE 381/456 · COMPUTER SCIENCE |
~4 MIN |
FOUNDATION / AI MEMORY · READING DATE 2027-10-17 · OCTOBER 2027 — LANGUAGE MODELS AND MEASUREMENT
Why a longer AI answer needs more working memory
START HERE
A long calculation can save repeated work by keeping intermediate results. A language model is a computer program trained to predict and generate text. A key-value cache is working storage of numerical results from earlier text positions, reused as this program generates more text. Keeping those results can speed generation, but the stored information often grows as the conversation or answer grows.
|
/ WHY NOW
This is a different question from reusing the same prompt across separate requests. Even during one continuous answer, a model may need more working memory at the end than at the beginning because more positions have been processed.
|
/ THE IDEA
In attention, a model operation for combining information across positions, a new position compares its query with stored keys and combines corresponding values. Queries, keys and values are numerical lists, not ordinary dictionary entries or database records. For standard full-attention generation, earlier keys and values do not need to be recalculated for every new token. The cache stores them for each relevant layer. A token is one text piece, and a layer is one stage of the model calculation. More cached positions mean more stored lists even though the model’s permanent settings remain unchanged.
THE FORMAL IDEA
cache bytes ≈ 2 × L × H × D × N × B
| 2 counts keys and values; L = cached layers; H = key-value heads, or parallel list groups. | | D = numbers per head; N = stored positions; B = bytes per number. A byte is a storage unit containing eight 0-or-1 digits. This is for one sequence and a simple full cache. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
Toy model: L = 2, H = 1, D = 4, B = 2 bytes. At N = 100: cache ≈ 2 × 2 × 1 × 4 × 100 × 2 = 3,200 bytes. Change only N to 200: cache ≈ 6,400 bytes. Permanent model weights are unchanged; intermediate storage doubled.
|
The saving is repeated arithmetic, while the price is retained information. A model fitting into memory before generation does not guarantee room for arbitrarily long outputs or many simultaneous users. Those uses need additional working space.
/ SO WHAT?
This makes maximum answer length and concurrent conversations practical memory decisions. Serving systems can reserve space, share suitable prefixes or manage cache blocks, but the underlying accounting still matters. Measuring only the size of the downloaded model leaves out this growing part of execution. Check what architecture and cache policy a memory estimate assumes.
ONE CAVEAT |
| Sliding windows, compressed caches, grouped heads and other architectures change the formula or growth. Batch padding and allocation overhead also matter. This is not a model-independent memory calculator or a claim that all conversation history is retained forever. |
KEEP THIS
Reusing earlier keys and values trades repeated calculation for storage that can grow with every retained position.
|
NEXT: Why a temperature probe needs to know its other end
|