Repository navigation
spec-decode: eliminate replay pass via fast-rollback - #389
Merged
Merged
Conversation
Replace the expensive snapshot→verify→restore→replay cycle with: - Pure-attention targets (Gemma4): KV truncation (no replay needed) - Hybrid SSM targets (Qwen35): fast-rollback using per-step SSM intermediate states captured during verify (GPU memcpy, no recompute) Key changes: - DFlashTarget interface: add truncate_kv(), has_recurrent_state(), supports_fast_rollback(), rollback_to() - Qwen35DFlashTarget: implement rollback via delta_captures (SSM dequant + conv cudaMemcpy2D), enable capture_delta_intermediate during verify - dflash_spec_decode.cpp: three-way branch (fast-rollback / legacy replay / pure-attention truncate) - qwen35_backend.cpp: daemon inline loop supports fast-rollback - server_main.cpp: add --fast-rollback CLI flag Fast-rollback uses the implicit bonus approach: target_tok[accept_n-1] seeds the next draft step and is guaranteed accepted as draft_tok[0], producing identical output with zero extra forward passes. Performance (Qwen3.6-27B, 256 tokens, RTX 2080 Ti): Baseline (replay): 36.5 tok/s Fast-rollback: 47.7 tok/s (+30%)
Contributor
There was a problem hiding this comment.
5 issues found across 10 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…x-pack Builds on Luce-Org#389's fast-rollback. Three groups of changes: Cubic review fixes (1 P0 + 4 P1) on the fast-rollback path: - respect the generation budget: commit_n = min(accept_n, need_commit_budget) in both spec-decode loops (the old path committed accept_n unbounded, overrunning the budget and emitting zero-initialised tokens) - rollback_to(): guard commit_n<=0 (size_t underflow -> OOB GPU read) - rollback_to(): null-check the ggml_get_to_fp32_cuda converter - honor cfg_.fast_rollback instead of hardcoding true - on rollback_to() failure, fall back to restore_kv+replay (don't abort) --ddtree crash fix: - the per-step SSM-intermediate cache is sized max_verify_tokens; copy the produced n_seq_tokens states into a destination view rather than asserting exact size-equality (the old GGML_ASSERT aborted whenever max_verify_tokens != n_seq_tokens, i.e. on every --ddtree generation). DDTree tree-verify in the server (verify_tree was a stub; only test_dflash drove the tree path): - DFlashTarget gains verify_tree / rollback_to_tree / project_hidden_to_topk (default unsupported, so chain and other backends are unaffected) - Qwen35DFlashTarget implements them: ancestor-masked tree forward, CPU posterior, and SSM/conv/target_feat/KV tree-path rollback - do_spec_decode runs the tree path under --ddtree when supported; plain generation only -- budget-hook / hint / stall / min-floor requests fall back to the chain verify path Verified on RTX 3090 (Qwen3.6-27B dense): coherent output, no crash, 43.8% accept / avg_commit 8.0 / ~117 tok/s vs chain 39.2% / 6.67 / ~66 (~1.8x). Gated to qwen35 dense + fast_rollback + no kvflash; all other targets transparently use chain verify. Cross-validated with codex. Co-Authored-By: WOZCODE <[email protected]>
Contributor
There was a problem hiding this comment.
2 issues found across 6 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="server/src/qwen35/qwen35_backend.cpp">
<violation number="1" location="server/src/qwen35/qwen35_backend.cpp:1920">
P1: DDTree feature-mirror sync missing cache_.target_feat null guard</violation>
</file>
<file name="server/src/common/dflash_target.h">
<violation number="1" location="server/src/common/dflash_target.h:17">
P2: Unnecessary strong include of `ddtree.h` in a widely-included interface header</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| } | ||
|
|
||
| // Sync draft-side feature mirror over the committed range. | ||
| if (feature_mirror_.target_feat && !draft_parked_) { |
Contributor
There was a problem hiding this comment.
P1: DDTree feature-mirror sync missing cache_.target_feat null guard
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At server/src/qwen35/qwen35_backend.cpp, line 1920:
<comment>DDTree feature-mirror sync missing cache_.target_feat null guard</comment>
<file context>
@@ -1828,6 +1828,105 @@ bool Qwen35Backend::do_spec_decode(int committed, int n_gen,
+ }
+
+ // Sync draft-side feature mirror over the committed range.
+ if (feature_mirror_.target_feat && !draft_parked_) {
+ draft_feature_mirror_sync_range(cache_.target_feat, cache_.target_feat_cap,
+ feature_mirror_, committed, emitted);
</file context>
Suggested change
| if (feature_mirror_.target_feat && !draft_parked_) { | |
| if (feature_mirror_.target_feat && cache_.target_feat && !draft_parked_) { |
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| #include "ddtree.h" |
Contributor
There was a problem hiding this comment.
P2: Unnecessary strong include of ddtree.h in a widely-included interface header
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At server/src/common/dflash_target.h, line 17:
<comment>Unnecessary strong include of `ddtree.h` in a widely-included interface header</comment>
<file context>
@@ -14,6 +14,8 @@
#include <cstdint>
#include <vector>
+#include "ddtree.h"
+
namespace dflash::common {
</file context>
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.
Replace the expensive snapshot→verify→restore→replay cycle with:
Key changes:
Fast-rollback uses the implicit bonus approach: target_tok[accept_n-1] seeds the next draft step and is guaranteed accepted as draft_tok[0], producing identical output with zero extra forward passes.
Performance (Qwen3.6-27B, 256 tokens, RTX 2080 Ti):
Baseline (replay): 36.5 tok/s
Fast-rollback: 47.7 tok/s (+30%)