Repository navigation
serve: prefix snapshots on disk - a new chat restores its system prompt instead of reading it again - #1090
serve: prefix snapshots on disk - a new chat restores its system prompt instead of reading it again#1090konijiwa110 wants to merge 3 commits into
Conversation
|
Found a hole while looking at rope scaling: the snapshot identity didn't cover the rope config (nor KV_ROT, the control vector or the arithmetic switches), so turning on Checked on main + this PR on a 2080 Ti: a same-config restart still restores (30,028 tokens from disk in 357 ms); a restart with |
…pt instead of reading it again The system-prompt checkpoint (Niko1221#62, Niko1221#65) lives in the one K/V arena, so it is gone as soon as a request with another start comes in, and after every restart. --prefix-cache-dir keeps it in a file: after DONE, the root checkpoint's running state and the K/V up to it (draft layer included) are streamed into DIR once per distinct system prompt; a later prompt that starts with one restores it and reads only the rest. Files are capped by --prefix-cache-disk-mib (LRU), the most recent ones optionally kept in RAM (--prefix-cache-ram-mib); without the RAM they stream through a 64 MB buffer. A file from another engine build, model or --kv is deleted at start-up. One GPU without --batch.
…gerprint (rope scaling, KV_ROT, control vector, switches)
… as a session file's A model file replaced in place (same path, other weights) left the saved snapshots valid. The identity now has the session files' model fingerprint (each file's size, first and last MiB); the cache stays off when a model file cannot be read for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dbfc0f5 to
d90777d
Compare
|
Rebased onto current main (e8ca9af). The only conflict was in Also added a small fix on top: the snapshot identity now includes the model files' fingerprint, the same one session files use (each file's size plus its first and last MiB). Before this, if a model file was replaced in place under the same path, the old snapshots still counted as valid. Retested on the rebased branch (RTX 2080 Ti,
|
Just a few factors I hope you will consider:
EDIT: Also asking GitHub Copilot, it seems quite a few other PRs exist and are active. #2510 seems to be the most ambitious in doing everything. Nonetheless, as much as I also wish we could have all features now, it would make sense to pick the simplest yet most extensible one as the foundation I think. |
|
A data point for the 0.1.46 decision, from a UD-Q4_K_XL box (V100 32 GB + 128 GB RAM, dual NUMA nodes):
|
|
Thanks for the pull request. We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to review properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected. To reopen it takes about two minutes:
The rules are in CONTRIBUTING.md. |
Reopening #960 here. It got auto-closed when
mainwas force-pushed, and its branch was on the old history.Same change, cherry-picked onto the new
main(82f46a8). It conflicted only with the session files that landed in 0.1.40, in three places:conversation_file.cppnext toprefix_store.cppin CMakeLists,--session-min-free-mibnext to the new flags in the argument parser, and the sentence in DETAILS.md about what survives a restart. I kept both sides everywhere. Nothing else changed.What
The system-prompt checkpoint from #62/#65 lives in the one K/V arena. It is gone as soon as a request with a
different start comes in (a title request, a subagent, a second client), and after every restart. Parking keeps it
inside the parked conversation, but lending it takes that conversation out whole, so the conversation reads its
history again on its next turn. With agent clients this means many new chats still start from token 0, and their
system prompt plus tool list is often 20-35K tokens.
--prefix-cache-dir DIRkeeps that checkpoint in a file:DONEis already out. Its root checkpoint'srunning state and the K/V up to that point, draft layer included, are streamed from the session into
DIR. Thishappens once per distinct system prompt.
when the live session or a batch slot cannot serve more of the prompt. A parked conversation of the same length
loses to the file, so it stays parked. The file stays on disk.
--prefix-cache-disk-mib N(default 51200) caps the directory, removing the least recently used files first.--prefix-cache-ram-mib N(default 2048, 0 = disk only) also keeps recent snapshots in RAM, when--conversation-cache-min-free-miballows it.--native,--mtp,--kvandSTRATA_BF16_TC.If any of these differs (a rebuilt engine counts), the file is deleted at start-up.
This works on one GPU without
--batchonly, and stays off unless the directory is set.Measured
All numbers are from this branch alone:
main(82f46a8) plus this commit, nothing else on top.Swift 1.5 IQ3_XXS, 256K context,
--kv-resident 32768,--prefix-cache-ram-mib 0,--adapt-every 100000(fixedexperts, so the answers can be compared). Each prompt is a 30K-token system prompt plus a short user message, with
greedy decoding and 64 output tokens.
RTX 3080 12 GB, i7-13700KF, 64 GB RAM, Windows 11, Samsung 980 PRO.
--kv int8.DONE. The file is 577 MB.--prefix-cache-ram-mib 2048, the first restore reads the file into RAM (402 ms) and the next one comes fromRAM (129 ms).
RTX 2080 Ti 22 GB, i5-12490F, 62 GB RAM, Ubuntu, NVMe.
--kv k8v4.I also checked whether the model still knows the restored prompt. I put a code word in the middle of a 13K-token
system prompt. After a restore from disk, a newly worded question still got it right.
Verification
prefix_store_test(new, GPU) runs FP16, INT8 and Q4_0, each with resident and streamed K/V, plus K8V4. It savesa prefix from a session that holds more than the prefix, then restores it three ways: streamed from the file, read
into RAM, and from RAM. After each restore, the K/V, indexer and running state are byte-identical to the state at
the prefix. It also checks four cases:
210 checks pass on this branch on Linux (sm_75) and on Windows (MSVC, sm_86).
conversation_snapshot_testpasses unchanged (3901 checks, Linux and Windows), and so doesconversation_file_test(185, Linux). The existingconversation_kv_validateandconversation_kv_restorenow share their size check and residency step with the new streaming functions.Docs
docs/DETAILS.mdgets a new paragraph, "Prefix snapshots on disk", after the parked-snapshot notes. That sectionnow says parked snapshots do not survive a restart, but the session files and the prefix snapshots do.
🤖 Generated with Claude Code