Repository navigation
gpu: an NVFP4 run of several tokens dots each selected expert's rows for all its slots in one warp - #808
Conversation
…for all its slots in one warp
There was a problem hiding this comment.
Verdict: CLEAN: No behavior bug or proven quality defect survived the bounds, ownership and numeric checks.
Non-blocking
⚠ Complete the geometry evidence: crates/gpu/src/mxfp4_sel.rs:1664.
For an expert selected d times with R output rows, dR dot warps become R warps executing d dots serially. This is the occupancy/geometry class in AGENTS.md.
Supply the register/shared-memory counts and occupancy derivation, both timed commit hashes, the checkpoint filename, and exact A/B commands with output. These make the reported gain reproducible before it becomes a baseline.
Optimization headroom
- D. More at once: crates/gpu/src/mxfp4_sel.rs:1676. Each matching slot calls
lane_partials::<1>and traverses the weights again. Reuselane_partials::<8>with its existing mask and column strides within an eight-slot tile. Fordmatches in that tile,Kweights per row andmtokens per step, this removes(d−1)K/(2m)source-level code-plane load bytes per expert row per token [derived], plus repeated scale loads and decoding. Cache effects determine the memory-traffic saving.
Checked
Duplicates: 4 new functions/constants checked; no duplicate owner found. Existing dot, activation and fault owners are reused. Dryer reported 0 pairs.
Complexity: crapper flagged no changed function.
Silent failure: 2 vector-view exit sites followed; host alignment and shape checks prevent them. Invalid ids reach the token reader as a named fault.
Tests: static mutation analysis finds assertions fail for a wrong gate column (1435), wrong down column (1683), skipped CardLeg down (1179), and removed zero-slot check (1905).
Gates: no tolerance moved; new PTX entries pin zero spills/local bytes; the unsafe increase has PIN(2026-10-25) and its reason.
Adversarial: repeated ids across 32-slot boundaries retain one writer; tail lanes are guarded; invalid ids and non-finite gate/up sums fault. Zero rows/slots are rejected before launch.
Escape catalog: C1–C4 do not match.
Notes
Static review only; no GPU build or gate was run here.
Dryer did not scan gpu-gates; its changed constructors were checked manually.
The PR includes GB10 gate output but lacks both commit hashes required for complete GPU evidence.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_nvfp4.rs, crates/gpu/src/card_leg.rs, crates/gpu/src/mxfp4_sel.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. |
MTP 검증 단계에서 한 expert를 고른 여러 slot의 NVFP4 행 dot을 첫 slot의 warp 하나에서 차례로 계산하게 해, GB10에서 draft를 켠 디코드 속도를 높이는 속도 PR입니다.
What and why
An MTP verify step runs the model on two to four tokens at once. Their routes often name the same expert more than once, and the NVFP4 selected-expert kernels gave every slot its own warp that read that expert's weight rows again. A route trace of a 128-token code generation shows how often this happens: the share of selected experts that another row of the same step already selected is 0.183 for 2 rows, 0.275 for 3 rows and 0.335 for 4 rows.
This PR adds two kernel entries to
crates/gpu/src/mxfp4_sel.rs,nvfp4_gate_up_sel_colsandnvfp4_gemv_sel32_cols. When a run holds more than one token (n_slots > slots_per_col), the warp of the first slot that names an expert computes that expert's rows for every slot that names it, one slot's dot after the other. The warps of the later slots end before they read any weight, so an expert repeateddtimes usesRdot warps instead ofdR(Rrows per expert) with the same launch count. A slot's result is bit for bit what the one-token entry writes for it. Decode with one token still uses the existing entries.names_beforeanswers, for a whole warp, whether an earlier slot of the run chose the same expert. The other slots of an expert are found withwarp::ballot, and the row dots go through the sharedlane_partials.Nvfp4Downgains aslots_per_colfield, which the caller supplies as data (the number of routes one token uses).enqueue_gate_upandenqueue_downpick the_colsentries whenn_slots > slots_per_col. Aslots_per_colof zero is refused with a named error.crates/gpu/src/card_leg.rssupplies the field, and the wide testhw_the_leg_writes_each_slots_one_token_rows_at_any_mgains a case for the NVFP4 stack (WIDE_PLANES).crates/gpu-gates/src/bin/gate_nvfp4.rssupplies the field in its threeNvfp4Downvalues.The kernel itself saves little time. In a verify profile the two kernels together gain about 0.37 ms per step, since the GB10's L2 cache already served most repeated reads. Most of the end-to-end gain on code looks like it comes from the draft width chooser: it picks a width from measured step times, and the cheaper verify steps moved it toward deeper drafts. On code, the time per draft window fell from 53.60 ms to 53.14 ms while the tokens emitted per window rose from 2.831 to 2.915.
Release notes: Changed: draft verification of NVFP4 checkpoints computes all slots of a selected expert in one warp, which speeds up decode with the draft on a GB10.
Code shape
act::apply_checked) and the fault sink are the existing owners. The new entries add only the first-slot check and the slot scan.slots_per_colcomes from the caller as data. No model name or per-model branch was added to a common owner.fromargument ofnames_beforewas always 0 and is removed.slots_per_colof zero is a named error, and an invalid expert id faults as it does in the existing entries.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.cargo clippyended with exit 0 on this head. I did not record a separatecargo fmtresult.Duplication found or removed (
path:line), or "none":crates/gpu/src/mxfp4_sel.rs:1368against:1253and:552, and:1615against:1515and:1368. These share only the entry head (thread row, id read, fault sink). The body of each new entry is the first-slot check and the slot scan, and the dots use the sharedlane_partials. Folding the heads into one device function would change the PTX of the existing entries.What I ran
GPU Evidence
Timed runs and the model gate ran on one DGX Spark. Its card and driver:
The NVFP4 checkpoint gate on that card, on this head:
In the same gate the last argmax of one pass and of one ubatch equals the reference (11751), and the argmax at position 3000 after 3000 ids equals the reference (423).
Other checks:
cargo checkpasses, and the three library tests pass 3/3 (the wide test with the NVFP4 stack, the selected-expert arms and the refusal).just gate-gpu-nvfp4passes with routed_gate_up bits 3200/3200 and routed_down bits 12800/12800. These ran on earlier commits of this branch and were not repeated on the head.generate_ds41entries pinned.ptx-compareof main against the branch reports added 2, removed none, changed none.FAIL-first, each against the wide test or the refusal test:
hits = 0) fails the wide test with "rows are all zero".slots_per_colof zero (if falsein place of the check) fails the refusal test.Speed
The timed model is the FP4-Local checkpoint with the Q8_0 MTP draft, greedy decoding, three rounds over eight windows of each corpus, base and head built from their own trees. Each cell is the median of three rounds. Greedy output is identical on every request. The smallest effect the run can resolve is 3.698% for code-fn decode and 1.804% for prose-en decode.
code-fn decode +4.233% (resolved above 3.698%); prose-en decode +1.335% (below the 1.804% the run can resolve, not resolved)
Only the code-fn decode gain is resolved. The other rows are not resolved, so they are not evidence of an effect or of none.
Reproduction
The second gate needs the NVFP4 checkpoint and the reference sets. For the timing, serve the FP4-Local checkpoint with the Q8_0 MTP draft from upstream main and from this branch, and send the same greedy requests over the same corpus windows, alternating the two trees.
Hardware
One DGX Spark (GB10, driver 595.84, CUDA 13.3 toolchain) for the timed runs and the model gate; an RTX 5090 machine for the build and the NVFP4 unit gate. This section lists only the card and driver lines saved with the runs.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.