← All guides

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, --mlock and --direct-io were 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 with error: invalid argument.
  • -ngl now defaults to auto. The advice to always pass -ngl 99 is 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: -fa and -ub. Everything else buys you the ability to run the model at all.
  • Do not copy a --n-cpu-moe value. 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.

FlagWhat it doesDefaultBuys you
-ngl, --gpu-layers, --n-gpu-layers NMax layers stored in VRAM. Takes a number, auto, or allautoFit
-lm, --load-mode MODEHow the model is loaded: auto, none, mmap, mlock, mmap+mlock, dioautoFit
-fa, --flash-attn [on|off|auto]Flash AttentionautoSpeed
--cpu-moe, -cmoeKeeps all MoE weights in CPU RAMoffFit
--n-cpu-moe N, -ncmoeKeeps MoE weights of the first N layers in CPU RAMoffFit
-c, --ctx-size NPrompt context size. 0 reads it from the model0Fit
-b, --batch-size NLogical max batch size2048Little
-ub, --ubatch-size NPhysical max batch size — sizes the compute buffers512Speed / fit
--cache-type-k TYPEKV cache type for K: f32, f16, bf16, q8_0, q4_0, q4_1, iq4_nl, q5_0, q5_1f16Fit
--cache-type-v TYPEKV cache type for Vf16Fit
-kvo/-nkvo, --kv-offload/--no-kv-offloadWhether the KV cache lives on the GPUenabledFit
--swa-fullUse a full-size sliding-window-attention cachefalseFit
-np, --parallel NNumber of server slots (concurrent requests)-1 (auto)Throughput
-sm, --split-mode {none,layer,row,tensor}How a model splits across several GPUslayerFit
-ts, --tensor-split N0,N1,...Fraction of the model sent to each GPUevenFit
-ot, --override-tensor <pattern>=<type>Per-tensor buffer placementoffFit
-dev, --device <dev1,dev2>Which devices to offload toallControl
-t, --threads NCPU threads used during generation-1 (auto)Speed on CPU
--numa TYPENUMA optimizations on multi-socket machinesoffSpeed on CPU
-n, --predict NTokens to predict. -1 is unlimited-1
--jinja / --no-jinjaJinja chat template engineenabledCorrectness

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:

ModeBehaviour
autommap, unless a device does not support it. The default
noneNo special loading mode. This is the old --no-mmap
mmapMemory-map the model
mlockForce the system to keep the model in RAM rather than swapping it
mmap+mlockBoth
dioUse DirectIO where available

The migration table is short:

Old flagWrite 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.

  1. error: invalid argument: --no-mmap — the flag was removed. Use -lm none.
  2. error: invalid argument: --ngl — that is the long form spelled wrong. The short flag is -ngl with one dash; the long forms are --gpu-layers and --n-gpu-layers.
  3. error: invalid argument: -cd-cd is not a llama-server flag. 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 on auto is fine, but pin it on when you are benchmarking, so a build-to-build change in the auto heuristic does not silently move your numbers.
  • -ub — lower it to 256 when 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.

  1. Start from defaults. Set only -c to the context you need.
  2. Change one flag. Measure tokens per second on a fixed prompt.
  3. 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.
  4. 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

Need OpenClaw fixed live?

Remote rescue sessions for gateway, auth, tunnel, VPS, and model access problems.

See Rescue Session

Read next

--n-cpu-moe Explained: llama.cpp MoE Offload Flags (2026)
What --n-cpu-moe, -ngl, --flash-attn and -lm do in llama.cpp, how to pick the CPU layer count for your VRAM, and measured tok/s on an RTX 3060 12GB.
Why Speculative Decoding Made My Local LLM Slower
You added a draft model and lost tokens/sec. The real causes — same-device contention, a Metal net loss of 11-24%, tokenizer mismatch, and low-draftability prompts — plus the acceptance-rate number that tells you whether to keep it.
Ollama vs LM Studio vs llama.cpp vs oMLX: Which Local LLM Runtime in 2026
Four local LLM runtimes, four different users. Ollama is the easy default, LM Studio is the GUI, llama.cpp gets features first, MLX is fastest on Apple Silicon with model coverage gaps.
Check KV Cache Size in llama.cpp and Ollama: Read the Log
The exact log lines that show how much KV cache llama.cpp and Ollama allocated, read from their source in September 2026. Why llama-server can shrink your context without a visible line, why its default is 4 slots, and how sliding-window models show two caches.