From d8f58af1b5c2bc89d7735d55c8e418a11018521c Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Tue, 20 Oct 2026 20:10:56 +0200 Subject: [PATCH] generate: STRATA_SPEC_T_CYCLE, a bench-only cycle of the verify window size with a per-width cost line (off by default) --- src/program/generate.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/program/generate.cpp b/src/program/generate.cpp index dbc0cf83..d7116d2d 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -16187,6 +16187,20 @@ int main(int argc, char** argv) { std::vector drafts((size_t) o.spec, 0); std::vector dprob((size_t) o.spec, 1.0f); std::vector window_hist((size_t) o.spec + 1, 0); + // STRATA_SPEC_T_CYCLE=1,2,3,4,5,6,7,8 (bench only, off by default): the window size cycles through the list, so one run + // measures the cost of each verify width (with --spec-oracle drafts every row is accepted); the first round of a + // width (its graph capture) is not counted + std::vector t_cycle; + if (const char* tc = std::getenv("STRATA_SPEC_T_CYCLE"); tc != nullptr && tc[0] != '\0') { + for (const char* q = tc; *q != '\0';) { + const int v = std::atoi(q); + if (v >= 1 && v <= o.spec) t_cycle.push_back(v); + while (*q != '\0' && *q != ',') ++q; + if (*q == ',') ++q; + } + } + std::vector t_cycle_ms((size_t) o.spec + 1, 0.0); + std::vector 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 // generated token and the MTP's first cell); otherwise the token loop already did that. bool first_window = native_pack; @@ -16258,6 +16272,7 @@ int main(int argc, char** argv) { while (T < S_mtp && dprob[(size_t) T - 1] >= (float) o.spec_min_p) ++T; } if (first_window) T = 1; + if (!t_cycle.empty() && !first_window) T = t_cycle[(size_t) (rounds % (int64_t) t_cycle.size())]; bool from_sfx = false; int sfx_match = 0; if (o.suffix_draft > 0 && !first_window) { @@ -16400,6 +16415,10 @@ int main(int argc, char** argv) { p += a + 1; const double round_ms = std::chrono::duration(Clock::now() - t0).count(); total_ms += round_ms; + 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]; + } if (timed_round && chain_n == 0) policy.observe(from_sfx, T, a, sfx_match, round_ms); else if (timed_round) policy.observe_chain(T_mtp, chain_n, a, cm, round_ms); if (rounds % 64 == 0) @@ -16430,6 +16449,12 @@ int main(int argc, char** argv) { if (o.lookup_chain > 0) std::printf("%-24s %lld windows, chained drafts accepted %lld of %lld\n", "lookup chain", (long long) chain_windows, (long long) chain_ok, (long long) chain_drafts); + if (!t_cycle.empty()) { + std::printf("%-24s", "window cost (ms/round)"); + for (size_t i = 1; i < t_cycle_ms.size(); ++i) + if (t_cycle_n[i] > 0) std::printf(" T%zu:%.2f(n=%lld)", i, t_cycle_ms[i] / (double) t_cycle_n[i], (long long) t_cycle_n[i]); + std::printf("\n"); + } std::printf("%-24s", "accepted per round"); for (size_t i = 0; i < accepted_hist.size(); ++i) std::printf(" %zu:%lld", i, (long long) accepted_hist[i]); std::printf("\n");