Repository navigation
server: save the draft state in the slot file - #30574
Conversation
The slot file held the target context and the context checkpoints, but never the draft context, so a restored slot drafted with an empty or stale draft KV until the cache refilled. The file now ends with the live draft state, the full draft context and the speculative state, in the same appendix style as the checkpoints. A draft state that does not fit the draft context is dropped and the draft starts empty, while older files and older servers keep working.
|
I think the file plumbing (open for append, flush and error check on save, open and seek to the offset on load) could be shared between the checkpoint appendix and the draft block with two small helpers, but I left the checkpoint code from #26004 untouched to keep this change focused, happy to factor it if you prefer. |
Yes, we can improve plumbing in general. Something we should refactor in follow-ups - for now it's nice to patch the gaps. |
… start With --slot-save-path set, the live slot is written to auto-slot0.bin when the server stops and read back after the model loads, so a long session resumes with a prefix hit instead of a full re-prefill. Measured on a 5900-token prompt: prompt_n 5900 -> 516 after a restart. The draft memory goes to an auto-slot0.drft sidecar. Without it a restored slot keeps an empty draft and accepts far fewer speculative tokens (llama.cpp ggml-org#30574, merged upstream one day after this tree). The target file keeps the /slots save format byte for byte, so a snapshot taken here can be restored through the REST API and vice versa. Anything that does not fit the running context is a warning plus a cold start.
Overview
Follow-up to #30514, fixes #28619 (thanks @dgabehar for the report).
A slot restored with --slot-save-path gets back the main model memory but not the draft model memory, so speculative decoding restarts with an empty draft and accepts far fewer tokens.
The slot file now also stores the draft memory, the same way the RAM prompt cache already does, and restores it. A draft that does not match is skipped and starts empty, and old slot files and old servers keep working.
Additional information
Draft acceptance rate on the turn after save, erase and restore (the output is identical in all cases):
test_slot_restore_draft_state fails without this PR.
Requirements