Repository navigation
llama-server: Avoids extra copying of existing checkpoints - #30683
sarahwu185 wants to merge 20 commits into
Conversation
964b2a3 to
305ef39
Compare
| // cache reuse shifted chunks over the tokens this checkpoint covers | ||
| if (n_past > n_prefix && cur.n_tokens > n_prefix) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
These changes also seem to fix a bug on master where, with --cache-reuse, deleting a chunk from the middle of the prompt can restore a checkpoint that still has the deleted tokens and produce wrong output. This branch gets it right. Repro: tinygemma3 with -c 1024.
No test seems to cover this, could you maybe add one and mention it in the description?
There was a problem hiding this comment.
Yeah thanks, I have added a test
|
Please rebase again. @tdakhran Could you help with review here? |
tdakhran
left a comment
There was a problem hiding this comment.
looks right to me, tested with internal harness locally and observed no regressions.
Can confirm that it fixes --cache-reuse case as @praneshgo pointed, worth adding it to commits or title for git history.
Semi-related: there is an issue with the pos_min_thold clamp (live SWA state with pos_min == 0 is never reused), but can be addressed in a separate PR.
435211b to
4611de0
Compare
|
Thanks for the comments, branch is rebased, comment is updated |
ORippler
left a comment
There was a problem hiding this comment.
Logic seems good to me, but I'm not super well-versed in llama-server yet.
Could think about adding a regression test to ensure we continue avoiding extra copies, though that would rely on flushing + parsing of log messages afaik
|
Let's wait for #30137 to merge and rebase this one. |
| server_args.extend(["--cache-ram", self.cache_ram]) | ||
| if self.n_cache_reuse: | ||
| server_args.extend(["--cache-reuse", self.n_cache_reuse]) | ||
| if self.n_ctx_checkpoints: |
There was a problem hiding this comment.
This will skip when value 0 is provided, shall it be if self.n_ctx_checkpoints is not None?
There was a problem hiding this comment.
Yes, I have updated
|
|
||
| // checkpoint reused by a task - checkpoints are immutable, so its id_task still names the task that created it | ||
| const common_prompt_checkpoint * ckpt_reused = nullptr; | ||
| int ckpt_reused_task = -1; |
There was a problem hiding this comment.
These probably require reset logic when the slot is reassigned.
There was a problem hiding this comment.
The reset logic is added.
There was a problem hiding this comment.
Setup logic for newly added tests is very similar and can be factored out.
There was a problem hiding this comment.
yeah sounds good, I have put them to the same test, also added SWA variant
| return server | ||
|
|
||
| @staticmethod | ||
| def tinylfm2() -> ServerProcess: |
There was a problem hiding this comment.
I propose adding also a model with SWA layers, like tinygemma3.
| server = ServerProcess() | ||
| server.offline = True # will be downloaded by load_all() | ||
| server.model_hf_file = None | ||
| server.model_hf_repo = "ggml-org/LFM2-test-ci-80M" |
There was a problem hiding this comment.
@ngxson @ServeurpersoCom Should we also move this model to the ggml-org-dev?
There was a problem hiding this comment.
Yes, since #32096 the CI test models live on ggml-org-dev, so a new one should go there directly. On master, test_infill (Qwen2.5-Coder-1.5B-IQ3_XXS) and test_spec_methods (spec-for-testing) still point to ggml-org.
There was a problem hiding this comment.
Hi, how do I move this model? Thanks
There was a problem hiding this comment.
Hi, how do I move this model? Thanks
I copied it to ggml-org-dev/LFM2-test-ci-80M, so you only need to point tinylfm2 at it: server.model_hf_repo = "ggml-org-dev/LFM2-test-ci-80M". If you need other test models there, just ping me and I'll copy them.
There was a problem hiding this comment.
Thanks! I have switched it.
Overview
If an existing checkpoint already exist, reuse it instead of copying the state again.
Also with --cache-reuse, deleting a chunk from the middle of the prompt can restore a checkpoint that still has the deleted tokens and produce wrong output.
Additional information
Tracks checkpoint reusing inside the slot.
Profiling
Same long system prompt with a different user message per request vs. a growing multi-turn chat. Median GPU prompt time per request, RTX PRO 6000 Blackwell.
Multi-turn chat benefits only when the next request goes back to a position that already has a checkpoint. lev restored a checkpoint on every turn, and all 48 re-copies became reuses. Qwen3.6 and Gemma just extended the cached prompt, so there was nothing to reuse.
Future works
an issue with the pos_min_thold clamp (live SWA state with pos_min == 0 is never reused)
Requirements
Yes