Repository navigation
gpu: head-256 prefill attention for EmbeddingGemma 1 (flash_band first-key bound, pack-1 lower entry) - #351
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: No reachable behavior defect or proven quality defect survived review.
Non-blocking
⚠ Exercise the excluded prefix: crates/gpu-gates/src/bin/gate_gemma_embedding_head256.rs:35.
The cache twin poisons only keys at or past t (prefill_gate.rs:48). The excluded prefix stays finite, so this gate does not detect removing key >= lo from the shared staging guard (flash_gqa_prefill.rs:1108): the per-row softmax still masks those keys.
Add a pack-1 case with positive first keys and NaNs below the block's minimum first key, inside its first key tile. The staging-guard mutant must fail that case.
Checked
Duplicates: 5 new functions checked; no duplicate owner found. The dryer pair selects different pack sizes through the existing launcher.
Complexity: diagnostics report run new at 49, prefill_256_p 41→44 for query staging (kernel exemption), and enqueue_packed 18→21 for one dispatch arm.
Silent failure: 3 refusal paths followed—short first-key buffer, invalid first key, invalid count. They return a named shape error or raise KeyCount and write NaNs.
Tests: the PR reports FAIL-first results for the query-load and LOWER mutants. The bound's unit assertions cover tile, 16-key and 4-key offsets. The new gate leaves prefix NaN exclusion untested; the existing pack-2 hardware test checks it on that entry.
Gates: existing callers retain first=0 and unchanged bounds; the unsafe ratchet has a dated PIN. No existing clause or selector was removed.
Escape catalog: C1–C4 do not match.
Adversarial checks: query tails, an unpadded cache, mixed invalid rows and an entirely invalid block are guarded.
Notes
No builds or GPU gates ran during validation. The PR reports FAIL-first runs and identical existing PTX on earlier revisions. Provide the current base/head add-class scan and owning-gate output, plus the required nvidia-smi line and gate recipe output. GPU evidence is incomplete.
Card check: needs-gpu. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/bin/gate_gemma_embedding2_head512.rs, crates/gpu-gates/src/bin/gate_gemma_embedding_head256.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 shared attention bound accounts for partial key tiles and accumulation groups at either end of a cut cache. Existing callers pass zero, which preserves their formulas and results. The host test checks the zero and aligned offsets against the closed form for uniform attention, and an interval of 64 keys starting inside a tile against its two-tile bound.
Instantiate the packed flash owner at pack one for groups of three query heads per key head. The query staging reads two positions per pass at this pack; existing pack instances retain their indexing. The synthetic gate compares whole-input and symmetric-window attention against the f64 attention band at three and six query heads, including block and key-tile tails, scaling, NaN padding, reruns, graph replay and count refusals.
fa4cdec to
a6797a2
Compare
There was a problem hiding this comment.
Verdict: CLEAN: No review finding requires changes.
Non-blocking
⚠ Refresh the GPU evidence for this head: crates/gpu/src/flash_gqa_prefill.rs:2462. The reported runs precede the reviewed head, a6797a20, and include no nvidia-smi output.
Run the new family gate and the add-class PTX comparison for generate_ds41 and gate_e2e against the current base. Attach the card/driver line, both hashes, commands and output. This establishes the kernel evidence before encoder integration; this change class needs no timed A/B.
Checked
Duplicates: 5 new functions checked. The dryer pair, enqueue_256_p2_lower / enqueue_256_p1_lower, selects different pack sizes through the existing common launcher. No additional owner is justified. GPU-gates searched manually.
Complexity: run is new at 49; its logical split points are fixture setup, eager/band checks, graph checks and refusals. prefill_256_p 41→44 adds a compile-time layout branch; its kernel body stays intact. enqueue_packed 18→21 adds one dispatch arm.
Silent failure: 4 bad-input classes followed: zero count, count beyond context, first key at/past count, and short first-key buffer. Consumers receive KeyCount with a NaN row, or a named Shape error.
Tests: source mutation checks cover the query stride at flash_gqa_prefill.rs:1007 (replace with t0 + e: band fails), offsets at flash_band.rs:106,122,123 (drop them: shifted assertions fail), and fault/NaN/short-buffer refusals (drop them: refusal checks fail). Boundary/odd-group index enumeration found complete, unique loads and stores. GPU gates were not executed in this review.
Gates: first=0 retains the old bound; new zero-spill rows added; the two-block unsafe increase has a dated PIN. No existing tolerance moved.
Adversarial checks: partial query tiles, invalid and wholly invalid intervals, and capture on the wrong stream are blocked by the index guards, fault/store logic and Gpu::capture's stream identity.
Escape catalog: C1–C4 do not match the added code.
Card check: needs-gpu. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/bin/gate_gemma_embedding2_head512.rs, crates/gpu-gates/src/bin/gate_gemma_embedding_head256.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. |
Part of #59 (plan and PR order in #190), E8: the kernel half of EmbeddingGemma 1. It adds the head-256 prefill attention entry that the encoder needs, with a gate that checks it against the f64 band owner. The tokenizer half of E8 is a separate PR. Nothing in the server calls this entry yet.
What and why
Release notes: internal: head-256 prefill attention for EmbeddingGemma 1, the kernel the embedding encoder will call.
EmbeddingGemma 1 attends with 256-wide heads over a causal window. The existing head-256 prefill kernels take query heads in packs of 2, 4 or 8. This PR adds the pack-1 variant with the lower-band key bounds,
gqa_prefill_flash_256_p1_lower, andgate_gemma_embedding_head256, which compares it with the f64flash_bandowner. The encoder PR can then call a kernel that is already checked.What changes
Two commits, one contract each.
flash_band::prefill_boundtakes the first key's original offset.prefill_boundandjudge_prefillcount tiles, 16-key accumulation groups and 4-key sum groups from that offset, including the partial groups at both ends of a window. The three existing callers (gate_gemma_embedding2_head512,gate_qwen3moe_flash,gate_qwen35moe_attn) give 0. There is no second bound function and no compatibility wrapper. A unit test checks that 0 and aligned offsets give the same bits as the old closed form, and covers a window[16, 80)that spans two 64-key tiles and an unaligned group.gqa_prefill_flash_256_p1_lowerand its gate.crates/gpu/src/flash_gqa_prefill.rsgains the pack-1 lower entry andenqueue_256_p1_lower. They use the sharedprefill_256_p,enqueue_packedandchecked_packed. In pack 1 the query load reads two positions per load step. The layout is chosen outside the load loop so the existing packed loop stays as it was. The gate binary, its required feature, the recipe row intools/gate-paths.tsv, thejustfileentry and the spill pins intools/ref/ptx-shapes*know the new entry.tools/unsafe-ratchet.txtmovesgpufrom 1869 to 1871 for two new unsafe blocks (the query read and the shared body call), each with a SAFETY comment.The gate runs heads 3/1 and 6/2, T of 1, 63, 65 and 129, the full input and valid windows (reach 17 and 64), and scale 1 and 0.0625. T=65 runs with ctx=65 and no padding. For each case it checks the f64 bound, that NaN padding is untouched, that a rerun is bit identical and that a single graph node gives the eager bits. A wrong first key or count must turn only its own row into NaN and raise the
KeyCountfault. A first-key buffer that is too short must be refused by name.Comparison with the reference
The reference is the f64 attention and first-order band owner,
flash_bandincrates/gpu-gates/src/flash_band.rs(blob84399a3e89c5e9d5fe141ebab4d8f772f8532922).gate_gemma_embedding_head256computes each query row's exact result and bound in f64 and divides the kernel's largest error by that bound. The comparison log is fromc618d7d0, andgit range-diffshows its two commits equal (=) to this head's.The pack-1 kernel stays within 0.278 of the f64 band's bound on every one of the 32 comparisons.
What this PR does not do
Code shape
tools/check-comments.shhas not been run on this head.gpuunsafe ratchet moved by the two new blocks, with the PIN line in the file.cargo fmtis clean on the touched Rust files, butcargo clippyand the lint count are still running on the card when this was posted. The result goes into this description when it ends.Duplication found or removed: none.
What I ran
The GPU checks ran on a DGX Spark in the project's dev container, on
c618d7d0754bcf0263c9e2fe02f330e269816677. The head751f89efis the same two commits rebased ontoce1c310ff, andgit range-diffshowed both as unchanged (=). I did not run the gate again on the rebased head.cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features gpu --release --bin gate_gemma_embedding_head256BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemma_embedding_head256gate_gemma_embedding_head256: PASSbash tools/gate.sh --release -p bloomery-gpu-gates --lib -- prefill_bound_counts_tiles_from_first_key --nocapturegate_gemma_embedding2_head512: PASSpython3 tools/recipes.py checkThe unit test, the build of the three existing callers and the head-512 synthetic run used
3b563994, an earlier head of the first commit.flash_band.rshas the same blob (84399a3e89c5e9d5fe141ebab4d8f772f8532922) there and in the final head.FAIL-first, on the final head, one edit at a time:
t0 + 2*e + r0changed tot0 + eband=falseLOWER=trueof the pack-1 call changed to false3b563994)Base versus head
tools/ptx-compare.shagainst75f72268e50dc172a8b0dc13d7734633440dbcdb, forgenerate_ds41andgate_e2e, with--features gpu,deepseek41, at PTX arch sm_86 and sm_121, JIT on the GB10 (cc 12.1). The sm_86 runs use the project's tool. For sm_121 I used a copy of the tool that differs by the one lineARCH=sm_86toARCH=sm_121. Each of the four runs ended rc 0 and shows one added entry,gqa_prefill_flash_256_p1_lower, and every existing entry identical:The new entry has no spill and no JIT local memory in all four runs. ptxas reports 214 registers at sm_86 and 212 at sm_121, and the GB10 JIT reports 212. The spill check on the entry, with a table cut down to its own rows, gave
violations=1 FAILbefore the pin andviolations=0 PASSafter it, at both arches. The0/0rows in the main spill tables are the zero-spill requirement for the new entry. They come from the GB10 JIT, not from a cc 8.6 card.Not run:
cargo clippyand the lint count (still running, as above),tools/check-comments.sh,just affected,just contrib-check, the full mac-static, and the whole spill gate on the final head. I ran no RTX 5090 or other GPU check, no cc 8.6 JIT and no timing. The gate uses synthetic inputs and no model file.What I ran into
None of this blocks the PR.
tools/ptx-compare.shreported four existing packed entries changed and the pack-2 JIT registers going from 206 to 208 (rc 3). Moving the layout choice outside the loop fixed it. No check was loosened.band=false.Hardware (if the change is for a machine)
DGX Spark: NVIDIA GB10, driver 595.84, compute capability 12.1, CUDA 13.3.1 in the project's dev container (
ptxas13.3.73). The unit test needs no GPU.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.