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

+17 -1
View File
@@ -1060,6 +1060,21 @@ token when it sits at `i * block_size`. This engine changes two things:
On a model with sliding-window attention and no linear state, a checkpoint snapshots the window
behind a prompt's tail instead, and chunks are not split at the interval.
**Exact resume.** A hit recomputes the tokens past where it resumes, and a kernel can round a row
differently at another chunk length (§17), so a hit is bit-identical to a cold run of the same
prompt only if it recomputes the cold run's own chunks. With `--prefix-resume exact` (the default)
a hit resumes only on the grid an idle server's cold prefill chunks on: the budget's chunk
(`--max-num-batched-tokens` rounded down to the quantum), or the interval where chunks split at it
and it is the smaller, times the span from the second interval on. Every snapshot the scheduler
writes is on that grid: interval checkpoints (the interval, when past the chunk, is rounded up to a
multiple of it), and the prompt's tail snapshot, which is taken where its last chunk starts rather
than at its last quantum boundary. That boundary is one the cold chunk already ends on, so the tail
snapshot costs no extra step; an exact repeat re-prefills the last chunk, an appended turn that
chunk and its own tokens, up to one chunk more than `--prefix-resume nearest` (the deepest snapshot
or block). A hit with no snapshot to resume from (full attention) steps back to the grid. The
property holds for a prefill alone in its steps; one sharing its steps with other work is cut
differently, as greedy text under batching already differs (§17).
Snapshots are large (at a 2048-token interval a 128K session on Qwen3.5-27B is 64 checkpoints,
about 9 GiB), so retention is budgeted. Retention keeps the session tip, which an appending agent
transcript resumes from, and any snapshot a lookup resumed from since the tip was written, which a
@@ -1648,7 +1663,8 @@ It does not give bit-exactness. The fp8 GEMM's split-K finisher sums in index or
repeats, but the split count is chosen from `M`, so a row computed at `M = 1` and at `M = 8` can
differ in the last bits. A speculative decode can therefore diverge from a non-speculative one on a
near-tie, and a request at a different batch position can take a different reduction order. Nothing
pins it (§19.7).
pins it (§19.7). A prefix hit is held to the cold run's chunks (§7.3, exact resume), so on an idle
server it repeats the cold run's output.
---