feat(kvflash): target-QK residency scorer (--kvflash-policy qk)#385
Open
dusterbloom wants to merge 2 commits into
Open
feat(kvflash): target-QK residency scorer (--kvflash-policy qk)#385dusterbloom wants to merge 2 commits into
dusterbloom wants to merge 2 commits into
Conversation
…kbench - common/kvflash_qk.h: Phase-0-validated scoring (pooled post-RoPE K x decode Q cosine, max-over-group-heads, layer-mean), seal-time pooling - graph: per-layer post-RoPE/post-FWHT Q capture into cache.q_cap - backend: policy=qk wiring (pool at seal, query at reselect) - test_kvflash --qkbench: LRU/drafter/QK arms, needle /16 + 4-fact cold-history probe with decoys, real-token filler
Contributor
There was a problem hiding this comment.
2 issues found across 12 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
- kvflash_qk_chunk_scores missing_score default 0.0 -> -2.0 (below the [-1,1] cosine-mean floor) so a no-info chunk never outranks a real chunk with negative query correlation in reselect() - unit test locks the default-sentinel ranking - README: server/ prefix on test_kvflash_qk.cpp path
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.
KVFlash target-QK residency scorer (
--kvflash-policy qk)Adds a third KVFlash residency policy that reuses the target model's own KV keys as the relevance index — no extra model resident, no separate scoring forward pass.
Score of a sealed chunk = mean over the full-attention layers of the max over (kv_head, group q-head) pairs of
cos(decode-Q, mean-pooled chunk-K), both post-RoPE (and post-FWHT when the K cache is rotated — the shared orthogonal transform preserves cosine, so it equals the unrotated-basis score).Why
The bounded KV pool (#373) needs a per-step "which chunks stay resident?" decision. Today's options:
The QK policy gets the drafter's selection quality at LRU's cost, because the keys it scores against were already computed and cached by the target.
Evidence — 3-arm gate
test_kvflash --qkbench, L=65536, pool=4096, Qwen3.6-35B-A3B-Q3_K_M, RTX 3090. One process per arm,arm=label verified in-log.QK matches drafter recall exactly (14/16 needle, 63/64 facts, 7/7 gold chunks resident) at 555× cheaper rescore, and decodes faster than the drafter arm (no 0.6B model resident). LRU is the control: free but recalls nothing.
Scope
kvflash_qk.hkernel = 195), ~382 LOC tests, +16 docs.test_kvflash_qk.cpp);--qkbenchis the end-to-end gate.Known limitations / follow-ups
kvflash_qk_policy_branches in the backend (not behind the scorer interface) — deliberately, since there's one query-capturing scorer. A second one should lift those into aKvFlashTargetScorerwith seal/step/reselect hooks.Branch sits directly on current
main(ahead 1, behind 0).