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)]
47#[cfg_attr(feature = "ts-bindings", derive(ts_rs::TS), ts(export))]
48pub struct ModelPerfResult {
49    /// Database ID of this result row (set after persistence).
50    #[cfg_attr(feature = "ts-bindings", ts(type = "number | null"))]
51    pub id: Option<i64>,
52    /// Foreign key → `models.id`.
53    #[cfg_attr(feature = "ts-bindings", ts(type = "number"))]
54    pub model_id: i64,
55    /// Foreign key → `benchmark_runs.id` (nullable; SET NULL on run delete).
56    #[cfg_attr(feature = "ts-bindings", ts(type = "number | null"))]
57    pub run_id: Option<i64>,
58    /// Prompt-processing throughput (tokens/sec).
59    pub pp_tps: f64,
60    /// Token-generation throughput (tokens/sec).
61    pub tg_tps: f64,
62    /// Number of prompt tokens used in the benchmark.
63    #[cfg_attr(feature = "ts-bindings", ts(type = "number"))]
64    pub pp_tokens: i64,
65    /// Number of generation tokens used in the benchmark.
66    #[cfg_attr(feature = "ts-bindings", ts(type = "number"))]
67    pub tg_tokens: i64,
68    /// Backend reported by llama-bench (e.g. "Metal", "CUDA", "CPU").
69    pub backend: Option<String>,
70    /// Number of GPU layers offloaded.
71    #[cfg_attr(feature = "ts-bindings", ts(type = "number | null"))]
72    pub ngl: Option<i64>,
73    /// Context size used.
74    #[cfg_attr(feature = "ts-bindings", ts(type = "number | null"))]
75    pub context_size: Option<i64>,
76    /// Number of repetitions averaged.
77    #[cfg_attr(feature = "ts-bindings", ts(type = "number"))]
78    pub repetitions: i64,
79    /// UTC timestamp of this result.
80    pub created_at: DateTime<Utc>,
81}