Skip to content

common : stop accepting draft tokens at EOG - #29638

Merged
ruixiang63 merged 2 commits into
ggml-org:masterfrom
ethanhq:fix/spec-stop-at-eog
Sep 29, 2026
Merged

ruixiang63 merged 2 commits into
ggml-org:masterfrom
ethanhq:fix/spec-stop-at-eog

Conversation

@ethanhq

@ethanhq ethanhq commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Overview

common_sampler_sample_and_accept_n keeps accepting matching draft tokens after the target samples an EOG, so the tokens after the EOG stay in the context. On hybrid models this breaks prefix reuse: the next turn restores a checkpoint and re-processes the whole previous answer. This stops accepting at an EOG that is not the last draft token (on a checkpoint replay the draft ends with the target's own token, which can be EOG).

Fixes #28049. Alternative to #28232 (discussion): fixing it where the draft is accepted needs no server change and also covers llama-speculative-simple.

Additional information

  • Qwen3.8-27B with draft-mtp: master caches 3 extra tokens per answer and the next turn falls back to an earlier checkpoint, with the fix the whole answer is reused. With ngram-simple (checkpoint replay) master caches 16 extra tokens, the fix only the EOG.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, Claude Code assisted with debugging and the fix.

@ethanhq
ethanhq requested review from a team as code owners September 29, 2026 10:10
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 29, 2026

Copy link
Copy Markdown

Hi @ethanhq, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

Comment thread common/sampling.cpp Resolved
@ethanhq
ethanhq requested a review from ruixiang63 September 29, 2026 14:34
@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Sep 29, 2026
@ruixiang63
ruixiang63 merged commit d280808 into ggml-org:master Sep 29, 2026
13 checks passed
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 7, 2026
* common : stop accepting draft tokens at EOG

* cont : remove the test

(cherry picked from commit d280808)
Achilles1089 added a commit to Achilles1089/llama.cpp that referenced this pull request Oct 15, 2026
…gml-org#29869 + ggml-org#30065, without their MUL_MAT+ADD fusion); stop accepting draft tokens at EOG (ggml-org#29638); graph capture flag fix (ggml-org#29390)

The 2..16-row mat-muls that MTP verify produces ran on mat-vec kernels whose time grows with every row. Measured on
the M1 Ultra with Raven's Qwen3.8-27B Q8_0 shapes: 8 rows now cost 1.6-1.9x one row (was 3.3-3.8x), matching
upstream within 1-3%. End to end (temp 1.0, 512 tokens): at --spec-draft-n-max 6 --spec-draft-n-min 1
--spec-draft-p-min 0.6, code echo 34.9 -> 54.7 tok/s and tool JSON 35.2 -> 54.9, prose level (25.6 -> 25.9).
Greedy output is identical to the previous build, with and without drafting. test-backend-ops MUL_MAT: 1163/1163.
The capture fix: the -1 capture counter was passed as a bool, so every node of every graph got debug-group markers.
philippesic added a commit to philippesic/llama.cpp that referenced this pull request Nov 21, 2026
common_sampler_sample_and_accept_n_rejection kept accepting draft tokens
after an accepted EOG and then drew a bonus token. Stop at an EOG that is
not the last draft token, as common_sampler_sample_and_accept_n does
since ggml-org#29638.

Assisted-by: Claude Opus
philippesic added a commit to philippesic/llama.cpp that referenced this pull request Nov 21, 2026
common_sampler_sample_and_accept_n_rejection kept accepting draft tokens
after an accepted EOG and then drew a bonus token. Stop at an EOG that is
not the last draft token, as common_sampler_sample_and_accept_n does
since ggml-org#29638.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server: speculative decoding keeps accepted tokens past the EOG, costing the whole previous answer on hybrid models

3 participants