dflash: fix VL/multimodal crash by clearing draft on position gap#7
Closed
dblmca wants to merge 1 commit into
Closed
dflash: fix VL/multimodal crash by clearing draft on position gap#7dblmca wants to merge 1 commit into
dblmca wants to merge 1 commit into
Conversation
When image/audio embeddings are processed by the target model, the
draft context's KV cache misses those positions because embedding-only
batches are correctly skipped in process(). This causes a
non-consecutive position error ("Y = X + 1" assertion) on the next
text batch, crashing the server with "failed to process speculative
batch".
Fix: detect position gaps between the draft KV cache and incoming
batch positions. When a gap is found (indicating image/audio tokens
were processed in between), clear the draft sequence and let
processing rebuild from the current text position. Speculative
decoding gracefully degrades for the first few tokens after an image,
then resumes normally.
This is the same class of bug as:
- EAGLE3 + VL (issue ggml-org#24816)
- MTP + VL (issue ggml-org#22867, fixed by calvarado2004)
Tested on Qwen3.6-27B VL with DFlash drafter:
- Text-only: 37-64% draft acceptance, ~2.2x speedup
- VL with images: no crash, face recognition working
- BrightPath benchmark: 0.976 score (vs 0.965 baseline), 264s (vs 581s)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Owner
|
Thanks. But need to close this per ggml-org#22105 (comment) for now. |
Author
|
No worries. Thanks for the great work.
…On Sun, Jun 28, 2026 at 6:56 AM Ruixiang Wang ***@***.***> wrote:
*ruixiang63* left a comment (ruixiang63/llama.cpp#7)
<#7 (comment)>
Thanks. But need to close this per ggml-org#22105 (comment)
<ggml-org#22105 (comment)>
for now.
—
Reply to this email directly, view it on GitHub
<#7?email_source=notifications&email_token=AGJFPXFSKFVCSACBY5PPCQL5CEPXHA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBSGYZTCMJRGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-4826311105>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGJFPXBJHUTTVUATN4RMA535CEPXHAVCNFSNUABGKJSXA33TNF2G64TZHMYTAOBWGYYTCNZWGU5US43TOVSTWNBXGYYTKMJSGQ2DTILWAI>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AGJFPXA7RYZKHQI2FRFULNL5CEPXHA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBSGYZTCMJRGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/AGJFPXH6AKJWITJHHHYJNMD5CEPXHA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBSGYZTCMJRGA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
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.
Summary
DFlash crashes when processing requests containing images (VL/multimodal) with:
Root cause: When the server processes image embeddings through the target model, the draft context's KV cache misses those positions (embedding-only batches are correctly skipped in
process()). This creates a non-consecutive position gap — the draft has positions0..X, but the next text batch starts atY > X+1.llama_decode(ctx_dft)enforces consecutive positions and fails.Fix: Detect position gaps between
llama_memory_seq_pos_max(ctx_dft)and the incoming batch position. When a gap is found, clear the draft sequence withllama_memory_seq_rm()and let processing rebuild from the current text position. Spec decode gracefully degrades for the first few tokens after an image, then resumes normally.Same class of bug as EAGLE3 + VL (ggml-org#24816) and MTP + VL (ggml-org#22867).
Benchmark Results
Tested on Qwen3.6-27B VL (Q4_K + mmproj-f16) with DFlash drafter on RTX 8000:
The benchmark covers all 11 BrightPath LLM call types including vision grading (math work, spelling, vocab, sentence combining/expansion) with synthetic handwriting images.
The patch
22 lines added to
common_speculative_impl_draft_dflash::process()— a position gap detection loop inserted before the main per-seq processing loop. No changes to any other files.Reviewed by Codex (gpt-5.5) and GLM 5.2 before submission — both approved the core mechanism and confirmed
llama_memory_seq_rm(mem, seq_id, -1, -1)is the correct API for full-sequence KV clear.Test plan