Repository navigation
ggml-openvino: keep stateful execution with -fa off - #361
Merged
cavusmustafa merged 2 commits 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-stateful-fa-off
branch
2 times, most recently
from
October 28, 2026 15:17
90ce648 to
c167c58
Compare
osabnis
force-pushed
the
ov-stateful-fa-off
branch
from
October 28, 2026 20:46
c167c58 to
e78d7ff
Compare
cavusmustafa
requested changes
Oct 28, 2026
osabnis
force-pushed
the
ov-stateful-fa-off
branch
from
October 28, 2026 21:07
1d6e908 to
1e075f6
Compare
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-stateful-fa-off
branch
from
October 29, 2026 17:44
1e075f6 to
d070186
Compare
Keep the V cache token-major in stateful mode instead of falling back to stateless execution. SET_ROWS appends to the state, and PERMUTE reads it back in the layout attention needs, so MUL_MAT does not transpose it. Dropping a reshape in grouped attention lets OpenVINO fuse it into SDPA. For padded V caches, slice after the transpose so the cache is read in place, without a copy that is recompiled for every KV length. This removes the stateless fallback for -fa off.
osabnis
force-pushed
the
ov-stateful-fa-off
branch
from
October 29, 2026 17:56
d070186 to
c23b626
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
Depends on #365
With
-fa off, llama.cpp writes the V cache transposed. Stateful execution did not support this layout, so these contexts fell back to stateless execution (ravi9/llama.cpp#346), where the KV cache stays in host memory and is read every token.This PR keeps the V cache token-major in stateful mode, like K, and removes the fallback.
[1, n_heads_kv, kv, head_size]and marks it soMUL_MATcan consume it without another transpose.-fa offpattern. Without the fusion, stateful execution was slower than the stateless fallback at short contexts.-fa off: stateless only" note fromdocs/backend/OPENVINO.md.Additional information
Tested on Panther Lake (Arc B390) and Arc B580 against OpenVINO master. Measured on 38d09d2 and rebased onto the current
dev_backend_openvino; the B580 accuracy check below was repeated after the rebase, with the same results.Decode performance
Stateful
-fa off,tg128tok/s on Panther Lake, before → after:* llama-bench's depth-4096 run rewinds the recurrent state of Qwen3.5, which stateful execution cannot do; before this change it ran only because the context fell back to stateless execution.
† llama-bench fails for Gemma-4 with
-fa offbefore and after this change, also in stateless mode. Its accuracy is covered below.With this change, stateful
-fa offdecodes at the speed of stateful-fa on(Llama-3.2 1B: 104.40 vs 105.08 tok/s at depth 0). The other three configurations (-fa onstateful/stateless and-fa offstateless) are unchanged: decode within -1.3% to +0.9%.Accuracy
KL divergence against the CPU backend (ctx 1024, one-token decode) for stateful
-fa offmatches stateless-fa offwithin 0.2% on Panther Lake for all six models with a reference: for example, Llama-3.2 1B 0.0406 vs 0.0406, Phi-4-mini 0.0356 vs 0.0357, Gemma-4 0.3634 vs 0.3635.On B580 the same holds for Llama-3.2 1B, Phi-3.5, Phi-4 and Gemma-4, with
-b 1024and with one-token decode (-b 1).Limitation
If a model pads V rows across layers and has more than one KV head per layer, the V slice still requires a reshape and copies the cache. None of the tested models hit this case; Gemma-4 has one KV head.
Requirements