DESTINY
GuidesG-03 · Local Inference PhysicsAuthor: Karan Yadav · Updated 2026-11-25

Apple Silicon Unified Memory, Block-16 Paged KV-Cache Math & Roofline Decode Bounds

Predicting local LLM performance on Apple Silicon does not require guesswork. Every autoregressive decode benchmark obeys the Williams–Waterman–Patterson Roofline memory-bandwidth ceiling: divide achievable LPDDR5X bandwidth (273 GB/s on M4 Pro) by active parameter bytes plus paged KV-cache bytes read per token. On M4 Pro, sparse MoE LFM2-8B-A1B-Q8_0 empirically sustains 83.95 tok/s while a 494M draft checkpoint reaches 240.5 tok/s.

Why does Unified Memory Architecture change local model loading and decode physics?

Direct answer: On discrete PCIe GPUs, weights must be copied from host DRAM over a 16–64 GB/s PCIe link into strictly partitioned GDDR6X VRAM. On Apple Silicon UMA, CPU cores and Metal compute queues address identical LPDDR5X physical pages, letting mmap() bind an 8.26 GiB GGUF file in 3.946 ms with zero duplicate host-to-device allocation.

Unified memory does impose one strict physical ceiling: macOS reserves wired headroom for WindowServer, kernel page tables, and application heaps, leaving roughly 72%–78% of installed RAM as safe GPU working set (about 18 GiB on a 24 GB M4 Pro, or ~11.5 GiB on a 16 GB base chip). Exceeding that practical Metal pool forces compressed-memory swap to NVMe SSD, collapsing decode speed by more than an order of magnitude. Accurate sizing therefore starts by budgeting three additive pools: static quantized weights, dynamic context KV cache, and workspace activation buffers.

What is the exact Roofline equation for batch-1 decode throughput?

Direct answer: For each output token generated at batch size 1, every active weight matrix multiplies a single activation vector (matrix-vector GEMV). Thus achievable throughput Rdecode is strictly bounded by effective memory bandwidth η·BW divided by the sum of active weight bytes Bact and KV-cache bytes BKV(L) streamed per step.

Rdecode(L) ≤ η⋅BW Bact+2nlayersnkvdheadLbq

Plug real numbers from our Apple M4 Pro (273 GB/s peak theoretical LPDDR5X, practical sustained Metal utilization η ≈ 0.72–0.80, giving ~200–219 GB/s effective stream bandwidth) into the denominator:

Model CheckpointTotal GGUF SizeActive Read / TokenM4 Pro Audited ResultRegime
qwen_draft.gguf (494M Q8_0)0.506 GB~0.51 GB240.5 tok/s (257.75 tg128)Speculative Draft (Overhead + BW)
LFM2-8B-A1B-Q8_0 (MoE)8.26 GiB~1.9–2.1 GB83.95 tok/s (Pure Metal)Production 8B MoE (Bandwidth Bound)
Dense 8B Q8_0 (Reference)~8.54 GB~8.54 GB~24–26 tok/s (Roofline)Dense Reference Ceiling

This table exposes why honest benchmark reporting MUST separate draft checkpoints from production models: marketing a 494M draft model’s 240.5 tok/s as if it were an 8B or 35B reasoning model violates basic conservation of memory bandwidth. Sparse Mixture-of-Experts models like LFM2-8B-A1B (1B active parameters) and Qwen3.6-35B-A3B (3B active parameters) excel on laptops precisely because they decouple total knowledge capacity (stored in Unified Memory) from active bytes read per token.

How does block-16 Paged KV memory avoid contiguous allocation fragmentation?

Direct answer: Pre-allocating contiguous KV buffers for maximum context length wastes 60%–85% of GPU memory on short prompts. Partitioning key/value tensors into fixed 16-token virtual pages (PagedAttention) allocates physical blocks on demand, capping internal fragmentation at most 15 tokens per active sequence while enabling radix prefix sharing across turns.

Combining Grouped-Query Attention (Ainslie et al., EMNLP 2023), block-16 quantization (Q8_0 or Q4_0), and pinned initial attention-sink tokens (Xiao et al., ICLR 2024) controls both memory footprint and attention stability at long context lengths. Take a 32-layer model with nkv = 8 GQA heads and dhead = 128: in FP16 (bq = 2 bytes), each 1,024 tokens consumes 2 × 32 × 8 × 128 × 1,024 × 2 = 134.2 MB (128 MiB). Quantizing KV pages to Q8_0 cuts that to 64 MiB per 1K tokens (~67 MiB including block scales), and Q4_0 halves it again to ~34 MiB per 1K tokens—allowing a 24 GB laptop to hold full-repository or multi-chapter dissertation contexts strictly inside Unified Memory without spilling to disk.

// Exact block-16 Paged KV footprint in GiB (including per-block FP16 scale overhead)
function pagedKvGiB({ layers, kvHeads, headDim, contextTokens, bitsPerVal = 8, blockSize = 16 }) {
  const numBlocks = Math.ceil(contextTokens / blockSize);
  const elementsPerBlock = blockSize * headDim;
  const payloadBytes = Math.ceil((elementsPerBlock * bitsPerVal) / 8);
  const scaleBytes = 2; // 1x FP16 scale per 16-element quantization group
  const bytesPerHeadBlock = payloadBytes + scaleBytes * (elementsPerBlock / 16);
  const totalBytes = 2 * layers * kvHeads * numBlocks * bytesPerHeadBlock; // K + V
  return totalBytes / (1024 ** 3);
}

Finally, transparency regarding NVMe KV tiering matters: while our standalone Linux CachyOS C++20 io_uring direct-I/O harness measures 3.11 GiB/s block hydration from NVMe Gen4, live end-to-end .dpc1 prefix-cache hit counts in Destiny’s desktop runtime are currently 0 pending final runtime integration—a distinction explicitly recorded in our benchmarks dataset.

How do prefill compute, attention sinks, and thermal throttling interact during long sessions?

Direct answer: Unlike batch-1 decode (which is memory-bandwidth bound), prompt prefill processes hundreds or thousands of tokens simultaneously via matrix-matrix multiplication (GEMM), shifting execution into the compute-bound region of the Roofline curve—which is why our 494M Q8_0 draft reaches 6,524.24 tok/s on pp512 prompt evaluation versus 257.75 tok/s on tg128 decode.

This 25× gap between prefill and decode speed governs real workstation ergonomics when analyzing long repositories, legal contracts, or dissertation manuscripts. Whenever a user asks a follow-up question over an unchanged 32,768-token document, recomputing the prompt from scratch incurs multi-second prefill latency and spikes SoC package power above 35 W. Maintaining a deterministic radix prefix tree over block-16 KV pages allows repeated system instructions and attached reference documents to skip prefill entirely, cutting warm time-to-first-token down to a single decode step plus cache lookup overhead.

When sizing an Apple Silicon workstation for daily engineering workloads, apply a conservative three-part memory rule: reserve at least 6 GiB of Unified Memory exclusively for macOS WindowServer, browser tabs, and IDE language servers; add the exact GGUF file size on disk (for example, 8.26 GiB for LFM2-8B-A1B-Q8_0 or 12.74 GiB for Qwen3.6-35B-A3B-UD-IQ3_S); and add the quantized KV budget for your target context window plus 1.2 GiB of Metal compute scratch buffers. If the sum stays below 80% of physical RAM, sustained decode remains silent, thermally stable, and completely free of SSD page-swap stalls across multi-hour offline sessions.

Primary Systems & Architecture References

  1. Williams, Waterman & Patterson (CACM 2009) — Roofline: An Insightful Visual Performance Model
  2. Kwon et al. (SOSP 2023) — Efficient Memory Management for LLM Serving with PagedAttention
  3. Ainslie et al. (EMNLP 2023) — GQA: Training Generalized Multi-Query Transformer Models
  4. Xiao et al. (ICLR 2024) — Efficient Streaming Language Models with Attention Sinks
  5. Apple Developer Documentation — Unified Memory Shared Storage Modes on Apple GPUs
  6. GGML Project — GGUF Binary Tensor Specification
[FAQ // VERIFIED SPECIFICATION]

Apple Silicon UMA & KV-Cache Math FAQ

04 ENTRIES · VISIBLE DOM PARITY
Why is single-user local LLM decoding bound by memory bandwidth rather than GPU TFLOPS?
At batch size B = 1, generating one token performs roughly two floating-point operations per active parameter byte while requiring the entire active weight tensor plus KV cache to stream from DRAM. The resulting arithmetic intensity (~1–2 FLOP/byte) sits far below Apple M4 Pro’s ridge point, locking throughput strictly to LPDDR5X bandwidth.
Why does LFM2-8B-A1B-Q8_0 reach 83.95 tok/s on M4 Pro while dense 8B Q8_0 models run around 27–30 tok/s?
LFM2-8B-A1B is a sparse Mixture-of-Experts architecture that activates only ~1B parameters per token rather than all 8B weights. Streaming ~1.9–2.1 GB of active expert weights and KV state across M4 Pro’s 273 GB/s Unified Memory bus achieves 83.95 tok/s empirically, roughly 3× faster than reading a full 8.5 GB dense Q8_0 model every token.
How does Grouped-Query Attention (GQA) plus Q8_0/Q4_0 KV quantization cut long-context memory?
Standard Multi-Head Attention stores full K and V projections for every query head in FP16 (2 bytes/element). GQA shares KV heads across groups of 4–8 query heads, and quantizing block-16 KV pages to Q8_0 (1 byte) or Q4_0 (0.5 bytes) cuts KV footprint by 8× to 32× combined.
What is the difference between cold mmap() time (3.946 ms) and full time-to-first-token (TTFT)?
Cold mmap() (3.946 ms on M4 Pro APFS NVMe) maps GGUF virtual memory pages into unified CPU/GPU address space with zero bulk RAM copy. Full TTFT additionally includes on-demand NVMe page faults on cold cache plus prompt prefill compute proportional to prompt length.