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).
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.
- proofs/inkling_loop.lean: formal model of the Inkling-2-Mini physical forward
schedule (prelude [0,6) + core [6,18) x3 passes + coda [18,24) = 48 visits)
and its AttnRes deep-residual block cadence + multi-pass bank rollback,
extracted from the reference run_visit / core loop. 12 theorems + 5
computational examples, 0 sorryAx, standard axioms only:
* snapshot iff ip % blockSize(6) == 0; prelude snapshots {0}, core {6,12},
coda {18}; full schedule snapshots [0,6,12,18].
* prelude=1 block, core=2/pass, coda=1; final depth = 4 (earlier core passes'
blocks rolled back, not accumulated).
* totalVisits = 48.
* bank rollback restores the prelude depth (idempotent reset).
* controllers (has_msgs) active only on core passes p>0, never pass 0.
- This is the proof-first foundation (Federico's Lean rule for complex state
machines) for implementing the loop runner: the snapshot cadence and rollback
invariant are verified by construction before the implementation is written.
Verified: lean proofs/inkling_loop.lean green (0 sorryAx); all 5 proof files
green (slab_ring_dma, bus_lifecycle, serve_session, arena_plan, inkling_loop).