Speculative prefill - #27692
Conversation
…e prefill
Assisted-by: Antigravity
Assisted-by: Antigravity
Assisted-by: Antigravity
Assisted-by: Antigravity
|
Hi @rockofox, 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. |
|
Can we set which device to put prefill draft model on ? I have a 3060ti + 2x5060ti setup, it much more convenience to put that draft model on 3060ti and let dual 5060ti handle full 27b model instead. Btw, thanks you so much 👏 |
Assisted-by: Antigravity
Assisted-by: Antigravity
|
very interesting one i think this would help us to use the rpc gpu. right now with help of deflash2 i was able to decode fast almost near to the sm tensor level but when i am using the rpc gpu the prefill went to really down which hurt the using the rpc gpus this would help everyone if its woks well i will test it when i have the time. |
…t reuse Assisted-by: Antigravity
Assisted-by: Gemini
Assisted-by: Gemini
Assisted-by: Gemini
…e prefill Assisted-by: Gemini
…ahead in CLI Assisted-by: Antigravity
Bug: DFlash2 draft decode crashes when combined with speculative prefill (non-contiguous KV positions)SummaryRunning Each feature works correctly on its own (confirmed separately below). The crash only occurs when both are active at the same time. Setup
Relevant server flagsSequence of events from the log
Root cause hypothesisSpeculative prefill's sparse retention is designed to feed a target model with attention over the full theoretical context (i.e. it's fine with position gaps at the target-model level, since the target model's KV cache is built directly from the retained sparse token set). DFlash2's draft decode path ( In other words: two independently-developed PRs each made a valid assumption about the KV cache/position handling that the other silently breaks. Neither PR was written with the other in mind — they were merged upstream only days apart, and I don't see evidence either was tested against the other. Reproduction
WorkaroundEach feature works fine in isolation — running with only DFlash2 or only speculative prefill enabled, everything loads and serves correctly. The bug only manifests when both are active together. Suggested fix direction (not verified, just a guess from the log)Either:
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
@rockofox can you check above error? |
…ent/hybrid and DFlash/DSpark Assisted-by: opencode
Assisted-by: opencode
|
@gopinath87607 I'm not sure if compatibility with DFlash2 is feasible right now, especially since that's not merged yet. Let's see |
should i test it with dflash2 and rpc ? if possiple maybe you can change change name from prefill to preflash little bit attractive |
|
Like I mentioned earlier, DFlash2 currently cannot work with speculative prefill, since it needs a full, continous prefill context. It should be possible to make it work, but this is out of scope for this PR for now, especially since DFlash2 hasn't been merged to master yet. I can revisit compatibility with DFlash2 once both PRs are merged. In the meantime, my personal advice is that you try using MTP instead of DFlash2. It's also quite fast (especially when combined with ngram-mod) and works with spec prefill.
I don't think that makes sense, since the name is based on the original paper for clarity. Also, the word "Flash" would imply that this has something to do with e.g DFlash, which it hasn't really |
Overview
This PR implements Speculative Prefill, based on the ICML 2025 paper: "Speculative Prefill: Turbocharging TTFT with Lightweight and Training-Free Token Importance Estimation" by Jingyu Liu, Beidi Chen, Ce Zhang (arXiv, GitHub)
Note
In contrast to speculative decoding, this is not lossless and can cause model performance degradation.
Approach
In long-context inference, prefill TTFT scales quadratically with prompt length. Speculative prefill reduces this compute by using a smaller draft model to estimate which context tokens are most relevant to the query before evaluating the main target model:
kq_soft_max) are captured during draft generation via an evaluation callback.Benchmarks & Performance Evaluation
All benchmarks were run natively on Vulkan (
AMD Radeon 8060S, RADV STRIX_HALO, 128 GiB unified LPDDR5X) using Qwen3.8-27B (Q6_K_XL) as target and Qwen3.5-2B (Q4_K_XL) as the primary draft model (unless noted otherwise).1. Draft Model Sizing & Context Scaling
Draft Model Comparison ($N = 1609$ , $p = 0.15$ ):
Context Length Scaling (27B Target + 2B Draft):
2. Synthetic Retrieval & QA Benchmarks
Failure Mode Analysis & Operational Limits
Because speculative prefill drops tokens permanently from target prefill, accuracy drops when the token budget ($p \cdot N$ ) cannot contain all non-redundant evidence across separate chunks.
1. Draft Model Comparison on Stress Tests (2B vs. 9B)
High-Entropy Multi-Key Retrieval (5 keys across 5 sections, ~1,100 tokens):
Distributed Summation (Box A: 15 + Box B: 25 + Box C: 60 = 100):
100 units100 units100 units100 units100 units100 units100 units100 units40 units77 units60) prunedNon-Parametric Multi-Hop QA (Target Year:
2348, 12 non-redundant documents):2348234823482348234823482348228021852. Multi-Ratio Stress Matrix (Qwen 27B + 2B)
ZETA-9999.Practical Operating Guidelines
Example Usage
Additional information
Has been mentioned as a feature request here: #19082
Requirements