perf(dflash): 16-byte loads in the draft GEMV + barrier-free draft attention - #678
Closed
fansilas wants to merge 1 commit into
Closed
perf(dflash): 16-byte loads in the draft GEMV + barrier-free draft attention#678fansilas wants to merge 1 commit into
fansilas wants to merge 1 commit into
Conversation
…tention (+10% DFLASH_TPS)
Member
Closed: no activity for 2+ daysThis PR has had no updates (commits, comments, reviews, or label changes) for 2 days (threshold: 2 days). Reopen this PR or open a fresh one when you're ready to continue. |
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
Two fixes in the DFlash draft block, found by profiling the draft step and reading the SASS.
DFlash 362.49 → 398.91 tok/s (+10.0%), mean accept τ unchanged, one file.
k_gemv_batcheddocuments a uint4 load as "the kernel's dominant cost", but(const bf16*)&wrow4[k8]only takes an address into global memory — so it compiled to8 + 8*BATCH = 136scalar 2-byte loads per lane per chunk where 17 wide loads carry the same bytes. Assigning each chunk to a localuint4first keeps it in registers: SASS onsm_120goes 136LDG.E.U16→ 34LDG.E.64, kernel 33.46 → 15.29 ms. Same operands in the same per-(row, batch) order, so bit-exact. +5.4% on its own.k_attnreduces every key across the whole block (~9__syncthreads()) for one FMA of real work per thread.k_attn_warpgives each warp a strided slice of keys with its own online softmax — shuffle reduction, accumulator in registers, one barrier for the whole kernel at the merge; 16 warps/block measured best. Kernel 15.52 → 1.54 ms. Not bit-identical, which nothing needs: the draft only proposes, and the early-exit verify accepts onlyblock[i+1] == p, so emitted tokens stay the target's greedy argmax.Both behind env flags defaulting on —
SPARKINFER_DFLASH_GEMV_VEC=0andSPARKINFER_DFLASH_ATTN_WARP=0restore the old kernels, so before/after is one binary.Proof of speedup
sm_120)Decode tok/s — DFlash decode from
qwen3_gguf_dflash_bench(the metricpr_dflash_bot.pyscores), same box, same binary, interleaved, median of 5 passes at 128 tokens:Prefill pp tok/s (
qwen3_gguf_bench,--ctx 32768, median of 3 interleaved passes). This PR does not touch prefill; measured only to show no regression — the +0.03% is run-to-run noise, not a claimed gain:ctest --test-dir buildis 9/9. Draft-only, so the AR accuracy gate is untouched by construction — these kernels run only insideDFlashDraftModel::forward_block, whichqwen3_gguf_scorenever instantiates; re-runningbench/scripts/accuracy.shwith them disabled gives byte-identical top-1/KL.