mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
prefill, serve: the CPU prompt share is learned once and kept in the draft cost table file (opt-in)
The default CPU prompt share (prompt chunks under the share's limit, CUDA one card and gfx12) picks which streamed experts the CPU computes from measured CPU and GPU times (an EMA) and decides per layer, from measured layer times, whether to share at all. On an RTX A6000 that streams experts (DFlash2 Auto configuration, frozen draft table, STRATA_ADAPT_NOWAIT=0) two starts gave identical tokens in 7 of 24 requests with the share balancing and in 24 of 24 with it fixed at 0.25 or 0.5 or off; the fixed 0.5 read the one short chunk the share helps (981 tokens) in 1,001-1,009 ms against 995-997 ms balancing and 1,070-1,074 ms off. - Prefill::fix_cpu_share(v): the default-armed share at a fixed value, used like a fixed STRATA_PREFILL_CPU_SHARE (the EMA and the per-layer gate are skipped); the variable, when set, still wins. Prefill::cpu_share_balancing() says whether it is still balancing; PrefillStats gains the last balanced value and the number of readings. - The table file gets an optional "share" line (0..1). With --draft-costs the engine stores the balanced share, to a 0.05 step (0.5 when no short prompt measured it yet), when it writes the table, and fixes it from the next request; a loaded file with a share fixes it from the start. Same key, same ignore-and-relearn rule; without --draft-costs nothing changes. - draft_policy_test: the share round trip and an out-of-range share refused. Settings register regenerated (moved lines only).
This commit is contained in:
1 parent
c25a71c6c2
commit
6a56a44a29
7 files changed
+258
-207
No files matched your search
@@ -14194,8 +14194,10 @@ int main(int argc, char** argv) {
|
||||
policy.set_fixed_costs(cf.tables[(size_t) k].data(), (int) cf.tables[(size_t) k].size(), k);
|
||||
sizes += (sizes.empty() ? "" : ", ") + std::to_string(cf.tables[(size_t) k].size());
|
||||
}
|
||||
std::fprintf(stderr, "strata serve: draft costs: this machine's table is used (%s; window sizes %s): the same request "
|
||||
"gives the same tokens on every start\n", o.draft_costs.c_str(), sizes.c_str());
|
||||
if (cf.cpu_share >= 0.0) strata::prefill::Prefill::fix_cpu_share(cf.cpu_share);
|
||||
std::fprintf(stderr, "strata serve: draft costs: this machine's table is used (%s; window sizes %s%s): the same request "
|
||||
"gives the same tokens on every start\n", o.draft_costs.c_str(), sizes.c_str(),
|
||||
cf.cpu_share >= 0.0 ? ("; CPU prompt share " + std::to_string(cf.cpu_share).substr(0, 4)).c_str() : "");
|
||||
} else {
|
||||
policy.set_learning(true);
|
||||
dc_learning = true;
|
||||
@@ -19551,8 +19553,17 @@ int main(int argc, char** argv) {
|
||||
cf.key = dc_key;
|
||||
for (int k = 0; k < strata::spec::CostLearner::kCtxBuckets; ++k)
|
||||
cf.tables[(size_t) k] = policy.learner().table(k, kDraftCostMinN);
|
||||
// the CPU prompt share, when it is on and balancing from measured times: its balance as measured so far, to a 0.05
|
||||
// step (0.5 when no short prompt has measured it yet: on an RTX A6000 a fixed 0.5 read a 981-token chunk as fast as the
|
||||
// balancing share, 1,001-1,009 against 995-997 ms); fixed from now on like the table
|
||||
if (strata::prefill::Prefill::cpu_share_balancing()) {
|
||||
const strata::prefill::PrefillStats& pst = sp.stats();
|
||||
const double s = pst.cpu_share_readings > 0 ? pst.cpu_share_balanced : 0.5;
|
||||
cf.cpu_share = std::clamp(std::round(s * 20.0) / 20.0, 0.05, 0.9);
|
||||
}
|
||||
std::string why;
|
||||
const bool saved = strata::spec::write_cost_file(o.draft_costs, cf, why);
|
||||
if (cf.cpu_share >= 0.0) strata::prefill::Prefill::fix_cpu_share(cf.cpu_share);
|
||||
for (int k = 0; k < strata::spec::CostLearner::kCtxBuckets; ++k)
|
||||
if (!cf.tables[(size_t) k].empty())
|
||||
policy.set_fixed_costs(cf.tables[(size_t) k].data(), (int) cf.tables[(size_t) k].size(), k);
|
||||
@@ -19565,6 +19576,10 @@ int main(int argc, char** argv) {
|
||||
std::snprintf(b, sizeof b, "%s%.2f", i ? "," : "", cf.tables[0][i]);
|
||||
t0 += b;
|
||||
}
|
||||
if (cf.cpu_share >= 0.0) {
|
||||
std::snprintf(b, sizeof b, "; CPU prompt share %.2f", cf.cpu_share);
|
||||
t0 += b;
|
||||
}
|
||||
std::fprintf(stderr, "strata serve: draft costs: this machine's table is learned (%s); it is fixed from the next request "
|
||||
"on%s%s\n", t0.c_str(), saved ? "" : " (not saved: ", saved ? "" : (why + "; the next start learns again)").c_str());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user