Sub topic 5
Estimating the Memory for Weights
This chapter assumes you know what a parameter count is, that quantisation stores each weight in fewer bits, and how bytes, bits and GB relate. Here you turn those facts into a number: how much memory the weights need.
The formula
Each parameter is one number. The memory for the weights is the parameter count times the bits stored per weight, divided by 8 to get bytes.
bytes = parameters × bits_per_weight / 8Divide by 2^30 to get GiB (the unit most tools report) or by 10^9 to get GB. The two differ by about 7%, so check which one a tool uses.
Worked example
An 8B model at different precisions:
| Format | Bits per weight | Weights size |
|---|---|---|
| FP16 / BF16 | 16 | about 14.9 GiB |
| 8-bit (Q8_0) | about 8.5 | about 7.9 GiB |
| Q4_K_M | about 4.85 | about 4.5 GiB |
Quantised formats store a little more than their nominal bits. Block scales and a few higher-precision tensors add overhead, which is why Q4KM is about 4.85 bits and not 4.
Compute it in code
def weights_gib(params_billion, bits_per_weight):
return params_billion * 1e9 * bits_per_weight / 8 / 2**30
for name, bits in [("FP16", 16), ("Q8_0", 8.5), ("Q4_K_M", 4.85)]:
print(f"{name:7} {weights_gib(8.0, bits):5.1f} GiB")The output is 14.9, 7.9 and 4.5 GiB, matching the table.
Shortcuts and checks
- At 16 bits, GB of weights is about 2 × billions of parameters.
- At about 4.85 bits, it is about 0.6 × billions of parameters.
- A GGUF file on disk is close to the weights in memory. If the file is 4.9 GB, expect about that much for weights.
Use the file size when you have it. It already includes the real per-tensor mix of formats, so it beats your estimate.
Common errors
- Confusing bits and bytes. Forgetting the division by 8 gives an answer 8 times too large.
- Using the nominal bit count. Treating Q4KM as exactly 4 bits underestimates by about 20%.
- Mixing GB and GiB. A 24 GB card holds 24 × 10^9 bytes, which is about 22.4 GiB, before any other use.
- Stopping at weights. The weights are only one part of the total. The KV cache, covered in the next chapters, and runtime buffers come on top.
Exercise
Exercise
A 70B-parameter model is stored at about 4.85 bits per weight. Roughly how many GiB do the weights need, and would they fit on a 24 GB GPU?
Show answer
70 × 10^9 × 4.85 / 8 = about 4.24 × 10^10 bytes, which is about 39.5 GiB. This does not fit in a 24 GB GPU (about 22.4 GiB), even before adding the KV cache. You would need more memory, a smaller or lower-bit model, or a split between GPU and system RAM.
Exercise
A tool reports a model file of 4.9 GB. You estimated 4.5 GiB from the formula. Are the two consistent?
Show answer
Yes. 4.9 GB is 4.9 × 10^9 bytes, which is about 4.56 GiB. The small remaining gap comes from tensors stored at higher precision and file metadata.