Repository navigation
Preserve FP32 partial sums in two-pass vector SDPA - #16
Merged
Merged
Conversation
This was referenced Sep 6, 2026
Member
Author
|
@codex review this |
davidtai
added a commit
that referenced
this pull request
Oct 5, 2026
Main #16 renamed the 2-pass vector SDPA kernels to sdpa_vector_2pass_fp32partials_*. The host builds "sdpa_vector_2pass_fp32partials_1_<type>_512_512", but the D512 instantiation still emitted "sdpa_vector_2pass_1_<type>_512_512", so every head-dim 512 call failed with "Unable to load function". Rename the instantiation. Replace the stale line reference to scaled_dot_product_attention.cpp with the symbol name. Add tests that compare with the reference attention: head dim 512 (16/2 and 4/4 heads, 7 to 8192 keys, with and without a mask), and the D512 GQA dedup kernel (8192 and 8201 keys) in a child process with DARKBLOOM_GEMMA4_D512_DECODE_2PASS_DEDUP=1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two-pass vector SDPA casts unnormalized partial sums to the input dtype before combining them. BF16 can lose cancellation residuals and FP16 can overflow even when the final attention output is representable. This patch keeps partial outputs in FP32 through the second pass and casts only the final result. Kernel entry names change so a stale shader cannot silently satisfy the new buffer contract.
The host intermediate allocation, ordinary/GQA first pass, second pass and Metal declarations change together. Python regression cases cover cancellation and overflow across D64/D128/D256, 32/128 partitions and masked/unmasked paths. Inputs and public output dtypes are unchanged. Low-precision intermediate storage grows to four bytes per element.
Before
After
Validation
e7b769e2713e48c53fb62fbe74e449bb409c8fc1b7e5f036b14e808a7c3da3f5: three Swift analytic tests passed all 50 internal subcases with zero skips. The new Python tests are included but are not claimed as executed.This is a new focused follow-up to merged #15. The companion Swift PR #21 regenerates embedded shader sources and pins this core commit; native PR #141 consumes that Swift revision. Parent PR #851 carries serving policy, regression integration and release evidence. No signing workflow or release publication is part of this PR.
Evidence: candidate D256 precision report, published with the companion parent update.