Repository navigation
gemm: copy the BF16 prompt sites' activations rounded once - #761
Conversation
On GB10 a BF16 dense site's MMA tile loaded its F32 activation pieces into registers, checked and rounded them, and stored them into the stage after the current products, in every row block of the product. The walk now rounds a model-width input once into a BF16 form beside its q8 scratch (GemmAct32::with_bf16 and bf16_cols: the words and a refusal word a column), and the tile copies those words with cp.async as it copies the weight's (Bf16Cols). A refused column still replays on the exact owner from the f32 rows, so every output keeps its bits. The tile takes its activations through MmaCols: F32Cols for the existing entries (bf16_mma_gemm, the E4M3 entries and the HC up and down), Bf16Cols for bf16_mma_cols_gemm. site::resident_quantize writes the form when a site reading the rows is BF16 on the MMA tile and marks it stale otherwise; a quantizer launch marks it stale as well, and a GEMM reads it only for the rows and columns it was rounded from. The qwen38 walk holds the form for its model-width rows (the mixers', the shared expert's and the PLE site's input) on a load with such a site whose stage card reserves it. machine_for_experts reserves 5,124 B a position on a unified card (GB10's) and place::bf16_form_bytes reads the row back for the load; a discrete card's plan is unchanged, and its load keeps rounding in the tile.
gqa_flash_fold_mma_256_p12_sel's rows in the three cc 12.1 tables read 0 0, but ptxas 13.3.73 spills 16 bytes of it at sm_121 and sm_121a and the GB10 JIT (driver 595.84) gives it 8 local bytes at every arch, so `ptx-spill-check.sh ... generate_ds41:mma` failed on upstream/main already. The rows now hold the measured values; the entry's PTX is the same with and without the dense MMA tile's activation source (ptx-compare: unchanged). The cc 8.6 rows in tools/ref/ptx-shapes.tsv stay as they are.
nvfp4mma.rs builds only with bloomery_nvfp4_mma (sm_120a and sm_121a), so the default lint never saw it. The SAFETY comment of the module load moves onto the unsafe line, the flat-argument kernel entries and the SwiGLU device core carry the tree's too_many_arguments allowances for kernel ABIs (the core sits in its own module, since the device macro's same-name wrapper repeats its arguments), and the scale packer's range loop keeps the unroller's form. The two host launchers still take flat arguments.
There was a problem hiding this comment.
Verdict: CLEAN: Both findings are non-blocking; neither establishes a must-fix defect.
Non-blocking
⚠ Complete final-head measurements: crates/gpu/src/site.rs:1184. Preparation adds one launch per eligible input group. Its logical traffic is 15,364 B/token at K=2,560 [derived: 4K F32 reads + 2K BF16 writes + one 4-byte refusal word].
The PR reports final-head gate reruns, but its timed A/B predates that head and omits the measured head hash. Supply a final-head A/B with both measured commit hashes, concrete model paths, commands and output to verify the final dispatch cost.
⚠ Overwrite the BF16 form before graph replay: crates/gpu-gates/src/bin/gate_gemm.rs:7394. The eager run leaves the same input and rounded words in place.
Omitting only the captured bf16_cols launch leaves those words valid, so graph_bits still passes. After capture, round a separate zero input into act, then launch the graph and compare with eager. This makes a missing preparation node observable.
Checked
Duplicates: the activation readers reuse land_values and Bf16Rows::fetch. Dryer reported zero model pairs and did not scan GPU crates.
Complexity: dense_mma_case 76→108 adds gate cases; fused_swiglu 17 is a moved body, unchanged apart from a qualified callee. site::gemm 34→38 adds cache dispatch; Wide38::new 13→16 adds optional storage; Body38::load_placed 69→71 adds load-time reserve checks.
Silent failure: cached reads check the source address and column count; fill invalidates the form. Missing optional storage uses the F32 path; malformed reserves and stale direct reads return named errors.
Tests: static mutation analysis confirms the capture-only preparation omission above. Changing reserve >= to == fails the smaller-ubatch assertion. The stale-form case asserts rejection after quantizer reuse.
Gates: unsafe and existing spill-pin changes carry dated PIN reasons; no numeric tolerance moved. New spill-pin FAIL-first evidence is absent and disclosed.
Escape catalog: no C1–C4 pattern matched.
Notes
GPU gates were not rerun during validation. The submitted measurements lack the measured head hash; gpu.json remains evidence: false.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/arch/qwen3moe/body38.rs, crates/gpu/src/arch/qwen3moe/plan38.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)
|
The review is done and the contribution check passed, so I'm merging this. |
Qwen3.8 prefill의 BF16 dense 행렬곱에서 activation을 한 번만 BF16으로 반올림해 두고, 각 곱셈이 weight처럼 그 값을 복사해 쓰게 해서 NVFP4 체크포인트의 prefill을 빠르게 하는 작업입니다.
Part of #565.
What and why
On a GB10, the BF16 dense prompt GEMMs of Qwen3.8 run through one MMA tile. Until now the tile loaded its F32 activation pieces into registers, checked them, rounded them to BF16 and stored them into the stage again in every row block of every product. A bench of tile variants located the cost there. Staging K 64 wide on F32 activations ran slower on the large shapes, and reading activations rounded beforehand at the current K width ran faster.
This PR rounds a model-width input once into a BF16 form (kernel
bf16_cols, which also writes a refusal word per column) and lets the tile copy those words withcp.async, the way it already copies the weight (kernelbf16_mma_cols_gemm). A column the range check refuses is still replayed on the exact path from the F32 rows, so every output keeps its bits.MmaCols.F32Colsis the existing behaviour and stays onbf16_mma_gemm, the E4M3 entries and the HC up and down kernels.Bf16Colscopies the rounded words.GemmAct32can hold aBf16Form(the words, the refusal words and whichxand how many columns they were rounded from).site::resident_quantizewrites it when a site reading those rows is BF16 on the MMA tile and marks it stale otherwise. Every quantizer launch goes throughGemmAct32::fill, which marks the form stale, and thefilledfield is private toact32.rs, so a new quantizer cannot skip that.xand no more columns than were rounded. Anything else takes the old path with the same output.machine_for_expertsreserves the bytes (5,124 B per token of the micro-batch) on a unified-memory card's stage, andbf16_form_bytesreads that row and refuses a missing or doubled one. A discrete card has no such reserve, so its plan does not move.tools/ref/ptx-shapes*.tsvgets rows for the two new entries. The second commit corrects the spill pin ofgqa_flash_fold_mma_256_p12_selat cc 12.1: the table said 0/0, but ptxas reports a 16-byte spill at sm_121 and sm_121a and the driver JIT 8 local bytes at every arch, soptx-spill-check.shwas already red on main. The entry's PTX is not changed by this PR.Release notes: Changed: on GB10, the BF16 dense prompt matrix multiply copies activations that were rounded once instead of rounding them in every tile, which cuts its kernel time and raises NVFP4 prefill speed; outputs are bit-identical.
Code shape
F32Cols, andbf16_cols_bodycalls the tile's ownland_valuesandmma_fits, so the rounding and refusal rule has one owner. HC down's inject read goes through the sameF32Cols::fetch. The gate compares against the F32 path's output, so no rule is copied into it.input_sites,shared_inputs,hidden_sites); the common GEMM owner gained no per-model branch.act.filled(and the one inenqueue_up_swiglu32) becamefill.x, or too few columns, is not read and takes the old path. A misalignedxis refused inenqueue_bf16_cols, and a stale form handed toenqueue_bf16_mma_colsis a State error.tools/check-comments.shis ok.gqa_flash_fold_mma_256_p12_selrow above, which was wrong on main, and it carriesPIN(2026-10-24)and its reason. The unsafe ratchet rises with the new code under a PIN line.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up. The lint count stays at the ratchet's 3 warnings, all inq38_combine.rs.nvfp4mma.rsbuilds only for native FP4 targets. UnderCUDA_OXIDE_TARGET=sm_121a ./tools/mac-check.sh lintit no longer reports the misplacedSAFETYcomment: this PR moves the comment onto theunsafeline and gives the file's kernel entries thetoo_many_argumentsallows the other kernel entries carry. Its two host launchers still reporttoo_many_arguments, as on main.Duplication found or removed (
path:line): the duplicate scan flaggedcrates/gpu/src/gemm/f32tile.rs:693againstcrates/gpu/src/hc_gated.rs:1729,f32tile.rs:1335againstcrates/gpu/src/q8f32.rs:2896, and twokernels32.rs:1324pairs. They differ in what they read (activation columns against weight rows, a form check and a different launch, separate kernel entries that call the shared body). An earlier flagged pair,Bf16Cols::fetchandBf16Rows::fetch, is now one:Bf16Cols::fetchcallsBf16Rows(self.words).fetch.What I ran
Output is unchanged
In the production-entry micro, the F32 path and the BF16-form path produce the same output digest at every shape. In the gate, every new
dense_mma bf16_colsrow compares both the eager output and the graph-replayed output with the F32 path's output.Greedy decoding of 128 tokens gives the same token hashes for main and head on both checkpoints in all three windows, and the 2-token profiled request matches too (
PARITY ... Truefor four pairs).GPU evidence
DGX Spark (GB10).
nvidia-smioutput on the gate run:Build:
cargo oxide build --arch sm_121a -- --locked -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,solar2,minimaxm3,gemma-embedding2,hf,checkpoint --release --bin gate_gemm --bin gate_hc_gated --bin gate_bf16 --bin gate_mxfp8, withBLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any.just gate-gpu-gemm,just gate-gpu-bf16,just gate-gpu-mxfp8andjust gate-gpu-hc-gatedwere not run as recipes: the node run built each gate binary withcargo oxide buildand ran it throughbash tools/gpu-gate.sh, the last step of each recipe.The gates below ran two commits before the head that goes up. On the head that goes up,
gate_gemm(dense_mma,nvfp4_native,nvfp4_swiglu) andgate_hc_gatedran again with the same counts. The last commit does not touch the code thatgate_bf16andgate_mxfp8cover:FAIL-first
Bf16Cols::refusedforced to false,gate_gemm --case dense_mmaexits 1, and the only FAIL lines are the two cells rows with a refused column (bf16_cols_bits=false). Every other row passes.dense_mma bf16_cols stale_refusedrow checks that a fresh form is read (fresh_read) and that the same read is refused after a quantizer reuses the activation buffer (after_quantize). With the invalidation removed fromGemmAct32::fill,dense_mmaexits 1 with 88 passed and 1 failed, the only FAIL beingafter_quantize=false.a_unified_stage_reserves_the_bf16_formpasses on the head and fails on each of three mutants (reserve on every card,b >= wantturned intob == want, the refusal removed). The tree was clean after the mutants.Speed
Server A/B on one DGX Spark with the default
sm_121abuild of both trees (main at100c224fc): Qwen3.8 NVFP4 and FP4-Local, C = 1, draft off, three 4096-id code windows with 128 greedy tokens each, median of three requests, then one profiled 2-token request per arm for kernel times. Each checkpoint started with a discarded warm load, the clock cap was lifted only around each arm's requests and restored after, and NVFP4 ran head, main, head, main. Reproduce withbloomery-serve -m <model dir> --parallel 4 --ctx-size 16896withBLOOMERY_DRAFT=off BLOOMERY_HOST_ROOM=96G, requests on/completionat temperature 0, seed 1.Delta (head against main): NVFP4 prefill +3.5% and +3.8% in two alternated pairs (1527.3 to 1581.4 and 1572.5 to 1631.8 tok/s) with 67.8 ms less GPU kernel time in the profiled request; FP4-Local, whose dense sites are MXFP8, moves 4.4 ms of kernel time and its +4.5% prefill comes from one slow main request; one sitting on one machine, so a single observation.
Where the NVFP4 time went, from the profiled request:
bf16_mma_gemmwent from 327 launches and 503.9 ms to 97 launches and 145.6 ms, plus 230 launches ofbf16_mma_cols_gemmat 245.2 ms and 97 launches ofbf16_colsat 27.9 ms. The TTFT drop (92 to 93 ms) is close to the 85.2 ms drop in BF16 dense kernel time. Head was ahead of the neighbouring main in both pairs, and both arms got faster over the sitting, which order alone does not explain.FP4-Local's dense sites are MXFP8, so this change barely touches it: its kernel time moves by 4.4 ms. Its +4.5% prefill comes from one slow third request of main (1320.8 tok/s), which the kernels do not explain. I count it as noise and make no FP4-Local speed claim.
Production-entry micro on one DGX Spark (4,096 columns, synthetic inputs, three orders alternated, median): the BF16-form entry takes 0.287 to 0.791 of the F32 entry's time at the TP=1 shapes and 0.690 to 0.790 at the split shapes for 2 and 4 ranks. For one 4K prompt's BF16 launches, 523.2 ms becomes 447.6 ms with the 96 roundings included (-75.7 ms, -14.5%). This micro ran on the commit that introduced the entries, whose dense device code is the same as the head's (the same ptx-compare md5 for each of these entries).
Compiler and PTX
Bf16Cols::fetchchange:ptx-comparereports identical PTX, 402 entries on each side.bf16_cols,bf16_mma_cols_gemm), none removed. Five existing entries (bf16_mma_gemm,fp8_b128_mma_gemm,mxfp8_mma_gemm,hc_gated_up_mma_mix_4,hc_gated_down_mma_4) changed only in their PTX text hash, with the same registers, shared memory, spills and instruction counts, because the tile now reads its activations throughF32Cols.bf16_mma_cols_gemm122 registers, 48 KiB static shared, no local memory;bf16_cols28 registers;bf16_mma_gemm128.ptx-spill-check.shreportsviolations=0 PASSat sm_121, sm_121a and sm_86 on the dense device code, also on the head that goes up, wherehc_gated_down_mma_4andgemm_nvfp4_mmastay at their pinned 0 spill bytes. Theptx-comparelines above were taken one commit before HC down's inject read moved toF32Cols::fetch.tools/check-unsafe.shis ok (gpu 2302 to 2314unsafeblocks, 285 to 295unsafe fn, each new block with aSAFETYcomment).Measured head against the head that goes up
The server A/B ran on an earlier head over main
100c224fc. The head that goes up was rebased onto a newer main afterwards, so the rebase is not pure: it carries three new upstream commits, and this PR gained a few host lines (the new SwiGLU quantizer now callsact.fill,nvfp4mma.rsreadsact.filled(),filledis private toact32.rs, andBf16Cols::fetchcallsBf16Rows::fetch). The device code of the dense entries did not change, which the identicalptx-compareabove shows against the gate head. I did not rerun the timed A/B on the final head.Hardware
DGX Spark (GB10), driver 595.84, CUDA 13.3 (
Build cuda_13.3.r13.3/compiler.38244171_0). Models: Qwen3.8 NVFP4 and Qwen3.8 FP4-Local. Thenvidia-smilines are under GPU evidence above.What I ran into
None of this blocks the PR.
qwen4exp_mtp_reserve::a_drafted_plan_on_one_pool_counts_the_draft_oncefails on main with the same message ("a pool one byte under the need: Ok(3583999)"); this branch does not touch that file or machine.hc_gated_up_mma_mix_4) read 1.2% to 1.9% slower at the median of nine launches in two micro runs, with the whole mix step unchanged within 0.4%. Its PTX hash moved and its resources did not. I could not tell noise from a small real cost with nine launches.fp8_b128_mma_gemm(its dense gate row passes, and neither checkpoint uses it), and a FAIL-first for the new 0/0 spill pins.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.