Apple Silicon LLM Memory Bandwidth & Sizing Dataset

2026-12-05来源 dev.toEnglish

Apple Silicon LLM Memory Bandwidth & Sizing Dataset

Apple Silicon Local LLM Sizing: Memory Bandwidth Rooflines, GQA KV-Cache Math & macOS Wired Limits

Why this problem wastes time

Engineers buying a MacBook Pro, Mac mini, or Mac Studio for local LLM inference routinely get burned by misleading rules of thumb. "Just divide parameters by two for 4-bit" or "an M3 Pro is always faster than an M2 Pro" sounds convenient—until a 32B model swaps to SSD or decodes 35% slower than expected. Four hardware and math traps explain almost every sizing surprise on Apple Silicon:

  1. Binned memory buses and the M3 Pro regression: Apple's M3 Pro narrowed its memory bus to 192-bit (150 GB/s), making single-stream token decode slower than the older M2 Pro (200 GB/s). Similarly, binned M3 Max (14c/30c GPU) runs at 300 GB/s (384-bit) while the full M3 Max (16c/40c GPU) runs at 400 GB/s (512-bit), and binned M4 Max (14c/32c GPU) runs at 410 GB/s vs 546 GB/s on the full 16c/40c die.
  2. Naive 4.0 bpw underestimates real GGUF weights by ~20%: In llama.cpp / MLX GGUF quantizations, embedding layers, output projection heads, and quantization block scales push effective Q4_K_M storage closer to 4.85 bpw (not 4.0 bpw). On a 32.5B parameter model like Qwen2.5-32B, that difference is 3.4 GB of unexpected RAM.
  3. macOS Metal wired-memory caps trigger early OOM: Buying a 64 GB Mac does not give Metal 64 GB of GPU-allocatable memory. By default, macOS caps wired GPU memory at roughly 67% on <= 24 GB machines and 75% on >= 32 GB machines (48 GB usable on a 64 GB system) unless you raise sysctl iogpu.wired_limit_mb.
  4. Non-uniform KV-cache geometries across modern models: Qwen2.5-7B uses 4 KV heads, Phi-4-14B uses 10 KV heads, and Gemma-2-9B uses head_dim=256 with alternating 50% global / 50% sliding-window-4096 attention layers. Ignoring hybrid sliding-window attention overstates Gemma-2 KV memory by up to 2× at long context.

Step-by-step workflow

Autoregressive token generation (batch size 1) is strictly memory-bandwidth bound: for every single token emitted, the GPU streams all active model weights plus the active KV cache across unified memory. You can compute an exact, zero-guesswork roofline in pure Python:

QUANT_BPW = {"Q4_K_M": 4.85, "Q5_K_M": 5.70, "Q6_K": 6.56, "Q8_0": 8.50, "FP16": 16.0} def roofline_estimate(bandwidth_gbs: float, params_b: float, layers: int, kv_heads: int, head_dim: int, ctx: int, quant: str = "Q4_K_M", kv_bytes: float = 2.0, hybrid_swa_4096: bool = False) -> dict: weights_gb = params_b * (QUANT_BPW[quant] / 8.0) if hybrid_swa_4096: g_layers = layers // 2 s_layers = layers - g_layers kv_gb = (2 * kv_heads * head_dim * kv_bytes * (g_layers * ctx + s_layers * min(ctx, 4096))) / 1e9 else: kv_gb = (2 * layers * kv_heads * head_dim * kv_bytes * ctx) / 1e9 active_gb = weights_gb + kv_gb ceiling = bandwidth_gbs / active_gb return { "weights_gb": round(weights_gb, 2), "kv_cache_gb": round(kv_gb, 2), "roofline_tok_s": round(ceiling, 1), "typical_range_tok_s": (round(ceiling * 0.65, 1), round(ceiling * 0.80, 1)), } 

Checking macOS usable GPU headroom

Before downloading a 40 GB GGUF file, verify both OS headroom and the Metal wired-memory ceiling:

def usable_gpu_gb(ram_gb: int, os_reserve_gb: float = 4.0) -> float: wired_ratio = 0.67 if ram_gb <= 24 else 0.75 return max(0.0, min(ram_gb - os_reserve_gb, ram_gb * wired_ratio)) 

Common pitfalls & edge cases

  • Confusing decimal GB with GiB: Apple publishes memory bandwidth in decimal GB/s (10^9 B/s). Computing weights_gb and kv_cache_gb in matching decimal GB (10^9 B) keeps the dimensional ratio GB/s / GB = tok/s exact.
  • Assuming 100% bus utilization: Real llama.cpp and MLX Metal kernels typically achieve 65%–80% of theoretical memory bandwidth during single-stream decode due to dequantization compute, attention overhead, and cache misses. Always plan around the realized band, not the 100% ceiling.
  • Invalid hardware pairings: Not every RAM size ships on every chip (e.g., M4 Max 14c/32c is 36 GB only; M3 Ultra ships in 96 / 256 / 512 GB; there is no M4 Ultra).

Automating it in seconds

Use the Interactive Apple Silicon LLM Sizing Calculator to explore all 17 verified Apple Silicon SKUs and 14 published open-weight LLM profiles, toggle FP16 vs Q8_0 KV-cache precision, and inspect FITS / TIGHT / OOM status instantly in your browser.

You can download the complete $0.00 Free Open Dataset & Python CLI Kit (Gumroad, GitHub Release, and Kaggle Datasets), including identical canonical apple_silicon_specs.csv/.json and llm_arch_profiles.csv/.json files, llm_sizing_cli.py (estimate, matrix --format md|csv|json, validate), METHODOLOGY.md, and test_llm_sizing.py.

Live Demo & Full Guide

原文:https://www.a8q9.cn/en/article/apple-silicon-llm-memory-bandwidth-sizing-dataset-7ef9f2.html

相关文章