Skip to content

SnapKV + TurboQuant composition (#51 follow-up) #60

Description

@pekkah

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

  1. 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.

  2. 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.

  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions