Tune for this PC: setup --calibrate measures the PCIe share, draft floor and CPU workers
tools/calibrate.py starts the engine through serve's StrataEngine and measures decode speed with the three settings that depend on the machine: --pcie-frac and --spec-min-p through new per-request GEN keys (pcie_frac=, spec_min_p=; the server forwards a request's "strata_tune"), then 2-3 worker counts (a restart each). A setting is kept only when it beats the product default by more than 3% in an interleaved re-measurement. Setup offers it after an interactive install and runs it with --calibrate; the result is saved per PC + model + context in the settings file and re-applied when a config is written, so updates keep it. The engine's INFO line now says pool_workers, pcie_frac and spec_min_p. tools/test_calibrate.py tests it with a stand-in engine (no GPU).
This commit is contained in:
1 parent
069b92b38d
commit
c1afbdac8a
7 files changed
+489
-5
No files matched your search
@@ -2616,13 +2616,15 @@ int main(int argc, char** argv) {
|
||||
size_t free_b = 0, total_b = 0;
|
||||
cudaMemGetInfo(&free_b, &total_b);
|
||||
std::printf("INFO context=%lld kv=%s kv_resident=%lld expert_slots=%lld expert_cache_mib=%lld spec=%d "
|
||||
"mtp_max=%d lookup=%d vram_free_mib=%lld cvec=%s arena_mib=%lld engine=" STRATA_VERSION "\n",
|
||||
"mtp_max=%d lookup=%d vram_free_mib=%lld cvec=%s arena_mib=%lld pool_workers=%d pcie_frac=%.2f "
|
||||
"spec_min_p=%.2f engine=" STRATA_VERSION "\n",
|
||||
(long long) o.max_context, o.kv.c_str(),
|
||||
(long long) (g.n_qsa_layers() > 0 && ss.qsa_states[0].kv_mode == 1
|
||||
? ss.qsa_states[0].n_slots * 4 : 0),
|
||||
(long long) xcache.slots(), (long long) (xcache.bytes() >> 20), o.spec, o.mtp_max_t,
|
||||
o.suffix_draft, (long long) (free_b >> 20), cvec_summary.c_str(),
|
||||
(long long) (strata::kernels::cpu::expert_layout().total >> 20));
|
||||
(long long) (strata::kernels::cpu::expert_layout().total >> 20), pool.workers(), o.pcie_frac,
|
||||
o.spec_min_p);
|
||||
}
|
||||
// issue #29: a request whose heartbeat (tokens, prompt chunks, verify windows) stops for this long is stuck on
|
||||
// a flag nobody will raise - end the engine with where it was, so the server starts it again instead of the
|
||||
@@ -2692,6 +2694,9 @@ int main(int argc, char** argv) {
|
||||
float req_min_p = 0.0f, req_penalty_repeat = 1.0f, req_penalty_freq = 0.0f, req_penalty_present = 0.0f;
|
||||
int req_penalty_last_n = 0;
|
||||
int req_cvec = 1; // cvec=0|1: a loaded control vector for this request (on when absent)
|
||||
// tuning keys (setup's calibration measures settings without restarting the engine): the PCIe share of
|
||||
// the missed experts and the draft-probability floor, for this request only
|
||||
double req_pcie_frac = o.pcie_frac, req_spec_min_p = o.spec_min_p;
|
||||
if (endp != nullptr) { // GENI takes only cvec=; its file path is the first token without an =
|
||||
for (;;) {
|
||||
while (*endp == ' ') ++endp;
|
||||
@@ -2714,6 +2719,8 @@ int main(int argc, char** argv) {
|
||||
else if (key == "penalty_freq") req_penalty_freq = fv;
|
||||
else if (key == "penalty_present") req_penalty_present = fv;
|
||||
else if (key == "seed") req_seed = std::strtoull(tok.c_str() + eq + 1, nullptr, 10);
|
||||
else if (key == "pcie_frac") req_pcie_frac = std::clamp((double) fv, 0.0, 1.0);
|
||||
else if (key == "spec_min_p") req_spec_min_p = std::clamp((double) fv, 0.0, 1.0);
|
||||
// unknown keys are skipped: the ids start at the first token without '='
|
||||
}
|
||||
}
|
||||
@@ -3002,6 +3009,7 @@ int main(int argc, char** argv) {
|
||||
req_sp.penalty_present = req_penalty_present;
|
||||
req_sp.counter = 0;
|
||||
ver.set_sampling(req_sp);
|
||||
drive.d.pcie_num = std::max(0, std::min(256, (int) (req_pcie_frac * 256.0 + 0.5)));
|
||||
const int hist_n = std::min(req_sp.penalty_last_n, kPenaltyWindowCap);
|
||||
ver.set_history(hist_n > 0 ? d_hist : nullptr, hist_n);
|
||||
bool cancelled = false;
|
||||
@@ -3079,9 +3087,9 @@ int main(int argc, char** argv) {
|
||||
if (cancelled) finish = "cancel";
|
||||
while (!cancelled && produced_n < max_new) {
|
||||
int T = S_mtp;
|
||||
if (o.spec_min_p > 0.0) {
|
||||
if (req_spec_min_p > 0.0) {
|
||||
T = 1;
|
||||
while (T < S_mtp && dprob[(size_t) T - 1] >= (float) o.spec_min_p) ++T;
|
||||
while (T < S_mtp && dprob[(size_t) T - 1] >= (float) req_spec_min_p) ++T;
|
||||
}
|
||||
if (first_window) T = 1;
|
||||
// a repeat of earlier context (prompt lookup) where the MTP's own first guess agrees: the policy takes it
|
||||
@@ -3148,7 +3156,7 @@ int main(int argc, char** argv) {
|
||||
std::fflush(stdout);
|
||||
++rounds;
|
||||
const bool drafted = eos || produced_n >= max_new ||
|
||||
mtp.draft(T, outv.data(), p, a, drafts.data(), err, dprob.data(), (float) o.spec_min_p);
|
||||
mtp.draft(T, outv.data(), p, a, drafts.data(), err, dprob.data(), (float) req_spec_min_p);
|
||||
if (adapt_thr.joinable()) adapt_thr.join();
|
||||
if (!adapt_ok) {
|
||||
std::printf("ERR an adaptive refill failed\n");
|
||||
|
||||
Reference in new issue
Block a user