Repository navigation
gpu: BF16 sites run small batches through the multi-column gemv - #652
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: Two new gate comparisons duplicate the existing bit-equality helper.
Must fix
1. Reuse bits_equal for the new comparisons
crates/gpu-gates/src/bin/gate_bf16.rs:371 and crates/gpu-gates/src/bin/gate_bf16.rs:384 copy the bit comparison in crates/gpu-gates/src/lib.rs:719. The public bits_equal helper already checks lengths and bits. This is a kind B duplication defect under R14.
Reusing it removes duplicate logic and leaves one equality contract to maintain, with no new helper or parameter.
Replace the tile comparison at line 371 with:
let same = bloomery_gpu_gates::bits_equal(&tile, &y);Replace the replay comparison at lines 384–387 with:
let same = bloomery_gpu_gates::bits_equal(&replay, &y);Checked
Duplicates: both added comparison loops were checked against bits_equal; the replacements use its existing public signature.
Complexity: site_case adds tile-comparison and replay branches; k96_case adds a width loop.
Silent failure: the changed launcher propagates geometry and launch errors; graph capture and replay errors propagate.
Tests, static mutation check: changing the strides at crates/gpu/src/q8f32.rs:2462 breaks site/F32 equality. Returning early from crates/gpu/src/q8f32.rs:1687 breaks the poisoned tile comparison. At crates/gpu/src/site.rs:578, an extra launch fails the graph node assertion; restoring tile dispatch fails K=96.
Gates: no bands or tolerances moved. The PR supplies tile and K=96 FAIL-first output.
Escape catalog: no C1–C4 patterns matched.
Notes
Validation was static. CUDA gates were not rerun here. The PR reports a GB10 gate run and timed A/B results.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_bf16.rs, crates/gpu/src/q8f32.rs, crates/gpu/src/site.rs and carries a gate run on the author's card, which counts as verified.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
| )?; | ||
| stream.synchronize()?; | ||
| let tile = f_dev.to_host_vec(stream)?; | ||
| let same = tile.iter().zip(&y).all(|(a, b)| a.to_bits() == b.to_bits()); |
There was a problem hiding this comment.
Reuse the existing public bit-equality helper, which checks lengths and bits (R14).
| let same = tile.iter().zip(&y).all(|(a, b)| a.to_bits() == b.to_bits()); | |
| let same = bloomery_gpu_gates::bits_equal(&tile, &y); |
| let same = replay | ||
| .iter() | ||
| .zip(&y) | ||
| .all(|(a, b)| a.to_bits() == b.to_bits()); |
There was a problem hiding this comment.
Reuse the existing public bit-equality helper for the replay comparison (R14).
| let same = replay | |
| .iter() | |
| .zip(&y) | |
| .all(|(a, b)| a.to_bits() == b.to_bits()); | |
| let same = bloomery_gpu_gates::bits_equal(&replay, &y); |
4e5cd6e to
148d827
Compare
There was a problem hiding this comment.
Since the last review: must-fix 1 is fixed. Both comparisons now reuse bits_equal at gate_bf16.rs:371 and gate_bf16.rs:384.
Verdict: CLEAN: The duplication is removed, and the two comparison replacements preserve the gate checks.
Checked
Duplicates: 0 new items in the interdiff; both edited sites reuse the existing owner. Dryer reported 0 pairs in gpu.
Complexity: crapper reports site_case 22 → 34 (tile and graph-check branches) and k96_case 9 → 15 (width loop) for the full PR. The interdiff adds no branches.
Silent failure: 2 comparison results followed through ok to checks_failed and a failing exit status.
Tests, static mutation check: replacing the token-major stride at q8f32.rs:2462 with (m, 1) fails the host-rule bit assertion. Both edited comparisons still reject differing bits and now reject unequal lengths. Matching NaN buffers still fail the existing finite-output check.
Gates: no bands, tolerances or pins moved. No test clauses changed in the interdiff.
Escape catalog: no C1–C4 patterns matched.
Notes
Dryer skipped gpu-gates by design; both edited comparisons were checked manually.
Validation was static. CUDA gates were not rerun here. The PR supplies GB10 gate output and timed A/B evidence.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_bf16.rs, crates/gpu/src/q8f32.rs, crates/gpu/src/site.rs and carries a gate run on the author's card, which counts as verified.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
BF16 가중치의 2~8행 호출을 64열 타일 GEMM 대신 다열 GEMV 한 번으로 처리하게 바꿔, DGX Spark에서 MTP 디코드가 코드 코퍼스 기준 30.33 tok/s에서 36.07 tok/s로 빨라집니다.
Part of #565.
What and why
A BF16 weight (attention and SSM projections, the output head) sees one row per request in plain decode, and 2 to 8 rows per step when several requests decode together or when MTP (multi-token prediction, drafted tokens checked together) verifies a draft.
site::gemvsent one row tobf16_gemvbut sent 2 to 8 rows tobf16_tile_gemm, the 64-column tile built for prompts, which also needs K to be a multiple of 64.This PR gives
bf16_gemvtwo output strides, so it writes either row-major or token-major.site::gemvnow sends every width from 1 to 8 through it with token-major output, as the Q8_0 sites do withq8_0_gemv_mcol. Wide calls (64 columns) keep the tile. The lane accumulation and the warp butterfly sum are unchanged, so every output bit equals the F32 entry's over the widened values, and the tile's. The change adds no CUDA entry, no output buffer and no transpose. It has no model, node or rank-count branch, and the stride follows each tensor's local rows, views included.Release notes: Changed: BF16 matrices take one multi-column gemv for batches of 2 to 8 rows, which speeds up MTP and concurrent decode on a DGX Spark.
Code shape
enqueue_bf16_gemvdelegates to the newenqueue_bf16_gemv_mcol; both layouts share the geometry check, the accumulation and the store helper. The BF16 head and MTP head callers keep the row-major call.gemv_planesis replaced by the gemv call.bf16_tile_gemmstays:site::gemmstill uses it at 64 columns.enqueue_bf16_gemvare unchanged and named.cargo fmtis clean on what I touched.Duplication found or removed (
path:line): none. The one kernel is reused; the output layout is chosen byGemvOut, as incrates/gpu/src/q8f32.rsfor Q8_0.What I ran
Speed A/B
Main is
05b5cbb94fb010ba15eaf569d7435224eb5bfd17, and the measured head259cd0bais this change on that main. The PR head is the same change on mainf02460d16. Main changed none ofq8f32.rs,site.rsandgate_bf16.rsbetween the two. Against the measured diff, the PR diff only refills the gate's output buffer with NaN before the tile comparison, compares the tile and replay outputs with the sharedbits_equal, makesenqueue_bf16_gemv_mcolandBf16GemvMcolArgspub(crate)and drops two doc-comment lines, so no kernel or launch differs from what was timed.The model is
nvidia/Qwen3.8-Flash-Next-NVFP4at revisionfc694b54fb0174e0913e6adf86691ef85a4ead47, converted by bloomery-model-hf'sprepare --keep-bf16withBLOOMERY_PREPARE_Q8unset, so its BF16 matrices stay BF16 (type 30). MTP usesMTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguffromunsloth/Qwen3.8-Flash-Next-GGUFat revision766911a6b7369840a91dbcd95f9f997acaab6cd6. Both servers run with--parallel 4 --ctx-size 16896. Each round starts a fresh server per arm after a discarded 4,096-token warm-up request. One request means one client at a time, four requests means four clients at once. Prompts are 4,096 tokens from a code corpus and a prose corpus, and each request generates 128 tokens. There were three rounds, the arm order rotated every round, and main and head alternated within one lease. The table gives medians of the three rounds.Decode tok/s is a request's 127 tokens after its first, divided by the time from its first to its last token. Steady total tok/s counts the tokens all four requests produce while all four are decoding, from the latest first token to the earliest last token. Makespan runs from the first request sent to the last token.
Delta (head minus main): MTP decode on code +18.9% and on prose +21.0%; four code requests: steady total +18.3%, makespan -4.0%, client decode median -17.5%.
The one-request no-MTP rows are controls: their ranges overlap, so this run shows no change at one request without MTP. MTP decode on code is faster in every round, +16.7% to +27.4%.
Every one of the 60 main/head response pairs holds the same 128 token ids.
The four-request code row
The client decode median for four code requests falls even though the steady total rises and the makespan shrinks. The fall tracks when the requests start decoding. The steady total shows the decode step itself is faster. The serve worker runs a whole prompt before it steps the other slots, so with four 4,096-token prompts the first tokens arrive in two waves (round 1, seconds from the start):
On main, three of four requests have their first token only after every prompt is done, so their decode window has no prompt in it. With this change two requests have a first token at 16.74 s and then wait through the other two prompts, and that gap sits inside their 127-token window. The median over four requests therefore moves with how many requests get an early first token. In the steady window all four are decoding, and the total there is 40.75 tok/s on main and 48.22 tok/s with this change. The prose row, which has the same prompt scheduling, rises. Prompt scheduling is not part of this PR.
GPU evidence
Card and driver, from
nvidia-smion the DGX Spark that ran the gate:Card and clock state at the start of the A/B sitting, with the clock cap lifted for the sitting and restored after it (
nvidia-smi --query-gpuline, then the first witness):The gate, on the changed gemv and its site:
gate_bf16now checks every width 1..=8 on four shapes (8,192 x 2,560, 2,560 x 4,096, 1,024 x 128 and a 19-row tail) against the F32 site and the BF16 tile, captures each small call as one graph node and replays it, and adds a K = 96 case the tile cannot take. All 32 tile comparisons and all 32 graph replays with one node pass. The kernel keeps no local memory:The tile comparison refills the output buffer with NaN before the tile runs, so a tile that skips a write cannot pass on the F32 site's values. With
bf16_tile_gemmchanged to return at once forn < 32, the gate fails on every small width, and passes again with the kernel restored:Launch geometry. Widths 2 to 8 used to launch
bf16_tile_gemmas ceil(rows / 32) blocks of 512 threads and now launchbf16_gemvas ceil(rows / 8) blocks of 256 threads. Fromjust ptx-scan gate_bf16 bf16on the GB10 (thejit_regscolumn is what the driver JIT assigned for compute capability 12.1):The GB10 has 48 SMs, 65,536 registers, 1,536 threads, 24 blocks and 102,400 B of shared memory per SM.
bf16_tile_gemmneeds 109 x 512 = 55,808 registers per block, so one block (16 warps) fits on an SM, and its 49,152 B of shared memory would allow two.bf16_gemvneeds 40 x 256 = 10,240 registers and no shared memory, so the thread limit binds at six blocks (48 warps). An SM therefore holds 48 rows in flight with the gemv against 32 with the tile, with three times the warps to cover memory latency [derived]. Neither kernel spills.The same gate with only its own changes applied to main's
site.rsfails on the K = 96 case: one column passes, and two columns reach the tile's multiple-of-64 check.Reproduce
Convert the checkpoint folder, then start one server per arm, main's binary and this branch's in turn:
Each request is a streamed
POST /completionwith the 4,096 prompt ids, greedy and without the prompt cache:{"prompt": [<4096 ids>], "n_predict": 128, "cache_prompt": false, "stream": true, "timings_per_token": true, "return_tokens": true, "temperature": 0, "top_k": 1}Hardware
A DGX Spark (NVIDIA GB10, driver 595.84, CUDA 13.3, sm_121 release builds), CPU governor
performance. During the sitting the card reported a 3003 MHz maximum SM clock and up to 83 C, with zero thermal-cap counts.What I ran into
None of this blocks the PR. A standalone read-bandwidth probe at the start and the end of the sitting fell from 252.4 GB/s to 196.1 GB/s, so I draw no absolute bandwidth conclusion. The result above is a main/head comparison taken under alternating arms in one lease. I took no component profile of the small BF16 calls, so the gain is measured end to end only. I also did not instrument why this change admits two requests in the first wave instead of one.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.