mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #120] [CLOSED] --kv k8v4: hybrid KV cache — INT8 K + Hadamard-rotated Q4_0 V (816 B/cell) #2467
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#2467
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/120
Author: @orangeswim
Created: 9/29/2026
Status: ❌ Closed
Base:
main← Head:kv-k8v4-hybrid📝 Commits (2)
629b546Hybrid K8V4 KV cache: INT8 K + Hadamard-rotated Q4_0 V (--kv k8v4)68fd4ecqsa_prompt_attn: mode 3 for hybrid K8V4 - int8 K, V dequantized from q4 at gather📊 Changes
11 files changed (+599 additions, -80 deletions)
View changed files
📝
CMakeLists.txt(+4 -0)📝
include/strata/core/layer.hpp(+15 -0)📝
setup.py(+10 -5)📝
src/core/layer.cpp(+55 -14)📝
src/core/mtp.cpp(+8 -0)📝
src/core/verify.cpp(+9 -2)📝
src/kernels/cuda/qsa_decode_attn.cu(+58 -37)📝
src/kernels/cuda/qsa_prompt_attn.cu(+60 -17)➕
src/kernels/kv_hybrid_parity.cpp(+356 -0)📝
src/prefill/prefill.cpp(+11 -3)📝
src/program/generate.cpp(+13 -2)📄 Description
--kv k8v4: hybrid KV cache — INT8 K + Hadamard-rotated Q4_0 V (816 B/cell)Rebased on v0.1.21 (the multi-GPU layer split); all parity checks and the needle
benchmarks below re-run on it.
https://github.com/Niko1221/Strata/issues/116
What
A fourth
--kvchoice: K stays INT8 (unrotated — the attention scores stay exactly asprecise as
int8's) and V uses PR #21's rotated q4_0 (kv_q4.hpp). 816 B per cell vsint8's 1,056 (−23%) and q4_0's 576. The quantization-sensitivity asymmetry is the point:
K enters through the softmax scores (errors redirect attention), V only through a
softmax-weighted average (errors are damped) — the same reasoning behind llama.cpp's
q8_K/q4_V-style hybrids.
How
blockIdx.zandtake separate K/V pointers, so the hybrid composes the existing validated q8/q4 kernels
with the unused half's lanes folded onto the used pool (a bit-identical duplicate write;
~µs of redundant work per token). The fused decode/prefill/verify attention
(
attn_chunk_kernel) getsKV_MODE == 3: the K loader takes the int8 branch (load8 isK-only today), the inline V loop already falls into the q4 branch. Only V and the output
are Hadamard-rotated; q is not, so
<q, k>needs no rotation.QsaState::kv_hybridusesk_q/k_scale+v_q4; sizing/init/zero/poolshandle it. The MTP drafter stays INT8 under this setting (mtp.cpp toggles the format
globals around its state creation, whatever ring shape it takes) so the kv_stream/kv_ring
block movers never see the hybrid layout.
--kv-residentstreaming is refused with it.--kv k8v4accepted; the streaming RAM math uses 816 B/token.Tests
New
kv_hybrid_parity(built alongside kv_q8_parity/kv_q4_parity): bitwise append/gatherchecks through a non-identity page table against host references (INT8 rules with
ties-to-even; rotated q4_0 rules), and mode-3 attention — step and batched forms, the
latter with per-query step arrays as verify uses it — against a host attention over the same
dequantized K/V. All checks pass at machine precision (≤ 1.1e-07); kv_q8_parity and
kv_q4_parity are unchanged.
Measured (RTX 3090 24 GB, Coder IQ1_M, 118.75k-token prompts, temp 0)
Decode moves ±10% between runs (draft acceptance varies with the generated text), so the
honest band at 119k is 82–97 t/s against int8's 75; the needles reproduce exactly. The gain
is larger than the expert-cache headroom alone would predict because the q4 V side also
halves the attention's V-gather bytes (144 vs 256 B per head per cell).
At
--max-context 204800on the same 24 GB card: 1,024 t/s prefill, 82.1 t/s decode,25/26 needles at 197.9k tokens (two seeds), fact-check follow-ups correct.
Not included (kept out on purpose)
--kv-resident): refused for now; the hybrid block layout wouldneed its own mover in kv_stream.cu.
whole-format.
AI tooling
Work assisted with Claude-code using GLM-5.3
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.