UPSTREAM PR #20428: server: fix multi-turn cache reuse for hybrid/recurrent models#1248
Open
UPSTREAM PR #20428: server: fix multi-turn cache reuse for hybrid/recurrent models#1248
Conversation
When llama_memory_seq_rm fails (common for hybrid models like Qwen3.5-A3B where recurrent memory lacks a cell-level checkpoint at the trim position), try restoring the nearest server-level checkpoint instead of clearing all memory and forcing full prompt reprocessing. This enables multi-turn cache reuse for hybrid models: on turn 2+, the server restores the checkpoint closest to the common prefix boundary rather than reprocessing the entire conversation from scratch.
For hybrid models like Qwen3.5-A3B, even short prompts (< 64 tokens) need checkpoints to enable multi-turn cache reuse. Without a checkpoint, the recurrent state cannot be rolled back and every new turn forces full prompt reprocessing. Remove the pos_max >= 64 and spacing >= 64 thresholds for hybrid/recurrent models while keeping them for SWA-only models.
|
No meaningful performance changes were detected across 119965 analyzed functions in the following binaries: build.bin.llama-tts, build.bin.llama-cvector-generator, build.bin.llama-bench, build.bin.libllama.so, build.bin.libmtmd.so, build.bin.libggml-base.so, build.bin.libggml-cpu.so, build.bin.libggml.so, build.bin.llama-quantize, build.bin.llama-qwen2vl-cli, build.bin.llama-tokenize, build.bin.llama-gemma3-cli, build.bin.llama-gguf-split, build.bin.llama-llava-cli, build.bin.llama-minicpmv-cli. 🔎 Full breakdown: Loci Inspector |
|
Sorry I commented in wrong PR before. |
efc22ce to
945fa3a
Compare
8c39ead to
418d9f2
Compare
d997939 to
8527fd7
Compare
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.
Note
Source pull request: ggml-org/llama.cpp#20428
Summary
Multi-turn conversations with hybrid models (e.g. Qwen3.5-A3B) currently force full prompt reprocessing on every turn because:
Short prompts never get checkpoints: The
pos_max >= 64minimum threshold prevents checkpoint creation for prompts shorter than ~68 tokens. For hybrid models, even short prompts need checkpoints since the recurrent state cannot be rolled back without one.seq_rmfailure clears everything: Whenllama_memory_seq_rmfails (the recurrent memory has no cell-level checkpoint at the trim position), the server clears all memory instead of trying to restore from a server-level checkpoint.Changes
Lower checkpoint thresholds for hybrid/recurrent models: Remove the
pos_max >= 64and spacing>= 64minimums for hybrid/recurrent models while keeping them for SWA-only models. This ensures checkpoints are always created during prompt processing, enabling multi-turn reuse.Restore checkpoint on
seq_rmfailure: Whenseq_rmfails, search for the nearest server-level checkpoint before the trim position and restore it, instead of clearing all memory. This is a safety net for cases where the primary checkpoint restore path (thepos_min > pos_min_tholdcheck) doesn't trigger.Test results (Qwen3.5-35B-A3B, macOS Apple Silicon)
Q4_K_XL quantization:
Q8_K_XL quantization:
Server logs confirm checkpoints are created and restored:
Previously, the logs showed:
Prior work and acknowledgments
This PR builds on the checkpoint infrastructure developed across several PRs:
seq_rmfails for hybrid models--checkpoint-every-nbfor finer-grained rollbackRelated: #20075 @eauchs — speculative decoding fixes for hybrid SSM/MoE (Qwen3.5)