diff --git a/include/strata/core/progress.hpp b/include/strata/core/progress.hpp index 2dfedeb1..46c93783 100644 --- a/include/strata/core/progress.hpp +++ b/include/strata/core/progress.hpp @@ -19,6 +19,7 @@ struct Progress { std::atomic busy{false}; std::atomic where{"idle"}; std::atomic detail{-1}; + std::atomic chunk{-1}; ///< #251: the prompt chunk (its first position) a batched-read stage is in std::atomic since_ms{0}; ///< when `where` was set (steady clock): how long a stage has lasted std::atomic ticks{0}; ///< layers served: a window that still moves, slowly, against one that stopped }; @@ -44,10 +45,11 @@ inline Progress& progress() { return p; } -inline void progress_at(const char* where, int64_t detail = -1) { +inline void progress_at(const char* where, int64_t detail = -1, int64_t chunk = -1) { Progress& p = progress(); p.where.store(where, std::memory_order_relaxed); p.detail.store(detail, std::memory_order_relaxed); + p.chunk.store(chunk, std::memory_order_relaxed); p.since_ms.store(progress_now_ms(), std::memory_order_relaxed); } diff --git a/src/core/verify.cpp b/src/core/verify.cpp index 4d2ba3d5..595e24e1 100644 --- a/src/core/verify.cpp +++ b/src/core/verify.cpp @@ -156,9 +156,12 @@ bool Verifier::release_gpu_waits(int timeout_ms) { void Verifier::diag(std::FILE* f) const { auto rd = [](const uint32_t* p) { return p ? *(const volatile uint32_t*) p : 0u; }; - std::fprintf(f, " verify window: %d tokens at position %lld, host at layer step %u; the GPU rang %u; flags: " - "served %u, plan (A) %u, copies (B) %u\n", last_t_, (long long) last_pos0_, cur_layer_ + 1, - rd(h_seq_), rd(h_flag_), rd(h_flagA_), rd(h_flagB_)); + // #251: outside a verify stage these are the LAST window's numbers (it finished), not the stalled work's + const char* where = progress().where.load(); + const bool current = where != nullptr && std::strncmp(where, "verify window", 13) == 0; + std::fprintf(f, " verify window%s: %d tokens at position %lld, host at layer step %u; the GPU rang %u; flags: " + "served %u, plan (A) %u, copies (B) %u\n", current ? "" : " (last window, not the current stage)", + last_t_, (long long) last_pos0_, cur_layer_ + 1, rd(h_seq_), rd(h_flag_), rd(h_flagA_), rd(h_flagB_)); } Verifier::~Verifier() { diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index 116094ad..85f00cae 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -994,6 +994,7 @@ bool Prefill::run(const int64_t* tokens, int64_t n, int64_t pos0, std::string& e if (should_stop && should_stop()) { err = "cancelled"; return false; } if (std::getenv("STRATA_TRACE")) { std::fprintf(stderr, "strata trace: prompt chunk %lld of %lld\n", (long long) c0, (long long) n); std::fflush(stderr); } const int64_t T = std::min(m.T, n - c0), p0 = pos0 + c0; + core::progress_at("reading the prompt (batched): preparing the chunk from token", p0); // #251 ++stats_.chunks; pt.mark(kPfStart, cs); const auto tsetup = Clock::now(); @@ -1198,6 +1199,7 @@ bool Prefill::run(const int64_t* tokens, int64_t n, int64_t pos0, std::string& e bool normed = false; // F-2: the previous half's write already normed R for this half (grs, xn16) for (int64_t l = LB; l < LE; ++l) { core::progress_beat(); // the serve watchdog: a prompt chunk of 8192 tokens is still moving + core::progress_at("reading the prompt (batched): layer", l, p0); // #251: a stall names layer and chunk const core::LayerView v(*m.wt, l); // ---- the PLE block at layer 1, token by token (its conv reads the previous tokens' rows) if (l == 1 && ple_on && ple_batch) { @@ -1784,6 +1786,7 @@ bool Prefill::run(const int64_t* tokens, int64_t n, int64_t pos0, std::string& e stats_.experts_dma += iss_dma; } stats_.tokens += T; + core::progress_at("reading the prompt (batched): finishing the chunk from token", p0); pt.mark(kPfStart, cs); if (next_ != nullptr) { // the rows to the host buffer the next stage read two chunks ago (it has finished: waited below) diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 4dff6d14..15aaffce 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -722,11 +722,19 @@ MemSample mem_sample() { return m; } +// the stage the watchdog names: " ", and the prompt chunk a batched read is in (#251) +std::string stage_text() { + const strata::core::Progress& p = strata::core::progress(); + std::string s = std::string(p.where.load()) + " " + std::to_string((long long) p.detail.load()); + if (const int64_t c = p.chunk.load(); c >= 0) s += " of the prompt chunk from token " + std::to_string((long long) c); + return s; +} + void stall_report(std::FILE* f, uint64_t layers_during) { strata::core::Progress& p = strata::core::progress(); - std::fprintf(f, "strata serve: stall report (engine %s): stage \"%s %lld\" for %lld s; %llu layers served since the " - "last finished step (0 = stopped, more = slow)\n", STRATA_VERSION, p.where.load(), - (long long) p.detail.load(), (long long) ((strata::core::progress_now_ms() - p.since_ms.load()) / 1000), + std::fprintf(f, "strata serve: stall report (engine %s): stage \"%s\" for %lld s; %llu layers served since the " + "last finished step (0 = stopped, more = slow)\n", STRATA_VERSION, stage_text().c_str(), + (long long) ((strata::core::progress_now_ms() - p.since_ms.load()) / 1000), (unsigned long long) layers_during); for (int pass = 0; pass < 2; ++pass) { if (pass == 1) { @@ -4102,9 +4110,9 @@ int main(int argc, char** argv) { const uint64_t b = p.beats.load(); if (!p.busy.load() || b != last) { last = b; ticks_at = p.ticks.load(); since = now; continue; } if (now - since < std::chrono::seconds(limit)) continue; - std::fprintf(stderr, "strata serve: no progress for %d s during a request (%s %lld) - stopping " + std::fprintf(stderr, "strata serve: no progress for %d s during a request (%s) - stopping " "the engine so the server starts it again (issue #29)\n", - limit, p.where.load(), (long long) p.detail.load()); + limit, stage_text().c_str()); stall_report(stderr, p.ticks.load() - ticks_at); strata::core::release_gpu_waits(stderr); // #267: no spin kernel outlives the process std::fflush(stderr);