Skip to content

gpu: raise faults for overflowing QSA sums and invalid f16 cache values - #976

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sa-q1b-kernel-fault
Oct 29, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-sa-q1b-kernel-fault

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

QSA 점수 합이 넘치거나 f16 KV 캐시 값이 유효하지 않을 때 이제 커널 fault를 올리도록 고쳤습니다.

What and why

Two kernel paths stored bad values without raising a fault. The QSA score kernel checked each head's dot product but not the sum of the four head dots, so four finite dots could add up to inf and be stored silently. The f16 KV cache writers (the 128-dim append, the K192 plane and ring append, and F16Sink) rounded to f16 with no check, so a NaN, an Inf or a value that overflows f16 (such as 65520) went into the cache.

The QSA kernel now raises PoolSelect when the final sum is not finite. A shared cache_f16_pair in crates/gpu/src/rope_neox.rs raises CacheValue when a source value or its f16 result is not finite and stores NaN for that lane only. The existing f32x2_to_f16x2_bits and f16_finite helpers are reused, and finite values keep their current rounding. gate_qwen35moe_attn --kernel-faults gains the boundary inputs below.

Release notes: Fixed: non-finite QSA score sums and invalid f16 KV cache values now raise a kernel fault instead of being stored silently.

Code shape

  • No second copy. The f16 cache check lives in one helper, cache_f16_pair, used by all three cache writers. Duplication found or removed is listed below.
  • Model code holds only architecture facts. The change is in the shared QSA and NEOX kernels; no model file changed.
  • Dead code is gone. Nothing was made unused.
  • No silent failure. Non-finite sums and cache values are now a named fault.
  • Comments state what is true now. The module doc in rope_neox.rs states the new fault behavior.
  • No relaxed gate. No band, tolerance or lint moved; the gate only gained cases.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": the three inline f32_to_f16_bits cache stores in crates/gpu/src/rope_neox.rs became one cache_f16_pair.

What I ran

On a DGX Spark, one run built the new gate against the two kernel sources as they were before this change, then against this branch, and ran each:

cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features gpu --release --bin gate_qwen35moe_attn
bash tools/gpu-gate.sh gate_qwen35moe_attn --kernel-faults
cargo oxide build --arch sm_121a -- -p bloomery-gpu-gates --features gpu --release --bin gate_qwen35moe_attn --bin gate_mimo2_flash
bash tools/gpu-gate.sh gate_qwen35moe_attn --kernel-faults
bash tools/gpu-gate.sh gate_mimo2_flash --only A,W1

Before (exit 1): the V and K cache NaN/Inf/65520 cases and the QSA sum overflow raise no fault.

rope f16 cache fault: key=false dim=64 NaN word=None want=Some(Fault { layer: 13, code: 16, sites: 65536, arch: None }) NaN=true other_bits=true FAIL
rope f16 cache fault: key=false dim=64 65520 word=None want=Some(Fault { layer: 13, code: 16, sites: 65536, arch: None }) NaN=false other_bits=true FAIL
qsa score sum: gain=1e36 dots=[1.2799988e38, 1.2799988e38, 1.2799988e38, 1.2799988e38] sum=inf finite_heads=true stored_sum=true word=None want=Some(Fault { layer: 13, code: 18, sites: 262144, arch: None }) FAIL

After (exit 0): the same cases raise the expected fault and mark the lane NaN. Finite boundary values keep their host-exact cache bits. All 16 cases (K and V, dim 64 and 192, NaN, Inf, 65520, -65520) pass.

rope f16 cache finite boundaries: store-only cache bit_exact_host=true PASS
rope f16 cache fault: key=false dim=64 NaN word=Some(Fault { layer: 13, code: 16, sites: 65536, arch: None }) want=Some(Fault { layer: 13, code: 16, sites: 65536, arch: None }) NaN=true other_bits=true PASS
rope f16 cache fault: key=false dim=64 65520 word=Some(Fault { layer: 13, code: 16, sites: 65536, arch: None }) want=Some(Fault { layer: 13, code: 16, sites: 65536, arch: None }) NaN=true other_bits=true PASS
qsa score sum: gain=1e36 dots=[1.2799988e38, 1.2799988e38, 1.2799988e38, 1.2799988e38] sum=inf finite_heads=true stored_sum=true word=Some(Fault { layer: 13, code: 18, sites: 262144, arch: None }) want=Some(Fault { layer: 13, code: 18, sites: 262144, arch: None }) PASS

The K192 append gates, which exercise the changed cache writers, pass:

A1 append: 72 launches (m = 1, 5, 64; positions 0, 127, 128, 129, 4095, 4096; bases 1e7, 1e4; 4 and 8 key heads) = the host transcription bit for bit (turned query, key in place, key and value planes, every other row the sentinel), reruns identical PASS
W1 append at rows == ctx: 36 launches (m = 1, 5, 64; positions 0, 127, 128, 129, 4095, 4096; 4 and 8 key heads) = the plane entry bit for bit (turned query, key in place, both planes) PASS

Hardware (if the change is for a machine)

Card Driver CUDA
NVIDIA GB10 (sm_121a) 595.84 13.3

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 29, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: No blocking defect survives review of the cache checks and QSA sum check.

Non-blocking

⚠ Complete the GPU evidence: gate_flint_attn.rs:946 and gate_mimo2_flash.rs:1630 add cases absent from the supplied output.
Add their FAIL-first/PASS output, the nvidia-smi card/driver line, and exact before/after commit hashes.
This lets the changed writers be verified against the reported binaries.

Checked

Duplicates: 6 new items Grep-checked; all 6 dryer pairs read. They are existing norm/rotation/format kernel variants. The new cache validation has one device owner and a separate host oracle.

Complexity: Flint cache_value_case (24), Qwen cache_value_check (24), generic_cache_value_check (21), and score_sum_check (21) are new case runners with setup, launch, and verification stages. Qwen run 63→74 adds CLI dispatch; Flint run 21→23 adds case calls; MiMo append_clauses 31→40 adds A3 cases; qsa_score 25→26 adds one finite check. Kernel bodies need no split.

Silent failure: 8 writer/sum sites followed. Invalid values raise CacheValue or PoolSelect; token readback returns GpuError::Fault and poisons model state. Invalid cache lanes become NaN. Position guards and live-pool guards prevent invalid accesses and padding faults.

Tests: static mutation review. Bypass the cache calls at flash.rs:850, rope_neox.rs:719/921/1104, qk_rms.rs:174, or attention_h128_ring.rs:166/327: the corresponding cache clause fails. Delete the check at qsa.rs:851: score_sum_check fails. Drop NaN marking or alter finite/neighbor bits: cache assertions fail. Omitting CacheValue makes the amended overflow clauses fail.

Gates: no tolerance relaxed or clause removed. Unsafe budgets have dated PINs explaining the additional bounded scopes.

Performance: decode/prefill cache writers and the selector changed; no added launches, copies, allocations, locks, syncs, or float reduction reorder.

Escape catalog: C1–C4 have no matches.

Notes

Validation was static. GPU gates were not rerun. The supplied card table and gate excerpts do not satisfy the complete GPU evidence list.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_flint_attn.rs, crates/gpu-gates/src/bin/gate_mimo2_flash.rs, crates/gpu-gates/src/bin/gate_p0b.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)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit fe680ee into midagedev:main Oct 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant