core/sched: a prefix hit resumes on the cold run's chunk grid, so it recomputes the cold run's own chunks

A hit recomputes the tokens past where it resumes. Kernels may round a row differently at another
chunk length (spec §17: the fp8 GEMM's split-K count is chosen from M), so a hit that recomputes
its tail in other chunks than a cold prefill of the same prompt can flip a near-tie in greedy text.
On the DeepSeek-V4.1 daily (TP4) a 24k-token prompt that hit a 16k one's tail snapshot resumed at
15856, ran a 528-token chunk to the next boundary and answered differently from its cold run.

--prefix-resume exact, the default:

- ChunkGeometry carries the grid an idle server's cold prefill chunks on: --max-num-batched-tokens
  rounded down to the quantum, or the checkpoint interval where chunks split at it and it is the
  smaller, times the span from the second interval on.
- plan_chunk writes checkpoints only on that grid. A prompt's tail snapshot is taken where its last
  chunk starts (sliding-window snapshots keep their one-block margin) instead of at its last
  quantum boundary. The chunk already ends there, so a long cold prompt no longer runs a short
  extra step at its end.
- A checkpoint interval past the chunk must be a multiple of it; otherwise it is rounded up, and
  startup says so.
- admit_one steps a hit with no snapshot to resume from (full attention) back to the grid. A
  request's own checkpoint (Request::checkpoint_at, /v1/systemone's shared head) is honored where
  it falls.

--prefix-resume nearest keeps the previous rule.

The cost is re-prefill: an exact repeat runs the cold run's last chunk again, and an agent's next
turn resumes where the previous prompt's last chunk started, about half a chunk more than nearest
(2048 tokens at a 4096-token budget). The property holds on an idle server; a prefill that shares
its steps with decode rows or other requests (--busy-prefill-chunk, --prefill-interleave) is cut
differently, as batching already changes greedy text.

Tests: sched_test covers the grid for six geometries (GDN hybrid, interval past the budget, span,
periodic and tip-only window snapshots, full attention), the interval rounding, the tail snapshot
at the last chunk start, admission stepping back to the grid, and a property over prompt lengths:
every checkpoint is a chunk start of the cold run of its prompt and of any longer prompt it
prefixes, and a hit from it cuts the cold run's chunks. config_test covers the flag.
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-28 12:50:54 +01:00
1 parent f43929ccb8
commit 662b7720b5
9 files changed
+449 -4

No files matched your search

+16
View File
@@ -167,6 +167,11 @@ static const Flag g_flags[] = {
" one, for each of --max-num-seqs, within an eighth of host\n"
" memory. N fixes the total; 0 keeps none" },
{ "--no-prefix-cache", nullptr, "disable prefix caching" },
{ "--prefix-resume", "MODE", "where a prefix hit resumes: exact (default) only where\n"
" an idle server's cold prefill of the prompt starts a\n"
" chunk, so the hit answers bit-identically to a cold run;\n"
" nearest at the deepest snapshot, up to a chunk less to\n"
" re-prefill" },
{ "--checkpoint-policy", "NAME", "which snapshots a session retains: geometric-backoff "
"(default), tip-only, keep-all" },
@@ -682,6 +687,15 @@ int config_parse(int argc, char** argv, Config* c) {
}
}
else if (S("--no-prefix-cache")) c->prefix_cache = false;
else if (S("--prefix-resume")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!std::strcmp(v, "exact")) c->prefix_exact = true;
else if (!std::strcmp(v, "nearest")) c->prefix_exact = false;
else {
RAD_ERR("--prefix-resume '%s' is not one of exact, nearest", v);
return RAD_E_INVAL;
}
}
else if (S("--checkpoint-policy")) {
if (!(v = need(i))) return RAD_E_INVAL;
/* Validated, so an unknown name does not silently fall back to the default. */
@@ -1182,6 +1196,8 @@ const ShowRow kShow[] = {
return c.checkpoint_slots < 0 ? std::string("auto") : num(c.checkpoint_slots); } },
{ "--no-prefix-cache", [](const Config& c) {
return std::string(c.prefix_cache ? "not given: prefix caching on" : "prefix caching off"); } },
{ "--prefix-resume", [](const Config& c) {
return std::string(c.prefix_exact ? "exact" : "nearest"); } },
{ "--checkpoint-policy", [](const Config& c) { return c.checkpoint_policy; } },
{ "--num-speculative-tokens", [](const Config& c) { return c.n_spec < 0 ? std::string("auto") : num(c.n_spec); } },
{ "--draft-window", [](const Config& c) { return std::string(draft_window_name(c.draft_window)); } },