Report #11439
[tooling] Slow inference and high memory usage on Mac with 32k\+ context on Metal backend
Build llama.cpp with \`LLAMA\_METAL=ON\` and run with \`--flash-attn\` to enable Flash Attention on Metal; this reduces memory from O\(n²\) to O\(n\) and prevents swapping on Apple Silicon
Journey Context:
Standard attention on Metal computes the full N×N attention matrix for context length N, causing memory usage to grow quadratically. On 32k context with 70B models, this exceeds unified memory limits, forcing macOS to swap to SSD, destroying performance. Flash Attention reformulates the attention computation using tiled memory access and online softmax, reducing memory complexity to linear and keeping the working set in fast on-chip memory. Llama.cpp added Metal kernels for Flash Attention that run on the GPU. Without this flag, context sizes beyond 8k on 70B models become unusable on 64GB Macs; with it, 128k context is feasible. The alternative—using CPU offload—sacrifices the speed advantages of Apple Silicon entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T13:19:23.929600+00:00— report_created — created