Skip to content

f32 gemv: the m-column walk keeps eight chunks' loads in flight a column - #511

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-verify-expert-once
Oct 19, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-verify-expert-once

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

MTP 검증 단계에서 라우터와 F32 GEMV가 여러 열을 계산할 때 메모리 읽기를 여러 개 미리 띄우게 바꿔서, DGX Spark 한 대에서 MTP 디코드를 빠르게 하는 작업입니다.

Part of #493, section 8.5 (one DGX Spark, TP=1).

What and why

This PR speeds up the MTP verify pass, where the target model checks 2 to 4 drafted rows at once. On one DGX Spark running Qwen3.8-Flash-Next with the shared Q8_0 MTP draft, drafted decode at 4,096 tokens went from 47.84 to 51.28 tok/s on the code-functions prompt set (+7.2%) and from 32.38 to 34.91 tok/s on English prose (+7.8%). Every run decoded the same tokens as main.

The change is in f32_lane_partials (crates/gpu/src/q8f32.rs). It is the per-lane row walk that f32_gemv and qwen35moe_router_fused_512 use when a launch has more than one column. The walk already read each weight word once and multiplied it into every live column. It moved one 32-value chunk per trip, though, and each column's multiply-add sits behind a runtime column guard, so a lane had only one load in flight.

  • A trip now covers LANE_UNROLL (8) chunks. The lane loads the row's eight weight words once. Each live column then loads its eight values before its first multiply-add, in the new helper f32_fold_chunks. The helper f32_load_chunks owns the eight stride-32 loads, for the weight words and the column values alike. The guarded one-chunk walk handles the remaining chunks when the row does not fill a whole trip.
  • Each column still adds its chunks in increasing order. Every column's sum keeps the bits of the single-column body, so the router's logits and the experts it picks do not change.
  • The single-column walks f32_lane_partial_1col and f32_lane_partial_1col_w32 load and fold their eight-chunk trips through the same two helpers, so the chunk offsets and order have one owner. Their compiled code does not change: against main, a ptx-scan of generate_qwen3moe and generate_ds41 moves only f32_gemv, qwen35moe_router_fused, qwen35moe_router_fused_512 and qwen3moe_router_fused, the four entries that run the m-column walk. Every other entry keeps its PTX md5.
  • New CPU test q8f32::tests::f32_walks_are_the_scalar_walk: for 1 to 8 columns and every row length from 32 to 1536 (the unrolled trips of both widths and each tail the walks can end in), column c equals a plain sequential fma walk over column c's chunks, bit for bit, in every lane. One column runs the single-column body, and f32_lane_partial_1col_w32 must give the same bits. The oracle does not call f32_fold_chunks. Swapping two multiply-adds in that helper fails the test, and so does dropping the fold call from either single-column walk.
  • tools/unsafe-ratchet.txt: the gpu crate goes from 1943 to 1958 unsafe blocks and from 212 to 214 unsafe fns, with a PIN(2026-10-19): line. Each fold call has its own block and SAFETY line.

Release notes: Changed: the F32 GEMV and the fused Qwen3.5 MoE router keep eight loads in flight per lane when a launch has 2 to 8 columns, which shortens each MTP verify pass.

Code shape

  • No second copy. f32_gemv and the router already share f32_lane_partials, so both get the change from one place. The m-column walk and both single-column walks load and fold eight chunks through the same two helpers.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone.
  • No silent failure. The inputs are unchanged; check_gemv_geometry still holds the column count to 1..=8.
  • Comments state what is true now.
  • No relaxed gate. The ratchet re-pin carries PIN(2026-10-19): and its reason.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. rustfmt --check is clean on q8f32.rs; clippy on the head: TBD(clippy)

Duplication found or removed (path:line), or "none": the eight-chunk load and multiply-add body of f32_lane_partial_1col and f32_lane_partial_1col_w32 (crates/gpu/src/q8f32.rs), now f32_load_chunks and f32_fold_chunks.

What I ran

On the head TBD(head):

  • tools/gate.sh --oxide -p bloomery-gpu --release --lib -- q8f32::tests::f32_walks_are_the_scalar_walk: TBD(unit-f32 /test result/)
  • just contrib-check --tier t0: TBD(t0 /DONE tier=t0/)
  • rustfmt --edition 2024 --check crates/gpu/src/q8f32.rs: rc 0.
  • just check-unsafe: ok (29 crates, 2998 blocks, 417 fns, 28 impls).
  • just check-comments: ok (1024 files).
  • PTX_SCAN_ARCH=sm_121 bash tools/ptx-scan.sh --no-jit generate_qwen3moe and the same for generate_ds41 (built with --features deepseek41), on this tree and with its two files reset to main: only f32_gemv, qwen35moe_router_fused, qwen35moe_router_fused_512 and qwen3moe_router_fused change md5.

Decode A/B on one DGX Spark

The A/B ran on d6fea090 against main e8abdc89. When both are built on one tree, the crates/gpu/src/q8f32.rs of that commit and of this head give the same PTX md5 for every entry of generate_qwen3moe and generate_ds41. The head adds the tools/unsafe-ratchet.txt pin. Its newer main changes crates/gpu only in the Qwen3.8 PLE host decode, which keeps the IQ4_NL rows of the GGUF below on the path they took before.

Both binaries were built from one base and alternated in one timing lease, in the order main, head, head, main, main, head for each prompt set. Each run loaded a fresh process, prefilled the first 4,096 tokens of the prompt set from #493 and decoded 96 greedy tokens with MTP. The table gives the median of three runs per arm. The verify column is the median, over the three runs, of each run's median 4-row verify pass.

Prompt set Main tok/s (median) Head tok/s (median) Main 4-row verify ms Head 4-row verify ms
code-fn 47.84 51.28 69.68 64.75
prose-en 32.38 34.91 65.55 61.36
Delta (head against main, medians): code-fn +7.2% tok/s and 4.93 ms shorter 4-row verify; prose-en +7.8% tok/s and 4.19 ms shorter 4-row verify; decoded tokens identical in all six runs of each prompt set.

Every run in order:

Prompt set Run Arm tok/s 4-row verify ms (median) Decoded tokens md5
code-fn 1 main 45.42 70.34 b1eabac0
code-fn 2 head 49.15 66.05 b1eabac0
code-fn 3 head 51.28 64.75 b1eabac0
code-fn 4 main 48.09 69.08 b1eabac0
code-fn 5 main 47.84 69.68 b1eabac0
code-fn 6 head 51.41 64.73 b1eabac0
prose-en 1 main 32.00 65.47 ac6f95a4
prose-en 2 head 34.99 61.15 ac6f95a4
prose-en 3 head 34.84 61.36 ac6f95a4
prose-en 4 main 32.62 65.55 ac6f95a4
prose-en 5 main 32.38 65.83 ac6f95a4
prose-en 6 head 34.91 61.73 ac6f95a4

In each round the head beat main by 3.19 to 3.73 tok/s on code-fn and by 2.22 to 2.99 tok/s on prose-en.

An nsys trace of the 4-row verify passes on the code-fn prompt set splits the time by kernel. The two kernels this PR changes take 4.25 ms less per pass, close to the 4.93 ms the A/B measured:

Kernel Blocks Main µs per pass Head µs per pass
qwen35moe_router_fused_512 513 4,564.3 2,396.5
f32_gemv 12 1,967.9 676.8
f32_gemv 16 654.4 223.5
f32_gemv 64 653.8 297.8

To reproduce, build generate_qwen3moe on each commit:

cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features gpu --release --bin generate_qwen3moe

and run each binary with IDS set to the prompt set's first 4,096 token ids, comma separated:

export BLOOMERY_MODEL=qwen4exp
export BLOOMERY_REF_MODEL=UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf
BLOOMERY_DRAFT=mtp BLOOMERY_MTP_DRAFT=MTP/mtp-Qwen3.8-Flash-Next-shared-Q8_0.gguf \
  generate_qwen3moe --tokens "$IDS" -n 96 --ctx 4352 --mode graph --time

The tok/s is the tok/s(mean) field of the SMOKE line.

Hardware

One DGX Spark (NVIDIA GB10, driver 595.84). The binaries were built in the CUDA 13.3.1 devel container and ran on the host. Before the lease no other GPU process ran and the load average was 0.57.

Model: unsloth/Qwen3.8-Flash-Next-GGUF at revision 766911a6b7369840a91dbcd95f9f997acaab6cd6, UD-Q4_K_XL, with the shared Q8_0 MTP draft from the same repository. Context 4,352.

What I ran into

None of this blocks the PR. On code-fn, run 1 (main) and run 2 (head) came in below the other runs of their arm, at 45.42 and 49.15 tok/s. The slow runs hit both arms, and neither is a median.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

The router and f32_gemv at 2 to 8 columns walked one chunk a trip behind
each column's guard, one load in flight a lane. A trip now takes
LANE_UNROLL chunks: the row's words once, then each live column's chunks
loaded before its first multiply-add. f32_load_chunks owns the eight
stride-32 loads and f32_fold_chunks the fold, and both single-column
walks use them too, so every walk adds a column's chunks in the same
order and its sums keep the single-column body's bits.
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 19, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: No correctness or proven quality defect survives the review.

Non-blocking

⚠ Complete the device proof: crates/gpu/src/q8f32.rs:123.
Each eight-chunk trip loads eight weight values per lane, then eight activation values before folding each live column. For the occupancy/geometry class, attach base/head JIT register and spill tables and the selected owning just gate-* commands with output. Include the nvidia-smi line and raw A/B output for the stated commits. The no-JIT md5 summary and timing tables leave this proof incomplete; recording it now makes later regressions comparable.

Checked

Duplicates: 3 new items checked; no duplicate owner. Dryer's pair at q8f32.rs:271/325 has different load widths; the shared eight-chunk loads and folds now use the same helpers.
Complexity: f32_lane_partials rose from 10 to 18 through column guards in the unrolled loop; its responsibility remains one row walk.
Silent failure: 0 added default or swallowed-error sites. GEMV and router launchers reject invalid geometry and propagate shape errors.
Tests: static mutation check: dropping the column-7 fold at line 156 makes the independent scalar assertion at line 2350 fail; dropping the wider walk's fold at line 517 makes line 2361 fail. Rust tests were not executed here.
Gates: unsafe ratchet adds 15 blocks and 2 functions with a dated PIN and reason; no numerical band changed.
Escapes: none of C1–C4 matched. Exact-trip boundaries, all tail lengths, inactive columns and unchanged per-column FMA order were checked.

Notes

The PR body still marks the unit-test, t0 and clippy results TBD. No GPU gate run meeting CONTRIBUTING.md's evidence list is supplied.

Card check: needs-gpu. This pull request changes crates/gpu/src/q8f32.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant