From 2838cbae46fb2990dd653dd19d24d64c34238ee7 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 28 Sep 2026 04:56:25 +0200 Subject: [PATCH] prompt path: never write into the borrowable cache slots while laying out (a resident expert was corrupted) When serving, the prompt path lays its buffers out at start in the expert-cache slots it may borrow, but those slots hold resident experts until a request lends them. Writing the MMQ row table at layout time overwrote part of a resident expert: decode later computed it on the GPU, and the first window that routed to it turned every logit into NaN ("!!!!" from mid-answer, e.g. at position 138 of an 86-token prompt, even with the prompt read through the windows). The table is written at the start of every prompt read, while the slots are lent. STRATA_DBG_NAN=1 also reports the first verify window with non-finite logits and the state a prompt leaves. --- src/core/verify.cpp | 16 ++++++++++++++++ src/prefill/prefill.cpp | 21 ++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/core/verify.cpp b/src/core/verify.cpp index 683ae354..e0f80a9a 100644 --- a/src/core/verify.cpp +++ b/src/core/verify.cpp @@ -854,6 +854,22 @@ bool Verifier::run(int T, const int32_t* tokens, int64_t pos0, PoolMultiFn pool, } } for (int t = 0; t < T; ++t) out[t] = ((volatile int32_t*) h_out_)[t]; + if (static const bool dbg = std::getenv("STRATA_DBG_NAN") != nullptr; dbg) { // debug: the first non-finite head + static bool reported = false; + if (!reported) { + std::vector h((size_t) T * (size_t) n_vocab_); + cudaMemcpy(h.data(), head_logits_, h.size() * 4, cudaMemcpyDeviceToHost); + for (int t = 0; t < T && !reported; ++t) { + int64_t bad = 0; + for (int64_t v = 0; v < n_vocab_; ++v) bad += !std::isfinite(h[(size_t) t * n_vocab_ + v]); + if (bad) { + reported = true; + std::fprintf(stderr, "strata dbg: verify window at position %lld, row %d: %lld of %lld logits non-finite " + "(token out %d)\n", (long long) pos0, t, (long long) bad, (long long) n_vocab_, out[t]); + } + } + } + } VDBG("window done\n"); ++windows; progress_at("decode"); diff --git a/src/prefill/prefill.cpp b/src/prefill/prefill.cpp index 9f7b20d2..297b70aa 100644 --- a/src/prefill/prefill.cpp +++ b/src/prefill/prefill.cpp @@ -555,7 +555,8 @@ bool Prefill::carve(size_t T, void* alloc) { m.bounds_dev = o.take((size_t) (2 * (NE + NE / MMQ_GROUP + 2)), ok); m.grp_gu = o.take(MMQ_GROUP * mp.gu_max + MMQ_TAIL, ok); m.grp_d = o.take(MMQ_GROUP * mp.d_max + MMQ_TAIL, ok); - if (ok) mmq::iota(m.ids_identity, (int64_t) (T * K), m.cs); + // (written at every run's start, not here: when serving, these are live expert-cache slots until a request + // lends them - a write now would corrupt a resident expert) if (!m.mmq_ctx) m.mmq_ctx = std::make_unique(); } m.ring = ring_slots(T); @@ -1363,6 +1364,24 @@ bool Prefill::run(const int64_t* tokens, int64_t n, int64_t pos0, std::string& e } ss.ple_prev[0] = prev[0]; ss.ple_prev[1] = prev[1]; + if (std::getenv("STRATA_DBG_NAN") != nullptr) { // debug: the state the prompt leaves for the token path + cudaStreamSynchronize(m.cs); + auto bad = [&](const float* d, int64_t n) { + std::vector h((size_t) n); + cudaMemcpy(h.data(), d, (size_t) n * 4, cudaMemcpyDeviceToHost); + int64_t c = 0; + double mx = 0; + for (float v : h) { c += !std::isfinite(v); if (std::isfinite(v)) mx = std::max(mx, (double) std::fabs(v)); } + std::fprintf(stderr, " %lld non-finite (max |x| %.3g)", (long long) c, mx); + }; + const int64_t last = (n - 1) % m.T; + std::fprintf(stderr, "strata dbg: prompt end: last residual row"); + bad(m.R + last * D, D); + if (ss.ple.ready()) { std::fprintf(stderr, "; PLE history"); bad(ss.ple.hist, (int64_t) strata::kernels::NG_HIST * strata::kernels::NG_HC_DIM); } + std::fprintf(stderr, "; GDN state 0"); + bad(ss.gdn_state, 64 * 1024); + std::fprintf(stderr, "\n"); + } if (cudaStreamSynchronize(m.cs) != cudaSuccess) { err = std::string("prefill: ") + cudaGetErrorString(cudaGetLastError()); return false;