Skip to content

server: do not recover prompt below cache-ram-similarity and other cleanup#2105

Merged
ikawrakow merged 2 commits into
mainfrom
fcp/server_cleanup
Jul 10, 2026
Merged

server: do not recover prompt below cache-ram-similarity and other cleanup#2105
ikawrakow merged 2 commits into
mainfrom
fcp/server_cleanup

Conversation

@firecoperana

Copy link
Copy Markdown
Collaborator

Supersedes #1877 as it is now stale

What it does now is that it does not restore the prompt if common prefix/cached prompt size less than cache-ram-similarity, which is the threshold that triggers the prompt caching. It makes the restoring process consistent with the saving process.

Other minor changes:

  1. Fix small bug in size_up_to_pos. With mtmd and max_pos=0, it should return 0 instead of 1. Add the check before the while loop.
  2. Simplify get_common_prefix steps
  3. Restore the checkpoint after n_past is subtracted by 1 to reflect "we have to evaluate at least 1 token to generate logits". apply_checkpoint() should happen after the final n_past. Noticed this bug after Bug: KV cache prompt comparison runs before checkpoint restore, causing erroneous re-evaluation (with proposed fix) #2033

copy_data_to_cached_prompt(tokens, *ret);

ret->prompt_load(*prompt_cache, task.tokens);
ret->prompt_load(*prompt_cache, task.tokens, cache_ram_similarity);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this to min_reusable_fraction to match the actual meaning?

@ikawrakow
ikawrakow merged commit 606d9db into main Jul 10, 2026
joelfarthing added a commit to joelfarthing/ik_llama.cpp that referenced this pull request Jul 10, 2026
Bring the openPangu-2.0-Flash port up to date with current main
(70ea152). Two files conflicted; resolutions:

- docs/parameters.md: keep the MTP heads key and default/experimental
  contract; add main's dflash stage, cross_ctx key, and draft-model example.
- examples/server/server-context.cpp: keep the partial-KV-reuse and MTP
  fresh-warmup reset guards; adopt ikawrakow#2105's prompt-cache cleanup and
  reusable-fraction behavior around them.

Merged tree is byte-identical to the validated integration tree
c3e9b73.
@firecoperana
firecoperana deleted the fcp/server_cleanup branch July 10, 2026 13:13
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.

2 participants