Open Source

Marzukia's qMLX fork fixes 3 bugs making Qwen3.5-122B long-context usable on Mac Studio

Prefill time dropped from minutes to sub-seconds after fixing KV cache mismatches

Deep Dive

Running large language models locally for long-context agentic coding has long been a pain point — high memory requirements, agonizing cold starts, and unreliable caching. Developer marzukia recently switched from DS4 Flash to Qwen3.5-122B on an M3 Ultra Mac Studio with 96GB of unified memory, expecting better context handling. Instead, they hit 3–5 minute delays on every follow-up message despite a 'warm' context. After digging into the qMLX serving stack (a fork of rapid-mlx), they uncovered three distinct bugs that were destroying KV cache efficiency.

The first bug, prompt instability, stemmed from a unique message ID embedded in the system prompt that broke byte-exact KV cache matching — forcing a full re-computation on every turn. The second, interrupt path, meant streaming replies weren't persisted when a generation was interrupted, causing history divergence on the next call. Finally, checkpoint poison: a background writer created unmatchable checkpoint files that crowded out valid ones, triggering aggressive eviction of cached tokens. After fixing all three, prefill time for 168k-token sessions dropped to 2.6–4.8 seconds with delta prefills as low as 67 tokens. The developer open-sourced the fork (qMLX) and a benchmark script (bench_qmlx.py) that separates prefill and decode metrics, noting that the hybrid attention optimizations are highly specific to Qwen and unlikely to be merged upstream.

Key Points
  • Prompt instability: a unique message ID in the system prompt broke byte-exact KV cache matching, forcing full re-compute on every turn
  • Interrupt path and checkpoint poison: streaming replies weren't persisted and background checkpoints crowded out valid ones, causing aggressive eviction
  • After fixes, 168k-token contexts prefilled in ~2.6s with only 67–1,782 delta tokens recomputed per turn

Why It Matters

Makes long-context agentic coding practical on local hardware, slashing latency for real-time AI assistants.

📬 Get the top 10 AI stories daily