ai.vostman.fi
Compute, memory & the cost of context

The RAM Price
Catastrophe,
Explained.

Why AI needs so much memory—and whether supply can ever catch up.

17 October 20265 minute read4 illustrated explorations
Computation stops; retained context connects the next requestA token stream enters GPU computation, is retained as memory, then returns to the next computation.COMPUTEa request runsRETAINthe context waitsinputKV statereuse on the next call
A request stops. Its context stays.
The cost of forgetting is what happens next.
Inside this story
  1. The expensive part of forgetting
  2. A cache that dies before its next use
  3. Can AI become efficient enough to escape?

A coding agent edits a file and starts a test. Its next message might be a single line. The history behind that message is much larger—and the work already done on it remains valuable.

While the test runs, the GPU serves someone else. But the agent will return with almost the same history: instructions, code, decisions, tool calls, and results. The service must keep the state representing that history, move it to another memory tier, or calculate it again.

Multiply that choice across a population of agents and a memory shortage starts to look different. Memory is preserving something more expensive than itself: computation.

The expensive part of forgetting

A Transformer's KV cache holds the keys and values its attention mechanism needs from earlier tokens. Reusing them lets the model continue from old work. Prompt caching extends that saving across API calls with matching prefixes, as OpenAI's documentation describes.

The state that survives a token

FIG. 01
A simplified Transformer layer and its KV cacheInput representations are projected to queries, keys and values. Only keys and values are appended to the cache. Attention reads the accumulated keys and values, then passes activations to the feed-forward network. ONE TRANSFORMER LAYER · schematic Hidden statenew tokens Q, K, V projectionslearned weights Q Attentionread the context FFN / expertstransform each token Next layeractivations append K, V KV cacheold state + new state Retained across tokensand eligible API calls
One attention head
Q: queries for new tokens. K, V: keys and values for the visible prefix, including new tokens. dh: query/key head dimension. M: causal mask (0 for allowed positions, −∞ for future ones). ⊤: transpose. Softmax acts across key positions.
Keep the results of old work. K and V carry the history forward. Each new token supplies a query that reads the retained state.

Several things grow differently as context gets longer. KV storage grows linearly. Projections and feed-forward operations during prefill also grow linearly with token count. But in full causal attention, tokens interact with preceding tokens: a prompt of n tokens contains n(n + 1)/2 query–key pairs. Double its length and this attention work approaches four times the original amount.

This also explains why uncached input tokens can cost less than output tokens. During prefill, the input is already known, so the GPU can process many tokens together and reuse model weights efficiently. During generation, each new token depends on the previous ones: the model must run again, reading weights and the growing KV cache. Batching different users helps, but memory capacity and response latency limit how much work can be combined.

Now follow an agent that keeps extending its history. Start with one new token per call so the arithmetic is visible. Without reuse, each call rebuilds its entire prefix. Across T calls, the attention-pair count is:

Rebuild the prefix on every call
Cubic growth · leading term T³ / 6
T = total calls; t = current call, from 1 to T. One new token per call. P counts causal query–key pairs for one attention head in one layer.

Quadratic attention work, repeated over a growing history, accumulates cubically.

With KV reuse, earlier rows are already computed. At call t, only the new token needs to attend over t positions. Across the same run:

Reuse the prefix; compute only the new row
Quadratic growth · leading term T² / 2
Same calls and pair-count convention. At T = 100: 171,700 pairs when rebuilding versus 5,050 with reuse — exactly 34× as many. The chart below uses these same equations.

At 100 calls, rebuilding uses 171,700 pairs versus 5,050 with reuse: 34 times as much attention work. Fixed blocks of new tokens preserve the cubic-versus-quadratic cumulative growth. Sparse attention and compressed architectures can change that curve; this is our full-attention baseline.

Caching leaves one generated token's attention cost linear in the existing history. It avoids rebuilding all the previous work. A linearly growing memory allocation protects an increasingly large amount of computation.

Forgetting changes the growth curve

FIG. 02
Rebuild every prefix · cubic cumulative growthReuse the prefix · quadratic cumulative growth

Move the slider to extend the run. The axes stay fixed; pale lines show the full 200-step comparison. The reuse curve stays near zero on this shared linear scale.

Cumulative causal-attention work across a growing agent runAt 100 steps, rebuilding uses 171,700 pair units versus 5,050 with reuse. 1.4M700K0 050100150200Agent steps →Cumulative attention pairs
5 steps200 steps
171,700
Rebuild every prefix
5,050
Reuse previous state
34×
More attention work without reuse

Double this run from 100 to 200 steps: rebuilding needs 7.88× the attention work; reuse needs 3.98×.

Count each pair once—or rebuild it on every call. One new token per step. The two curves use the same equations as the text.

A cache that dies before its next use

Keeping one context is straightforward. Keeping a population alive is the problem. While agent A waits for a test, B reads a file and C receives a browser result. Each will want its own state again.

A cache can save A's state, evict it to make room for B and C, then discover A has returned. Now the service repeats the work it just discarded. EfficientAgent's concurrent coding-agent experiments explore this working-set problem: host-cache capacity must cover the state agents reuse across their tool waits.

The useful hierarchy is GPU memory for active attention, host RAM for recently used contexts, and NVMe for colder state. NVIDIA Dynamo supports this kind of tiering. A backing copy can exist before the upper copy is evicted; freeing GPU space then need not wait for a new copy.

To put the transfer cost in perspective, take 288 GB, the memory capacity of one GPU in NVIDIA’s GB300 reference. Refilling that capacity takes roughly 1.5 seconds from RAM or 20 seconds from NVMe under our full-bandwidth, equally shared assumptions. That capacity and bandwidth may serve one agent or many.

Host RAM lets the service release GPU memory without discarding useful work. Across many interleaved agents, the state waiting for another call becomes a substantial resource in its own right.

Comparing OpenAI’s cached-input pricing with hardware rental costs from Verda, an affordable Finnish hyperscaler, gave us an estimate of about 2 MB of KV state per token, assuming a 30-second GPU lifetime and a two-minute RAM lifetime. Even with the longer lifetime, retaining the cache in RAM costs only about 30% as much as retaining it on the GPU.

While one agent waits, everyone else keeps working

FIG. 03
Interleaved agents and cache survivalAgent A runs, waits for a tool while agents B and C execute, then returns. If its cache survives, A reuses it. If evicted from all tiers, the prefix must be recomputed. TIME → Agent AAgent BAgent C model calltool execution · no active generationnext model call read / generatenext call read / generate A’s contextretain state until A returnsRetained → reuse. Evicted from all cache tiers → rebuild the prefix.
Capacity must cover reuse, not just execution. Other agents create state during A’s tool wait. A cache that evicts A’s state before its next call cannot deliver the expected recomputation saving.

Keep the state available for the next call

FIG. 04
Retained state across GPU memory, host RAM and NVMeState used for active attention stays in GPU memory. Host RAM retains reusable state between calls, with NVMe as a further tier. GPU memoryactive attention Host RAMretain between calls NVMelonger retention Retain useful work while the GPU serves other requests.
Preserve the work across calls. The next request restores the state it needs for active attention.

Can AI become efficient enough to escape?

The obvious escape is to make remembering more efficient. Models can share KV across heads and layers, compress historical state, use fewer bits, or attend selectively. Shared prefixes let many requests reuse one physical copy of common instructions.

DeepSeek's V4.1 Flash combines compressed global state, cross-layer reuse, lower precision, and bounded reconstruction of selected state. Its technical report describes separate GPU-resident and persistent host/SSD caches. Better architecture can shrink both what must be stored and what must be moved.

But efficiency has a rival: how much work we ask the system to do. A tenfold reduction in memory per token is consumed by ten times as many retained tokens. Longer histories, more concurrent agents, and more delegated tasks can expand the working set as quickly as architecture shrinks each context.

New production expands supply. Better models stretch each gigabyte further. More ambitious workloads pull in the other direction. Whether RAM prices ease depends on which side moves faster.

AI's hunger for RAM is partly the price of avoiding an even greater hunger for computation.

Independent technical analysis · Sources are linked throughout.