Repository navigation
perf(qwen35): fewer glue launches in the target graph (q8_1 memo, strided gates, gate|up stack) - #948
Merged
Conversation
Graffioh
force-pushed
the
perf/qwen35-glue-fusions
branch
from
November 6, 2026 08:42
1cb3eb5 to
ce11425
Compare
Graffioh
marked this pull request as ready for review
November 6, 2026 08:43
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 18 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
View guided diff | Re-trigger cubic
davide221
reviewed
Nov 6, 2026
davide221
left a comment
Contributor
There was a problem hiding this comment.
Code review
No issues found. Checked for bugs and logic errors in the changed code.
Reviewed ce11425c · 0 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again
…ided gates, gate|up stack) Three byte-identical fusions on the Qwen3.5/3.6/3.8 target, always on where their rules allow them: - Q8 memo (ggml-cuda MMQ): a matmul whose F32 activation is read again later in the same graph by a matmul of the same q8_1 layout keeps its quantized copy, and the later calls skip their quantize launch. Entries end at the first node that may write those bytes and never outlive a graph compute. - Strided gates: on the dense single-sequence DeltaNet chain the GDN kernel reads beta/alpha, and the gated norm reads z, in place from the stacked projections instead of contiguous copies. - Gate|up stack: the loader places ffn_gate|ffn_up back to back, and the FFN runs one GEMM over the stack wherever the backend vouches that every row matches the separate GEMMs (MMQ without stream-k, rows a multiple of 128). There is no runtime switch. The GPU test turns the fusions off through the test-only ggml_backend_cuda_set_q8_memo_override and luce::qwen35::glue::set_fusions_for_test. It also drops GGML_CUDA_DISABLE_FUSION: the graph-node fusions always run, as they did by default, and tests turn them off with ggml_backend_cuda_set_fusion_disabled_override. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Graffioh
force-pushed
the
perf/qwen35-glue-fusions
branch
from
November 6, 2026 11:19
ce11425 to
2ac57be
Compare
This was referenced Nov 6, 2026
main now has Luce-Org#946. server/CMakeLists.txt: both PRs added a unit test to the same two target lists and the same block; keep both (test_gdn_single_commit, then test_glue_fusions), as on the stacked branch of Luce-Org#964.
Graffioh
added a commit
to Graffioh/lucebox-hub
that referenced
this pull request
Nov 9, 2026
Two copies per GDN layer in the concurrent verify, 96 launches per C4 round, are gone: - The tree commit reads the replay log through the view of the GDN result, as SINGLE_REPLAY's rollback already does, instead of a compact copy. The view has the copy's [width, H, T, seqs] layout, and the GDN result stays alive past the compute. - The mapped verify's z goes into the fused silu*mul as a strided view of the attn_gate|qkv stack (Luce-Org#948's strided gates), instead of a contiguous copy. Its GDN output has the same contiguous rows as the chain's. Both read the same values, so outputs are bit-identical. Co-Authored-By: Claude Opus 5.5 <[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.
Summary
Three byte-identical fusions on the Qwen3.5/3.6/3.8 target graph remove about 300 of the ~2,090 launches in a DFlash verify round. None has a runtime switch: each is always on where its rules allow it.
ggml-cuda/mmq.cu, rules inglue-q8-memo.h):qwen35/glue_fusions.h). On the dense single-sequence DeltaNet chain (single-request prefill and capture verify), the GDN kernel reads beta/alpha in place from the stacked ssm_beta|alpha result (ggml_gated_delta_net_shared_gates). The gated norm reads z in place from the stacked attn_gate|qkv result, through the fused silu*mul kernel.ggml_backend_cuda_row_stack_inexactvouches that every row matches the separate GEMMs: MMQ without stream-k, more columns than MMVQ takes, and both members a multiple of 128 rows.The PR also removes
GGML_CUDA_DISABLE_FUSION. ggml-cuda's graph-node fusions always run now, as they did when it was unset. Tests turn them off with the test-onlyggml_backend_cuda_set_fusion_disabled_override: the DS4 grouped-MMID test's legacy arm moved to it. The strided-gates rule asksggml_backend_cuda_fusion_enabled(), so it never hands a strided z to the unfused silu.Evidence
Throughput, R9700. Setup:
--profile qwen38-r9700, greedy, thinking on,max_tokens2048, one request at a time.Concurrency 4. Setup: paged attention,
--max-concurrency 8, 4 clients in a closed loop, 40 prompts × 1024 tokens, ABBA twice.Identity and per-fusion gains (measured while the fusions still had runtime switches). Setup: R9700, Qwen3.8-27B UD-IQ4_XS + DFlash2 Q8_0 drafter, greedy, thinking on,
max_tokens2048, 30 prompts (6 each from gsm8k, math500, humaneval, mbpp, mt-bench), one request at a time, AR burst pinned off for strict identity. Sequential runs, tokens/s geometric mean:Every arm gave 30/30 outputs identical to "before" by token ids.
Where the time goes. A rocprofv3 trace of 5 requests, steady rounds:
At verify width (16 columns), one stacked gate|up GEMM against two separate ones: IQ4_XS 191.8 vs 210.2 µs (−8.8%), IQ3_S 251.5 vs 287.3 µs (−12.5%), Q5_K 233.8 vs 246.6 µs (−5.2%). The output hashes are equal.
Correctness.
test_glue_fusions(CPU, 23 cases) covers the memo's sharing window: in-place writes, overlapping nodes, non-matmul readers, views, reshapes and the scan bound. It also covers the strided-gate and gate|up plans on every path.test_glue_fusions_gpuruns 5 arms (all off, each alone, all on) in child processes. All 26 outputs and 10 pair checks are bit-identical across the arms. The memo hits exactly whereglue-q8-memo.hallows (4 + 12). The tiny target's verify drops CONT 5 → 2 and MUL_MAT 14 → 12, and tree verify keeps its copies.test_server_unit: 1218 passed, 0 failed.Merge Danger
Door: two-way, by revert. There is no runtime switch any more, and no file format or API change outside ggml-cuda and qwen35. The new exports,
ggml_backend_cuda_set_q8_memo_override,ggml_backend_cuda_set_fusion_disabled_overrideandluce::qwen35::glue::set_fusions_for_test, are test hooks.GGML_CUDA_DISABLE_FUSIONis no longer read: anyone who set it, on any model and device, now runs the fused kernels.Blast Radius: medium.
🤖 Generated with Claude Code