Repository navigation
card leg: a routed NVFP4 stack runs on the card, a gate and up and down _sel pair with a scale an expert - #517
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: The NaN-clamp defect described in the PR remains reachable in the MXFP4 sibling.
Must fix
1. Reject non-finite MXFP4 sums before the clamp
crates/gpu/src/mxfp4_sel.rs:576 still sends unchecked sums into act::apply. With K=256, scale bytes 128 in both stacks, zero gate codes, and up codes 0x77 in the first four blocks and 0xff in the last four, finite input 1e38 produces opposing infinite partials and a NaN up sum. At clamp limit 7, this writes finite zero. CardLeg quantizes that zero and reports no fault. This is the remaining sibling of the defect the PR describes, covered by the fix-PR sibling rule.
Adding the guard and its overflow case now closes both FP4 paths under the same fault contract. Replace the MXFP4 kernel's lane-0 block with:
if lane == 0 {
let v = if g.is_finite() && u.is_finite() {
act::apply(act, limit, g, u)
} else {
fault.raise(FaultSite::F32Product);
f32::NAN
};
// SAFETY: row < n_slots * rows_per_expert <= h.len() by the
// launch contract; only lane 0 of the warp writes h[row].
unsafe { *h.get_unchecked_mut(row) = v };
}Exercise the MXFP4 arm with this overflow input and assert F32Product and NaN rows. Removing the guard must turn that assertion red. The new NVFP4 overflow clause does not exercise this arm.
Checked
Duplicates: 50 new items and the renamed scale reader checked. All four dryer pairs read: two module-load boilerplate pairs, independent gate-up/GEMM maps, and existing gated/relu² shape checks. No duplicate requiring extraction found.
Complexity: new routed::run 49 has load/run/judge stages; bench::routed 24 has gate-up/down stages; overflow 16 has setup/launch/check stages. CardLeg::launch 30→47 adds format dispatch; upload_rows 33→40 adds stack validation/upload; bench::run 18→19 adds one arm. Kernel bodies were checked for correctness.
Silent failure: six sites followed. Both new vector-view returns are prevented by alignment/shape checks; the division fallback, scale-count conversion and PLE first-scale selection lead to named errors. The MXFP4 clamp survivor is item 1.
Tests, static mutation review: dropping checked multiplication at kquant/sel.rs:469 or :533 fails the slot tests; removing the alignment check at mxfp4_sel.rs:1421 fails the alignment test; dropping either NVFP4 launch at card_leg.rs:592 or :664 fails the leg comparison. Removing placement.rs:1701's scale buffer or :1982's host refusal fails the placement test. Removing NVFP4 table entries or changing its down activation fails the table pins.
Gate clauses: weights.rs:1004 scale gathering, :1102 scale count and :1118 finite checks are covered by load/refusal assertions. Removing mxfp4_sel.rs:1289's finite guard fails the reported NVFP4 overflow control. Dense clauses retain their band and bit comparisons. MXFP4 coverage needs the case in item 1.
Gates: kernel-table and unsafe-count additions have dated PIN reasons; no numerical tolerance was relaxed.
Performance: new kernels retain four card-leg launches and allocate no buffers per step. Static index checks covered minimum and padded down widths and sparse expert ordering.
Escape catalog: no C1–C4 pattern matched.
Notes
CUDA gates and mutation runs were not executed during this review. The PR supplies GB10 gate results and FAIL-first controls.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_dspark_experts.rs, crates/gpu-gates/src/bin/gate_iq_sel.rs, crates/gpu-gates/src/bin/gate_kquant.rs … and carries a gate run on the author's card, which counts as verified.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Filed outside this PR: #518
…sel pair with a scale an expert An NVFP4 expert stack had no routed kernel: the card table named no entry for its gate·up or down, so a plan put such a stack nowhere. mxfp4_sel gains the NVFP4 pair beside the MXFP4 one. The gate·up reads the token's q8_1 columns (Q8Act) like the MXFP4 pair; the down reads the 32-value Q8Blocks32 form, which takes any routed width that is a multiple of 64. Both multiply each slot's sum by its expert's own f32 scale after the warp reduce, the order of the dense nvfp4_gemv, and an id past the stack raises ExpertId and leaves NaN rows. The table admits NVFP4 through card_planes_runs, a rule of its own beside card_runs, so the file-block sets of the K-quant, IQ and MXFP4 kernels do not change. The placement holds a stack's scales as a third card buffer, one f32 an expert the card holds, and refuses an NVFP4 stack with host experts by name: the host has no NVFP4 kernel. Weights reads a stack's .scale [n_expert] through tensor_scales (the one scale reader, the F8 PLE table's too) and uploads the scales of the segment's experts in plane order. CardLeg holds the stack in planes and runs the pair from the same places as the other formats. gate_nvfp4 loads a six-expert GGUF NVFP4 (type 40) stack at Qwen3.8's widths onto three card experts and checks the pair bit for bit against its host rule and within the derived band of the f64 dequant, the resident scales against the file's, and an id past the stack by name; the dense and routed clauses share one host rule. Its --bench-kernels prices both launches. The card leg's test checks the NVFP4 arms against the hand launches. Q8Blocks32Host::column reads a column's codes back, for this gate and the two that unpacked them by hand. Gate-up sums are checked before activation through one shared device function: a non-finite gate or up sum raises F32Product and writes NaN instead of being hidden by the clamp. The MXFP4 route-plan entry, K-quant selection, arena and tiles, IQ selection and the V4.1 expert entries use the same check. Their callers supply the fault sink, and V4.1 reuses the common activation math. Hardware regressions cover the finite-input overflows through the real launchers. The host's experts follow the same rule. qdot::swiglu_clamp reports a non-finite gate or up value in the same pass as the combine, and the host combine every gated expert path calls refuses it by name, where the clamp would have written a finite value. Without the clamp the value stays non-finite and the quantizer refuses it, as before. A union test feeds a Q3_K layer overflowing up sums through each host entry.
7b3182a to
2c28abd
Compare
There was a problem hiding this comment.
Since the last review: item 1 is fixed. Both MXFP4 entries use the shared finite-sum guard, and the regression requires a fault and NaN rows (mxfp4_sel.rs:1765).
Verdict: CLEAN: The earlier overflow defect is closed, and no must-fix finding survives in the revised code.
Checked
Duplicates: 17 new functions, types and constants checked. Both dryer pairs read; gate-up, GEMM and dense format tables share a match shape but select different entries. No duplicate found.
Complexity: routed::run (49), bench::routed (24) and overflow (16) retain their stages. CardLeg::launch (47) and upload_rows (45) retain format dispatch. DS41 enqueue_shadow (19), enqueue_batch_shadow_chunk (27) and enqueue_block (29) add fault-sink arguments.
Silent failure: four new test sites followed. Three discarded Results remain inside assertions requiring a named panic; the printing fallback follows an assertion requiring a captured panic. The production host caller consumes the finite flag and panics by name.
Tests, static mutation review: bypassing kquant/act.rs:60 makes the new K-quant/IQ, V4.1 and both MXFP4 overflow cases fail their fault/NaN assertions. Returning true at qdot/src/lib.rs:9631 fails the input-position test. Removing model/src/ops.rs:1640's panic fails the union refusal test. Dropping either card-leg launch fails the shared hand-result checker. Removing the alignment check still fails the adapted alignment test. The tightened IQ/K-quant clauses reject a missing F32Product fault.
Gates: no numerical band relaxed. The unsafe-count changes have dated PIN reasons. The DS41 library recipe includes the new ignored hardware test.
Adversarial checks: inactive multi-column sums remain zero; empty and padded host slices stay in bounds; NaN and both infinities reach the host refusal or device fault. Reusing linear::silu preserves the activation arithmetic.
Performance: GPU launch counts are unchanged. The AVX2 second pass adds 12 × ff logical bytes per clamped expert and token [derived, full vectors]. The PR supplies paired host measurements and a GB10 decode A/B.
Escape catalog: no C1–C4 pattern matched.
Notes
Review and mutation checks were static; no build or hardware gate was run here. The PR supplies card evidence and explains the unavailable model-dependent gates.
Card check: gpu-evidence. This pull request changes crates/gpu-deepseek41/src/block.rs, crates/gpu-deepseek41/src/chain/ffn.rs, crates/gpu-deepseek41/src/chain/ffn/batch.rs … and carries a gate run on the author's card, which counts as verified.
🔨 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. |
The card leg took NVFP4 gate·up and down in 5c5c935 (#517); the table test still pinned the list before it, so gate-gpu-lib was red on main. The test now pins the current list and an NVFP4 layer as a card layer. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015btATo6y3zHmKzfE8eHYmN
NVFP4 전문가 스택용 GPU 커널을 추가하고, gate와 up 합이 무한대나 NaN이면 활성화 전에 오류를 기록합니다.
Part of #493 and #495.
This adds the routed NVFP4 card path for Qwen3.8 FP4-Local. Routed NVFP4 stacks run on the card and match the host rule bit for bit, reading from GB10 memory at 0.86 of its 273 GB/s peak.
Scope: this is groundwork in the common card leg, not a Qwen3.8 model load. The Body38 filters in
crates/placement/src/accepts.rslines 147 and 161 still exclude NVFP4, andcrates/gpu/src/arch/qwen3moe/card38.rsline 309 accepts only K-quant stacks. The gate below uses a synthetic six-expert file at Qwen3.8's widths, so it shows the kernels and the card leg, not model support.What and why
Main runs NVFP4 only as a dense gemv. A routed stack has no card entry or layout, although MoE checkpoints store most of their weights in such stacks. Each expert also has its own f32 tensor scale (
.scalewith shape[n_expert]).mxfp4_sel.rsgainsnvfp4_gate_up_selandnvfp4_gemv_sel32. Both reuse the FP4 lane walk and multiply the reduced sum by the selected expert's scale. Gate-up reads the token'sQ8Act; down readsQ8Blocks32, allowing routed widths that are multiples of 64. The code planes must have 16-byte base alignment. An id past the stack raisesExpertId; gate-up writes NaN into its slot.kquant::act::apply_checkedchecks both gate and up sums before activation. A non-finite sum raisesF32Productand writes NaN, because the SwiGLU clamp can otherwise turn an overflow into a finite output. The same owner covers NVFP4, both MXFP4 entries (selection and draft route plan), K-quant selection and arena entries, grouped Q4_K/Q5_K tiles, IQ selection and the V4.1 Q3_K/Q8_0 routed and shared experts, including their multiple-column and tile forms. Launchers that lacked a fault sink now take one from their caller.card_planes_runsandCardFormat::Nvfp4Planes, without changing the file-block sets of the other formats. Card bytes include one scale per resident expert. The weight reader uploads each segment's own scales and rejects missing, non-finite or wrongly sized scale data. A split that puts NVFP4 experts on the host is refused by name, because the host has no NVFP4 kernel.qdot::swiglu_clamptracks non-finite gate or up values in its existing loop with an integer bit accumulator, so output bits do not change, andswiglu_intorejects a non-finite dot sum with a named panic (swiglu: non-finite gate or up sum), the host counterpart of the card'sF32Productfault. The scalar path reduces the largest absolute f32 encoding as an integer. The AVX2 path computes SiLU into the output buffer first, then checks both inputs while it applies the clamp and multiply.CardLegholds NVFP4 stacks as planes and dispatches the pair through the common card table. Slot-capacity checks for K-quant, MXFP4, IQ and NVFP4 share the checked output-row product. The FP4 lane walk's activation-scale shift also supports the 32-value down input.Release notes: Added: Routed NVFP4 expert stacks (GGUF type 40 with a per-expert
.scale) run on the card through a gate-up and down_selpair. A common gate-up activation check rejects non-finite dot sums before a clamp can hide them.Code shape
linear::silu. The NVFP4 pair reuses the FP4 lane core.gate_iq_selandgate_kquantuseQ8Blocks32Host::columninstead of unpacking columns themselves. Card-leg assertions reuseslot_state.CardLeg.F32Productfault.cargo fmt --all -- --checkis clean, andcargo clippy -p bloomery-gpu -p bloomery-qdot --all-targetsreturns rc 0 with the warnings that main already has.The two hand-launch tests in
card_leg.rsshare one result checker, the MXFP4 overflow fixture reuses the existing word conversion, the card leg builds its NVFP4 view throughWeights::nvfp4_stack, and the one-usekept_finitehelper inqdotis gone.Duplication removed: the FP4 lane walk and selected-launch shape checks are shared; activation refusal lives in
kquant::act::apply_checked; V4.1 reexports the shared activation rules; column readback usesQ8Blocks32Host::column; card-leg slot assertions useslot_state.What I ran
The NVFP4 oracle is the host f64 rule over
gguf::quant::dequant_row, with each expert's own scale, plus the host transcription for bit equality. The source iscrates/gpu-gates/src/bin/gate_nvfp4.rsandcrates/gguf/src/quant.rsat308309433. The gate loads a six-expert GGUF at Qwen3.8's widths, places experts 1, 3 and 4 on the card and runs two tokens with repeated experts and a host slot.The benchmark reports logical weight bytes per graph replay.
On GB10,
gate_nvfp4andgate_kquantpass. The resident expert scales, out-of-range ids and NaN rows are checked. The new refusal checks preserve finite-input arithmetic and the existing numeric bands.On GB10, the model-free tables pass 12 K-quant/IQ cases and six V4.1 cases. The K-quant table includes a gate-only overflow as well as up overflows. MXFP4 pair and route each require 768 NaN rows and exact
F32Product. Disabling only the shared guard makes all 21 cases fail (12 K/IQ, six V4.1, two MXFP4 and the existing NVFP4 overflow clause). The source is restored after this control.The MXFP4 route regression uses three experts of 256 rows, K=256, scale bytes 128, gate codes 0, up codes 0x77 for four blocks followed by 0xff for four, x=1e38, limit=7 and sel=route=[0,1,2]. The up sum becomes NaN. Before the route fix it produced finite zero without a fault; the test requires
F32Productand NaN rows from both MXFP4 entries.On RTX 5090,
just gate-gpu-iq-selpasses with the upstreamref-synthblocks (tools/ref/build-dequant.sh, thendequant_ref --synthetic). All nine empirical-error pins and the NaN/fault clauses pass without changing a band.The sm_86 PTX comparison on GB10, with the cc 12.1 driver JIT, identifies two added entries (
nvfp4_gate_up_sel,nvfp4_gemv_sel32) and 19 changed gate-up entries. It returns rc 3, meaning changed.The cc 12.1 pin reader scans the complete binary. All 21 changed or added entries meet their pins: 18 are
spill=0 jit_local=0; Q3_K tiles retain0/144, and Q4_K/Q5_K tiles retain0/136. The full command returns rc 1 for the same nine unpinned entries on main and head, with no owned entry above its pin.Qwen3-30B-A3B Q4_K_M full-model decode on GB10, main versus head under one lease: seven ABBA cycles, 14 paired rounds, N=32, warm=8, initial prompt 6, ctx 256, default levers. The 28 arms finish in 101 seconds. Main averages 9.842700 ms and head 9.840114 ms; paired head/main throughput is 1.0003 ± 0.0037 (n=14). The effect is +0.027%, with a 95% lower bound of -0.346%, passing the unchanged 1% non-inferiority margin. This resolves no slowdown or speed gain beyond noise.
cargo fmt --allandgit diff --check: clean.Host SwiGLU clamp
The host finite check costs nothing measurable. The table compares head with main on the same machine in one sitting: ten ABBA rounds (base, head, head, base), a paired ratio per round, the geometric mean of the ten ratios, and a 95% interval from a t distribution (9 degrees of freedom) on the log ratios. The function rows time
qdot::swiglu_clampwith limit 7, best of nine batches. The union rows timeexperts_union_intoon a clamped Q3_K layer (embd 4096, ff 2048, eight experts, limit 7), best of five batches. A ratio below 1 means head is faster. The benchmark sources are local test files and are not part of this PR.The clamped function is about 7% faster on GB10 and 3.6 to 4.4% faster on the AVX2 host at these widths. Every union interval contains 1.0. The unchanged plain
swiglucontrol reads 1.000 on both machines. The speedup is measured only at these widths.Machines: GB10 is a Cortex-X925 and Cortex-A725 aarch64 part (function on CPU 6, union on CPUs 5 to 9). The x86 host is an AMD Ryzen 5 PRO 6650H with AVX2 and FMA (function on CPU 3, union on CPUs 2 to 5). Main is
e16725d6128b3107c3406d9f468b229d456c549f. GB10 measured tree17e78da7802247abb9c5bd6d1c9ae6d13ad4a302; x86 measured tree941c712b4b3d088f98357744979db02d17385af1. Command per arm, pinned withtaskset:The host finite flag has failing-first controls. Replacing only the final finite result with true makes the existing flag test fail at
gate[0] = NaNon both architectures (rc 101). The restored code passes 3 SwiGLU tests on GB10 and 4 on the AVX2 host. They cover the largest finite value, NaN and both infinities at all 19 input positions, clamp off, output bits and the padded tail.Measured commits
The published head is
0dbc4d6fbe6fb4177cd36e743bb56b16844c5638on base819d3d705d5d405751f97f4f2dd63a97b30d3855(upstream main). The host rows above come from the two trees named there. Since those trees, only the pin comment changed, and the base differs frome16725d6in signal and self-test tools only, not in CPU or GPU engine code.The GPU gate rows come from commit
36a32adda8e064bbdb3769da3949ca0857ec69baon GB10 and the bandwidth rows from0bb58b08. No CUDA kernel, launch count or numeric GPU operation has changed since, so those measurements carry to the head. The later GPU changes are the card leg's reuse of the load-timeWeights::nvfp4_stackaccessor and tests. On RTX 5090, tree1e64a55b,gate_nvfp4passes 40/40 clause rows, including 12 routed rows with gate-up 3200/3200 and down 12800/12800 bit matches. Hand-launch tests on that card pass 2 of 2 (K-quant and NVFP4), and the MXFP4 overflow test passes 1 of 1 in both pair and route modes.GPU run output
Gate output on GB10 (
just gate-gpu-nvfp4, routed clauses):gate_nvfp4 routed clauses
The finite-guard overhead comparison ran main (
b09ec042) against36a32addas seven cycles in the order base, head, head, base, on one lease, with thedocs/cards/gate-up-finite.cardmargin (sha256cc8db55ed22d2a001fcc7de7bc25a48b26f7ce3737cc8368404266436a368b8e). Each arm ran the default levers:A/B result lines
Model file:
Qwen3-30B-A3B-Instruct-2507-Q4_K_M.gguffromunsloth/Qwen3-30B-A3B-Instruct-2507-GGUF, revisioneea7b2be5805a5f151f8847ede8e5f9a9284bf77, sha2566c997b8af17debdfb01d890214400ccbab00db6acc0ba8da5de1cc906c4774d0.To reproduce, from the repository root with CUDA configured:
just gate-gpu-nvfp4 just gate-gpu-kquant just gate-gpu-iq-sel bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- card_leg::tests::hw_ --ignored --nocapture bash tools/gate.sh --oxide -p bloomery-gpu --release --lib -- mxfp4_sel::tests --ignored --nocapture bash tools/gate.sh --oxide -p bloomery-gpu-deepseek41 --release --lib -- hw_gate_up_sums_fault_before_activation --ignored --nocapture just ptx-compare b09ec042 generate_ds41 --features deepseek41 cargo test -p bloomery-placement --libWhat I ran into
The following limits do not block the PR. The model-dependent DSpark and V4.1 gates were not run because their model files are unavailable on the test nodes. Their changed launchers compile, and model-free hardware tests exercise the overflowing sums through the real entries.
The GLM routed-stack check still accepts only K-quant stacks, so that model cannot use an NVFP4 routed stack yet.
Hardware
GB10 gate runs use CUDA 13.3.1 and this raw card line:
The IQ gate uses an RTX 5090, driver 595.99.02, compute capability 12.0.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.