llama.cpp icon indicating copy to clipboard operation
llama.cpp copied to clipboard

Feature Request: plugin interface for drafters/spec decode interface

Open Cyronius opened this issue 1 week ago • 0 comments

Prerequisites

  • [x] I am running the latest code. Mention the version if possible as well.
  • [x] I carefully followed the README.md.
  • [x] I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • [x] I reviewed the Discussions, and have a new and useful enhancement to share.

Feature Description

I've been working on a fast-but-slightly-stupid drafter I'm calling MemDraft, and would like to add a way for external drafters to plug into llama.cpp without having to maintain them in-tree. More broadly, it would be nice to be able to experiment with different drafting techniques without having to patch llama.cpp every time.

I've broken this into three stages:

Stage 1: A basic plugin interface that takes committed tokens and returns draft tokens. This is all MemDraft needs at its most basic level.

Stage 2: Adds access to hidden states, decode callbacks, and per-drafter state. This would allow things like external MTP heads.

Stage 3: Allows drafters to work together. For example, MTP could draft one token and MemDraft could draft three more. This is where I've gotten the best results so far.

For qwen 9b on my modest hardware:

Setup Coding prompts HumanEval
Plain decoding 38.0 tok/s (1.00×) 38.2 tok/s (1.00×)
MemDraft alone¹ 69.4 tok/s (1.82×) 88.2 tok/s (2.31×)
ngram-simple alone 43.3 tok/s (1.13×) 73.7 tok/s (1.93×)
ngram-simple, then MemDraft 70.5 tok/s (1.85×) 125.5 tok/s (3.29×)
The MTP head alone (draft-mtp, 3 tokens) 73.9 tok/s (1.94×) 88.0 tok/s (2.30×)
ngram-simple, then the MTP head, then MemDraft 81.6 tok/s (2.14×) 136.3 tok/s (3.57×)
ngram-mod 41.0 tok/s (1.08×) 67.8 tok/s (1.78×)

Each stage is a reasonable stopping point. There are still some edge cases around checkpointing, state management, and combined drafts that need testing.

I'd like to get some feedback from the maintainers on whether this is something they'd be open to supporting, and how much of the proposed interface makes sense to have upstream.

MemDraft can be found here and the patch against llama.cpp here. If the maintainers are amenable to this approach, I can submit the changes as stacked PRs or a single PR, whichever is preferred.

Motivation

I would like to add a way for external drafters to plug into llama.cpp without having to maintain them in-tree or patch llama.cpp every time.

Possible Implementation

proposed patch here

Cyronius avatar Nov 25 '26 17:11 Cyronius