System Design
19. AI System Design and LLM InfrastructureAnimated
GPU Memory Management
Fitting models and caches into GPU memory.
The idea
Weights, activations, optimiser state and KV cache compete for limited memory.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
Memory is split into small blocks, like pages in an operating system.
- used:
- 0
- free:
- 16
1/12
PagedAttention (vLLM) removes the fragmentation that wastes most KV-cache memory.
Step by step
- 1Estimate memory for weights
- 2Add activations or KV cache
- 3Reduce with quantisation, sharding or paging
- 4Monitor out-of-memory
Where it is used
Training and inference.
Watch out for
Fragmentation causes out-of-memory errors even with free space.