Follow-up to #51 / PR #57.
TurboQuantKvCache stores K/V in 3-/4-bit Lloyd-Max codebooks with per-block scale staging and a fixed-size FP32 attention window at the tail. Compositing SnapKV onto it gets ~16× total KV reduction (4× TQ × 4× position pruning) — the issue's headline use case for 12 GB cards at long context.
Scope
-
Score the TQ cache. TQ K is stored compressed; to score it against the last-W queries we either decompress on the fly per (head, position) or hoist the existing per-block staging path. The TQ attention kernel (CPU + CUDA + Vulkan) already does on-the-fly decompress at attention time — extend that same path to emit per-position softmax weights as a side output instead of (or in addition to) the attention output.
-
Compact the TQ cache. TQ blocks are fixed-size groups (32 or 64 tokens per block, see TurboQuantKvCache.cs). Compaction needs to either:
- Re-quantize after picking survivors (cleanest, preserves block invariants).
- Carry a per-block bitmap of kept positions and skip-evicted-positions in attention (simpler but no actual VRAM win for unevicted blocks).
Prefer re-quantization, since the issue's value is VRAM reduction.
-
FastScan compatibility. The CPU --tq path uses FastScan tiles (#34); confirm the compaction doesn't invalidate the per-block scale tables.
Acceptance
Notes
- The TQ layout doc lives in
docs/SharpInference-Design.md ("TurboQuant" section) — read before touching block boundaries.
Follow-up to #51 / PR #57.
TurboQuantKvCachestores K/V in 3-/4-bit Lloyd-Max codebooks with per-block scale staging and a fixed-size FP32 attention window at the tail. Compositing SnapKV onto it gets ~16× total KV reduction (4× TQ × 4× position pruning) — the issue's headline use case for 12 GB cards at long context.Scope
Score the TQ cache. TQ K is stored compressed; to score it against the last-W queries we either decompress on the fly per (head, position) or hoist the existing per-block staging path. The TQ attention kernel (CPU + CUDA + Vulkan) already does on-the-fly decompress at attention time — extend that same path to emit per-position softmax weights as a side output instead of (or in addition to) the attention output.
Compact the TQ cache. TQ blocks are fixed-size groups (32 or 64 tokens per block, see
TurboQuantKvCache.cs). Compaction needs to either:Prefer re-quantization, since the issue's value is VRAM reduction.
FastScan compatibility. The CPU
--tqpath uses FastScan tiles (#34); confirm the compaction doesn't invalidate the per-block scale tables.Acceptance
SHARPI_SNAPKV_BUDGET=2048+--tqon a 16 K prompt: total KV footprint drops ~16× vs fp16 baseline (Issue SnapKV-style prefill KV eviction (stacks on TurboQuant) #51 motivation).--tqalone.Notes
docs/SharpInference-Design.md("TurboQuant" section) — read before touching block boundaries.