STRA-338 size-fn: examples: long strings continued, more helpers
This commit is contained in:
@@ -23,6 +23,18 @@ struct Data {
|
||||
yq: Vec<i8>,
|
||||
}
|
||||
|
||||
/// A Q8_0 activation row of `BLOCKS_PER_ROW` blocks with scale 0.0625 and random quants.
|
||||
fn random_activation(next: &mut impl FnMut() -> u32) -> Vec<u8> {
|
||||
let mut act = vec![0u8; BLOCKS_PER_ROW * Q8];
|
||||
for block in act.as_chunks_mut::<Q8>().0.iter_mut() {
|
||||
block[..2].copy_from_slice(&0x2C00u16.to_le_bytes()); // 0.0625
|
||||
for b in &mut block[2..] {
|
||||
*b = ((next() % 255) as i64 - 127) as i8 as u8;
|
||||
}
|
||||
}
|
||||
act
|
||||
}
|
||||
|
||||
fn make_data(rows: usize) -> Data {
|
||||
let row_bytes = BLOCKS_PER_ROW * MXFP4;
|
||||
let mut state = 0x1234_5678_9ABC_DEF0u64;
|
||||
@@ -39,13 +51,7 @@ fn make_data(rows: usize) -> Data {
|
||||
*b = next() as u8;
|
||||
}
|
||||
}
|
||||
let mut act = vec![0u8; BLOCKS_PER_ROW * Q8];
|
||||
for block in act.as_chunks_mut::<Q8>().0.iter_mut() {
|
||||
block[..2].copy_from_slice(&0x2C00u16.to_le_bytes()); // 0.0625
|
||||
for b in &mut block[2..] {
|
||||
*b = ((next() % 255) as i64 - 127) as i8 as u8;
|
||||
}
|
||||
}
|
||||
let act = random_activation(&mut next);
|
||||
let ys = vec![0.0625f32; BLOCKS_PER_ROW];
|
||||
let yq: Vec<i8> = act
|
||||
.as_chunks::<Q8>()
|
||||
|
||||
@@ -189,7 +189,8 @@ struct Comparison {
|
||||
/// The line of one finished request.
|
||||
fn print_turn((pair, slots, a, t): (usize, usize, usize, usize), prompt_len: usize, r: &Run, same: bool) {
|
||||
println!(
|
||||
"pair {pair} {} slot(s) agent {a} turn {t}: {} prompt tokens, {} reused, prompt {:.0} ms, decode {:.0} ms, {} tokens, identical={same}",
|
||||
"pair {pair} {} slot(s) agent {a} turn {t}: {} prompt tokens, {} reused, prompt {:.0} ms, decode \
|
||||
{:.0} ms, {} tokens, identical={same}",
|
||||
slots,
|
||||
prompt_len,
|
||||
r.reused,
|
||||
@@ -236,7 +237,8 @@ fn run_scenario(
|
||||
fn report_totals(agents: usize, totals: &[Vec<f64>; 2], identical: bool) {
|
||||
let ratios: Vec<f64> = totals[0].iter().zip(&totals[1]).map(|(a, b)| a / b).collect();
|
||||
println!(
|
||||
"total prompt time, 1 slot {:?} s, {agents} slots {:?} s; paired speed-up {:?}; outputs of all runs identical: {identical}",
|
||||
"total prompt time, 1 slot {:?} s, {agents} slots {:?} s; paired speed-up {:?}; outputs of all runs \
|
||||
identical: {identical}",
|
||||
totals[0].iter().map(|x| x.round()).collect::<Vec<_>>(),
|
||||
totals[1].iter().map(|x| x.round()).collect::<Vec<_>>(),
|
||||
ratios.iter().map(|r| (r * 100.0).round() / 100.0).collect::<Vec<_>>()
|
||||
@@ -260,7 +262,8 @@ fn prepare_prompts(model: &Path, st: &Settings) -> Vec<Vec<Vec<u32>>> {
|
||||
.take_while(|(a, b)| a == b)
|
||||
.count();
|
||||
println!(
|
||||
"{} agents x {} turns, prompt tokens per agent and turn {sizes:?}, shared prefix {shared} tokens, max_new {}, {} threads",
|
||||
"{} agents x {} turns, prompt tokens per agent and turn {sizes:?}, shared prefix {shared} tokens, \
|
||||
max_new {}, {} threads",
|
||||
st.agents, st.turns, st.max_new, st.threads
|
||||
);
|
||||
prompts
|
||||
|
||||
@@ -235,7 +235,11 @@ fn replay_policies(tokenizer: &GgufBpe, prompts: &[Vec<u32>], path: &str) {
|
||||
/// The shared system and developer messages and the source file every task is asked about.
|
||||
fn prompt_head(name: &str, source: &str) -> String {
|
||||
format!(
|
||||
"<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.\nKnowledge cutoff: 2024-06\nCurrent date: 2026-10-16\n\nReasoning: low\n\n# Valid channels: analysis, commentary, final. Channel must be included for every message.<|end|><|start|>developer<|message|># Instructions\n\nYou are a coding agent working in a Rust repository. Answer concisely.<|end|><|start|>user<|message|>Here is the file {name}:\n\n```rust\n{source}\n```<|end|>"
|
||||
"<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.\nKnowledge \
|
||||
cutoff: 2024-06\nCurrent date: 2026-10-16\n\nReasoning: low\n\n# Valid channels: analysis, \
|
||||
commentary, final. Channel must be included for every message.<|end|><|start|>developer<|message|># \
|
||||
Instructions\n\nYou are a coding agent working in a Rust repository. Answer \
|
||||
concisely.<|end|><|start|>user<|message|>Here is the file {name}:\n\n```rust\n{source}\n```<|end|>"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -248,6 +252,17 @@ struct Arms {
|
||||
reference: Option<Vec<u32>>,
|
||||
}
|
||||
|
||||
/// 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}",
|
||||
TASKS[i].0,
|
||||
r.tokens.len(),
|
||||
r.prompt_ms,
|
||||
r.decode_ms
|
||||
);
|
||||
}
|
||||
|
||||
/// Alternating plain and speculative runs of one task.
|
||||
fn run_arms(
|
||||
engine: &mut engine::GptOssEngine,
|
||||
@@ -273,13 +288,7 @@ fn run_arms(
|
||||
let same = arms.reference.get_or_insert_with(|| r.tokens.clone()) == &r.tokens;
|
||||
arms.identical &= same;
|
||||
let rate = r.tokens.len() as f64 / (r.decode_ms / 1000.0);
|
||||
println!(
|
||||
"{} 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,
|
||||
r.decode_ms
|
||||
);
|
||||
print_run((i, pair, speculate), &r, (rate, same));
|
||||
if speculate { &mut arms.spec } else { &mut arms.plain }.push(rate);
|
||||
}
|
||||
}
|
||||
@@ -295,7 +304,8 @@ fn summary_line(i: usize, arms: &Arms) -> String {
|
||||
};
|
||||
let ratios: Vec<f64> = arms.spec.iter().zip(&arms.plain).map(|(s, p)| s / p).collect();
|
||||
format!(
|
||||
"{}: plain median {:.2} tok/s, speculate median {:.2} tok/s, paired ratio mean {:.2} (runs {:?}), outputs identical: {}",
|
||||
"{}: plain median {:.2} tok/s, speculate median {:.2} tok/s, paired ratio mean {:.2} (runs {:?}), \
|
||||
outputs identical: {}",
|
||||
TASKS[i].0,
|
||||
median(&arms.plain),
|
||||
median(&arms.spec),
|
||||
@@ -355,16 +365,24 @@ fn task_prompts(tokenizer: &GgufBpe, (file, chars): (&str, usize)) -> Vec<Vec<u3
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The optional numbers of the command line: pairs, max_new, threads and the characters of the source.
|
||||
fn parse_options(args: &[String]) -> (usize, usize, usize, usize) {
|
||||
let arg = |i: usize, default: usize| args.get(i).and_then(|s| s.parse().ok()).unwrap_or(default);
|
||||
(
|
||||
arg(2, 3),
|
||||
arg(3, 320),
|
||||
arg(4, std::thread::available_parallelism().map_or(1, |n| n.get())),
|
||||
arg(5, 2400),
|
||||
)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
if args.len() < 2 {
|
||||
eprintln!("usage: ab_speculation <model.gguf> <source file> [pairs] [max_new] [threads] [chars]");
|
||||
std::process::exit(2);
|
||||
}
|
||||
let arg = |i: usize, default: usize| args.get(i).and_then(|s| s.parse().ok()).unwrap_or(default);
|
||||
let (pairs, max_new) = (arg(2, 3), arg(3, 320));
|
||||
let threads = arg(4, std::thread::available_parallelism().map_or(1, |n| n.get()));
|
||||
let chars = arg(5, 2400);
|
||||
let (pairs, max_new, threads, chars) = parse_options(&args);
|
||||
let model = Path::new(&args[0]);
|
||||
let tokenizer = read_tokenizer(model);
|
||||
let prompts = task_prompts(&tokenizer, (&args[1], chars));
|
||||
|
||||
@@ -209,7 +209,8 @@ fn main() {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
if args.len() < 6 {
|
||||
eprintln!(
|
||||
"usage: ab_prefill_npu <model.gguf> <openvino root> <service exe> <device> <tokens[,tokens...]> <pairs> [batch]"
|
||||
"usage: ab_prefill_npu <model.gguf> <openvino root> <service exe> <device> <tokens[,tokens...]> \
|
||||
<pairs> [batch]"
|
||||
);
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
@@ -99,7 +99,6 @@ fn run_once(
|
||||
(ids, prefix): (&[u32], usize),
|
||||
(npu_share, warm): (f64, bool),
|
||||
) -> (f64, u32, Vec<f64>) {
|
||||
let rest = &ids[prefix..];
|
||||
let mut state = State::new(&model.config, ids.len() + 1);
|
||||
if prefix > 0 {
|
||||
split.set_npu_share(0.0);
|
||||
@@ -111,7 +110,7 @@ fn run_once(
|
||||
split.set_npu_share(npu_share);
|
||||
let t = Instant::now();
|
||||
let hidden = split
|
||||
.prefill(model, &mut state, rest, prefix, &mut |_| true)
|
||||
.prefill(model, &mut state, &ids[prefix..], prefix, &mut |_| true)
|
||||
.expect("prefill")
|
||||
.expect("not cancelled");
|
||||
let seconds = t.elapsed().as_secs_f64();
|
||||
@@ -170,7 +169,8 @@ fn main() {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
if args.len() < 5 {
|
||||
eprintln!(
|
||||
"usage: split_prefill <model.gguf> <openvino root> <service exe> <device> <ids file|synth:N> [rounds] [npu share] [prefix] [gpu batch] [npu batch]"
|
||||
"usage: split_prefill <model.gguf> <openvino root> <service exe> <device> <ids file|synth:N> \
|
||||
[rounds] [npu share] [prefix] [gpu batch] [npu batch]"
|
||||
);
|
||||
std::process::exit(2);
|
||||
}
|
||||
@@ -186,7 +186,8 @@ fn main() {
|
||||
let mut split = start_split(&args, path, (gpu_batch, npu_batch));
|
||||
let rest_len = ids.len() - prefix;
|
||||
println!(
|
||||
"{rest_len} tokens after a prefix of {prefix}; npu share {share} ({} tokens); gpu batch {gpu_batch}, npu batch {npu_batch}",
|
||||
"{rest_len} tokens after a prefix of {prefix}; npu share {share} ({} tokens); gpu batch {gpu_batch}, \
|
||||
npu batch {npu_batch}",
|
||||
((rest_len as f64 * share).round() as usize).min(rest_len - 1)
|
||||
);
|
||||
// one untimed run of each first: graphs, pipelines and caches
|
||||
|
||||
Reference in New Issue
Block a user