Skip to content

server : truncate speculative results at EOG before rollback - #28232

Closed
Lipenghee wants to merge 1 commit into
ggml-org:masterfrom
Lipenghee:codex/llama-cpp-28049-eog-tail
Closed

Lipenghee wants to merge 1 commit into
ggml-org:masterfrom
Lipenghee:codex/llama-cpp-28049-eog-tail

Conversation

@Lipenghee

@Lipenghee Lipenghee commented Sep 2, 2026 •

Copy link
Copy Markdown

Overview

Speculative decoding could return accepted draft tokens past an EOG within the accepted draft portion of the result. The server used this untrimmed result to compute draft acceptance, rollback, prompt contents, and model state before process_token() stopped generation, leaving client-visible output correct while acceptance statistics and slot state could include post-EOG tokens.

Search the accepted draft portion for its first EOG and truncate the full speculative result at that token before rollback or state updates. For FULL/recurrent memory, restore the checkpoint and replay only the valid prefix before EOG; if that prefix is empty, skip drafting once so the target can resample the terminating token without a replay loop.

Additional information

The regression test covers the ngram-simple 48-EOG draft case and verifies zero accepted drafts and no stale slot tail.
Fixes #28049

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES Used Codex to review the speculative decoding changes, refine code style, and suggest small implementation improvements around EOG handling and replay logic. I manually reviewed the resulting changes and verified the final behavior with the relevant regression tests and local checks.

Speculative decoding could return accepted draft tokens past an EOG within the accepted draft portion of the result. The server used this untrimmed result to compute draft acceptance, rollback, prompt contents, and model state before `process_token()` stopped generation, leaving client-visible output correct while acceptance statistics and slot state could include post-EOG tokens.

Search the accepted draft portion for its first EOG and truncate the full speculative result at that token before rollback or state updates. For FULL/recurrent memory, restore the checkpoint and replay only the valid prefix before EOG; if that prefix is empty, skip drafting once so the target can resample the terminating token without a replay loop.

The regression test covers the `ngram-simple` 48-EOG draft case and verifies zero accepted drafts and no stale slot tail.
@Lipenghee
Lipenghee requested a review from a team as a code owner September 2, 2026 07:31
@ggml-gh-bot

ggml-gh-bot Bot commented Sep 2, 2026

Copy link
Copy Markdown

Hi @Lipenghee, thanks for your contribution!

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

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

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

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Sep 2, 2026
@github-actions
github-actions Bot marked this pull request as draft September 2, 2026 07:37
@github-actions github-actions Bot added server and removed draft PR will be changed to draft by github-actions bot labels Sep 2, 2026
@Lipenghee
Lipenghee marked this pull request as ready for review September 2, 2026 08:08
@ethanhq

ethanhq commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

@Lipenghee I ran into the same issue (MTP on Qwen3.8-27B) and fixed it one level lower, in common_sampler_sample_and_accept_n: stop accepting at an EOG that has more draft tokens after it (ethanhq@55c6fd9f5, +5/-1). The rest then goes through the existing partial acceptance path, so the server needs no change and llama-speculative-simple is fixed as well. A trailing EOG still has to be accepted, since the draft of a checkpoint replay ends with the last target token.

Would you be open to switching to this approach? Otherwise I can open it as a separate PR and reference this one.

@philippesic

Copy link
Copy Markdown

#29638 fixed the mid-draft EOG case and closed #28049, but I found a broader version of the bug. Any stop on an accepted draft token, including stop strings, leaves stale tokens in the slot cache. I have a fix that trims the cache wherever process_token stops and leaves the acceptance counts alone. It doesn't cover the checkpoint rounds your PR handles, so the two partly overlap.

I'd like to open mine separately and link it here, unless you'd rather combine them.

@Lipenghee

Copy link
Copy Markdown
Author

Thanks @ethanhq and @philippesic, and sorry for the late reply.

#29638 already stops mid-draft EOG acceptance in common_sampler_sample_and_accept_n and closed #28049, including the checkpoint-replay loop, so the server-side truncation in this PR is no longer needed for that path.

#32771 covers the remaining non-checkpoint cases this PR did not handle — stop strings, end-of-draft EOG, and rejection-sampling mid-draft EOG — by trimming the slot cache after process_token. It also notes that checkpoint / FULL-memory rounds need a larger follow-up; I will leave that to #32771 rather than keep this overlapping branch open.

Closing this PR in favor of #29638 and #32771.

@Lipenghee Lipenghee closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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