Unified Memory Bandwidth Roofline Physics: Sparse MoE vs Dense GGUF Decode on Apple Silicon M1 to M4 Pro
Unified Memory Bandwidth Roofline Physics: Sparse MoE vs Dense GGUF Decode on Apple Silicon M1 to M4 Pro
Autoregressive token generation at batch size 1 is memory-bandwidth bound, not ALU-FLOPS bound. Every generated token requires streaming every active parameter and attention key-value (KV) state from Apple Unified Memory into the GPU shader cores once per forward pass.
In commit 4e9b17d8 inside mcp/destiny_mcp_server.py, we added estimate_apple_silicon_tok_per_sec to turn manufacturer Unified Memory bandwidth specs and Ed25519-verified byte counts into deterministic roofline and realistic decode bounds paired with Apple Silicon GGUF VRAM Calculator.
1. Bandwidth Roofline & Active-Parameter Equation
For a chip with peak Unified Memory bandwidth BW (GB/s), model file size W (GB), active sparse routing ratio alpha (0 < alpha <= 1.0), and live KV-cache footprint K (GiB):
active_read_gb_per_tok = W * alpha + 0.12 * K
roofline_decode_tok_s = BW / active_read_gb_per_tok
realistic_metal_tok_s = (BW * 0.615) / active_read_gb_per_tok
- Why
alphadominates latency: On Apple M4 Pro (273 GB/s), denseQwen3.8-27B UD-Q4_K_M(16,817,244,384B,alpha = 1.00) reads16.840 GB/tokenat8192tokens (q8_0KV):273 / 16.840 = 16.21 tok/stheoretical ceiling and9.97 tok/ssustained solo Metal decode (29.37 tok/swhen accelerated byDFlash2speculative drafting). - Sparse Mixture-of-Experts (
LFM2-8B-A1B Q8_0): With8,868,428,480B total weights andalpha = 0.24(~2.0Bactive weights per token), per-token read drops to2.143 GB(8192context,q8_0KV). That yields a127.37 tok/shardware ceiling and78.33 tok/srealistic decode (0.615Metal efficiency) — matching our measured78.62 tok/ssingle-stream M4 Pro benchmark in nandai.org/benchmarks and Destiny-M4-Pro-Hardware-Benchmarks.
2. q8_0 KV-Cache Byte Math (fp16 vs q8_0 vs q4_0)
Long contexts shift bottlenecks from weights into attention cache growth:
- Scaling factors:
fp16 = 1.0x,q8_0 = 0.5x,q4_0 = 0.25x(32 MiB / 1K tokensbase onLFM2-8B-A1B,40 MiB / 1KonInkling-2-Mini,48 MiB / 1KonQwen3.8-27B). - At
8192tokens (8×1K) withq8_0KV quantization (0.5x),LFM2-8B-A1Bneeds only8 * 16 MiB = 128 MiB(0.125 GiB), whereasfp16doubles to0.250 GiBand131,072tokens expands to2.000 GiB(q8_0) vs4.000 GiB(fp16).
3. macOS Wired-Memory Pool, vm.compressor & MAP_SHARED Headroom
Exceeding macOS’s Metal recommendedMaxWorkingSetSize wired budget forces kernel vm.compressor paging and swap thrashing, collapsing decode throughput by 4x–10x:
- Usable Metal wired pools:
11.50 GiBon16 GBMacs (71.9%),18.00 GiBon24 GBMacs (75.0%), and~79%of physical Unified Memory on36 GB–512 GBsystems (37.9 GiBon48 GB,101.1 GiBon128 GB,151.7 GiBon192 GB). - Required footprint (
W_GiB + K_GiB + 0.45 GiBruntime scratch):- On
24 GBM4 Pro:LFM2-8B-A1B Q8_0uses8.834 GiB(+9.17 GiBheadroom), whileQwen3.8-27B UD-Q4_K_Muses16.300 GiB(+1.70 GiBwired headroom — cleanMAP_SHAREDresidency with zero0 Bdirty GGUF pages). - Across
M1(68.25 GB/s),M2 Pro(200 GB/s),M3 Pro(150 GB/s),M3 Max(300/400 GB/s),M4 Max(546 GB/s), andM3 Ultra(819 GB/s), scaling is linear withBWuntil contextKVreads approach active weight bytes.
- On
Verified Specifications & Interactive Sizing Tools
- Web UMA Calculator: nandai.org/tools/gguf-vram-calculator
- Live Signed Model Catalog: models.nandai.org/v1/models-manifest.json
- Zero-Dependency MIT MCP Tool (
estimate_apple_silicon_tok_per_sec): github.com/karany97/destiny/tree/main/mcp - Benchmarks & macOS Download: nandai.org/benchmarks · nandai.org/download · Zenodo Record
24642737
Write a comment