MadWeightsOpen weights research. The Raw Uncut.
TUTORIAL ·

Choose a GGUF quant that fits your VRAM and RAM

At the end of this you will be able to look at a list of GGUF files and say which one your machine can run, where its parts will live, and how much quality you are giving up. It is for anyone choosing a download for a GPU, a few GPUs, or a CPU with plenty of RAM. The arithmetic is simple. The traps are the KV cache, mixture-of-experts models, and fidelity claims taken on trust.

Requirements: Any NVIDIA GPU or a CPU with plenty of RAM · Linux, Windows or macOS · nvidia-smi and free (or your OS equivalents) · a GGUF engine such as a current llama.cpp release

Requirements

  • The model's parameter count, from its model card.
  • The file sizes listed on the GGUF repository you are downloading from.
  • Your VRAM per card and your free RAM, measured with no model loaded (nvidia-smi and free -g).
  • The maker's quant comparison page, if it publishes one.

Steps

1. Read the quant name

The names describe how many bits each weight gets, on average.

  • Q8_0: 8-bit weights with a scale per block. In practice very close to full precision.
  • Q6_K, Q5_K_M, Q4_K_M: "K-quants" at about 6, 5 and 4 bits. The _M (medium) and _S (small) suffixes say how many sensitive tensors keep a higher precision.
  • IQ4_XS, IQ3_XXS, IQ2_XXS and similar: "I-quants", usually made with an importance matrix, data that says which weights matter most. They suit the low end.
  • UD-Q4_K_XL and other "UD" files: Unsloth's dynamic quants. Unsloth says it chooses the quant type per layer and calibrates with its own data (Unsloth Dynamic page). The name gives the typical type; the real average can be well above it.

The llama.cpp quantize README lists measured bits per weight for Llama-3.1-8B: Q4_K_M 4.89, Q5_K_M 5.70, Q6_K 6.56, Q8_0 8.50, IQ4_XS 4.46, IQ3_XXS 3.25. They vary a little by model but are right for estimates.

2. Estimate the file size

File size in bytes is parameters times bits per weight, divided by 8. For a 177-billion-parameter model at 5.0 bits per weight:

177e9 × 5.0 / 8 = 110.6e9 bytes, about 111 GB

The published UD-Q4_K_XL file of such a model is 111.3 GB (Unsloth's model page). At Q8_0's 8.50 bits the same arithmetic gives 188 GB, and Unsloth lists 188.2 GB. At Q6_K's 6.56 bits it gives 145 GB, but Unsloth's UD-Q6_K_XL is 169.2 GB: a dynamic quant keeps more tensors at higher precision, so always check the real size before you plan.

3. Add the KV cache and working space

The weights are not all the memory. The KV cache holds the conversation and grows with context length and the number of request slots. For a standard attention model:

KV bytes = 2 × layers × KV heads × head size × bytes per value × tokens × slots

Take the layer, head and head-size figures from the model's config. For example, 32 layers, 8 KV heads of size 128, a 16-bit cache (2 bytes) and 32,768 tokens in one slot need 2 × 32 × 8 × 128 × 2 × 32,768 bytes, which is 4 GiB. Double the context and it doubles. Hybrid models with recurrent layers need less, because only some layers keep a cache. Leave room for the engine's own compute buffers as well; engines differ here, so keep a few GB per card spare until you have measured.

4. Decide what must sit in VRAM

A dense model requires every weight for every token. The CPU reads whatever sits in RAM on every token, or the bus transfers it, and generation slows to that pace. Aim to fit the whole file plus the KV cache in VRAM. If it will not fit, a smaller quant fully on the GPU usually beats a larger one split with RAM.

A mixture-of-experts model uses only a few experts for each token. The engine needs the shared parts, such as attention, embeddings and the output head, every time, and they belong in VRAM. The engine can split the experts: as many as fit on the cards, the rest in RAM. That is why an MoE file larger than your VRAM can still run at a useful speed, and why "what fits" depends on how the engine places the experts. In llama.cpp, --cpu-moe and --n-cpu-moe control this (see our expert offload tutorial).

As one example, our server has 96 GB of VRAM and 144 GB of RAM and runs the 111 GB 4-bit file of a 177B MoE model: the parts needed on every token fit on the cards, and our server splits the experts between VRAM and RAM (where the time goes).

5. Check the fidelity claim

Makers that measure their quants publish how far the quant's next-token probabilities are from a reference: mean KL divergence (lower is better) and the share of positions where the top token matches (higher is better). Unsloth's table for Qwen3.8-Flash-Next, from its model page:

QuantSizeTop-1 agreementMean KL
UD-IQ4_XS93.7 GB89.554%0.083630
UD-Q4_K_XL111.3 GB92.255%0.046893
UD-Q5_K_XL158.3 GB93.680%0.030415
UD-Q6_K_XL169.2 GB94.089%0.027091
Q8_0188.2 GB94.122%0.026574

Make three checks before you trust a table like this. Find out what the reference was; that page does not say. Compare the gaps with the noise between engines: two engines reading the same 4-bit file had a mean KL of 0.066 between them in our comparison, larger than the gap between the Q5 and Q8 rows. And run one public benchmark yourself on the quant you choose.

Check it worked

Load the model and read the engine's start-up log. In llama.cpp, the lines ending in model buffer size = ... MiB show how much of the model sits on each CUDA device and on the CPU; compare them with your plan from step 4. Then run nvidia-smi with a long prompt in flight and check that every card keeps some free memory. If your engine warns that it is reading weights from the model file during use, part of the model is coming from disk, and speed will suffer.

Common problems

  • Load fails with out-of-memory: lower the context or the number of slots before you drop a quant level.
  • Long prompts slow down after you raise the context limit: the larger KV cache pushed weights off the cards. Give the engine more RAM for experts, or lower the context.
  • A larger quant gives worse answers or is much slower: check whether fewer experts now fit on the cards and whether your engine switched on an approximation to compensate.
  • A low-bit quant performs poorly: prefer files made with an importance matrix, which the quantize README says reduces accuracy loss.

Our recommendation

These picks are our judgement, not measurements.

  • A dense model on one 24 GB card: we'd pick the largest of Q4_K_M, Q5_K_M or Q6_K that fits fully on the card with the context you need, and go below 4 bits only to fit a larger model.
  • A dense model with VRAM to spare: Q6_K or Q8_0. Above 6 bits we'd spend memory on context instead.
  • A large MoE model on about 96 GB of VRAM and 144 GB of RAM: the 4-bit dynamic quant. It leaves room for a long context, and on our server it scored in line with the published full-precision MMLU-Pro figure (the run).
  • A large MoE model with about 64 GB in total: a 2-bit or 3-bit dynamic quant of that model before a 4-bit quant of a smaller one, but run a benchmark of your own on it first.

Further reading