Repository navigation
ggml-openvino: support gemma-2 soft-capped attention - #362
Merged
cavusmustafa merged 1 commit intoOct 29, 2026
Merged
Conversation
ravi9
force-pushed
the
dev_backend_openvino
branch
from
October 26, 2026 21:41
674af4a to
9e01c2f
Compare
osabnis
force-pushed
the
ov-gemma2-soft-capping
branch
from
October 27, 2026 16:18
a129cdd to
7acab80
Compare
Collaborator
Author
|
Update:
Same KLD as on the B580 (0.0384 / 0.0375). |
ravi9
force-pushed
the
dev_backend_openvino
branch
2 times, most recently
from
October 29, 2026 17:37
be796d8 to
25e3135
Compare
osabnis
force-pushed
the
ov-gemma2-soft-capping
branch
from
October 29, 2026 17:44
7acab80 to
bb76930
Compare
Gemma-2 caps its attention scores as softcap * tanh(scores / softcap) before the softmax. FLASH_ATTN_EXT now applies the cap on the manual attention path, as SDPA has no soft-capping, and the decoder looks through the SCALE, TANH, SCALE chain of -fa off when it matches attention. One helper finds the K cache of an attention for both the sliding-window pre-pass and the main pass. The pre-pass copy did not see through the chain, so the sliding-window layers used the full-attention sizes once the context exceeded n_swa + n_ubatch. Soft-capped attention keeps the flat KV cache layout: with the 4-D layout the GPU plugin fails in its oneDNN path.
osabnis
force-pushed
the
ov-gemma2-soft-capping
branch
from
October 29, 2026 17:56
bb76930 to
a39bba2
Compare
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.
Overview
Gemma-2 caps its attention scores as
softcap * tanh(scores / softcap)before the softmax. The OpenVINO backend did not support this, so Gemma-2 gave wrong output in stateless mode with both-fa onand-fa off.-fa on): applies the soft-capping on the manual attention path, since OpenVINO's SDPA has no soft-capping.supports_opnow accepts soft-capped attention when Q, K and V share one head size.-fa off): the decoder looks through theSCALE,TANH,SCALEchain between the KQ product andSOFT_MAX.n_swa + n_ubatch(4096 + 512 tokens).-fa off, the attended tokens are taken from the last axis.GGML_OPENVINO_ENABLE_KV_4D): soft-capped attention keeps the flat KV layout, as the GPU plugin fails in its oneDNN path with the 4-D layout ("could not construct a memory descriptor using strides"). Same approach as the existing exclusion for-fa off.Additional information
Tested on Arc B580 with an OpenVINO master build from 2026-10-15, Gemma-2 2B Q4_K_M, before and after this change on the current
dev_backend_openvino.Accuracy (stateless)
KL divergence against the CPU backend:
-fa on, before-fa on, after-fa off, before-fa off, afterWith
GGML_OPENVINO_ENABLE_KV_4D=1the results are the same (0.0345 and 0.0343 at ctx 8192); before this change,-fa onfailed with it.Decode performance (stateless, after)
tg128tok/s at depth 0 / 4096:-fa on110.6 / 66.0,-fa off112.7 / 74.8.Stateful
Stateful execution works with this change but is not optimized: soft-capped attention cannot fuse into SDPA, so it runs as separate matmuls (
-fa on: 68.4 / 59.8 tok/s at depth 0 / 4096). With-fa off, stateful execution needs #361; without it, the context falls back to stateless as before.Requirements