What Uses Memory at Inference Time?
Which parts of a GPU's memory a model uses while it answers: the weights, the KV cache and working memory, and how teams fit more users, for your AI interview.
In short
While a model answers, the graphics card holds the model's weights and the KV cache, a store of past tokens that grows with every word of every chat. The weights stay fixed, so the number of chats open at once, and how long each one runs, decides whether everything fits.
11 min readAdvancedCommon · estimateFacts checked 26 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
The graphics card holds two big things while a model answers. The first is the weights, the model's learned numbers, which stay the same size. The second is the KV cache, a notebook of past tokens that grows with every word of every chat. Working memory for each step is reused. So when I size a server, I add up the weights and the cache for the chats I want at once, then check that it fits.
Inference is the moment a trained model answers. The model's weights are loaded into GPU memory first, and they stay there. NVIDIA's 2023 guide puts a 7 billion parameter model in 16-bit numbers at about 14 GB, and that size is fixed no matter what the user types.
The second big user is the KV cache. For every token of every chat, the model keeps key and value lists for each layer, so it does not redo that work. The cache grows with each word, and each chat in the batch gets its own. One 4,096-token chat is about 2 GB on that same model.
The third part is working memory, the temporary numbers made during each step. It is reused from one step to the next, but it still needs room. Add the three and you get the peak the card must hold. If the total is too big, the server runs out of memory and requests fail.
So I size it in this order. Count the weights, count the cache for the chats I want at once, and leave a margin. If it doesn't fit, I use quantisation for smaller weights, a model with fewer cached heads, or a paged cache that wastes less space. Each one has a cost, so I test quality after the change.
What is inference memory, in plain words?
Inference is the step where a trained model answers. Training is the long, earlier step that built it. In this answer, memory means the memory on the graphics card (GPU) that runs the model. It has nothing to do with an agent's long-term notes.
Think of a call centre desk. The desk, the phone system and the software are in place before the first call, and they never change size. Each open call adds a folder of notes, and the folder grows until the call ends. A busy desk fills up because of the open folders.
In an AI system, the desk is the model's weights and each open chat is a KV cache. When a bank's card support assistant has four long chats open at once, the card holds one copy of the model and four caches beside it.
Key words
- Token
- A small piece of text, about a word or part of one, that the model reads and writes.
- Weights
- The model's learned numbers, called parameters. Loaded once, they stay the same size.
- KV cache
- A notebook of key and value numbers for each past token. It grows as the chat grows.
- Batch
- The group of chats the model works on together in one step.
- Quantisation
- Storing each number in fewer bits than before, to save memory.
What takes up memory while the model answers?
NVIDIA's 2023 guide names two main contributors to GPU memory: the model weights and the KV cache. Working memory and some overhead make up the rest.
The weights come first. Hugging Face gives a rule of thumb for 16-bit numbers: about 2 GB for every billion parameters. A 7 billion parameter model therefore needs about 14 GB just to load. For shorter inputs, under 1,024 tokens, the weights are what mostly fills memory.
“In effect, the two main contributors to the GPU LLM memory requirement are model weights and the KV cache.”
NVIDIA, 2023
“existing systems struggle because the key-value cache (KV cache) memory for each request is huge and grows and shrinks dynamically.”
The vLLM paper, 2023
Where the memory goes while a model answers
Fixed for the model
Model weights
loaded once, same for every chat
Grows with use
KV cache
stores past tokens, per chat
Working memory
short-lived, reused each step
GPU memory in use
weights + cache + working memory
Fits on the card?
if not, fewer chats or smaller weights
- 1The weights take a fixed block of the card.
- 2Each open chat adds its own cache, and the cache keeps growing.
- 3Working memory for each step sits on top, and is reused.
- 4The total must fit on the card, or the server cannot serve all its chats.
Working memory is the third part. It holds the temporary numbers made during each step, and that space is reused from one step to the next. The server still needs room for it. Some memory also goes to the software that runs the model. No formula covers that, so leave a margin.
Why does the KV cache get so big?
The KV cache keeps a key list and a value list for every layer and every past token. That way the model does not redo the work at each new word. Its size grows with five things: the number of layers, the hidden size (how wide the model is), the bytes per number, the number of tokens, and the number of chats open at once.
NVIDIA writes the total as batch size times sequence length times 2 times the number of layers times the hidden size times the bytes per number. The 2 is for keys and values. Each chat in a batch gets its own cache, so the total grows with the number of chats.
Take a bank's card support assistant. It runs a 7 billion parameter model in 16-bit numbers on a 24 GB card. The weights take about 14 GB, which leaves 10 GB. One 4,096-token chat needs about 2.15 GB of cache, so only four long chats fit, and working memory needs room too. Ten chats at once would need about 21.5 GB of cache, and the card would run out.
Here is the same sum in Python, in decimal gigabytes (1 GB = 1,000,000,000 bytes). The last line checks the formula against NVIDIA's example, which is about 2 GB.
# A 7B-parameter model in 16-bit numbers (2 bytes each), with the shape NVIDIA used in its 2023 Llama 2 7B example:
# 32 layers, hidden size 4096. Sizes are decimal gigabytes (1 GB = 1,000,000,000 bytes).
PARAMS = 7_000_000_000
LAYERS = 32
HIDDEN = 4096
BYTES = 2
CARD_GB = 24
CHAT_TOKENS = 4096
weights = PARAMS * BYTES / 1e9
# Keys and values (2), for every layer, every token, every chat.
per_chat = 2 * LAYERS * HIDDEN * BYTES * CHAT_TOKENS / 1e9
room = CARD_GB - weights
chats = int(room // per_chat)
print(f"Weights: {weights:.1f} GB")
print(f"Cache for one 4,096-token chat: {per_chat:.2f} GB")
print(f"Room left after the weights: {room:.1f} GB")
print(f"Long chats that fit: {chats}")
print(f"Ten chats need: {10 * per_chat:.1f} GB of cache")
# Sanity check: NVIDIA's example, 1 x 4096 x 2 x 32 x 4096 x 2 bytes, is about 2 GB.
print(f"NVIDIA's example in GiB: {1 * 4096 * 2 * 32 * 4096 * 2 / 2**30:.1f}")Output
Weights: 14.0 GB Cache for one 4,096-token chat: 2.15 GB Room left after the weights: 10.0 GB Long chats that fit: 4 Ten chats need: 21.5 GB of cache NVIDIA's example in GiB: 2.0
The simple formula assumes every attention head keeps its own key and value lists. Grouped-query attention, which the GQA paper introduced, uses an intermediate (more than one, less than number of query heads) number of key-value heads, so the cache per token is smaller.
How do teams fit more chats on one card?
There are three levers, and each one has a cost. Smaller weights through quantisation: Hugging Face notes that it trades memory against accuracy, so the team tests quality before it switches. A smaller cache through fewer heads, which is set in the model's design. You get it by choosing a model built that way, not by changing a running one. And a paged cache, which stores the cache in small blocks, like pages, so the vLLM paper says it wastes close to nothing.
Some serving software also caps how much of the card it may use. vLLM, for example, has a setting for the fraction of GPU memory it can use, from 0 to 1.
Three levers to fit more chats on one card
Too little room
many long chats at once
Smaller weights
Quantise the weights
fewer bits per number, less accuracy
Less cache memory used
Fewer key-value heads
chosen at design time, before training
Paged cache blocks
small blocks, so little space sits empty
More chats per card
same card, same model
- 1Fewer bits per number make the weights smaller.
- 2A model with fewer key and value heads has a smaller cache.
- 3Storing the cache in small blocks wastes less space.
- 4Smaller weights leave more room for chats.
- 5Fewer heads means fewer numbers stored per token.
- 6Less wasted space means more chats per card.
Tip
Asked how to fit more users, don't jump to a bigger GPU. Do the sum first, then name the lever you would pull and what it costs in quality or effort.
What does the interviewer want to hear?
A strong answer covers
- Name the two big parts: the weights and the KV cache.
- Say the weights are fixed, and the cache grows with tokens and chats.
- Add working memory and the peak it creates.
- Do the fit check: the total against the card's size.
- Name the levers, quantisation, fewer cache heads and a paged cache, with their costs.
- Admit the numbers depend on the model, the precision and the batch.
Common traps
Trap"Only the model size matters."
BetterModel size sets the weights. Users and context length set the cache.
Trap"The KV cache is a fixed cost."
BetterIt grows with every token and with every chat open at once.
Trap"Buy a bigger GPU first."
BetterCount first. Smaller weights or a smaller cache may fit the same card.
Can you spot the gap?
Spot the gap
Which sizing note says the assistant fits without counting the cache?
Quick check
A bank's assistant runs a 7 billion parameter model on a 24 GB card, with ten long chats at once. What should the team check first?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
- Q055What is the KV cache, and why does it speed up generation?12 min
- Q319What is PagedAttention / vLLM?Coming soon
- Q311What is quantization?10 min
- Q327GPU basics: why does memory bandwidth limit decoding?Coming soon
- Q328Does a 70B model fit on one 80GB GPU?Coming soon
Learn it in depth
Last updated on 26 November 2026
Sizing a GPU for an AI app with many users at once?
I design and build AI products and agents, including the system behind them. Book a short call and tell me the model, the number of users and the hardware you have.