Why does a long LLM chat need GPU memory?

The model fits on the GPU. Then the conversations arrive.

The weights are only part of the memory budget. The KV cache grows with active context, and concurrent requests need their own state.

This comic calculates a toy cache from its layers, KV heads, head dimension and precision: 128 KiB per token, then 1 GiB for an 8,192-token sequence. Runtime overhead comes after that.

Download this comic as a PDF

Comic page 1 of 6: Why does a long LLM chat need GPU memory?
Read page 1 as text

Why does a long LLM chat need GPU memory?

The weights fitted. Then the conversations arrived.

WHAT WE WILL FIGURE OUT

01

Weights and working state differ

02

Calculate one cache budget

03

Capacity and speed are different

OUR EXAMPLE

A toy cache: 32 layers, 8 KV heads, 128 numbers per head, 2 bytes per number.

Follow the steps. Ask the obvious questions. Check the result.

Part 8 of 18 · Challenge: page 5 · Suggested answers: page 6

Comic page 2 of 6: Weights and working state differ
Read page 2 as text

Weights and working state differ

1

MODEL LOADED

weights

cache

overhead

weights

cache

overhead

Are we ready for every user?

Loaded weights are only one part of serving memory. Active requests also need context state and temporary working space.

GPU memory = weights + cache + overhead

2

WHAT THE CACHE STORES

keys

values

keys

values

KV means keys and values computed for earlier positions at each attention layer. It is runtime state, not a list of final answers.

Earlier K and V reused during decode

3

WHAT STILL HAPPENS

FOLLOW THE CHANGE

new query

earlier K,V

new query

→

earlier K,V

The new token needs fresh computation. Its query still attends over earlier cached keys and values.

Reuse earlier work; compute the new position

4

WHY IT CAN GROW

FOLLOW THE CHANGE

more positions

more KV

more positions

→

more KV

A growing sequence usually adds cached positions. Cache layout and retention depend on architecture and runtime.

More active tokens often mean more cache memory

Comic page 3 of 6: Calculate one cache budget
Read page 3 as text

Calculate one cache budget

5

COUNT BOTH K AND V

2 arrays: keys AND values

32 layers × 8 KV heads × 128 dimensions × 2 bytes

= 131,072 bytes per cached token

2 × 32 × 8

128 × 2 bytes

How many bytes per token?

For this simple configuration, multiply two arrays by layers, KV heads, head dimension and bytes per number.

2 × 32 × 8 × 128 × 2 = 131,072 bytes

6

EXTEND TO A CONVERSATION

128 KiB for one token

× 8,192 cached positions

= 1 GiB raw KV payload

128 KiB/token

→

8,192 tokens

That is 128 KiB per token. An 8,192-token sequence uses 1 GiB of raw KV payload in this toy configuration.

128 KiB × 8,192 = 1 GiB

7

ADD CONCURRENT REQUESTS

EIGHT INDEPENDENT SEQUENCES

1 GiB

1 GiB

1 GiB

1 GiB

1 GiB

1 GiB

1 GiB

1 GiB

8 × 1 GiB = 8 GiB, before overhead

1 GiB × 8

→

8 GiB

Eight independent sequences of this length need about 8 GiB of raw cache payload before allocator and runtime overhead.

8 requests × 1 GiB = 8 GiB

8

RESERVE HEADROOM

16 theoretical

leave headroom

16 theoretical

leave headroom

With 16 GiB available for cache, arithmetic gives 16 such sequences. A real service needs margins for growth and variation.

A theoretical fit is not a safe admission limit

Comic page 4 of 6: Capacity and speed are different
Read page 4 as text

Capacity and speed are different

9

SHARED PREFIXES

SHARED PREFIX

›

›

Request A private suffix

Request B private suffix

shared prefix

private suffixes

Does every request duplicate everything?

Supporting runtimes can share eligible identical prefix blocks. Private suffixes and permissions still need isolation.

Shared prefix; request-specific continuation

10

CAPACITY

state needed

memory available

state needed

memory available

Capacity asks whether all required state fits. Long contexts and many users can compete for the same memory.

Enough room for weights is only the first check

11

BANDWIDTH

bytes moved

time taken

bytes moved

time taken

Bandwidth asks how quickly data can be moved. Small-batch decode can spend much of its time moving weights and cache data.

Fits in memory does not imply fast generation

12

MY NEW MENTAL MODEL

less recompute

more storage

less recompute

more storage

Reuse saves work but occupies space.

KV caching is a computation-versus-memory tradeoff. It does not, by itself, promise a discounted API bill.

Next: reuse across requests and billing

Comic page 5 of 6: Your turn. Can you explain what happens?
Read page 5 as text

Your turn. Can you explain what happens?

Use the same example. Change one detail. What follows?

KEEP THIS EXAMPLE IN MIND

A toy cache: 32 layers, 8 KV heads, 128 numbers per head, 2 bytes per number.

Try first. Suggested answers are on the next page.

1

What is the toy raw KV payload for 8,192 tokens?

What makes you say that?

2

Why does the next token still need computation?

What makes you say that?

3

Why is the maximum arithmetic request count unsafe as a production target?

What makes you say that?

Write your answers in the comments.

Comic page 6 of 6: Suggested answers
Read page 6 as text

Suggested answers

Why does a long LLM chat need GPU memory?

01

What is the toy raw KV payload for 8,192 tokens?

1 GiB for the stated toy architecture and precision.

02

Why does the next token still need computation?

Its hidden state, projections and attention result must be computed using the earlier cached state.

03

Why is the maximum arithmetic request count unsafe as a production target?

Requests grow, lengths vary, and the runtime and allocator require headroom.

Try the challenge on page 5. Suggested answers follow on page 6.