[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).
This commit is contained in:
adm committed 2026-12-01 20:30:13 +01:00
1 parent f12281ec61
commit 736c541887
6 files changed
+220 -10

No files matched your search

+4
View File
@@ -34,6 +34,10 @@ int vetta_buf_alloc(void** out, size_t bytes);
int vetta_buf_free(void* p);
int vetta_buf_h2d(void* dst, const void* src, size_t bytes);
int vetta_buf_d2h(void* dst, const void* src, size_t bytes);
// Device-to-device copies (prefix-checkpoint snapshot/restore).
int vetta_buf_copy(void* dst, const void* src, size_t bytes);
int vetta_buf_copy2d(void* dst, size_t dpitch, const void* src, size_t spitch,
size_t width, size_t height);
// k_rms_norm (kernel #2): y[row] = x[row] * rsqrt(mean(x^2)+eps) * w.
int vetta_rms_norm_f32(const float* x, const float* w, float* y,
+11
View File
@@ -71,6 +71,17 @@ extern "C" int vetta_buf_d2h(void* dst, const void* src, size_t bytes) {
HIP_CHECK(hipMemcpy(dst, src, bytes, hipMemcpyDeviceToHost));
return 0;
}
// Device-to-device copies for prefix-checkpoint snapshot/restore (KV prefix is a
// strided sub-block of the contiguous [n_kv, max_seq, hd] cache).
extern "C" int vetta_buf_copy(void* dst, const void* src, size_t bytes) {
HIP_CHECK(hipMemcpy(dst, src, bytes, hipMemcpyDeviceToDevice));
return 0;
}
extern "C" int vetta_buf_copy2d(void* dst, size_t dpitch, const void* src,
size_t spitch, size_t width, size_t height) {
HIP_CHECK(hipMemcpy2D(dst, dpitch, src, spitch, width, height, hipMemcpyDeviceToDevice));
return 0;
}
// ---- k_rms_norm (kernel #2): y = x * rsqrt(mean(x^2)+eps) * w --------------
// One block per row; block-wide reduction over D. f32 in/out.