New Tool Radar

AI Concepts

How to Check Whether a Quantized Model Fits in CPU RAM

Check whether a quantized model fits in CPU RAM by adding the file size and the context cache before you load it.

Schematic illustration of check whether a quantized model fits in cpu ram: step one add the file size, step two add the context cache, step three compare with free ram.

A quantized model that fits on disk may still not fit in memory, because running it needs the file plus the KV cache for the context, plus a little overhead. On a CPU-only machine the check is simple addition: file size plus cache, compared with free RAM. Do the addition before loading the model, not after it fails.

Prerequisites

  • The quantized file size, from the file itself.
  • The context length you plan to use, in tokens.
  • The free RAM on the machine, from the system monitor.

Steps

Step 1: Add the file size

Note the file size: an 8B model at Q4_K_M is 4.58 GiB. That memory is needed in full once the model is loaded.

Step 2: Add the context cache

Estimate the KV cache for your context length. As a planning figure, allow about 2 GiB for a 4096-token context on an 8B model; longer context needs proportionally more. Add it to the file size.

Step 3: Compare with free RAM

Compare the sum with the free RAM. If the sum is below the free RAM, the model should load; if it is above, choose a smaller quant, a shorter context, or a smaller model.

Worked example: Bluebell Bakery 8 GiB laptop

The fictional Bluebell Bakery wants to run an 8B Q4_K_M model with a 4096-token context on a laptop with 8 GiB of free RAM.

Item Memory Running total
Model file Q4_K_M 4.58 GiB 4.58 GiB
KV cache, 4096 tokens About 2 GiB About 6.58 GiB
Free RAM 8 GiB Headroom about 1.4 GiB

The file plus the cache is about 6.58 GiB, under the 8 GiB of free RAM, so the model should load with about 1.4 GiB to spare.

Expected result. You have a written sum of file size plus cache against free RAM, and the decision follows from it. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.

Limits

  • The cache estimate is approximate; the exact figure depends on the model and the runtime.
  • Overhead for the runtime itself is not in the sum; keep at least 1 GiB of headroom.
  • This guide does not cover GPU VRAM, which needs the same addition with VRAM figures.

Sources

See all