test: record the paired CPU-vs-GPU prefill A/B and add the ab_prefill harness (STRA-219)
Warm, alternating order, same prompts, same process: paired speed-up 2.87x (512 tokens), 3.40x (1024), 3.97x (2048), 3.57x (4096) with 95% CIs in docs/igpu-prefill.md; GPU 50-64 tok/s against 15-17 tok/s on the CPU. Synthetic prompts, 3-5 pairs, clocks/power not controlled. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
f07302b944
commit
c44d1f553d
@@ -0,0 +1,50 @@
|
||||
# paired prefill A/B (warm)
|
||||
model: gpt-oss-20b-MXFP4.gguf (12109565632 bytes, sha256 65D06D31A3977D553CB3AF137B5C26B5F1E9297A6AAA29AE7CAA98788CDE53AB)
|
||||
cpu: 14 threads, kernels avx-vnni; gpu: Intel(R) Graphics (Vulkan), batch 512; context capacity = prompt + 1
|
||||
date: 2026-10-15 00:50 (hardware/driver/power state are not controlled; see docs/igpu-prefill.md)
|
||||
|
||||
## 512 prompt tokens, 5 pairs
|
||||
pair first cpu s gpu s speed-up next tokens
|
||||
1 cpu 30.21 9.62 3.14x cpu 27 gpu 27
|
||||
2 gpu 32.04 9.80 3.27x cpu 27 gpu 27
|
||||
3 cpu 31.64 12.44 2.54x cpu 27 gpu 27
|
||||
4 gpu 32.18 12.73 2.53x cpu 27 gpu 27
|
||||
5 cpu 28.75 10.07 2.85x cpu 27 gpu 27
|
||||
cpu: mean 30.96 s (sd 1.46), median 31.64, min 28.75, max 32.18 => 16.2 tok/s at the median
|
||||
gpu: mean 10.93 s (sd 1.52), median 10.07, min 9.62, max 12.73 => 50.8 tok/s at the median
|
||||
paired speed-up cpu/gpu: mean 2.87x, 95% CI [2.45, 3.29], median 2.85x (5 pairs)
|
||||
|
||||
## 1024 prompt tokens, 5 pairs
|
||||
pair first cpu s gpu s speed-up next tokens
|
||||
1 cpu 59.40 19.00 3.13x cpu 27 gpu 27
|
||||
2 gpu 61.72 18.04 3.42x cpu 27 gpu 27
|
||||
3 cpu 57.98 17.80 3.26x cpu 27 gpu 27
|
||||
4 gpu 73.83 17.33 4.26x cpu 27 gpu 27
|
||||
5 cpu 60.37 20.49 2.95x cpu 27 gpu 27
|
||||
cpu: mean 62.66 s (sd 6.39), median 60.37, min 57.98, max 73.83 => 17.0 tok/s at the median
|
||||
gpu: mean 18.53 s (sd 1.25), median 18.04, min 17.33, max 20.49 => 56.8 tok/s at the median
|
||||
paired speed-up cpu/gpu: mean 3.40x, 95% CI [2.77, 4.04], median 3.26x (5 pairs)
|
||||
|
||||
# paired prefill A/B (warm)
|
||||
model: gpt-oss-20b-MXFP4.gguf (12109565632 bytes, sha256 65D06D31A3977D553CB3AF137B5C26B5F1E9297A6AAA29AE7CAA98788CDE53AB)
|
||||
cpu: 14 threads, kernels avx-vnni; gpu: Intel(R) Graphics (Vulkan), batch 512; context capacity = prompt + 1
|
||||
date: 2026-10-15 00:50 (hardware/driver/power state are not controlled; see docs/igpu-prefill.md)
|
||||
|
||||
## 2048 prompt tokens, 3 pairs
|
||||
pair first cpu s gpu s speed-up next tokens
|
||||
1 cpu 126.57 31.83 3.98x cpu 27 gpu 27
|
||||
2 gpu 133.17 31.74 4.20x cpu 27 gpu 27
|
||||
3 cpu 122.45 32.84 3.73x cpu 27 gpu 27
|
||||
cpu: mean 127.40 s (sd 5.41), median 126.57, min 122.45, max 133.17 => 16.2 tok/s at the median
|
||||
gpu: mean 32.14 s (sd 0.61), median 31.83, min 31.74, max 32.84 => 64.3 tok/s at the median
|
||||
paired speed-up cpu/gpu: mean 3.97x, 95% CI [3.39, 4.55], median 3.98x (3 pairs)
|
||||
|
||||
## 4096 prompt tokens, 3 pairs
|
||||
pair first cpu s gpu s speed-up next tokens
|
||||
1 cpu 270.03 80.68 3.35x cpu 27 gpu 27
|
||||
2 gpu 256.68 73.91 3.47x cpu 27 gpu 27
|
||||
3 cpu 288.72 74.38 3.88x cpu 27 gpu 27
|
||||
cpu: mean 271.81 s (sd 16.10), median 270.03, min 256.68, max 288.72 => 15.2 tok/s at the median
|
||||
gpu: mean 76.32 s (sd 3.78), median 74.38, min 73.91, max 80.68 => 55.1 tok/s at the median
|
||||
paired speed-up cpu/gpu: mean 3.57x, 95% CI [2.87, 4.26], median 3.47x (3 pairs)
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
//! Paired A/B of the prompt-processing speed: the CPU decoder against the GPU prefill, same prompts, runs
|
||||
//! alternating in order (CPU first, then GPU first, ...) with a fresh cache each time, in one process so that
|
||||
//! the page cache and the machine state are shared. Warm only: each path is run once untimed first. Prints
|
||||
//! every run, the distribution per path and the paired speed-up with a 95% confidence interval.
|
||||
//!
|
||||
//! Run: `cargo run --release -p leleka-gptoss-igpu --example ab_prefill -- <model.gguf> <tokens[,tokens...]> <pairs> [batch]`
|
||||
//! Set `LELEKA_MODEL_SHA256` to record the model digest in the report.
|
||||
|
||||
use leleka_cpu_kernels::Dispatch;
|
||||
use leleka_cpu_sys::mapping::Mapping;
|
||||
use leleka_gguf::Gguf;
|
||||
use leleka_gptoss::{Model, State};
|
||||
use leleka_gptoss_igpu::GpuPrefill;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::path::Path;
|
||||
use std::time::Instant;
|
||||
|
||||
fn synth(n: usize) -> Vec<u32> {
|
||||
let mut s = 0x2545_F491_4F6C_DD1Du64;
|
||||
(0..n)
|
||||
.map(|_| {
|
||||
s ^= s << 13;
|
||||
s ^= s >> 7;
|
||||
s ^= s << 17;
|
||||
1000 + (s % 60_000) as u32
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Two-sided 95% Student t critical values for 1..=30 degrees of freedom.
|
||||
fn t95(df: usize) -> f64 {
|
||||
const T: [f64; 30] = [
|
||||
12.706, 4.303, 3.182, 2.776, 2.571, 2.447, 2.365, 2.306, 2.262, 2.228, 2.201, 2.179, 2.160,
|
||||
2.145, 2.131, 2.120, 2.110, 2.101, 2.093, 2.086, 2.080, 2.074, 2.069, 2.064, 2.060, 2.056,
|
||||
2.052, 2.048, 2.045, 2.042,
|
||||
];
|
||||
T[df.clamp(1, 30) - 1]
|
||||
}
|
||||
|
||||
fn mean_sd(x: &[f64]) -> (f64, f64) {
|
||||
let m = x.iter().sum::<f64>() / x.len() as f64;
|
||||
let var = if x.len() > 1 {
|
||||
x.iter().map(|v| (v - m) * (v - m)).sum::<f64>() / (x.len() - 1) as f64
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
(m, var.sqrt())
|
||||
}
|
||||
|
||||
fn median(x: &[f64]) -> f64 {
|
||||
let mut v = x.to_vec();
|
||||
v.sort_by(|a, b| a.total_cmp(b));
|
||||
let n = v.len();
|
||||
if n % 2 == 1 {
|
||||
v[n / 2]
|
||||
} else {
|
||||
(v[n / 2 - 1] + v[n / 2]) / 2.0
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
if args.len() < 3 {
|
||||
eprintln!("usage: ab_prefill <model.gguf> <tokens[,tokens...]> <pairs> [batch]");
|
||||
std::process::exit(2);
|
||||
}
|
||||
let sizes: Vec<usize> = args[1]
|
||||
.split(',')
|
||||
.map(|s| s.trim().parse().expect("token count"))
|
||||
.collect();
|
||||
let pairs: usize = args[2].parse().expect("pairs");
|
||||
let batch: usize = args
|
||||
.get(3)
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or(leleka_gptoss_igpu::DEFAULT_BATCH);
|
||||
let path = Path::new(&args[0]);
|
||||
let size = std::fs::metadata(path).expect("model file").len();
|
||||
let gguf = Gguf::read(
|
||||
BufReader::with_capacity(1 << 20, File::open(path).expect("open")),
|
||||
size,
|
||||
)
|
||||
.expect("valid GGUF");
|
||||
let threads = std::thread::available_parallelism().map_or(1, |n| n.get());
|
||||
let dispatch = Dispatch::from_env().expect("kernel level");
|
||||
let isa = dispatch.isa();
|
||||
let model = Model::load(
|
||||
std::sync::Arc::new(Mapping::open(path).expect("map model")),
|
||||
&gguf,
|
||||
dispatch,
|
||||
threads,
|
||||
)
|
||||
.expect("load model");
|
||||
let mut accel = GpuPrefill::new().expect("a GPU").with_batch(batch);
|
||||
println!("# paired prefill A/B (warm)");
|
||||
println!(
|
||||
"model: {} ({} bytes, sha256 {})",
|
||||
path.file_name().and_then(|n| n.to_str()).unwrap_or("?"),
|
||||
size,
|
||||
std::env::var("LELEKA_MODEL_SHA256").unwrap_or_else(|_| "not recorded".into())
|
||||
);
|
||||
println!(
|
||||
"cpu: {threads} threads, kernels {isa}; gpu: {}, batch {batch}; context capacity = prompt + 1",
|
||||
accel.adapter_name()
|
||||
);
|
||||
println!(
|
||||
"date: {} (hardware/driver/power state are not controlled; see docs/igpu-prefill.md)",
|
||||
std::env::var("LELEKA_AB_DATE").unwrap_or_else(|_| "unrecorded".into())
|
||||
);
|
||||
|
||||
for n in sizes {
|
||||
let prompt = synth(n);
|
||||
let run_cpu = |model: &Model| {
|
||||
let mut state = State::new(&model.config, n + 1);
|
||||
let t = Instant::now();
|
||||
let r = model
|
||||
.prefill_reuse(&mut state, &prompt)
|
||||
.expect("cpu prefill");
|
||||
(t.elapsed().as_secs_f64(), r.next)
|
||||
};
|
||||
let run_gpu = |model: &Model, accel: &mut GpuPrefill| {
|
||||
let mut state = State::new(&model.config, n + 1);
|
||||
let t = Instant::now();
|
||||
let r = model
|
||||
.prefill_reuse_accelerated(&mut state, &prompt, accel, 1, &mut |_, _| true)
|
||||
.expect("gpu prefill")
|
||||
.expect("not cancelled");
|
||||
(t.elapsed().as_secs_f64(), r.next)
|
||||
};
|
||||
// warm-up: page the weights in, compile the GPU pipelines
|
||||
let warm_n = n.min(64);
|
||||
{
|
||||
let mut state = State::new(&model.config, warm_n + 1);
|
||||
let p = &prompt[..warm_n];
|
||||
let _ = model.prefill_reuse(&mut state, p).expect("warm cpu");
|
||||
let mut state = State::new(&model.config, warm_n + 1);
|
||||
let _ = model
|
||||
.prefill_reuse_accelerated(&mut state, p, &mut accel, 1, &mut |_, _| true)
|
||||
.expect("warm gpu");
|
||||
}
|
||||
println!("\n## {n} prompt tokens, {pairs} pairs");
|
||||
println!(
|
||||
"{:>4} {:>6} {:>10} {:>10} {:>9} next tokens",
|
||||
"pair", "first", "cpu s", "gpu s", "speed-up"
|
||||
);
|
||||
let (mut cpu_s, mut gpu_s, mut ratios) = (Vec::new(), Vec::new(), Vec::new());
|
||||
for i in 0..pairs {
|
||||
let gpu_first = i % 2 == 1;
|
||||
let ((c, cn), (g, gn)) = if gpu_first {
|
||||
let g = run_gpu(&model, &mut accel);
|
||||
let c = run_cpu(&model);
|
||||
(c, g)
|
||||
} else {
|
||||
let c = run_cpu(&model);
|
||||
let g = run_gpu(&model, &mut accel);
|
||||
(c, g)
|
||||
};
|
||||
println!(
|
||||
"{:>4} {:>6} {:>10.2} {:>10.2} {:>8.2}x cpu {cn} gpu {gn}",
|
||||
i + 1,
|
||||
if gpu_first { "gpu" } else { "cpu" },
|
||||
c,
|
||||
g,
|
||||
c / g
|
||||
);
|
||||
cpu_s.push(c);
|
||||
gpu_s.push(g);
|
||||
ratios.push(c / g);
|
||||
}
|
||||
for (name, x) in [("cpu", &cpu_s), ("gpu", &gpu_s)] {
|
||||
let (m, sd) = mean_sd(x);
|
||||
let mut sorted = x.clone();
|
||||
sorted.sort_by(|a, b| a.total_cmp(b));
|
||||
println!(
|
||||
"{name}: mean {m:.2} s (sd {sd:.2}), median {:.2}, min {:.2}, max {:.2} => {:.1} tok/s at the median",
|
||||
median(x),
|
||||
sorted[0],
|
||||
sorted[sorted.len() - 1],
|
||||
n as f64 / median(x)
|
||||
);
|
||||
}
|
||||
let (m, sd) = mean_sd(&ratios);
|
||||
let half = if pairs > 1 {
|
||||
t95(pairs - 1) * sd / (pairs as f64).sqrt()
|
||||
} else {
|
||||
f64::NAN
|
||||
};
|
||||
println!(
|
||||
"paired speed-up cpu/gpu: mean {m:.2}x, 95% CI [{:.2}, {:.2}], median {:.2}x ({pairs} pairs)",
|
||||
m - half,
|
||||
m + half,
|
||||
median(&ratios)
|
||||
);
|
||||
}
|
||||
}
|
||||
+25
-13
@@ -56,22 +56,34 @@ Conclusion: borderline against the strict llama.cpp criterion on the one referen
|
||||
floor everywhere else; it stays experimental and off by default until the gate has more reference text.
|
||||
Greedy continuations of a 128-token synthetic prompt were identical from both caches (8 tokens).
|
||||
|
||||
## Speed (first measurements, no claim yet)
|
||||
## Speed: paired A/B (warm), 2026-10-15
|
||||
|
||||
Not a performance result: single runs on a machine under no load control, synthetic random-id prompts, no paired
|
||||
A/B at the workloads in the charter, GPU numbers include the CPU repack thread competing for memory bandwidth.
|
||||
`crates/gptoss-igpu/examples/ab_prefill.rs`, raw output in `benchmarks/results/igpu-prefill-ab-2026-10-15.txt`.
|
||||
CPU decoder (AVX-VNNI, 14 threads) against the GPU prefill (batch 512), same random-id prompts, runs alternating
|
||||
in order in one process with a fresh cache each time, one untimed warm-up of each path first. Core Ultra 7 265U,
|
||||
Intel iGPU via Vulkan (driver version and power limit not recorded), model gpt-oss-20b-MXFP4 (SHA-256
|
||||
65d06d31…cde53ab), commit of this document's parent (HEAD at the time: f07302b plus the example). Warm only; no
|
||||
cold-cache runs; prompt tokens as listed, 0 output tokens (prefill only; both paths returned the same next token
|
||||
in every run, 27).
|
||||
|
||||
| Prompt | CPU (AVX-VNNI, 10 threads) | GPU prefill | Where the GPU time went |
|
||||
| --- | --- | --- | --- |
|
||||
| 128 tokens | 7.0 s (18 tok/s) | 11.3 s (weights not yet overlapped) | upload 6.0 s |
|
||||
| 1024 tokens | 54.0 s (19.0 tok/s) | 20.9 s (48.9 tok/s) | attention 6.4, experts 13.8 |
|
||||
| 4096 tokens | 247 s (16.6 tok/s, earlier session) | 91.9 s (44.6 tok/s) with the first attention kernel, 67.5 s (60.7 tok/s) with the vec4 one | attention 45.3 -> 22.8, experts 44 |
|
||||
| 8192 tokens | not run | 244.9 s (33.5 tok/s) with the first attention kernel | attention 147, experts 95 |
|
||||
| Prompt tokens | pairs | CPU median s (tok/s) | GPU median s (tok/s) | paired speed-up, mean (95% CI) |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 512 | 5 | 31.6 (16.2) | 10.1 (50.8) | 2.87x (2.45-3.29) |
|
||||
| 1024 | 5 | 60.4 (17.0) | 18.0 (56.8) | 3.40x (2.77-4.04) |
|
||||
| 2048 | 3 | 126.6 (16.2) | 31.8 (64.3) | 3.97x (3.39-4.55) |
|
||||
| 4096 | 3 | 270.0 (15.2) | 74.4 (55.1) | 3.57x (2.87-4.26) |
|
||||
|
||||
At short prompts the GPU path is not faster (hence the default 256-token threshold in the worker). Long prompts:
|
||||
experts are the floor (the grouped GEMM runs at about 0.6 TOPS of integer work, `crates/igpu/examples/gemm_bench.rs`)
|
||||
and attention grows with the square of the context (one full layer over a 512-token batch ending at position 4096:
|
||||
0.52 s with the first kernel, 0.22 s with the vec4 one; sliding layers 0.008 s).
|
||||
Limits of this result: synthetic random-id prompts (not an agent trace), three to five pairs per size (enough for a
|
||||
3x effect, not for percent-level claims), the machine was otherwise idle but clocks and power were not controlled,
|
||||
and the GPU path's quality is the borderline gate result above. Time-to-first-token for a real request also
|
||||
includes the CPU's lm-head and the control plane; the end-to-end agent workload A/B is still to do.
|
||||
|
||||
Where the GPU time goes (earlier single runs): experts are the floor (the grouped GEMM runs at 0.6-0.85 TOPS of
|
||||
integer work against 4.49 TOPS for `dot4I8Packed` alone, `examples/dot4_peak.rs`, tile sweep with
|
||||
`LELEKA_IGPU_TILE`), and attention grows with the square of the context (one full layer over a 512-token batch
|
||||
ending at position 4096: 0.52 s with the first kernel, 0.22 s with the vec4 one). Below about 256 prompt tokens
|
||||
the GPU is not faster (128 tokens: CPU 7.0 s, GPU 11.3 s before the upload overlap), hence the worker's default
|
||||
threshold.
|
||||
|
||||
## Next
|
||||
|
||||
|
||||
Reference in New Issue
Block a user