Skip to main content

gglib_core/domain/benchmark/
perf.rs

1//! Perf-mode benchmark types: `llama-bench` configuration and results.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6/// Configuration for a performance (`llama-bench`) run.
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct PerfConfig {
9    /// Models to benchmark (by database ID), run sequentially.
10    pub model_ids: Vec<i64>,
11    /// Number of prompt tokens to use in the benchmark.
12    #[serde(default = "PerfConfig::default_pp_tokens")]
13    pub pp_tokens: u32,
14    /// Number of generation tokens to use in the benchmark.
15    #[serde(default = "PerfConfig::default_tg_tokens")]
16    pub tg_tokens: u32,
17    /// Number of repetitions to average.
18    #[serde(default = "PerfConfig::default_repetitions")]
19    pub repetitions: u32,
20}
21
22impl PerfConfig {
23    const fn default_pp_tokens() -> u32 {
24        512
25    }
26    const fn default_tg_tokens() -> u32 {
27        128
28    }
29    const fn default_repetitions() -> u32 {
30        3
31    }
32}
33
34impl Default for PerfConfig {
35    fn default() -> Self {
36        Self {
37            model_ids: vec![],
38            pp_tokens: Self::default_pp_tokens(),
39            tg_tokens: Self::default_tg_tokens(),
40            repetitions: Self::default_repetitions(),
41        }
42    }
43}
44
45/// Result of running `llama-bench` on a single model.
46#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct ModelPerfResult {
48    /// Database ID of this result row (set after persistence).
49    pub id: Option<i64>,
50    /// Foreign key → `models.id`.
51    pub model_id: i64,
52    /// Foreign key → `benchmark_runs.id` (nullable; SET NULL on run delete).
53    pub run_id: Option<i64>,
54    /// Prompt-processing throughput (tokens/sec).
55    pub pp_tps: f64,
56    /// Token-generation throughput (tokens/sec).
57    pub tg_tps: f64,
58    /// Number of prompt tokens used in the benchmark.
59    pub pp_tokens: i64,
60    /// Number of generation tokens used in the benchmark.
61    pub tg_tokens: i64,
62    /// Backend reported by llama-bench (e.g. "Metal", "CUDA", "CPU").
63    pub backend: Option<String>,
64    /// Number of GPU layers offloaded.
65    pub ngl: Option<i64>,
66    /// Context size used.
67    pub context_size: Option<i64>,
68    /// Number of repetitions averaged.
69    pub repetitions: i64,
70    /// UTC timestamp of this result.
71    pub created_at: DateTime<Utc>,
72}