Repository navigation
perf(ds41): 5-7x prefill and 1.7-2.1x decode on R9700 + Ryzen AI Max hybrid targets - #811
Merged
Merged
Conversation
- mul_mat_vec_q8_0_rdna4: the one-column (and batch-invariant multi-column) Q8_0 MMVQ on RDNA4 computes exactly the eight-wave kernel's arithmetic (same per-lane FMA chains, partials added in virtual-wave order, same butterfly) with fewer waves per row and rows sharing activation loads. On by default on RDNA4; LUCE_CUDA_MMVQ_Q8_RDNA4=0 turns it off. - ROCmFP2 MoE MMVQ on gfx1151: issue up to eight iterations' weight, scale and activation loads before the dot products; each lane adds the same terms in the same order. On by default on gfx1151; LUCE_CUDA_MMVQ_MOE_FP2_PREFETCH=0/1 overrides. - mmvf: unroll the HIP K loops so loads of several trips are in flight; each column's FMA chain keeps its order. - test/bench_ds41_q8_mmvq: the DS4.1 dense projections through the ggml dispatch at 1-4 columns, with the column-identity check. Outputs are bit-identical to the existing kernels. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two GGML_OP_DS4_HC modes replace short op chains the DS4 graph runs every layer: - ggml_ds4_router_select / ggml_ds4_router_weights (modes 4 and 5): the sqrt(softplus) router, biased top-k with the protected-expert rule, and the normalised weights in two kernels instead of about ten. - ggml_ds4_hc_collapse (mode 6): the staggered HC collapse in one kernel instead of a mul, a transpose and a 4-wide sum_rows. Both round exactly as the chains they replace (the collapse is the device sum_rows order, (x0 + x2) + (x1 + x3), with contraction off). test_ds4_fused_ops_cuda checks ids, weights and collapse bit for bit, ties and protected experts included. LUCE_DS4_FUSE_ROUTER=1 and LUCE_DS4_FUSE_COLLAPSE=1 turn them on. DS4.1 on an R9700 + Ryzen AI Max+ PRO 495, output unchanged: decode 34.7 -> 36.3 tok/s on a code prompt, 20.4 -> 21.8 after a 2K prompt. Co-Authored-By: Claude Opus 5.5 <[email protected]>
V4.1 decode and verify lanes are Explicit with a shared top-k selection, so they run the D=512 flash kernel; on a hybrid target the graph built an F16 [raw | compressed] concat and cast it to F32 every layer and step, O(context) work that made decode fall from 29 to 10 tok/s at 64K. - LUCE_DS4_HYBRID_F16_VERIFY_KV / LUCE_DS4_F16_KV_LANES: F16 K/V for hybrid verify and single-token lanes; selection lanes feed segmented F16 K/V straight to the split-KV kernel (no concat, no cast). - LUCE_DS4_EXPLICIT_SPLIT: short-context lanes take the split-KV schedule through an identity row list; LUCE_DS4_MASK_F16_ONCE: one F16 mask per step; GGML_CUDA_MLA_SPLIT_KV_COUNT (4/8/16) sets the split count. - fattn: the visibility-bounds scan finds the last compressed row from the end; the indexed-rows top-k skips its sort for ascending input and counts valid rows with one block reduction (owner ranks now read the sorted rows). DS4.1 on an R9700 + Ryzen AI Max+ PRO 495: decode 36.3 -> 47.4 tok/s on a code prompt and 21.8 -> 29.9 after a 2K prompt; with the rest of the stack decode stays at 30-31 tok/s after a 30.7K prompt (it fell to about 10 at 64K before). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Long prompts on a two-GPU hybrid target (dense work and hot experts on the primary, the other experts on a secondary GPU, all resident) were host bound: the residual crossed the host link every layer, plain ROCmFP2 experts ran one sliced matmul chain each, and the secondary GPU idled through every round trip. All switches below are off by default. - LUCE_DS4_LAYER_MAJOR_DEVICE_RESIDUAL, LUCE_DS4_ENGRAM_DEVICE: the layer-major residual stays on the primary between layers and Engram is applied there; LUCE_DS4_SPLIT_DEVICE_JOIN joins both owners' partials on the device. - LUCE_DS4_GROUPED_HYBRID_PREFILL, LUCE_ROCMFP2_WMMA_PREFILL: plain ROCmFP2 (type 107) owner stacks take the grouped MUL_MAT_ID graph and the gfx1151 WMMA MoE kernel (32-route tiles, dead fragments skipped). - LUCE_DS4_PREFILL_PIPELINE=N: a two-slot pipeline from 128 rows; each band's secondary owner runs behind the other slot's while the primary routes and runs the next band, its input crossing on a side stream into a per-slot staging tensor (ggml_backend_cuda_copy_tensor_async_side), its partial returning with an event the join waits on (..._async_nowait). Band rows are capped by free memory; an out-of-memory prefill is retried once with the prefill arenas retired. - Engram rows (V4.1: 2 x 101 GB of tables in the GGUF, read from the drive) are fetched by a reader thread from the start of a layer-major pass, so the reads overlap the layers before each Engram layer. - LUCE_DS4_DEVICE_TOPK: per-token top-k candidates from the device; LUCE_DS4_PREFILL_ARENA_CHUNK_MB=0: one grow-only attention arena. - RDNA4 runs the D512 WMMA attention kernels when their switches are on, and the F16 prefill K/V transport covers dense flash prefill of any band size. - LUCE_DS41_DECODER_BOUNDED_REPLAY: the decoder SWA bounded replay of the V4.1 report: rows before the last n_swa run only the layers up to the last KV source (layer 20). A prompt that saves a prefix snapshot inside it (an agent turn) is prefilled in two parts split at the snapshot, each with replay, as a later request restoring the snapshot would run them. Band sizes follow free device memory, so a restored prompt can differ from a cold one in the last bits, as batching does. DS4.1 on an R9700 + Ryzen AI Max+ PRO 495, outputs unchanged on the bench prompts: prefill 160 -> 751 tok/s on a 2K prompt and 144 -> 697 on a 15K one. A six-turn agent session with prefix reuse prefills its new tokens at 726-803 tok/s on turns of 4.9K-8.3K new tokens and 503 on a 1.6K-token turn (190-310 when snapshot requests turned replay off). Co-Authored-By: Claude Opus 5.5 <[email protected]>
- LUCE_DS4_DRAFT_SWAP: keep a pinned host copy of the DSpark drafter; a prefill longer than 10240 tokens (the longer part of a split one) frees the drafter's device memory for it (the chunk is sized as if the drafter were absent) and restores it before decode (about 1.4 s over PCIe Gen3 x4; below ~10K tokens that costs as much as it saves). Single-sequence serving only (paged serving loads no drafter). - ds41-gorgon: DS4.1 on an R9700 beside a 192 GB Ryzen AI Max+ PRO 495 with every expert resident; every switch of this stack at its measured value. The expert placement and router bias come from the command line. R9700 + Ryzen AI Max+ PRO 495 192 GB: the swap takes a 15K-token prefill from 697 to 1026 tok/s. ds41-gorgon overall: prefill 724-751 / 1026-1033 / 1015 tok/s at 2K / 15K / 30.7K; decode 48-49 tok/s on code, 32-33 after a 2K prompt, 30 after 30.7K. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…id prefill - Pipelined prefill: each caller band (a chunk started at every restore point) runs as max(N, 2) equal parts (deepseek4_pipeline_parts), instead of the whole pass cut into equal bands sized from free memory. The parts depend on the chunk alone, so a request restoring a snapshot reproduces the request that saved it, as on main; before, the restored answer differed. Two parts in flight hold one chunk's rows. - The prefill retry applies to pipelined hybrid prefills only, and reruns the same bands with the pipeline off instead of smaller bands. - A failed drafter swap-in decodes the request without DSpark instead of failing it; the next request tries again. - V4.1 explicit verify lanes keep F16 K/V only under LUCE_DS4_EXPLICIT_SPLIT, so --ds4-fused-verify-f16-kv alone is unchanged. - Bounded replay eligibility lives in one helper, and the prefill splits at a snapshot only when replay can run; replay is off when the drafter captures a layer at or below the cut. - HC collapse: __fmul_rn products (nvcc ignores the clang contract pragma and builds with fast math) and a token stride past the 65535 grid limit. - Router select/weights assert contiguous inputs of the right size. - Peer side/nowait copies share one eligibility check: buffer devices must match their backends, and GGML_CUDA_NO_PEER_COPY disables them. - RDNA4 Q8_0 kernel built for HIP only; MIX WMMA grid guard sized for 32-route tiles; GGML_CUDA_MLA_SPLIT_KV_COUNT read per launch; device top-k keeps only normed/probs alive. - test_ds4_fused_ops_cuda runs in both GPU CI jobs (plus a 70000-token collapse case); test_pipeline_parts_follow_each_band; the new switches are in docs/ENVIRONMENT.md. - ds41-gorgon leaves LUCE_DS4_DRAFT_SWAP off: with these bands the swap no longer speeds up prefill, and a cache hit after a swapped-out prefill runs smaller chunks. It stays opt-in, documented in ENVIRONMENT.md. R9700 + Ryzen AI Max+ PRO 495, ds41-gorgon, fresh servers: a 21965-token two-turn prompt answered from the cache now matches the full prefill token for token on two servers (before: diverged at character 335). Prefill 14.1K / 25.4K tokens: 985 / 1019 tok/s (before: 1026 / 1006 with the swap). Co-Authored-By: Claude Opus 5.5 <[email protected]>
davide221
added a commit
to dusterbloom/lucebox-hub
that referenced
this pull request
Oct 7, 2026
… into feat/qwen4exp-strix-halo # Conflicts: # server/deps/llama.cpp/gguf-py/gguf/constants.py
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
DeepSeek V4.1 Flash on a Radeon AI PRO R9700 next to a Ryzen AI Max+ PRO 495 with 192 GB, every expert resident (hot experts and the dense work on the R9700, the rest on the iGPU). Prefill was host bound and decode fell with context; this makes prefill 4.8x faster at 2K and 7.5x at 15K-30K, and decode 1.7x faster at short context and 2.1x after a 30K prompt (decode now stays flat with context). Six commits, one per layer of the change plus the review fixes, each building and passing the tests on its own:
perf(ggml-cuda): bit-exact RDNA4 Q8_0 and gfx1151 ROCmFP2 decode kernelsperf(ds4): fused, bit-exact router and HC collapse opsperf(ds41): flat long-context decode on hybrid targetsperf(ds41): heterogeneous layer-major prefillfeat(ds41): drafter swap for long prompts and theds41-gorgonprofilefix(ds41): restore-exact pipeline bands and review fixes for the hybrid prefillDefaults are unchanged outside the two bit-exact kernels (1): every other switch is off unless the new
ds41-gorgonprofile sets it.Impact
Same box, same GGUF (ROCMFP2S), expert placement, router bias, DSpark drafter and 12 GB expert budget in both columns; greedy; fresh server per column.
With the prefix cache, a six-turn agent session (each turn appends a source file) prefills its new tokens at 726-803 tok/s on turns of 4.9K-8.3K new tokens and 503 tok/s on a 1.6K-token turn.
What each commit moves (tok/s): (1) code decode 29.1 -> 34.7; (2) 34.7 -> 36.3; (3) 36.3 -> 47.4, decode after 2K 21.8 -> 29.9; (4) prefill 2K ~155 -> 751 and 15K ~140 -> 697; (5) 15K prefill 697 -> 1033 (drafter swap); (6) on a 14.1K / 25.4K-token prefill, 1026 / 1006 -> 985 / 1019 with per-chunk bands and the swap out of the profile.
Implementation
mul_mat_vec_q8_0_rdna4computes exactly the eight-wave Q8_0 MMVQ arithmetic with fewer waves per row and rows sharing activation loads; the gfx1151 ROCmFP2 MoE MMVQ issues several iterations' loads before the dot products; the HIP mmvf K loops are unrolled. Same terms in the same order, bit-identical.bench_ds41_q8_mmvqtimes the DS4.1 dense projections with the column-identity check.GGML_OP_DS4_HCmodes 4-6: the sqrt(softplus) router, biased top-k with the protected-expert rule and the normalised weights in two kernels instead of about ten, and the staggered HC collapse in one kernel. Both round exactly as the chains they replace;test_ds4_fused_ops_cudachecks ids, weights and collapse bit for bit.ggml_backend_cuda_copy_tensor_async_side) and the partial returning with an event (..._async_nowait). Each chunk (chunks start at every restore point) runs as two equal bands of at least 64 rows, so the bands depend on the chunk alone and two bands in flight hold one chunk's rows; a pipelined prefill that runs out of memory is retried once with the arenas retired and the pipeline off (same bands). Engram rows (2 x 101 GB of tables inside the GGUF, read from the drive) are fetched by a reader thread from the start of the pass, so the reads overlap the layers before each Engram layer.LUCE_DS41_DECODER_BOUNDED_REPLAYimplements the decoder SWA bounded replay of the V4.1 report (rows before the last n_swa run only the layers up to the last KV source); a prompt that saves a prefix snapshot inside it is prefilled in two parts split at the snapshot, each with replay, as a later request restoring that snapshot runs them.LUCE_DS4_DRAFT_SWAPkeeps a pinned host copy of the DSpark drafter; a prefill longer than 10240 tokens frees the drafter's device memory for larger bands and restores it before decode (about 1.4 s over PCIe Gen3 x4, worth it from about 10K tokens); if the swap-in fails, that request decodes without DSpark. Since (6)ds41-gorgonleaves the swap off: with per-chunk bands it no longer speeds up prefill on this box. Single-sequence serving only (paged serving loads no drafter). Theds41-gorgonprofile sets every switch above at its measured value; the expert placement and router bias come from the command line.Runtime Flags / Configuration
Default-on paths:
LUCE_CUDA_MMVQ_Q8_RDNA4=0andLUCE_CUDA_MMVQ_MOE_FP2_PREFETCH=0turn them off.Opt-in (all set by
--profile ds41-gorgon):LUCE_DS4_FUSE_ROUTER,LUCE_DS4_FUSE_COLLAPSE,LUCE_DS4_HYBRID_F16_VERIFY_KV,LUCE_DS4_F16_KV_LANES,LUCE_DS4_EXPLICIT_SPLIT,LUCE_DS4_MASK_F16_ONCE,GGML_CUDA_MLA_SPLIT_KV_COUNT(4/8/16).LUCE_DS41_DECODER_BOUNDED_REPLAY,LUCE_DS4_LAYER_MAJOR_DEVICE_RESIDUAL,LUCE_DS4_ENGRAM_DEVICE,LUCE_DS4_SPLIT_DEVICE_JOIN,LUCE_DS4_GROUPED_HYBRID_PREFILL,LUCE_ROCMFP2_WMMA_PREFILL,LUCE_DS4_PREFILL_PIPELINE,LUCE_DS4_PREFILL_ARENA_CHUNK_MB,LUCE_DS4_DEVICE_TOPK,LUCE_MOE_SIDE_COPY,LUCE_DS4_PREFILL_F16_KV_ALL.LUCE_DS4_DRAFT_SWAP.Not bit-exact relative to main: bounded replay (approximate by design, the model is trained for it) and the split-KV schedule for short lanes. The router and collapse fusions, the kernels in (1), the side copy and the Engram read-ahead are exact. A request that restores a snapshot reproduces the request that saved it, as on main. The opt-in
LUCE_DS4_DRAFT_SWAPis the exception: a cache hit whose own prefill stays under 10K tokens keeps the drafter and runs smaller chunks than the swapped-out full prefill, so its answer can differ.Validation
test_feature_gate(incl. theds41-gorgonlaunch-policy case) andtest_ds4_fused_ops_cuda--profile ds41-lucebox): code, 2K and 30.7K outputs--paged-attention --max-concurrency 4 --ds4-prefill sparse): defaults identical to main; with every switch coherent, no errorsds41-gorgonLUCE_DS4_DRAFT_SWAP=1(opt-in)test_ds4_fused_ops_cudaon gfx1201 and gfx1151 (now also run by both GPU CI jobs, with a 70,000-token collapse case),test_server_unit,test_deepseek4_unitNotes
🤖 Generated with Claude Code