Repository navigation
gpu: tile prefill SDPA over 2..64-row chunks (stacked on #3417) - #3431
joshuaswarren wants to merge 2 commits into
Conversation
|
[Joshua's agent] Main moved again (5c82ef2) and its new CHANGELOG.md entries collided with this branch's, so I merged main once more (head 9c0c013, merge commit, no force-push) and moved this branch's own entries to the bottom of the Unreleased list, where main's top inserts no longer touch them. No code changed since the last head, so the earlier A/B and contract results stand. |
|
[Joshua's agent] The lean check failed on this head after the last merge of main: two comments in attention.zig went past 120 columns and one was multi-line. New head: 9b677bf. Comment text only, no behavior change, pushed as a plain commit with no rebase. |
|
Thanks @joshuaswarren. The whole-prefill comparisons are useful. There is one causal correctness issue to fix: the PV tile masks future probabilities to zero but still multiplies them by future values. With two rows, zero Q/K, V0=1 and future V1=NaN, row 0 becomes NaN instead of 1 because 0*NaN is NaN. Please guard accumulation by each row's visible-key bound and add a device regression with future NaN and both infinity signs, comparing complete output bytes with the old path and individual rows. Also cover capacity above visible keys and the actual served prompt path. Keep the new shader comments on single lines within 120 columns. Afterward we need the receipt and green zig, zig-windows, pytest and fmt jobs at the updated head.
|
|
[Joshua's agent] Read, thanks. You are right: the PV tile zeroes future probabilities but still multiplies them by future values, so 0 times NaN or infinity poisons the row. I will guard accumulation by each row's visible-key bound and add a device regression with future NaN and both infinity signs, comparing complete output bytes with the old path and per row, with capacity above visible keys and the served prompt path. New shader comments will be single lines within 120 columns. This is the first of the five I will fix; #3436 will be rebased on it. |
|
[Joshua's agent] Ready note: the fix is pushed at 85a672f (two commits on fork branch vulkan-sdpa-tile), CI green at that head (8 success, 2 skipped host-nightly). What changed: sdpa_pv_tile now guards accumulation by each row's visible-key bound (key < first_key + qrow + 1), so a zeroed future probability is never multiplied by a future value. The attention contract plants non-finite future V (NaN, +inf, -inf) against the tiled prefill: pre-fix the 3 new cases FAIL on the 16-inch M1 Max (18/21 pass), post-fix all pass (21/21), tiled byte-identical to per-row decode in BF16 and F32. No behavior change on the served path: Qwen3.5-2B 6173-token prompt, 2 greedy steps x2 runs x both stacks, greedy token hash d81e4486eedc80b0e43cc5d2b62053a01d4c6d9bf0397feea1b09fc04467092 and logits_bf16.bin sha d050eed9a7a75609bc42229c90933cdd186add254646 identical pre vs post on both binaries. The fixture's Metal oracle hash does not match the Vulkan greedy ids on either head (pre-existing Vulkan-vs-Metal divergence, unchanged by this fix). tools/zig/lean_check.py stays at 341 problems, same as main. |
|
@joshuaswarren, the causal issue is the kind this review exists to catch: the PV tile zeroes future probabilities The whole-prefill comparisons and the 32.6% and 34.6% gains at 6,173 tokens are the useful measurements here,
|
|
[Joshua's agent] Pointing at the posted receipt rather than re-arguing it: the ready note of 01:13Z (fix at 85a672f, CI green) already contains the device regression you ask for — pre-fix the 3 new NaN/±inf cases FAIL on the 16-inch M1 Max (18/21), post-fix 21/21 pass with tiled output byte-identical to per-row decode in BF16 and F32, and the served-path probe (Qwen3.5-2B 6173-token prompt, token hash d81e4486eedc80b0e43cc5d2b62053a01d4c6d9bf0397feea1b09fc04467092 identical pre/post on both binaries). Capacity sits above visible keys in the contract; the Metal-oracle mismatch on both heads is the pre-existing Vulkan-vs-Metal divergence, unchanged by this fix. Nothing further is queued for this PR. |
|
Thanks @joshuaswarren. Your posted 21/21 result and served token/logit hashes answer most of our earlier requests. Please attach the contract summary and the complete old-prefill byte comparison, plus paired timings for the guarded shader if those are not already in the receipt. We will handle the source review, stack integration and CI checks.
|
|
[Joshua's agent] Attaching the three items from the receipts we already hold; nothing needed a new run. 1. Contract summary (16-inch M1 Max, honeykrisp "Apple M1 Max (G13C C0)", vendor 0x10005)The gate is tf-attention-contract: rope, sdpa decode and prefill families, and the sdpa-tile poison cases, each checking tiled output byte-identical to per-row decode with repeats. Pre-fix (parent 3401-base shader), 18/21 — the three new future-poison cases fail exactly as your review predicted: Post-fix (this PR at 85a672f), 2. Complete old-prefill byte comparison
3. Paired timings, guarded shader vs parent
Single-machine deltas only; no cross-machine A/B has passed, so I claim no gain. |
85a672f to
037cc2b
Compare
037cc2b to
85a672f
Compare
|
[Joshua's agent] A note on the two force-pushes above from this morning (11:20 and 11:24 UTC). A rebase attempt on our side went wrong, and for four minutes this branch pointed at a commit that would have undone unrelated files on main. I have put the branch back to |
The branch carried 442 restack-merge commits; this is the same tree delta applied onto current main as one commit. CHANGELOG union-merged; all other paths auto-merged.
85a672f to
e2220ce
Compare
|
Rebased onto the rebased #3417 (one squashed commit; MERGEABLE). RTX 5060 Ti rerun: outputs bit-identical across the tile and non-tile arms on doc-256 and doc-1024. Timing claim not re-established yet: same-binary pairs on this host swing 5.3 s to 13.4 s under concurrent guard lanes, which swamps the tile's expected gain; medians from 5 pairs landed on both sides of zero between the two cases. Receipt: |
|
Follow-up on the quiet case: at capacity-7105, ctx 8192, on the same card and the same rebased pair (5 alternating pairs, |
|
[Joshua's agent] The three items, re-run fresh at the current restacked head e2220ce rather than re-quoted: the contract runner was built natively from this PR's tree on a 16-inch M1 Max (zig 0.17.0, 1. Contract summary
2. Complete old-prefill byte comparison
3. Paired timings, guarded shader vs parentAlready in the receipt posted 2026-11-17 05:38Z (13-inch M1 ABBA medians at 1024/2048/4096 keys, eGPU run2 medians at document-256/1024; single-machine deltas only, no cross-machine A/B claimed). Nothing in the tile arithmetic changed since those runs, so I have not re-run them. CI at e2220ce: benchmark-clients, fmt and release-paths green; zig, zig-b, zig-windows, zig-macos-dev-tools and pytest were still pending when this was posted. |
|
[Joshua's agent] Fresh guarded-shader pair timings at the current heads, all runs through the jw16-gpu queue as class=perf rows, on the RTX 5060 Ti eGPU (16-inch M1 Max host, driver nvidia, nvidia_icd.json; gpu-timeouts 0 before and after). Different card from the 13-inch M1 and eGPU medians in the 2026-11-17 receipt — not mixed into any table. Binaries, built natively on the host (zig 0.17.0,
Method: 5 alternating parent/head pairs (ABBA) per case, one server process per rep, fitted prompt at the stated server keys, 256-token serial greedy, temperature 0.
Per-rep first-token ms — 256: parent [388, 393, 437, 391, 394], guarded [381, 386, 381, 384, 390]; 1024: parent [1007, 978, 983, 979, 987], guarded [917, 916, 920, 921, 917]. Each side produced one stable ids hash across all five reps. Receipts: One finding you should review: at 256 server keys the two arms' greedy token-id hashes differ — parent A scheduling note for honesty: the first ab256 attempt was stopped after 3 reps on request when another lane needed the GPU alone; its partial receipt is kept at |
|
[Joshua's agent] Root cause of the 256-key greedy-id split from the earlier follow-up: a one-bf16-ULP tie flip, not a large-margin tiling error. Same fitted 254-token prompt on both arms (base
So at 256 keys the head's tiled prefill rounds a one-ULP lead into a tie at step 185 — tiled summation order/rounding at the boundary, near-tie class, not a bug producing a confidently different token. |
|
[Joshua's agent] Closing the 256-key and general decode picture on this PR with a measured key curve for the same A/B pair (base Method: 100 receipt datasets (97 with JSON, 3 salvaged from REP lines), repeat matrix across four windows plus legacy one-shot median runs; 256 decode ids per rep; single ids-hash per window everywhere including A==B; every median traces to per-run rows. First-token ms, parent vs head (B/A ratio), pooled:
Interpretation: the head is faster at every measured key size, and the gain decays with context — from 4.2% at 512 keys to ~0.4% at 6144. So the measured direction supports the PR's claimed trend, while showing the benefit vanishing at scale. Per-window detail and every pooled receipt are archived in the lab notebook artifacts. |
|
Thanks @joshuaswarren for finding the 256-key split yourself and tracing it to step 185. The tiled path is the default for every prefill chunk of 2 to 64 rows ( Your note also says the logit rows before step 185 already differ by less than one bf16 step. So the difference starts in prefill, before the tie. The contract shows the tiled output equal to one-row decode, so its cases don't seem to reach the shape that differs. What we need:
We have no Vulkan device of this kind, so your posted runs are the evidence. If the tiled sums can't give the parent's bytes, please say so here before spending more time on timings.
|
|
[Joshua's agent] You're right: at |
|
Thanks @joshuaswarren for confirming the remaining parity problem and the comparison you plan to run. The current head still sends every 2–64-row prefill through Two owned shader comments also exceed 120 columns: The supplied diff also conflicts with current main in
|
|
Note 🤖 GPT-6.2-Sol responding on behalf of joshuaswarren I replayed SHA-256: With the NVIDIA ICD selected, each traced binary used: VK_DRIVER_FILES="$ICD" LD_LIBRARY_PATH="$NVIDIA_LIB" MESA_SHADER_CACHE_DISABLE=true \
timeout -k 5s 120s "$PROBE" --vendor 0x10de --timeout-ms 20000 --context 1024 "$MODEL" "$PROMPT" "$ORACLE" "$OUT"Both arms kept their original token and BF16 hashes. The first differing stage is isolated; the parity fix remains open. |
|
[Joshua's agent] Both points confirmed, with fresh evidence. Your reading of the layout is right: You are also right that the contract cases do not reach the divergent shape. We reran the attention contract today on a 13-inch M1 MacBook Pro (honeykrisp, boot pinned): 21 of 21 passed, including the tile 17-row and tile 64-row poison cases, each byte-identical to per-row decode - and the served 256-key divergence still exists on the same machine. So the byte gap lives outside the current case set, exactly as you said. What we are doing, in your order:
Parity evidence (the 256/512/1,024/2,048/4,096/6,144 hash matrix and the step-185 logits from both arms) posts from the new head once the fix lands, before any timing claim.
|
[Joshua's agent]
Stacked on #3417 (this branch contains that chain; the new commit is
4e9940aab, "gpu: tile prefill SDPA over 2..64-row chunks"). Review that commit only. Merge #3417 first.What it does
Prefill attention on Vulkan ran one query row per workgroup pass over every visible key. For a prefill chunk of 2 to 64 rows,
attend()now takes a tiled path (attendTiled) built from three kernels:sdpa_scores_tile,sdpa_softmax_rowsandsdpa_pv_tile. Scores go to an f32 scratch (stridemax_visible_keys), softmax runs per row, and PV keeps the old kernel's accumulation order. Chunks of 1 row (decode) and chunks over 64 rows keep the existing kernels and the #3417 long path.Measured, clean-tree builds (git archive of the base and of this head, same zig, same checkpoint)
Prefill wall time, base
a52027e0avs this head, alternating arms, 5 pairs plus warm-up on the 14-inch M2 Max and 3 pairs plus warm-up on the 13-inch M1:Not claimed
Part of #1420.