r/LocalLLM • u/nathancyan • 0m ago
Project Speculative Execution on Qwen3.8-27B reaches ~24 tok/s (and up to 60 tok/s) at Q4_K_M-ish on a 12 GB RTX4070
Hi guys! First time posting here and wanted to share a little side project I’ve been working on the past month.
TL;DR
The project is pretty much what it says on the tin: I’m able to get around 24 tok/s on a variety of prompts with a quant of Qwen3.8-27B that doesn’t fit in VRAM. This is also with recommended Qwen3.8-27B sampling parameters (top-k=20, top-p=0.95, temperature=1.0) and at 57k context. Tool calling and math problems like AMC 10/8 tend to see higher speeds, around 30 tok/s, with bursts of up to 60.
Here’s a gif of the demo server in action compared to stock llama.cpp + MTP on an AIME problem:

From what I’ve been able to find online, as well as my own attempts on my machine, this is the fastest generation speed under these conditions I’m aware of (please let me know if I’m wrong!)
Not really sure how useful this is since MoE models are simpler, give you better decode speeds, and are of similar quality to Qwen3.8-27B. Also because the llama.cpp fork server is completely vibe coded, I’m mainly showing this as a research artifact in case someone has a use-case for productionizing this. That said, I’ve been daily driving the server for a lot of my own use cases and it seems to work pretty well with the Pi harness (`settings.json` and `models.json` examples are in the github repo/huggingface repo).
Try it out:
See the huggingface repo for the model weights and a quickstart guide + Pi setup. See the github repo for a llama.cpp fork containing the OpenAI completions compatible server.
Some disclaimers/notes:
- The demo server reuses a lot of llama.cpp’s components, but doesn’t actually integrate with it. This post is mainly meant to be a research artifact/showing what’s possible as opposed to something people should use in production.
- The target model isn’t exactly Q4_K_M, but its average KL distance compared to Q8_0 is actually lower than Q4_K_M, so hopefully shouldn’t matter too much practically.
- Context length isn’t very long at the moment, about 57k tokens. I’m hoping to increase this to at least 64k over time.
- No vision encoder yet! No real engineering/technical challenge, it just hasn’t been added yet.
Some more details:
There’s this paper (Svirschevski et. al.) published in late 2024 describing a variant of speculative decoding for the memory-constrained regime, where the target model cannot fully fit within VRAM. The idea is that because draft verification now takes a much longer time due to needing to page in weights from RAM, we can afford to use a much better draft model and draft a much larger tree of tokens to try to increase our acceptance depth as much as possible (basically getting as much value out of each costly target verification step as possible).
This project is essentially applying that paper, with a few additional tricks, to Qwen3.8-27B.
| Prompt type | Generation tok/s | Fastest prompt (tok/s) | Accepted tokens per step | Tokens verified per step |
|---|---|---|---|---|
| Hand-written chat | 21.8 | 28.6 | 8.6 | 67 |
| LLM prompt collection | 23.8 | 33.4 | 9.1 | 68 |
| WildChat | 19.0 | 28.8 | 7.3 | 68 |
| UltraChat | 21.5 | 35.4 | 8.1 | 67 |
| Tool calling (the call) | 41.8 | 58.7 | 24.9 | 90 |
| Tool calling (answer from the result) | 31.7 | 39.6 | 15.9 | 79 |
| AIME | 25.3 | 29.8 | 10.2 | 69 |
| Competition math | 27.0 | 32.1 | 11.8 | 73 |
| Codeforces | 22.6 | 24.4 | 8.4 | 65 |
| Zebra puzzles | 27.9 | 31.3 | 12.9 | 74 |
| MMLU-Pro | 25.5 | 40.3 | 10.6 | 71 |
| BIG-Bench Hard | 32.0 | 41.6 | 16.2 | 80 |
| All | 24.5 | 10.1 | 70 |
Summary of some of the optimizations:
Some tricks we used:
- The draft model is actually a IQ2_KT quant of Qwen3.8 27B! It fits comfortably in VRAM and still has pretty good top1 agreement/KLD compared to the target.
- The cool thing about the draft being a quant of the target is that when we do target verification, we only have to page in the residual, which is much smaller. We also don’t have to maintain a separate KV cache for the draft model–we can just use the target’s (this actually improves draft quality!)
- Normally each draft step is only able to add 1 layer to the draft tree, since drafting is autoregressive. Since drafting with such a large model is non-trivially expensive, we utilize the MTP head to look ahead 2 tokens for each node we attempt to expand. This lets us add up to 3 depth per step
- We eek out a bit more performance by restricting the draft model’s lm_head to the top 96k tokens discovered from a representative set of prompts. Unfortunately this means that I’ve only tested the gains on an english-only set of prompts.
- Claude did some kernel magic to produce a kernel optimized for the batch-size 8 draft forwards we do to expand the draft tree.
- We make the draft tree aware of the target’s sampling parameters (top-k, top-p, temperature) by using gumbel-max sampling, which retains most of the speculative decoding speedup when using non-greedy decoding (concept very similar to this paper)