On Apple Silicon, llama.cpp uses the Metal backend to run on the GPU, and Metal is enabled by default on macOS. When a Mac runs the model on the CPU instead, the usual causes are an Intel build running under Rosetta, zero GPU layers, or a model too large for the GPU share of unified memory.
What you need
- A Mac with Apple Silicon, M1 or newer
- llama.cpp or Ollama installed
- A terminal, and the model that runs slowly
Step 1: Confirm you run a native arm64 build
Run uname -m and file $(which ollama). Both should report arm64. If uname -m prints x86_64, the terminal itself runs under Rosetta: quit it, untick Open using Rosetta in the terminal app Get Info window, and reopen it. An Intel build under Rosetta will not use Metal at all.
Step 2: Push layers onto the GPU
With a Metal build, run ./llama-cli -m model.gguf -ngl 999. The -ngl flag offloads layers to the GPU; the value 999 means all of them. Check the load log: it should report every layer offloaded, and Activity Monitor GPU History should show sustained activity while tokens are generated.
Step 3: Shrink the model or the context if Metal fails
If loading fails with ggml_metal_init: failed to allocate buffer, the weights plus cache exceed the GPU share of unified memory, which macOS reports as recommendedMaxWorkingSetSize and is commonly around 65 to 75 percent of total memory. Pick a smaller model, an 8 GB Mac comfortably runs 3B to 7B models at Q4, or lower the context length and retry. A build with -DGGML_METAL=OFF, or –n-gpu-layers 0, disables GPU inference, so do not use those when you want Metal.
Worked example: a 7B model that ran on CPU
The table below is a synthetic example. The checks, the error text, and the memory tiers come from the cited Mac troubleshooting guide; the model is illustrative.
| Check | Finding | Fix |
|---|---|---|
| uname -m | x86_64 | Untick Open using Rosetta, reopen terminal |
| GPU layers | -ngl 0 in command | Use -ngl 999 instead |
| Model size | 14B Q8 on a 16 GB Mac | Switch to a 7B Q4 model |
Expected result (UNTESTED). after the fix, uname -m reports arm64, the load log reports all layers offloaded, and Activity Monitor GPU History shows activity during generation. This check was not run live; the checks and fixes come from the cited troubleshooting guide.
Limits
- Apple Silicon shares one unified memory pool; the GPU share is roughly 65 to 75 percent of it.
- Intel Macs do not get the Apple Silicon Metal path; models run on CPU there.
- A long context adds gigabytes of KV cache on top of the weights.
- Ollama on Apple Silicon enables Metal automatically; if it shows 100 percent CPU, suspect a Rosetta install first.
