Doubling the maximum context length on a served model causes out-of-memory errors at the same batch size. Why?
- Exam domain
- Inference Concepts15% of the exam
- Difficulty
- Medium
- In this mock
- 8 questions on this domainPractise this domain
Why the exam asks this
Inference Concepts (15% of the exam)
Objective in the exam guide: Optimization techniques: quantization and precision tradeoffs, KV and prefix caching, speculative decoding, tensor parallelism, disaggregated serving, and context-length effects on GPU memory.
Context-length effects on memory are listed under optimization.
Why C is the answer
The KV cache grows with sequence length
The KV cache stores keys and values for every token in every sequence, so memory grows with context length and batch size. Weights stay the same size.
Remember: KV cache memory scales with context and batch.
How it works
KV caching avoids recomputation but uses memory proportional to tokens. Paged attention and KV quantization reduce it.
In detail
- KV cache grows with tokens and batch.
- Weights do not change.
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. Weights double in size when the context doubles, so the model file itself becomes twice as largeWrongMost tempting
Weight size is fixed.
Why it tempts: Weights are the biggest memory item, so they seem to be the cause.
B. The tokenizer vocabulary growsWrong
Vocabulary does not change.
C. The KV cache grows with sequence lengthRight
KV cache memory scales with context and batch.
D. GPUs slow their clocks for long inputsWrong
Clocks are not the cause.
Use case
An illustrative scenario, not a real incident.
Illustrative: halving the batch size or using paged KV cache restores stable serving at the longer context.
See it in different ways
mindmap
root(("GPU memory"))
n1["Weights"]
n2["Fixed per model"]
n3["KV cache"]
n4["Grows with context"]
n5["Grows with batch"]
n6["Activations"]
n7["Temporary"]How to read this chart
- The centre is "GPU memory".
- "Weights" covers "Fixed per model".
- "KV cache" covers "Grows with context", "Grows with batch".
- "Activations" covers "Temporary".
flowchart TD
Q{"What can change?"}
Q -->|"Batch"| A0["Lower batch size"]
Q -->|"Precision"| A1["Quantize KV cache"]
Q -->|"Hardware"| A2["Tensor parallelism across GPUs"]How to read this chart
- At "What can change?": if "Batch", go to "Lower batch size"; if "Precision", go to "Quantize KV cache"; if "Hardware", go to "Tensor parallelism across GPUs".
Related questions
Learn more
- Our lesson: Inference concepts
- Practise Inference Concepts questions in the mock exam
- Source: Efficient Memory Management for LLM Serving with PagedAttention (arXiv)
- Source: TensorRT-LLM documentation
- TensorRT-LLM documentation
- NVIDIA Dynamo documentation
- Efficient Memory Management for LLM Serving with PagedAttention (arXiv)
- Fast Inference from Transformers via Speculative Decoding (arXiv)