#284 follow-up: wait for the async commit on an event, at every point that touches the session afterwards

The commit graph writes the GDN state and conv tail, the QSA indexer's tail/dead/pooled/block_pos and the PLE
history; with #284 it may still run when commit() returns. Verifier::commit records commit_done_ after it, and
Verifier::wait_commit() synchronizes that event (not the device; a no-op when nothing is pending, recursing into a
layer split's later stages). A layer split's first stage keeps the synchronous commit (next_ set).

Audited, and where the wait now is:
- the serve decode loop's end (end of turn, max tokens, STOP/cancel): wait before the live session, the state
  fingerprint (STRATA_STATE_HASH) and the DONE line - so the next request's park (conversation snapshot capture),
  restore, checkpoint restore and zeroing never see a running commit;
- the prompt read by verify windows (serve): wait at its end - the batched prompt path (other streams), prompt
  checkpoints (cudaDeviceSynchronize already) and snapshots may follow;
- the start of each serve request: an event wait replaces #284's cudaDeviceSynchronize (covers error paths);
- the end of a generate run: wait right after the decode loop, before the stats and the dumps (#284 synchronized
  only later, after the routing dump);
- unchanged and safe: the next window (same stream), the MTP draft (its own stream; reads the window's final rows
  and its own K/V, which commit does not write), the adaptive tier thread (expert slots and residency tables only),
  STRATA_LOGPOS / STRATA_DUMP_FIRST_LOGITS (read run()'s head logits after run() synchronized), QUIT and /unload
  (the Verifier destructor synchronizes its streams before freeing).
This commit is contained in:
Niko1221 committed 2026-10-01 08:34:33 +02:00
1 parent a1e4fb4c80
commit bd84d0bc6d
3 files changed
+46 -7

No files matched your search

+18 -3
View File
@@ -4609,8 +4609,12 @@ int main(int argc, char** argv) {
};
const bool want_cvec = strata::kernels::cvec().loaded() ? req_cvec != 0 : true;
// the last request's final commit may still be running on the verifier's stream (set_commit_async):
// everything below reads, restores or zeroes the session from other streams and the host
cudaDeviceSynchronize();
// everything below reads, restores or zeroes the session from other streams and the host (the end of the
// last request waited already; this covers a request that ended on an error path)
if (!ver.wait_commit(err)) {
std::printf("ERR %s\n", err.c_str());
return 1;
}
int64_t resume = 0;
bool from_live = false;
if (o.prompt_cache > 0 && want_cvec == cvec_cached) {
@@ -4802,6 +4806,8 @@ int main(int argc, char** argv) {
if (!ver.commit(T, e) || !mtp.prefill(ver.final_R_all(), nxt.data(), T, q, e)) return false;
q += T;
}
// the batched prompt path (other streams), checkpoints and snapshots may follow: the last commit first
if (!ver.wait_commit(e)) return false;
const double ms = std::chrono::duration<double, std::milli>(Clock::now() - pp_t0).count();
std::printf("PP %lld %lld %.0f %.1f\n", (long long) b, (long long) pp_total, ms,
ms > 0.0 ? 1000.0 * (double) (b - pp_from) / ms : 0.0);
@@ -5121,6 +5127,11 @@ int main(int argc, char** argv) {
p += a + 1;
}
const double decode_ms = std::chrono::duration<double, std::milli>(Clock::now() - d0).count();
// the last commit (set_commit_async): the session is complete before anything reads or copies it
if (!ver.wait_commit(err)) {
std::printf("ERR %s\n", err.c_str());
return 1;
}
if (dec_timing && dec_windows > 0) {
const DecSnap d1 = dec_snap();
const double w = (double) dec_windows, L = (double) g.n_layers;
@@ -5923,6 +5934,11 @@ int main(int argc, char** argv) {
std::fprintf(stderr, "strata generate: position %lld, %lld tokens, %lld rounds\n", (long long) p,
(long long) produced.size(), (long long) rounds);
}
// the last commit (set_commit_async) before anything reads the session again
if (!ver.wait_commit(err)) {
std::fprintf(stderr, "strata generate: %s\n", err.c_str());
return 1;
}
std::printf("%-24s %lld rounds of %d, drafts accepted %lld of %lld (%.3f), %.2f tokens per round\n",
"speculation", (long long) rounds, o.spec, (long long) drafts_ok, (long long) drafts_total,
drafts_total > 0 ? (double) drafts_ok / (double) drafts_total : 0.0,
@@ -6020,7 +6036,6 @@ int main(int argc, char** argv) {
for (int64_t t : produced) std::printf(" %lld", (long long) t);
std::printf("\n");
const double decode_ms = decoded > 0 ? total_ms / (double) decoded : 0.0;
cudaDeviceSynchronize(); // the last commit (set_commit_async) before anything reads the session
std::printf("%-24s %lld tokens in %.1f ms -> %.2f tok/s\n", "decode", (long long) decoded, total_ms,
decode_ms > 0.0 ? 1000.0 / decode_ms : 0.0);
if (n_prompt > 1)