Repository navigation
Conversation
Assisted-by: Codex
Adapt the slot save/restore checkpoint appendix from ggml-org#26004 to the shared_ptr checkpoint list and the common_state_data buffers. Assisted-by: Claude Opus 5.5
d133b80 to
d2d35a3
Compare
|
Would the shared references to the checkpoints also reduce the memory footprint of the prompt cache? If so, it might be useful to include numbers in the table. |
No, this patch uses |
I see. But just for clarification, the scenario I had in mind was when 2 prompts share the same prefix (eg. system prompt+tool schema) but different user messages. With this pr, do they share the same checkpoint object for the matching system prompt? I'm curious because if the original behaviour was a vector copy, it sounds like it's going to store the same checkpoint twice. |
|
Yes, sorry, you're right: If there are the same prefixes (a growing conversation), this saves (peak) RAM. It does not save RAM unrelated histories, even if they have the same input (there is no deduplication). Added the Memory table |
|
Sweet! I have only a few GB of RAM left once I load the model/prompt cache, so even a few hundred MB of savings would be meaningful to me. Looking forward to seeing this in mainline. |
|
/bot review |
Automated code reviewReview of PR #30137 (llama-server: reference-counted checkpoints). I checked the quick-reject gate, security, and the server/general checklists (paths touched: Summary of what I verified before the findings: every path that fills a Will slow the review (point 1) Cache accounting now over-counts shared checkpoint memory, and eviction cannot free it. (point 2) PR description/diff mismatch: the description's third bullet ("Reject broken requests before inserting into the prompt cache ... cheap because it's just an (point 3) (point 4) Test coverage: the new sharing between slot, cache entries, and Nits (point 5) (point 6) In Security note (no finding, but worth keeping in mind) The no-init vector is correct today only because all three fill sites validate completeness; the type itself enforces nothing. Any future Overall: the approach (immutable, reference-counted checkpoints) is the right one and the fill-path validation is done properly. Please address the accounting issue (point 1) and the description mismatch (point 2) before requesting maintainer review. This review was generated automatically by pi coding agent using |
|
Here for my support of this, I run this pr (augmented with a few patches of my own). It's stable, and saves anywhere between 6% and 30% of time when it hits. I have several downstream patches for better caching that gets my workload up to 94% cached for limited pinned streams - allowing a fused (cache load + processed) TPS of 26k tokens processed a second on a 5090 with qwen 3.8 27b q6ms @ 70k ctx. |
Overview
llama-servercurrently creates and reuses context-checkpoints through a vector copy.Since the checkpoints are immutable by design, this patch introduces reference-counted sharing instead.
This PR includes 3 changes to the system:
std::shared_ptrfor the context checkpoints, allowing cheap (ref-counted) copiesstd::moveAdditional information
This applies mainly to the host-side copies. The effects become larger as context grows. The effects are most visible when queuing events, as they need to wait on the serialized cache-checkpoint copies.
Tested on 3x Arc Pro B60, Threadripper 1950X x399 platform, 128GB RAM, qwen3.8-flash-next:UD-IQ4XS, RAM prompt cache 8GB, 16 checkpoints, checkpoint spacing 8192 tokens, no MTP, running on the SYCL backend (but should not affect this code).
Memory savings:
Requirements