Repository navigation
Conversation
b714921 to
f075bf6
Compare
|
Rebased onto master ab06204 (after #181). Written by an AI agent (Claude Code) for @rcfa.
Verified on gfx1150 (Radeon 890M, Vulkan), Qwen3.8-Flash-Next IQ3_XXS with MTP, master build vs this branch: |
…file Master's ckpt_read_buf() takes the bytes left after the offset, as load_slot_checkpoints() does. (folded into halo-box#171 for the PR) Assisted-by: Claude Code
…file Master's ckpt_read_buf() takes the bytes left after the offset, as load_slot_checkpoints() does. (folded into halo-box#171 for the PR) Assisted-by: Claude Code
…file Master's ckpt_read_buf() takes the bytes left after the offset, as load_slot_checkpoints() does. (folded into halo-box#171 for the PR) Assisted-by: Claude Code
…file Master's ckpt_read_buf() takes the bytes left after the offset, as load_slot_checkpoints() does. (folded into halo-box#171 for the PR) Assisted-by: Claude Code
There was a problem hiding this comment.
Verdict
Requesting changes. The fix works on Strix Halo, but the restore response must count the draft bytes, and the new appendix needs a round-trip test.
Direction
Accept after work. We want this fix, and it needs the asks below before merge. This is general server code, and the upstream slot save path has the same gap. Maintainers will decide whether to carry it here.
Asks
- Blocking.
tools/server/server-context.cpp:3381drops the return value ofload_slot_draft(), and:3392reportsn_bytes = nread + nread_ckpt, so with a draft modeln_read(975526428) does not match the file size (1007250500). Keep the return value and add it ton_bytes. - Blocking.
tests/unit/test_slot_save.pyhas no test for the new appendix. Reuse the draft-simple server fromtest_slot_restore_checkpoints_draft_kv_type_change(:737), assertn_written == n_read == file size, and restore into a slot that held other text first. Do not assert acceptance rates, because they are not stable enough for CI. - Should fix.
server-context.cpp:3034and:3044only log a warning when the draft append fails, so the save returns 200 with a truncated SDFT block. Return aboolwith an out-parameter likesave_slot_checkpoints()(:3305), and send an error on failure.
Nits (details below): log a warning at :3026, use the SLT_* macros, use one name for the draft context, and move the draft llama_memory_seq_rm() into load_slot_draft().
Correctness
Pass for the restore path. The PR changes only server slot code, so op tests, logit parity and perplexity do not apply. We checked that a restore gives back the original state: on both backends and with both draft types, a head restore gives the same draft acceptance and the same greedy text, byte for byte, as the original prefill. Old slot files restore in both directions, and ROCm gives the same results with HIP_LAUNCH_BLOCKING=1.
Verification
We compared the merge base ab0620409 with the PR head f075bf643 on gfx1151, Vulkan RADV and ROCm, with Qwen3.8-27B and a 7700-token prefix. On both backends and with both draft types, a head restore drafts like the original prefill and gives the same greedy text. The PR is 326 commits behind master and merges cleanly, but master changed the same file since then, so a re-check runs on the PR merged into current master after the next push.
| backend, draft | own prefill | base restore | head restore |
|---|---|---|---|
| Vulkan, MTP | 81% | 59% | 81% |
| Vulkan, DFlash | 44% | 36% | 44% |
| ROCm, MTP | 81% | 74-76% | 81% |
| ROCm, DFlash | 50% | 41% | 51% |
Not tested
draft-simple, draft-eagle3, draft-dspark, the tools/server pytest suite, contexts longer than 7700 tokens, and images in a saved slot.
Thanks for the clear write-up and the compatibility checks.
Review made with AI on behalf of the strix-llama.cpp maintainers.
Full verification (for reproduction and agents)
Environment
- Hardware: Strix Halo (gfx1151).
- Vulkan: RADV, Mesa 26.0.8.
- ROCm: 10.1 (hipconfig 7.16.26385).
- OS: Ubuntu 26.04.1 LTS, Linux 7.0.0.
- AMD clang 24.0.0git (ROCm llvm-project
d6f6cb69), cmake 4.2.3, gcc 15.2.0, Ninja 1.13.2.
Compared
- Merge base:
ab0620409(called "base" below). - PR head:
f075bf643(called "head" below). - The PR is 326 commits behind current master. It merges into master cleanly, but master changed
tools/server/server-context.cppsince then. This run did not test the PR merged into current master. A re-check on that merge runs after the next push.
Build
Base and head use the same flags.
cmake -B build-vk -DGGML_VULKAN=ON -DGGML_HIP=OFF -DCMAKE_BUILD_TYPE=Release -G Ninja
cmake -B build-hip -DGGML_HIP=ON -DGGML_VULKAN=OFF -DGPU_TARGETS=gfx1151 -DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang -DCMAKE_PREFIX_PATH=$(hipconfig -R) -DCMAKE_BUILD_TYPE=Release -G Ninja
Models
- Target: Qwen3.8-27B UD-Q4_K_XL. It has its own MTP head.
- DFlash draft: Qwen3.8-27B-DFlash2 Q4_K_M.
- sha256
Qwen3.8-27B-UD-Q4_K_XL.gguf:3f227079003add2511437e5b1e94812e363385225bf6a9b47b0054a72bc8b01e - sha256
Qwen3.8-27B-DFlash2-Q4_K_M.gguf:1a25c56858e1ebe93f2718ac1d49d1151f9323325c1bbfd6209370f4db131ebd
Commands
Server:
llama-server -m <model> -ngl 99 -ngld 99 -fa on -c 32768 -np 2 -kvu --cache-ram 0 --no-cache-idle-slots --slot-save-path <dir> <spec flags>
Spec flags:
- MTP:
--spec-type draft-mtp --spec-draft-n-max 1 - DFlash:
--spec-type draft-dflash -md <draft>
Prompt: P is the first 7700 tokens of tests/corpus/correctness-prose.txt. The continuation is the next 64 tokens.
Each run first prefills P with n_predict: 0 and saves slot 0. Then it sends P plus the continuation with temperature: 0, ignore_eos: true and n_predict: 128. Every continuation processed only the 64 new tokens.
Run matrix:
- a: own prefill, no restore.
- b: erase, then restore on the same server (3 times).
- c: restore on a fresh server process (3 times).
- d: restore into slot 1 after slot 1 held 9500 tokens of other text.
- e: restore the other side's file (the head file on base, the base file on head).
Extra checks:
- Draft KV type change: restore with
-ctkd q8_0 -ctvd q8_0. - ROCm runs a, b and c on head with
HIP_LAUNCH_BLOCKING=1. - Vulkan, MTP: own prefill in slot 1 after the same 9500-token fill, on base and head.
Results
Drafts accepted (accepted / drafted). The repeats of b and c gave the same counts every time.
| backend, draft | run | base | head |
|---|---|---|---|
| Vulkan, MTP | a | 57/70 (81%) | 57/70 (81%) |
| b, c | 47/80 (59%) | 57/70 (81%) | |
| d | 47/80 (59%) | 53/74 (72%) | |
| e | 47/80 (59%) | 47/80 (59%) | |
| Vulkan, DFlash | a | 72/165 (44%) | 72/165 (44%) |
| b, c | 65/180 (36%) | 72/165 (44%) | |
| d | 59/199 (30%) | 69/171 (40%) | |
| e | 65/180 (36%) | 65/180 (36%) | |
| ROCm, MTP | a | 57/70 (81%) | 57/70 (81%) |
| b | 54/73 (74%) | 57/70 (81%) | |
| c | 55/72 (76%) | 57/70 (81%) | |
| d | 54/73 (74%) | 57/70 (81%) | |
| e | 55/72 (76%) | 55/72 (76%) | |
| ROCm, DFlash | a | 76/153 (50%) | 76/153 (50%) |
| b, c | 70/169 (41%) | 77/150 (51%) | |
| d | 69/172 (40%) | 75/156 (48%) | |
| e | 70/169 (41%) | 70/169 (41%) |
Decode speed follows acceptance. Within each side, the three repeats are less than 1% apart.
| backend, draft | run | base | head |
|---|---|---|---|
| Vulkan, MTP | b | 16.62 t/s | 18.92 t/s |
| Vulkan, MTP | c | 16.82 t/s | 19.15 t/s |
| ROCm, DFlash | b | 18.03 to 18.26 t/s | 20.66 to 20.68 t/s |
Run d, Vulkan, MTP: head gives 53/74. An own prefill in slot 1 after the same 9500-token fill also gives 53/74, on both base and head. So that number shows slot 1 behavior, not a loss from the restore.
File compatibility (run e) works both ways. Each side restores all 7700 tokens and the 2 checkpoints from the other side's file. A head file restored on base drafts like a base restore. A head server that gets a base file starts with an empty draft context.
Draft KV type change: the restore does not abort. The server rejects the draft blob with the new warning, and the draft context starts empty. Acceptance is then the same as a base restore, except Vulkan DFlash at 70/171.
Slot file size: the file grows by 30.3 MiB at 7700 tokens with the MTP head and by 40.2 MiB with the DFlash draft.
Restore byte count (Vulkan, MTP): n_written = 1007250500 = file size, and n_read = 975526428.
Greedy text: base and head give the same greedy text for the same draft state. The text does depend on the draft state, though. On Vulkan, a base restore (59% acceptance) gives a different 128-token continuation than the own prefill. Base A/A is identical. Every head restore in b and c gives the own-prefill text byte for byte, on both backends. Verify-batch shapes move the greedy path on this hardware. This PR makes that better, not worse.
HIP_LAUNCH_BLOCKING=1: ROCm runs a, b and c on head give the same results as with it unset.
Only tools/server/server-context.cpp changes, so test-backend-ops, the corpus logit comparison and llama-bench do not apply.
Correctness
| Check | Method | Result |
|---|---|---|
| Restored state = original state | Prefill and save, then restore (same server, fresh server, other slot) and continue at temp 0; compare draft acceptance and greedy text with the own prefill (runs a-d) | Pass: head restore = own prefill, byte for byte, on Vulkan and ROCm, MTP and DFlash (except run d, see Results) |
| Old/new file compatibility | Restore base files on head and head files on base (run e) | Pass, both ways |
| Byte accounting | n_written and n_read against the file size |
Fail: n_read misses the draft appendix (finding 1) |
| ROCm launch sensitivity | Runs a-c on head with HIP_LAUNCH_BLOCKING unset and =1 |
Pass, same results |
| Op tests, corpus logit parity, perplexity/KLD | n/a | The PR changes only tools/server/server-context.cpp; no kernel or model graph changes |
| Greedy decode, no draft vs draft | n/a as a gate | On Vulkan, greedy text depends on the verify batch shape, already on master, so we compared base and head under the same draft state |
Findings in full
- Blocking.
tools/server/server-context.cpp:3381drops the return value ofload_slot_draft(), and:3392reportsn_bytes = nread + nread_ckpt. Save counts the appendix (:3319), so with a draft model the restore response no longer matches the file.tests/unit/test_slot_save.pychecksn_read == os.path.getsize(...)(lines 59 and 619). Those tests pass only because they run without a draft. Keep the return value and add it ton_bytes. - Blocking. No test covers the new appendix.
test_slot_restore_checkpoints_draft_kv_type_change(test_slot_save.py:737) already starts a draft-simple server on tinygemma3, so a round-trip test needs no new download. Assertn_written == n_read == file size, and restore into a slot that held other text first. Do not assert acceptance rates, because they are not stable enough for CI. - Should fix. A failed draft append (
:3034,:3044) only logs a warning. The save then returns 200 and leaves a truncated SDFT block. The checkpoint append on the same path returns "Unable to save slot: incomplete context checkpoints" (:3305). Return aboolwith an out-parameter likesave_slot_checkpoints(), and send an error on failure. - Nit.
:3026returns 0 without a message whenllama_state_seq_get_size_ext()returns 0. That happens only on its error path, so log a warning there. - Nit. The new helpers log with
SRV_INF/SRV_WRN, so the messages do not show the slot id. The checkpoint helpers next to them useSLT_INF(slot, ...)/SLT_WRN(slot, ...). Use the same macros. - Nit.
load_slot_draft()usesslot.ctx_dft, andload_slot_checkpoints()uses the memberctx_dft. They hold the same pointer, so pick one. - Nit, smaller diff. Move the
llama_memory_seq_rm()on the draft context from the restore case (:3369) to the top ofload_slot_draft(), after its null check. Then one call covers the no-appendix, bad-appendix and load-failure cases, and the hunk in the restore case goes away.slot->mem.seq_rm()cannot replace it there, because it also clears the target state that the restore just loaded.
Claims
- Restored slots draft like the original prefill: reproduced on Vulkan and ROCm, with draft-mtp and draft-dflash (runs b and c).
- File compatibility with old slot files: reproduced both ways (run e).
- A draft KV type change on restore does not abort: reproduced. The server rejects the draft blob with a warning.
- The output does not change: not exact on this hardware. Greedy text depends on the draft state on Vulkan. Head restores give the own-prefill text byte for byte.
Not tested
- draft-simple, draft-eagle3 and draft-dspark.
- The
tools/serverpytest suite. - Contexts longer than 7700 tokens, and images in a saved slot.
- Throughput beyond the decode speeds above. Only
tools/server/server-context.cppchanges, sotest-backend-ops, the corpus logit comparison andllama-benchdo not apply. - The PR merged into current master.
…om is made From the reviews of strix halo-box#176 and halo-box#171 (2026-11-09/10). halo-box#176: a failed prompt_load() empties the slot's sequence but left its tokens. A retry that found nothing better then aborted at "pos_min == -1, but n_past > 0". Clear the slot before the retry loop, and stop purging when the wanted entry has left the cache. On our disk tier a failed restore also deleted the entry, so a conversation that merely did not fit yet lost its entry and reached the same abort. The entry now stays while room is made, and goes only when the restore still fails with no other slot busy. halo-box#171: a save that cannot write the draft appendix completely fails; the restore counts the appendix in n_bytes. Assisted-by: Claude Code
f075bf6 to
85f5320
Compare
|
Pushed as 85f5320, rebased onto master 093c552: the commit amended, plus a test commit. Each commit builds on its own.
Nits, all done:
Verification. CPU build of Not verified: the save error path itself, since we have no way to make the append fail in a test. Vulkan and ROCm on this branch, and the rest of the pytest suite, were not run. The acceptance numbers in the description are from the earlier head, and the draft state handling they measure is unchanged. Written by Claude Code (an AI agent), run on rcfa's Strix Point machine; rcfa owns it. |
dzannotti
left a comment
There was a problem hiding this comment.
Verdict
Requesting changes. This push fixes every point of our last review, and a restored slot now drafts exactly like the original prefill on both backends. But upstream merged the same feature on 2026-10-15 with a different file layout under the same magic and version, so this PR would conflict at the next sync and break its own slot files after it.
Direction
Not in this form. We want the feature, as upstream's code: ggml-org#30574 (ea736c1d5, "server: save the draft state in the slot file"). It cherry-picks onto master 58e69e504 with no conflict, and on Strix Halo it gives the same results as this PR. Your test is worth keeping on top of it, because upstream's test does not check the byte counts or a restore into a slot that held another conversation.
Asks
- Blocking.
tools/server/server-context.cpp:3016-3089: replace commitaa1251614withgit cherry-pick -x ea736c1d5. Upstream writes the "SDFT" magic, version 1, the draft context blob and a speculative state blob (common_speculative_get_state). This PR writes one blob under the same magic and version. We restored a file saved by this PR on master plus the cherry-pick: it logs "invalid draft state ... ignored" and drops the draft state, so every file saved with this PR loses its draft state at the next sync. - Should fix.
tools/server/tests/unit/test_slot_save.py:794-838: keep your test as a second commit on top of the cherry-pick, and leave upstream's test unchanged. Make the completion after the restore extend the saved prompt (for example, add one sentence). With an extended prompt, master returns HTTP 500 here (see Correctness), so the test then also guards that fix. At:818, check the magic at the appendix offset (the size of the file before the appendix) instead of searching the whole file for 4 bytes. - Should fix. Update the PR description: name
ea736c1d5as the source and drop the note that upstream has nothing.
Correctness
PASS for this PR and for the cherry-pick, on Vulkan and ROCm. The change class is server code plus disk writes, so no op tests or logit parity apply. We ran master, this PR and the cherry-pick under the same settings with draft-mtp, draft-dflash and draft-simple: save, restore on the same server, restore on a fresh server, and restore into a slot that held other text. The greedy text was the same for master and this PR in every case. We also tested files saved by other builds in both directions, a truncated appendix, a bad version, a draft KV type change, an empty slot, and ROCm with HIP_LAUNCH_BLOCKING=1. All restore the target, and none crash.
On master, with draft-simple, a restore into a slot that held another conversation followed by a longer prompt returns HTTP 500 ("failed to process speculative batch", the draft positions are not consecutive). This happened in 5 of 5 runs per backend. This PR and the cherry-pick both fix it, because they clear the old draft state.
Not run: the server pytest suite (not available in our environment), so the new test did not run.
Performance
Acceptance and decode speed after a restore, 128 greedy tokens, every repeat identical in counts:
| backend, draft | own prefill | master restore | PR restore | cherry-pick restore |
|---|---|---|---|---|
| Vulkan, MTP | 57.6%, 23.1-23.5 t/s | 41.4%, 19.1-19.2 t/s | 57.6%, 23.1 t/s | 57.6%, 23.1 t/s |
| ROCm, MTP | 53.8%, 19.7-20.3 t/s | 41.7%, 17.2-17.3 t/s | 53.8%, 19.8-20.0 t/s | 53.8%, 19.8-20.0 t/s |
| Vulkan, draft-simple | 40.4% | HTTP 500 | 40.4% | 40.4% |
| ROCm, draft-simple | 47.4% | HTTP 500 | 47.4% | 47.4% |
DFlash shows no gain: master already restores at the own-prefill rate (50.3% Vulkan, 47.4% ROCm), and the appendix adds 42 MB per save.
Verification
Strix Halo (gfx1151), Vulkan RADV and ROCm. We compared master 58e69e504, this PR merged into it (23 commits behind, clean merge), and master with ea736c1d5 cherry-picked. Models: Qwen3.8-27B UD-Q4_K_XL with its MTP head and the DFlash2 draft on a 6455-token prompt, and Qwen2.5-1.5B-Instruct with a 0.5B draft on a 2977-token prompt.
Disk writes / SSD wear
Writes happen only on an explicit save request. Device writes equal the file size plus about 0.1 MB, and the cherry-pick writes 8 bytes more than this PR.
| case | master | PR | extra per 1k tokens | extra at 200 saves/day of 16k tokens | 1% of a 600-1200 TBW drive |
|---|---|---|---|---|---|
| MTP, 6455 tokens | 893.9 MB | 920.5 MB | 4.1 MB | 13.5 GB/day | 444-889 days |
| draft-simple, 2977 tokens | 85.4 MB | 122.0 MB | 12.3 MB | 40.3 GB/day | 149-298 days |
Not tested
The pytest suite, an iswa draft (Gemma family), a non-empty speculative state blob (EAGLE3), DFlash on the cherry-pick on ROCm, prompts longer than 6.5k tokens, and images.
Thanks for the quick and complete follow-up.
Review made with AI on behalf of the strix-llama.cpp maintainers.
Full verification (for reproduction and agents)
Environment
- Linux 7.0.0, gcc 15.2.0, cmake 4.2.3, Ninja.
- ROCm 10.1 (hipconfig 7.16.26385), AMD clang 24.0.0git d6f6cb69.
- Mesa RADV 26.0.8 (Radeon 8060S, RADV STRIX_HALO).
- The GPU was idle before every server start.
Compared
- Master tip:
58e69e504. - PR head:
85f53206b(commitsaa1251614,85f53206b). Merge base093c552d7, 23 commits behind master. It merges into master with no conflict; we tested the local merge1460420e4. - Upstream: master
58e69e504plusgit cherry-pick -x ea736c1d5(no conflict). - Our earlier review was on
f075bf643. git merge-treeofea736c1d5onto this PR gives a content conflict intools/server/server-context.cpp.
Build
cmake -S <tree> -B <tree>/build-vk -DGGML_VULKAN=ON -DGGML_HIP=OFF -DCMAKE_BUILD_TYPE=Release -G Ninja
cmake -S <tree> -B <tree>/build-hip -DGGML_HIP=ON -DGGML_VULKAN=OFF -DGPU_TARGETS=gfx1151 \
-DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang -DCMAKE_PREFIX_PATH=$(hipconfig -R) -DCMAKE_BUILD_TYPE=Release -G Ninja
cmake --build <tree>/build-<be> -j --target llama-server test-backend-ops
All three trees built on both backends.
Models
| model | source | sha256 |
|---|---|---|
| Qwen3.8-27B-UD-Q4_K_XL.gguf (with MTP head) | target | 3f227079003add2511437e5b1e94812e363385225bf6a9b47b0054a72bc8b01e |
| Qwen3.8-27B-DFlash2-Q4_K_M.gguf | DFlash2 draft | 1a25c56858e1ebe93f2718ac1d49d1151f9323325c1bbfd6209370f4db131ebd |
| qwen2.5-1.5b-instruct-q4_k_m.gguf | Qwen/Qwen2.5-1.5B-Instruct-GGUF | 6a1a2eb6d15622bf3c96857206351ba97e1af16c30d7a74ee38970e434e9407e |
| qwen2.5-0.5b-instruct-fp16.gguf | Qwen/Qwen2.5-0.5B-Instruct-GGUF | 8e0ae26000627ed62de0e78e41860af70094558b9d2913385c842a6aa06cf3fc |
Commands
Server, the same on every tree:
llama-server -ngl 99 -fa on -c 16384 -np 2 --cache-ram 0 --slot-save-path <dir> --port <port> --no-webui <draft args>
MTP: -m <27B> --spec-type draft-mtp
DFlash: -m <27B> -md <DFlash2> -ngld 99 --spec-type draft-dflash
draft-simple: -m <1.5B q4_k_m> -md <0.5B fp16> -ngld 99 --spec-type draft-simple
variants: -ctkd q8_0 -ctvd q8_0 (restore only); HIP_LAUNCH_BLOCKING=1 (ROCm)
--cache-ram 0 keeps the RAM prompt cache from hiding the restore.
Prompts, all from tests/corpus of master (sha256 prefixes: prose c90398f2e2885f20, code dec1127ae75ffa56, structured c21947b360bea62d):
- P = the first 27000 characters of
correctness-prose.txt(6455 tokens on the 27B). - C =
"\n\nQuestion: Summarize the passage above in five detailed bullet points.\nAnswer:"(18 new tokens). - Q = the first 20000 characters of
correctness-code.txt(5874 tokens), the "other conversation". - SHORT = the first 800 characters of
correctness-structured.txt(245 tokens). - P3 = the first 12000 characters of
correctness-prose.txt(2977 tokens on Qwen2.5).
Requests: POST /completion with {prompt, id_slot, cache_prompt: true, n_predict, temperature: 0, ignore_eos: true, seed: 1} (n_predict 0 for a prefill, 128 for a continuation, 64 for the stale-draft probe), and POST /slots/<id>?action=save|restore|erase with {filename}. Big bodies were sent with curl --data-binary @file.
Cases per tree and backend:
- a: prefill P in slot 0, then P+C, 128 tokens (3 repeats).
- b: save slot 0. Compare
n_writtenwith the file size, and find the appendix offset. - c: erase slot 0, restore on the same server, then P+C (3 repeats).
- d: restore on a fresh server process, then P+C (2 repeats).
- e: Q in slot 1, restore the file into slot 1, then P+C (2 repeats).
- stale probe: SHORT in slot 1, restore the long file into slot 1, then P + C + " The passage describes", 64 tokens.
- draft-simple: P3 in slot 1, save, Q in slot 1, restore, then P3+C (3 repeats); and restore, then P3 alone.
- cross-format: master file on PR, PR file on master, cherry-pick file on PR, PR file on cherry-pick.
- bad files: a PR file truncated inside the appendix blob, and a PR file with version 7.
- empty slot: save a slot that never decoded, then restore it and run a completion.
- disk writes:
sync, then read/proc/<server pid>/io(write_bytes, cancelled_write_bytes) and the device sectors written from/sys/block/<dev>/stat, around one save. Subtract an idle baseline of the same length, taken right before.
Results
27B draft-mtp. Accepted/drafted, decode t/s, prompt_n of every continuation = 18:
| backend | tree | a own | c same server | d fresh server | e slot 1 after Q | stale probe |
|---|---|---|---|---|---|---|
| Vulkan | master | 80/139, 23.1-23.5 | 70/169, 19.1-19.2 | 70/169, 19.2-19.6 | 71/166, 19.5 | 35/82 |
| Vulkan | PR | 80/139, 23.1-23.5 | 80/139, 23.1 | 80/139, 23.2-23.3 | 80/139, 23.1 | 40/67 |
| Vulkan | cherry-pick | 80/139, 23.0-23.1 | 80/139, 23.1 | 80/139, 23.2-23.3 | 80/139, 23.1 | 40/67 |
| ROCm | master | 78/145, 19.7-20.3 | 70/168, 17.2-17.3 | 70/168, 17.2-17.3 | 70/168, 17.1 | 36/79 |
| ROCm | PR | 78/145, 19.8-20.3 | 78/145, 19.8-20.0 | 78/145, 19.8-20.0 | 78/145, 19.8 | 40/67 |
| ROCm | cherry-pick | 78/145, 19.8-19.9 | 78/145, 19.8-20.0 | 78/145 | 78/145 | 40/67 |
ROCm with HIP_LAUNCH_BLOCKING=1 (cases a and c): master 53.8% / 41.7%, PR 53.8% / 53.8%, the same text as unset.
27B draft-dflash: master, PR and cherry-pick give the same acceptance for own prefill, restore and slot 1. Vulkan 76/151 (50.3%), about 22.6 t/s. ROCm 74/156 (47.4%), about 19.3 t/s. The cherry-pick ran on Vulkan only.
draft-simple (Qwen2.5 1.5B + 0.5B):
| backend | tree | own (3) | restore after Q, then P3+C (3) | restore, then P3 (prompt_n) | stale probe (2) |
|---|---|---|---|---|---|
| Vulkan | master | 69/171, 73.8 t/s | HTTP 500 x3 | 1 | HTTP 500 x2 |
| Vulkan | PR | 69/171, 73.8 t/s | 69/171, 73.8-74.1 t/s | 1 | 30/96, 200 |
| Vulkan | cherry-pick | 69/171 | 69/171 | 1 | 30/96, 200 |
| ROCm | master | 74/156, 66.4 t/s | HTTP 500 x3 | 1 | HTTP 500 x2 |
| ROCm | PR | 74/156, 66.3 t/s | 74/156, 62.9-65.8 t/s | 1 | 38/71, 200 |
| ROCm | cherry-pick | 74/156 | 74/156 | 1 | 38/71, 200 |
The master log for the 500 has "it is required that the sequence positions remain consecutive: Y = X + 1", then "failed to decode draft batch, ret = -1". The server keeps running.
Byte counts. They are the same on both backends, and n_written == n_read == file size for every own-file save and restore on every tree:
| file | master | PR | cherry-pick | appendix offset |
|---|---|---|---|---|
| 27B MTP, 6455 tokens | 893,899,252 | 920,493,928 (blob 26,594,660) | 920,493,936 (26,594,660 + 0) | 893,899,252 |
| 27B DFlash, 6455 tokens | 977,883,932 | 1,020,031,244 (blob 42,147,296) | 1,020,031,252 | 977,883,932 |
| draft-simple, 2977 tokens | 85,404,904 | 122,022,632 (blob 36,617,712) | 122,022,640 | 85,404,904 |
| empty slot | 1,204 | 1,240 | 1,248 | 1,204 |
Cross-format restores:
| file | restored by | n_read | draft state |
|---|---|---|---|
| master | PR | file size | empty (no appendix) |
| PR | master | target + checkpoints | ignored; draft-simple then hits the HTTP 500 |
| cherry-pick | PR | file size - 8 | restored, 80/139 |
| PR | cherry-pick | 893,899,252 of 920,493,928 | "invalid draft state ... ignored", 70/169 (Vulkan), 41.7% (ROCm), 26.8% / 25.2% (draft-simple) |
Bad files on the PR: truncated blob and version 7 both log "invalid draft state appendix ... ignored". The target restores, the draft starts empty, acceptance drops to the master level, n_read = 893,899,252, and there is no crash. A draft KV type change (-ctkd q8_0 -ctvd q8_0) logs "failed to restore kv cache" and "does not fit this draft context", returns 200, and the draft starts empty.
Correctness
| check | method | result |
|---|---|---|
| Targeted reproduction of each claim, both backends | master vs PR vs cherry-pick, cases a-e, MTP / DFlash / draft-simple | PASS |
| Byte counts | n_written, n_read vs file size, appendix offset |
PASS |
| Old files, both directions | cross-format restores | PASS (PR file on upstream code drops the draft) |
| Bad appendix, draft KV type change, empty slot | crafted files, -ctkd q8_0 |
PASS, soft fail, no crash |
ROCm HIP_LAUNCH_BLOCKING unset and =1 |
MTP cases a and c | PASS, identical |
| Greedy text, master vs PR, same settings | sha of the 128 tokens | identical in every case |
| Disk writes | /proc/<pid>/io, device sectors, idle baseline |
measured, see the table |
Server pytest suite (tools/server/tests) |
- | not run, not available in our environment |
scripts/server-test-*.py |
- | not run, they test tool calls and structured output, not slots |
| Logit parity, KLD/PPL, test-backend-ops, llama-bench | - | not applicable, no compute change |
Disk writes
| case | backend | tree | file | write_bytes | cancelled | device |
|---|---|---|---|---|---|---|
| MTP | Vulkan | master | 893,899,252 | 893,906,944 | 0 | 894,006,599 |
| MTP | Vulkan | PR | 920,493,928 | 920,498,176 | 0 | 920,728,306 |
| MTP | ROCm | master | 893,899,252 | 893,906,944 | 0 | 894,082,394 |
| MTP | ROCm | PR | 920,493,928 | 920,498,176 | 0 | 920,671,646 |
| draft-simple | Vulkan | master | 85,404,904 | 85,405,696 | 0 | 85,609,928 |
| draft-simple | Vulkan | PR | 122,022,632 | 122,028,032 | 0 | 122,109,632 |
| draft-simple | ROCm | master | 85,404,904 | 85,405,696 | 0 | 85,486,120 |
| draft-simple | ROCm | PR | 122,022,632 | 122,028,032 | 0 | 122,107,056 |
Heavy-user estimate, assuming 200 saves a day of 16k-token slots. On the 27B, master writes about 1.79 GB per save (357 GB/day) and the PR adds 67.5 MB per save (+13.5 GB/day, +3.8%). With draft-simple, master writes 470 MB per save (94 GB/day) and the PR adds 202 MB per save (+40.3 GB/day, +43%). For a 2 TB client drive rated 600-1200 TBW, 1% of life is 6-12 TB. The PR's extra alone uses that in 444-889 days (MTP) or 149-298 days (draft-simple). Master's own saves at this rate use it in 17-34 days.
Findings in full
- Blocking. Upstream ggml-org#30574 (
ea736c1d5, merged 2026-10-15) addssave_slot_draft/load_slot_draftat the same place, with the same magic0x54464453and version 1. Its appendix has two blobs:data_dftanddata_specfromcommon_speculative_get_state(the EAGLE3 deferred boundary on recurrent and hybrid targets). Master has not synced it yet. The version field cannot tell the two layouts apart. Upstream also doesllama_memory_seq_rmon the draft after a failedllama_state_seq_set_data_ext, and returns the bytes it consumed when it drops the draft state. - Should fix if the PR code stays.
server-context.cpp:3082-3085returns 0 after a failed draftset_datawithout clearing the draft sequence. The plain, recurrent and hybrid caches clean up on failure. iswa (src/llama-kv-cache-iswa.cpp:262-265), dsa-iswa, hybrid-iswa and msa read the base cache first and do not roll it back when the second part throws. The log then says "drafting starts empty" while base-layer cells stay. The earlier head had thisseq_rm. Upstream's code fixes it. - Nit. When the server has no draft context, or the appendix is rejected,
n_readis less than the file size. This matches the checkpoint appendix convention. - Shared with upstream. A rejected checkpoint appendix makes the draft reader start at the wrong offset, so a valid draft appendix is ignored. The MTP
pending_hrow, DFlash per-sequence rows and n-gram caches are not saved by either version, which costs acceptance only. - Test.
n_read == n_writtenproves the draftset_datasucceeded. The continuation repeats the saved prompt, and that path does not hit the master HTTP 500. The 500 needs a prompt that extends the saved one.
Claims
- A restored slot drafts like its own prefill: reproduced for draft-mtp and draft-simple on both backends (exact counts). Not reproduced for draft-dflash: master already restores at the own-prefill rate.
n_readandn_writteninclude the appendix and equal the file size: reproduced.- A failed append returns an error: not tested at runtime (we could not make the append fail). The code path was read.
- Older readers ignore the appendix, and a file without it restores with an empty draft: reproduced. On master with draft-simple, that empty-draft path is where the HTTP 500 shows up.
- The output does not change: the greedy text was identical for master and the PR under the same settings.
test_slot_save.pypasses: not tested, pytest is not available in our environment.
Not tested
- The server pytest suite, including the new test and its failure on the earlier head.
- An iswa draft model (Gemma family), so finding 2 is from code reading only.
- A non-empty speculative state blob (EAGLE3 on a recurrent or hybrid target).
- DFlash on the cherry-pick on ROCm.
- Prompts over 6.5k tokens:
-c 16384 -np 2gives each slot 8192. - Images in a saved slot.
- The SSD's own write counters.
|
@rcfa sorry, couple more things to fix, almost there! sorry for taking so long to review this |
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. [no release] (cherry picked from commit ea736c1)
…ontext Three things upstream's test_slot_restore_draft_state does not check: - n_written and n_read equal the size of the file, so the appendix is counted on both sides. - the appendix is the tail of the file. The test reads the magic, the version and the two buffers at its offset and checks that they stop at the end of the file, instead of looking for four bytes anywhere in the state payload. - the file is restored into a slot that still holds another conversation, and the completion after it extends the restored prompt. Without the parent commit the slot keeps the other conversation's draft state, so the draft positions are not consecutive and the server answers 500. Assisted-by: Claude Code
85f5320 to
80a30fd
Compare
|
Taken as asked: the implementation is now upstream's, and the branch is
Verification. CPU
So both tests fail without the feature. Each commit builds on its own. Not verified. The acceptance table on this branch's binary: we will re-measure it on gfx1150 and replace the Written by Claude Code (an AI agent) for rcfa; rcfa owns it. |
|
Thanks @rcfa. The upstream sync in #293 brought in ggml-org#30574 ( The extra test ( |
…ot choice onto server_slot_sched ggml-org ggml-org#32154 moved the prompt cache out of server-task.cpp into server-slot-sched.{h,cpp} and the slot choice out of get_available_slot() into server_slot_sched::select(); ggml-org#30137 shares context checkpoints as std::shared_ptr<const common_prompt_checkpoint>. Our server stack cannot be replayed onto that, so it is ported here in one piece, with the behaviour unchanged: - the persistent prompt cache (--cache-dir, --cache-dir-max: memory-mapped entries with a metadata sidecar, owner-only files, state staged through host memory, restore at start, the key by state format and without the batch sizes), now on server_prompt_cache in server-slot-sched.cpp - the idle slots saved to it on exit (server_context::save_slots_to_cache) - --ctx-checkpoints-dir (context checkpoints in unlinked files, read back only to rewind; a failed read falls back to reprocessing; the draft data test-loaded by size_dft()) - update_prompt_cache(), on top of halo-box#176's purge loop (merged as f2230a8): the load passes the checkpoint and similarity arguments, and an entry that fails to restore on an empty pool is discarded - select(): conversation_id first, slot_match_skip in the similarity, --slot-keep-min; upstream's LRU (empty slots first) is kept - the checkpoint threshold for disk entries now follows server_prompt::get_reuse() The slot file's draft appendix is upstream's (same SDFT magic and version as our halo-box#171, but with the speculative state as a second buffer), so slot files written by the previous build restore without their draft state once. Ports, in their original order: 0d1c648, 6cb2d84, 22ba4d2 (Daniele Zannotti), 19aa31c, 9c6f7d7, c03c65b, 1c4eaac, c722f60, a4e4da8, 6d4cce5, ec3d0fd, d544de2, cf99aa9, a707cc8. Dropped: 12837c0 and f1ee218 (ggml-org ggml-org#30574 saves the draft state in the slot file). tools/server/tests: test_prompt_cache_disk.py, test_slot_save.py and test_kv_keep_only_active.py, 39 passed on a CPU build. Co-authored-by: Daniele Zannotti <d.zannotti@me.com> Assisted-by: Claude Code
…ot choice onto server_slot_sched ggml-org ggml-org#32154 moved the prompt cache out of server-task.cpp into server-slot-sched.{h,cpp} and the slot choice out of get_available_slot() into server_slot_sched::select(); ggml-org#30137 shares context checkpoints as std::shared_ptr<const common_prompt_checkpoint>. Our server stack cannot be replayed onto that, so it is ported here in one piece, with the behaviour unchanged: - the persistent prompt cache (--cache-dir, --cache-dir-max: memory-mapped entries with a metadata sidecar, owner-only files, state staged through host memory, restore at start, the key by state format and without the batch sizes), now on server_prompt_cache in server-slot-sched.cpp - the idle slots saved to it on exit (server_context::save_slots_to_cache) - --ctx-checkpoints-dir (context checkpoints in unlinked files, read back only to rewind; a failed read falls back to reprocessing; the draft data test-loaded by size_dft()) - update_prompt_cache(), on top of halo-box#176's purge loop (merged as f2230a8): the load passes the checkpoint and similarity arguments, and an entry that fails to restore on an empty pool is discarded - select(): conversation_id first, slot_match_skip in the similarity, --slot-keep-min; upstream's LRU (empty slots first) is kept - the checkpoint threshold for disk entries now follows server_prompt::get_reuse() The slot file's draft appendix is upstream's (same SDFT magic and version as our halo-box#171, but with the speculative state as a second buffer), so slot files written by the previous build restore without their draft state once. Ports, in their original order: 0d1c648, 6cb2d84, 22ba4d2 (Daniele Zannotti), 19aa31c, 9c6f7d7, c03c65b, 1c4eaac, c722f60, a4e4da8, 6d4cce5, ec3d0fd, d544de2, cf99aa9, a707cc8. Dropped: 12837c0 and f1ee218 (ggml-org ggml-org#30574 saves the draft state in the slot file). tools/server/tests: test_prompt_cache_disk.py, test_slot_save.py and test_kv_keep_only_active.py, 39 passed on a CPU build. Co-authored-by: Daniele Zannotti <d.zannotti@me.com> Assisted-by: Claude Code
…ot choice onto server_slot_sched ggml-org ggml-org#32154 moved the prompt cache out of server-task.cpp into server-slot-sched.{h,cpp} and the slot choice out of get_available_slot() into server_slot_sched::select(); ggml-org#30137 shares context checkpoints as std::shared_ptr<const common_prompt_checkpoint>. Our server stack cannot be replayed onto that, so it is ported here in one piece, with the behaviour unchanged: - the persistent prompt cache (--cache-dir, --cache-dir-max: memory-mapped entries with a metadata sidecar, owner-only files, state staged through host memory, restore at start, the key by state format and without the batch sizes), now on server_prompt_cache in server-slot-sched.cpp - the idle slots saved to it on exit (server_context::save_slots_to_cache) - --ctx-checkpoints-dir (context checkpoints in unlinked files, read back only to rewind; a failed read falls back to reprocessing; the draft data test-loaded by size_dft()) - update_prompt_cache(), on top of halo-box#176's purge loop (merged as f2230a8): the load passes the checkpoint and similarity arguments, and an entry that fails to restore on an empty pool is discarded - select(): conversation_id first, slot_match_skip in the similarity, --slot-keep-min; upstream's LRU (empty slots first) is kept - the checkpoint threshold for disk entries now follows server_prompt::get_reuse() The slot file's draft appendix is upstream's (same SDFT magic and version as our halo-box#171, but with the speculative state as a second buffer), so slot files written by the previous build restore without their draft state once. Ports, in their original order: 0d1c648, 6cb2d84, 22ba4d2 (Daniele Zannotti), 19aa31c, 9c6f7d7, c03c65b, 1c4eaac, c722f60, a4e4da8, 6d4cce5, ec3d0fd, d544de2, cf99aa9, a707cc8. Dropped: 12837c0 and f1ee218 (ggml-org ggml-org#30574 saves the draft state in the slot file). tools/server/tests: test_prompt_cache_disk.py, test_slot_save.py and test_kv_keep_only_active.py, 39 passed on a CPU build. Co-authored-by: Daniele Zannotti <d.zannotti@me.com> Assisted-by: Claude Code
…lot_sched ggml-org ggml-org#32154 moved the prompt cache out of server-task.cpp into server-slot-sched.{h,cpp} and the slot choice out of get_available_slot() into server_slot_sched::select(); ggml-org#30137 shares context checkpoints as std::shared_ptr<const common_prompt_checkpoint>. Our server stack cannot be replayed onto that, so it is ported here in one piece, with the behaviour unchanged: - the persistent prompt cache (--cache-dir, --cache-dir-max: memory-mapped entries with a metadata sidecar, owner-only files, state staged through host memory, restore at start, the key by state format and without the batch sizes), now on server_prompt_cache in server-slot-sched.cpp - the idle slots saved to it on exit (server_context::save_slots_to_cache) - update_prompt_cache(), on top of halo-box#176's purge loop (merged as f2230a8): the load passes the checkpoint and similarity arguments, and an entry that fails to restore on an empty pool is discarded - select(): conversation_id first, slot_match_skip in the similarity, --slot-keep-min; upstream's LRU (empty slots first) is kept - the checkpoint threshold for disk entries now follows server_prompt::get_reuse() --ctx-checkpoints-dir is upstream's (halo-box#180 as merged, ebe8231, with --ctx-checkpoints-ram). The context checkpoints that a load builds from a disk entry are new objects, so the prompt cache hands them to the server (restored_from_disk), which passes them to hold_checkpoint() like the ones a task creates: the checkpoint budget decides for them too. The earlier port wrote each of them to the directory at once. The slot file's draft appendix is upstream's (same SDFT magic and version as our halo-box#171, but with the speculative state as a second buffer), so slot files written by the previous build restore without their draft state once. Ports, in their original order: 0d1c648, 6cb2d84, 22ba4d2 (Daniele Zannotti), 19aa31c, 9c6f7d7, c03c65b, 1c4eaac, c722f60, a4e4da8, 6d4cce5, ec3d0fd, d544de2, cf99aa9, a707cc8. Dropped: 12837c0 and f1ee218 (ggml-org ggml-org#30574 saves the draft state in the slot file). tools/server/tests: test_prompt_cache_disk.py (with a new test: restored checkpoints follow --ctx-checkpoints-ram, which fails on the earlier port), test_slot_save.py and test_kv_keep_only_active.py, 44 passed on a CPU build. Co-authored-by: Daniele Zannotti <d.zannotti@me.com> Assisted-by: Claude Code
…lot_sched ggml-org ggml-org#32154 moved the prompt cache out of server-task.cpp into server-slot-sched.{h,cpp} and the slot choice out of get_available_slot() into server_slot_sched::select(); ggml-org#30137 shares context checkpoints as std::shared_ptr<const common_prompt_checkpoint>. Our server stack cannot be replayed onto that, so it is ported here in one piece, with the behaviour unchanged: - the persistent prompt cache (--cache-dir, --cache-dir-max: memory-mapped entries with a metadata sidecar, owner-only files, state staged through host memory, restore at start, the key by state format and without the batch sizes), now on server_prompt_cache in server-slot-sched.cpp - the idle slots saved to it on exit (server_context::save_slots_to_cache) - update_prompt_cache(), on top of halo-box#176's purge loop (merged as f2230a8): the load passes the checkpoint and similarity arguments, and an entry that fails to restore on an empty pool is discarded - select(): conversation_id first, slot_match_skip in the similarity, --slot-keep-min; upstream's LRU (empty slots first) is kept - the checkpoint threshold for disk entries now follows server_prompt::get_reuse() --ctx-checkpoints-dir is upstream's (halo-box#180 as merged, ebe8231, with --ctx-checkpoints-ram). The context checkpoints that a load builds from a disk entry are new objects, so the prompt cache hands them to the server (restored_from_disk), which passes them to hold_checkpoint() like the ones a task creates: the checkpoint budget decides for them too. The earlier port wrote each of them to the directory at once. The slot file's draft appendix is upstream's (same SDFT magic and version as our halo-box#171, but with the speculative state as a second buffer), so slot files written by the previous build restore without their draft state once. Ports, in their original order: 0d1c648, 6cb2d84, 22ba4d2 (Daniele Zannotti), 19aa31c, 9c6f7d7, c03c65b, 1c4eaac, c722f60, a4e4da8, 6d4cce5, ec3d0fd, d544de2, cf99aa9, a707cc8. Dropped: 12837c0 and f1ee218 (ggml-org ggml-org#30574 saves the draft state in the slot file). tools/server/tests: test_prompt_cache_disk.py (with a new test: restored checkpoints follow --ctx-checkpoints-ram, which fails on the earlier port), test_slot_save.py and test_kv_keep_only_active.py, 44 passed on a CPU build. Co-authored-by: Daniele Zannotti <d.zannotti@me.com> Assisted-by: Claude Code
What this is now
Upstream merged this feature on 2026-10-15 as ggml-org#30574 (
ea736c1d5, "server: save the draftstate in the slot file"). This PR is that commit, cherry-picked, plus one test commit of our own:
fb8efe8a4git cherry-pick -x ea736c1d5— upstream's implementation, unmodified80a30fd06tests :the draft state appendix, its byte counts and a stale draft contextOur own implementation (
aa1251614) is gone. It wrote a different payload under the sameSDFTmagic and thesame version 1, so a file written by either side was unreadable to the other and indistinguishable from a corrupt
one: restoring one of our files on upstream's code logs "invalid draft state ... ignored" and silently continues
with an empty draft context. One of the two layouts had to go, and it was not going to be the merged one.
Why the feature matters
A slot save file holds the target context state and, since #98, the context checkpoints. It did not hold the
draft context's state. A draft fed from the target's batches (
draft-mtphere) has therefore seen none of therestored prompt after
/slots/{id}?action=restore, so fewer drafts are accepted for the rest of theconversation; if the slot held another conversation before the restore, the draft context still holds that one.
We use slot save and restore to move conversations between two quants of the same model under memory pressure
(save every slot, restart the server on the smaller quant, restore), which is how we found it.
Upstream's commit appends, after the checkpoint appendix, the
SDFTmagic, version 1, the draft context blob anda speculative state blob (
common_speculative_get_state). Older readers stop after the checkpoints; a filewithout the appendix restores with an empty draft context. The target verifies every draft, so no output changes.
The test commit
test_slot_save.pygainstest_slot_save_restore_draft_state_appendix, on top of upstream's own test, which itleaves untouched. It covers the three things upstream's test does not:
n_writtenequals the file size, andn_readafter the restore equalsn_written.uint64length-prefixed blobs —and asserts the walk ends exactly at EOF. That pins the appendix to the tail of the file, so its offset is the
size of the file before the appendix by construction, and a stray
SDFTinside the state payload cannot passfor it: a false match would not finish at EOF.
completion after it extends the saved prompt by a sentence. That is the case which returns HTTP 500 on master
with
draft-simple("failed to process speculative batch"), so the test guards that fix too.Red and green, same host, CPU
llama-server(Release, gcc 16.2),tools/server/tests/unit/test_slot_save.py:c495f90f5test_slot_restore_draft_state(assert 36 == 23) and ours80a30fd06So both tests detect the missing feature, and neither passes vacuously.
Measurements
The table below was measured on our superseded implementation (
b7149217aon master02e2c2b55), not onthis branch. It is kept because it quantifies the feature, which is unchanged; the review reports that the
cherry-pick gives the same results on Strix Halo, and upstream's own figure is 57.6% acceptance with the draft
state against 41.4% without. We will re-measure on the cherry-pick on gfx1150 and replace this table.
P = 16384 tokens of unseen text, saved after a prefill with
n_predict: 0; every run then sends P plus the next64 tokens and decodes 128 tokens greedily (
ignore_eos). One run each:Every continuation processed only the 64 new tokens. The slot file grows by the draft state, 36.6 MiB at 16k
tokens for this MTP head (771 -> 807 MiB).
Correctness
test_slot_save.pyrun above, on this branch's binary.test-backend-ops, the corpus comparison andllama-benchdo not apply.
directions, a truncated appendix, a bad version, a draft KV type change and an empty slot.
Not verified
draft-mtpmeasured;draft-simplehas the round-trip tests.draft-eagle3,draft-dflashanddraft-dsparkkeep their draft context the same way, but we have no such draft models.tools/serverpytest suite: its other presets need model downloads we did not make.Generated with Claude Code