Hybrid K8V4 KV cache: INT8 K + Hadamard-rotated Q4_0 V (--kv k8v4)
K stays INT8 (unrotated - the attention scores stay exactly int8's), V uses the rotated q4_0 of kv_q4.hpp: 816 B per cell vs int8's 1,056. The K/V quantization asymmetry is the point: K enters through the softmax scores, V only through a softmax-weighted average (llama.cpp's q8_K/q4_V hybrids reason the same way). No new kernels: the append/gather entry points already select K/V by blockIdx.z and take 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). The fused attention gets KV_MODE 3 (K-side int8 loader, V-side q4); 0.1.22's tensor-core prompt path (qsa_prompt_attn) refuses the hybrid pools through its !v_q check and the old kernel runs - covered by the parity test. The MTP drafter stays INT8 (mtp.cpp toggles the format globals around its state creation, any ring shape); qsa_kv_format exits on a hybrid state rather than misreporting a layout (the kernels' own unsupported-geometry convention); the hybrid appends pass nullptr for the host mirror (mode 0 has none). setup.py excludes k8v4 from the whole auto-streaming decision (the engine refuses --kv-resident with it). kv_hybrid_parity: bitwise append/gather through a non-identity page table, step and batched mode-3 attention vs host references (<= 1.1e-07), and the qsa_prompt_attn refusal - all at machine precision; kv_q8/kv_q4 parity unchanged. Measured on a RTX 3090, Coder IQ1_M, 118.75k-token prompts, temp 0: decode 82-97 t/s (int8: 75; the band is draft-acceptance variance), prefill unchanged ~1,130-1,170 t/s, 26-needle seed 42 identical to int8's tokens, KV 1.39 GB at 131k (int8: 1.80). At --max-context 204800 on 24 GB: 1,024 t/s prefill, 82-91 t/s decode, 25/26 needles at 197.9k.
This commit is contained in:
1 parent
3945aac617
commit
3597c47ff8
10 files changed
+527
-65
No files matched your search
@@ -201,6 +201,12 @@ bool MtpDrafter::load(const std::string& rt_dir, const ModelGeometry& g, Session
|
||||
// window (plus the cells a round writes ahead of its queries) over a host copy, refilled on a resume. The host copy
|
||||
// is pinned after the expert arena has pinned what it could: if it does not fit, the K/V stays whole in VRAM.
|
||||
int64_t ring = (window > 0 && window < max_cells) ? window + 4 * (int64_t) max_t + 64 : 0;
|
||||
// K8V4 never applies to the drafter: its own attention paths (below, and verify.cpp) handle whole formats
|
||||
// only, whatever ring shape it takes (0, a window, or the -1 fully-resident fallback).
|
||||
const bool kv_hybrid_was = qsa_kv_hybrid();
|
||||
const bool kv_int8_was = qsa_kv_int8();
|
||||
qsa_set_kv_hybrid(false);
|
||||
if (kv_hybrid_was) qsa_set_kv_int8(true); // the drafter under --kv k8v4: plain INT8
|
||||
uint64_t sb = qsa_state_bytes(g, max_cells, false, ring);
|
||||
if (cudaMalloc(&state_arena_, sb) != cudaSuccess) { err = "mtp: the K/V state does not fit"; return false; }
|
||||
if (qsa_state_init(g, max_cells, state_arena_, st_, &ss.qsa_states[0], ring) == 0) {
|
||||
@@ -214,6 +220,8 @@ bool MtpDrafter::load(const std::string& rt_dir, const ModelGeometry& g, Session
|
||||
if (cudaMalloc(&state_arena_, sb) != cudaSuccess) { err = "mtp: the K/V state does not fit"; return false; }
|
||||
if (qsa_state_init(g, max_cells, state_arena_, st_, &ss.qsa_states[0], ring) == 0) { err = "mtp: state init failed"; return false; }
|
||||
}
|
||||
qsa_set_kv_int8(kv_int8_was);
|
||||
qsa_set_kv_hybrid(kv_hybrid_was);
|
||||
qsa_state_zero(st_, g, nullptr);
|
||||
cudaDeviceSynchronize();
|
||||
vram_ += sb;
|
||||
|
||||
Reference in new issue
Block a user