Skip to content

spec : reset ngram-cache state between requests - #27866

Open
Beatrice0377 wants to merge 2 commits into
ggml-org:masterfrom
Beatrice0377:fix-ngram-cache-request-state
Open

spec : reset ngram-cache state between requests#27866
Beatrice0377 wants to merge 2 commits into
ggml-org:masterfrom
Beatrice0377:fix-ngram-cache-request-state

Conversation

@Beatrice0377

@Beatrice0377 Beatrice0377 commented Aug 28, 2026

Copy link
Copy Markdown

Overview

common_speculative_impl_ngram_cache::begin() was a no-op, so a new request on a reused slot kept the previous request's per-sequence context n-gram cache and its cache_size offset. The new prompt was then either never re-ingested (shorter prompt) or ingested from the wrong offset, and drafts came from stale n-grams (acceptance dropped from 86% to 11% in the report).

begin() now clears sinfo.ngram_cache_context and resets sinfo.cache_size to 0. The static and dynamic caches are shared across requests by design and are not touched.

The regression test in tests/test-arg-parser.cpp runs two requests on the same seq_id: the second one ends with an n-gram that only exists in the first request's context cache, and it asserts the second request produces no draft. It fails before the fix and passes after.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - I used an AI coding assistant for the fix and the test. I traced the ingest/draft path to confirm the root cause and verified the test fails pre-fix and passes post-fix.

@Beatrice0377
Beatrice0377 requested review from a team and ggerganov as code owners August 28, 2026 09:04
@ggml-gh-bot

ggml-gh-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

Hi @Beatrice0377, 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 Aug 28, 2026
@github-actions github-actions Bot added the testing Everything test related label Aug 28, 2026
@github-actions
github-actions Bot marked this pull request as draft August 28, 2026 09:18
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Aug 28, 2026
@Beatrice0377
Beatrice0377 force-pushed the fix-ngram-cache-request-state branch from e67c784 to 2e61742 Compare August 28, 2026 09:44
Reset the per-sequence context n-gram cache and its size when a new
request begins (begin). Previously begin was a no-op, so a sequence
reused by a new request kept the n-grams ingested by the previous
request. This made the draft for the new request depend on stale
context, e.g. dropping acceptance from 86% to 11% in server scenarios
that reuse slots across requests. The static and dynamic caches are
intentionally shared across requests and are left untouched.

Assisted-by: Sisyphus
Adds no new test file, per project convention.

Assisted-by: Sisyphus
@Beatrice0377
Beatrice0377 force-pushed the fix-ngram-cache-request-state branch from 2e61742 to 8492c2e Compare August 28, 2026 09:54
@Beatrice0377
Beatrice0377 marked this pull request as ready for review August 28, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant