llama.cppOut of memory

unable to allocate CUDA0 buffer (llama.cpp)

The message

unable to allocate CUDA0 buffer

What it means

llama.cpp could not reserve room for the model's weights on that device. The device name follows your backend: CUDA0, ROCm0, Vulkan0 or Metal.

Why it happens

  • The weights alone are larger than the free memory on that device — before any context is added.
  • Too many layers were forced onto the card with -ngl.
  • Another process already holds part of the card.

How to fix it

  1. Compare the file size with your card in the VRAM calculator; the weights are roughly params × bits ÷ 8.
  2. Download a smaller level of the same model, or let llama.cpp choose the layer split by not passing -ngl.
  3. Free the card: stop other servers (nvidia-smi on NVIDIA, rocm-smi on AMD shows what is using it).

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.