inkling: the governor also watches the sampled block step, and the probe decodes its chat prompt sampled

Measured 2026-11-23 (RTX A6000, SQ-20, temperature 0.7 top_p 0.95 top_k 64): a sampled request takes the block-8 step, not the greedy tree
step, and the governor only watched the tree step: chat 0.91x and prose 0.92x of plain decoding stayed unprotected (greedy chat with the
governor was 1.04x). The governor now counts the sampled block step too (one gov_step helper for both). The launch probe decodes its code
prompt greedy and its chat prompt sampled the way a chat client asks, so a card that only wins on greedy code is not switched on by a chat
number it will not see.
This commit is contained in:
Niko1221 committed 2026-11-23 18:39:38 +01:00
1 parent 5ca7cd99b9
commit 540f3b3dfb
3 files changed
+33 -17

No files matched your search

+17 -14
View File
@@ -458,6 +458,20 @@ inline int run_serve_loop(const ServeConfig& cfg, InkModelFile& mf, InkBackend&
// time is measured on the first 4 decode steps of the first request and refreshed by every plain step after that.
const bool spec_adapt = (spec_env && std::string(spec_env) == "adapt") || cfg.bopts.spec_adapt;
double gov_t_plain = 0.0, gov_t_spec = 0.0;
// one speculative step (the greedy tree step or the sampled block step) took `ms` and produced `n_emit` tokens
auto gov_step = [&](ActiveReq& rq, int n_emit, double ms) {
gov_t_spec = (gov_t_spec <= 0.0) ? ms : 0.8 * gov_t_spec + 0.2 * ms;
rq.gov_win_steps += 1;
rq.gov_win_emit += n_emit;
if (rq.gov_win_steps >= 12) {
const double per_step = static_cast<double>(rq.gov_win_emit) / rq.gov_win_steps;
const double gain = (gov_t_plain > 0.0 && gov_t_spec > 0.0) ? per_step / (gov_t_spec / gov_t_plain) : 2.0;
rq.gov_gain = (rq.gov_gain < 0.0) ? gain : 0.5 * rq.gov_gain + 0.5 * gain;
if (rq.gov_gain < 0.93) { rq.gov_plain_left = 40; rq.gov_gain = -1.0; }
rq.gov_win_steps = 0;
rq.gov_win_emit = 0;
}
};
// Probe Vision shard lazily (zero VRAM/RAM until first image request)
bool images_ok = false;
@@ -797,20 +811,7 @@ inline int run_serve_loop(const ServeConfig& cfg, InkModelFile& mf, InkBackend&
}
if (n_emit > 0) {
rq.drafts_offered += drafted;
if (spec_adapt) {
const double ms = (now_s() - gov_t0) * 1000.0;
gov_t_spec = (gov_t_spec <= 0.0) ? ms : 0.8 * gov_t_spec + 0.2 * ms;
rq.gov_win_steps += 1;
rq.gov_win_emit += n_emit;
if (rq.gov_win_steps >= 12) {
const double per_step = static_cast<double>(rq.gov_win_emit) / rq.gov_win_steps;
const double gain = (gov_t_plain > 0.0 && gov_t_spec > 0.0) ? per_step / (gov_t_spec / gov_t_plain) : 2.0;
rq.gov_gain = (rq.gov_gain < 0.0) ? gain : 0.5 * rq.gov_gain + 0.5 * gain;
if (rq.gov_gain < 0.93) { rq.gov_plain_left = 40; rq.gov_gain = -1.0; }
rq.gov_win_steps = 0;
rq.gov_win_emit = 0;
}
}
if (spec_adapt) gov_step(rq, n_emit, (now_s() - gov_t0) * 1000.0);
int kept = 0;
bool done = false;
const char* fin = nullptr;
@@ -846,6 +847,7 @@ inline int run_serve_loop(const ServeConfig& cfg, InkModelFile& mf, InkBackend&
int32_t draft_ids[8]{};
std::string derr;
const int max_d = std::min(7, rq.max_new - rq.generated - 1);
const double gov_b0 = now_s();
int nd = backend.dspark_draft(rq.slot, rq.next_tok, rq.cur_pos, max_d, draft_ids, derr);
if (nd > 0) {
backend.snapshot_slot(rq.slot);
@@ -906,6 +908,7 @@ inline int run_serve_loop(const ServeConfig& cfg, InkModelFile& mf, InkBackend&
backend.rollback_slot(rq.slot, rq.cur_pos + accepted);
}
rq.cur_pos += accepted;
if (spec_adapt) gov_step(rq, accepted, (now_s() - gov_b0) * 1000.0);
} else if (fin) {
finish_req(rq, fin);
}
+4 -1
View File
@@ -27,6 +27,9 @@ except ImportError: # run as a script from this folder
from inkling_probe_prompts import CHAT_IDS, CODE_IDS
MARGIN = 1.10 # the mixed gain drafting has to reach
# how each probe request is decoded: code greedy (coding tools run cold), chat sampled the way a chat client asks (the drafter then takes the
# sampled path, measured 2026-11-23 on an A6000: chat 0.91x sampled where greedy chat was 1.04x with the governor)
GEN_OPTS = {"code": "temperature=0", "chat": "temperature=0.7 top_p=0.95 top_k=64 seed=7"}
TOKENS = 128 # tokens decoded per probe request (64 was too short: the A6000 with SQ-20 measured 1.05 at 64 tokens, 1.14 at 128 against 1.19 in the long runs)
REPS = 2 # requests per prompt and arm; the median is used
READY_TIMEOUT = 900.0
@@ -175,7 +178,7 @@ def _arm(open_engine, args: list[str], prompts: dict, tokens: int, reps: int) ->
speeds: dict[str, list[float]] = {k: [] for k in prompts}
plan = [("warm", next(iter(prompts.values())), 16)] + [(k, v, tokens) for k in prompts for v in [prompts[k]] for _ in range(reps)]
for name, ids, n in plan:
eng.send("GEN %d temperature=0 %s" % (n, ",".join(str(x) for x in ids)))
eng.send("GEN %d %s %s" % (n, GEN_OPTS.get(name, "temperature=0"), ",".join(str(x) for x in ids)))
while True:
ln = eng.readline(STEP_TIMEOUT)
if ln is None or ln == "TIMEOUT" or ln.startswith("ERR"):
+12 -2
View File
@@ -27,7 +27,7 @@ class FakeEngine:
self.sent.append(line)
if line.startswith("GEN"):
n = int(line.split()[1])
ids = line.split()[3].split(",")
ids = line.split()[-1].split(",")
kind = "code" if len(ids) == len(P.CODE_IDS) else "chat"
tps = self.speeds[kind]
self.lines.append("DONE %d %d 10.0 %.1f length 0 0 0" % (n, len(ids), n / tps * 1000.0))
@@ -109,12 +109,22 @@ class Driver(unittest.TestCase):
def run_probe(self, speeds=None, fail_arm=None, base=None):
started = []
self.engines = []
def open_engine(args):
started.append(list(args))
return FakeEngine(args, speeds or self.SPEEDS, fail=(fail_arm is not None and len(started) == fail_arm))
e = FakeEngine(args, speeds or self.SPEEDS, fail=(fail_arm is not None and len(started) == fail_arm))
self.engines.append(e)
return e
res = P.probe(open_engine, base or ["--native", "m.strata", "--max-context", "32768"], key="k")
return res, started
def test_code_is_decoded_greedy_and_chat_sampled(self):
self.run_probe()
sent = [l for l in self.engines[0].sent if l.startswith("GEN")]
self.assertTrue(any(" temperature=0 " in l and l.split()[-1].count(",") + 1 == len(P.CODE_IDS) for l in sent))
self.assertTrue(any("temperature=0.7 top_p=0.95 top_k=64 seed=7" in l and l.split()[-1].count(",") + 1 == len(P.CHAT_IDS) for l in sent))
def test_plain_first_then_chain_drafting_and_the_numbers_are_recorded(self):
res, started = self.run_probe()
self.assertEqual(len(started), 2)