Repository navigation
gpu: walk the native NVFP4 route tile, the HC norm and the prefill flash's query staging with fewer loads - #847
Conversation
…staging The ubatch walk's selecting layers ran head_norm_neox_append_256 over every query and key head: each query head's RMS norm and NEOX turn written to the arena's query rows (at 4,096 rows 100.7 MB), which the prefill flash read back to stage them as f16. The flash's staging can make those values from the [q | gate] rows it already reads for the gate. The prefill bodies take their query rows through QueryRows: Stored reads them as before; Normed38 takes each staged row's scale from one warp (rope_neox::query_scale_256, which works the norm block's four warp sums in the block's order) into the exchange, then each value as the norm writes it (query_value_256: (scale * gain) * x, the first 64 turned through neox_pair), a position at or past the cache's height NaN. The gated entries read [q | gate] rows and a Query38 (gain, table, positions, eps) and run the query norm, the flash and the out gate in one launch; the walk runs the norm launch over the key heads alone, so the ubatch arena holds no query rows. hw_gated_entries_are_the_query_norm_flash_and_out_gate holds both gated entries bit for bit to the query norm, the plain entry and the out gate, over raw queries, gates in [-8, 8), a NaN gate's fault and a position past the cache; it also checks that both refuse each input one value short by name.
…oss the norm's sum
… dead fragments unread
…ed memory ahead of the K walk, so its epilogue reads them without a global load
There was a problem hiding this comment.
Verdict: CLEAN: no failure path survived; the bit-for-bit gates cover the new query staging and the NVFP4 full-tile walk, and the open points below are non-blocking.
Non-blocking
⚠ The plan still counts query rows the ubatch arena no longer holds: place.rs:1165 UBATCH_TOKEN_BYTES (644,345) includes the q rows that scratch38.rs:346 now allocates as parts * ATTN (zero in a ubatch walk). That is 24,576 B per position, 100,663,296 B at U = 4096 [derived: 4096 · 6144 · 4], counted and never used. The check at body38.rs:1890 only refuses a larger arena, so nothing fails. The earlier flash-row change re-pinned this constant the same way. Re-pin it here or say in the PR body that the re-pin follows.
⚠ The HC norm's two paths are gated on one side only: hc_gated.rs:708 one = hid <= NORM_CHUNK * NORM_THREADS is 4096, and the gate and the unit test run hidden 2560 and 64 only. Hidden 4352 takes the !one path, which no gate runs. Mutant: one true for hidden > 4096. The loop then runs twice, xv keeps only the last chunk, and no assertion turns red. Add one hidden-4352 case, or state in the PR body that the path is not gated.
⚠ hc_gated.rs:680: PIN(2026-10-27) is dated after the other PINs of this PR (2026-10-26). Use the date of the commit.
Also 1 minor: the three unsafe-ratchet.txt PINs each say 2655 -> 2691; give each its own delta.
Checked
- Duplicates: 14 new items checked (
shortmoved to one owner,warp_sum_f64reused,QueryRows,NormedRows,QueryNorm,TileColumns,query_scale_256,query_value_256); none duplicated beyond what the PR body lists. The 3 dryer pairs inflash_gqa_prefill.rsare kernel entry wrappers that differ byPACK; no finding. - Complexity:
prefill_256_p44→50 andprefill_256_sel28→34 are one compile-timeQ::RAWbranch (read for correctness only);norm_stream20→24 is theonebranch (see ⚠);qsa26→27 is even growth. - Silent failure: 6 sites followed. A position past
ctxgives a NaN row, and the key launch still raisesCachePos. A shortqg, gain, table or position list is refused by name. - Position indexing: after
narrow,pos[r]is the position ofqgrowt0 + r. Matcheswide38.rs:2612. - Tests: the new hw test compares both entries bit for bit with the old chain. Mutants checked (dropped RoPE turn,
pos[0]forpos[t], changed warp sum order, missing NaN forp >= ctx) each turn an assertion red. The new gemm row (128, 129, 256) reaches the full-tile path. - Gates: no band or tolerance moved. Escape catalog: no pattern matched.
Notes
- The head was not run on a card (PR body). The arena change and
n_head: 0inwide38.rshave no GPU run at this head;n_head: 0has a gate precedent ingate_qwen35moe_attn.rs:592.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/arch/qwen3moe/scratch38.rs, crates/gpu/src/arch/qwen3moe/wide38.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. |
Qwen3.8 FP4-Local의 prefill에서 native NVFP4 expert tile, HC norm, prefill flash의 query 준비가 읽는 양을 줄여 DGX Spark의 prefill 속도를 높이는 속도 PR입니다.
What and why
This PR removes redundant loads and checks from three parts of the Qwen3.8 prefill on a DGX Spark: the native NVFP4 route kernels, the HC norm and the prefill flash. The results stay the same in the checks below.
crates/gpu/src/gemm/nvfp4mma.rs). A whole tile, and a short tile of an even K, are walked as whole ones without the half and fragment checks for fragments that are never read. The tile's slots and input scales are kept in shared memory (TileColumns) ahead of the K walk, so the epilogues ofgate_up_nvfp4_mmaandgemm_nvfp4_mmaread them without a global load.norm_streamincrates/gpu/src/hc_gated.rs). For a stream of one chunk per thread, the values and gains stay in registers across the norm's sum instead of being read back after it. The sum order is unchanged.crates/gpu/src/flash_gqa_prefill.rs,rope_neox.rs,arch/qwen3moe/wide38.rs). The selecting layers used to run the query head norm and NEOX turn into the arena's query rows, which the flash then read back to stage. The two gated entries (enqueue_256_p4_gated,enqueue_256_p12_sel_gated) now take the[q | gate]rows and aQueryNorm(gain, table, positions, eps) and norm and turn each query in the staging, so the walk's append runs over the key heads alone. The scale is worked by one warp in the norm block's order throughlatent::warp_sum_f64, which is nowpub(crate).Greedy output is identical on every request in both comparison parts below.
Release notes: Changed: Qwen3.8 FP4-Local prefill is faster on a DGX Spark, with identical greedy output.
Code shape
TileColumns. The query norm calls the existinglatent::warp_sum_f64, nowpub(crate), and the gated entries' length check callsshort, which moved fromq38.rstocrates/gpu/src/lib.rsso that common code can call it.cand.rsnow calls it too, in place of its own private copy.QueryNormandNormedRowsare named for the norm they run, not for a model, and sit in the commonflash_gqa_prefill.rs;wide38.rshands its gain, table and positions throughQueryNorm.wide38.rsstill passes its (empty)q.qto the append, which writes no query head into it.[q | gate]buffer, gain, table or position list one value short is refused by name in both gated entries, and a position past the cache gives a NaN row.tools/unsafe-ratchet.txtrises for new code (gpu 2655 to 2691 blocks, 336 to 346 fns) with three datedPINlines, each new block with its SAFETY line.norm_streamgains oneallow(clippy::needless_range_loop)with its reason and a datedPINline.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.just lintpassed with 0 warnings and 0 errors on981493fb; I did not record a separatecargo fmtrun.Duplication found or removed (
path:line), or "none": the f64 warp butterfly (16, 8, 4, 2, 1) thatlatent::warp_sum_f64holds is also written out atcrates/gpu/src/ple.rs:483,crates/gpu/src/linear/conv.rs:172,crates/gpu/src/linear/norm_gate.rs:117,crates/gpu/src/qk_rms.rs:112,crates/gpu/src/qsa.rs:175andcrates/gpu/src/rope_neox.rs:292,:514,:1025,:1496. The same inline length check asshortis also written out at several other sites inflash_gqa_prefill.rs. I left them as they are.What I ran
The commands ran on a DGX Spark. The two flash and HC gates ran on
981493fb5b5f70eab85db0ea5f7138098c6169a0. The head differs from it by rebases onto upstream main (one over a change to the prefill-256 staging inflash_gqa_prefill.rs, the last over changes to the MTP width chooser and a PTX shape table, none in files this PR touches), renames of two types and one error string,shortmoving tolib.rsandcand.rscalling it instead of its private copy, the ubatch walk's arena allocating no query rows, the flash test building its gated arguments in one helper (gated_launch), and one comment line before theallowonnorm_stream. On an sm_86 build of1062258a, which has the renames but not the changes after them,just ptx-comparereports all 452 entries identical to981493fb. The changes after that are host or test code, and I did not rerun a GPU gate, a GPU build or the timings on this head, including after the last rebase. Thegate_gemmcases ran on an earlier revision of this branch whosecrates/gpu/src/gemm/nvfp4mma.rsis identical to this head's.The test above holds both gated entries bit for bit to the query norm, the plain flash and the out gate. Each new length check was made to fail first by removing it, and the test passes again after the file was restored:
poslength check fails the test: MUTANT holds-pos rc=101The native NVFP4 cases:
nvfp4_native: nvfp4_native PASS lines: 43, including the new row (128, 129, 256).nvfp4_gate_up: nvfp4_gate_up PASS lines: 9.nvfp4_swiglu: nvfp4_swiglu PASS lines: 21.The slot and input scale columns were made to fail first by reading or writing one column over in
nvfp4mma.rs; the file was restored afterwards:nvfp4_native: MUTANT put-slot nvfp4_native rc=1 FAIL lines: 22nvfp4_gate_up: MUTANT gate-up-slot nvfp4_gate_up rc=1 FAIL lines: 6nvfp4_gate_up: MUTANT gate-up-scale nvfp4_gate_up rc=1 FAIL lines: 6just lint(clippy over the workspace, all targets) on981493fb: LINT rc=0 warnings=0 errors=0I did not run
just gate-ptx-spillor the other recipesjust affectedselects forcrates/gpuon this head; a maintainer runs those on the workstation.Speed
The timed runs and the lint run below are on
981493fb5b5f70eab85db0ea5f7138098c6169a0; the gates and timings were not rerun on this head. The timed model isnvidia/Qwen3.8-Flash-Next-FP4-Localat revisionb9ce18a6887e18c089fdea8509a33e63429a3300, with the Q8_0 MTP draft for the draft-on arms (unsloth/Qwen3.8-Flash-Next-GGUFat revision766911a6b7369840a91dbcd95f9f997acaab6cd6). Each run uses a 4096-id prompt and 128 greedy tokens, on eight corpus windows 50,000 ids apart, with three rounds after a lead-in. Base is upstream mainba8877d75fc1aacbcc5427d7bc99d0f8ec438d37, built from its own tree, and head is981493fb5b5f70eab85db0ea5f7138098c6169a0, so the timed base is not this PR's base. Base and head run alternately. The draft-off arm and the draft-on arms ran as two parts of one comparison. Each cell is the median of three rounds. Greedy output is identical on every request.Change is head against base; higher is better for tok/s and lower is better for TTFT. Ranges are "separate" when the three head rounds and the three main rounds do not overlap.
without a draft, prefill +1.445% and TTFT p95 -1.441% are resolved above 0.500% and decode +0.647% above 0.524%; with the MTP draft only prose-en prefill (+1.951%) and TTFT p95 (-1.909%) are resolved, and the other MTP rows are inside the 3.040%, 1.116%, 1.168% and 5.928% their runs can resolve
The draft-on rows other than prose-en prefill and TTFT are inside the spread of repeated runs of the same tree, so they are not evidence of an effect or of none.
Reproduction
Build the head the same way. Send 4096-id prompts from eight windows of the same corpus with 128 greedy tokens (temperature 0), alternating the two trees, and compare the median server prefill rate. For the draft-on arms set
BLOOMERY_DRAFT=mtp,BLOOMERY_MTP_DRAFTto the MTP draft file andBLOOMERY_MTP_WIDTH=cost.Hardware
DGX Spark machines for the timed runs and the gates. This section lists only the card and driver lines saved with the runs.
CPU and RAM were not recorded for these runs.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.