A transformer model is a stack of layers, and llama.cpp lets you choose how many of them run on the GPU. The -ngl flag — short for --n-gpu-layers — is that choice: it sets the maximum number of layers to keep in VRAM, and the rest run on the CPU. More layers on the GPU means faster replies, but only if the model and its context fit in the card’s memory.
Offload all layers
Ask for more layers than the model has, and llama.cpp offloads everything that fits. The official llama.cpp multi-GPU docs say to “use 999 or all to push everything possible to the GPUs”, and the default is auto:
llama-cli -m model.Q4_K_M.gguf -ngl 99 -c 4096
Here -m is the GGUF file and -c is the context size in tokens. If the model has 32 layers and you set -ngl 99, all 32 run on the GPU.
Lower the number if it does not fit
If the model plus its context does not fit in VRAM, the load fails — so lower -ngl in steps until it loads. A guide to the flag describes the trade-off: a few layers on the GPU is slow, half the layers is still slow, and the jump from “most layers” to “all layers” is the big one, because a model with most layers offloaded still shuffles data to the CPU every token.
| -ngl setting | VRAM used | Relative speed | When to use it |
|---|---|---|---|
0 (CPU only) |
Near zero | Slowest | VRAM far too small; the model still runs |
A few layers (-ngl 10) |
Low | Very slow | It just needs to run |
| Half the layers | Medium | Slow | Borderline fit, no other option |
All layers (-ngl 99) |
Maximum | Fastest | Model and context fit comfortably |
Start at -ngl 999 and let llama.cpp take what fits, noting how many layers it actually offloads. If it fails, lower the number in steps until the load succeeds.
Check whether the GPU is used at all
If the model runs but the GPU sits idle, the docs’ troubleshooting table gives the likely causes: “--n-gpu-layers is 0 or too low — try explicitly setting -ngl all“, or the GPUs are hidden by an environment variable such as CUDA_VISIBLE_DEVICES=-1, or the build has no support for the relevant backend.
Expected result. We checked llama.cpp’s own multi-GPU docs for the -ngl definition, the 999/all form, and the troubleshooting rows. We did not run llama-cli.
Limits
The speed table above is qualitative: exact numbers depend on the model, the context size, and the drivers, and no speed was measured for this guide. The model.Q4_K_M.gguf file name is a placeholder for your own model. Lowering the context size (-c) also frees memory, since the KV cache grows with it, but that changes how much the model remembers. This guide covers a single GPU; spreading layers across several GPUs needs the split-mode flags in the same docs. We did not run llama-cli, so no output here is a recorded result.
