Repository navigation
qwen38: a load whose every layer runs hostless over native NVFP4 downs keeps its card route's down rows in BF16, the product rounding each to nearest even and the block's card sum widening it - #909
juliankang4 wants to merge 5 commits into
Conversation
…uad and loads its fragments before their MMAs
… their count a literal
…s keeps its card route's down rows in BF16, the product rounding each to nearest even and the block's card sum widening it
There was a problem hiding this comment.
Verdict: MUST_FIX: one PIN comment states a move that the table does not make; the kernel and combine changes held up under my checks.
Must fix
1. The gemm_nvfp4_mma PIN narrates a change the row does not make
tools/ref/ptx-shapes/sm_121a-cc12.1.tsv:187 says "spill 16 -> 0 B, JIT local 8 -> 0 B" above gemm_nvfp4_mma 0 0. The base row is already 0 0, and this diff leaves it unchanged. A PIN records a moved value with evidence. This one records a move that is not in the table, and it carries history, which the project keeps in commit messages. The reader cannot tell whether the base gate was stale or the comment is wrong. Fixing it now is cheaper than a later reader trusting it.
Fix: delete the two lines at 187-188 and put the new entry's own PIN above its row:
# PIN(2026-10-28): gemm_nvfp4_mma_bf16, a new entry: 0 spill and 0 JIT local bytes (sm_121a ptxas 13.3.73, cc 12.1 JIT on GB10 driver 595.84, gate-ptx-spill).
generate_ds41 gemm_nvfp4_mma_bf16 0 0
(Keep the existing generate_ds41 gemm_nvfp4_mma 0 0 line as it is.)
Non-blocking
⚠ Decode numbers moved with no cause: the PR body shows draft-off decode -1.0% and MTP prose decode -3.6%, ranges not overlapping, "cause not found". card_acc_at (card_slots.rs:439) is now generic over RowValues and also serves the decode kernels. Class "move, split, rename" needs ptx-scan identical for the F32 entries (q38_card_sum_shared_add, ds41_ffn_card_acc_10). Please show that output. If it differs, the generic change is the cause.
⚠ Tile-length coverage of live_walk!: nvfp4mma.rs:649 has five arms (1, 2, 4, 6, 8 fragments). The cases in nvfp4_native_case are (rows, slots) pairs, and I cannot tell which of them make tiles of 1-8, 17-32 and 33-48 columns. Mutant: live_rows(6) returns 32 instead of 48. Only a case with a 33-48 column tile turns red. Name the case per arm in the PR body, or add the missing one.
⚠ Same shared-stage block twice: product_stages! (nvfp4mma.rs:981) repeats the four static mut arrays and as_raw_mut_ptr calls of the gate-up kernel at nvfp4mma.rs:1495. Reusing the macro there would remove about 14 lines and 4 unsafe blocks. I did not make it a must-fix because it is a "move" class change that needs a ptx-scan check. Do it in a follow-up with that proof.
⚠ Two PIN blocks in the unsafe ratchet: unsafe-ratchet.txt:652 has two PINs that each say "2776 -> 2782 blocks, 355 -> 361 fns" for one line. Merge them into one PIN that lists both parts of the delta.
Checked
- Duplicates: 14 new items checked (
Down38,DownWin,DownRows,ProductCell,ProductOut,cells_view,scale_quad,b_pair,col_scale,live_rows,product_stages,card_sum_shared_add_at,has_native_form,all_hostless). One hit:product_stagesagainst the gate-up statics (⚠ above).cells_viewreplacesf32_vieweverywhere; no old use is left. Dryer pairs read: wide38 856/871 isDown38::rowsandDownWin::rowsover two types, with no shorter fix, so no finding. nvfp4mma 1189/1231 and q38 592/627 are paired kernel entries, whichAGENTS.mdkeeps flat. - Complexity:
check_hostless25→37 (a new BF16 block in a gate, the same shape as the F32 block),nvfp4_native_case89→96 (one more clause),CardRoute38::new18→23 (thebf16_downcondition, one owner),CardRoute38::enqueue+1 (match arm). No split suggested. - Silent failure: 6 sites followed.
.f32(WHAT)?on the Acc and tier paths refuses BF16 by name.enqueue_gemm32_bf16refuses a non-native stack by name. An overflow to infinity reaches the combine's finite check.f32_to_bf16_rnekeeps NaN (documented atcrates/gpu-vision/src/lib.rs:91).hostlessis fixed per load, so the route's row type cannot change afternew. - Kernel bounds:
live_rows(live)equals the rowsb_pairreads for every arm.col_scaleis a permutation (const-asserted) andscale_quadstays 16-byte aligned. The gate-upcontinueskips no barrier. - Tests:
bf16_eqfails on a truncating product (the PR's own mutant). Thebf16_rowslines fail on a narrowing widen. A droppedliveguard in a dead fragment is covered only if the arm coverage question above is answered. - Gates: PTX rows added with PINs. One PIN is misleading (must-fix 1). No band or tolerance moved.
- Performance: no allocation, lock or launch added per step. The BF16 route halves the card sum's read bytes (a derived claim, not a measurement). Escape catalog: no pattern matched (no shell changes).
Notes
- The timed runs name head
7a9073307db8, but the PR head isae96c1809a13. The DGX Spark gates andcargo fmt --checkdid not run on this head. A maintainer needs a card run, as the author wrote. - The
nvidia-smiline itself and the command output of the gates are not in the PR text, so I marked GPU evidence as not present.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu-gates/src/bin/shared/q38_combine.rs, crates/gpu/src/arch/qwen3moe/body.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)
|
Superseded by #914. |
DGX Spark에서 Qwen3.8 FP4-Local의 prompt 처리를 빠르게 하는 PR입니다. native NVFP4 expert GEMM이 tile마다 하는 일을 줄이고, routed down 출력을 BF16으로 두어 카드 합산이 읽는 양을 절반으로 줄입니다.
What and why
Prompt processing of Qwen3.8 FP4-Local spends most of its time in the routed experts' native NVFP4 tensor-core GEMM and in the per-layer sum of the experts' outputs. This PR cuts the work in both.
ldmatrix, and runs a whole tile's live fragments with a literal count, so the checks for unused fragments no longer run in the hot loop.gemm_nvfp4_mma_bf16entry, and the card sum (q38_card_sum_shared_add_bf16) widens each value back to F32 and adds the slots in the same ascending order as before, so the sum reads half the bytes. Any other load keeps F32 rows. A value outside the BF16 range becomes infinity and the existing finite check in the combine raises its named error.Greedy tokens differ from the base: the first difference is at token 40 of the first MTP code request, where the BF16 rounding of the down values changes the numeric result.
Release notes: Changed: Qwen3.8 FP4-Local prompt processing is 4.9% faster on a DGX Spark, with TTFT p95 4.6% lower.
Code shape
product_body) that the F32 and BF16 entries share.card_acc_atreads either down form, and both card-sum entries sharecard_sum_shared_add_at.live_walk!calls the onewalk!body with literal tile lengths, so the generated code has several bodies and the source has one.bf16_eqingate_gemmand twobf16_rowslines ingate_kquantare new checks. The two new entries and one changed walk entry carryPIN(2026-10-28)rows in the PTX shape tables, and the unsafe ratchet is raised for them with its PIN lines. Thesm_86andsm_121rows of the BF16 entries copy their F32 sibling's values because I measured no card of those classes.cargo clippy -p bloomery-gpu-gates --all-targets -- -D warningsis clean on this head. I did not runcargo fmt --checkon this head.Duplication found or removed (
path:line), or "none": none.What I ran
Timed runs use one DGX Spark,
bloomery-servewith--parallel 1 --ctx-size 16896, andnvidia/Qwen3.8-Flash-Next-FP4-Localat revisionb9ce18a6887e18c089fdea8509a33e63429a3300. The base is upstream51ed64b09a06124de61e3ebfb5cd03b8334a2fffand the head is7a9073307db854c2cfc4537a40f8d151ff85f87d. A request is a 4096-token prompt with 128 generated tokens at temperature 0, on eight prompt windows of the code corpus (and of the prose corpus for the prose arm). Each side has three recorded rounds after one discarded lead-in round, and the sides alternate base, head, head, base, base, head. There are three arms: draft off on the code prompt, and the checkpoint's own MTP layers on the code and the prose prompts. Prefill and decode are the server's timings and TTFT is the client's.The base is built the same way in its own checkout.
Each cell is the median of three rounds with its range in parentheses.
Prefill is 4.9% higher on all three arms (2198.9 to 2305.7, 2092.5 to 2195.2 and 2144.5 to 2248.9 tok/s) and TTFT p95 is 4.6% lower; the sample ranges do not overlap.
MTP decode is 4.3% higher on the code prompt and 3.6% lower on the prose prompt. Draft-off decode is 1.0% lower with ranges that do not overlap; I have not found the cause.
Checks on the code of this branch:
cargo clippy -p bloomery-gpu-gates --all-targets -- -D warnings: exit 0 on this head.just gate-gpu-gemm --case <case>run as its two steps,cargo oxide build --arch sm_120a -- -p bloomery-gpu-gates --features gpu --release --bin gate_gemmandbash tools/gpu-gate.sh gate_gemm --case <case>:nvfp4_native43 PASS lines,nvfp4_gate_up9 PASS lines, and thenvfp4_swiglucase matched no lines.crates/patch (the last rebase onto upstream changed only the unsafe ratchet and PTX shape tables),arch=sm_121a:gate_gemm --case nvfp4_nativePASS=43 FAIL=0 andgate_kquantq38_card_hostlessPASS=4 FAIL=0. A mutant that replaces the round-to-nearest-even product with truncation fails 16bf16_eqlines ofnvfp4_native(PASS=27), and a mutant of the widening fails 2 of the 4q38_card_hostlesslines.Not run on this head: the DGX Spark gates,
cargo fmt --check, the workspace tests andcontrib-check. The change touchescrates/gpu, so a maintainer needs to run the GPU gates on a card.Hardware
Timed runs and the DGX Spark gates ran on:
nvidia-smireportsDriver Version: 595.84andCUDA Version: 13.3)Gate runs on this head used an RTX 5090:
gate_gemmon this head;nvidia-smireportsDriver Version: 595.99.02andCUDA Version: 13.2)AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.