Skip to content

Feature/prefix attention return full kv - #1205

Merged
0xShug0 merged 2 commits into
0xShug0:mainfrom
apt-install-coffee:feature/prefix-attention-return-full-kv
Nov 5, 2026
Merged

0xShug0 merged 2 commits into
0xShug0:mainfrom
apt-install-coffee:feature/prefix-attention-return-full-kv

Conversation

@apt-install-coffee

Copy link
Copy Markdown
Contributor

Streaming decoders that carry a growing K/V prefix either concatenate the prefix with the new K/V for attention, or write the new K/V into a preallocated cache. In the shared decoder, DecoderLayerModule::build casts the (post-RoPE) prefix and concatenates it with the new tokens on every prefix path but returned only the new K/V, so a caller that wants the accumulated K/V as its next state had to rebuild the same node.

Change is opt-in with DecoderAttentionPolicy::prefix_state_returns_full_kv so only the callers that want the accumulated state need to change.

Only callers that reach this path with a non-null prefix could benefit: breeze_tts's fused depth loop, and higgs's prefill-with-cache-view call. Only breeze_tts has been changed here, since it is the only one tested.

The prefix attention path already concatenates the prefix K/V with the new
K/V for the attention:

    all_k = ConcatModule({1}).build(ctx, *attention_prefix_key, k);

but the layer state only handed back the *new* K/V, so a caller that needs the
prefix state again has to rebuild the same concatenation itself.

DecoderAttentionPolicy::prefix_state_returns_full_kv makes the prefix path
return the concatenation it already built. The flag is off by default: the
existing prefix-state callers (yue2/ar_runtime.cpp, audio8_tts/ar.cpp)
concatenate the returned K/V themselves and would otherwise duplicate the
prefix.

Co-Authored-By: Deepseek v4.1-Flash
The fused depth runtime rebuilt the prefix state by concatenating the prefix
K/V with the new K/V, which the decoder's prefix path had already
concatenated for its own attention. A rocprof trace of the shipped build
showed 648 concat_cont dispatches per audio frame, half of them redundant.

The runtime now uses the concatenation the decoder hands back
(prefix_state_returns_full_kv) as the next prefix state.

Measured on gfx1101, interleaved A/B of the two binaries, q8_0,
guidance_scale = 1.0, two rounds each: RTF 0.4757 -> 0.4641 (-2.4 %) and
36.13 -> 35.23 ms per AR frame (-2.5 %), with bit-identical output.

Co-Authored-By: Deepseek v4.1-Flash
@0xShug0
0xShug0 merged commit 845623d into 0xShug0:main Nov 5, 2026
7 checks passed
@0xShug0

0xShug0 commented Nov 5, 2026

Copy link
Copy Markdown
Owner

@apt-install-coffee Thanks! PR merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants