engine: stream a step's tokens before the drafter's passes behind it end

Since 1.11.0 a block drafter's context and query passes (DFlash, DFlash2), like a serial drafter's
rounds (MTP), are queued behind the step before its readback, and the host waited for all of them
before it read the sampled ids. The ids' copy was already issued ahead of the passes, but the
commit that streams the tokens came only after the passes had run: every token, the first one
included, reached the client a drafter's passes late.

The copy now has an event of its own (tok_end_). collect_step waits on it, the commit streams the
tokens while the card runs the passes, and the step loop waits for the step's end (step_end_)
right after the commit, before finish_*_drafter reads the slots and before anything else is
issued. The commit issues no device work, so whatever it releases is in use only by the passes
that wait covers, and the next work that could reuse it is issued after the wait. KL mode and
embedding programs keep the old wait; RADIANCE_IDS_EARLY=0 restores it, for an A/B.

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:57 +01:00
1 parent f55570e351
commit bf6c019571
5 files changed
+72 -15

No files matched your search

+8 -1
View File
@@ -1966,6 +1966,11 @@ void Scheduler::promote_next() {
}
/* ------------------------------------------------------------------ commit */
/* With early ids (Engine::collect_step waits on tok_end_, not step_end_), this runs while the card
* may still be running the drafter's passes behind the step. So it issues no device work and
* allocates nothing: what it releases (KV blocks, StepSlot cards, prefix-cache publications) may
* still be read by those passes, and is reused only by work the engine issues after its wait for
* step_end_. Device work or an allocation added here must move behind that wait. */
int Scheduler::commit(const StepResult& res) {
std::lock_guard<std::mutex> lk(mu_);
if (!step_open_) return RAD_E_STATE;
@@ -2181,7 +2186,9 @@ int Scheduler::commit(const StepResult& res) {
/* Every entry is retired, so anything deferred on this step, or on a drafter snapshot that
* block_end() / serial_end() has since cleared, can be released: every pass naming them was
* issued before this step's readback, which waited for the compute stream. */
* issued before this step's readback. That readback may return while the drafter's passes
* behind it still run (Engine::StepOut::early), and the engine then waits for them before it
* issues anything else, so nothing reuses what is released here before they end. */
sweep_deferred();
return RAD_OK;
}