New Tool Radar

Local AI

How to Set GPU Layers for a llama.cpp Model on the Command Line

Pass -ngl to llama-cli or llama-server to choose how many model layers run on the GPU, from 0 for CPU only to all for full offload.

Schematic diagram with three steps: pass -ngl with a layer count, watch VRAM while the model loads, and raise or lower the count until it fits.

A transformer model is a stack of layers, and llama.cpp can put some of them on the GPU and leave the rest on the CPU. More layers on the GPU is faster; more layers than fit in VRAM fails to load. The server README documents -ngl, --gpu-layers, --n-gpu-layers N as the maximum number of layers to store in VRAM — an exact number, auto, or all — with a default of auto.

Related guide: How to Run a llama.cpp Model with GPU Offload

Set the layer count

llama-cli -m model.gguf -ngl 20 -p "Explain what a lighthouse keeper does in two sentences."

Use -ngl 0 for CPU only, -ngl all to try to put every layer on the GPU, and a number in between for a partial offload. The older server README described the same flag as offloading layers to the GPU when compiled with GPU support, generally increasing performance. The same flag works for llama-server. If you do not pass it, auto decides for you — which is usually right, and this guide is for the cases where it is not: a GPU shared with another program, or a model that only just fits.

Tune it until it fits

Start from all. If loading fails with an out-of-memory error, drop to half the layers, then raise in steps until it fails again and step back one. Watch VRAM while the model loads (nvidia-smi on NVIDIA) so you can see how close to full the card is. A partial offload is still much faster than CPU only, so there is no need to chase the last layer.

Expected result. We checked the llama.cpp server README and the llama-cli man page for the -ngl flag, its values auto/all/number, and its default. We did not run this software ourselves for this guide, so no output here is a recorded result; steps marked UNTESTED were checked against the sources below, not run.

Limits

GPU offload only works if your llama.cpp build was compiled with GPU support; a CPU-only build ignores the flag. Layer counts differ between models, so a number that works for one model is meaningless for another — always tune per model. We did not run llama.cpp, so no speed here is a measured result.

Sources

Checked 2026-11-28.

See all