← Blog · · 10 min read

Speculative decoding for Qwen3.6-27B on an M3 Max with a 9B draft: 0.51x to 1.18x in MLX

On this page (7 sections)
  1. TL;DR
  2. The question
  3. Setup
  4. Results
  5. Surprises and caveats
  6. Reproduce it
  7. Conclusion

TL;DR

The question

Speculative decoding is often sold as a free 2-3x speedup. A small draft model proposes k tokens, the large target model checks them all in one forward pass, and every accepted token saves one full target step. mlx_lm exposes it as a single flag.

Many published numbers come from datacenter GPUs, often with drafts much smaller than the target. Our setup is different. Decode on Apple Silicon is limited by memory bandwidth, and the only same-family draft we have locally is a 9B model, about a third the size of a 27B target. So we wanted to know three things: does it help at all, how does the result depend on the task and on k, and does a speculated dense 27B ever beat simply running the 35B-A3B MoE we already use?

Setup

Machine and software. An Apple M3 Max with 64 GB, on AC power, running macOS 27.0.1 (Darwin 27.0.0). The chip and memory size come from MLX's device_info (Apple M3 Max, memory_size 68719476736 bytes). The 64 GB M3 Max ships only with the 40-core GPU (about 400 GB/s memory bandwidth), which matters for a bandwidth-bound workload like this. We used Python 3.13.5 (miniconda), mlx 0.31.2, mlx-lm 0.31.3, numpy 2.4.2 and transformers 5.12.1. sysctl, system_profiler and sudo-only powermetrics were unavailable to the run, so thermal state was logged with pmset -g therm only. It reported no thermal or performance warnings before or after the run.

Models (mlx-community, 4-bit, HF commit hashes in the raw data):

Tokenizer check first. We planned to use Qwen3.8-27B as the main target. Before any GPU run we compared tokenizers. Qwen3.8 has the same vocabulary and the same special tokens as the 9B draft, but its pre-tokenizer config differs. Our sample text is 2931 tokens with the draft's tokenizer and 2935 with Qwen3.8's, and the ids diverge at token 2894. Our English chat prompts happened to tokenize identically, but we only allowed pairs with identical tokenization, so Qwen3.8 was dropped. Qwen3.6-27B and the 35B-A3B both matched the draft exactly.

Prompts. We wrote 12 prompts in 4 categories of 3:

The chat template was applied with thinking disabled (enable_thinking=False) for every model.

Method.

We planned k=6 and a temperature 0.7 pass too. The script's time budget dropped both before the run started. Of the 108 timed dense runs (12 prompts x 3 configurations x 3 repeats), 2 were cut at the deadline, so two cells (baseline/code and one speculative cell) have 8 runs and the rest have 9.

The stock path does not work. The first thing the benchmark does is try mlx_lm's own speculative decoding. It fails:

ValueError: Speculative decoding requires a trimmable prompt cache (got {'ArraysCache'}).

Qwen3.5/3.6 are hybrid models. Their Gated DeltaNet layers keep a recurrent state (ArraysCache) next to a normal KVCache. mlx_lm rolls back rejected draft tokens by trimming the cache, and a recurrent state cannot be trimmed. Our specdec.py is mlx_lm's loop with one change: non-trimmable layers are rolled back by restoring a snapshot. For the draft, which runs one token at a time, we keep a snapshot after every step. For the target, which verifies k+1 tokens in a single pass, no intermediate state exists. So after a rejection we restore the state from before the verify step and run the accepted tokens through the target again. This is the core of it:

# 2) verify all drafts with one target forward pass over [y, d1..dk]
target_snap = snapshot(model_cache) if target_hybrid else None
verify_in = mx.concatenate([y, draft_tokens])
tokens = step(model, model_cache, verify_in, num_draft + 1)
mx.eval(tokens, draft_tokens)
draft_list, tok_list = draft_tokens.tolist(), tokens.tolist()

# 3) accept the longest matching prefix, then emit the target's own next token
n = 0
while n < num_draft and tok_list[n] == draft_list[n]:
    n += 1
    ...

# 4) roll both caches back to "prompt + accepted tokens"
if n < num_draft:
    if target_hybrid:
        rewind(model_cache, target_snap, num_draft + 1)
        with ctx():
            model(verify_in[: n + 1][None], cache=model_cache)  # re-forward
        stats["target_reforwards"] += 1
    else:
        rewind(model_cache, [None] * len(model_cache), num_draft - n)
    rewind(draft_cache, draft_snaps[n], num_draft - n - 1)

The re-forward cost is included in every speculative number below. As a correctness check we diffed every greedy speculative output against the greedy baseline. All 71 of 71 were token-identical, and baseline repeats matched each other in 23/23 runs.

Results

Decode throughput is the median across runs, in tokens per second. Speedup is the speculative median divided by the baseline median. Acceptance is accepted draft tokens divided by proposed draft tokens.

Category Baseline tok/s k=2 tok/s k=2 speedup k=2 accept k=4 tok/s k=4 speedup k=4 accept MoE tok/s
code 18.3 21.1 1.15x 95.8% 21.6 1.18x 93.1% 97.6
extract 17.5 18.7 1.07x 86.2% 16.7 0.96x 77.5% 97.8
explain 17.7 15.9 0.90x 72.3% 13.4 0.76x 59.5% 97.3
creative 17.3 12.0 0.69x 52.6% 8.9 0.51x 38.4% 99.3
all 17.7 16.9 0.96x 74.5% 15.0 0.85x 61.6% 97.6

The pattern follows acceptance closely. Code refactors copy large parts of the input, so the draft guesses right almost every time and speculation pays off a little. Extraction is in between. On open-ended prose the draft is wrong about half the time, and each miss costs a draft pass, a wasted verify and a rollback re-forward. On creative prompts at k=4 the target needed 85 re-forwards per 256-token run on average. On code at k=2 it needed fewer than 5. Raising k from 2 to 4 helped only on code.

End-to-end time tells the same story. On creative prompts, 256 tokens took a median of 15.2 s without a draft and 29.4 s at k=4, about 1.94x as long. Speculation also adds the draft's prefill to time-to-first-token. On the long code prompts TTFT went from 2768 ms to 3487 ms at k=2, roughly 718 ms more.

The MoE question has a simple answer on this machine, as far as speed goes. Qwen3.6-35B-A3B decoded at 96-100 tok/s on every prompt, finished 256 tokens in a median of 2.83 s, and peaked at 20.3 GB, against 21.4-21.5 GB for the 27B + 9B pair. Measured against the fastest dense configuration in each category, it was 4.51x faster on code, 5.22x on extract, 5.51x on explain and 5.73x on creative. This is a throughput-only comparison: the MoE is a different model, its outputs differ from the 27B's, and we did not evaluate the output quality of either. Our hypothesis is that the MoE reads only its active experts per token, so it moves far fewer bytes per step than a dense 27B. We did not measure that directly.

Why the textbook formula overshoots

The classic expected speedup is (1 - a^(k+1)) / ((1 - a)(k*c + 1)), where a is per-position acceptance and c is the cost of a draft step relative to a target step. We measured c with a forward-pass microbenchmark at a 474-token context: 16.2 ms per draft step against 48.0 ms per target step, so c = 0.338. With that c, the classic formula predicted 1.74x to 2.02x on code. We measured 1.15x to 1.18x. Across all cells its mean absolute error was 0.631x.

The formula assumes that verifying k+1 tokens costs the same as one target step. On our machine it does not: one target forward over 3 tokens took 60.4 ms (1.26x a single step), and over 5 tokens it took 93.2 ms (1.94x). When we put the measured verify costs and the rollback re-forward costs into the model, the mean error fell to 0.165x. A single run fits that model almost exactly: the first k=2 run on the code_method prompt accepted every draft token and decoded at 32.9 tok/s, against 3 tokens / (2 x 16.2 + 60.4 ms) ≈ 32 tok/s predicted. The remaining gap across cells is still optimistic, for example 1.47x predicted against 1.15x measured on code at k=2. We have not explained that part. One hypothesis is thermal state: the microbenchmark ran on a cool machine, while baseline speed later fell from about 23 to about 18 tok/s.

The microbenchmark also shows that a 2-token target forward costs almost the same as a single step (49.2 vs 48.0 ms). That suggests k=1 might be the best setting for this pair. We did not test it.

For drafts much smaller than ours, the classic model predicts larger gains: at a=0.8 and k=4, 2.40x for c=0.1 and 2.80x for c=0.05. Given how far the classic model overshot here, treat those as upper bounds, not as expectations.

Surprises and caveats

Reproduce it

Scripts, prompts, the raw per-run CSV, results.json and plots are at https://hackbig.com/blog-data/speculative-decoding-mlx-m3-max/. The run is offline and needs the models in your local HF cache. run.sh hardcodes a miniconda Python path (/opt/homebrew/Caskroom/miniconda/base/bin/python) and installs the analysis environment from a local ./wheels directory, so adjust both for your machine.

./run.sh                 # full run: env log, tokenizer check, dense + MoE benchmarks, analysis
./run.sh --smoke         # CPU-only pipeline test with a synthetic backend (fake numbers)
python test_specdec.py   # rollback-logic test with a numpy stand-in for mlx.core

run.sh requests k=6 and the temperature pass too, and passes --budget-s, --deadline, --reserve-s 45 and --out. Its budget planner is what removed k=6 and the temperature pass in our run. To run only the configurations reported here, without the budget planner:

python bench.py --model mlx-community/Qwen3.6-27B-4bit \
  --draft mlx-community/Qwen3.5-9B-MLX-4bit --configs base,k2,k4 --reps 3 \
  --draft-alone --microbench --stock-check --tag target --out out

If you have a smaller draft that tokenizes identically to a Qwen3.6 target, we would like to see your numbers.

Conclusion

On our M3 Max, a 9B draft gave Qwen3.6-27B at most 1.18x, and only on code. It slowed down prose by up to half. In raw decode speed, the 35B-A3B MoE was more than 4.5x faster than any speculative setup we tried. We did not compare output quality, so check that the MoE's output is good enough for your task before switching.

Code and raw data for this post

How this was made: an AI agent (Claude) designed and ran this experiment on our own MacBook in a sandbox; every number comes from the run's results file (linked below), checked by script before publishing.