Block FP32 vision attention value accumulation - #1019
Closed
Mikyx-1 wants to merge 1 commit into
Closed
Conversation
Mikyx-1
marked this pull request as draft
September 6, 2026 16:40
Author
|
Closing: I mistakenly benchmarked this optimization against main instead of dev. The reported 1.97× speedup does not apply to dev, which already uses a different FlashAttention implementation. |
Member
|
:) Sorry about that. Yes, main is quite a ways behind, but it would indeed have been a nice optimization prior to our Flash attention. |
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.
Gemma 3 vision attention on
maincallsMulByConstAndAddfor every query/source pair, repeatedly loading V and updating the output vector. This change packs V per head and computes four query rows together, keeping FP32 accumulators in SIMD registers and sharing V loads.Fixes #1018
Scope and implementation
dev. The current patch and measurements were developed againstmainat3ed403e;devhas replaced this loop with FlashAttention, so integration requires a port and fresh validation. The measurements below do not establish a speedup overdev.Measurement setup
-O3 -DNDEBUG).4b-it-sfp-padded.sbsweights.paligemma/testdata/image.ppm, resized to 896 × 896 (4,096 patches).mainbuild. Those changes are excluded from this PR.Image-encoder latency
1.97× faster image encoding; 49.3% lower latency (19.18 s saved per image).
Timing excludes model/image loading, resizing, language-model prefill, text generation, and output-file writes. Each pass recomputes the image embeddings; there is no previous-image cache.
Validation
mainheaders, and its four kernel tests passed.Measurements cover one image/model on this CPU with unlocked clocks; speed and numerical equivalence beyond the tested cases are not established.