Commit Graph
3 Commits
Author SHA1 Message Date
adm 47f8b52070 [Core] Flat VRAM: persistent KV states + SWA-window prefix checkpoints
a6 (persistent states): serve_gen allocated+freed ~3.75GB KV every request
(the +/-3.75GB sawtooth, max_new=16384). InklingEngine now holds persistent
per-layer states sized to a 4096-bucket cap >= prompt+max_new, reused across
requests and grown only on a bucket crossing. restore reuses a correctly-sized
state; a cold request resets the ShortConv hist rings (reset_history, async)
since the KV prefix is overwritten by prefill before any causal read. Verified:
two identical GEN16384 requests -> vram 23.46/23.49GB flat (no sawtooth),
identical reference output; twice-paris cold-reuse output identical.

a8 (SWA-window checkpoints): 40 of 48 KV pools are SWA (swa_win=1024) but the
snapshot stored the full seq_len on all of them (~510MB/checkpoint at seq2600).
Now SWA layers checkpoint only the last min(seq,1024) positions (kv_start offset
via new DeviceBuf::copy2d_at); full-attn layers keep the whole prefix. Checkpoint
~210MB. proofs/prefix_cache.lean Part D proves kvStart_le_winStart containment +
swa_window_restore_equiv (windowed restore observationally exact). Verified:
cold vs restored(1536, window truncated to [512,1536)) emit identical tokens.

Measured 5-turn VRAM climb +2.6GB -> +1.16GB (bounded by cap 8), KV flat.
Suite green: ld23 hip33 gw4 GPU serial, CPU -D warnings, Lean 0 sorryAx.
2026-12-02 02:52:32 +01:00
adm 736c541887 [GW][LD][HIP][Proofs] Wire prefix checkpoint cache into serve: restore longest prefix, prefill only new suffix
Concept ported from strata --auto-ckpt, adapted to vetta's contiguous per-pass
KV + ShortConv history (proofs/prefix_cache.lean, restore_equiv). serve_gen now
restores the longest cached STRICT prefix of a prompt and prefills only the new
suffix tokens; the final logits still come from a real forward of the last prompt
token. Checkpoints save at pos (prompt + generated non-EOS tokens) so the next
turn reuses the full prior context. Pinned anchors {512,1024} never evicted (I3),
LRU at cap 6; KV snapshots unpooled (freed on eviction). VETTA_NO_PREFIX_CACHE
forces cold prefill for A/B.

Device-to-device copy FFI (vetta_buf_copy / vetta_buf_copy2d) + DeviceBuf
copy_from/copy2d_from; LayerState snapshot/restore (pitched KV prefix + hist).

Verified: CPU 91 + gw GPU 5 + hip GPU 18 + ld GPU 18 green; Lean 0 sorryAx.
Multi-turn parity EXACT (restore == cold re-prefill), both prewarm- and
decode-state checkpoints. Measured (gfx1150, Inkling-2-Mini, FP16 KV, greedy):
605-token prompt, 600-token cached prefix -> prefill 132.5s cold vs 2.29s warm
(57.8x), end-to-end 133.2s vs 3.2s (41.8x).
2026-12-01 20:30:13 +01:00
adm f12281ec61 [Proofs] Prefix checkpoint cache: restore-equivalence + pool invariants (0 sorryAx)
Proof-first for the prefix-reuse cache adopted in concept from strata's
--auto-ckpt (reference proofs/auto_ckpt_pool.lean), adapted to vetta's contiguous
per-pass KV + ShortConv history (single conversation slot, no paged SWA ring).

Part A (correctness core): prefill is a causal fold; restore_equiv proves that
restoring a valid checkpoint and prefilling the suffix is observationally
identical to cold-prefilling prefix++suffix — this is what makes partial prefill
(only the new tokens) exact.
Part B: checkpoint validity is intrinsic and preserved by filter (invalidation)
and append.
Part C: auto-pool eviction — pinned anchors {512,1024} never evicted (I3), size
cap, no duplicate seq_len. Self-contained core lemmas (mem_of_find_some,
nodup_filter, length_filter_ne_lt); no Mathlib.

lean proofs/prefix_cache.lean: 0 errors, 0 sorryAx.
2026-12-01 20:15:19 +01:00