Skip to content

spec: add initial adaptive draft length heuristic (curently mtp only) - #25726

Open
Us5rName wants to merge 6 commits into
ggml-org:masterfrom
Us5rName:draft-adaptive-length
Open

Us5rName wants to merge 6 commits into
ggml-org:masterfrom
Us5rName:draft-adaptive-length

Conversation

@Us5rName

@Us5rName Us5rName commented Jul 15, 2026 •

Copy link
Copy Markdown

Overview

related issue: #24768
This PR Adds a simple heuristic for adjusting the length of generated drafts during runtime (mtp only currently)
UPDATE: I added a more sophisticated heuristic using a rolling window in this branch, based on this code.
So this PR is more of an initial poc

Additional information

The simple heuristic algorithm works as follows:

we define

  • Threshold N

  • Bias B

  • "success" - the target model accepting the full draft minus B tokens.

  • "failure" - the opposite of success.

  • If a "success" happens N times in a row, then increase the size of the generated by one, and if a "failure" happens N times in a row, reduce the size of the generated draft by one.

  • Draft size never goes past --spec-draft-n-min or --spec-draft-n-max.

N is configurable via the cli arg --spec-draft-adaptive-length-threshold (defaults to 0, i.e. disabled)

*N=11 worked well for me (i.e. draft size stayed mostly constant after adjusting to the workload)

B is configurable via the cli arg --spec-draft-adaptive-length-bias (defaults to 0)

*Sometimes a bias of 1 when testing on gemma 4 gave me better results than a bias of 0.

I do not recommend enabling --draft-p-min with this flag, as it was not tested and no thought was put into the interaction between the flags.

Currently, the heuristic doesn't work when --spec-draft-n-min is 0.

Code is intentionally limited to mtp implementation to make needed refactoring easier.

I tested PR with the prompts

"Write a long relaxing story" for prose
and
"Write 15 python functions" for code

using the vulkan backend with llama-server

How to test:

llama-server \ 
     --spec-draft-adaptive-length-threshold N>0 \
     --spec-draft-adaptive-length-bias B>=0 \
     --draft-p-min 0 \
     --spec-draft-n-min m>0 \
     --spec-draft-n-max M>m \
     ...

Requirements

@Us5rName
Us5rName requested a review from a team as a code owner July 15, 2026 15:42
@Us5rName Us5rName changed the title sped: add initial adaptive draft length heuristic (curently mtp only) spec: add initial adaptive draft length heuristic (curently mtp only) Jul 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant