llama.cpp Flags Explained (2026): Every Flag That Matters
Most llama.cpp guides copy a command line from a forum post and never say what the flags do. That worked until 2026, when the flag set changed underneath everyone. --no-mmap and --mlock are gone, -ngl defaults to auto instead of 0, and -fa decides for itself. Here is what every flag that matters actually does, which ones buy speed, which ones only buy memory, and which commands on the internet now fail outright.
Bottom Line (2026)
- Three flags changed underneath everyone in 2026.
--no-mmap,--mlockand--direct-iowere folded into-lm, --load-mode(PR #20834, merged 2026-07-23), kept as deprecated aliases, then removed outright in PR #28334. Most command lines published before mid-2026 now fail witherror: invalid argument. -nglnow defaults toauto. The advice to always pass-ngl 99is a workaround for a default that no longer exists.- Separate the memory flags from the speed flags. This is the distinction almost nobody writes down, and it is why people set KV cache quantization expecting a speed-up and measure a slow-down.
- Only two flags reliably buy you speed on a machine that already fits the model:
-faand-ub. Everything else buys you the ability to run the model at all. - Do not copy a
--n-cpu-moevalue. Sweep it. See llama.cpp MoE Offload Flags Explained for the method.
The Flag Table
Flag spellings and defaults below are quoted from the llama-server README on 2026-09-15. Check your own build with llama-server --help; this project moves fast.
| Flag | What it does | Default | Buys you |
|---|---|---|---|
-ngl, --gpu-layers, --n-gpu-layers N | Max layers stored in VRAM. Takes a number, auto, or all | auto | Fit |
-lm, --load-mode MODE | How the model is loaded: auto, none, mmap, mlock, mmap+mlock, dio | auto | Fit |
-fa, --flash-attn [on|off|auto] | Flash Attention | auto | Speed |
--cpu-moe, -cmoe | Keeps all MoE weights in CPU RAM | off | Fit |
--n-cpu-moe N, -ncmoe | Keeps MoE weights of the first N layers in CPU RAM | off | Fit |
-c, --ctx-size N | Prompt context size. 0 reads it from the model | 0 | Fit |
-b, --batch-size N | Logical max batch size | 2048 | Little |
-ub, --ubatch-size N | Physical max batch size — sizes the compute buffers | 512 | Speed / fit |
--cache-type-k TYPE | KV cache type for K: f32, f16, bf16, q8_0, q4_0, q4_1, iq4_nl, q5_0, q5_1 | f16 | Fit |
--cache-type-v TYPE | KV cache type for V | f16 | Fit |
-kvo/-nkvo, --kv-offload/--no-kv-offload | Whether the KV cache lives on the GPU | enabled | Fit |
--swa-full | Use a full-size sliding-window-attention cache | false | Fit |
-np, --parallel N | Number of server slots (concurrent requests) | -1 (auto) | Throughput |
-sm, --split-mode {none,layer,row,tensor} | How a model splits across several GPUs | layer | Fit |
-ts, --tensor-split N0,N1,... | Fraction of the model sent to each GPU | even | Fit |
-ot, --override-tensor <pattern>=<type> | Per-tensor buffer placement | off | Fit |
-dev, --device <dev1,dev2> | Which devices to offload to | all | Control |
-t, --threads N | CPU threads used during generation | -1 (auto) | Speed on CPU |
--numa TYPE | NUMA optimizations on multi-socket machines | off | Speed on CPU |
-n, --predict N | Tokens to predict. -1 is unlimited | -1 | — |
--jinja / --no-jinja | Jinja chat template engine | enabled | Correctness |
Memory Flags and Speed Flags Are Not the Same Thing
This is the distinction that makes the table usable.
A memory flag changes whether the model runs at all. -ngl, -c, --cache-type-k, --cache-type-v, --n-cpu-moe, -ts and --swa-full all trade something away so the weights and the cache fit in the memory you own. Most of them make generation slower. You accept that, because the alternative is not running.
A speed flag changes tokens per second on a model that already fits. There are far fewer of these than the internet implies. -fa on is the reliable one. -ub helps prompt processing when you raise it and helps VRAM fit when you lower it. -t matters when the CPU is doing real work, which now includes every MoE offload setup.
The practical consequence: quantizing your KV cache will not speed anything up. --cache-type-k q8_0 is a memory feature. It frees VRAM so you can raise -c, and it adds conversion work on every token. If f16 fits, f16 is faster. People try it as a performance tweak, measure a regression, and conclude llama.cpp is unpredictable. It is not; the flag was never a speed flag.
The 2026 Breaking Change: --no-mmap and --mlock Are Gone
If you have hit error: invalid argument on a command that worked last year, this is almost certainly why.
llama.cpp collapsed four separate loading flags into one. -lm, --load-mode MODE now takes:
| Mode | Behaviour |
|---|---|
auto | mmap, unless a device does not support it. The default |
none | No special loading mode. This is the old --no-mmap |
mmap | Memory-map the model |
mlock | Force the system to keep the model in RAM rather than swapping it |
mmap+mlock | Both |
dio | Use DirectIO where available |
The migration table is short:
| Old flag | Write this instead |
|---|---|
--no-mmap | -lm none |
--mlock | -lm mlock |
--mmap | -lm mmap |
--direct-io | -lm dio |
The honest caveat nobody publishes with the migration table. The new enum treats mlock as always implying mmap, so the old --no-mmap --mlock combination has no replacement. That combination mattered specifically to MoE offload users: it loaded weights into ordinary heap buffers while stopping the kernel swapping out the CPU-resident expert tensors. Issue #26110, opened 2026-07-25 and still open at the time of writing, reports the consequence — -lm none lets CPU-resident weights get swapped out under load, with throughput falling from roughly 25-27 tok/s to 7.55 tok/s, while -lm mlock double-buffers the model and invites the OOM killer.
If you run a large MoE with --n-cpu-moe on a machine that is tight on RAM, test both modes and watch swap. There is currently no setting that gives you what the old pair gave you.
Why Your Copied Command Line Fails
Three failures account for most of them.
error: invalid argument: --no-mmap— the flag was removed. Use-lm none.error: invalid argument: --ngl— that is the long form spelled wrong. The short flag is-nglwith one dash; the long forms are--gpu-layersand--n-gpu-layers.error: invalid argument: -cd—-cdis not allama-serverflag. It comes from speculative-decoding examples for other tools in the project. Every binary in llama.cpp has its own argument list, and a flag that exists for one is not guaranteed to exist for another. Check the README for the tool you are running.
The Flags Worth Setting By Hand
Everything defaults sensibly now. These are the ones still worth a deliberate value.
-c, --ctx-size— the default reads the model’s trained context, which on a modern model can be enormous and will reserve VRAM to match. Set it to the context you actually use. This is the single most common cause of “it used to fit.”-fa on— leaving it onautois fine, but pin itonwhen you are benchmarking, so a build-to-build change in the auto heuristic does not silently move your numbers.-ub— lower it to256when you are a few hundred megabytes short of fitting. Raise it when prompt processing is your bottleneck and VRAM is not.--n-cpu-moe N— for MoE models only, and only after a sweep.-np, --parallel— raise it only if you genuinely serve concurrent requests. Each slot reserves its own KV cache, so raising it on a single-user machine costs VRAM and returns nothing.
How to Find Your Own Numbers
The values in every guide, including this one, came off somebody else’s machine. Quant, RAM speed, context length, GPU and CPU all move them. The method transfers; the numbers do not.
- Start from defaults. Set only
-cto the context you need. - Change one flag. Measure tokens per second on a fixed prompt.
- Watch VRAM while you do it. The cliff where VRAM spills into driver-managed system memory is sharp, and on many systems it produces no error message at all — just a collapse in speed.
- When speed collapses, back off one step and stop.
Which card you own decides how many of these flags you ever need — most of the memory flags exist to work around VRAM you do not have.
See Also
- llama.cpp MoE Offload Flags Explained — the deep dive on
--n-cpu-moe, with measured sweeps - Why Local LLMs Are Slow Even When They Fit — the bandwidth ceiling no flag can raise
- KV Cache Quantization: q8 vs q4 and VRAM — how much context each cache type buys
- How Much VRAM for 128K Context? — sizing
-cbefore you set it - IQ4_XS vs Q4_K_M vs Q4_K_XL — picking the quant that fits the VRAM you have
- vLLM vs llama.cpp vs SGLang — when the flags are not the problem and the engine is
- Why Is My Local LLM So Slow? — the diagnostic order to work through first
Need OpenClaw fixed live?
Remote rescue sessions for gateway, auth, tunnel, VPS, and model access problems.
See Rescue Session