metal: add opt-in V skip for negligible attention weights#21119
Open
TheTom wants to merge 1 commit intoggml-org:masterfrom
Open
metal: add opt-in V skip for negligible attention weights#21119TheTom wants to merge 1 commit intoggml-org:masterfrom
TheTom wants to merge 1 commit intoggml-org:masterfrom
Conversation
Skip V dequantization and accumulation for positions where post-softmax attention weight < 1e-6. Reduces wasted dequant + FMA work when attention is sparse. Gated by GGML_METAL_FA_SKIP_V env var (default: off). Tested on q8_0 at 32K context (50 chunks, wikitext-103): no measurable PPL change (7.0638 ON/OFF, CI ±0.021).
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.
Summary
Adds an opt-in optimization to the Metal flash attention vec kernel that
skips V dequantization and accumulation for positions where the post-softmax
attention weight is below 1e-6.
Reduces wasted dequant + FMA work when attention is sparse.
Gated by GGML_METAL_FA_SKIP_V=1 environment variable (default: off).
No behavior change unless explicitly enabled.
Changes
Validation (Apple M5 Max, Qwen3.5-35B-A3B Q8_0)
Perplexity (wikitext-103, 32K context, 50 chunks):
SKIP_V=0: 7.0638 ± 0.021
SKIP_V=1: 7.0638 ± 0.021
Delta: 0.000
Decode (llama-bench, q8_0):
SKIP_V=0: 85.15 tok/s (tg128), 1142.93 tok/s (pp32768+tg128)
SKIP_V=1: 85.04 tok/s (tg128), 1144.78 tok/s (pp32768+tg128)
Within noise. No regression observed.
Scope
Notes
in this setup