Running Small Models Locally: How to Estimate Memory and Choose a GGUF Quantization
A practical guide to running small open-source LLMs (0.5B–10B) on local hardware. Learn how quantization compresses model weights, how to estimate runtime memory including KV cache, how to pick the right GGUF quantization level for your device, and how to convert safetensors checkpoints to GGUF with llama.cpp after cloud fine-tuning.
Introduction: Why Small Models Are Worth Running Locally
Open-source large language models currently split into two camps. One camp consists of massive models with hundreds of billions of parameters — highly capable, but requiring professional GPU clusters. The other camp includes small models in the 1B to 10B range, plus micro-scale models around 0.5B, which can run on consumer PCs and thin-and-light laptops. For everyday developers, researchers, and hobbyists, the latter is far more practical. Running models locally means data never leaves your device, there are no per-call charges, and everything works offline.
The main challenge with local deployment is memory. This article addresses three questions: what quantization actually compresses, how much memory you need, and which quantized version to download. At the end, we’ll also cover how to safely bring a cloud-fine-tuned model down to your local machine.
Why Raw Weights Won’t Run: From FP16 to 4-bit
Large models are typically released with weights stored in safetensors format, using 16-bit floating-point numbers (FP16 or BF16), with each parameter occupying 2 bytes. A 9B model requires roughly 18GB just to load the weights — more than the VRAM of most consumer GPUs, and more than the unified memory of most thin-and-light laptops.
Quantization reduces the number of bits used to store each parameter. After 4-bit quantization, each parameter averages 0.5 to 0.6 bytes, shrinking the weights to roughly a quarter of their original size. Note that “4-bit” is an average — the actual bit widths of individual tensors inside the file vary — so always use the file size listed on the download page as the authoritative number.
“Dynamic Quantization” Means Two Different Things
The term “dynamic quantization” has two common usages in the community, which are easy to confuse.
The first is dynamic quantization in frameworks like PyTorch. Weights are quantized to integers ahead of time, while scaling coefficients for activations are computed at inference time based on actual data. It is mainly used to speed up certain computations and is not the most common compression approach in local LLM inference.
The second is what the community calls “dynamic 4-bit.” This usually refers to mixed-precision quantization, where different network layers use different bit widths. Layers that are more precision-sensitive — such as certain projection layers in the attention mechanism, the output layer, and the embedding layer — retain more bits. Some layers in the feed-forward network are less precision-sensitive and get compressed more aggressively.
In the rest of this article, we’ll use “mixed-precision quantization” to refer to the latter. In the llama.cpp ecosystem, the representative approach is the K-quants family, such as Q4_K_S and Q4_K_M. There is also the IQ family, which incorporates an importance matrix (imatrix). The importance matrix uses a small batch of calibration texts to measure how much each weight influences the output, and allocates quantization error accordingly. IQ variants are typically more stable than standard quantization at very low bit rates, but they place stricter requirements on the inference engine version.
How Much Memory Do You Need: A Table Covering Three Model Tiers
A model’s total runtime memory consists of three parts: the quantized weights, the KV cache (the key-value cache that stores context and grows linearly with context length), and the overhead of the inference framework itself. In other words, the weight file size is not the same as runtime memory.
The table below uses 4-bit mixed-precision variants like Q4_K_M as a reference. All values are estimates, based on these assumptions:
- Inference engine is llama.cpp, single user, single request (batch size 1).
- KV cache is stored in FP16.
- Context length is 4K to 8K.
- Inference framework overhead is roughly 0.5GB to 1GB.
| Model size | ~4-bit weight file | Suggested context | Total runtime memory | Suggested configuration |
|---|---|---|---|---|
| 0.8B to 2B | 0.5GB to 1.5GB | 4K to 8K | ~3GB | Any PC or laptop with 8GB RAM |
| 4B | ~2.5GB | 4K to 8K | 5GB to 6GB | 8GB is tight; 16GB is comfortable |
| 9B | 5GB to 6GB | 4K to 8K | 8GB to 10GB | 16GB RAM, or 12GB+ VRAM |
KV cache size can be estimated with this formula:
KV cache bytes = 2 × number of layers × number of KV heads × head dimension × context length × bytes per element
The factor of 2 accounts for the K and V caches, and each element takes 2 bytes under FP16. For a model with 32 layers, 8 KV heads, and a head dimension of 128, the KV cache is roughly 1GB at 8K context. If the context grows to 32K, the same model’s KV cache grows to about 4GB. For long-document processing, re-estimate using this formula.
When sizing your hardware, leave 20% to 30% memory headroom. The operating system and background programs typically consume 2GB to 4GB, so an 8GB configuration is only suitable for 0.8B to 2B models; for a 4B model, you’ll need to close memory-hungry programs like browser tabs with heavy pages. If you serve multiple requests concurrently, each request requires its own KV cache, so total memory must scale with the level of concurrency.
On mobile, some flagship phones ship with 16GB or more of RAM and can attempt 0.8B to 2B models. Whether they run smoothly depends on the inference backend (CPU acceleration or NPU support) and context length; results vary widely, so test on your own device.
Which Quantization Should You Choose? Decide by Scenario
Choosing a quantization comes down to answering four questions in order: how much memory does your device have, what formats does your inference engine support, how much quality does the task require, and how long a context do you need. Based on that, here are the recommendations.
- Tight memory, device with around 8GB: Prefer Q4_K_S or IQ4_XS. Smaller files, with a slight drop in quality.
- Plenty of memory, for everyday chat, code completion, and text summarization: Choose Q4_K_M. It’s one of the most widely used 4-bit variants in the community, balancing size and quality well.
- Higher quality, device with ample memory (e.g., 32GB or more): Choose Q5_K_M or Q6_K. Larger files, with output quality closer to the original model.
- Long-form creative writing or complex mathematical reasoning, memory permitting: Consider Q8_0. Its precision is clearly better than 4-bit and lower-bit variants, but still not equivalent to FP16. Its size is roughly half of FP16 — and that estimate assumes every layer is stored at 8 bits; the actual file will be slightly larger than half due to scaling coefficients.
- Only older hardware available, and only basic Q&A needed: 2-bit or 3-bit variants are the only viable option. Language repetition, logical leaps, and hallucinations will increase noticeably — not suitable for serious tasks.
Three extra cautions for the IQ family:
- Inference engine version: IQ variants require a recent version of llama.cpp. Older versions will usually throw an unknown-format error on load. Check the model card and the engine release notes for minimum version requirements.
- Calibration text source: When generating the imatrix, choose texts close to your intended use case — for example, general-domain text mixed with code samples. Don’t use your evaluation set for calibration, or your benchmark scores will be artificially inflated.
- Inference speed: On some CPU-only setups, IQ variants may run slower than K-quants. Benchmark on your target device before committing.
Different publishers may name variants differently, and some filenames carry labels like “Dynamic.” Before downloading, check the model card to confirm the quantization method and its inference engine requirements.
Common Mistakes
- Downloading the wrong file: Not verifying the quantization method and engine support, leading to load failures or abnormal speed.
- Ignoring the chat template: If the model’s conversation template doesn’t match the one used at inference, output becomes garbled or generation never stops.
- Setting the context too long: A context length beyond what memory allows triggers out-of-memory (OOM) errors.
- Version mismatch: Using different llama.cpp versions for model conversion and inference; some newer formats fail to load.
How to Convert safetensors to GGUF
GGUF is the file format used by llama.cpp, storing weights, the tokenizer, and the chat template in a single file. Conversion involves three stages: first convert safetensors to an unquantized GGUF, then quantize, then verify. The commands below use the llama.cpp repository as an example; refer to your version’s help output for exact parameters.
Step 1: Prepare the environment
Use a dedicated Python virtual environment. After cloning the llama.cpp source, check out a fixed release tag or commit and record it for reproducibility.
git clone https://github.com/ggml-org/llama.cppcd llama.cppgit checkout <fixed tag or commit>pip install -r requirements.txt
Step 2: Inspect the model directory
Confirm the model directory contains config.json, the tokenizer files, and all safetensors shards. If the model came from cloud fine-tuning, merge the LoRA adapters into the base weights before converting. After merging, the vocabulary size should match the base model, otherwise conversion will fail with a shape mismatch error.
Step 3: Convert to FP16 GGUF
python convert_hf_to_gguf.py /path/to/model --outtype f16 --outfile model-f16.gguf
The resulting file should be roughly twice the parameter count in bytes. For example, a 9B model should be close to 18GB. A file that is noticeably too small usually means incomplete weight shards.
Step 4: Build and quantize
cmake -B buildcmake --build build --config Release./build/bin/llama-quantize model-f16.gguf model-Q4_K_M.gguf Q4_K_M
To produce IQ variants, first generate an importance matrix from calibration text, then pass it in during quantization:
./build/bin/llama-imatrix -m model-f16.gguf -f calib.txt -o imatrix.dat./build/bin/llama-quantize --imatrix imatrix.dat model-f16.gguf model-IQ4_XS.gguf IQ4_XS
Step 5: Verify
- Use sha256sum to compute the hash of each GGUF file and record it in your deployment checklist. Compare hashes after downloading or copying to confirm file integrity. Note that hashes differ across quantization variants — only compare a file against copies of that same file.
- Check the file size. Q4_K_M is typically about a quarter of the FP16 file.
- Run a simple test to confirm the output is normal:
./build/bin/llama-cli -m model-Q4_K_M.gguf -p "Hello, introduce yourself in one sentence."
