diff --git a/include/strata/core/mtp.hpp b/include/strata/core/mtp.hpp index 7216f015..d97d26bd 100644 --- a/include/strata/core/mtp.hpp +++ b/include/strata/core/mtp.hpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -105,6 +106,10 @@ public: float* probs = nullptr, float min_p = 0.0f, int* n_drafts = nullptr); /// The first round: one cell (`cell`) from `R_row` (device) and `token` -> T-1 drafts. + /// STRATA_SPEC_COST: called after each draft step with (index, probability) instead of the `min_p` test; false ends the chain. + /// Also called once for the last step of a chain that reached its length (so the rule sees every draft). Empty: min_p decides. + void set_chain_rule(std::function f) { chain_rule_ = std::move(f); } + bool draft_first(int T, const float* R_row, int32_t token, int64_t cell, int32_t* drafts, std::string& err, float* probs = nullptr, float min_p = 0.0f, int* n_drafts = nullptr); @@ -117,6 +122,7 @@ public: /// window's commit (`tail`) and the window's pick at its last accepted row (`next`, the next window's row 0). void set_draft_history(const int32_t* tail, int64_t n_tail, int32_t next); void set_ple_session(SessionState* s) { ple_ss_ = s; } + std::function chain_rule_; bool coupled() const { return coupled_active_; } /// PROBABILISTIC DRAFT ACCEPTANCE (core/spec_prob.hpp, STRATA_SPEC_PROB=1): this request's drafts are SAMPLED from /// q and each draft j's distribution is in spec_q() + j * kSpecQStride (ids, -1 terminated; then float bits), diff --git a/include/strata/spec/draft_policy.hpp b/include/strata/spec/draft_policy.hpp index 245fa4b1..88970c8b 100644 --- a/include/strata/spec/draft_policy.hpp +++ b/include/strata/spec/draft_policy.hpp @@ -16,6 +16,7 @@ #pragma once #include +#include namespace strata::spec { @@ -23,6 +24,7 @@ class DraftPolicy { public: static constexpr int kMaxT = 8; static constexpr int kBuckets = 4; + static constexpr int kCtxBuckets = 3; // STRATA_SPEC_COST: row costs per context length (< 6K, < 24K, longer) explicit DraftPolicy(int max_t, double margin = 0.03); @@ -45,14 +47,34 @@ public: double chain_rate(int match) const; double lookup_rate(int match) const; // current q for a match length double cost_ms(int t) const; // measured or scaled round time of a window of t tokens + /// A per-card row-cost table (round ms of the windows of 1..n rows, the draft included) counted as `weight` earlier rounds each: + /// the start of a process that already knows the card (STRATA_SPEC_COST_TABLE; tuning time), replaced by what it then measures. + void seed_costs(const double* ms, int n, double weight, int bucket = 0); + /// STRATA_SPEC_COST: the context position of the next round; selects the row-cost table of its length (a row of attention costs + /// more at 16K than at 1K). A bucket with no measurement yet starts from the nearest one that has. A no-op without set_robust(true). + void set_context(long long pos); + /// The measured round cost of every window size seen: "T1:39.8(n=120) T2:..." for the log / the next process's table. + std::string cost_table_text() const; + /// STRATA_SPEC_COST: a round time far above what is known for that width (the first use of a width captures its graph; a stalled + /// round) counts as a tenth of a sample, so one capture cannot price a width out of use. Off: the cost EMA as it always was. + void set_robust(bool on) { robust_ = on; } - /// COST-AWARE MTP WINDOW (STRATA_SPEC_COST=1 / --spec-cost): the window of 1..cap rows with the best expected committed - /// tokens per ms, from the MTP chain's draft probabilities p[0..n) (n = drafts computed; the chain is drafted in full): - /// E(T) = 1 + q_1 + .. + q_{T-1}, q_j = prod_{i<=j} a(p_i), a() = the acceptance measured for drafts of that probability - /// cost(T) = the measured round time of that window size (cost_ms, kept non-decreasing) - /// A wider window is taken only if its E/cost beats the narrower best by `margin`. Only chooses which rows are verified. - int best_rows(const float* p, int n, int cap) const; - /// After a round of the MTP window T whose drafts were p[0..T-1): `accepted` of them held. Teaches a(). + /// COST-AWARE MTP WINDOW (STRATA_SPEC_COST=1): the MTP chain is drafted one step at a time; after draft j (probability p_j) + /// E_j = 1 + q_0 + .. + q_j, q_i = prod_{k<=i} a(p_k) a() = the acceptance measured for MTP drafts of that probability + /// is the expected tokens of the window of j + 2 rows, worth E_j / cost(j + 2) tokens per ms (cost() = the measured round time of + /// that window size, which includes the draft). The window is the best of the widths seen; the chain goes on only while one or two + /// more drafts could still beat it (the cost is not convex: on a card with experts in RAM a window of 3 costs about a window of 2). + /// It only chooses which rows are verified; the output is unchanged. + struct ChainState { + double q = 1.0, e = 1.0; + double best_v = 0.0; + int best_rows = 1; ///< the window to verify: 1 + the drafts kept + int kept = 0; ///< best_rows - 1 + }; + /// Draft `idx` (0-based, probability p) was just computed: update `st` and say whether to compute draft idx + 1. + /// idx == 0 starts a new chain. `cap` = the widest window (rows). + bool keep_draft(ChainState& st, int idx, float p, int cap) const; + /// After a round of the MTP window T whose drafts were p[0..T-1): `accepted` of them held. Teaches draft_rate(). void observe_probs(const float* p, int n_window_drafts, int accepted); double draft_rate(double p) const; // acceptance of an MTP draft that came with probability p @@ -63,14 +85,17 @@ private: int max_t_; double margin_; - std::array cost_{}, cost_n_{}; // round ms by window size + std::array, kCtxBuckets> cost_{}, cost_n_{}; // round ms by context bucket and window size + int bk_ = 0; // the current context bucket std::array mtp_tok_{}, mtp_n_{}; // tokens committed by MTP windows of that size std::array ok_{}, bad_{}; // lookup drafts accepted / windows cut short, decayed std::array cok_{}, cbad_{}; // chained lookup drafts, the same (reached rounds only) double rounds_ = 0; // rounds observed so far + bool robust_ = false; + double clamp_sample(int t, double ms) const; static constexpr int kPBuckets = 8; std::array pa_ok_{}, pa_n_{}; // MTP drafts reached / accepted by probability bucket (decayed) - std::array last_{}; // the round at which each size was last measured + std::array, kCtxBuckets> last_{}; // the round at which each size was last measured }; } // namespace strata::spec diff --git a/src/core/mtp.cpp b/src/core/mtp.cpp index 58627029..f4b82b33 100644 --- a/src/core/mtp.cpp +++ b/src/core/mtp.cpp @@ -1620,7 +1620,7 @@ bool MtpDrafter::draft(int T, const int32_t* tokens, int64_t p, int a, int32_t* }; int n = 0; - if (min_p <= 0.0f && max_steps > 0) { + if (min_p <= 0.0f && !chain_rule_ && max_steps > 0) { if (cudaGraphLaunch(cp ? round_exec_c_[T] : round_exec_[T], cs_) != cudaSuccess) { err = std::string("mtp draft: ") + cudaGetErrorString(cudaGetLastError()); return false; @@ -1686,7 +1686,7 @@ bool MtpDrafter::draft(int T, const int32_t* tokens, int64_t p, int a, int32_t* float pj = ((volatile float*) h_prob_)[0]; if (probs) probs[0] = pj; n = 1; - for (int j = 1; j < max_steps && pj >= min_p; ++j) { + for (int j = 1; j < max_steps && (chain_rule_ ? chain_rule_(j - 1, pj) : pj >= min_p); ++j) { if (dt) cudaEventRecord(g_dt.eb[j], cs_); tl = Clock::now(); if (cudaGraphLaunch(cp ? step_exec_c_[j] : step_exec_[j], cs_) != cudaSuccess) { @@ -1705,6 +1705,7 @@ bool MtpDrafter::draft(int T, const int32_t* tokens, int64_t p, int a, int32_t* if (probs) probs[j] = pj; ++n; } + if (chain_rule_ && n >= max_steps) (void) chain_rule_(n - 1, pj); // the last step of a full chain prefetch_ple(drafts[n - 1]); const Clock::time_point t_pre_sync = Clock::now(); if (cudaStreamSynchronize(cs_) != cudaSuccess) { diff --git a/src/program/generate.cpp b/src/program/generate.cpp index fd6187ff..bd8a398b 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -11069,6 +11069,15 @@ int main(int argc, char** argv) { strata::spec::SuffixDrafter sfx(std::max(1, o.suffix_draft), 64, (size_t) o.max_context + 4096); strata::spec::DraftPolicy policy(S); // MTP or lookup window, learned over the whole process const bool spec_cost = [] { const char* v = std::getenv("STRATA_SPEC_COST"); return v != nullptr && v[0] == '1'; }(); // cost-aware MTP window (A/B arm) + strata::spec::DraftPolicy::ChainState chain_st; + int chain_rows = 1; // the window the cost-aware rule kept in the MTP chain just drafted + policy.set_robust(spec_cost); + if (spec_cost && use_mtp) + mtp.set_chain_rule([&](int idx, float pj) { + const bool k = policy.keep_draft(chain_st, idx, pj, S_mtp); + chain_rows = chain_st.best_rows; + return k; + }); // The vision path (--vision): GENI carries images. The file is one // or more strata-vision records (int32 'SVE1', n, nx, ny, n_embd, then n x n_embd floats) in prompt order; // each image's rows go to its run of <|image_pad|> tokens, whose M-RoPE positions are mtmd's: t = p, @@ -14762,8 +14771,9 @@ int main(int argc, char** argv) { } while (!pl_ran && !cancelled && produced_n < max_new) { int T = use_mtp ? S_mtp : 1; // no --mtp: one token a round unless a lookup draft fires + policy.set_context(p); if (use_mtp && spec_cost && !first_window) { - T = policy.best_rows(dprob.data(), S_mtp - 1, S_mtp); + T = std::clamp(chain_rows, 1, S_mtp); } else if (use_mtp && req_spec_min_p > 0.0) { T = 1; while (T < S_mtp && dprob[(size_t) T - 1] >= (float) req_spec_min_p) ++T; @@ -15048,7 +15058,7 @@ int main(int argc, char** argv) { if (use_mtp && hist_n > 0 && mtp.coupled() && !eos && produced_n < max_new) mtp.set_draft_history(consumed.data(), (int64_t) consumed.size(), outv[(size_t) a]); const bool drafted = !use_mtp || eos || produced_n >= max_new || - mtp.draft(T, outv.data(), p, a, drafts.data(), err, dprob.data(), spec_cost ? 0.0f : (float) req_spec_min_p); + mtp.draft(T, outv.data(), p, a, drafts.data(), err, dprob.data(), (float) req_spec_min_p); { const Clock::time_point tw3 = Clock::now(); auto msd = [](Clock::time_point a0, Clock::time_point b0) { return std::chrono::duration(b0 - a0).count(); }; @@ -16245,7 +16255,7 @@ int main(int argc, char** argv) { // STRATA_SPEC_TRACE= (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 // STRATA_SPEC_COST=1 (A/B arm, bench): the MTP window by expected tokens per ms at this machine's measured row costs - // (DraftPolicy::best_rows) instead of "draft probability >= --spec-min-p"; the chain is drafted in full + // (DraftPolicy::keep_draft, step by step) instead of "draft probability >= --spec-min-p" const bool spec_cost = [] { const char* v = std::getenv("STRATA_SPEC_COST"); return v != nullptr && v[0] == '1'; }(); std::vector dwin((size_t) o.spec, 0.0f); // the draft probabilities this round's window was chosen from std::FILE* spec_trace = nullptr; @@ -16256,7 +16266,7 @@ int main(int argc, char** argv) { // generated token and the MTP's first cell); otherwise the token loop already did that. bool first_window = native_pack; if (use_mtp && !first_window && - !mtp.draft_first(o.spec, ss.R, x, p - 1, drafts.data(), err, dprob.data(), spec_cost ? 0.0f : (float) o.spec_min_p)) { + !mtp.draft_first(o.spec, ss.R, x, p - 1, drafts.data(), err, dprob.data(), (float) o.spec_min_p)) { std::fprintf(stderr, "strata generate: %s\n", err.c_str()); return 1; } @@ -16274,6 +16284,30 @@ int main(int argc, char** argv) { if (use_mtp && S_mtp < o.spec) mtp.set_max_drafts(S_mtp - 1); strata::spec::SuffixDrafter sfx(std::max(1, o.suffix_draft), 64, (size_t) o.max_context + 4096); strata::spec::DraftPolicy policy(o.spec); // MTP or lookup window (see draft_policy.hpp) + strata::spec::DraftPolicy::ChainState chain_st; + int chain_rows = 1; // STRATA_SPEC_COST: the window the cost-aware rule kept in the MTP chain just drafted + if (const char* tab = std::getenv("STRATA_SPEC_COST_TABLE"); spec_cost && tab != nullptr && tab[0] != '\0') { + // "T1,T2,..;T1,T2,..;T1,..": the row costs of the 3 context buckets (< 6K, < 24K, longer); one list seeds the first + double ms[strata::spec::DraftPolicy::kMaxT] = {}; + int n = 0, bucket = 0; + for (const char* q = tab; *q != '\0' && bucket < strata::spec::DraftPolicy::kCtxBuckets;) { + if (n < strata::spec::DraftPolicy::kMaxT) ms[n++] = std::atof(q); + while (*q != '\0' && *q != ',' && *q != ';') ++q; + const bool end_list = *q == ';' || *q == '\0'; + if (*q != '\0') ++q; + if (end_list) { + policy.seed_costs(ms, n, 6.0, bucket++); + n = 0; + } + } + } + policy.set_robust(spec_cost); + if (spec_cost && use_mtp) + mtp.set_chain_rule([&](int idx, float pj) { + const bool k = policy.keep_draft(chain_st, idx, pj, S_mtp); + chain_rows = chain_st.best_rows; + return k; + }); std::vector sbuf((size_t) o.spec, 0); int64_t sfx_windows = 0, sfx_drafts = 0, sfx_ok = 0; int64_t chain_windows = 0, chain_drafts = 0, chain_ok = 0; // --lookup-chain's own counts @@ -16318,8 +16352,9 @@ int main(int argc, char** argv) { const Clock::time_point t0 = Clock::now(); strata::core::progress_at("spec loop: choosing the window", (int64_t) produced.size()); int T = S_mtp; + policy.set_context(p); if (use_mtp && spec_cost && !first_window) { - T = policy.best_rows(dprob.data(), S_mtp - 1, S_mtp); + T = std::clamp(chain_rows, 1, S_mtp); } else if (use_mtp && o.spec_min_p > 0.0) { T = 1; while (T < S_mtp && dprob[(size_t) T - 1] >= (float) o.spec_min_p) ++T; @@ -16458,7 +16493,7 @@ int main(int argc, char** argv) { break; } const bool drafted = !use_mtp || (int64_t) produced.size() >= max_new || - mtp.draft(T, outv.data(), p, a, drafts.data(), err, dprob.data(), spec_cost ? 0.0f : (float) o.spec_min_p); + mtp.draft(T, outv.data(), p, a, drafts.data(), err, dprob.data(), (float) o.spec_min_p); if (adapt_thr.joinable()) adapt_thr.join(); if (!adapt_ok) return 1; if (!drafted) { @@ -16510,6 +16545,7 @@ 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 (spec_cost) std::printf("%-24s %s\n", "spec cost table", policy.cost_table_text().c_str()); if (!t_cycle.empty()) { std::printf("%-24s", "window cost (ms/round)"); for (size_t i = 1; i < t_cycle_ms.size(); ++i) diff --git a/src/spec/draft_policy.cpp b/src/spec/draft_policy.cpp index 8ec78ea5..ffd9bbbf 100644 --- a/src/spec/draft_policy.cpp +++ b/src/spec/draft_policy.cpp @@ -2,6 +2,7 @@ #include "strata/spec/draft_policy.hpp" #include +#include namespace strata::spec { namespace { @@ -39,19 +40,80 @@ double DraftPolicy::lookup_rate(int match) const { double DraftPolicy::cost_ms(int t) const { t = std::clamp(t, 1, kMaxT); - if (cost_n_[t] > 0) return cost_[t]; + if (cost_n_[bk_][t] > 0) return cost_[bk_][t]; // scale from the measured sizes, weighting each by how often it was seen double num = 0.0, den = 0.0; for (int u = 1; u <= kMaxT; ++u) - if (cost_n_[u] > 0) { - const double w = std::min(cost_n_[u], 20.0); - num += w * cost_[u] * kShape[t] / kShape[u]; + if (cost_n_[bk_][u] > 0) { + const double w = std::min(cost_n_[bk_][u], 20.0); + num += w * cost_[bk_][u] * kShape[t] / kShape[u]; den += w; } return den > 0 ? num / den : kShape[t]; } -bool DraftPolicy::stale(int t) const { return cost_n_[t] > 0 && rounds_ - last_[t] > kStaleRounds; } +double DraftPolicy::clamp_sample(int t, double ms) const { + if (!robust_) return ms; + const double known = cost_ms(t); // the measured value, or the scaled guess from the other widths + if (cost_n_[bk_][t] == 0) { + // the first use of a width captures its graph: that round says nothing about its cost, the guess from the other widths stands in + for (int u = 1; u <= kMaxT; ++u) + if (cost_n_[bk_][u] > 0) return known; + return ms; + } + return std::min(ms, 2.0 * known); +} + +void DraftPolicy::seed_costs(const double* ms, int n, double weight, int bucket) { + bucket = std::clamp(bucket, 0, kCtxBuckets - 1); + for (int t = 1; t <= std::min(n, kMaxT); ++t) + if (ms[t - 1] > 0.0 && cost_n_[bucket][t] == 0) { + cost_[bucket][t] = ms[t - 1]; + cost_n_[bucket][t] = weight; + } +} + +void DraftPolicy::set_context(long long pos) { + if (!robust_) return; + const int nb = pos < 6000 ? 0 : pos < 24000 ? 1 : 2; + if (nb == bk_) return; + bool has = false; + for (int t = 1; t <= kMaxT; ++t) has = has || cost_n_[nb][t] > 0; + if (!has) { // nothing measured at this length yet: the nearest bucket that has data is the prior (one sample's worth) + for (int d = 1; d < kCtxBuckets && !has; ++d) + for (const int src : {nb - d, nb + d}) { + if (src < 0 || src >= kCtxBuckets || has) continue; + for (int t = 1; t <= kMaxT; ++t) + if (cost_n_[src][t] > 0) { + cost_[nb][t] = cost_[src][t]; + cost_n_[nb][t] = 1.0; + last_[nb][t] = rounds_; + has = true; + } + } + } + bk_ = nb; +} + +std::string DraftPolicy::cost_table_text() const { + std::string out; + char b[64]; + for (int k = 0; k < kCtxBuckets; ++k) { + bool any = false; + for (int t = 1; t <= kMaxT; ++t) any = any || cost_n_[k][t] > 0; + if (!any) continue; + out += (out.empty() ? "" : " | "); + out += k == 0 ? "ctx<6K:" : k == 1 ? "ctx<24K:" : "ctx>=24K:"; + for (int t = 1; t <= kMaxT; ++t) + if (cost_n_[k][t] > 0) { + std::snprintf(b, sizeof b, " T%d:%.2f(n=%.0f)", t, cost_[k][t], cost_n_[k][t]); + out += b; + } + } + return out; +} + +bool DraftPolicy::stale(int t) const { return cost_n_[bk_][t] > 0 && rounds_ - last_[bk_][t] > kStaleRounds; } double DraftPolicy::mtp_tokens(int t) const { if (mtp_n_[t] > 0) return mtp_tok_[t]; @@ -82,7 +144,7 @@ DraftPolicy::Pick DraftPolicy::choose(int t_mtp, int lookup_k, int match) const } // a guessed cost can keep the policy from ever measuring a size: the first few times a confident lookup would // need a size not measured yet, it is tried (verification keeps the output; only the one round's speed is at stake) - if (t_full > p.t && (cost_n_[t_full] < kProbes || stale(t_full)) && q >= 0.85) { + if (t_full > p.t && (cost_n_[bk_][t_full] < kProbes || stale(t_full)) && q >= 0.85) { p.lookup = true; p.t = t_full; } @@ -92,9 +154,11 @@ DraftPolicy::Pick DraftPolicy::choose(int t_mtp, int lookup_k, int match) const void DraftPolicy::observe(bool lookup, int t, int accepted, int match, double round_ms) { t = std::clamp(t, 1, kMaxT); if (round_ms > 0) { - cost_[t] = cost_n_[t] > 0 ? (1.0 - kCostAlpha) * cost_[t] + kCostAlpha * round_ms : round_ms; - cost_n_[t] += 1.0; - last_[t] = rounds_; + round_ms = clamp_sample(t, round_ms); + const double alpha = robust_ ? std::max(kCostAlpha, 1.0 / (cost_n_[bk_][t] + 1.0)) : kCostAlpha; // a running mean for the first samples + cost_[bk_][t] = cost_n_[bk_][t] > 0 ? (1.0 - alpha) * cost_[bk_][t] + alpha * round_ms : round_ms; + cost_n_[bk_][t] += 1.0; + last_[bk_][t] = rounds_; } rounds_ += 1.0; if (lookup) { @@ -132,24 +196,31 @@ void DraftPolicy::observe_probs(const float* p, int n, int accepted) { } } -int DraftPolicy::best_rows(const float* p, int n, int cap) const { +bool DraftPolicy::keep_draft(ChainState& st, int idx, float p, int cap) const { cap = std::clamp(cap, 1, max_t_); - const int m = std::min(n, cap - 1); - double q = 1.0, e = 1.0, floor_cost = cost_ms(1); - double best_v = e / floor_cost; - int best_t = 1; - for (int j = 0; j < m; ++j) { - q *= draft_rate(p[j]); - e += q; - const int t = j + 2; - floor_cost = std::max(floor_cost, cost_ms(t)); - const double v = e / floor_cost; - if (v > best_v * (1.0 + margin_)) { - best_v = v; - best_t = t; - } + if (idx == 0) { + st = ChainState{}; + st.best_v = 1.0 / cost_ms(1); } - return best_t; + const double a = draft_rate(p); + st.q *= a; + st.e += st.q; + const int rows = idx + 2; + if (rows <= cap) { + const double v = st.e / cost_ms(rows); + if (v > st.best_v * (1.0 + margin_ / 3.0)) { + st.best_v = v; + st.best_rows = rows; + } + // a width not measured yet is tried a few times when the chain is likely to hold that far + if (cost_n_[bk_][rows] < kProbes && st.q >= 0.15) st.best_rows = rows; + } + st.kept = st.best_rows - 1; + if (rows + 1 > cap) return false; // no row left for another draft + // one or two more drafts, each as likely to hold as this one did, could they beat the best width so far? + const double v1 = (st.e + st.q * a) / cost_ms(rows + 1); + const double v2 = rows + 2 <= cap ? (st.e + st.q * a + st.q * a * a) / cost_ms(rows + 2) : 0.0; + return std::max(v1, v2) > st.best_v * (1.0 + margin_ / 3.0) || (cost_n_[bk_][rows + 1] < kProbes && st.q * a >= 0.15); } double DraftPolicy::chain_rate(int match) const { @@ -180,16 +251,18 @@ int DraftPolicy::chain(int t_mtp, double p_mtp, int k_avail, int match) const { return best_k; } // as choose(): a size whose cost is only guessed is tried a few times when the continuation looks likely - if ((cost_n_[t_full] < kProbes || stale(t_full)) && p_mtp * c >= 0.6) return kmax; + if ((cost_n_[bk_][t_full] < kProbes || stale(t_full)) && p_mtp * c >= 0.6) return kmax; return 0; } void DraftPolicy::observe_chain(int t_mtp, int k, int accepted, int match, double round_ms) { const int t = std::clamp(t_mtp + k, 1, kMaxT); if (round_ms > 0) { - cost_[t] = cost_n_[t] > 0 ? (1.0 - kCostAlpha) * cost_[t] + kCostAlpha * round_ms : round_ms; - cost_n_[t] += 1.0; - last_[t] = rounds_; + round_ms = clamp_sample(t, round_ms); + const double alpha = robust_ ? std::max(kCostAlpha, 1.0 / (cost_n_[bk_][t] + 1.0)) : kCostAlpha; // a running mean for the first samples + cost_[bk_][t] = cost_n_[bk_][t] > 0 ? (1.0 - alpha) * cost_[bk_][t] + alpha * round_ms : round_ms; + cost_n_[bk_][t] += 1.0; + last_[bk_][t] = rounds_; } rounds_ += 1.0; // the MTP part is an ordinary MTP window as far as its own drafts go