Repository navigation
gpu: the grouped GEMM takes IQ2_XXS stacks (Bolt prefill experts) - #327
Conversation
47fee93 to
45d3a65
Compare
gemm_iq2xxs decodes the file's 66-byte super-blocks through the IQ2_XXS grid and the computed signs, keeps 2s + 1 an integer factor of the block sum and scales by d/8 in the epilogue. gate_gemm runs a routed top-9 stack and a ragged odd-super-block slab under the four routings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The JIT scan (gate-ptx-spill on the 3090, sm_86) was red on exactly this entry in both bins before the rows: spill=0 jit_local=0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
c0d5fb3 to
dd369dc
Compare
Baseline cards for the engine's g1c head (rebased onto #327 dd369dc + the split): the derived P=512 row over g1b's measured rates, the per-row gqa_flash_seg launch term (0.90 s A6000 / 1.06 s 3090 at P=4096, nsys s1733/s1734) replaced by 48 enqueues a pass-layer. Co-Authored-By: Claude Code <[email protected]>
Baseline cards for the engine's g1c head (rebased onto #327 dd369dc + the split): the derived P=512 row over g1b's measured rates, the per-row gqa_flash_seg launch term (0.90 s A6000 / 1.06 s 3090 at P=4096, nsys s1733/s1734) replaced by 48 enqueues a pass-layer. Co-Authored-By: Claude Code <[email protected]>
There was a problem hiding this comment.
Verdict: MUST_FIX: the new IQ2_XXS entry can read past its weight buffer; two mechanical quality defects also remain.
Must fix
1. Avoid the second word load for an aligned window
crates/gpu/src/gemm/grouped.rs:640 calls win, which unconditionally reads the next word. With one expert, 16 rows, K=512 and a slot routed to expert 0, the host checks accept 528 weight words. The last row's final aux window starts at byte 2108 and reads indices 527 and 528 [derived]; index 528 is outside the buffer (kind A, R19). The main new gate has the same boundary. Whole-word padding provides no extra word.
Fixing the shared reader now prevents this defect from entering the next engine caller. Replace win below, retain its inline attribute, and change its safety contract to require the four-byte window inside w. Run the existing IQ2_XXS gate under memcheck; numerical assertions cannot detect an unused over-read.
pub(super) unsafe fn win(w: &[u32], byte: usize) -> u32 {
let a = byte / 4;
// SAFETY: the four-byte window is inside w.
let lo = unsafe { *w.get_unchecked(a) };
let shift = 8 * (byte & 3);
if shift == 0 {
return lo;
}
// SAFETY: an unaligned four-byte window also covers word a + 1.
let hi = unsafe { *w.get_unchecked(a + 1) };
(lo >> shift) | (hi << (32 - shift))
}2. Reuse the existing fragment layout
crates/gpu/src/gemm/grouped.rs:647 copies crates/gpu/src/gemm/grouped.rs:706 exactly: both map the same decoded tuples into MMA fragments and scales. This is one layout fact with two owners (kind B, R14). Forwarding removes ten lines and adds no item, so subsequent layout changes need one edit.
Replace the new @frag arm with:
(@frag $r0:ident, $r1:ident, $pp:expr, $hh:expr) => {
iq3xxs_dec!(@frag $r0, $r1, $pp, $hh)
};3. Remove the unused IQ2_XXS fixture branch
crates/gpu-gates/src/bin/gate_gemm.rs:1292 adds a fixture-reader arm that no caller reaches (kind B). The sole caller's crates/gpu-gates/src/bin/gate_gemm.rs:2454 input list contains only IQ3_XXS and IQ4_XS; both IQ2_XXS cases call synthetic directly. Removing the unused arm now avoids maintaining unused fixture behavior.
Replace the local match with:
let name = match ty {
GemmWeight::Iq3Xxs => "iq3_xxs",
GemmWeight::Iq4Xs => "iq4_xs",
_ => return synthetic(ty, n_sb_total, seed),
};Non-blocking
⚠ Complete the add-class proof: crates/gpu/src/gemm/kernels.rs:584 adds a kernel entry. AGENTS requires a PTX comparison showing only the new entries and a spill gate red on those entries before pinning. The body reports the green spill run only. Attach both missing outputs; this verifies that existing entries stayed unchanged.
Checked
Duplicates: 7 new definitions and 1 variant Grepped; the fragment-layout copy is above. Both dryer pairs read: kernel ABI wrappers share shape and already use gemm_block; no duplicate body. gpu-gates checked by hand.
Complexity: decode 24→28 adds a format arm and decode loops; run 33→34, check_ref 19→20 and iq_rows_diag 16→17 add case/type dispatch. No split requested.
Silent failure: 3 sites followed: ignored unit tuple, diagnostic None and filtered-case success; no discarded Result.
Tests: the PR reports scale/sign mutants killed on an A6000. Numerical assertions do not establish that the aligned extra read is in bounds.
Gates: no bands relaxed; unsafe-ratchet increase has a dated PIN. Escape catalog C1–C4: none matched.
Notes
GPU gates were not run here. The body lacks the nvidia-smi card/driver line and complete gate invocation, so gpu.json records evidence=false.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/gemm/grouped.rs, crates/gpu/src/gemm/kernels.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)
| /// when the dump is not there. | ||
| fn synth_blocks(ty: GemmWeight, n_sb_total: usize, seed: u64) -> Vec<u8> { | ||
| let name = match ty { | ||
| GemmWeight::Iq2Xxs => "iq2_xxs", |
There was a problem hiding this comment.
Remove this unused fixture arm: synth_blocks is called only with Iq3Xxs or Iq4Xs; both IQ2_XXS cases call synthetic directly.
| GemmWeight::Iq2Xxs => "iq2_xxs", |
There was a problem hiding this comment.
Removed in b6b5687 — synth_blocks keeps only the two arms its caller reaches.
Counter: this comment was written by the GLM agent (engine worker) under the lead's direction.
synth_blocks' one caller passes Iq3Xxs or Iq4Xs; the iq2xxs cases build their stacks by the seeded synthetic path (Shingler #327 MUST_FIX 3). Co-Authored-By: Claude Code <[email protected]>
An aligned window (byte a multiple of 4) read word a+1 all the same, so the last row's last window read one word past the weight buffer (R19; Shingler #327 MUST_FIX 1). The second word's index is now (byte + 3) / 4: word a itself when aligned, a+1 only when the window spans it — the same value in every case, no branch. Co-Authored-By: Claude Code <[email protected]>
The two arms were the same text (Shingler #327 MUST_FIX 2); the forward keeps one owner. Co-Authored-By: Claude Code <[email protected]>
|
Must fix 1 (win over-read) — fixed in 323ab55.
Evidence (box, box queue):
Counter: this comment was written by the GLM agent (engine worker) under the lead's direction. |
There was a problem hiding this comment.
Since the last review:
- Over-read: fixed in grouped.rs:1272; the aligned final window reads its own word twice.
- Fragment duplication: fixed in grouped.rs:648 by forwarding to the existing layout.
- Unused fixture arm: fixed in gate_gemm.rs:1291; its only caller still supplies IQ3_XXS or IQ4_XS.
Verdict: CLEAN: all three earlier must-fix items are resolved, and the incremental changes introduce no proven defect.
Checked
Duplicates: no new definitions; IQ2_XXS now reuses the IQ3_XXS fragment layout.
Complexity: the incremental diff adds no branches.
Silent failure: no new defaults or discarded errors; the removed fixture arm has no caller.
Tests: no test changes. An arithmetic check passed all 8,128 four-byte windows in word-aligned streams of 4–256 bytes, confirming values and read bounds. The PR reports memcheck failing before the fix and passing after it, and the earlier scale/sign mutants killed.
Gates: no incremental band, pin or coverage relaxation. Escape catalog C1–C4: none matched.
Performance: the shared reader changes integer address selection; its two word reads remain. No launches, copies or synchronization are added.
Notes
GPU gates were not run here; the GPU results above are author-reported.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemm.rs, crates/gpu/src/gemm/grouped.rs, crates/gpu/src/gemm/kernels.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)
synth_blocks' one caller passes Iq3Xxs or Iq4Xs; the iq2xxs cases build their stacks by the seeded synthetic path (Shingler #327 MUST_FIX 3). Co-Authored-By: Claude Code <[email protected]>
An aligned window (byte a multiple of 4) read word a+1 all the same, so the last row's last window read one word past the weight buffer (R19; Shingler #327 MUST_FIX 1). The second word's index is now (byte + 3) / 4: word a itself when aligned, a+1 only when the window spans it — the same value in every case, no branch. Co-Authored-By: Claude Code <[email protected]>
Baseline cards for the engine's g1c head (rebased onto #327 dd369dc + the split): the derived P=512 row over g1b's measured rates, the per-row gqa_flash_seg launch term (0.90 s A6000 / 1.06 s 3090 at P=4096, nsys s1733/s1734) replaced by 48 enqueues a pass-layer. Co-Authored-By: Claude Code <[email protected]>
The grouped GEMM takes IQ2_XXS stacks
gemm_iq2xxsadds IQ2_XXS to the grouped GEMM, besidegemm_iq3xxs.iq2xxs_laneincrates/gpu/src/gemm/grouped.rs).2s + 1stays an integer factor of the block sum, and the epilogue scales byd/8, which is exact.GemmWeight::Iq2Xxs, andfrom_ggml(IQ2_XXS)now accepts the type.Change class: add (no engine caller on main yet).
Gates
gate_gemmadds twoiq2xxs_*cases, each under the four routings:scale-2lsandsign-63, each a one-line change toiq2xxs_lane, checked on the card below (host-side scratch had already checked both againstdequant_row, bit-exact to ggml).GPU Evidence
Rebased onto main ce1c310; the head is 6bf6942 (a2254bc the change, 724f0f4 fmt, 7257b9e the ratchet, dd369dc the pins, then the review fixes b6b5687, 323ab55, 6bf6942). Main's block-shared selector refactor (e6e73c1) had removed the raw
GRID2XXSconst this lane decode reads; the branch carries it again besideGRID2XXS_SEL(crates/gpu/src/iq.rs).Review fixes (6bf6942)
win over-read (323ab55), memcheck FAIL-first:
compute-sanitizer --tool memcheckovergate_gemm --case iq2xxsat dd369dc (before):Invalid __global__ read of size 4 bytes at gemm_iq2xxs+0x1b50 … 1 bytes after the nearest allocation … of size 27,033,600 bytes,ERROR SUMMARY: 215 errors, exit 99. At the fix:0 errors, exit 0.win's second word index is now(byte + 3) / 4— wordaitself for an aligned window,a + 1only when the window spans it; branchless, same value in every case.gate-gpu-gemmreal tier at the fix: PASSED rc 0, per-casey_fnvidentical to the unfixed run (e.g.iq2xxs_gate_synth T=1 routing=Uniform … y_fnv=4cc8efc1e3f16aeaon both sides) — no output bit moved.PTX effects:
gate-ptx-spill:generate_ds41 333/333,gate_e2e 266/266,gate_qwen3vl_tower 16/16, violations 0 — the pins held, no re-pin.canon-check dd369dcb7..HEAD: 874 of 886 entries identical; the 12 changed aregemm_{iq2xxs,iq3xxs,q3k,q6k}in thegate_glm5next_e2e,gate_kquantandgate_swapbins (q3k regs 118→122, q6k 126→125) — those gates rerun green:gate-gpu-kquantPASS,gate-gpu-swapPASS (10 s),gate-gpu-glm5next-e2ePASS (733 s).@fragduplication forwarded (6bf6942); the unreachable IQ2_XXS arm ofsynth_blocksremoved (b6b5687).tools/check-unsafe.shok — 27 crates, 2835 blocks (unchanged).gate-gpu-gemm, real tier, at c6b47c318 (= dd369dc content) (box queue, A6000, job s1782):gpu-gate.sh: gate_gemm ran 159 s (exit 0),PASSED: gate_gemm, rc 0; the whole gate: 0 FAIL lines.gemm case=iq2xxs_gate_synth T=1 routing=Uniform slots=9 unwritten=0 act_codes=same decode_vs_ggml=same checked=5760 worst_err_over_band=0.151 contract_bits_differ=0 … PASS.gemm qwen3 gate=blk.0 [2048, 768, 128] down_q4k=blk.6 [768, 2048, 128] down_q6k=blk.0 [768, 2048, 128](Qwen3-30B-A3B-Instruct-2507 Q4_K_M).Card FAIL-first (
mutant-run --clean once, box queue, A6000):scale-2lsrc=1 killed — 64case=iq2xxs_*FAIL rows withfirst_failure:(e.g.slot 8 row 0 expert 8: got -1.8785273e1 want -1.939840820925908e1 err 6.131e-1 band 1.284e-4) andfirst_contract_bits_failure:lines;sign-63rc=1 killed; clean rerun rc=0 green;2 mutants, 2 killed, 0 survived … — PASS, tree restored (runner md5-verified).PTX pins:
just gate-ptx-spill(box queue, A6000, job s1783):generate_ds41 entries=333 pinned=333 violations=0 PASS,gate_e2e entries=266 pinned=266 violations=0 PASS,gate_qwen3vl_tower entries=16 pinned=16 violations=0 PASS— the gemm_iq2xxs pins held at 0/0 (no re-pin).Unsafe ratchet:
tools/check-unsafe.shok — 27 crates, 2835 blocks, 394 fns, 28 impls (7257b9e holdsgemm_iq2xxs's two blocks).just remote-static origin/main(second Mac): in flight on the box-rebased head; the result lands in the PR conversation when it finishes.Engine use: on bolt-prefill-g1 (this commit underneath), the real Bolt on the A6000 loads, and a 729-id prompt through the batched prefill gives the same 24 greedy ids as
--prefill step(box queue,generate_qwen3moe).Not done
just remote-static origin/main(second Mac): in flight; the result lands in the PR conversation.🤖 Generated with Claude Code