sched: skip periodic window snapshots under tip-only

Treat tip-only as a true opt-out from periodic window snapshot creation and interval chunk splits, while retaining the existing tail snapshot and explicit request checkpoints. Leave recurrent-state scheduling unchanged and report the effective chunk bound accurately.

Cover geometric-backoff and keep-all interval behavior, tip-only chunk planning and single-snapshot reservation, aligned and short prompts, explicit checkpoints, and recurrent-state scheduling.
This commit is contained in:
John authored and StillDeadcode committed 2026-10-24 11:08:38 +02:00
1 parent 192fe10278
commit d6957e88a1
5 files changed
+69 -4

No files matched your search

+4 -2
View File
@@ -153,9 +153,11 @@ 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 /* 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 * when the interval is below --max-num-batched-tokens, raising the budget does not change the
* chunk; the log line makes that visible. */ * chunk; the log line makes that visible. tip-only window snapshots do not
* split at the interval, so their chunk is bounded by the token budget. */
const int64_t span_tok = g.checkpoint_interval * g.span; const int64_t span_tok = g.checkpoint_interval * g.span;
const int64_t eff = (g.checkpoint_interval > 0 && span_tok < cfg.max_tok) const bool periodic = !g.window_ckpt || cfg.checkpoint_policy != "tip-only";
const int64_t eff = (g.checkpoint_interval > 0 && periodic && span_tok < cfg.max_tok)
? span_tok : cfg.max_tok; ? span_tok : cfg.max_tok;
RAD_INFO("chunk geometry: quantum %lld (attn block %lld, state chunk %lld), checkpoint " 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", "interval %lld, max_tok %lld -> prefill chunks of at most %lld%s",
+2 -1
View File
@@ -53,7 +53,8 @@ struct ChunkGeometry {
/* No linear state but a sliding window: checkpoints snapshot the window behind an /* 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 * 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. */ * snapshots let an edited prompt resume below its divergence instead of from zero.
* tip-only skips interval snapshots and keeps the original tail-only chunking. */
bool window_ckpt = false; bool window_ckpt = false;
bool checkpoints() const { return checkpoint_interval > 0; } bool checkpoints() const { return checkpoint_interval > 0; }
+5 -1
View File
@@ -751,7 +751,11 @@ int64_t Scheduler::plan_chunk(int64_t n_computed, int64_t n_target, int64_t budg
if (geo_.checkpoints()) { if (geo_.checkpoints()) {
const int64_t I = geo_.checkpoint_interval; const int64_t I = geo_.checkpoint_interval;
int64_t next = ((n_computed / I) + 1) * I; /* strictly after n_computed */ int64_t next = ((n_computed / I) + 1) * I; /* strictly after n_computed */
if (geo_.window_ckpt) { if (geo_.window_ckpt && cfg_.checkpoint_policy == "tip-only") {
/* An explicit tail-only policy should not pay for intermediate
* window copies or chunk splits just to retire those snapshots. */
next = INT64_MAX;
} else if (geo_.window_ckpt) {
/* A tail-only window snapshot is unreachable after a prompt edit. /* A tail-only window snapshot is unreachable after a prompt edit.
* Keep interval checkpoints too; the ordinary retention policy bounds * Keep interval checkpoints too; the ordinary retention policy bounds
* their storage. Preserve the tail before the template's changed suffix, * their storage. Preserve the tail before the template's changed suffix,
+6
View File
@@ -1042,6 +1042,12 @@ does not support spans; there the flag only plans every step but a lone prefill
budget, and startup warns. Window snapshots are written at `--checkpoint-interval` boundaries budget, and startup warns. Window snapshots are written at `--checkpoint-interval` boundaries
as well as just before the prompt's end. The intermediate snapshots let an edited prompt resume as well as just before the prompt's end. The intermediate snapshots let an edited prompt resume
below its first changed token; `--checkpoint-policy` bounds the snapshots kept. below its first changed token; `--checkpoint-policy` bounds the snapshots kept.
For a window-only checkpoint model, `--checkpoint-policy tip-only` also skips
creating the intermediate snapshots and splitting chunks at their intervals, not
just retaining the tip afterward. This restores tail-only snapshot scheduling and
avoids the extra copies, at the cost of full re-prefill if an edit precedes the tip.
Recurrent-state models still checkpoint at intervals under `tip-only`; their
existing scheduling is unchanged.
**Sharing a step** (`--busy-prefill-chunk`, default `auto`). When other work is pending, a prefill **Sharing a step** (`--busy-prefill-chunk`, default `auto`). When other work is pending, a prefill
chunk leaves room for one row plus the draft window per decode row behind it, and a share of the chunk leaves room for one row plus the draft window per decode row behind it, and a share of the
+52
View File
@@ -347,6 +347,7 @@ TEST(chunk_geometry_refuses_a_budget_it_cannot_serve) {
* cannot serve a request whose last few hundred tokens changed: it is past the * cannot serve a request whose last few hundred tokens changed: it is past the
* divergence. Keep periodic snapshots as well, so lookup can resume below it. */ * divergence. Keep periodic snapshots as well, so lookup can resume below it. */
TEST(window_prefill_writes_interval_snapshots_before_the_tail) { TEST(window_prefill_writes_interval_snapshots_before_the_tail) {
for (const char* policy : { "geometric-backoff", "keep-all" }) {
Fixture f; Fixture f;
f.build(4096, 64, 512, 4096, /*windowed=*/true); f.build(4096, 64, 512, 4096, /*windowed=*/true);
f.prog.kv_groups.erase(f.prog.kv_groups.begin() + 1, f.prog.kv_groups.begin() + 3); f.prog.kv_groups.erase(f.prog.kv_groups.begin() + 1, f.prog.kv_groups.begin() + 3);
@@ -354,6 +355,7 @@ TEST(window_prefill_writes_interval_snapshots_before_the_tail) {
f.prog.buffers.resize(1); /* its derived conv/state indices do not apply either */ f.prog.buffers.resize(1); /* its derived conv/state indices do not apply either */
f.kv.setup(f.prog.kv_groups, f.cfg.max_ctx, 4096, 64); f.kv.setup(f.prog.kv_groups, f.cfg.max_ctx, 4096, 64);
f.pc.groups = { 0 }; f.pc.groups = { 0 };
f.cfg.checkpoint_policy = policy;
REQUIRE_EQ(f.start(), RAD_OK); REQUIRE_EQ(f.start(), RAD_OK);
CHECK(f.sch.geometry().window_ckpt); CHECK(f.sch.geometry().window_ckpt);
@@ -382,6 +384,56 @@ TEST(window_prefill_writes_interval_snapshots_before_the_tail) {
CHECK_EQ(ckpt, -1ll); CHECK_EQ(ckpt, -1ll);
CHECK_EQ(f.sch.plan_chunk(160, 1100, 160, &ckpt), 96ll); CHECK_EQ(f.sch.plan_chunk(160, 1100, 160, &ckpt), 96ll);
CHECK_EQ(ckpt, 256ll); CHECK_EQ(ckpt, 256ll);
}
}
/* tip-only is a window snapshot opt-out, not just retention after paying for
* copies which will be discarded. Match the original unsplit prefill schedule. */
TEST(tip_only_window_prefill_writes_only_the_tail_snapshot) {
Fixture f;
f.build(4096, 64, 512, 4096, /*windowed=*/true);
f.prog.kv_groups.erase(f.prog.kv_groups.begin() + 1, f.prog.kv_groups.begin() + 3);
f.prog.ops.resize(1);
f.prog.buffers.resize(1);
f.kv.setup(f.prog.kv_groups, f.cfg.max_ctx, 4096, 64);
f.pc.groups = { 0 };
f.cfg.checkpoint_policy = "tip-only";
REQUIRE_EQ(f.start(), RAD_OK);
CHECK(f.sch.geometry().window_ckpt);
int64_t ckpt = -1;
CHECK_EQ(f.sch.plan_chunk(0, 1100, 512, &ckpt), 512ll);
CHECK_EQ(ckpt, -1ll);
CHECK_EQ(f.sch.plan_chunk(512, 1100, 512, &ckpt), 512ll);
CHECK_EQ(ckpt, -1ll);
CHECK_EQ(f.sch.plan_chunk(1024, 1100, 512, &ckpt), 48ll);
CHECK_EQ(ckpt, 1072ll);
CHECK_EQ(f.sch.plan_chunk(1072, 1100, 512, &ckpt), 28ll);
CHECK_EQ(ckpt, -1ll);
CHECK_EQ(f.sch.plan_chunk(768, 1024, 512, &ckpt), 240ll);
CHECK_EQ(ckpt, 1008ll);
CHECK_EQ(f.sch.plan_chunk(0, 256, 512, &ckpt), 256ll);
CHECK_EQ(ckpt, -1ll);
/* Explicit request checkpoints must still be honored. */
CHECK_EQ(f.sch.plan_chunk(0, 1100, 512, &ckpt, 256), 256ll);
CHECK_EQ(ckpt, 256ll);
f.submit(1100, 1);
for (int i = 0; i < 8 && f.sch.step(); ++i) f.commit_plain();
CHECK_EQ(f.pc.reserved, 1);
CHECK_EQ(f.sch.metrics().checkpoints_written, 1ll);
}
TEST(tip_only_does_not_disable_recurrent_interval_checkpoints) {
Fixture f;
f.build();
f.cfg.checkpoint_policy = "tip-only";
REQUIRE_EQ(f.start(), RAD_OK);
CHECK(!f.sch.geometry().window_ckpt);
int64_t ckpt = -1;
CHECK_EQ(f.sch.plan_chunk(0, 1100, 512, &ckpt), 256ll);
CHECK_EQ(ckpt, 256ll);
} }
TEST(prefill_chunks_split_at_the_checkpoint_interval) { TEST(prefill_chunks_split_at_the_checkpoint_interval) {