Archived
sched: checkpoint sliding windows at prefill intervals
Keep intermediate window snapshots as well as the prompt-tail snapshot so a tail edit can resume below its divergence instead of re-prefilling the entire matched prefix. Reuse the existing checkpoint retention policy and preserve the pre-template-divergence tail boundary. Add scheduler and cache regression tests for interval snapshots, aligned prompt tails, constrained chunk budgets, and edited-prefix lookup. Update the geometry report and guide to describe periodic window snapshots.
This commit is contained in:
1 parent
9eaf10da6e
commit
192fe10278
6 files changed
+89
-16
No files matched your search
@@ -126,14 +126,14 @@ int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry
|
||||
* retention.
|
||||
*
|
||||
* Without linear state there are no checkpoints, except for a trunk window under a prefix
|
||||
* cache, which snapshots the window behind a prompt's tail (window_ckpt) without splitting
|
||||
* chunks. */
|
||||
* cache, which snapshots the window at interval boundaries and the prompt's tail
|
||||
* (window_ckpt). */
|
||||
if ((has_linear || (has_window && cfg.prefix_cache)) && cfg.checkpoint_interval > 0)
|
||||
g.checkpoint_interval = align_up(cfg.checkpoint_interval, g.quantum);
|
||||
else
|
||||
g.checkpoint_interval = 0;
|
||||
g.window_ckpt = !has_linear && g.checkpoint_interval > 0;
|
||||
/* A window snapshot splits no chunk (plan_chunk), so there is no interval grid to span. */
|
||||
/* Window checkpoints do not support skipping snapshots inside a prefill span. */
|
||||
g.span = (g.checkpoint_interval > 0 && !g.window_ckpt && cfg.prefill_span > 1)
|
||||
? cfg.prefill_span : 1;
|
||||
g.shared_tok = prefill_shared_tok(cfg);
|
||||
@@ -153,9 +153,9 @@ int chunk_geometry_resolve(const Program& prog, const Config& cfg, ChunkGeometry
|
||||
|
||||
/* Log the effective chunk length. `plan_chunk` splits at the checkpoint interval first, so
|
||||
* when the interval is below --max-num-batched-tokens, raising the budget does not change the
|
||||
* chunk; the log line makes that visible. A window snapshot splits nothing. */
|
||||
* chunk; the log line makes that visible. */
|
||||
const int64_t span_tok = g.checkpoint_interval * g.span;
|
||||
const int64_t eff = (g.checkpoint_interval > 0 && !g.window_ckpt && span_tok < cfg.max_tok)
|
||||
const int64_t eff = (g.checkpoint_interval > 0 && span_tok < cfg.max_tok)
|
||||
? span_tok : cfg.max_tok;
|
||||
RAD_INFO("chunk geometry: quantum %lld (attn block %lld, state chunk %lld), checkpoint "
|
||||
"interval %lld, max_tok %lld -> prefill chunks of at most %lld%s",
|
||||
|
||||
@@ -51,10 +51,9 @@ struct ChunkGeometry {
|
||||
/* Every contributor by name, for the startup line and the refusal. */
|
||||
std::string why;
|
||||
|
||||
/* No linear state but a sliding window: the checkpoint snapshots only the window behind a
|
||||
* prompt's tail (KVManager::has_window_snapshot). Chunks are not split at the interval, since
|
||||
* a mid-prompt window snapshot gains nothing; the interval is only the shortest prompt worth
|
||||
* a snapshot. */
|
||||
/* No linear state but a sliding window: checkpoints snapshot the window behind an
|
||||
* interval boundary or the prompt's tail (KVManager::has_window_snapshot). Intermediate
|
||||
* snapshots let an edited prompt resume below its divergence instead of from zero. */
|
||||
bool window_ckpt = false;
|
||||
|
||||
bool checkpoints() const { return checkpoint_interval > 0; }
|
||||
|
||||
@@ -751,7 +751,14 @@ int64_t Scheduler::plan_chunk(int64_t n_computed, int64_t n_target, int64_t budg
|
||||
if (geo_.checkpoints()) {
|
||||
const int64_t I = geo_.checkpoint_interval;
|
||||
int64_t next = ((n_computed / I) + 1) * I; /* strictly after n_computed */
|
||||
if (geo_.window_ckpt) next = INT64_MAX; /* a window snapshot: the tail only */
|
||||
if (geo_.window_ckpt) {
|
||||
/* A tail-only window snapshot is unreachable after a prompt edit.
|
||||
* Keep interval checkpoints too; the ordinary retention policy bounds
|
||||
* their storage. Preserve the tail before the template's changed suffix,
|
||||
* even when the prompt ends exactly on an interval boundary. */
|
||||
const int64_t tail = tail_checkpoint(n_target);
|
||||
if (tail > n_computed) next = std::min(next, tail);
|
||||
}
|
||||
/* A span (ChunkGeometry::span) starts only on an interval boundary past the first
|
||||
* interval, and its chunk is the span's intervals in a row, each the piece a span of 1
|
||||
* makes a chunk of its own. Not from a prompt's start: the first interval may be served on
|
||||
@@ -765,7 +772,8 @@ int64_t Scheduler::plan_chunk(int64_t n_computed, int64_t n_target, int64_t budg
|
||||
want = far - n_computed;
|
||||
else if (n_computed + want > next && n_computed + want < n_target)
|
||||
want = (n_computed + want) / I * I - n_computed;
|
||||
if (!geo_.window_ckpt && (n_computed + want) % I == 0) {
|
||||
if ((geo_.window_ckpt && n_computed + want == next) ||
|
||||
(!geo_.window_ckpt && (n_computed + want) % I == 0)) {
|
||||
if (checkpoint_pos) *checkpoint_pos = n_computed + want;
|
||||
} else if (n_computed + want == n_target) {
|
||||
/* Also one at the prompt's tail. The next turn resumes from the deepest snapshot
|
||||
|
||||
Reference in new issue
Block a user