Skip to content

gpu: load a pair of columns' chunks of a multi-column F32 row walk before their multiply-adds - #707

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-mtp-fp8
Oct 23, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-mtp-fp8

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

2열에서 8열까지 처리하는 F32와 BF16 행 읽기가 열 두 개의 chunk를 먼저 읽은 뒤 계산하도록 바꿔, DGX Spark의 NVFP4 MTP 디코드가 코드 기준 40.93 tok/s에서 44.47 tok/s로 빨라집니다.

Part of #565.

What and why

With MTP (multi-token prediction), the target verifies a draft in one step of 2 to 8 rows. Besides the routed experts, every extra row costs the dense BF16 projections, the router and the F32 beta and alpha gemvs. These calls share one row walk, f32_lane_partials in crates/gpu/src/q8f32.rs. For 2 to 8 columns it used to load each column's chunk and multiply-add it behind that column's branch, so a trip waited for one load round trip per live column.

A trip now loads the chunks of two columns, then does their multiply-adds, so it waits for one round trip per pair. When the column count is odd, the last pair's second column reads column 0's chunk, which keeps the pair under one branch, and its sum is reset to zero before the tail. Every column still adds its chunks in increasing order, so the output bits are the same. f32_fold_values is the one place that fixes the order of the eight multiply-adds, shared by the pair walk and the one-column fold. The change touches one file and adds no CUDA entry, flag or per-model branch.

Release notes: Changed: NVFP4 MTP verify steps and batched decode on a DGX Spark run about 6 to 9 percent faster, with the same output tokens.

Code shape

  • No second copy. The pair walk and the one-column fold call f32_fold_values, so the fold order has one owner.
  • Model code holds only architecture facts. No model file changes.
  • Dead code is gone. Nothing is left unused.
  • No silent failure. The walk adds no new error path; the padding column's sum is reset to zero, and the host test checks it.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance, pin or lint level moves.
  • cargo fmt is clean on what I touched.

Duplication found or removed (path:line): none.

What I ran

Speed A/B

Main is a83dd0df93eded2e88dcf7be7a886d5c3c97646f, and the measured head is this change on that main. This PR's head is the same commit rebased onto main b9dfc4a748ea7d7b713ec831100761ef047b5472. git range-diff shows the commit unchanged, so the patch is the same, and I did not measure again after the rebase. The whole A/B ran in one sitting.

The model is nvidia/Qwen3.8-Flash-Next-NVFP4 at revision fc694b54fb0174e0913e6adf86691ef85a4ead47, served with its own MTP layer. Each arm starts a fresh server, with one load per arm, and the clock cap is lifted for the timed arm only. Prompts are 4,096 token ids from a code corpus and a prose corpus, and each request generates 128 tokens with greedy decoding. The four-request arm sends four 256-id prompts at once and ignores EOS. Decode tok/s is the request's generated tokens divided by its decode time. Steady total tok/s counts the tokens all four requests produce while all four decode.

Case Metric Main Head Change
code, MTP, one request decode tok/s 40.93 44.47 +8.66%
prose, MTP, one request decode tok/s 30.20 32.12 +6.37%
code, no MTP, one request decode tok/s 21.89 22.52 +2.87%
prose, no MTP, one request decode tok/s 21.91 22.35 +2.04%
four requests steady total tok/s 51.83 56.13 +8.30%
four requests TPOT p95 ms 89.48 83.10 -7.13%

Delta (head minus main): MTP decode on code +8.66% and on prose +6.37%; four requests: steady total +8.30%, TPOT p95 -7.13%.

Main and head generate the same tokens on every request, with MTP on and off. The paired requests move in the same direction: both code requests gain 6.4 percent and 10.9 percent, and both prose requests gain 6.1 percent and 6.6 percent. This is a short sample with two requests per corpus and one sitting, so it has no confidence interval. The no-MTP gain is small. With MTP on, the chooser also picked different widths, which changes the draft count between the two builds.

GPU evidence

Card and driver, from nvidia-smi on the DGX Spark that ran the A/B:

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |

The card at idle, and its clock under load with the cap lifted:

| N/A   50C    P8              4W /  N/A  | Not Supported          |      0%      Default |
2457 MHz, [N/A], 53.83 W, 67

The NVFP4 MTP gate, with the folder's own MTP layer, on a second DGX Spark (GB10):

NVIDIA GB10, 595.84, 12.1
BLOOMERY_DRAFT=mtp BLOOMERY_REF_MODEL=<Qwen3.8-Flash-Next-NVFP4 folder> BLOOMERY_BOX_LOCAL=1 just gate-gpu-qwen4exp-nvfp4
(l) folder MTP draft_resident_bytes=2775963648 arena_bytes=53526700 PASS
(mtp-g) rows=1 poisoned scratch: eager = graph = replay PASS
(mtp-g) rows=2 poisoned scratch: eager = graph = replay PASS
(mtp-g) rows=3 poisoned scratch: eager = graph = replay PASS
(mtp-g) rows=4 poisoned scratch: eager = graph = replay PASS
(mtp-v) greedy target oracle: 32 tokens plain = verified PASS
gpu-gate.sh: gate_qwen4exp_nvfp4 ran 294 s (exit 0)

The BF16 gate checks the output bits of the BF16 site and the F32 site for 1 to 8 columns, graph replay included, on an RTX 5090:

just gate-gpu-bf16
bf16 clause=site.bits shape=blk.3.attn_q.weight rows=8192 k=2560 call=gemv m=8 equal=65536/65536 PASS
bf16 clause=f32.bits shape=blk.3.attn_q.weight rows=8192 k=2560 call=gemv m=8 the f32 site's outputs equal=true PASS

The host test f32_walks_are_the_scalar_walk compares 1 to 8 columns, k from 32 to 1536, against a scalar fma walk bit by bit, and checks that columns past the live count read 0.0. It succeeds on the head. With the padding column's sum reset removed, it stops on the first odd pair:

head rc=0
assertion `left == right` failed: k=256 m=3 row=0 lane=0 col=3
mutant rc=101

sm_86 PTX

The three sel kernels (nvfp4_gemv_sel32, nvfp4_gemv_sel_f32 and nvfp4_gate_up_sel) are not changed, so the sm_86 build, the spill pins and the jit_local pins stay as they are. just ptx-compare shows six changed entries and none added or removed:

changed       6: bf16_gemv (regs:48->56 blk/SM(static):5->4 jit_regs:40->48
qwen35moe_router_fused (regs:40->62

bf16_gemv and qwen35moe_router_fused also serve the one-row path, so on sm_86 their higher register counts lower the static blocks per SM by one step for plain decode too (5 to 4 for bf16_gemv). I have no sm_86 card here and did not measure that path, so its speed there is unknown.

Hardware

DGX Spark (NVIDIA GB10, driver 595.84, CUDA 13.3, sm_121) for the A/B and the MTP gate, and an RTX 5090 for the BF16 gate and the host test.

What I ran into

None of this blocks the PR. The A/B for the final code is one sitting, so the gain is not confirmed across sittings. The draft-off gain is small enough that run-to-run variation may account for part of it. I did not profile the kernels after the change, so I do not know which kernel gives the gain.

AI help

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

…fore their multiply-adds

f32_lane_partials, the row walk of the F32 and BF16 gemv at 2 to 8
columns (the dense sites of a verify pass or a batch of slots, and the
router's gated walk), guarded each column's chunk loads and their
multiply-adds behind that column's branch, so a trip waited on one
load round trip per live column. A trip now loads the chunks of two
columns before either column's multiply-adds, one branch per pair;
when m_cols is odd, the last pair's second column reads column 0's
chunks and its sum is zeroed before the tail. Each column still adds
its chunks in increasing order, so every output keeps its bits
(f32_walks_are_the_scalar_walk).
@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 23, 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: The changed walk preserves live-column bounds and accumulation order; no must-fix defect was found.

Non-blocking

⚠ Complete the timing evidence: crates/gpu/src/q8f32.rs:267. The changed loop feeds bf16_gemv; the PR reports sm_86 static blocks/SM falling from 5 to 4, an occupancy/geometry change.
The GB10 A/B table omits the measured head SHA and timing commands/output. Attach the original run record with both measured SHAs, commands/output, and the GB10 resource calculation.

Checked

Duplicates: 1 new function and 2 local closures checked. The pair walk and single-column fold share the fold sequence.
Complexity: pair guards replace individual column guards.
Silent failure: 2 zero fallbacks followed; they select valid padding reads and clear only inactive sums.
Tests: none added or changed. The existing scalar oracle checks all eight slots; removing the reset at line 306 fails its bit assertion, as the PR's mutant output reports.
Bounds and order: checked one column, odd widths, the last lane of a full chunk group, and partial tails. Live columns retain increasing chunk order and explicit FMA.
Gates: no gate or pin changed. BF16 and NVFP4 gate output is present in the PR.
Escape catalog: C1–C4 do not match.

Notes

Static validation only; tests and GPU gates were not rerun.

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.

@juliankang4
juliankang4 merged commit f183978 into midagedev:main Oct 23, 2026
7 checks passed
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