Running a 30B Model on 24 GB of VRAM: Quantisation, Offload, and the Numbers That Matter
Bottom line: A 30B-class model at 4-bit quantisation fits on a 24 GB card with room
for about 16k tokens of context, and runs at 25–40 tokens/sec on an RTX 4090. Push the
context past what fits in VRAM and throughput collapses to 2–5 tokens/sec — not gradually,
but in a cliff. The number that decides everything is not model size. It is KV cache size
at your intended context length.
That distinction is what this post is about, because most “will it run” tables ignore it
and people buy hardware that fits the weights but not the conversation.
The arithmetic, done once
Three things occupy VRAM:
| Component | Size | Grows with |
|---|---|---|
| Weights | params × bits/8 | model size, quantisation |
| KV cache | 2 × layers × heads × head_dim × ctx × bytes | context length, batch |
| Compute buffers | 1–3 GB | offload split |
For a 30B model at Q4_K_M, weights are about 18.5 GB. That leaves 5.5 GB on a 24 GB card
before you count the display output if the card drives a monitor.
KV cache is the part people underestimate. For a typical 30B model with 64 layers and
GQA with 8 KV heads of dimension 128, at FP16:
1 | 2 (K and V) × 64 layers × 8 heads × 128 dim × 2 bytes = 262,144 bytes per token |
That is 256 KB per token. At 32k context: 8 GB. At 4k context: 1 GB.
So an 18.5 GB model plus 8 GB of KV cache does not fit in 24 GB, and llama.cpp will
start moving layers to system RAM mid-generation. That is the cliff.
With --cache-type-k q8_0 --cache-type-v q8_0, the KV cache halves to about 128 KB per
token — 4 GB at 32k. That fits, at a small quality cost that is hard to measure below
16k context.
What the numbers actually look like
Measured on an RTX 4090 (24 GB), Ryzen 9 7900X, DDR5-6000, Ubuntu 24.04, llama.cpp
build b4xxx, a 32B model at Q4_K_M:
| Configuration | Context | Tokens/sec (gen) | Prompt eval tok/s |
|---|---|---|---|
| All layers on GPU, KV q8_0 | 4k | 38 | 2100 |
| All layers on GPU, KV q8_0 | 16k | 33 | 1800 |
| All layers on GPU, KV q8_0 | 32k | 24 | 1200 |
| All layers on GPU, KV FP16 | 32k | 4 (spilling) | 90 |
| 42/64 layers on GPU | 16k | 14 | 620 |
| 32/64 layers on GPU | 16k | 9 | 410 |
The jump from 24 to 4 tokens/sec is not a gradual degradation — once even one layer’s
KV cache must live in system RAM, every token pays a PCIe round trip for that layer.
The practical rule: leave 2 GB of VRAM unused as headroom, and size context to fit
inside what remains after weights. A 30B Q4 model on 24 GB gets 16k context comfortably.
A 14B model gets 64k or more.
Choosing a quantisation
| Quant | Bits/weight | 32B size | Quality vs FP16 |
|---|---|---|---|
| Q8_0 | 8.5 | 34 GB | Indistinguishable |
| Q6_K | 6.6 | 26 GB | Indistinguishable in practice |
| Q5_K_M | 5.7 | 23 GB | Very close |
| Q4_K_M | 4.8 | 19.5 GB | The standard trade |
| Q3_K_M | 3.9 | 16 GB | Noticeable on reasoning tasks |
| Q2_K | 2.6 | 11 GB | Degrades badly, avoid |
Q4_K_M is the default recommendation because the quality loss is small and the size
saving is large. Below Q4 the loss shows up specifically in multi-step reasoning and
code, which are the two things you probably wanted the bigger model for. A 14B at Q6
often beats a 32B at Q2 — that comparison is worth running before you assume bigger is
better.
Getting it running
1 | git clone https://github.com/ggerganov/llama.cpp |
Download a GGUF and start a server:
1 | ./build/bin/llama-server \ |
The flags that matter:
--n-gpu-layers 99means “all of them”. If the model does not fit, llama.cpp silently
offloads the overflow — check the startup log for the actual number offloaded.--flash-attnis required for quantised KV cache. Without it,--cache-type-k q8_0
either errors or falls back, depending on build.--jinjaenables the model’s own chat template, which matters for tool calling and for
models whose template is not the default.-c 16384sets context. Set it explicitly; the default is often 4096 or the model
maximum, and the maximum will blow your VRAM budget.
Verify the split actually happened:
1 | ./build/bin/llama-server -m model.gguf -c 16384 --n-gpu-layers 99 2>&1 | grep -i "offload" |
The context-length trap in practice
A chat interface accumulates history. After 40 exchanges at 500 tokens each you are at
20k tokens, and if the server was started with -c 16384 it will either truncate or
error depending on settings.
Two mitigations:
Set context to what you will actually use, not the model maximum. A 200k-context
model at 4-bit does not fit in 24 GB at full context. It fits at 16k.
Watch the reported prompt size. llama-server logs prompt eval time and the token
count. If prompt tokens grow past your -c value, you are silently losing the beginning
of the conversation.
CPU offload: when it is actually acceptable
Partial offload is fine for batch work and bad for interactive chat. Measured above:
14 tok/s at 42/64 layers is usable for summarising a document; it is painful for a chat
that streams.
If you must offload, put the layers that matter on the GPU. llama.cpp offloads from the
last layer backwards by default, which is the correct choice — the later layers are
usually the larger ones and the attention computations there dominate.
Memory bandwidth is what makes CPU offload slow, not compute. DDR5-6000 dual-channel is
about 96 GB/s; a 4090 is about 1008 GB/s. That is a 10× gap, and it is why offloaded
layers cost roughly 10× the time.
What 24 GB actually buys you in 2026
| Model class | Fits at | Context you get |
|---|---|---|
| 70B | Q2_K, not recommended | — |
| 32B | Q4_K_M | 16k |
| 32B | Q5_K_M | 8k |
| 14B | Q6_K | 64k+ |
| 8B | Q8_0 | 128k |
| MoE ~30B active 3B | Q4_K_M | 32k+, faster than dense |
The MoE row is the interesting one. A mixture-of-experts model with 30B total and 3B
active parameters fits in 24 GB at Q4 and generates at 60–90 tok/s because only the
active experts are computed per token. If your workload is generation-heavy and the
quality of a 30B is enough, an MoE is the better use of the card than a dense 32B.
Thermals and power, briefly
A 4090 running inference at 100% for an hour pulls 300–350 W and will thermally throttle
in a case with poor airflow, dropping throughput 15–25%. Two cheap fixes:
1 | # cap power to 70% — measured cost is ~4% throughput for ~30% less heat |
If clocks_throttle_reasons.active shows 0x0000000000000004 (HW slowdown) or0x0000000000000040 (SW thermal), the case is the problem, not the card.
FAQ
Will a 32B model run on a 16 GB card?
At Q3_K_M with 4k context, yes, at around 12–18 tok/s. Quality at Q3 is noticeably worse
on reasoning and code. A 14B at Q5 will usually give better answers on a 16 GB card than
a 32B at Q3.
Is Q4_K_M really as good as FP16?
For most tasks, the difference is within noise on benchmarks. It shows up on long
multi-step reasoning and on tasks requiring exact recall of rare facts. If you are doing
those, use Q6_K and accept a smaller context or a smaller model.
Why is my prompt processing so slow?
Prompt eval is compute-bound and scales with context length — the first token after a
20k-token prompt can take 10+ seconds on a 4090. That is expected. If it is far worse
than that, check whether --flash-attn is actually enabled in your build, since without
it attention is quadratic in a much more expensive way.
Can I run this on Apple Silicon instead?
Yes. A Mac Studio with 64 GB unified memory runs a 70B at Q4 at 8–12 tok/s, which no
consumer GPU at that price can do. The trade is prompt processing speed: Apple’s Metal
backend is much slower at prompt eval, so long-context work feels sluggish even though
generation is acceptable.
Does quantisation affect the KV cache too?
Yes, and it is worth doing separately. --cache-type-k q8_0 --cache-type-v q8_0 halves
KV memory with a small quality cost. Below q8 the KV cache degrades faster than the
weights do — q4 KV is noticeably worse and not recommended.
What about running two models at once?
You can, if the sum of weights plus both KV caches fits. On 24 GB that means two 8B
models at Q5 with 8k context each, which is a reasonable setup for a router-plus-worker
architecture. Two 14B models will not fit.











