Repository navigation
gpu: the GDN prompt delta's products take each f32 operand as three BF16 parts, so a chunk keeps the one-token rule's precision - #1140
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: The new state-update sum can overflow on finite input that the one-token rule and base kernel accept.
Must fix
1. Keep the decayed state in the product accumulator
crates/gpu/src/linear/delta.rs:2024 computes the correction from zero before adding the old state. Call enqueue_delta_prompt with keep=false, no carried rows and a matching lane stamp. For one value column, start with S=(-1e38,0), use four keys (.5,.5),(.5,-.5),(.5,.5),(.5,-.5), values (1.5e38,1.5e38,2.5e38,2.5e38), and β=decay=1. Set other state and key channels and queries to zero; pad to 16 rows with k=v=β=0 and decay=1. The launch checks accept these values.
The correction is about 4e38, which overflows before cancellation with the initial state. The one-token rule and base accumulation remain finite at about 3e38 [derived; scalar f32 reproduction]. The new state becomes infinity, raises LinearDelta, and makes Head::tokens return a fault.
Fix this before the new sum order becomes the reference for later precision changes. Reuse split_mma with an initial accumulator. Keep its existing attributes and replace its definition:
unsafe fn split_mma(
a: [[u32; 4]; PLANES],
b: [*const u32; PLANES],
mut c: [f32; 4],
) -> [f32; 4] {
for i in 0usize..SPLIT_TERMS.len() {
cuda_device::thread::__unroll_config::<0>();
let (pa, pb) = SPLIT_TERMS[i];
// SAFETY: the caller's row of part pb.
c = unsafe { frag_mma(a[pa], b[pb], c) };
}
c
}Pass zero at the inverse call on line 1968 and the causal-product call on line 1975:
ut[tt] = unsafe { split_mma(r_split, planes(0, tt), [0.0; 4]) };let y = unsafe { split_mma(u_split, planes(128, tt), [0.0; 4]) };Replace lines 2023–2028 with:
for i in 0usize..4 {
cuda_device::thread::__unroll_config::<0>();
st[kt][i] *= d;
}
// SAFETY: keys 8·kt + g of each part's complete keys by time.
st[kt] = unsafe { split_mma(e_split, keys, st[kt]) };Update the state sum-order documentation and add this input to the existing prompt clause, asserting finite state and no fault. Seeding the three-part accumulator keeps this reproduction finite.
Non-blocking
⚠ Supply the precision and occupancy timing proof: crates/gpu/src/linear/delta.rs:614 doubles full-chunk work from 84 to 168 warp MMA instructions per token per value head; prepared shared memory rises from 32,192 to 46,016 bytes per block [derived; 16-row chunks, HEAD=128]. The PR gives precision and spill results but no timed A/B. Supply the RTX 5090 A/B required by AGENTS.md's precision/occupancy classes and identify the owning e2e count-pin result.
Checked
Duplicates: dryer reported 0 pairs. The tile and register product helpers have different fragment contracts.
Complexity: crapper flagged gdn_chunk_prepare, 27→29; added plane and record loops in a kernel, reviewed for correctness without suggesting a split.
Silent failure: 0 new default/error-suppression sites; followed both output/state finite checks through the fault word to the token readback error.
Tests: restoring the two-part products fails the revised band in the reported base run. The current prompt inputs miss the finite-overflow case above.
Gates: prompt band tightened from 2e-4 to 2e-6 with a dated PIN and baseline failures; changed spill and unsafe pins carry dated reasons.
Escape catalog: no C1–C4 pattern matched.
Notes
Dryer skipped gpu-gates; the changed gate was reviewed manually. No CUDA builds or gates ran during validation; checks used source inspection, loop-count derivation and scalar f32 reproductions.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_linear.rs, crates/gpu/src/linear/delta.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)
…F16 parts, so a chunk keeps the one-token rule's precision
cd42d4d to
5e48cf7
Compare
There was a problem hiding this comment.
Since the last review:
- Overflow finding: fixed at crates/gpu/src/linear/delta.rs:2031. Both the state and output products now start from their state contribution.
- Timing question: still open at crates/gpu/src/linear/delta.rs:615.
Verdict: CLEAN: The previous blocking defect is fixed, and no new blocking defect remains in the interdiff.
Non-blocking
⚠ Supply the precision and occupancy proof: crates/gpu/src/linear/delta.rs:870. Full chunks still cost 84 → 168 warp MMA instructions per token per value head, and prepared shared memory rises from 32,192 to 46,016 bytes per block [derived; 16-row chunks, HEAD=128]. Attach the RTX 5090 timed A/B and owning e2e count-pin result required by the precision/occupancy classes.
Checked
Duplicates: 0 new named items in the interdiff; the existing product helper and gate launcher remain the owners. Dryer reported 0 pairs; the new gate fixture was checked manually.
Complexity: crapper reports prompt_clauses 42 → 52, from boundary-fixture loops and branches in an existing function; gdn_chunk_prepare 27 → 29, from kernel plane/record loops unchanged by the interdiff. No kernel split is proposed.
Silent failure: 0 new suppression sites. Both finite checks raise LinearDelta, which reaches the token readback error. The new clause requires finite output/state and no fault.
Tests: resetting either product seed at delta.rs:1982 or :2031 to zero lets the boundary fixture's correction overflow. Its finite/no-fault clause rejects that mutant [derived; 16-row, HEAD=128 fixture]. Partial and kept chunks still bypass state updates.
Gates: no pin changes in the interdiff; the previously reviewed dated pins remain.
Escape catalog: no C1–C4 pattern matched.
Notes
Dryer did not scan gpu-gates. No CUDA build or gate ran during validation; checks used source inspection and loop-count derivation.
The run report omits the tested head commit hash, so gpu.json marks the evidence incomplete. The new boundary clause also lacks reported FAIL-first output.
Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_linear.rs, crates/gpu/src/linear/delta.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. |
|
@juliankang4 On sm_86 (fixture tier, our landing batch at main 13a27dc), two gates went red after 44a23e8. Both are green at its parent 35a7e8e:
The other 125 gates the change selects are green. I can look into it on our cards if that helps; tell me which you prefer. Written with Claude Code; posted by the maintainer. |
|
@midagedev Thanks for running these and for the exact lines. Both come from my change, so I will take them and open a fix today. The (AI 코딩 에이전트가 작성한 코멘트입니다.) |
|
@midagedev The fix is in #1145 (4f8fca6). Both reds came from one defect in this PR, not from the cards.
(AI 코딩 에이전트가 작성한 코멘트입니다.) |
GDN prompt delta 커널의 곱이 f32 값을 BF16 세 성분으로 받도록 바꿔, 16토큰 chunk 결과가 한 토큰씩 도는 규칙에 훨씬 가까워진 수정입니다.
What and why
The chunked GDN prompt delta (
gdn_chunk_prepare,gdn_delta_preparedincrates/gpu/src/linear/delta.rs) fed the tensor cores each f32 operand as a BF16 high part and one BF16 residual. That drops the bits below 2⁻¹⁶, soodiffered from the one-token rule by 5.4e-6 to 2.2e-5 (relative L2) on an RTX 5090. Each operand of the four products (k·k, q·k, T·r, P·u) and the state update is now three BF16 parts holding all of its f32 bits, and each product sums six terms down to 2⁻¹⁶, smallest first. The state update andostart that sum from the decayed state and from Dₜ times Sᵀq, so a correction that cancels against them stays finite where the one-token rule does.gate_linearhas a clause for it (a state near f32's limit). The chunk is still 16 tokens, the launch count is still three and the record is still 560 words.gate_linear's prompt band moves from 2e-4 to 2e-6 with a datedPIN; the base kernel reads 6.6e-6 and 2.2e-5 against it.Refs #1127.
gdn_delta_preparedalso no longer spills (172 B to 0 on sm_120a, 172 B to 0 on sm_121a, 48 B to 0 on sm_86): each eight keys' state parts are built once and live alone through that block's products. The pinned spill tables and thegpuunsafe ratchet (3000 to 2992 blocks) are recounted. Every GDN prompt takes this path (Qwen3.5/3.6 and Qwen3.8); KDA and the one-token, verify and recovery kernels are untouched. The change makes no speed claim.Release notes: Fixed: the GDN prompt kernel's error against the one-token rule drops about 7 to 21 times on an RTX 5090, and its register spill is gone.
Code shape
The review reads these first. A box left unticked needs one line of why.
copying it (
AGENTS.md"Common code first",docs/rust-quality.mdR14). Where I found an existing copy, Inamed it below.
(tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
tools/check-comments.sh).PIN(YYYY-MM-DD):and its reason.
cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none":crates/gpu/src/linear/delta.rs:645and:704(chunk_productover two shared-memory tiles,split_mmaover one register-held 16-key step) share only the loop overSPLIT_TERMS, which is the single owner of the term order. The oldchunk_pair_lowand the two-part split helper are replaced bychunk_planeandSPLIT_TERMS.What I ran
Base
853be26fbfef009bcfc30ecee6af48491683d464. The gate recipes ran on an RTX 5090.Prompt precision against the one-token rule,
gate_linear(synthetic inputs, n_k=16, n_v=32, head=128):The base kernel through the same clauses (
BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_linear):Qwen3.6 real binary through the shared prompt path, model
lmstudio-community/Qwen3.6-35B-A3B-GGUFat revision68a34855558af61cbef0324d31f411be8a506b08, fileQwen3.6-35B-A3B-Q4_K_M.gguf(21,166,757,728 bytes, sha2564ac6a06bce551257267f49ad2226f8671a22519ccc1a4dde9d5b433d1f2a410d):Register spill of the changed kernels, from
ptxas13.3.73:Hardware (if the change is for a machine)
nvidia-smi);ptxas13.3.73gate_linear,gate_qwen35moe_e2e,hw_last_step_keeps_pass_path, and theptxasscans aboveAI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.