Memory math
You load an 8B model on a 24 GB GPU and it fits with room to spare. Then you set the context to 128K tokens, and the first long conversation runs it out of memory. The weights didn't grow. The KV cache did, and it's easy to calculate before it surprises you.
In this lesson you'll learn to
- Calculate the memory a model's weights need at a given precision.
- Calculate the KV cache per token and per request from a model's shape.
- Size a GPU for a model, a context length and a number of concurrent requests.
- Explain the main ways to fit more, from grouped-query attention to KV cache quantization and paging.
Create a free account to open this lesson
It's free. You'll get every free lesson, quizzes that save your progress, daily flashcards and streaks.