Skip to content

graph : create V as a view of K in the k_iswa build_attn - #27392

Merged
ggerganov merged 1 commit into
masterfrom
gg/llama-graph-k-iswa-v-view
Aug 20, 2026
Merged

graph : create V as a view of K in the k_iswa build_attn#27392
ggerganov merged 1 commit into
masterfrom
gg/llama-graph-k-iswa-v-view

Conversation

@ggerganov

Copy link
Copy Markdown
Member

Overview

In build_attn for the llm_graph_input_attn_k_iswa input (MLA-style attention where the cached K is used as V), V was the cached K tensor itself. It is now created as a view of K (the first v_cur->ne[0] elements of each row), like the other K-only build_attn overloads (llm_graph_input_attn_k, llm_graph_input_attn_k_dsa).

All current callers (deepseek4 MTP block, dflash DSpark decoder) have equal K/V head sizes, so the view is full-size and the attention results are unchanged — V simply becomes a proper view of K, which lets backends detect the V-is-view-of-K pattern.

The deepseek4 MTP call site now passes the kv tensor as v_cur (it passed nullptr before).

Additional information

Related: #27390 (Metal FA: skip the redundant V dequant when V is a view of K)

Requirements

build_attn with the llm_graph_input_attn_k_iswa input was using the cached K
tensor itself as V. Create V as a view of K (the first v_cur->ne[0] elements
of each row), like the other K-only build_attn overloads.

The deepseek4 MTP call site now passes the kv tensor as v_cur.

Assisted-by: pi:llama.cpp/Qwen3.8-27B
@github-actions github-actions Bot added the model Model specific label Aug 19, 2026
@ggerganov
ggerganov requested a review from am17an August 19, 2026 14:51
@ggerganov
ggerganov marked this pull request as ready for review August 19, 2026 14:51
@ggerganov
ggerganov requested a review from CISC as a code owner August 19, 2026 14:51
@ggerganov
ggerganov merged commit 929d47a into master Aug 20, 2026
26 checks passed
@ggerganov
ggerganov deleted the gg/llama-graph-k-iswa-v-view branch August 20, 2026 07:00
@ggerganov

Copy link
Copy Markdown
Member Author

@am17an A quick look in the deepseek4.cpp seems that the V_is_K_view is not utilized for the compressed caches. Haven't looked yet in details, but it's likely something to fix. Making a simple view like in this PR does not seem to fix it, though I am not sure why.

therealkenc pushed a commit to therealkenc/llama.cpp that referenced this pull request Aug 24, 2026
)

build_attn with the llm_graph_input_attn_k_iswa input was using the cached K
tensor itself as V. Create V as a view of K (the first v_cur->ne[0] elements
of each row), like the other K-only build_attn overloads.

The deepseek4 MTP call site now passes the kv tensor as v_cur.

Assisted-by: pi:llama.cpp/Qwen3.8-27B
ravel7524 pushed a commit to ravel7524/llama.cpp that referenced this pull request Aug 30, 2026
)

build_attn with the llm_graph_input_attn_k_iswa input was using the cached K
tensor itself as V. Create V as a view of K (the first v_cur->ne[0] elements
of each row), like the other K-only build_attn overloads.

The deepseek4 MTP call site now passes the kv tensor as v_cur.

Assisted-by: pi:llama.cpp/Qwen3.8-27B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Model specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants