rocm: implement the two DSpark kernels so --dspark can draft on gfx1151 (fixes #597) - #670
Open
zom-2018 wants to merge 2 commits into
Open
rocm: implement the two DSpark kernels so --dspark can draft on gfx1151 (fixes #597)#670zom-2018 wants to merge 2 commits into
zom-2018 wants to merge 2 commits into
Conversation
…ero-draft) Port the two CUDA-only DSpark kernels to ROCm so the speculative path actually drafts on Strix Halo: - dspark_markov_argmax_kernel + ds4_gpu_dspark_markov_argmax_tensor (rocm/ds4_rocm_indexer.cuh): on-device markov-chain argmax over the vocab with q8_0 w1/w2 rows, same monotonic-key atomicMax tie-break. - attention_noncausal_raw_batch_heads_kernel + ds4_gpu_attention_noncausal_raw_batch_heads_tensor (rocm/ds4_rocm_attention_launch.cuh): non-causal batch attention over the raw KV ring for draft blocks, incl. DS4_DSPARK_VERIFY_NONCAUSAL host oracle (first 3 launches). - drop both ROCM_UNAVAILABLE stubs. Previously the engine probe failed on ROCm (unavailable stubs), so --dspark entered the propose path but emitted proposed=0 every cycle. (cherry picked from commit d3c8e665f62d41d384145e4b5f807b93048bd058)
The DSpark port drafted correctly but the speculative path stayed slow. These kernel optimizations move it from ~0.67x to ~0.81x of plain decode (dspark_tps 10.71 -> 13.05, verify 135 -> 100 ms/cycle on Strix Halo, lossless / byte-identical to greedy decode): Markov draft kernel (rocm/ds4_rocm_indexer.cuh): - 4096x32 one-row-per-thread grid (was 128x256); vals/idxs 768. - Aligned uint16 pair loads in the w2 dot loop and the w1 state init. - Alternate the w2 scan direction per chain step (L3 tail reuse; the argmax is direction-independent, so this is oracle-safe). Verify path: - Batched parallel argmax for top_k=1 row tops (argmax_rows_kernel), replacing a single-threaded ~13 ms insertion-sort kernel. - Adaptive token tile (8/16/32 by n_tok) for the shared-x batch q8 matmuls: a fixed 32-wide token tile wasted up to 6x ALU at the small verify batch; per-token accumulation order is unchanged (bit-identical). - float4 output accumulation in the non-causal draft-block attention. - MoE float-down rows_per_block 16 -> 32 (more mid-tile reuse). Measured with the two DSpark kernels' accept oracle and a byte-identity check against plain greedy decode.
Author
|
Update: refreshed the description and pushed a follow-up commit (
Markov draft kernel (
Verify path
Measured on Strix Halo (gfx1151), still lossless / byte-identical to greedy decode: |
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
Fixes #597 — "DSpark never produces a draft on ROCm / gfx1151".
Root cause: the DSpark engine path in
ds4.cis backend-shared, but two GPUkernels it needs existed only in
ds4_cuda.cu. ROCm builds resolved themthrough
ROCM_UNAVAILABLE_INTstubs inds4_rocm_unavailable.cu, so thesession probe always failed and every propose cycle ended with
proposed=0.This PR implements both kernels for ROCm (HIP) and removes the two stubs:
dspark_markov_argmax_kernel+ds4_gpu_dspark_markov_argmax_tensor(
rocm/ds4_rocm_indexer.cuh): on-device markov-chain argmax over the vocabwith q8_0 w1/w2 rows — direct port of the CUDA kernel, same monotonic-key
atomicMaxtie-break.attention_noncausal_raw_batch_heads_kernel+ds4_gpu_attention_noncausal_raw_batch_heads_tensor(
rocm/ds4_rocm_attention_launch.cuh): non-causal batch attention over theraw KV ring for draft blocks — direct port, same one-block
max/denominator/value accumulation order; keeps the
DS4_DSPARK_VERIFY_NONCAUSALhost-side oracle for the first 3 launches.Signatures match the existing declarations in
ds4_gpu.h; no other files aretouched.
Scope / safety
--dsparkis used (the kernels are only reachedthrough the DSpark propose/verify path).
Measured on AMD Strix Halo (Ryzen AI Max+ 395, Radeon 8060S gfx1151), ROCm 7.2
Before (upstream):
proposed=0every cycle (exactly the #597 symptom).After,
--dspark-confidence 0.3, 300 generated tokens, DeepSeek-V4-Flash-0731abliterated GGUF (80.76 GiB) + its DSpark support drafter:
At the default
--dspark-confidence 0.9the adaptive scheduler staysconservative:
proposed=21, accept_rate=90.5%.Wall-clock is currently break-even on this bandwidth-bound APU (the 6-row
target verify costs ~4–5x a single decode pass, dominated by routed-expert
weight reads), so this is not a speedup claim — it makes DSpark functional
on ROCm, which is the precondition for any follow-up verify-path optimization.
Testing
make strix-haloclean (gfx1151).--dspark+DS4_DSPARK_STATS=1: drafts proposed,verified and accepted; coherent output; stats counters advance.
--dspark: unchanged behavior.Update: DSpark kernel speedups (this branch now also makes it fast)
The port above drafted correctly but slowly. A follow-up commit on this branch
optimizes the draft + verify kernels; on the same Strix Halo box that moves the
speculative path from ~0.67x to ~0.81x of plain decode
(
dspark_tps10.71 -> 13.05, verify 135 -> 100 ms/cycle), still lossless.Markov draft kernel:
direction-independent, so oracle-safe).
Verify path:
argmax_rows_kernel),replacing a single-threaded ~13 ms insertion-sort kernel.
(a fixed 32-wide tile wasted up to 6x ALU at the small verify batch;
per-token accumulation order unchanged, bit-identical).
The speedups touch only ROCm kernel files plus the
ds4.c/ds4_gpu.h/ds4_cuda.cureverse-scan plumbing; outputs remain byte-identical to plaingreedy decode (accept oracle passes).