Repository navigation
perf: Replace Q8_0 format for KV with Q4_0 + Rotation, fix window_filled for long context - #108
Merged
Merged
Conversation
Three prefill optimizations that eliminate the Turing-specific ubatch scaling workaround and make long-context prefill dramatically faster: 1. FA windowed prefill: use g_fa_window (default 2048) during prefill, capping attention cost at O(ubatch × window) instead of O(ubatch × kv_len). Compute time stays flat at ~1.15s/step across 100K context (was 3.5s→13s). 2. last_token_logits_only: skip lm_head matmul for all but the last token during prefill (only last_tok is needed to seed decode). Saves ~233MB scratch at ubatch=384 and eliminates a large [vocab × ubatch] matmul. 3. gallocr pre-reserve: build max-shape graph before prefill loop so gallocr allocates its CUDA buffer once upfront, preventing hundreds of reallocations as the mask grows. Results (RTX 2080 Ti 22GB, Qwen3.5-27B Q4_K_M, Q4_0+rot_K, 100K tokens): Before: ubatch=16 (forced on Turing), 846s, degrading 97→30 tok/s After: ubatch=384, 301s, constant 330 tok/s (2.8× faster) Co-authored-by: Copilot <[email protected]>
Contributor
Author
|
need additional change in llama.cpp |
Contributor
There was a problem hiding this comment.
1 issue found across 5 files
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="dflash/src/qwen35_target_graph.cpp">
<violation number="1" location="dflash/src/qwen35_target_graph.cpp:74">
P1: Do not force graph-side K rotation for TQ3_0; that type already applies the WHT during quantization, so this double-rotates the K cache.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
…g quantization) TQ3_0 applies WHT during its own quantization path. Setting kv_k_rotated=true unconditionally caused double-rotation of the K cache when TQ3_0 was selected, corrupting attention scores. Now kv_k_rotated is only set when K type is not TQ3_0. Co-authored-by: Copilot <[email protected]>
Contributor
Author
|
need double check the quality of the output |
1 of 4 tasks
Contributor
Contributor
Author
|
Looks good although I cannot explain why AL is increased. |
davide221
added a commit
that referenced
this pull request
May 8, 2026
Resolve conflict in dflash/test/test_dflash.cpp: keep both main's TQ3_0 KV-stride padding block (q4rot fix from PR #108) and the PR's laguna-aware early-exit (skips the prompt/out positional-arg check when the target is laguna and dispatches to run_laguna_daemon). Co-Authored-By: WOZCODE <[email protected]>
dusterbloom
added a commit
to dusterbloom/lucebox-hub
that referenced
this pull request
May 8, 2026
Replaces the layer-by-layer gemma4_pflash_prefill() with a single-graph- per-chunk path using the new GGML_OP_FLASH_ATTN_SPARSE op for full- attention layers. SWA layers continue to use ggml_flash_attn_ext. Perf (MoE 26B-A4B at 64K, RTX 3090, Q8_0 KV): chunked baseline: 1867 tok/s prefill, 100.6 tok/s decode, 10.67/16 accept + --pflash: 3374 tok/s prefill (1.81x), 101.8 tok/s decode Changes: - Adapter (pflash_ggml_adapter.cpp/h) registers the pFlash CUDA kernel with the ggml op. Maps alpha>=1.0 to fully-dense mode. - build_full_attn_block() conditionally uses ggml_flash_attn_sparse when use_pflash is set. - attn_mask is skipped (in graph + driver) when use_pflash=true since the sparse op applies block-level causal internally. - gemma4_pflash_prefill.cpp removed (replaced by chunked path). - test/test_flash_attn_sparse.cpp: TDD coverage for the ggml op (dense vs sparse @ alpha=1.0 within BF16 precision; alpha<1.0 liveness). Ported upstream fixes: - TQ3_0 mask stride (PR Luce-Org#128): bump g_kq_stride_pad to 256 when KV is selected via DFLASH27B_KV_K/V env vars. Prevents NaN at chunk sizes 256/512/1024/2048 with TQ3_0 KV. - last_token_logits_only (PR Luce-Org#108): skip lm_head matmul over all but last token during prefill chunks. Saves ~1GB output tensor and ~1000x lm_head compute per chunk on Gemma4-31B (vocab=262144).
5 of 6 tasks
smpurkis
pushed a commit
to smpurkis/lucebox-hub
that referenced
this pull request
May 10, 2026
perf: Replace Q8_0 format for KV with Q4_0 + Rotation, fix window_filled for long context
smpurkis
pushed a commit
to smpurkis/lucebox-hub
that referenced
this pull request
May 10, 2026
Resolve conflict in dflash/test/test_dflash.cpp: keep both main's TQ3_0 KV-stride padding block (q4rot fix from PR Luce-Org#108) and the PR's laguna-aware early-exit (skips the prompt/out positional-arg check when the target is laguna and dispatches to run_laguna_daemon). Co-Authored-By: WOZCODE <[email protected]>
oliveagle
pushed a commit
to oliveagle/lucebox-hub
that referenced
this pull request
May 22, 2026
perf: Replace Q8_0 format for KV with Q4_0 + Rotation, fix window_filled for long context
oliveagle
pushed a commit
to oliveagle/lucebox-hub
that referenced
this pull request
May 22, 2026
Resolve conflict in dflash/test/test_dflash.cpp: keep both main's TQ3_0 KV-stride padding block (q4rot fix from PR Luce-Org#108) and the PR's laguna-aware early-exit (skips the prompt/out positional-arg check when the target is laguna and dispatches to run_laguna_daemon). Co-Authored-By: WOZCODE <[email protected]>
oliveagle
pushed a commit
to oliveagle/lucebox-hub
that referenced
this pull request
May 22, 2026
perf: Replace Q8_0 format for KV with Q4_0 + Rotation, fix window_filled for long context
oliveagle
pushed a commit
to oliveagle/lucebox-hub
that referenced
this pull request
May 22, 2026
Resolve conflict in dflash/test/test_dflash.cpp: keep both main's TQ3_0 KV-stride padding block (q4rot fix from PR Luce-Org#108) and the PR's laguna-aware early-exit (skips the prompt/out positional-arg check when the target is laguna and dispatches to run_laguna_daemon). Co-Authored-By: WOZCODE <[email protected]>
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.


Three prefill optimizations that eliminate the Turing-specific ubatch scaling workaround and make long-context prefill dramatically faster:
FA windowed prefill: use g_fa_window (default 2048) during prefill, capping attention cost at O(ubatch × window) instead of O(ubatch × kv_len). Compute time stays flat at ~1.15s/step across 100K context (was 3.5s→13s).
last_token_logits_only: skip lm_head matmul for all but the last token during prefill (only last_tok is needed to seed decode). Saves ~233MB scratch at ubatch=384 and eliminates a large [vocab × ubatch] matmul.
gallocr pre-reserve: build max-shape graph before prefill loop so gallocr allocates its CUDA buffer once upfront, preventing hundreds of reallocations as the mask grows.