verify: STRATA_LOGPOS hook for per-position teacher-forced log-probabilities

Verifier::window_logprobs writes one line per row of the last verify window's
head: position, target, its log-probability, the top token and its
log-probability, a hit flag, the log-probability of STRATA_LOGPOS_EXTRA
(default 248046, <|im_end|>) and the target's log-probability renormalized
without that token. read_windows calls it before commit when
STRATA_LOGPOS=<path> is set; otherwise the only cost is one null check.
A layer split's earlier stage forwards to the stage that holds the head,
under OnDevice as commit() does.
This commit is contained in:
Enky authored and Niko1221 committed 2026-09-30 20:35:02 +02:00
1 parent a3037d5435
commit 5396360ef7
3 files changed
+64

No files matched your search

+14
View File
@@ -4497,6 +4497,20 @@ int main(int argc, char** argv) {
if (drive.d.failed && drive.d.fail) e = drive.d.fail;
return false;
}
// STRATA_LOGPOS=<path>: the teacher-forced log-probability of every token read here (every
// token is committed and nxt[t] is the prompt's own next token), appended to <path>; the last
// column is the log-probability of STRATA_LOGPOS_EXTRA (default 248046, <|im_end|>), so the
// end-of-turn mass a chat model puts on raw text can be taken out of the measurement
static std::FILE* logpos = [] {
const char* p = std::getenv("STRATA_LOGPOS");
return p != nullptr ? std::fopen(p, "ab") : nullptr;
}();
static const int32_t logpos_extra = [] {
const char* p = std::getenv("STRATA_LOGPOS_EXTRA");
return p != nullptr ? (int32_t) std::atoi(p) : (int32_t) 248046;
}();
if (logpos != nullptr && !ver.window_logprobs(nxt.data(), T, q, logpos_extra, logpos, e))
return false;
if (!ver.commit(T, e) || !mtp.prefill(ver.final_R_all(), nxt.data(), T, q, e)) return false;
q += T;
}