Repository navigation
perf(ggml-cuda): row-split gated-delta-net prefill recurrence on gfx1151 - #860
Merged
Merged
Conversation
Replace the tiled S_v=128 chain-mode prefill kernel with a row-split
recurrence on RDNA3.5: four lanes own one state row, each lane carries two
rows, the decay is folded into a scaled state so the per-token update is one
in-place FMA per element, and token windows are staged through
double-buffered LDS. The scaled-state factor is floored at 1e-24 so gates
with expf(g) == 0 do not produce NaN.
The route is unchanged: qwen4exp graphs, chain path, one sequence,
S_v=128, H=48, T>=2. LUCE_GDN_LEGACY=1 restores the tiled kernel. The output
differs from the tiled kernel by float32 reassociation noise, so greedy
decoding can diverge between the two kernels; test_gdn_rowsplit_parity
compares both at T in {1, 5, 33, 512, 4096}. Layout adapted from gufo's
GdnRowSplitKernelT (MIT); the notice is in gated_delta_net.cu.
davide221
reviewed
Oct 20, 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 dc50b1d5 · 0 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again
davide221
added a commit
to dusterbloom/lucebox-hub
that referenced
this pull request
Oct 23, 2026
ENVIRONMENT.md: keep Luce-Org#860's LUCE_GDN_LEGACY row (now on main) and this PR's five kill-switch rows. The tree equals 183b7c3 + this branch, the build verified on lucebox2. Co-Authored-By: Claude Opus 5.5 <[email protected]>
davide221
added a commit
that referenced
this pull request
Oct 23, 2026
…tacked on #860) (#862) * perf(ggml-cuda): row-split gated-delta-net prefill recurrence on gfx1151 Replace the tiled S_v=128 chain-mode prefill kernel with a row-split recurrence on RDNA3.5: four lanes own one state row, each lane carries two rows, the decay is folded into a scaled state so the per-token update is one in-place FMA per element, and token windows are staged through double-buffered LDS. The scaled-state factor is floored at 1e-24 so gates with expf(g) == 0 do not produce NaN. The route is unchanged: qwen4exp graphs, chain path, one sequence, S_v=128, H=48, T>=2. LUCE_GDN_LEGACY=1 restores the tiled kernel. The output differs from the tiled kernel by float32 reassociation noise, so greedy decoding can diverge between the two kernels; test_gdn_rowsplit_parity compares both at T in {1, 5, 33, 512, 4096}. Layout adapted from gufo's GdnRowSplitKernelT (MIT); the notice is in gated_delta_net.cu. * perf(ggml-cuda): 16-byte vector path for strided same-type copies The K/V cache append of the qwen4exp graphs (a permuted F16 CPY into a cache view) ran cpy_scalar<half, half> with one element per thread at about 36 GB/s. When source and destination have the same type, a contiguous inner dimension that is a multiple of 16 bytes, and 16-byte aligned outer strides and bases, the copy now moves one uint4 per thread with the same index decomposition. The bytes are moved, not converted, so the result is identical; every other shape takes the scalar kernel as before. LUCE_CPY_VEC_LEGACY=1 keeps the scalar kernel. test_cpy_vec_parity compares the whole destination buffer against a host reference for vector-eligible shapes (F16 [256, 2, 4136] into a cache view, T=1, F32 [128, 48, 128]) and for the fallback shapes (inner dimension 24 and 6, misaligned base). * perf(ggml-cuda): qwen4exp QSA3 prefill union bitmap kernel and per-forward M-RoPE table QSA3 prefill built the union of the selected blocks of each query group with a rank sort of every id row followed by a pairwise merge. The rows hold -1 holes between the selected blocks and the tail, so the sortedness check failed for every query before the indexer top-k position and the O(ns^2) sort ran on half the rows. One bitmap kernel now marks the selected blocks per group directly. M-RoPE recomputed the FP64 angle for every layer and head. The angle depends only on the token and the pair, so a table of cos/sin is built once per positions tensor and forward and shared by Q, K and the indexer query of all layers. Entries are keyed by node, data pointer and a generation bumped per graph compute, so a recycled pool address cannot serve a stale table. Both changes are bit-identical. LUCE_ATTN_PREFILL_LEGACY=1 restores the previous kernels and the inline angles. test_qsa3_union_parity compares every kernel variant with a CPU set union, test_rope_table_parity compares table and inline rotations byte for byte. * perf(qwen4exp): wave-per-row gated norm and q/k norm folded into the GDN conv epilogue Gated-delta-net layers normalised q and k with a separate RMS_NORM and SCALE after the conv, and the gated output norm ran one 128-thread block per row with an LDS reduction. On gfx1151 the SSM_CONV epilogue now applies the q/k L2 norm itself (the graph passes the channel count, epsilon and scale in the node's op_params, and the generic kernel asserts if the fusion did not match so an unnormalised q/k can never reach the recurrence), and a 32-lane wave owns each 128-column gated-norm row. Both reproduce the reduction order of the kernels they replace, so the results are bit-identical. LUCE_GDN_NORM_LEGACY=1 restores the previous kernels and graph. The 256-wide gamma-free gate stays on the block kernel, where the wave version measured slower. test_gated_norm_wave_parity and test_gdn_conv_qknorm_parity compare against the block-per-row and the RMS_NORM + SCALE chains, byte for byte. * perf(ggml-cuda): fuse the qwen4exp attention norm sites at prefill Three bit-identical changes behind one kill switch, LUCE_ATTN_FUSE_LEGACY=1: - rope.cu: RMS_NORM -> MUL -> ROPE [-> PERMUTE -> CONT] in one launch for the attention Q/K and the indexer q (one block per token looping the heads, the same reduction as rms_norm_f32<256,true> and the same rotation as the per-forward table kernel). - qsa.cu: the QSA3 prefill attention store folds in the sigmoid output gate and writes the F16 operand of the output projection directly. - qwen4exp_graph.cpp: the hc grouped norm applies gamma on the 3-D norm output and expands the gamma view first, so RMS_NORM and MUL are adjacent and the backend fuses them. Unit tests: test_norm_rope_fusion, test_qsa3_gate_parity, test_hc_norm_mul_fusion. * perf(ggml-cuda): fuse the qwen4exp PLE conv and norm at prefill Two bit-identical changes behind one kill switch, LUCE_PLE_FUSE_LEGACY=1: - ple-conv.cu: the PLE conv matcher took its shape from the 3-D view root and never matched. It now reads the logical shape from the reshape and the contiguity from the root, so concat, tap copies, mul, add and silu run as one launch. The graph drops the CONT after silu. - qwen4exp_graph.cpp: the PLE grouped norm expands its gamma view first so RMS_NORM and MUL are adjacent and the backend fuses them. Unit tests: test_ple_conv_fusion and test_ple_norm_mul_fusion. * fix(ggml-cuda): keep the gated QSA3 store and the norm+rope fusion to the HIP qwen4exp path qsa.cu is built for HIP only, so the gated-store dispatch in ggml-cuda.cu left three undefined symbols on every CUDA build (the Linux, Windows and GB10 jobs failed to link). It is now under GGML_USE_HIP, like the qsa calls in fattn.cu. The RMS_NORM -> MUL -> ROPE matcher fired for any F32 M-RoPE q/k-norm chain, but the fused kernel is rope_multi_cuda's per-token path, which runs only for qwen4exp on HIP RDNA3.5. Anywhere else (Qwen3.5 graphs, CUDA builds) it hit GGML_ASSERT(per_token) on the first prefill of 64 or more tokens. ggml_cuda_norm_rope_enabled() now requires that path. test_norm_rope_fusion gains a profile-off arm: nothing fuses and the output equals the separate kernels. Before this change that arm aborted. * fix(ggml-cuda): LUCE_ATTN_PREFILL_LEGACY restores the rank-sort rows kernel of the QSA3 union The kill switch selected variant 1, the compacting rows kernel this PR adds. Variant 0 is the rows kernel and merge that main runs. The union was the same either way (test_qsa3_union_parity covers every variant); now the switch runs main's kernels. --------- Co-authored-by: mrciffa <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
davide221
added a commit
to dusterbloom/lucebox-hub
that referenced
this pull request
Oct 24, 2026
CMakeLists.txt and ENVIRONMENT.md: keep this PR's test target and LUCE_MMVQ_INVARIANT_* rows next to the ones Luce-Org#860 and Luce-Org#862 added on main. 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.
What
The S_v = 128 prefill recurrence of the gated delta net (the qwen4exp graphs on gfx1151, chain path, one sequence, H = 48, T >= 2) ran the tiled chain-mode kernel. This replaces it with a row-split recurrence: four lanes own one state row, each lane carries two rows, the decay is folded into a scaled state so the per-token update is one in-place FMA per element, and token windows are staged through double-buffered LDS. The scaled-state factor is floored at 1e-24 so a gate with
expf(g) == 0cannot produce NaN. Layout adapted from gufo'sGdnRowSplitKernelT(MIT); the notice is ingated_delta_net.cu.The route is unchanged. Decode, other head sizes and other backends keep their kernels.
Greedy outputs change
This PR is not bit-identical to main. The row-split kernel reassociates the float32 state update, so the recurrence differs from the tiled kernel by rounding noise, and greedy decoding can pick a different token where two logits are close.
test_gdn_rowsplit_paritycompares both kernels at T in {1, 5, 33, 512, 4096} and requires the attention output and final state to agree to float32 reassociation noise (max relative difference 9.7e-6 on the output and 4.1e-5 on the state at T = 4096); it is a tolerance test, not a memcmp test, because the two kernels are not bit-identical. The quality section below measures the effect on the model's distributions.Kill switch
LUCE_GDN_LEGACY=1restores the tiled kernel. With it set the output is bit-identical to main: greedy outputs hash-identical on the 10 p4096 and 8 p16384 generations of a paired run, and the teacher-forced KL against main is exactly 0 over 2,392 positions.Tests
test_gdn_rowsplit_parity(T = 1, 5, 33, 512, 4096). Passes on gfx1151.Measurement
Radeon 8060S (gfx1151), Qwen3.8-Flash-Next UD-Q4_K_XL (4 shards) with the shared Q8_0 MTP sidecar,
--max-ctx 32768, prefix and disk caches off, temperature 0, seed 1, a distinct prompt per request (cached_prefix_tokens = 0on every request), a server restart per block. Main is 8194012.Prefill, server tok/s, median / mean / best / min. Four blocks per arm (8 measured p4096 and 6 measured p16384 requests per block, so n = 32 and n = 24 per arm) in a balanced rotation over three arms (main, main + this PR, main + this PR + a bit-identical PLE fusion from a follow-up PR),
A B C C B A A B C C B A:Block medians, p4096: main 1162, 1136, 1132, 1137; this PR 1171, 1207, 1174, 1182. p16384: main 1309, 1249, 1275, 1288; this PR 1342, 1364, 1312, 1338. At p4096 every block of this PR is above every block of main. At p16384 the spread between blocks of the same arm (about 4.7% for main) is as large as the delta, one block of this PR (1312) sits next to the best block of main (1309), and the pooled medians separate the arms.
Client-side prefill (time to first token), median tok/s: p4096 1111.4 vs 1151.0, p16384 1271.1 vs 1331.6.
Wall for 8 new tokens, seconds, median / mean / lowest / highest: p4096 main 3.74 / 3.77 / 3.65 / 4.04, this PR 3.62 / 3.66 / 3.54 / 4.11; p16384 main 13.00 / 13.17 / 12.54 / 14.56, this PR 12.39 / 12.58 / 12.09 / 13.77.
Decode (256 new tokens, short prompt), tok/s, median / mean / best / min:
Decode without the draft is unchanged (the recurrence kernel is prefill only; the no-draft arm also carries the follow-up PLE fusion, which is bit-identical). With the draft it is -1.7% median, and that is the changed greedy text: the draft acceptance rate moves from 0.581 to 0.561 (tokens per step 2.387 to 2.343) over the 46 decode requests per arm.
Quality: teacher-forced against main
Both arms prefill the same 4 text slices (2 code, 2 prose) and then decode through the same 599 forced tokens each (the first 5 after the prefill dropped), 2,392 positions in total, no MTP draft. We compare the full next-token distributions: mean KL(main || this PR), top-1 agreement, mean negative log-likelihood of the forced token, and the accuracy of the arm's argmax against the forced token.
Top-5 overlap is 92.7%. The model predicts the forced text as well as before (accuracy 72.78% on both, NLL 1.0970 vs 1.1006); the distributions move by a mean KL of 0.0096. Any rounding change in these paths flips a few near-tied MoE routing choices, so this is the size of change to expect from a reassociated recurrence.