mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #711] [CLOSED] kv: --kv k8v4 streams with --kv-resident #2781
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2781
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/711
Author: @T-Crypt
Created: 10/4/2026
Status: ❌ Closed
Base:
main← Head:feat/k8v4-kv-stream📝 Commits (1)
573fc26kv: --kv k8v4 streams with --kv-resident📊 Changes
9 files changed (+90 additions, -40 deletions)
View changed files
📝
include/strata/core/layer.hpp(+3 -8)📝
include/strata/kernels/kv_stream.hpp(+20 -3)📝
src/core/conversation_snapshot.cpp(+5 -3)📝
src/core/layer.cpp(+14 -8)📝
src/core/verify.cpp(+4 -2)📝
src/kernels/cuda/kv_stream.cu(+11 -1)📝
src/kernels/kv_stream_parity.cpp(+18 -6)📝
src/prefill/prefill.cpp(+14 -4)📝
src/program/generate.cpp(+1 -5)📄 Description
What
--kv k8v4(INT8 K + rotated Q4_0 V, 816 B/cell) now streams with--kv-resident N, like fp16, int8 and q4_0. Both refusals are gone (generate.cppand the backstop inqsa_state_init).How
The streaming machinery already moves a block as a list of byte runs (
runs_ofinkv_stream.cu), so K8V4 is a fourth format with three runs, and everything that moves blocks (resolve, copy, ring restore, prompt-path staging) takes it unchanged.KvFormatgainskKvHybrid = 3, the number conversation snapshots already use for K8V4. Its runs are K codes, K scales and V q4_0, andkv_block_bytesknows its size.qsa_kv_formatreturns it instead of exiting.kv_append_q8_step(k_q, k_q, ...),kv_append_q4_step(v_q4, v_q4, ...)). Two helpers inkv_stream.hpp,kv_hybrid_k_halfandkv_hybrid_v_half, give each half's host copy (and staging pool) in the shape those kernels expect. Both fields of a half point at the same array on purpose: the kernels test the K-side pointer for presence (if (host.k_q4 != nullptr)) and then pick K or V per lane, so a V half with onlyv_q4set would silently skip the host write. The decode (layer.cpp), verify-window (verify.cpp) and prompt (prefill.cpp) appends pass them.qsa_state_initallocates the host copy in the three runs, andtake_stagegives the prompt path's staging pool the K8V4 layout (pools_ofthen reads it as mode 3).setup.pyis unchanged and still keeps K8V4 unstreamed: a prebuilt engine without this refuses the pair, so turning it on there needs aMIN_ENGINEthat includes it. I left that for you to time.Tests
kv_stream_paritynow runs K8V4 too, with the engine's folded appends. Streamed and resident attention are bitwise equal: 306 batches, 702,021 block lookups, 70,449 misses, 0 failures, and the ring restore is identical. The other three formats are unchanged and still pass.k8v4 pos 130 n_q 8: streamed attention differs).kv_hybrid_parity: all pass.Measured
RTX 4090 24 GB (sm_89), i9-14900K, 31 GB RAM, Linux, CUDA 13. Qwen3.8-Flash-Next IQ2_XS,
--max-context 262144 --expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --mtp <rt> --resident-experts, one engine start per row. Long prompts are synthetic log lines with one planted line in the middle, and the answer was right in every row. "Decode at depth" is a ~300-token second turn on the cached prompt.--kv--kv-resident 32768--kv-resident 32768Streamed K8V4 holds 2.39 GiB of KV in pinned RAM, 95.7% of its KV block reads hit VRAM, and its freed VRAM went to 1,745 more expert slots (11,208 -> 12,953). Prompt-cache checkpoints were restored on the streamed K8V4 state (114,688 and 229,376 tokens reused) and decoded normally.
Single runs, so read the decode differences of a few percent as noise, except the short-decode gain, which comes from the larger expert cache.
Not tested
kv_stream.cu, so a HIP build should pick it up the same way it does for the other formats.--gpus). A port of this change on 2x V100 with a layer split reports wrong answers on short stateless prompts under k8v4 that int8 does not show (jmnargi/Strata-V100#34). Not reproduced on sm_89 yet; see the thread below.Tested by others
--kv k8v4 --kv-resident 20480, 2 GiB two-slot conversation cache: a 17-request smoke test passed, including a 57,745-token conversation restore after an unrelated request and an image prefix restore.kv_stream_parityandkv_hybrid_paritypass on that GPU. Built on v0.1.39 with #732, #733 (opt-ins off) and #749.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.