Verify: the commit graph no longer waits; it overlaps the MTP draft
The commit's cudaStreamSynchronize held the host ~0.45 ms a round. The next window follows it on the same stream and the drafter (its own stream) reads only this window's final rows and its own K/V, so a single-GPU session (Verifier::set_commit_async) returns at once. Whatever touches the session from another stream or the host afterwards synchronizes the device: the start of each --serve request (checkpoint restore, zeroing, the prompt path) and the end of a generate run; checkpoint saves already did. A layer split keeps the wait, as does STRATA_COMMIT_SYNC=1. IQ2_XS, 400-token answers, 3 runs each: 128.6 -> 135.8 tok/s decode (+5.6%), the same tokens. NVFP4 pack +0.8%.
This commit is contained in:
1 parent
272c16c767
commit
a1e4fb4c80
3 files changed
+20
-2
No files matched your search
@@ -119,6 +119,11 @@ public:
|
||||
|
||||
/// Keep the first `n_keep` (1..T) tokens of the last window; advances `ss.ple_prev` by them.
|
||||
bool commit(int n_keep, std::string& err);
|
||||
/// commit() returns without waiting for its graph (a single-GPU session sets it): the next window follows it on
|
||||
/// the same stream and the drafter reads nothing it writes, so it overlaps the draft. Whoever reads or writes
|
||||
/// the session from another stream or the host afterwards (a new request, a checkpoint) synchronizes the device
|
||||
/// first. STRATA_COMMIT_SYNC=1 keeps the wait.
|
||||
static void set_commit_async(bool on);
|
||||
|
||||
/// Measurement hook (STRATA_LOGPOS): after run(), write one line per row t of the last window's head -
|
||||
/// "pos target logprob top top_logprob hit extra_logprob target_logprob_without_extra" - where row t is the
|
||||
|
||||
+10
-2
@@ -1292,6 +1292,9 @@ bool Verifier::window_logprobs(const int32_t* targets, int T, int64_t pos0, int3
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace { bool g_commit_async = false; }
|
||||
void Verifier::set_commit_async(bool on) { g_commit_async = on && std::getenv("STRATA_COMMIT_SYNC") == nullptr; }
|
||||
|
||||
bool Verifier::commit(int n_keep, std::string& err) {
|
||||
const OnDevice on_device(device_);
|
||||
if (n_keep < 1 || n_keep > last_t_) { err = "verify: commit count out of range"; return false; }
|
||||
@@ -1302,8 +1305,13 @@ bool Verifier::commit(int n_keep, std::string& err) {
|
||||
std::atomic_thread_fence(std::memory_order_seq_cst);
|
||||
const cudaError_t le = cudaGraphLaunch(commit_exec_, cs_);
|
||||
if (le != cudaSuccess) { err = std::string("verify: commit launch: ") + cudaGetErrorString(le); return false; }
|
||||
const cudaError_t se = cudaStreamSynchronize(cs_);
|
||||
if (se != cudaSuccess) { err = std::string("verify: commit: ") + cudaGetErrorString(se); return false; }
|
||||
// set_commit_async: no wait here - the next window runs on the same stream after it, and the drafter (its own
|
||||
// stream) reads only this window's final rows and its own K/V. h_commit_ is next written after the next window's
|
||||
// results are read, i.e. after this graph has run.
|
||||
if (!g_commit_async) {
|
||||
const cudaError_t se = cudaStreamSynchronize(cs_);
|
||||
if (se != cudaSuccess) { err = std::string("verify: commit: ") + cudaGetErrorString(se); return false; }
|
||||
}
|
||||
if (ple_stage()) // stages that share one session must advance it once
|
||||
for (int t = 0; t < n_keep; ++t) {
|
||||
ss_->ple_prev[0] = ss_->ple_prev[1];
|
||||
|
||||
@@ -2054,6 +2054,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
}
|
||||
strata::core::Verifier::set_commit_async(!multi_gpu); // see Verifier::set_commit_async
|
||||
// ---- layer split across GPUs: each later stage's own copy of the dense weights, its session and (the last) the
|
||||
// head, made on its device before the host arena is mapped (as the drafter below, for the same WDDM reason)
|
||||
std::vector<std::unique_ptr<GpuStage>> stages;
|
||||
@@ -4607,6 +4608,9 @@ int main(int argc, char** argv) {
|
||||
return imgs_below(req_imgs, L) == pre_imgs;
|
||||
};
|
||||
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();
|
||||
int64_t resume = 0;
|
||||
bool from_live = false;
|
||||
if (o.prompt_cache > 0 && want_cvec == cvec_cached) {
|
||||
@@ -6016,6 +6020,7 @@ 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)
|
||||
|
||||
Reference in new issue
Block a user