Tur
Chapters

Architecture

Speculative decoding

Decoding one token per pass leaves the GPU underused, because the weights are read for a single row of work. Speculative decoding guesses several next tokens cheaply and checks them all in one pass. Every guess that turns out right is a token that didn't need a pass of its own. It's opt-in: it raises throughput when guesses are often right, but tokens then arrive in small bursts.

Where drafts come from

Prompt lookup (--speculative-draft N) looks for the longest recent run of 1 to 4 tokens that also appeared earlier in the request's prompt or output, and proposes whatever followed it last time. It costs almost nothing and works well when output repeats its input, as in code edits, extraction or JSON with repeated keys. If the continuation reaches the end of the history, it repeats with the period between the two occurrences, so a short cycle can fill the whole draft.

The MTP head (--mtp) ships inside Qwen3.5 checkpoints. It is a single extra layer that combines the embedding of the token at p + 1 with the model's final hidden state at p and predicts the token at p + 2. Tur runs the head after each pass over the newly committed positions, writing its own keys and values, and uses its draft when prompt lookup has nothing better.

The Gemma 4 assistant (--draft-model) is a four-layer drafter Google publishes for each Gemma 4 size. It combines the target's embedding of the token at p + 1 with the target's final hidden state at p, and attends at position p + 1 over the target's own keys and values, so it needs no state of its own. Its output covers only the tokens in its 32 best-scoring vocabulary clusters (4,096 of 262,144 on E2B), which keeps it cheap. With one request decoding, it chains drafts: each next step feeds its own greedy draft back in at the same position, as Transformers' assisted generation does.

Inkling 2's drafter (--mtp) ships beside the checkpoint in mtp.safetensors; vLLM and SGLang call it DSpark. After every pass, each new position mixes four target features (the residual stream entering layer applications 5, 23 and 41, and the final-normed output) and writes keys and values into three draft layers. A draft runs one block: the next token's embedding and seven learned mask rows through those layers, attending in both directions over the context and the block, so each mask predicts the token at its position. A small recurrent head then walks the masks in order and adds a bias from the token it just drafted before each greedy pick, folded into the unembedding once at load so a step costs a 256-wide projection. One block yields seven chained drafts for about the cost of one: give it room with --speculative-draft 7.

Verification is exact

The engine asks for logits at every drafted position and checks drafts by target matching:

  1. Draw a token from the model's full distribution at the first drafted position, after penalties, temperature and truncation.
  2. If it equals the draft, accept it and move to the next position.
  3. At the first mismatch, publish the model's own draw and discard the remaining drafts.
  4. If every draft matches, also publish the draw at the last row as a bonus token.

A draft d is accepted with exactly the probability the model gives it, and a mismatching draw already follows the model's distribution over everything else. So the published tokens follow the model's distribution exactly: the same seed gives the same tokens as normal decoding. Unlike classic speculative sampling, there is no min(1, p/q) correction and no draft tree.

Undoing rejected drafts means restoring the accepted boundary. Fused Qwen verification keeps one recurrent output slot and small projection records. If it accepts only part of a pass, it replays those rows from the original state into that slot using the same convolution and scan kernels, then waits for completion before releasing the old state. Full acceptance needs no replay. Reference execution keeps a slot at each candidate position. Attention pages past the accepted boundary are released. The random stream, penalties and grammar state advance only for published tokens.

Drafting only when it pays

Verifying drafts costs GPU time, and a wrong draft wastes it. Tur keeps track of both sides:

  • Each request estimates how often its drafts are accepted, separately for each draft source. Lookup's estimate starts neutral for every request, so one request's rejected drafts can't stop drafting for later ones.
  • DraftCosts fits measured GPU time against the number of drafted tokens, separately for each number of decoding requests.
  • Planning drafts the most likely tokens first and stops where expected tokens per second would start to fall. A pass drafts only if the predicted gain exceeds 5%, because the cost fit sees device time and verified rows also cost host work. When a larger batch makes verification more expensive, speculation turns itself off.
  • When planning has turned drafting off, a pass drafts anyway after 16 skipped passes, and the interval doubles up to 256. Without new drafts, a per-draft cost measured too high could never be corrected.

The MTP head and the Gemma assistant have extra gates:

  • Each draft carries the head's own probability, calibrated online against how often such drafts were accepted.
  • The head runs only while its acceptance rate is at least 0.3, with at most four requests decoding, and only while it is predicted to pay. Its acceptance estimate counts only the first head draft of each verification.
  • The assistant chains drafts only when one request is decoding, and only while the chance of reaching the next draft stays at least 0.3. Verification keeps the leading drafts of a chain while their calibrated acceptance rates multiply to at least 0.3.
  • A block head (Inkling 2's) computes its whole block when it drafts, because deeper drafts cost little more, and verification keeps the likely ones by calibrated confidence. Whether a block pays is judged by the drafts calibration kept from its last block, against the head's cost for the drafts it computes.
  • A head turned off as unprofitable is retried after 16 passes, and the interval doubles up to 256 while it keeps losing.

Constraints

  • Speculation needs F32 recurrent state. With F16 or BF16 state, the pipeline logs a warning and decodes normally, because verifying several tokens keeps F32 intermediate state between drafts.
  • Grammar-constrained requests never draft, and the end-of-sequence token is never proposed.
  • Drafting needs projection records and output rows, which the memory plan reserves up front. Reference execution reserves a recurrent slot per candidate boundary instead of records.

Decisions

Measured on Qwen3.5-0.8B on an M1 unless noted:

  • Target matching over draft-model sampling. Outputs are identical to normal decoding; 1,278 same-seed comparisons produced identical tokens.
  • Speculation is an opt-in throughput mode. Prompt lookup ran 3.25× faster on repetitive single-request output, but tokens arrive in bursts with longer pauses between them, which hurts the slowest token gaps.
  • The MTP head drafts from a reduced vocabulary: the 32,768 lowest token IDs, through a copy of the output layer's first rows. Byte-level BPE numbers tokens in merge order, so these are the most frequent ones. This cut a head pass from about 6.5 ms to under 3 ms with unchanged acceptance; 16K tokens lost prose drafts and 64K added cost.
  • Calibrated confidence makes MTP useful with sampling. Drafts with confidence of at least 0.8 were 99% accepted, and those below 0.4 only 20%.
  • Lookup's acceptance starts neutral for each request instead of from a pipeline-wide rate. The shared rate fell after early rejections and new requests inherited it: over 16 mixed prose, code, JSON and chat requests, 13 verified no drafts and lookup stayed at 1.00×. With neutral starts, lookup gave 1.19× greedy and 1.14× sampled with one request, and up to 1.5× on JSON. Tokens matched normal decoding.
  • Planning requires a 5% predicted gain. Without it, lookup lost 2 to 3% with four requests, and with it lookup is level at about 1.00×. Lookup plus MTP on the same requests gave 1.25 to 1.32× greedy and 1.25 to 1.27× sampled with one request, and 1.10 to 1.24× with four.
  • Planning re-tests drafting after it has turned off. Some long runs stayed at 1.00× while others on the same code reached 1.14 to 1.20×. A stale per-draft cost is the suspected cause. This recovery has a unit test but no measured real-run gain yet.
  • Lookup plus MTP gives 1.12 to 1.38× normal decoding on new prose and code with one to four requests, greedy and sampled.
  • The head turns off above four decoding requests. At eight, its upkeep costs 3 to 5% and a draft costs nearly as much as decoding the token. For the same reason, a finer cost model wasn't built: it could gain at most about 10%.
  • Table-based drafters aren't used (see Rejected experiments). just bench drafter replays them over recorded tokens.
  • There is no learned drafter for Qwen. No smaller Qwen3.5 checkpoint exists to draft with, and no EAGLE-3, DFlash or DSpark drafter targets these checkpoints.
  • The Gemma assistant drafts one token per pass for several requests. On E2B (Q8_0, F16 K/V, greedy), lookup plus the assistant beat normal decoding by 1.42× on prose and 1.17 to 1.30× on code with one request, and 1.23× and 1.35× with four. On repetitive prompts, where lookup alone gives 3.2×, it changes little. About two thirds of its drafts were accepted, at about 2.9 ms each against a 47 ms decode, and all 36 runs reproduced normal decoding's tokens.
  • The Gemma assistant chains drafts with one request decoding. Against one draft per pass, chains were 1.14× faster on prose and 1.50× on repetitive text, and level on code. With four requests they lost 6% on prose and 13% on code, so chaining is limited to one request. Every run reproduced the single-draft tokens.
  • Expert checkpoints carry an MTP head too, whose single layer has its own routed experts and shared expert. It matches Transformers' MoE decoder layer on a tiny fixture within 2e-4, on the host and on the kernels, and its tensor shapes match the published Qwen3.6 header. On the real Qwen3.6-35B-A3B Q4K artifact it was accepted for 80 to 90% of its drafts on new prose and code, and lookup plus MTP gave 1.09 to 1.34× normal decoding with one to four requests, outputs identical to normal decoding (see Measured performance). That is one 36 GB M3 Pro, with the artifact's experts resident.
  • Inkling 2's drafter drafts whole blocks and lets calibration choose what to verify. Its first policy, the one-draft head's, priced a chain at its running acceptance raised to each depth (0.44 per draft), so it offered one draft and the cost gate turned it off: 48 ms per decode, 14 ms per verified row (each row brings 8 more experts into all 48 layer applications) and 8.6 ms per drafter pass. Forcing every block through showed what the drafter does: on code 3.9 tokens per verification and 1.45× normal decoding, with 164 of 177 drafts at confidence 0.9 or more accepted. With block-aware drafting on the M3 Pro, one greedy request decoded new prose 1.20× and code 1.17 to 1.55× faster than normal decoding, outputs identical.
  • Chained MTP drafts are the next candidate, estimated at about 10% with one request (see Open work).
  • Fused Qwen verification commits partial accepts by replay with F32 state. On the 0.8B, repetitive lookup output improved 7 to 8% at one, four and eight requests; code output ranged from 3% slower to 2% faster. Lookup plus MTP gave similar results, with identical tokens in every paired run. The plan saves 74 to 297 MiB after charging records (see Replay measurements).

Edit this page on GitHub