kv: --kv k8v4 streams with --kv-resident

K8V4 (INT8 K + rotated Q4_0 V, 816 B/cell) was refused with --kv-resident. It now streams like
the other formats:

- kv_stream: a fourth block format, kKvHybrid (= 3, the number conversation snapshots already
  use for K8V4), moved as three runs per block - K codes, K scales, V q4_0 - by the same resolve,
  copy, ring-restore and stage paths; kv_block_bytes knows its size.
- kv_hybrid_k_half / kv_hybrid_v_half: each half of the host copy (and of the prompt path's
  staging pool) as the single-format append kernels see it, so a hybrid layer's host copy is
  written by the same folded calls that write its VRAM pools. Both fields of a half point at the
  same array: the kernels test the K-side pointer for presence and pick K or V per lane.
- The decode (layer.cpp), verify-window (verify.cpp) and prompt (prefill.cpp) appends pass those
  halves; the prompt path's staging pool gets a K8V4 layout; the host copy is allocated in it.
- Conversation snapshots read a streamed K8V4 state's host copy, as they do for the others.
- qsa_kv_format returns kKvHybrid instead of exiting; the two refusals are gone.

setup.py still keeps K8V4 unstreamed: enabling it there needs a MIN_ENGINE that has this.

Tests: kv_stream_parity runs K8V4 too (streamed vs resident attention, bitwise): 306 batches,
70,449 misses, 0 failures, ring restore identical; a negative control (the V half's K-side
pointer left null) fails it from the first batch. kv_hybrid_parity: all pass.
This commit is contained in:
Trevin authored and Niko1221 committed 2026-10-05 19:57:34 +02:00
1 parent 65fc896329
commit fea9ff5a4d
9 files changed
+90 -40

No files matched your search

+1 -5
View File
@@ -645,7 +645,7 @@ void usage() {
" --kv q4_0 4-bit K/V after a Hadamard rotation (PR #21): half of int8's memory,\n"
" slightly lower precision (see bench/results/2026-09-27-kv-q4)\n"
" --kv k8v4 hybrid: INT8 K (exact attention scores) + rotated Q4_0 V, 816 B/cell\n"
" (vs int8's 1,056); not with --kv-resident\n"
" (vs int8's 1,056); streams with --kv-resident too\n"
" --kv-resident N KV streaming: keep N cells of each QSA layer in VRAM (min 20480) and the\n"
" whole K/V in pinned RAM; the freed VRAM goes to expert slots. 0 (default):\n"
" all of it in VRAM. A context of N cells or fewer is not streamed\n"
@@ -2012,10 +2012,6 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: --kv-resident must be >= 0\n");
return 2;
}
if (o.kv == "k8v4" && o.kv_resident > 0) {
std::fprintf(stderr, "strata generate: --kv k8v4 does not support --kv-resident streaming (yet)\n");
return 2;
}
strata::core::qsa_set_kv_resident(o.kv_resident);
// Prompt lookup (the suffix drafter, on by default): the MTP keeps its --spec windows and a lookup window may be
// up to 2 tokens longer; the draft policy (strata/spec/draft_policy.hpp) takes one only where it pays. Code