[Proto] prefix checkpoint grid (512) fixes multi-turn restored=0
The prompt re-rendered by strata-ctl diverges on the last ~2 turn-tag tokens once turn 1 becomes history (live log: common_prefix=2644 vs checkpoint len=2646), so best_match (full-checkpoint prefix) discarded everything and turn 2 cold-prefilled. Save an intermediate checkpoint every 512 tokens during prefill (strata --auto-ckpt grid): turn 2 now restores the longest 512-grid checkpoint that is a full prefix (2560 for common=2644) and prefills only the new suffix (-93%). Verified: turn2 restored=1024 RESUME 1024, prefill 2631ms vs 25816ms cold (~9.8x), parity EXACT. Also enrich VETTA_DBG_PREFIX to log per-checkpoint common_prefix on a miss.
This commit is contained in:
1 parent
01d8a48d51
commit
ac31924ebb
1 file changed
+22
@@ -299,6 +299,16 @@ pub fn serve_gen(
|
||||
}
|
||||
if std::env::var("VETTA_DBG_PREFIX").is_ok() {
|
||||
eprintln!("[prefix] prompt_len={n_prompt} restored={start}");
|
||||
if start == 0 {
|
||||
// No match: show each cached checkpoint's length and how many leading
|
||||
// tokens it shares with this prompt, to pinpoint a token divergence
|
||||
// (common < len => the re-rendered prompt differs at that position).
|
||||
let p = eng.prefix.borrow();
|
||||
for (i, ck) in p.pool.iter().enumerate() {
|
||||
let common = ck.tokens.iter().zip(g.ids.iter()).take_while(|(a, b)| a == b).count();
|
||||
eprintln!("[prefix] ck[{i}] len={} common_prefix={common}", ck.tokens.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Weights are resident in eng.cache (loaded once at boot, reused across all
|
||||
@@ -342,6 +352,18 @@ pub fn serve_gen(
|
||||
history.extend_from_slice(toks);
|
||||
pos += take as i32;
|
||||
done += take;
|
||||
// Multi-level checkpoint grid (strata --auto-ckpt): save an intermediate
|
||||
// checkpoint every 512 tokens so the next turn can restore a stable prefix
|
||||
// even when the prompt's trailing turn-tag tokens re-render differently
|
||||
// (strata-ctl serializes the turn boundary differently once turn 1 becomes
|
||||
// history). best_match then picks the longest 512-grid checkpoint that is a
|
||||
// full prefix, instead of discarding everything over a 2-token tail mismatch.
|
||||
if std::env::var("VETTA_NO_PREFIX_CACHE").is_err() && pos > 0 && pos % 512 == 0 {
|
||||
let _ = eng.prefix.borrow_mut().save(&history[..pos as usize], &states, &eng.d);
|
||||
if std::env::var("VETTA_DBG_PREFIX").is_ok() {
|
||||
eprintln!("[prefix] grid save seq={pos}");
|
||||
}
|
||||
}
|
||||
let ms = t0.elapsed().as_secs_f64() * 1000.0;
|
||||
if let Ok(pp) = sess.on_prefill_chunk((start + done) as u32, n_prompt as u32, ms) {
|
||||
emit_all(emit, pp);
|
||||
|
||||
Reference in new issue
Block a user