Will it fit?
Move the sliders until the total turns green on your machine. Each line below the total is a common machine with the memory a model can actually use on it.
- Weights
- 16 GB
- Context
- 3.7 GB
- Runtime
- 0.5 GB
- Total
- 20 GB
- 16 GB laptopToo big
- 24 GB GPUFits
- 32 GB GPUFits
- 64 GB MacFits
- 128 GB boxFits
- 512 GB Mac StudioFits
The formula
The total has three parts, and you can do the sums by hand.
- WeightsWeightsThe full set of a model's parameters, stored in a file.Read more: parametersParameterOne learned number inside a model. An 8B model has about eight billion of them.Read more in billions, times bits per weight, divided by 8. A 27B model at about 4.8 bits is about 16 GB.
- Context: the KV cacheKV cacheSaved work from earlier tokens, so the model does not reread the whole conversation for every new token.Read more grows with every tokenTokenA chunk of text, usually part of a word. Models read and write in tokens.Read more in the context window. Bigger models store more per token.
- RuntimeRuntimeThe software that loads a model file and runs it.Read more: about half a GB for the runtime itself and its buffers.
At 4-bit, budget about 0.6 GB per billion parameters. At 8-bit, budget about 1.1 GB per billion parameters. Then add a few GB for context.
Reading the result
A model that fits with less than a GB to spare will load, then slow down or crash as the conversation grows. Leave headroom of a few GB, or more if you run an agent with a long context.
The usable memory per machine is our estimate. On a Mac, macOS keeps a share of unified memoryUnified memoryOne pool of memory shared by CPU and GPU, as on Apple silicon and some AMD and NVIDIA boxes.Read more for itself. On a PC with a graphics card, only VRAMVRAMMemory on a graphics card. On a PC with a GPU, it is your model budget.Read more counts, and the desktop takes a little of that too. Will the model fit in my memory? explains both.
The context estimate assumes the attention layout most current models use and a 16-bit cache. Some models store far less per token, a few store more. Check the real number in your runtime's log the first time you load a model.
Go deeperThat's enough
Where the context estimate comes from
For each token, every layer stores a key and a value for each attention head group.
Multiply layers, head groups, head size, two and the bytes per number, and you get the cache per token. For Llama-style 8B models that is about 0.13 MB per token, and for 70B models about 0.33 MB. The tool scales between those with the square root of the parameter count, which tracks current models within about a third.
Why 8-bit KV cache helps
Halving the bits per cached number halves the context memory.
The cost is a small loss in recall over long contexts. It is worth it when the context, not the weights, is what stops a model fitting. See How do I make it faster?.
Mixture of experts models
Use the total parameter count, not the active count. An MoEMixture of expertsA model split into experts, where only a few run for each token.Read more model still has to hold every expert in memory, even though each token only uses a few. What is a mixture of experts model? covers why.