Repository navigation
Conversation
nemotron_h_moe::PASS_ROWS and GpuModel<Body>::prefill / prefill_with, the surface the batched pass fills in; today each pass runs its ids as steps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A pass embeds its ids, runs each Mamba-2 layer as one scan over its rows, appends the attention K/V rows and runs the group-16 flash in runs of MAX_PASS_ROWS, routes the MoE rows in two launches and runs the routed and shared experts as one _sel launch over the pass's slots. Projections run their family's multi-column gemv in runs of 8 rows. Each MoE layer's results are the pass's last row's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Several ids run GpuModel::prefill, one id a step, the Nano's split; the serve gate's Bolt head feed is the same call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
--prefill auto (the default) and gemm run NemotronHMoeModel::prefill, pass and step the step chain, the nemotron_h paths. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The latent pair and the attention projections run gemm32 on the rows' q8 blocks of 32 over the pass's one-expert table, filled once a pass; up to 8 rows they keep the multi-column gemv. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each NVFP4 projection gets a Q8_0 twin at load (its rows decoded times the tensor scale, coded per 32 as quantize_row_q8_0), which a pass past 8 rows runs as one gemm32 on the rows' q8 blocks of 32. The routed and shared experts take the grouped GEMM where the build has an IQ2_XXS entry, else their _sel launches. Co-Authored-By: Claude Opus 5.5 <[email protected]>
prefill_near_mainlines and prefill_then_step_near_mainlines, each a fixture-oracle clause and a real-tier one: every prompt through prefill, alone and before its last id as a step, keeps the cosine floor against mainline's logits, the step path's distance printed beside. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…triage; cargo fmt Co-Authored-By: Claude Opus 5.5 <[email protected]>
A pass past 8 rows runs an NVFP4 site as a GEMM over its Q8_0 twin when the twins were derived, otherwise as the multi-column gemv runs. The twins are planned only when the card's room after the body's load holds every twin and a 2 GiB margin, so a card the twins do not fit (the 3090's 24 GB) loads where main loads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Code <[email protected]>
… refusals, the unsafe pin The kernel entry landed one commit below (WIP finished on the Mac). This adds its gate on the g32 family's model: g32_nvfp4_dense over Bolt's two NVFP4 projections' shapes (ssm_in 18560x4096, ssm_out 4096x8192) and 128 rows at both K for 1, 9, 64 and 448 columns, and g32_nvfp4_routed under uniform and same-expert routings with an id past the stack (refused slots NaN, the rest the clean run's bits); every output inside gamma(2K/32 + 4) of the f64 reference (ggml's dequant_row x scale against the dequantized q8 column) and bit for bit gemm32::dot32_nv, the new one-owner host transcription of the module doc's contract; a rerun and a graph replay bit-identical. The reference check generalizes to a dot closure (check's four call sites pass row_dot; the band's rounding count moves to the caller). g32_refuse gains the four NVFP4 refusals (K not a multiple of 64, a short qs, a short e, a non-finite scale). unsafe-ratchet: gpu 1863 -> 1865 blocks, the nvfp4p relays of w32! (each with its SAFETY line). Clean run: gate_gemm --case nvfp4 PASS on the 3090 (all 29 case lines, band worst 0.022, bits 0, refused [5, 9]). Co-Authored-By: Claude Code <[email protected]>
The add-class proof's last piece: just gate-ptx-spill was red on exactly the two unpinned rows (measured spill=0 jit_local=0 on both, the family's every other entry all zeroes too) and is green over the pinned table on a rerun — generate_ds41 333/333, gate_e2e 266/266, gate_qwen3vl_tower 16/16, violations 0. Co-Authored-By: Claude Code <[email protected]>
A pass past 8 rows runs every NVFP4 site (ssm_in, ssm_out) as the 32-value GEMM over its resident NVFP4 planes (Gemm32Weight::Nvfp4Planes, #342), the twin Q8_0 derivation dropped: no card derives twins at load, and the 8-column gemv runs the sites were falling back to are half the P=4096 prefill (nsys s1927). The GEMM arm no longer reads the card's room. Co-Authored-By: Claude Code <[email protected]>
The pass's whole row set in one enqueue_split (the group of 16 as two group-of-eight sub-group launches), in place of the MAX_PASS_ROWS loop of plain group-16 passes. The sub-group scratch (rows × n_kv × GROUP × HEAD f32 ×2) joins PassBufs at load and resident_bytes; Body loads FlashGqaPrefill once beside the trunk's flash. Co-Authored-By: Claude Code <[email protected]>
…and T=8 staging
mamba2_conv_rows, one fully parallel launch, writes every token's conv
outputs (conv_out, the step's exact taps and sum order, now one
(token, head)'s σ and dA into Mamba2PassScratch, so no block of the scan
recomputes its group's channels again. mamba2_steps reads the scratch and
stages STAGE_T = 8 tokens double-buffered — 2 · 8 · 274 · 4 = 17 536 B of
static shared memory, five blocks an SM at sm_86's 100 KB — so a token is
a barrier only each eighth; the staging loops are not unrolled (the
unrolled index arithmetic pushed the scan to the register cap, measured by
ptx-scan; regs 96 as pinned). The scan's per-token operations, their order,
the fault rule and the single state store are unchanged, so the pass stays
bit for bit u steps. enqueue_steps is conv_rows, steps, ring_tail and, with
a gain, norm_rows: three or four launches. StepsArgs gains the scratch; a u
past its max_u and a scratch of another shape are refused by name, read
before the buffer lengths so a short rows cannot mask them. The Nano
prefill owns its scratch at load; the Bolt prefill gets the minimal wiring
the engine's cherry-pick supersedes. gate_mamba2 stages the boundary
lengths u ∈ {T−1, T, T+1, 2T+3}, pins the captured pass at four nodes and
the two scratch refusals; ptx-shapes.tsv and unsafe-ratchet.txt pin
mamba2_conv_rows.
Co-Authored-By: Claude Code <[email protected]>
mamba2_steps read z from global memory once per (token, channel), after the shuffle chain, and 89 registers with 17.5 KB of stage capped the SM at five blocks: a 512-block grid ran in 1.25 waves. z now stages with B, C, x, sigma and dA; STAGE_T 8 -> 5 brings the stage to 11.6 KB; launch_bounds(128, 7) with a register diet (one state-row index a warp, 32-bit channel predicates and stage walk) gives 72 registers, spill 0, seven blocks an SM: one wave on 84 SMs. Every output bit is unchanged (gate_mamba2 bit for bit; the Bolt e2e prefill and step lines byte-equal on both cards). Also documents the sigma/dA load's unsafe block, which clippy refused. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…our channels Both scan sites (the prompt pass and the staged step) ran the xor butterfly per channel — five shuffles a channel, twenty a warp. The four channels now share one tree: two shuffle-downs at 16 and 8 halve each channel's partials, a gather puts channel c's halves on lanes c*8 .. c*8+7, and the xor 4, 2, 1 quarter sums each group, so every lane of group c holds channel c's total and the group's first lane stores its y (fifteen shuffles a warp). The pairing tree is the xor butterfly's, value for value — proven bit-equal on 10^6 random and adversarial accumulator sets in exact f32 — so every y, the state and the ring keep their bits; the collectives now sit outside the channels' liveness guards, and the y phase re-reads z's staged value in its own unsafe block (ratchet 1878 -> 1879). Co-Authored-By: Claude Code <[email protected]>
The relu_sqr elem pass over each up buffer (four sites of the prompt pass, the step path's slots and shared expert) is folded into the quantizer that read the buffer next: q3k_quantize_q8_1_relu_sqr applies elem's relu_sqr rule to each value inside its load, through q8_1_quant_block_relu_sqr, and the f32 activation buffers between the two (PassBufs' act/sh_act, MoeScratch's act/sh_act) are gone. The plain entries keep their signatures (an underscore core holds the launcher both share); bit for bit, the squared ReLU rule is the elem kernel's, value for value, and the q8_1 form of a transformed value is the form the buffer pass produced. Co-Authored-By: Claude Code <[email protected]>
The relu_sqr-fold quantizer's entry in generate_ds41 and gate_e2e, pinned from the scan the fold landed on (spill 0, jit_local 0, both bins; the tower bin gains no entry). Co-Authored-By: Claude Code <[email protected]>
The batch score launch of each router instance (nemotron's five, glm5next, mimo2 through the shared instance macro, deepseek41's own copy) computed its scores as per-(token, expert) f32 gemvs, eight a tile, re-reading the router rows once a token tile and the activations once a row tile. The wide path now runs them all as one F32 tile GEMM — the common f32_tile_gemm, whose contract is bit for bit f32_gemv's, and whose lane walk (f32_lane_partials) and warp tree (gemv_lane_sums) are the same code the score bodies ran — followed by the score's scalar over the logits in place (elem's sigmoid_rows, softplus_rows for deepseek41's sqrt_softplus); the pick launch is unchanged. The five scores entries, scores_body and deepseek41's inline copy are gone; the instances' launch plumbing carries the gpu and wide handles the tile call needs. Co-Authored-By: Claude Code <[email protected]>
The thirteen *_scores entries the scans no longer print (eight of generate_ds41, five of gate_e2e) leave the table, and elem's sigmoid_rows and softplus_rows — the score scalars the wide path writes over the tile GEMM's logits — pin at 0/0 in both bins. Co-Authored-By: Claude Code <[email protected]>
…ds the nvfp4p short planes truncated The relu_sqr case pins the fold's contract (step 2's coverage gap, whose square-drop mutant survived every e2e floor): enqueue_quantize_gemm_relu_sqr bit for bit enqueue_relu_sqr then enqueue_quantize_gemm at K 768 and 2048 for 1, 8, 64 and 4096 columns, the scales and code sums the host transcription gives from the transformed rows, the transform itself each value's f32 bits, and a NaN input the named QuantColumn fault with its block refused. FAIL-first: relu-sqr-square (r*r -> r) reds the case's planes and host checks, clean green (mutant-run, 1 killed). The gemm_nvfp4p short-plane refusals (e61be01) upload their leading columns instead of full data at a shrunk cols, so the refusal tested is the gemm's, not upload's length check (it exited 1 before the clause: data.len() 1536 != rows*cols = 32*47). Co-Authored-By: Claude Code <[email protected]>
Five #[kernel] entries (q3k_quantize_q8_1, its relu_sqr fold, q6k_gemv, q3k_gemv, q5_quantize_q8) were missing the too_many_arguments allow every other flat kernel entry in these files carries: the launch ABI is flat by cuda_module's contract (rust-quality R8, the reason line names it). The host-side enqueue wrappers left warning in elem.rs and q5.rs are the argument-struct round's. Co-Authored-By: Claude Code <[email protected]>
head_dim 72 (576 as 8 heads of one group) is the geometry where a head's channels are not a multiple of the staging block: the pass's staged z and x hold masked channels, and channel_live is load-bearing at the reads (the y and state stores stay in bounds only because of it). The gate's machinery (weights, tokens, Dev, both runs) now takes a Shape derived from the Geom; every existing case runs at MAIN (= GEOM, bits unchanged) and one new clause runs a warmed pass of 2*STAGE_T + 3 rows against as many steps, bit for bit. FAIL-first: hd-round16.patch (channel_live's bound rounded down to the staging block, < head_dim & !15) is behaviour-preserving at head_dim 80 and leaves y holding the poison at channels 64..71 of every head here. Co-Authored-By: Claude Code <[email protected]>
…hannel xor butterfly The transpose-reduce (fc114f6) carried local depot into both mamba2_step and mamba2_steps (gate_mamba2's shape clause: ld_local=1 st_local=8 each; the tsv pins 0/0). Every kernel keeps its contract of no local memory: both y-reductions return to the per-channel five-shuffle xor butterfly, bit for bit the same pairing tree, and the unsafe ratchet goes back to 1878 with fc114f6's pin line. Co-Authored-By: Claude Code <[email protected]>
7c69607 dropped the transpose-reduce from both kernels to close the local-depot red it carried. The lead's call (11:4x): the prefill pass is where the shared reduction tree pays, the decode step is not — so this restores fc114f6's mamba2_steps (prefill) alone; mamba2_step (decode) keeps the per-channel five-shuffle xor butterfly of 7c69607, bit for bit the same pairing tree. mamba2_steps's PTX-level local use is pinned, not hidden: gate_mamba2's shape clause holds it to exactly depot with ld_local 1, st_local 8 (PIN(2026-10-17); FAIL-first: the strict no-local-depot clause reds on the restored tree before the exception) while the other three entries stay at zero. The JIT columns ptxas measures stay 0/0 for both kernels (the scan on gate_e2e: mamba2_steps spill 0, jit_local 0; mamba2_step 0/0), so tools/ref/ptx-shapes.tsv is untouched — the regression nvf4occ measured (jit_local 16) was the decode kernel's alone, and the revert closed it. The gate's head_dim 72 clause is rewritten against the host twin (both the steps and a past-two-stages pass), so a defect one kernel alone carries cannot hide behind a matching one in the other — the symmetric pass-vs-steps form could. The unsafe ratchet returns to 1879 with the steps-only attribution. Co-Authored-By: Claude Code <[email protected]>
There was a problem hiding this comment.
Verdict: MUST_FIX: launch records undercount; host logic is duplicated.
Must fix
1. Count the added router launch
crates/gpu-deepseek41/src/router.rs:689 now launches GEMM, softplus and a pick per bias run. A bulk prompt reaches body/prefill.rs:2591, which counts one score launch plus picks and places. Its stats underreport one launch per served layer-batch; tools/flow/ds41_prefill.py:346 has the same omission, so --counts can still report equality. Correct both before relying on these records. In crates/gpu-deepseek41/src/body/prefill.rs:2591:
self.tally.route(i, m.set, (m.cuts.len() - full) as u64 + 3 + picks as u64)?;In tools/flow/ds41_prefill.py:
TAIL_BULK_ACTS = 7 # GEMM, score scalar, pick, places, three D2H2. Reuse the reference checker (R14)
crates/gpu-gates/src/bin/gate_gemm.rs:3477 copies crates/gpu-gates/src/bin/gate_gemm.rs:3396: both check slots, bands and bits. Reuse check_dot before the checks diverge:
fn check(
w: &Wts, mins: bool, rows: usize, a: &HostAct,
expert: &(dyn Fn(usize) -> Option<usize> + Sync),
col: &(dyn Fn(usize) -> usize + Sync), y: &[f32], slots: usize,
) -> Result<Checked, GateError> {
check_dot(w.k / 32 + 3, rows, expert, col,
&|r, c| row_dot(w, r, a, c, mins), y, slots)
}3. Share the prompt walk (R14)
crates/gpu/src/arch/nemotron_h_moe/prefill.rs:923 repeats crates/gpu/src/arch/nemotron_h/prefill.rs:463: validation, chunking and final-head selection. Share it before either walk changes. In model.rs's generic GpuModel impl:
pub(crate) fn prompt_rows(
&mut self, ids: &[u32], rows: usize, cap: usize, what: &'static str,
pass: fn(&mut B, &Gpu, &Weights, (&[u32], u32), Option<&mut Head>)
-> Result<(), GpuError>,
) -> Result<u32, GpuError> {
if ids.is_empty() || rows == 0 || rows > cap {
return Err(GpuError::shape(what, format!("empty prompt or rows {rows} outside 1..={cap}")));
}
self.check_pos(self.pos() + crate::launch_u32(what, "ids", ids.len())? - 1, what)?;
let n = ids.len().div_ceil(rows);
let mut next = None;
for (i, ids) in ids.chunks(rows).enumerate() {
let last = i + 1 == n;
next = self.run_rows(ids.len(), what, |gpu, w, body, head, pos| {
pass(body, gpu, w, (ids, pos), last.then_some(head))?;
Ok(last)
})?;
}
next.ok_or(GpuError::state(what, "the last token"))
}Replace both family methods with:
pub fn prefill_with(&mut self, ids: &[u32], rows: usize) -> Result<u32, GpuError> {
let cap = self.body(WHAT)?.prompt.rows;
self.prompt_rows(ids, rows, cap, WHAT, Body::enqueue_pass)
}4. Reuse the stack accessor (R14)
crates/gpu/src/arch/nemotron_h_moe/prefill.rs:418 copies crates/gpu/src/arch/nemotron_h_moe/moe.rs:164. Prevent divergent checks: make moe::stack pub(super); replace the new helper:
fn stack<'w>(w: &'w Weights, name: &str) -> Result<&'w DeviceTensor<u32>, GpuError> {
super::moe::stack(w, WHAT, name)
}5. Narrow the unsafe scope (R1)
crates/gpu/src/mamba2.rs:1117 wraps the function in unsafe. Isolate loads before extending it; recount unsafe:
unsafe fn conv_out(
x0: f32, x1: f32, x2: f32, cur: f32,
conv_w: &[f32], conv_b: &[f32], c: usize,
) -> f32 {
let w = 4 * c;
// SAFETY: w + 3 < conv_w.len() by the caller's contract.
let ws = unsafe { [
*conv_w.get_unchecked(w), *conv_w.get_unchecked(w + 1),
*conv_w.get_unchecked(w + 2), *conv_w.get_unchecked(w + 3),
] };
// SAFETY: c < conv_b.len() by the caller's contract.
let bias = unsafe { *conv_b.get_unchecked(c) };
let mut acc = 0.0f32;
acc += mul_rn_f32(x0, ws[0]);
acc += mul_rn_f32(x1, ws[1]);
acc += mul_rn_f32(x2, ws[2]);
acc += mul_rn_f32(cur, ws[3]);
silu(acc + bias)
}Non-blocking
⚠ GPU proof: crates/gpu/src/mamba2.rs:1508, +1 launch/Mamba layer/pass, +1/router layer/pass, −2/ReLU MoE layer/token [derived]. Attach gates, PTX resources and occupancy/fold A/B: card/driver, SHAs, model, commands and output.
Optimization headroom
- G, per-launch cost: crates/gpu/src/arch/nemotron_h_moe/prefill.rs:813, Q8_0 attention, rows > 8: quantize q/k/v's shared input once; save two launches/pass and 8 × hidden bytes/token/layer [derived].
Checked
- Duplicates: all three pairs confirmed; fixes reduce code.
- Complexity: no separate finding.
- Accounting: tally and flow paths traced.
- Tests: static inspection; CUDA gates not run.
- Gates: GPU proof remains advisory.
- Escape catalog: no match.
Card check: needs-gpu. This pull request changes crates/gpu-deepseek41/src/chain/ffn.rs, crates/gpu-deepseek41/src/chain/ffn/batch.rs, crates/gpu-deepseek41/src/router.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)
GPU Evidence — release batch #1 (fixture tier)Branch head Witness: NVIDIA GeForce RTX 3090 and NVIDIA RTX A6000, driver 615.71.09, power limits 250 W / 300 W. The 4 reds are environment, not Bolt:
The 71 items deferred to the real tier run once on the final release head (bolt-r6 + ubimpl + lintdebt + main 🤖 Generated with Claude Code |
|
Superseded by #400 (the same stack plus -ub, the lint commit and two tool fixes). Written by a bot (Claude agent) for the maintainer. |
Bolt's prompt path: NVFP4 on the card, the Mamba-2 scan, the relu_sqr fold, the common router
Supersedes #328 (this branch is that stack carried to main
753df0aea, with the NVFP4 sites moved from the host-requantized Q8_0 twin to the real NVFP4 GEMM, and the Mamba-2 prompt scan rewritten).What
4ad7c3f40…38e171e6a): a prompt runs as layer-major passes of up to 448 ids; the serve seat,gate_nemotron_serveandgenerate_qwen3moerun Bolt prompts throughprefill.5f875eb61,943a70bff,92a075c0e): one gemm32 over the rows' q8 blocks, the prompt path held to mainline (cosine floor).f610d4833…ebd61fb36):Gemm32Weight::Nvfp4Planesand its entries; the host-requantized Q8_0 twin stays only when the card's room does not hold the planes (5ffec9012);gate_gemmgains the dense and routed NVFP4-plane cases, the short-qs/short-e/NaN-scalerefusals and the unsafe pin (e380321a6,32c79abab); ptx shapes pinned at 0/0 (f639ea1c2).c22698b5a): the prefill flash's split entry.447ee18e5…25ba0f7ea): no per-token barrier — a conv pre-pass and T=8 staging; the scan stages z and holds seven blocks an SM; the y-reduction keeps one transpose-reduce across the four channels formamba2_steps(prefill,874f344adrestored by25ba0f7eawith the dated clause-7 exception), while the decodemamba2_stepkeeps the per-channel xor butterfly (2c7719e85), which ptxas holds at spill 0 / jit_local 0.d18261da8,99cc33d36,32c79abab):q3k_quantize_q8_1_relu_sqrwith the fused path bit-identical to the split planes; gate clause plus a FAIL-first mutant.77ff640aa,47a14898d): every family, with the ptx-shape rows moved with it.873018b17): the flat-argument allow with its reason on the quantize/gemv entries.Per-commit summary
Evidence so far
25ba0f7ea: boxjust checkrc 0;just mac-fmt-checkrc 0;tools/check-unsafe.shok — 28 crates, 2909 blocks, 398 fns (every pin the rebase re-derived carriesPIN(2026-10-17); gpu 1908/207 and gpu-deepseek41 385 are the measured values).gate_mamba2: clause 7's no-local-depot check holds with one dated exception (mamba2_stepsalone, the pass's transpose-reduce, 1/8 —PIN(2026-10-17)), FAIL-first from the strict clause red before the exception; the head_dim-72 clause is a host-twin comparison, steps and pass each bit-identical 13/13; thehd-round16geometry mutant KILLED on the final shape.gate_gemm: the relu_sqr clause compares the fused q8_1 planes with the split quantizer bit for bit (K 768/2048 x cols 1/8/64/4096) and refuses NaN blocks; therelu-sqr-squaremutant KILLED; the nvfp4p refusals cover a K-mismatched act and shortqs/eplanes and a NaNscale.gemm_nvfp4pandq3k_quantize_q8_1_relu_sqrpinned at spill 0 / jit_local 0; the router rows moved withf32_tile_gemmintools/ref/ptx-shapes.tsv.GPU Evidence
The lead's release batch runs on
25ba0f7eanow (~30 min); the rows follow there. Prefill and decode headline numbers land with it.🤖 Generated with Claude Code