Repository navigation
server : share prompt prefix cells between slots (--slot-attach) - #30970
rochaudhari wants to merge 1 commit into
Conversation
|
Roshan, could you please squash the two patches? The second patch overwrites a lot of the first patch, so it's difficult to review both independently. I suggest making it one patch. The combined lines of code will also be lower. |
0dc9947 to
c06e06a
Compare
|
@ggerganov @ngxson @angt Can you please take a look at this. Thanks! |
Assisted-by: Claude Opus 5.5
493a299 to
61e6777
Compare
|
Turning on attach for multimodal. Attach is kept only for text based prompt, any request containing media will not use attach feature. However, requests with media can act as donor. |
|
|
Following the Nov 12 thread on a possible There is already a memory-level capability-query precedent in I would still keep explicit rejection for paths known to produce incorrect output (the PR currently identifies DeepSeek V4), since a capability query should describe what an implementation supports, not substitute for correctness validation. I’m asking only about the memory capability boundary for this PR, not proposing a client-facing fork API. |
…very - timings.cache_reusable_n and the prometheus counter llamacpp:prompt_tokens_reusable_total: the prompt tokens shared with the cached state the slot starts from (its own tokens or the host cache entry it loaded), before a checkpoint restore. cache_n / cache_reusable_n is the hit share of what could have been reused; the rest is the distance back to the restored checkpoint. An INFO line per task logs both. - --checkpoint-every N (LLAMA_ARG_CHECKPOINT_EVERY, default 0 = off): a long prompt also gets a context checkpoint every N tokens, so a prompt that diverges in its middle re-processes at most about N tokens. Idea: mkyt docs/decisions.md P4-6 (checkpoints at message boundaries and every ~8K tokens, hit share of reusable tokens), ignis, llama.cpp ggml-org#30970. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
honestly cell-sharing is quite a headache so I would avoid it at this stage. there are quite many edge cases, including recurrence memory and also KV shifting (for example, one cell shared by 2 seq but one seq decide to shift it) in anyway, I'm working on a similar feature here. appreciate if you can take a look: #32358 |
@ngxson Agree that there are many cases need to be handled with cell sharing feature, however, my plan is to add them incrementally. Recurrent memory is already handled in this PR and this PR disables cell sharing for cell shifting case (and other cases mentioned in description). I looked at #32358 and it looks like it is also doing cell sharing but there is difference in scope: #32358 waits for a busy slot when requests arrive together and current PR reuses a prefix that's already computed, including in idle slots. Do you see any other edge cases which current PR and description does not cover? |
@slamfinger Agree on keeping separate capabilities for shared-cell attachment and checkpoint based attachment. Regarding scope of this PR, I would add explicit check in current PR and capabilities check in separate PR. If we really want to avoid broader redesign and follow existing approach, using per-operation queries might be better vs descriptor approach (it also involves struct's ABI problem), but I would let maintainers provide their take on this. |
…very - timings.cache_reusable_n and the prometheus counter llamacpp:prompt_tokens_reusable_total: the prompt tokens shared with the cached state the slot starts from (its own tokens or the host cache entry it loaded), before a checkpoint restore. cache_n / cache_reusable_n is the hit share of what could have been reused; the rest is the distance back to the restored checkpoint. An INFO line per task logs both. - --checkpoint-every N (LLAMA_ARG_CHECKPOINT_EVERY, default 0 = off): a long prompt also gets a context checkpoint every N tokens, so a prompt that diverges in its middle re-processes at most about N tokens. Idea: mkyt docs/decisions.md P4-6 (checkpoints at message boundaries and every ~8K tokens, hit share of reusable tokens), ignis, llama.cpp ggml-org#30970. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…very - timings.cache_reusable_n and the prometheus counter llamacpp:prompt_tokens_reusable_total: the prompt tokens shared with the cached state the slot starts from (its own tokens or the host cache entry it loaded), before a checkpoint restore. cache_n / cache_reusable_n is the hit share of what could have been reused; the rest is the distance back to the restored checkpoint. An INFO line per task logs both. - --checkpoint-every N (LLAMA_ARG_CHECKPOINT_EVERY, default 0 = off): a long prompt also gets a context checkpoint every N tokens, so a prompt that diverges in its middle re-processes at most about N tokens. Idea: mkyt docs/decisions.md P4-6 (checkpoints at message boundaries and every ~8K tokens, hit share of reusable tokens), ignis, llama.cpp ggml-org#30970. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…very - timings.cache_reusable_n and the prometheus counter llamacpp:prompt_tokens_reusable_total: the prompt tokens shared with the cached state the slot starts from (its own tokens or the host cache entry it loaded), before a checkpoint restore. cache_n / cache_reusable_n is the hit share of what could have been reused; the rest is the distance back to the restored checkpoint. An INFO line per task logs both. - --checkpoint-every N (LLAMA_ARG_CHECKPOINT_EVERY, default 0 = off): a long prompt also gets a context checkpoint every N tokens, so a prompt that diverges in its middle re-processes at most about N tokens. Idea: mkyt docs/decisions.md P4-6 (checkpoints at message boundaries and every ~8K tokens, hit share of reusable tokens), ignis, llama.cpp ggml-org#30970. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…very - timings.cache_reusable_n and the prometheus counter llamacpp:prompt_tokens_reusable_total: the prompt tokens shared with the cached state the slot starts from (its own tokens or the host cache entry it loaded), before a checkpoint restore. cache_n / cache_reusable_n is the hit share of what could have been reused; the rest is the distance back to the restored checkpoint. An INFO line per task logs both. - --checkpoint-every N (LLAMA_ARG_CHECKPOINT_EVERY, default 0 = off): a long prompt also gets a context checkpoint every N tokens, so a prompt that diverges in its middle re-processes at most about N tokens. Idea: mkyt docs/decisions.md P4-6 (checkpoints at message boundaries and every ~8K tokens, hit share of reusable tokens), ignis, llama.cpp ggml-org#30970. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Overview
A new session has following limitations which reusing prefix that another slot holds:
With Unified KV cache + this PR, a new request can also start from the cells of another slot that holds the same prefix. Prefix is neither copied or computed.
Recurrent and hybrid models can only resume at a checkpoint, so they attach at a checkpoint of the other slot. To make this useful, the server also creates a checkpoint where a prompt diverges from a known prompt, at least 1,024 tokens in, so later prompts can attach up to that point.
Attach is on by default, and --no-slot-attach turns it off. It also turns itself off where it cannot work, for example without a unified KV cache or with sliding-window models.
Additional information
Original discussion: #30664
Behaviour
Supported memory types
Attach gives the same output as same-slot reuse on each of these:
Not supported: attach turns itself off
Numbers
Setup: NVIDIA A40 (48 GB), CUDA 12.8, q8_0 KV, 4 slots with unified KV, 3 concurrent sessions, MTP off. Prompts use Hermes's real tools and system prompt; the project context, skills and memory parts are synthetic. The shared prefix is 14.1K tokens. Times are the mean of 3 runs. The KV cell counts come from one separate run.
Values are "off -> attach":
A checkpoint copy on the 35B is 62.8 MiB and takes about 29 ms per attach.
Tests
tools/server/tests/unit/test_completion.py.Related and follow-ups
seq_cpsharing idea on attention-only models.--cache-dir). ngxson mentions a block-hash prompt cache there that would replace it.abort_all_slots, then drop theseq_pos_maxclamp infind_attach.Requirements