Home / use case

How much RAM a local LLM needs on a Mac: measurements on a 16 GB MacBook M5

At a glance
Hardware
Apple MacBook M5 with 16 GB unified memory
Models & engines
Ollama 0.31 with MLX builds
Memory as reported by ollama ps; answers capped at 200 tokens
Key gotcha
Long documents hurt latency more than memory on newer models.

What they built

Kirill Lukyanov set out to answer "will this model run on my Mac?" properly, because the model's file size is only a third of the answer. While a model runs, memory goes to the weights, the context (KV cache), and macOS with everything else you have open.

He measured Qwen 3.5 0.8B, Qwen 3.5 4B and Gemma 4 12B on his own MacBook M5 with 16 GB, calculated the context cost for classic 8B to 70B models from their configs, and combined both into a table of what fits into 16 to 128 GB.

His working rule: weights plus context should stay at or below three quarters of the Mac's RAM.

Setup

  • Apple MacBook M5 with 16 GB unified memory
  • Ollama 0.31 with MLX builds
  • Three test modes: a short 150-word email request with a 4K window, a 4.2K-token document with an 8K window, and an 18K-token document with a 32K window
  • Memory as reported by ollama ps; answers capped at 200 tokens

How it works

  1. At 4-bit, weights take about 0.5 GB per billion parameters (8B is about 5 GB, 70B about 40 GB).
  2. Ollama and LM Studio reserve memory for the whole configured context window up front, not for the text you actually send.
  3. On his 16 GB MacBook, Metal's recommendedMaxWorkingSetSize is 12.7 GB, about three quarters of RAM; the rest belongs to macOS and other apps.
  4. For classic models he computed cache size as 2 × layers × KV heads × head dim × 2 bytes from Hugging Face config files.

Results & numbers

  • Qwen 3.5 4B used 3.43 GB for a short request (34 tok/s, 8 s) and 4.81 GB for the 45-page document (27 tok/s, 67 s).
  • Gemma 4 12B used 7.64 GB for a short request (25 tok/s) and 9.21 GB for the 45-page document, which took 4.8 minutes at 9 tok/s.
  • A 32K window added 1.4 GB to Qwen 4B and 1.6 GB to Gemma 12B, roughly 50 KB per token, against 128 KB per token for classic Llama 3.1 8B.
  • His buying guide: 32 GB is the sensible minimum for document work, 48 to 64 GB for 32B models, 96 to 128 GB for 70B.

Gotchas

  • Long documents hurt latency more than memory on newer models.
  • On 16 GB, an 8 GB model depends on what else is open: his first Gemma run while working took 169 seconds at 4 tok/s, against 57 seconds at 16 tok/s on a quiet system.
  • Raising the GPU limit with sysctl iogpu.wired_limit_mb leaves apps less memory and macOS starts swapping.
  • The 16 to 128 GB table is a calculation, not a measurement on every machine.

Do it yourself

  1. Check your Mac's RAM and budget about three quarters of it for the model.
  2. Pick a 4-bit model whose weights (about 0.5 GB per billion parameters) leave room for context.
  3. Set the context window to the task: num_ctx in Ollama or Context Length in LM Studio.
  4. For GGUF models in Ollama, set OLLAMA_FLASH_ATTENTION=1 and OLLAMA_KV_CACHE_TYPE=q8_0 to halve the cache.
  5. Run your prompt and check real memory use with ollama ps, with other heavy apps closed.
OLLAMA_FLASH_ATTENTION=1 OLLAMA_KV_CACHE_TYPE=q8_0 ollama serve
ollama ps
Source: Kirill Lukyanov (DEV Community) · Published 2026-10-28 · Added 2026-10-28. This write-up summarizes the original source; see it for full details.

Similar setups

Getting OpenCode to work with a local Ollama model by fixing the 4,096-token context

OpenCode on a local Ollama model ignored files, invented tasks or looped, because each ~23k-token request was silently cut to fit Ollama's default 4,096-token context on a 16 GB GPU.

DEV Community (Davidrs) · 2026-11-27

PatchPal TinyAgent: a coding agent on a 4B model and a 6GB laptop GPU

WiseProbe adapted its PatchPal coding agent to run Gemma 4 E4B or Qwen3.5 4B through Ollama on a 6GB RTX A1000, using handoff-note compaction and capped file reads to work inside a 16K or 32K window.

WiseProbe Blog · 2026-11-25

LM Studio vs Ollama on an RTX 5080: memory settings mattered more than the app

LK Wood IV ran LM Studio and Ollama on the same RTX 5080 with identical GGUF files and found the apps within 14% of each other, while one wrong offload or context setting cost up to 3.4x.

LK Wood IV (DEV Community) · 2026-11-01

A €200 mini PC as an offline AI box: a week with Gemma and Qwen

Diogo Soares ran Gemma 4 E4B and Qwen2.5-Coder 7B on a cheap NiPoGi P1 mini PC firewalled off the internet, used it from his Mac for a week, and measured what was fast and what wasn't.

Diogo Soares (DEV Community) · 2026-10-30