Sub topic 7
Picking a model that fits your hardware: parameters and quantization
This chapter assumes you can pull and run a model with Ollama and that you know what a model tag is. You will learn how to estimate whether a model fits in your memory before you download it.
Two numbers decide the size
A model file is mostly a long list of numbers called weights. Two things set its size on disk and in memory:
- Parameter count. The number of weights, written as 1B, 3B, 8B, 70B and so on (billions). More parameters usually means better answers and more memory.
- Quantization. A method that stores each weight with fewer bits. A full-precision weight takes 16 bits. A 4-bit weight takes a quarter of that, with a small loss in quality.
A rough size estimate is:
size in GB ≈ parameters in billions × bits per weight ÷ 8An 8B model at 4 bits is about 8 × 4 ÷ 8 = 4 GB. At 16 bits it is about 16 GB. Real files run a little larger, because some layers are kept at higher precision and the file includes metadata.
Reading quantization names
Tags in the library often end with a label such as q4_K_M or q8_0.
| Label | Approx. bits per weight | Trade-off |
|---|---|---|
| q2_K | 2-3 | Smallest. Quality drops noticeably. |
| q4_K_M | about 4.5 | Common default. Good balance of size and quality. |
| q5_K_M | about 5.5 | Slightly better quality, slightly larger. |
| q8_0 | 8 | Close to full quality, about twice the size of q4. |
| fp16 | 16 | Full precision. Largest. |
Start with q4 variants. Move up only if you have spare memory and see quality problems.
Leave room for more than the weights
The weights are not the only thing in memory. The context window needs space too, in a structure called the KV cache. A larger num_ctx uses more memory, and the cost grows as you raise it. Add about 1-2 GB of headroom for a 4096-token context on a small model, and more for long contexts.
The operating system and other programs also need memory. As a guide, keep the model file under about 70-80% of the memory available to it.
Which memory counts
- Dedicated GPU: the model runs fastest when it fits entirely in video memory (VRAM). If it does not fit, Ollama puts some layers on the GPU and the rest on the CPU. That works, but it is much slower.
- CPU only: the model lives in system RAM. It runs, but expect low speed on large models.
- Apple silicon: the CPU and GPU share unified memory, so total RAM is the limit, and the system keeps part of it for itself.
Check what actually happened
After loading a model, run:
ollama psThe PROCESSOR column shows where the model is running, for example 100% GPU or 35%/65% CPU/GPU. A split means the model did not fully fit. Pick a smaller model or a lower quantization.
Exercise
You have a GPU with 8 GB of VRAM. Using the size formula, is a 13B model at q4 (about 4.5 bits per weight) a good fit? What would you try instead?
Show answer
13 × 4.5 ÷ 8 ≈ 7.3 GB. That is over 90% of the VRAM and leaves almost nothing for the KV cache, so some layers will spill to the CPU and the model will be slow. Try an 8B model at q4 (about 4.5 GB), or a 7B-8B model at q5KM. Confirm with ollama ps that the processor column shows 100% GPU.