llama.cppOut of memory

Metal: failed to allocate buffer on a Mac

The message

ggml_metal_buffer_init: error: failed to allocate buffer, size = <n> MiB

Parts in <angle brackets> change from run to run.

What it means

On a Mac, Metal would not give llama.cpp a GPU buffer that large. macOS lets the GPU use only part of unified memory, by default about three quarters.

Why it happens

  • The model plus context is larger than the GPU's share of unified memory, even though the machine's total RAM looks big enough.
  • Other apps already use a lot of memory, so less is free for the GPU.

How to fix it

  1. Size it against the usable share, not the number on the box: the calculator judges Macs at about 75% of their memory.
  2. Pick a smaller level or a shorter context; close memory-hungry apps.
  3. Advanced: sudo sysctl iogpu.wired_limit_mb=<MB> raises the GPU's limit until the next reboot. Leave several GB for macOS itself, or the whole machine starts swapping.

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.