Will the model fit in my memory?

5 min readMarkdown

Memory is the first question for any model. If the whole model fits in fast memory, it runs at your hardware's full speed. If it does not, it either crawls or refuses to load.

It fits or it does not

A model is not like a game that runs at lower settings on a weaker machine. Every weight is needed for every tokenTokenA chunk of text, usually part of a word. Models read and write in tokens.Read more, so all of them have to sit in memory at once. There is no partial mode that keeps the quality and drops the size.

What you can change is which file you load. A smaller model, or the same model at a lower What is quantization?, is the only real way to make something fit. Will it fit? does the sums for your machine.

RAM, VRAM and unified memory

Your memory budget depends on where the model runs. Each platform has one number that matters.

PlatformYour budgetWhy
Mac with Apple siliconUnified memory, minus what macOS keepsCPU and GPU share one pool. RAM is the whole budget
PC with an NVIDIA or AMD graphics cardVRAM on the cardThe GPU can only work fast on its own memory
Unified-memory PC, such as AMD Strix HaloThe share given to the GPUShared pool, often split in firmware or the driver
CPU onlySystem RAMWorks, but slowly

On a PC with a graphics card, system RAM is a fallback, not part of the budget. A 16 GB card in a machine with 64 GB of RAM still has a 16 GB budget for full speed.

On a Mac, macOS will not hand all of memory to the GPU. It keeps a share for itself and your apps.

On a 16 GB machine, plan on about 11 GB for the model. On a 64 GB machine, plan on about 48 GB. Is a Mac good for local AI? and Which NVIDIA card should I get? cover each platform in detail.

The rule of thumb

Rule of thumb

At 4-bit, a model needs about 0.6 GB per billion parameters. At 8-bit, it needs about 1.1 GB per billion parameters. Then add the context and leave room for everything else.

The weightsWeightsThe full set of a model's parameters, stored in a file.Read more are the big part, and the rule covers them. Two more items sit on top.

The context is the second item. The runtimeRuntimeThe software that loads a model file and runs it.Read more stores every token of the conversation in the KV cacheKV cacheSaved work from earlier tokens, so the model does not reread the whole conversation for every new token.Read more, and that grows as the chat gets longer.

For a small model with an 8K context it is about 1 GB. For an agent with a 64K context on a mid-size model it can be several GB. How much can the model keep in mind? shows how to estimate it.

Headroom is the third, because the operating system, your browser and the runtime itself all need memory. On a GPU, leave about 1 to 2 GB free. On a Mac or a CPU-only machine, everything you have open competes with the model.

Worked examples

ModelWeights at 4-bitPlus 8K contextFits on
8Babout 5 GBabout 6 GBA 16 GB laptop, with room
27Babout 16 GBabout 18 GBA 24 GB GPU, or a 32 GB Mac
70Babout 42 GBabout 45 GBA 64 GB Mac, just. Not one consumer GPU

These are rough. The real file size is on the download page, and that number beats any rule.

The catch

"Fits" and "fits with a useful context" are different things. A 27B model on a 24 GB card loads fine, then runs out of room once an agent pushes the context past 32K. Size for the context you will actually use, not the one the runtime starts with.

What happens when it does not fit

There are three outcomes, and each is worse than picking a smaller model.

Swapping

On a Mac or a CPU-only machine, the operating system starts moving memory to disk. The model still loads, then every token waits on the SSD, and output drops to a word every few seconds. The whole computer gets sluggish with it.

Partial offload

On a PC with a graphics card, runtimes such as llama.cpp, Ollama and LM Studio can put some layers on the GPU and the rest in system RAM. The model runs, but at the speed of the slowest part. With a third of the model on the CPU, expect most of the GPU's speed advantage to disappear.

A crash

Sometimes the runtime just fails. It reports an out-of-memory error, the model unloads mid-answer, or the app closes. This often happens late, when the context grows past what the first load left room for. Why won't it load? lists the fixes.

Try it

Load a model, then check how much memory it really takes. On a Mac, open Activity Monitor and look at the Memory tab. On a PC with an NVIDIA card, run this in a terminal.

shell
nvidia-smi

The memory column shows what the model and its cache use on the card. Compare it with the file size you downloaded.

Go deeperThat's enough

Why the rule says 0.6 and not 0.5

Four bits is half a byte, so a 4-bit model should be 0.5 GB per billion parametersParameterOne learned number inside a model. An 8B model has about eight billion of them.Read more. Real files are larger.

Each block of weights stores a scale alongside it, and a few sensitive layers are kept at higher precision. That adds up to about 4.5 to 5 bits per weight on average.

The 8-bit rule is over 1.0 for the same reason. What is quantization? explains the block scheme.

Raising the Mac GPU limit

macOS caps how much unified memory the GPU can wire down. Advanced users raise it with a sysctl setting called iogpu.wired_limit_mb. The setting resets on reboot, and pushing it too high starves macOS and freezes the machine.

Mixture of experts and memory

A mixture of experts model only runs part of itself per token, but it still needs all of itself in memory. Size it by total parameters, not active ones. Some runtimes can keep the rarely used experts in system RAM on a PC, which trades speed for fit more gently than ordinary partial offloadOffloadRunning part of a model on the CPU because it does not fit in VRAM.Read more.