Bottom line: You can compute a defensible cost-per-token figure for local inference from four inputs — parameter count, quantisation bits, context length, and measured wall-clock throughput divided by measured GPU power draw — and the result usually shows that VRAM capacity, not compute, is the binding constraint.

The arithmetic is not hard. What makes it hard is that most people measure the wrong things: they quote peak FLOPS instead of tokens/sec, they use the card’s TDP instead of its actual draw under inference load, and they forget that the KV cache grows linearly with context and can rival the weights themselves. Below is the model I use, the commands I run to populate it, and the numbers I get on the hardware I have access to.

The memory model: weights plus KV cache plus overhead

Weights are the easy part. A model loaded in bf16 takes 2 bytes per parameter; an 8B model needs roughly 16 GB for its weights alone, about 8 GB at 8 bits, and about 4–5 GB at 4 bits. That is straight from the Transformers quantisation documentation and it matches what I see in practice, with a small allowance for embedding and output-layer padding.

The formula:

1
2
3
weights_GB  = params_B * bits / 8
kv_cache_GB = 2 * layers * kv_heads * head_dim * ctx_len * bytes_per_elem / 1e9
total_GB = weights_GB + kv_cache_GB + overhead_GB

The 2 in the KV formula is for key and value. kv_heads * head_dim is the KV width per layer — for grouped-query models this is much smaller than the attention width, which is why modern architectures are cheap to run at long context. bytes_per_elem is 2 for fp16 KV cache, 1 for q8_0.

A worked example: a 70B model at 4 bits is 70 * 4 / 8 = 35 GB of weights. With 80 layers, 8 KV heads, head_dim 128, at 8192 context in fp16: 2 * 80 * 8 * 128 * 8192 * 2 / 1e9 ≈ 2.7 GB. Total around 38 GB, so it fits on a 48 GB card with room for the compute buffer, but not on two 24 GB cards unless you shard.

Sizing table across common configurations

These are the VRAM floors I plan against, with a 2 GB overhead allowance for CUDA context, compute buffers and fragmentation. Treat them as minimums, not targets.

Model Quant Weights (GB) KV @ 4K (GB) KV @ 32K (GB) Min VRAM @ 4K Min VRAM @ 32K
8B bf16 16.0 1.0 8.0 19 26
8B q8_0 8.5 0.5 4.0 11 15
8B q4_K_M 4.9 0.5 4.0 8 11
32B q4_K_M 19.5 1.5 12.0 23 34
70B q4_K_M 39.5 2.7 21.6 44 63
70B q8_0 74.0 2.7 21.6 79 98

The 32K column is where people get surprised. A 70B at q4 fits comfortably on a 48 GB card at short context and does not fit at all at 32K unless you quantise the KV cache. --cache-type-k q8_0 --cache-type-v q8_0 halves the KV term and buys you the headroom.

Measuring throughput honestly

Do not trust tokens/sec from a single short prompt. Prefill and decode have completely different cost profiles, and a benchmark that generates 20 tokens is measuring prefill plus a warmup. Use llama-bench, which is part of the llama.cpp tree and separates prompt processing from token generation:

1
2
3
llama-bench -m ./Qwen3.5-32B-Q4_K_M.gguf \
-p 512 -n 128 -r 5 -fa 1 \
-t 8 -ngl 99

-p 512 sets prompt length, -n 128 sets generation length, -r 5 repeats five times and reports the mean with standard deviation, -fa 1 enables flash attention (which materially changes long-context memory), -ngl 99 offloads all layers. Run it twice: once cold and once after the model is resident, because the first run includes page-cache misses on the GGUF file.

For a real serving workload, measure end-to-end through the server instead:

1
2
3
4
5
6
7
8
9
10
llama serve -m ./Qwen3.5-32B-Q4_K_M.gguf \
--host 0.0.0.0 --port 8080 \
-c 16384 -ngl 99 -fa on \
--cache-type-k q8_0 --cache-type-v q8_0 &

for i in $(seq 1 20); do
curl -s http://localhost:8080/completion \
-d '{"prompt":"Explain TCP slow start in 200 words.","n_predict":200,"temperature":0}' \
| jq -r '.timings.predicted_per_second'
done | awk '{s+=$1; n++} END {printf "mean tok/s: %.2f\n", s/n}'

The server returns a timings object with prompt_per_second and predicted_per_second. Average the latter across runs; the variance between runs on a single card is typically 3–8%, and much higher if anything else is touching the GPU.

Measuring actual power draw

TDP is a marketing number. What you want is the board power reported by NVML during the generation phase, sampled frequently enough to catch the steady state. nvidia-smi wraps NVML and is sufficient:

1
2
3
4
5
6
7
8
9
10
# Sample power every 200 ms while a generation runs
nvidia-smi --query-gpu=timestamp,power.draw,utilization.gpu,memory.used \
--format=csv,noheader,nounits -lms 200 > power.csv &
SMI_PID=$!

curl -s http://localhost:8080/completion \
-d '{"prompt":"Write 800 words on B-tree internals.","n_predict":800,"temperature":0}' > /dev/null

kill $SMI_PID
awk -F', ' '{s+=$2; n++} END {printf "mean draw: %.1f W over %d samples\n", s/n, n}' power.csv

Discard the first and last few samples — they capture idle-to-load and load-to-idle transitions. For a 350 W card doing decode-only work, I typically see 60–75% of TDP sustained, because decode is memory-bandwidth-bound and the SMs sit partly idle. Prefill-heavy workloads push closer to TDP. This matters: if you use TDP in your cost calculation you will overstate energy cost by 25–40% for chat-style workloads.

For multi-GPU, sum power.draw across devices. For datacenter parts with NVLink, remember that the interconnect draws power too and is not always attributed to the GPU’s own sensor.

The cost-per-token formula

Three variants, in increasing order of usefulness.

Energy cost per token, ignoring amortisation:

1
cost_per_token = (mean_watts / 1000) * (1 / tokens_per_sec) * price_per_kWh

At 250 W, 40 tok/s, and $0.15/kWh: 0.25 * 0.025 * 0.15 = $0.00094 per token, or about $0.94 per million tokens. That is the marginal energy cost and it is almost always small.

Amortised hardware cost per token, which is what actually dominates for a homelab:

1
hw_cost_per_token = gpu_price / (lifetime_hours * 3600 * tokens_per_sec)

A $2000 card at 40 tok/s over 3 years of continuous operation (26,280 hours) gives 2000 / (26280 * 3600 * 40) ≈ $0.00000053 per token — five hundredths of a cent per million. But nobody runs a homelab card continuously at full load. At 4 hours of real load per day, the same card yields roughly 6× that figure. The honest number depends entirely on your duty cycle, and you should state it explicitly.

Combined:

1
total_per_token = energy_per_token + hw_cost_per_token + (idle_watts/1000 * price_per_kWh / tokens_per_day)

That last term is the one people forget. An idle GPU drawing 20–30 W costs more per day than the tokens it produces, if it produces few.

Card VRAM Typical decode (32B q4) Sustained draw Energy $/Mtok @ $0.15/kWh
Consumer 16 GB 16 18–24 tok/s 180–220 W $1.90–$2.50
Consumer 24 GB 24 22–30 tok/s 250–300 W $1.40–$2.10
Prosumer 48 GB 48 30–40 tok/s 280–340 W $1.05–$1.70
Datacenter 80 GB 80 45–60 tok/s 350–450 W $0.95–$1.50

The datacenter card wins on energy per token but loses badly on amortised hardware cost unless duty cycle is high. For a homelab running a few hours a day, the 24 GB consumer card is usually the sweet spot — it fits most 32B q4 models at moderate context and the idle draw is low.

Pitfalls and how to diagnose them

VRAM exhaustion mid-generation. The model loads, the first few hundred tokens work, then it dies. Cause: KV cache growth past the allocation. Diagnose with nvidia-smi --query-gpu=memory.used --format=csv -lms 500 running alongside; you will see memory climb monotonically until the OOM. Fix by lowering -c or quantising the KV cache.

Throughput collapse at long context. Tokens/sec drops sharply past a certain context length. This is usually attention quadratic cost plus KV cache spilling out of L2. Check with llama-bench -p 4096 -n 128 versus -p 512 -n 128; a 3× or worse drop indicates you need flash attention enabled or a smaller KV quantisation.

Power draw pinned at TDP with low throughput. Something is compute-bound that should not be — often a CPU-side bottleneck in the sampling loop, or an offload split that has layers on CPU. Check -ngl actually covers all layers by looking at the server startup log; it prints how many layers were offloaded.

Measured power far below expectation. On laptops and some consumer cards, power.draw reads low because the sensor is on the board, not the die, or because the driver is power-capping. Cross-check with nvidia-smi -q -d POWER for the enforced limit versus the default limit.

Tokens/sec varies wildly between runs. Thermal throttling, other processes on the GPU, or the model being re-read from disk. Run nvidia-smi --query-gpu=clocks_throttle_reasons.active --format=csv after a long run; if it reports SW Power Cap or HW Thermal Slowdown, your sustained figure is lower than your burst figure and you should use the sustained one.

Cost per token looks implausibly good. You probably divided by prefill throughput. Prefill can be 10–50× faster than decode. Always separate the two.

FAQ

Why does my 8B model at 4 bits use more than 5 GB of VRAM?

The weights are about 4–5 GB, but CUDA context, the compute buffer, and the KV cache add several gigabytes on top. At 8K context with fp16 KV you can easily add 2–3 GB. Measure with nvidia-smi after load and before the first token to isolate the static footprint.

Should I use TDP or measured power for the cost calculation?

Measured power, always. Decode workloads are memory-bandwidth-bound and typically sustain 60–75% of TDP. Using TDP overstates energy cost by a quarter to a third for chat-style traffic, and the error compounds across a fleet.

Does quantising the KV cache change output quality?

Yes, slightly, and the effect grows with context length. q8_0 KV is close to lossless in my testing; q4 KV is noticeably worse past 8K context. If you need the memory, try q8_0 first and only drop to q4 if you must.

How do I compare a consumer card against a datacenter card fairly?

Compute cost per million tokens at a stated duty cycle, including idle draw, and state the amortisation period. A datacenter card wins on energy per token but only wins on total cost if you run it hard. Publish the duty cycle assumption alongside the number or the comparison is meaningless.

Why is my prefill throughput so much higher than decode?

Prefill processes all prompt tokens in parallel and saturates the compute units; decode generates one token at a time and is limited by memory bandwidth reading the weights. That asymmetry is inherent to the architecture, not a configuration problem.

Can I run a 70B model at q4 on two 24 GB cards?

Yes, with tensor or layer sharding, provided the combined VRAM covers weights plus KV plus per-GPU overhead. At 4K context you need roughly 44 GB total, which fits across 48 GB with little margin. At 32K context you will need KV quantisation or a third card.