llama.cppOut of memory

CUDA error: out of memory (llama.cpp)

The message

CUDA error: out of memory

What it means

llama.cpp asked the card for memory and none was left: the weights, the KV cache for your context and the compute buffers add up to more than the free VRAM.

Why it happens

  • The model at this quant level, at this context, does not fit the card. Context is the part people forget: the KV cache grows with every token of -c.
  • You passed -ngl all (or a large -ngl) or a large -c. llama.cpp's automatic fitting (--fit, on by default) only adjusts arguments you did not set, so a forced value can push it over.
  • Something else holds VRAM: another model server, a game, the desktop on the same card. nvidia-smi lists every process and what it uses.
  • On AMD builds the same failure prints ROCm error: out of memory — the cause and fixes are the same.

How to fix it

  1. Check the size first: put the model, level and context into the VRAM calculator with your card. If it is red, no flag will make it fit — pick a smaller level or a shorter context.
  2. Shorten the context: -c 8192 instead of the model's full window. Omitting -c starts from the context the model was trained for.
  3. Quantize the KV cache: -ctk q8_0 -ctv q8_0 roughly halves it, with a very small quality cost.
  4. Offload fewer layers: drop -ngl (or set a number below the layer count) so the rest runs from system RAM. It loads, but generation slows sharply. For MoE models --n-cpu-moe N moves only expert weights and costs less speed.

Check the size before changing flags

Most memory errors are a size problem. Put the model, quant level, context and your card into the VRAM calculator: if it is red there, no flag will make it fit.

Guides that cover this

Related errors

Checked against

Message text read from source on 2026-10-26.