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.
This commit is contained in:
Niko1221 committed 2026-09-28 04:56:25 +02:00
1 parent 9ee557f781
commit 2838cbae46
2 files changed
+36 -1

No files matched your search

+16
View File
@@ -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<float> 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");
+20 -1
View File
@@ -555,7 +555,8 @@ bool Prefill::carve(size_t T, void* alloc) {
m.bounds_dev = o.take<int32_t>((size_t) (2 * (NE + NE / MMQ_GROUP + 2)), ok);
m.grp_gu = o.take<uint8_t>(MMQ_GROUP * mp.gu_max + MMQ_TAIL, ok);
m.grp_d = o.take<uint8_t>(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<mmq::Context>();
}
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<float> 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;