Pull requests / #2351

#2351 Suffix-reuse: conversation KV prefix mount, quant-safe splices, state checkpoint ladder

open · @justindressler · 0 commentaires · Sur GitHub

AMD / HIPNVIDIA / CUDAModels & quantsDocumentation

Description

## Summary

Suffix-reuse for the conversation KV cache: reuse verified conversation prefixes across
requests, splices, and mid-history edits — built on v0.1.43 as a stack of three independent,
default-off flags. **All flags off = byte-identical engine behavior** (verified empirically
per commit).

**Three orthogonal features:**

1. **`--cache-suffix-reuse <N>`** — mount a parked previous conversation whose token prefix
   matches the incoming prompt (LCP-verified), narrowing the read window. Works across all
   five KV formats (fp16, int8, int8+KV_ROT, k8v4, q4_0) — splicing int8/k8v4/q4_0 through
   their exact quant/dequant paths so reused blocks stay byte-identical.
2. **`--prompt-cache-dense-tail <N>`** (FW-1) — dense checkpointing of the tail region so
   late-turn conversations restore cheaply.
3. **`--prompt-cache-state-every <N>`** (FW-2b) — state checkpoint ladder at a token cadence,
   capping the re-read gap after mid-history edits and compaction-style rewrites.

Full design, invariants, and measurement methodology: `docs/SUFFIX_REUSE.md` (in this PR).

## Results (RTX 3090 24 GB, Qwen3.8-Flash-Next abliterated GSQ-RCO IQ3_XXS, 131k ctx, MTP spec-4, temp 0)

| Suite | Base | This PR | Note |
|---|---|---|---|
| Needle-retention (3 seeds × 96) | 0.750 | 0.792 ± 0.042 | reward-neutral across seeds; seed-42 margin alone was an artifact — honestly documented |
| Mean prompt reuse (needle harness) | 0% | 15.5% | compaction-phase concentration documented |
| kv-store 4-family re-cert | — | kv 24/24, sudoku 15/15, log 15/24 | correctness ≥ base on all four families |
| KV-format sweep | — | 5/5 GREEN | fp16/int8/kvrot/k8v4/q4_0, identical reuse across formats (81.0% best) |
| Steady-state 3-turn | — | 160→161→162 correct, 89.3% token reuse, 3.4s vs 45.2s cold prefill |
| Needle A/B (state-every on/off) | 0.750 / 0.0% reuse | 0.833 / 25.2% reuse | same binary+seed+config, single-flag delta |

End-to-end behavior verified on a real interactive chat workload (mid-history edits,
regenerations, appends; thinking model, streaming): double-digit-to-near-full prompt reuse on
edit-shaped requests, prefill dropping from ~11.5s to 1–4s on cache hits, generation quality
and output length unaffected (prefill-only mechanism).

## Correctness invariants

- Off-flags → byte-identical outputs (A/B verified per layer, cross-binary diff = self-noise)
- Mounts only from **LCP-verified** prefixes; recurrence-state restore refuses any rung above
  the divergence point (fail-closed; stale-state probe from v3 development never reaches main)
- Splice paths for quantized formats round-trip through the format's own quant/dequant ops —
  reused K/V blocks are bit-equal to a full read's

## Review & verification

- Each layer independently code-reviewed (APPROVE, 0 blocking on the final layer; 3
  informational MINORs, all docs-adjacent)
- Fresh clean builds + CPU test suites green per layer (52/52 base, 82/0 group)
- 3-seed validation on the headline claim before shipping

## Not in this PR (deliberately)

- FW-2c session-local partial K/V splice (state-advance kernel) — parked with a full
  implementation plan in `docs/SUFFIX_REUSE.md` §10
- Engine-level disk persistence of the conversation pool — separate effort

**Note on base:** stack is built on `v0.1.43`; upstream has since tagged `v0.1.44` /
`v0.1.44.1`. Happy to rebase on request.

Sur le site

Liens install, modèles, releases.