Skip to content

spec-decode: eliminate replay pass via fast-rollback - #389

Merged
davide221 merged 2 commits into
Luce-Org:mainfrom
howard0su:verify
Jun 15, 2026
Merged

davide221 merged 2 commits into
Luce-Org:mainfrom
howard0su:verify

Conversation

@howard0su

@howard0su howard0su commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

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%)

Review in cubic

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%)

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 10 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread server/src/qwen35/qwen35_backend.cpp Resolved
Comment thread server/src/qwen35/qwen35_backend.cpp Resolved
…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]>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

@davide221
davide221 merged commit 222137a into Luce-Org:main Jun 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants