MTPLX icon indicating copy to clipboard operation
MTPLX copied to clipboard

Feature: prompt-lookup (n-gram copy) drafting alongside the MTP head for input-grounded workloads

Open ashalliants opened this issue 5 months ago • 6 comments

Summary

Feature suggestion: prompt-lookup (n-gram copy) drafting as a supplementary draft source alongside the MTP head, for input-grounded workloads (code editing, multi-turn agents, summarization) where long spans of the output are verbatim copies of tokens already in context.

Evidence from a sibling runtime

I recently benchmarked prompt-lookup drafting on dense Qwen3.6-27B (Apple M5, 32 GB, 4-bit) via dflash-mlx, which ships a hybrid drafter: try an n-gram match against prompt+committed tokens first, fall back to the neural drafter on a miss (after fixing a gating bug — bstnxbt/dflash-mlx#36). On a code-edit prompt (model re-emits a ~100-line file with a small refactor, 3072 generated tokens, greedy):

backend tok/s notes
mtplx 0.3.7, --mtp (quickstart defaults, depth 3) 16.6 server-reported tok_s
draft-model spec + prompt-lookup hybrid 32.0 copy drafting covered 74.5% of generated tokens
same, fresh-code prompt (nothing to copy) 18.6 vs 15.4 parity-or-better on the unfavourable case

The dense-model economics are what make this interesting for MTPLX specifically: each verified copy block replaces up to ~15 sequential decode steps with one verify pass, and on a dense 27B those steps are expensive. The drafting itself is trivial (rolling-hash window match over context tokens — no extra model, no extra memory beyond a small index).

Why I'm filing it here

MTP depth on Apple Silicon tops out around D2/D3, which caps the per-cycle speedup on copy-heavy output. A prompt-lookup pass in front of (or fused with) the MTP head would let the verify path consume much longer draft blocks exactly where they're free. The main open question is whether mtplx's verify strategies (e.g. capture_commit with the linear-GDN conv-tape rollback) can verify variable-length blocks beyond MTP depth, or whether that's a deeper change — you'd know best.

Happy to share the benchmark prompts/harness or run comparisons on M5/32GB hardware if useful.

ashalliants avatar Jun 05 '26 13:06 ashalliants

One methodological note for fairness: the 16.6 tok/s mtplx figure above was measured with quickstart default sampling (temperature 0.6, depth 3), while the draft-model+prompt-lookup rows were greedy. Greedy decoding would likely lift the MTP number somewhat (higher acceptance), so treat the exact gap as approximate — the qualitative point (prompt-lookup drafted ~75% of tokens on the edit workload, which depth-capped MTP drafting can't reach) is unaffected.

ashalliants avatar Jun 05 '26 13:06 ashalliants

As offered — prompts and harness behind the numbers above: https://gist.github.com/ashalliants/91819d410f6822e406a314740c8b7d0e. edit_prompt.txt/fresh_prompt.txt are the exact workloads; the README documents environment and methodology (including the sampling caveat noted earlier).

ashalliants avatar Jun 05 '26 14:06 ashalliants

This is a great idea, Currently working on a massive release and will implement this as a follow-up update.

youssofal avatar Jun 07 '26 01:06 youssofal

Awesome stuff, let me know if you need any help happy to contribute pr's as needed

ashalliants avatar Jun 07 '26 07:06 ashalliants

Still interested in this for input grounded workloads, and the speculative path rework happening now makes it easier to slot a second draft source in cleanly. No date, but it is not dead.

youssofal avatar Aug 23 '26 11:08 youssofal

Shipped, in stages, and 2.10.0 completes it. Context copy is exactly this: when the stream's tail matches an n-gram in the prompt, up to 24 tokens are proposed as one block and verified in one forward pass alongside the MTP head, with the same probability-ratio acceptance, so sampling is identical at any temperature. On a file rewrite it measures 87.6 tok/s against 73.8 for a fresh build. 2.10.0 added the batched-lane version and made short turns stop paying for misfires.

youssofal avatar Aug 29 '26 12:08 youssofal