We built a custom in-browser runtime for Astro.
Full tsx/mdx compilation, visual CMS, live preview, AI editing agents - all running in the browser.
Create a branch, edit content visually, preview instantly, merge & deploy to the edge.
Result on GLM-4.7-Flash with a 2K to 16K token prompt: the checking step goes from 414 ms to 28 ms, and speculative decoding goes from 7.1 to 64.4 tokens a second. Before the fix it was slower than not using it. After, it is 1.35ร faster than plain decoding.
Follow-up: mlx-vlm #2141 is closed, the work is now @Blaizzy/mlx-vlm#2150 and covers ten MLA models instead of one. On Moonlight-16B at 32K context a two-token verify step goes 380.8 ms โ 22.1 ms. @Prince_Canuma CI needs an approving run when you get a chance ๐
The fix is to work out, per model, how many tokens the fast path stays fast for. That number depends on the model's shape, not on how long your prompt is. It is 170 for the DeepSeek-style models and 398 or 512 for GLM. Then use the fast path up to that number.
The models have a fast path and a slow path for attention, and the fast path was only switched on when handling exactly one token. Checking guesses always handles two or more. So every check took the slow path.
Speculative decoding works by guessing a few tokens ahead, then checking them all in one go. The checking step is supposed to be cheap. On these models it was re-doing work over the entire conversation every time, so the longer your chat, the slower it got.
Speculative decoding on DeepSeek-lineage models in mlx-lm was slower than not speculating. On GLM-4.7-Flash at long context it ran at 0.15ร plain decode. The cause was one comparison operator. Write-up with all the measurements and fix: