Repository navigation
[Engine] restore a session file without holding its K/V in RAM - #3251
Open
pspranger-throw wants to merge 1 commit into
Open
pspranger-throw wants to merge 1 commit into
pspranger-throw wants to merge 1 commit into
Conversation
The RESTORE path materialized the whole snapshot in host memory, so a deep session could not be restored on a machine that serves it: upstream's own documented 503 'when the RAM to read the file is not there'. The restore is now two passes over the same file, format v1 unchanged: - the read pass parses and validates the whole file (running state, K/V headers, every count against this session's limits, the payload hash) without materializing the K/V; it reports each layer's part sizes. - the apply pass re-reads the file and copies the K/V into the authoritative pools a 16 MiB block at a time. It is bound to the read pass: a file whose layer count or any part size differs is refused before that part is applied, and the payload hash is compared to the trailer at the end. The first applied block is the gate - before it a failure refuses cleanly, after it the engine fail-stops rather than decode from bytes it cannot vouch for. Peak RAM is two 16 MiB buffers and the running-state metadata, so a session of any depth restores under the same floor. Measured on a 198,830-token IQ3_S session: 3.05 GiB restored in 3.4-3.5 s, next turn 99.99% reused. The residency refill after the pool writes is mandatory for the modes that keep K/V in VRAM and runs per layer (kv_stream_reset / kv_ring_restore). (cherry picked from commit d438ca5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #1269, which was closed in the 0.2.0-beta tracker reset. That PR cannot be reopened after its branch was rebased while closed (GitHub returns 422 on reopen); the diff and the validation below are unchanged.
Problem and result
The RESTORE path reads the whole snapshot into host memory before it writes anything, so its peak is about the size of the file. On a machine that is also serving the model, a deep session is larger than the RAM left free: a 198,830-token IQ3_S session is a 3.05 GiB file, with roughly 5 GiB available while the model is loaded, and the server answers 503 ("when the RAM to read the file is not there", DETAILS.md). Shallow sessions restore fine, which makes the limit easy to miss.
After this change the restore is two passes over the same file, format v1 unchanged: the read pass validates the whole file without materializing the K/V, and the apply pass re-reads it and copies the K/V into the authoritative pools in blocks of at most 16 MiB. Peak RAM is two 16 MiB buffers plus the running-state metadata, so a session of any depth restores under the same floor.
Related discussion
PR #1269. Niko, 2026-10-17: "It avoids the 503 on deep sessions by restoring in blocks, which is a memory fix and not a speed change, so it is outside this round. It needs a rebase and we would take it as a fix."
The branch is rebased onto
main(e88ee39d, head69fb7912) and retested on 0.2.0-beta. Rebase-only: the diff is unchanged from the reviewed patch (8 files, 561 insertions / 50 deletions).Approach
ConversationKvTarget. It is bound to the read pass: a file whose K/V layer count or any part size differs is refused before that layer or part is applied. The payload hash is recomputed and compared to the trailer at the end.kv_stream_reset/kv_ring_restore); without it the modes that keep K/V in VRAM read stale slots.session_file_readis untouched, so callers that hold the K/V in RAM behave exactly as before.Validation
Passed:
main(e88ee39d), CUDA 13.4, archs 75;86 (368 targets).conversation_file_test: 223/223 checks. All 8 conversation suites pass underctest: conversation_cache, conversation_split_failure, conversation_memory, conversation_file, session_save_reclaim, conversation_snapshot, conversation_validation, conversation_transfer.--peer-device 1, 153K session, direct server on loopback:SERR, noFATAL, no refusals. Peer tier active throughout: 3,339 experts / 6.34 GiB on the RTX 2060S.Failed:
Not run:
Limits