benchmarks-mv
Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS.
Brought by drakestapleton
benchmarks-mv / src / harness / inference_bench.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | use super::llm_stream::{self, distribution, Distribution, StreamConfig, TokenAccounting}; |
| 17 | use crate::models::NeuralMetric; |
| 18 | use std::io::{Read, Write}; |
| 19 | use std::net::TcpStream; |
| 20 | use std::time::{Duration, Instant}; |
| 21 | |
| 22 | pub fn measure_embedding_latency( |
| 23 | host: &str, |
| 24 | port: u16, |
| 25 | text: &str, |
| 26 | iterations: usize, |
| 27 | ) -> Result<Distribution, String> { |
| 28 | let mut latencies = Vec::with_capacity(iterations); |
| 29 | let body = format!(r#"{{"text":"{}"}}"#, text); |
| 30 | |
| 31 | for _ in 0..iterations { |
| 32 | let addr = format!("{}:{}", host, port); |
| 33 | let mut stream = |
| 34 | TcpStream::connect(&addr).map_err(|e| format!("Connect to {} failed: {}", addr, e))?; |
| 35 | stream |
| 36 | .set_read_timeout(Some(Duration::from_secs(5))) |
| 37 | .map_err(|e| e.to_string())?; |
| 38 | stream |
| 39 | .set_write_timeout(Some(Duration::from_secs(5))) |
| 40 | .map_err(|e| e.to_string())?; |
| 41 | |
| 42 | let req = format!( |
| 43 | "POST /embed HTTP/1.1\r\nHost: {}:{}\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}", |
| 44 | host, port, body.len(), body |
| 45 | ); |
| 46 | |
| 47 | let t0 = Instant::now(); |
| 48 | stream |
| 49 | .write_all(req.as_bytes()) |
| 50 | .map_err(|e| format!("Write error: {}", e))?; |
| 51 | let mut buf = [0u8; 1024]; |
| 52 | let mut read_any = false; |
| 53 | while let Ok(n) = stream.read(&mut buf) { |
| 54 | if n == 0 { |
| 55 | break; |
| 56 | } |
| 57 | read_any = true; |
| 58 | } |
| 59 | if read_any { |
| 60 | latencies.push(t0.elapsed().as_secs_f64() * 1000.0); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if latencies.is_empty() { |
| 65 | return Err("No successful embedding responses".to_string()); |
| 66 | } |
| 67 | |
| 68 | Ok(distribution(&latencies)) |
| 69 | } |
| 70 | |
| 71 | /// Live neural rows for the measurement sweep: the configured streaming endpoint (if any) |
| 72 | /// and the embedding service. Labels come from the configuration, never from constants. |
| 73 | pub fn run_neural_inference_benchmarks(llm: Option<&StreamConfig>) -> Vec<NeuralMetric> { |
| 74 | let mut metrics = Vec::new(); |
| 75 | |
| 76 | if let Some(cfg) = llm { |
| 77 | println!( |
| 78 | " Benchmarking streaming endpoint {} (model {}, engine {}, {} request(s), concurrency {})...", |
| 79 | cfg.endpoint(), |
| 80 | cfg.model, |
| 81 | cfg.engine, |
| 82 | cfg.requests, |
| 83 | cfg.concurrency |
| 84 | ); |
| 85 | let run = llm_stream::run_stream_benchmark(cfg); |
| 86 | let s = llm_stream::summarize(&run.samples, run.wall); |
| 87 | print_stream_summary(&s); |
| 88 | if s.requests_ok > 0 { |
| 89 | metrics.push(NeuralMetric { |
| 90 | measurement_id: Some("BENCH-LIVE-TTFT-001".to_string()), |
| 91 | workload: format!("First content event latency (TTFT), N={}", s.ttft.samples), |
| 92 | model: cfg.model.clone(), |
| 93 | engine: cfg.engine.clone(), |
| 94 | p50_ms: s.ttft.p50.unwrap_or_default(), |
| 95 | p95_ms: s.ttft.p95, |
| 96 | }); |
| 97 | if let Some(p50) = s.inter_event.p50 { |
| 98 | metrics.push(NeuralMetric { |
| 99 | measurement_id: Some("BENCH-LIVE-INTER-EVENT-001".to_string()), |
| 100 | workload: format!( |
| 101 | "Inter-event latency (SSE events, not tokens), N={}", |
| 102 | s.inter_event.samples |
| 103 | ), |
| 104 | model: cfg.model.clone(), |
| 105 | engine: cfg.engine.clone(), |
| 106 | p50_ms: p50, |
| 107 | p95_ms: s.inter_event.p95, |
| 108 | }); |
| 109 | } |
| 110 | if let Some(tpot) = s.tpot.as_ref().filter(|d| d.p50.is_some()) { |
| 111 | metrics.push(NeuralMetric { |
| 112 | measurement_id: Some("BENCH-LIVE-TPOT-001".to_string()), |
| 113 | workload: format!("Time per output token (backend usage), N={}", tpot.samples), |
| 114 | model: cfg.model.clone(), |
| 115 | engine: cfg.engine.clone(), |
| 116 | p50_ms: tpot.p50.unwrap_or_default(), |
| 117 | p95_ms: tpot.p95, |
| 118 | }); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // Embedding service on port 18081 (cortex-encoder-rs ONNX); unchanged target. |
| 124 | println!(" Benchmarking live embedding service (port 18081, BGE-base-en-v1.5 INT8)..."); |
| 125 | match measure_embedding_latency( |
| 126 | "127.0.0.1", |
| 127 | 18081, |
| 128 | "The sovereign architecture achieves deterministic low-latency execution on Grace Blackwell.", |
| 129 | 10, |
| 130 | ) { |
| 131 | Ok(d) => { |
| 132 | println!( |
| 133 | " cortex-encoder-rs (ONNX INT8): p50 {:.2} ms | p95 {} | N={}", |
| 134 | d.p50.unwrap_or_default(), |
| 135 | fmt_opt_ms(d.p95), |
| 136 | d.samples |
| 137 | ); |
| 138 | metrics.push(NeuralMetric { |
| 139 | measurement_id: Some("BENCH-LIVE-EMBED-001".to_string()), |
| 140 | workload: format!("Bi-Encoder Vector Embedding, N={}", d.samples), |
| 141 | model: "BAAI/bge-base-en-v1.5 (INT8)".to_string(), |
| 142 | engine: "cortex-encoder-rs (ONNX Runtime)".to_string(), |
| 143 | p50_ms: d.p50.unwrap_or_default(), |
| 144 | p95_ms: d.p95, |
| 145 | }); |
| 146 | } |
| 147 | Err(e) => { |
| 148 | println!(" [Notice] cortex-encoder-rs (18081) skipped: {}", e); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | metrics |
| 153 | } |
| 154 | |
| 155 | pub fn fmt_opt_ms(v: Option<f64>) -> String { |
| 156 | v.map(|x| format!("{:.2} ms", x)) |
| 157 | .unwrap_or_else(|| "n/a (too few samples)".to_string()) |
| 158 | } |
| 159 | |
| 160 | /// Terminal summary; under events_not_tokens it never prints tokens per second. |
| 161 | pub fn print_stream_summary(s: &llm_stream::StreamSummary) { |
| 162 | println!( |
| 163 | " requests ok {}/{} | wall {:.1} ms | token accounting: {}", |
| 164 | s.requests_ok, |
| 165 | s.requests_attempted, |
| 166 | s.wall_ms, |
| 167 | s.token_accounting.as_str() |
| 168 | ); |
| 169 | for (kind, n) in &s.failures { |
| 170 | println!(" failed: {} x {}", n, kind); |
| 171 | } |
| 172 | if s.requests_ok == 0 { |
| 173 | return; |
| 174 | } |
| 175 | println!( |
| 176 | " TTFT p50 {} | p95 {} | N={}", |
| 177 | fmt_opt_ms(s.ttft.p50), |
| 178 | fmt_opt_ms(s.ttft.p95), |
| 179 | s.ttft.samples |
| 180 | ); |
| 181 | println!( |
| 182 | " inter-event (events, not tokens) p50 {} | p95 {} | N={} | coalesced in one read: {}", |
| 183 | fmt_opt_ms(s.inter_event.p50), |
| 184 | fmt_opt_ms(s.inter_event.p95), |
| 185 | s.inter_event.samples, |
| 186 | s.events_coalesced_in_read |
| 187 | ); |
| 188 | if let Some(eps) = s.events_per_sec { |
| 189 | println!(" content events/s: {:.1}", eps); |
| 190 | } |
| 191 | if s.token_accounting == TokenAccounting::BackendUsage { |
| 192 | if let (Some(total), Some(tps)) = (s.output_tokens_total, s.output_tokens_per_sec) { |
| 193 | println!( |
| 194 | " backend usage: {} output tokens, {:.1} output tokens/s", |
| 195 | total, tps |
| 196 | ); |
| 197 | } |
| 198 | if let Some(t) = &s.tpot { |
| 199 | println!( |
| 200 | " time per output token p50 {} | p95 {} | N={}", |
| 201 | fmt_opt_ms(t.p50), |
| 202 | fmt_opt_ms(t.p95), |
| 203 | t.samples |
| 204 | ); |
| 205 | } |
| 206 | } |
| 207 | } |