Repository navigation
Conversation
|
Hi @myml, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
|
Tested on gfx1201 (R9700), Qwen3.8-27B Q5_K_M + draft-mtp, f16 KV cache (K and V), ~100k context:
Output after restoring a checkpoint is identical to master (greedy, 4 requests), draft acceptance unchanged. Running it in production since today. |
hiromimie
added a commit
to hiromimie/llama.cpp
that referenced
this pull request
Oct 7, 2026
…gml-org#29509) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
hiromimie
added a commit
to hiromimie/llama.cpp
that referenced
this pull request
Oct 7, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
sanmai
reviewed
Oct 14, 2026
Context checkpoints are written with LLAMA_STATE_SEQ_FLAGS_PARTIAL_ONLY, which asks for only the parts of the memory that cannot be rolled back. llama_memory_hybrid::state_write() implements that by skipping mem_attn and writing only mem_recr, and state_read() does the same on the way back, so the target's attention cache is deliberately left out of every checkpoint and stays resident. The draft model's context is a plain llama_kv_cache -- a prefix-addressed attention cache, the same kind of memory as mem_attn. But llama_kv_cache:: state_write() discards the flags (GGML_UNUSED(flags)) and serializes every cell, so the PARTIAL_ONLY request has no effect on it and the whole draft KV ends up in every checkpoint. That is what makes checkpoint size grow with the context: the draft is sized to the target's n_ctx, so an MTP or draft-model setup stores on the order of 4 KiB per token in each checkpoint. Measured on Qwen3.8-27B (16 attention + 48 recurrent layers), MTP draft, q8_0 KV, -c 262144, checkpoint 1..8 over a 13789-token prompt: before: 157.673, 165.724, 173.775, 181.825, 189.876, 197.927, 201.778, 203.734 MiB after: 149.626 MiB each The slope is 46.061 MiB over 11723 tokens, i.e. 4.02 KiB per token, and extrapolating it to zero tokens lands exactly on the 149.626 MiB that the recurrent state alone costs. So the draft term is linear in the context and overtakes the recurrent state around 38k tokens; at 256k it is 1.0 GiB per checkpoint, which over the 144 checkpoints -ctxcp allows is ~150 GiB instead of ~21 GiB. Skipping the draft needs no matching change on the way back. Its cells are position-addressed and survive like mem_attn's, and load_dft() returns early when data_dft is empty, so restoring such a checkpoint leaves the draft memory alone rather than clearing it (the clear in state_read_sinfo is guarded by seq_id == -1, and an empty stream is skipped outright). The per-draft-step rollback checkpoint in slot.spec_ckpt is untouched.
Author
|
merged #30514 |
wispoffates
pushed a commit
to wispoffates/llama.cpp
that referenced
this pull request
Oct 24, 2026
Cherry-picked-from: ggml-org#29509
wispoffates
pushed a commit
to wispoffates/llama.cpp
that referenced
this pull request
Oct 25, 2026
Cherry-picked-from: ggml-org#29509
wispoffates
pushed a commit
to wispoffates/llama.cpp
that referenced
this pull request
Oct 26, 2026
Cherry-picked-from: ggml-org#29509
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.
Overview
Context checkpoints are written with
LLAMA_STATE_SEQ_FLAGS_PARTIAL_ONLY, which asks for only the parts of the memory that cannot be rolled back.llama_memory_hybrid::state_write()implements that by skippingmem_attnand writing onlymem_recr, andstate_read()does the same on the way back, so the target's attention cache is deliberately left out of every checkpoint and stays resident:The draft model's context is a plain
llama_kv_cache— a prefix-addressed attention cache, the same kind of memory asmem_attn. Butllama_kv_cache::state_write()discards the flags and serializes every cell, so thePARTIAL_ONLYrequest has no effect on it:So the whole draft KV ends up in every checkpoint. Since the draft is sized to the target's
n_ctx, checkpoint size grows linearly with the context instead of being the constant cost of the recurrent state.Skip the draft when creating a long-term checkpoint.
Measured
Qwen3.8-27B (16 attention + 48 recurrent layers), MTP draft, q8_0 KV,
-c 262144,-ctxcp 144, checkpoints 1..8 over a 13789-token prompt:The slope is 46.061 MiB over 11723 tokens, i.e. 4.02 KiB per token, and extrapolating it to zero tokens lands exactly on the 149.626 MiB that the recurrent state alone costs (which is
RS buffer / (1 + n_rs_seq), as expected).The draft term therefore overtakes the recurrent state around 38k tokens, and at 256k it is 1.0 GiB per checkpoint — over the 144 checkpoints
-ctxcpallows that is ~150 GiB instead of ~21 GiB.Greedy output and draft acceptance are unchanged.
Why no matching change on the way back
The draft's cells are position-addressed and survive like
mem_attn's, and the restore path already tolerates a checkpoint without draft data:common_prompt_checkpoint::load_dft()returns early whendata_dft.empty()(common/common.cpp), so the draft memory is left untouched rather than cleared.clear()inllama_kv_cache::state_read_sinfo()is guarded byseq_id == -1, and an empty per-stream cell count is skipped outright, so loading a partial state does not wipe the cache.The per-draft-step rollback checkpoint in
slot.spec_ckptis untouched: it goes throughupdate_dft()directly withON_DEVICEand does not depend on the long-term checkpoints.Requirements