Skip to main content

el_core/
value_objects.rs

1//! Core value objects from the ubiquitous language.
2
3/// A vocabulary id produced or consumed by the model — the atomic generation
4/// unit.
5pub type Token = u32;
6
7/// Supported on-disk model formats (ADR-002). `.pte`/GGUF-via-C++ is gone;
8/// Candle reads GGUF and safetensors natively, ONNX via `tract`.
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum ModelFormat {
11    Gguf,
12    Safetensors,
13    Onnx,
14}
15
16/// The execution engine that owns a loaded model (ADR-002).
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum RuntimeKind {
19    /// Pure-Rust Candle (primary): GGUF/safetensors, CPU NEON + Metal + WebGPU.
20    Candle,
21    /// Pure-Rust `tract` for the optional ONNX path.
22    Tract,
23}
24
25impl ModelFormat {
26    /// The engine required by this format. Encodes the ADR-002 compatibility
27    /// rule (`GGUF`/`safetensors` → Candle, `ONNX` → tract).
28    pub fn runtime(self) -> RuntimeKind {
29        match self {
30            ModelFormat::Gguf | ModelFormat::Safetensors => RuntimeKind::Candle,
31            ModelFormat::Onnx => RuntimeKind::Tract,
32        }
33    }
34}
35
36/// Requested device class; `Auto` is resolved by the Hardware & Delegate
37/// context at runtime.
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub enum DeviceTarget {
40    Auto,
41    MidRange,
42    HighEnd,
43}
44
45/// Inference session state machine (ADR-001).
46#[derive(Debug, Clone, Copy, PartialEq, Eq)]
47pub enum Phase {
48    Initialized,
49    Prefilling,
50    Decoding,
51    Completed,
52}
53
54impl Phase {
55    pub fn as_str(self) -> &'static str {
56        match self {
57            Phase::Initialized => "Initialized",
58            Phase::Prefilling => "Prefilling",
59            Phase::Decoding => "Decoding",
60            Phase::Completed => "Completed",
61        }
62    }
63}
64
65/// Tiered safety strategy (ADR-005), budget-gated by device profile.
66#[derive(Debug, Clone, Copy, PartialEq, Eq)]
67pub enum SafetyMode {
68    Off,
69    Lightweight,
70    SecDecoding,
71    Csd,
72}
73
74/// Speculative decoding strategy (ADR-002 / context 3). Default is `Off`.
75#[derive(Debug, Clone, Copy, PartialEq, Eq)]
76pub enum SpeculationMode {
77    Off,
78    Draft,
79    LeverLite,
80}
81
82/// Why generation stopped.
83#[derive(Debug, Clone, Copy, PartialEq, Eq)]
84pub enum StopReason {
85    Eos,
86    MaxTokens,
87    Stopped,
88}
89
90#[cfg(test)]
91mod tests {
92    use super::*;
93
94    #[test]
95    fn format_picks_engine() {
96        assert_eq!(ModelFormat::Gguf.runtime(), RuntimeKind::Candle);
97        assert_eq!(ModelFormat::Safetensors.runtime(), RuntimeKind::Candle);
98        assert_eq!(ModelFormat::Onnx.runtime(), RuntimeKind::Tract);
99    }
100}