MasterFabric Logo
v1.7
AI-Portfolio

MasterFabric · LLM Serving Bench

Measured LLM serving benchmarks comparing llama.cpp and MLX on Apple Silicon across quantization, concurrency, context and speculative decoding.

sha 83af7fe·snapshot 2026-11-23·View on GitHub →
MasterFabric LLM Serving Bench: throughput, prefill, KV cache and quantization measured on an M4 Pro

Overview

This repo measures LLM serving performance on servers that actually ran, rather than borrowed numbers: aggregate throughput, time to first token and inter-token latency against concurrency, prefill cost against prompt length, weight quantization (Q4_K_M, Q8_0, F16), KV-cache quantization and prompt-cache reuse. It compares llama.cpp on an Apple M4 Pro GPU via Metal against the same server in a CPU-only container and against Apple's MLX engine, with the main runs repeated on a MacBook Air M5. It also measures a long-context curve from 512 to 31k tokens and speculative decoding with a 0.5B draft model against 1.5B and 7B targets. Every number comes from a file in results/, generated by scripts in bench/, and the serving defaults chosen here feed the companion masterfabric-onprem-llm-stack repo.

Key measured results

  • 01Peak output throughput, Q4_K_M, 4 concurrent requests: 381 tok/s on the Metal GPU vs 184 tok/s in the CPU container
  • 02Peak output throughput, Q8_0, 4 concurrent: 358 tok/s Metal vs 328 tok/s CPU container (reproduced in a second run at 335 vs 181)
  • 03Q4_K_M costs little quality: perplexity 24.69 ± 1.09 vs 23.63 ± 1.04 for Q8_0 (F16: 23.62 ± 1.04), for a 41% smaller file
  • 04A q8_0 KV cache halves KV memory at the same speed: at 32k context, 896 to 476 MiB KV buffer (computed), server RSS 2,746 to 2,042 MiB (measured), 38.2 vs 37.9 tok/s
  • 05MLX is faster at 4-bit but loses more quality: one request 210 vs 171 tok/s, server peak 474 vs 378 tok/s; perplexity rises 17.5% over MLX's own 8-bit vs 4.5% for Q4_K_M
  • 06Long context from 512 to 31,744 prompt tokens: llama.cpp peak footprint grows 1.40 to 2.25 GiB (1.85 GiB with a q8_0 KV cache) and decode falls 171 to 96 tok/s; MLX stays faster at 114 tok/s at 31k but peaks at 3.40 GiB
  • 07Speculative decoding with a 7B target and 0.5B draft: 1.60x (llama.cpp) and 1.73x (MLX) speed-up on code/SQL/YAML, but 0.41-0.49x on open text with 16 draft tokens; always slower (0.31-0.71x) on a 1.5B target
  • 08A MacBook Air M5 decodes at 0.57-0.75x the M4 Pro with llama.cpp, but prefills short prompts faster (2,753 vs 2,196 prompt tok/s at ~1k tokens) and long prompts slower (1,638 vs 1,999 at 3.8k)
  • 09The prompt cache turns a 1.89 s prefill into 13 ms for a repeated 4k-token prompt, at no cost on the cold request (1.888 s vs 1.891 s)
  • 10Every one of the 5 draft-vs-target output divergences (7B, 8 prompts) happened where the target's own top two tokens were within 0.002-0.034 nats, against a median gap of 5.36 nats over all tokens

Honest limitations

  • No GPU server and no vLLM run: the lab has no NVIDIA GPU, so 'GPU' means the Apple M4 Pro through Metal; vLLM numbers could be added without code changes but none are claimed
  • The MacBook Air ran on battery, once: on 2026-11-23 the M4 Pro was offline, so the Air runs and the mismatch study were done there (battery 43% to 21%, low power mode off, one run per configuration); an unexplained throughput discrepancy (213 vs 131 tok/s at 4 concurrent Q8_0) between two sweeps makes the Air numbers indicative, and the CPU container and long-context runs were not repeated there
  • The mismatch study ran on one machine and one build; the batched-vs-single-token kernel explanation is inferred from the batched-prefill test and near-tie gaps, not from reading the Metal kernels, and decode speeds in the mismatch results include the cost of returning top-2 probabilities and are not benchmarks
  • Ollama is installed but was not measured, since its server was not running and the repo does not start or change long-lived services
  • Only one small model (Qwen2.5-1.5B) was tested with short runs and a single repetition per configuration; there are no confidence intervals for latency
  • Laptop conditions such as other apps, thermal state and a background model download during the first runs were not controlled
  • The concurrency sweep uses short prompts (~48 tokens) that llama.cpp may serve partly from the prompt cache, so its TTFT measures queueing rather than prefill
  • KV buffer sizes are computed rather than read from the server, and RSS includes weights and compute buffers
  • The two llama.cpp builds differ between host (12359) and container (12464)
  • MLX vs llama.cpp is not bit-for-bit matched: the 4-bit formats differ in size and quality, and the MLX server cannot ignore EOS
  • Speculative decoding was measured with one request at a time and 8 prompts; gains are usually smaller under concurrent load on a GPU server
  • The long-context curve used one request per point with no repetitions, and the MLX 8-bit KV memory increase was observed but not explained
  • Perplexity on 38 KB of text is a coarse quality signal, not a task evaluation, and the Q4_K_M/Q8_0 difference is within error bars
  • The Q8_0 > Q4_K_M result on CPU was reproduced but not profiled; the cause is a hypothesis about CPU kernel differences on ARM

Screenshots & diagrams

Benchmark setup: load generator, run matrix, Metal and CPU servers
Benchmark setup: load generator, run matrix, Metal and CPU servers
Throughput, TTFT and inter-token latency against concurrency
Throughput, TTFT and inter-token latency against concurrency
TTFT and prefill throughput against prompt length
TTFT and prefill throughput against prompt length
KV cache type, prompt-cache reuse and perplexity by quantization
KV cache type, prompt-cache reuse and perplexity by quantization
Server throughput against concurrency for llama.cpp and MLX at 4 and 8 bits, and single-stream decode speed with the perplexity cost of 4-bit
Server throughput against concurrency for llama.cpp and MLX at 4 and 8 bits, and single-stream decode speed with the perplexity cost of 4-bit
Peak memory footprint, prefill speed and decode speed against prompt length for llama.cpp and MLX with f16 and 8-bit KV caches
Peak memory footprint, prefill speed and decode speed against prompt length for llama.cpp and MLX with f16 and 8-bit KV caches
Decode speed-up from a 0.5B draft model by number of draft tokens, for structured and open prompts
Decode speed-up from a 0.5B draft model by number of draft tokens, for structured and open prompts
Log-probability gap between the target's top two tokens at each divergence, all below 0.04 nats against a median gap of 5.36 over all tokens; repeats identical 8 of 8, with a draft 3 of 8 (7B) and 6 of 8 (1.5B)
Log-probability gap between the target's top two tokens at each divergence, all below 0.04 nats against a median gap of 5.36 over all tokens; repeats identical 8 of 8, with a draft 3 of 8 (7B) and 6 of 8 (1.5B)
Decode throughput on the Air M5 at 0.39 to 0.75 times the M4 Pro for llama.cpp and MLX, and prefill tokens per second against prompt length
Decode throughput on the Air M5 at 0.39 to 0.75 times the M4 Pro for llama.cpp and MLX, and prefill tokens per second against prompt length