diff --git a/data/settings-register.json b/data/settings-register.json index 550f63e689..35f32f8c9f 100644 --- a/data/settings-register.json +++ b/data/settings-register.json @@ -35468,13 +35468,13 @@ { "name": "STRATA_SERVE_STOP_BOUND", "backends": [ - "hip" + "cuda-hip" ], "reads": [ { "file": "src/program/generate.cpp", - "line": 18141, - "backend": "hip", + "line": 18199, + "backend": "cuda-hip", "fn": "getenv" } ], diff --git a/include/strata/core/serve_stop_bound.hpp b/include/strata/core/serve_stop_bound.hpp index f270b31988..2e1722c9ce 100644 --- a/include/strata/core/serve_stop_bound.hpp +++ b/include/strata/core/serve_stop_bound.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace strata::core { // A committed input row must correspond to an output the caller can expose. @@ -12,4 +13,11 @@ int serve_stop_bound(int accepted, int64_t remaining, const Token* outputs, IsEo if (is_eos(outputs[i])) return i + 1; return count; } + +// #4677: the bound is on by default on every backend; STRATA_SERVE_STOP_BOUND=0 (the variable's value, passed in) +// turns it off. It only limits which accepted rows enter the cached conversation: the tokens a request emits are the +// same either way. +inline bool serve_stop_bound_on(const char* env_value) { + return env_value == nullptr || std::strcmp(env_value, "0") != 0; +} } diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 34020b57ee..e40ce74d3d 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -33,9 +33,7 @@ #include "strata/core/expert_nibble.hpp" #include "strata/core/conversation_snapshot.hpp" #include "strata/core/lookup_default.hpp" -#if defined(STRATA_USE_HIP) #include "strata/core/serve_stop_bound.hpp" -#endif #include "strata/core/conversation_file.hpp" #include "strata/core/session_save_reclaim.hpp" #include "strata/core/conversation_memory.hpp" @@ -18195,14 +18193,10 @@ int main(int argc, char** argv) { if (fol_next < fol_sets.size() && !fol_sets[fol_next].empty()) fol = &fol_sets[fol_next]; ++fol_next; } -#if defined(STRATA_USE_HIP) - // on by default (HIP, where it was measured: 4 x R9700, Qwen3.8-Flash-Next IQ3_S, 0 of 16 continuations fell back to the older - // checkpoint against 4 of 16 without it, #4677); STRATA_SERVE_STOP_BOUND=0 turns it off - static const bool stop_bound = [] { - const char* v = std::getenv("STRATA_SERVE_STOP_BOUND"); - return v == nullptr || std::strcmp(v, "0") != 0; - }(); -#endif + // on by default on every backend (measured on HIP: 4 x R9700, Qwen3.8-Flash-Next IQ3_S, 0 of 16 continuations fell back to + // the older checkpoint against 4 of 16 without it, #4677; it changes no emitted token, only which accepted rows the + // session keeps); STRATA_SERVE_STOP_BOUND=0 turns it off + static const bool stop_bound = strata::core::serve_stop_bound_on(std::getenv("STRATA_SERVE_STOP_BOUND")); int64_t chain_windows = 0, chain_drafts = 0, chain_ok = 0; // --lookup-chain's own counts int64_t t2_rej[8] = {}, t2_hit[8] = {}; // STRATA_MTP_TOP2: rejections inside the MTP drafts by depth, runner-up hits int64_t dp_tested[8] = {}, dp_ok[8] = {}; // STRATA_SPEC_DEPTH=1: MTP drafts tested / accepted by depth @@ -18758,12 +18752,10 @@ int main(int argc, char** argv) { chain_kind = 0; int a = 0; while (a < A.T - 1 && A.tok[a + 1] == outp[(size_t) a]) ++a; -#if defined(STRATA_USE_HIP) if (stop_bound) a = strata::core::serve_stop_bound(a + 1, max_new - produced_n, outp.data(), [&](int32_t y) { return std::find(o.eos_ids.begin(), o.eos_ids.end(), (int64_t) y) != o.eos_ids.end(); }) - 1; -#endif if (!V1(A).pl_commit_async(a + 1, err)) return die(err); for (int i = 0; i <= a; ++i) consumed.push_back(A.tok[i]); draft_offered += A.T - 1; @@ -19300,14 +19292,12 @@ int main(int argc, char** argv) { if (!ver.window_logprobs(fol_tg.data(), a + 1, p, 248046, fol_lp, fe)) std::fprintf(stderr, "strata serve: STRATA_FOLLOW_LOGPOS: %s\n", fe.c_str()); } -#if defined(STRATA_USE_HIP) // A merged window contains prompt rows: every one must still be committed. // Otherwise do not cache accepted rows whose outputs this request cannot emit. if (stop_bound && !merged) a = strata::core::serve_stop_bound(a + 1, max_new - produced_n, outv.data(), [&](int32_t y) { return std::find(o.eos_ids.begin(), o.eos_ids.end(), (int64_t) y) != o.eos_ids.end(); }) - 1; -#endif if (from_sfx) { ++sfx_windows; sfx_drafts += T - 1; sfx_ok += a; } if (chain_n > 0) { ++chain_windows; chain_drafts += chain_n; chain_ok += std::max(0, a - (T_mtp - 1)); } if (!from_sfx && !first_window) diff --git a/tests/core/serve_stop_bound_test.cpp b/tests/core/serve_stop_bound_test.cpp index 5bf8534680..9485f6866d 100644 --- a/tests/core/serve_stop_bound_test.cpp +++ b/tests/core/serve_stop_bound_test.cpp @@ -27,5 +27,10 @@ int main() { ++cases; } assert(strata::core::serve_stop_bound(4, 0, static_cast(nullptr), [](int) { return false; }) == 0); + // on unless the variable is exactly "0" (every backend, since the bound left HIP-only) + assert(strata::core::serve_stop_bound_on(nullptr)); + assert(strata::core::serve_stop_bound_on("1")); + assert(strata::core::serve_stop_bound_on("")); + assert(!strata::core::serve_stop_bound_on("0")); std::cout << "SUMMARY stop_bound cases=" << cases << " passed\n"; }