sched: no step issued ahead behind a step that ends every request it carries

A pipelined engine issues each step's successor before the step is read back: block drafters
(DFlash, DFlash2) since 1.11.0, serial MTP and decoding without a drafter since 1.0.0. The step that
emits a request's last token therefore had one more step queued behind it, for a request its commit
then finishes. That step verifies nothing, yet the card runs its whole forward pass and the
drafter's context pass behind it, and a request that arrives once the last token is out -- a
single-stream client's next turn, sent as the reply ends -- waits for all of it before its prefill
starts. On Qwen3.8-27B ParoQuant int5 with DFlash2 on one R9700 that is about one decode step (34-53
ms) of TTFT on every back-to-back request (#225: 105 -> 139 ms); for 127 requests 1.12.0 ran 806
decode steps, all issued ahead, against 1.8.1's 680.

Scheduler::step_next_locked, beside the other rules for issuing ahead and before the next step's KV
is reserved, now issues nothing when the step just issued ends every request it carries: when it can
bring each to its max_tokens (certainly with the token it emits, possibly with the drafts it
verifies: output + 1 + drafts >= max_tokens), or, most likely, when those drafts hold an
end-of-generation id (ignore_eos requests excepted). The engine hands the scheduler the
end-of-generation ids at start (set_eog), the sorted list the card's acceptance reads. A guess that
misses (a drafted end the verify rejects, too few drafts accepted to reach max_tokens) costs one
step built after the commit instead of before it. Ends it does not predict still leave one step
behind: an end the verify chose itself, a stop string, the context limit. Without a drafter only
max_tokens ends are caught, exactly. At -v the commit names each request that ended with a step
issued ahead behind it (finish reason, its last step's tokens and accepted drafts, output against
max_tokens, whether its drafts held an end).

Tests: sched_test pins both halves (a drafted end issues and reserves nothing; a request whose next
token is its last, or whose token and accepted drafts could reach max_tokens, issues nothing; an
ignore_eos request's drafted end, drafts without an end, and a request that every draft accepted
would leave a token short still issue ahead; of two requests one going on, both issue ahead); the
test of a request finishing under a step issued ahead now ends it on an end of text the scheduler
cannot see coming. engine_e2e_test: two 32-token replies without a drafter are 62 decode steps, all
issued ahead, not 64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
AshlynandClaude Opus 5.5 authored and StillDeadcode committed 2026-10-26 09:18:33 +01:00
1 parent 55cf057a30
commit f55570e351
5 files changed
+150 -3

No files matched your search

+23
View File
@@ -1813,6 +1813,29 @@ TEST(decoding_without_a_drafter_issues_steps_ahead) {
CHECK_EQ(spec.stop(), 0);
}
/* The step that emits a request's last token issues nothing behind it: a step issued ahead for a
* request the commit then finishes verifies nothing, and the next request would wait out its
* forward pass (#225). A reply of 32 tokens is the prefill's token and 31 decode steps, each
* issued ahead of the one before it, and no 32nd. Twice, so the second request starts behind the
* first's last step. */
TEST(a_requests_last_step_issues_no_step_ahead) {
REQUIRE(world().ok);
Server plain;
REQUIRE(plain.start(world().lfm2, kPlain));
for (uint64_t seed : { 6, 7 }) {
const std::vector<int32_t> t =
tokens_of(post(plain.port, "/completion", completion(prompt_ids(seed, 80), 32)));
CHECK_EQ(t.size(), (size_t)32);
}
const double decode = metric(plain.port, "radiance:engine_steps_decode_total");
const double ahead = metric(plain.port, "radiance:engine_steps_ahead_total");
if (decode != 62.0 || ahead != 62.0)
fprintf(stderr, " decode steps %g, issued ahead %g\n", decode, ahead);
CHECK_EQ(decode, 62.0);
CHECK_EQ(ahead, 62.0);
CHECK_EQ(plain.stop(), 0);
}
/* Decoding a token runs the recurrent kernels over one row; prefilling it runs the chunked ones
* over the whole prompt. Each decoded position's probabilities must be what a cold prefill of the
* prompt and the tokens before it gives: exactly where both paths compute each row the same way