generate: STRATA_SPEC_TRACE, a per-round trace of the window rows, accepted drafts, round ms and MTP draft probabilities for offline window-length studies (bench only, off by default)

This commit is contained in:
Niko1221 committed 2026-10-21 13:46:06 +02:00
1 parent d276adf277
commit 651a56806a
1 file changed
+10
+10
View File
@@ -16199,6 +16199,10 @@ int main(int argc, char** argv) {
if (*q == ',') ++q;
}
}
// STRATA_SPEC_TRACE=<file> (bench only, off by default): one line per round, "T a sfx ms p1 p2 ..." (window rows, drafts accepted,
// lookup window, round ms, the MTP draft probabilities), for offline window-length policy studies
std::FILE* spec_trace = nullptr;
if (const char* tf = std::getenv("STRATA_SPEC_TRACE"); tf != nullptr && tf[0] != '\0') spec_trace = std::fopen(tf, "w");
std::vector<double> t_cycle_ms((size_t) o.spec + 1, 0.0);
std::vector<int64_t> t_cycle_n((size_t) o.spec + 1, 0), t_cycle_seen((size_t) o.spec + 1, 0);
// plan v0.3 P6: with a native pack the first window is the last prompt token alone (it produces the first
@@ -16415,6 +16419,11 @@ int main(int argc, char** argv) {
p += a + 1;
const double round_ms = std::chrono::duration<double, std::milli>(Clock::now() - t0).count();
total_ms += round_ms;
if (spec_trace != nullptr && timed_round) {
std::fprintf(spec_trace, "%d %d %d %.3f", T, a, from_sfx ? 1 : 0, round_ms);
for (int i = 0; i < T_mtp - 1; ++i) std::fprintf(spec_trace, " %.4f", (double) dprob[(size_t) i]);
std::fprintf(spec_trace, "\n");
}
if (!t_cycle.empty() && timed_round && T <= o.spec && t_cycle_seen[(size_t) T]++ > 0) {
t_cycle_ms[(size_t) T] += round_ms;
++t_cycle_n[(size_t) T];
@@ -16431,6 +16440,7 @@ int main(int argc, char** argv) {
return 1;
}
if (hashes != nullptr) std::fclose(hashes);
if (spec_trace != nullptr) std::fclose(spec_trace);
std::printf("%-24s %lld rounds of %d, drafts accepted %lld of %lld (%.3f), %.2f tokens per round\n",
"speculation", (long long) rounds, o.spec, (long long) drafts_ok, (long long) drafts_total,
drafts_total > 0 ? (double) drafts_ok / (double) drafts_total : 0.0,