STRA-338 size-fn: ab_slots and ab_speculation last trims

This commit is contained in:
Pavlo Ratushnyi
2026-11-06 18:53:42 +01:00
parent e4da26d74b
commit 8d1b2fbb21
2 changed files with 38 additions and 20 deletions
+13 -5
View File
@@ -200,6 +200,18 @@ fn print_turn((pair, slots, a, t): (usize, usize, usize, usize), prompt_len: usi
);
}
impl Comparison {
/// Whether request number `index` reproduced the first run's output (the first run becomes the reference).
fn check(&mut self, index: usize, tokens: &[u32]) -> bool {
if self.reference.len() <= index {
self.reference.push(tokens.to_vec());
}
let same = self.reference[index] == tokens;
self.identical &= same;
same
}
}
/// Every agent's every turn in turn order with `slots` cache slots; the prompt seconds.
fn run_scenario(
engine: &mut engine::GptOssEngine,
@@ -219,11 +231,7 @@ fn run_scenario(
prompt_ms += r.prompt_ms;
reused_total += r.reused;
computed += prompt.len() as u64 - r.reused;
if cmp.reference.len() <= index {
cmp.reference.push(r.tokens.clone());
}
let same = cmp.reference[index] == r.tokens;
cmp.identical &= same;
let same = cmp.check(index, &r.tokens);
print_turn((pair, slots, a, t), prompt.len(), &r, same);
}
}
+25 -15
View File
@@ -141,7 +141,8 @@ struct Arms {
/// The line of one finished run.
fn print_run((i, pair, speculate): (usize, usize, bool), r: &Run, (rate, same): (f64, bool)) {
println!(
"{} pair {pair} speculate={speculate}: {} tokens, prompt {:.0} ms, decode {:.0} ms ({rate:.2} tok/s), identical={same}",
"{} pair {pair} speculate={speculate}: {} tokens, prompt {:.0} ms, decode {:.0} ms ({rate:.2} \
tok/s), identical={same}",
TASKS[i].0,
r.tokens.len(),
r.prompt_ms,
@@ -262,6 +263,28 @@ fn parse_options(args: &[String]) -> (usize, usize, usize, usize) {
)
}
/// The engine with a context for the longest prompt, and its stop tokens; says what it is about to measure.
fn start_engine(
model: &Path,
(threads, pairs, max_new): (usize, usize, usize),
prompts: &[Vec<u32>],
) -> (engine::GptOssEngine, Vec<u32>) {
let context = prompts.iter().map(Vec::len).max().unwrap_or(0) + max_new + 64;
let loaded = engine::load(&LoadOptions {
model,
threads,
context,
warm: true,
})
.expect("load");
eprintln!(
"ab_speculation: {} prompts of {:?} tokens, {pairs} pairs, max_new {max_new}, {threads} threads",
prompts.len(),
prompts.iter().map(Vec::len).collect::<Vec<_>>()
);
(loaded.engine, loaded.stop_tokens)
}
fn main() {
let args: Vec<String> = std::env::args().skip(1).collect();
if args.len() < 2 {
@@ -277,20 +300,7 @@ fn main() {
return;
}
let context = prompts.iter().map(Vec::len).max().unwrap_or(0) + max_new + 64;
let loaded = engine::load(&LoadOptions {
model,
threads,
context,
warm: true,
})
.expect("load");
let (mut engine, stops) = (loaded.engine, loaded.stop_tokens);
eprintln!(
"ab_speculation: {} prompts of {:?} tokens, {pairs} pairs, max_new {max_new}, {threads} threads",
prompts.len(),
prompts.iter().map(Vec::len).collect::<Vec<_>>()
);
let (mut engine, stops) = start_engine(model, (threads, pairs, max_new), &prompts);
// one untimed request pages in and fills the cache with the shared prefix
run(&mut engine, &stops, &prompts[0][..prompts[0].len() - 8], 1);
let summary: Vec<String> = prompts