Skip to content

Performance tuning

Throughput on a streaming engine is a balance: the more layers stay resident, the less streaming has to hide under compute. These are the levers, from biggest effect to smallest.

The levers

LeverEffect
--quant int4 | int8Shrinks each layer 2–4x at load, so more of the model stays resident and streaming shrinks or stops entirely — worth far more than making streaming itself faster. On a 4 GB GTX 1650, Qwen2.5-1.5B goes from 21–27 tok/s streaming bf16 to 79–87 tok/s fully resident at int4. See Quantization.
--stream vs --gpu-layers NTwo ways to run a model too big for the card. --stream moves every non-resident layer over PCIe each token; --gpu-layers N keeps the first N layers in VRAM and runs the rest on the CPU, where their weights already sit. On a GTX 1650, Qwen2.5-7B-Instruct Q3_K_M decodes at 7.6–8.4 tok/s streamed against 2.8–3.0 with --gpu-layers 19, and --gpu-layers prefills slower (the CPU half runs a prompt token by token). So on the GPU a model whose weights don’t fit streams on its own. A machine whose RAM computes faster than PCIe copies can come out the other way — measure both with dlm bench.
--resident-layersMore resident layers → fewer streaming passes → closer to the compute ceiling. Fewer → fits a bigger model. Start at the profiler's plan.
NVMe + PCIeA warm host-RAM cache skips the disk read; a faster PCIe generation drains the streaming window quicker. Both raise the tok/s floor.
--prefetch-depthCPU streaming: load the next N layers while the current one computes, hiding load latency under the math. --auto-prefetch tunes the depth to your disk. On the GPU the worker always loads the next missing layer, so neither flag applies. Watch dlm_stream_layer_misses_total on /metrics.
--speculativeOn by default where verifying a few tokens costs about one step: on the GPU, and on a CPU model streamed from disk. With no draft model, n-gram lookup proposes what followed the last time the context’s latest tokens occurred, and the model verifies the proposals in one pass. Output is unchanged. GTX 1650, batch 1, Qwen2.5-0.5B Q4_K_M greedy: 111 → 358 tok/s — on a bench prompt that repeats, its best case. Real text proposes less often, and a round whose guesses all miss costs about a third of a step more. A request speculates only while it is the one decoding. --draft-model-path speculates with a draft model or an EAGLE-3 head instead (Qwen3-1.7B int4 with AngelSlim’s head: 78% of single proposals accepted). --speculative mtp uses Qwen3.5/3.6’s own MTP head: Qwen3.6-35B-A3B streamed on a GTX 1650, 1.5–1.6 → 2.1–2.6 tok/s. --speculative off turns it off.
Continuous batching (--max-batch)Concurrent requests share each pass, so aggregate throughput rises even when single-stream tok/s doesn't. Up to --max-batch (default 8) decode at once; on the GPU each holds its own KV, so raise it on a big card.
--prefix-cache-sizeCache prompt prefixes — requests that share a system prompt or a chat's history skip re-prefilling it. On by default on the GPU (64 entries). Big win when many requests share a long prefix.
--context-lengthA longer context spends more of the VRAM budget on the KV cache, leaving fewer layers resident. Shorten it to keep more layers in VRAM.
--kv-quantThe GPU’s KV cache is int8 by default: 56% of fp16’s memory, so 1.76x the tokens in the same VRAM, at fp16’s speed and within 0.005 nats per token of it on the models measured. f16 keeps the fp16 cache, f32 is exact. On the CPU kernels, int8 halves the KV memory and int4 quarters it, with more error. When even one full-context request doesn’t fit beside a resident GPU model, the layers that don’t fit keep their KV in host RAM instead of being refused — slower (Qwen2.5-1.5B Q8_0 at 32k context: 21 tok/s against 49), but it runs.
--ram-cache-gb NA host-RAM cache of materialized layers, so an evicted layer isn't re-read and re-decoded — roughly 2x on the streamed path. On by default with --stream when the whole layer set fits in a quarter of physical RAM (for a streamed MoE model, enough for its experts too, up to that quarter). A smaller cache still pays: every streaming cache evicts the most recently used layer, so one holding a third of the model serves that third each token (Qwen2.5-0.5B, a third cached: 2.5–2.7 → 3.65–3.96 tok/s). Pack a quantized model with dlm pack so a miss reads ready int4/int8 instead of re-quantizing.
--lm-head-int4Hold the GPU's LM head in int4 — a large share of a small model's bytes per token. Qwen2.5-0.5B bf16: batched decode about 9% faster, batch 1 within noise, for +0.025 nats of mean NLL. Opt-in; pays most on a bf16 head.
--stream with --quant keeps the quantized layers in the host-RAM cache by default, since re-quantizing on every window miss measured 12x slower. That default holds only when every layer fits in a quarter of physical RAM; a bigger quantized model re-quantizes on every miss, so raise --ram-cache-gb, pack it once with dlm pack (see Quantization), or drop --stream: once quantized, the model often no longer needs it.

Measure your setup first

Before tuning, run the profiler — it reports how many layers stay resident and the streaming-pass count for your exact card, no weights loaded.

$dlm profile --model-path /path/to/model

Then measure. dlm bench loads the model exactly as serve would with the same flags and reports prefill and decode tok/s per batch size — the way to settle --stream against --gpu-layers, or whether a lever paid on your machine. Save a baseline with --json, and check a later build or setting against it with --compare: it prints each metric’s change and exits non-zero if prefill or decode tok/s fell by more than --tolerance percent (default 5).

$dlm bench --model-path /path/to/model --batch 1,4,8 --json base.json
$dlm bench --model-path /path/to/model --batch 1,4,8 --compare base.json
bench decodes plainly unless given --speculative ngram, so baselines stay comparable. A baseline saved before the int8 KV default needs --kv-quant f16 to compare like with like.
Try the interactive version on the Benchmarks page — change the VRAM and model and watch the resident count and tok/s band update live.

Recipes