Repository navigation
draft: sliding window attention for Qwen3.6 draft model - #129
Merged
Merged
Conversation
Contributor
howard0su
marked this pull request as draft
May 8, 2026 23:20
Implement per-layer K/V truncation in the draft graph for SWA layers (Qwen3.6 pattern: layers 0..n-2 use sliding window, last layer full). When --draft-swa=<window> is set and ctx_len > window, SWA layers: - Window target_feat to last <window> positions via ggml_view_3d - Adjust positions_k to start from the window offset - Use eff_total_k = window + q_len for K/V reshape The draft context cap is controlled separately via --draft-ctx-max=N (default 2048). To exercise SWA, set draft-ctx-max > draft-swa so that the full-attention last layer sees more context while SWA layers stay windowed. Usage: --draft-swa=2048 --draft-ctx-max=4096 DFLASH27B_DRAFT_SWA=2048 DFLASH27B_DRAFT_CTX_MAX=4096 Co-authored-by: Copilot <[email protected]>
This was referenced May 9, 2026
Contributor
howard0su
marked this pull request as ready for review
May 10, 2026 11:23
dusterbloom
added a commit
to dusterbloom/lucebox-hub
that referenced
this pull request
May 10, 2026
Adapts PR Luce-Org#129 (howard0su/swa) — sliding-window attention truncation for the qwen3 draft graph — to the gemma4 cached-KV draft layout. draft graph (gemma4_dflash_graph.cpp): * draft_swa_trunc_enabled() — opt-in via DFLASH_DRAFT_SWA_TRUNC=1. For SWA layers (first n-1; final layer stays full attn), restrict K_full / V_full views to the last (sliding_window + n_tokens) slots and copy a contiguous mask slice (ggml_cont) for FA. * draft_rope() — single wrapper around ggml_rope_ext used at all three draft RoPE sites. Optional YaRN scaling via DFLASH_DRAFT_YARN=1 (default n_ctx_orig=32768, override via DFLASH_DRAFT_YARN_NCTX_ORIG). test harness (test_gemma4_dflash.cpp): * --draft-swa-trunc CLI flag mirroring the env var. * Bundles the bench-harness infrastructure that has been in-progress on this branch: adaptive draft_max, --draft-kv-cap override, --mem-diag, --fa-window plumbing through build_gemma4_step. Bench (RTX 3090, gemma-4-31B-Q4_K_M target + qwen3 5-layer draft, 50K-token prompt, n_predict=64, ctx=65536, NO_VMM=1): cap | SWA | AL | decode tok/s ------+-----+------+-------------- 2096 | off | 1.36 | 1.31 2096 | on | 1.73 | 1.68 8192 | off | 1.02 | 4.29 8192 | on | 1.68 | 6.96 <-- +65% AL, +62% decode The SWA truncation does not fix the underlying long-position acceptance collapse (the qwen3 draft model itself appears to have been effectively trained at <=32K positions; see comment near the sliding re-prefill block in test_gemma4_dflash.cpp). It is a real partial improvement shippable today; the residual cliff needs a long-context drafter. The diff is large because it bundles the pre-existing harness infrastructure noted above; happy to split if reviewers prefer.
5 of 6 tasks
oliveagle
pushed a commit
to oliveagle/lucebox-hub
that referenced
this pull request
May 22, 2026
draft: sliding window attention for Qwen3.6 draft model
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.


Implement per-layer K/V truncation in the draft graph for SWA layers (Qwen3.6 pattern: layers 0..n-2 use sliding window, last layer full, while Qwen3.5 draft model use all full layers).
When --draft-swa= is set and ctx_len > window, SWA layers:
Also raises the effective DRAFT_CTX_MAX when SWA is enabled so that ctx_len can exceed the window size and SWA truncation can activate.
Usage: --draft-swa=2048 or DFLASH27B_DRAFT_SWA=2048
Benchmark (RTX 2080 Ti, Qwen3.6-27B Q4_K_M + DFlash draft)
Significant AL and throughput improvement at 6K–16K context. No regression on short prompts (HumanEval bench: identical AL at 5.47).