infernum_arbiter/
priority.rs1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
9pub enum Priority {
10 Background = 0,
12 Low = 1,
14 Normal = 2,
16 High = 3,
18 Critical = 4,
20}
21
22impl Default for Priority {
23 fn default() -> Self {
24 Self::Normal
25 }
26}
27
28impl Priority {
29 pub fn can_preempt(self, other: Self) -> bool {
31 self as u8 > other as u8 + 1
32 }
33
34 pub fn quality_multiplier(self) -> f32 {
38 match self {
39 Self::Background => 0.6,
40 Self::Low => 0.8,
41 Self::Normal => 1.0,
42 Self::High => 1.1,
43 Self::Critical => 1.2,
44 }
45 }
46
47 pub fn timeout_multiplier(self) -> f32 {
51 match self {
52 Self::Background => 0.5,
53 Self::Low => 0.75,
54 Self::Normal => 1.0,
55 Self::High => 1.5,
56 Self::Critical => 2.0,
57 }
58 }
59}
60
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
63pub enum WorkloadType {
64 LlmInference,
66 ImageGeneration,
68 VideoGeneration,
70}
71
72impl WorkloadType {
73 pub fn min_quality(self) -> f32 {
77 match self {
78 Self::LlmInference => 0.4, Self::ImageGeneration => 0.3, Self::VideoGeneration => 0.25, }
82 }
83
84 pub fn target_quality(self) -> f32 {
86 match self {
87 Self::LlmInference => 1.0,
88 Self::ImageGeneration => 1.0,
89 Self::VideoGeneration => 1.0,
90 }
91 }
92
93 pub fn typical_memory_mb(self) -> u64 {
95 match self {
96 Self::LlmInference => 8 * 1024, Self::ImageGeneration => 6 * 1024, Self::VideoGeneration => 12 * 1024, }
100 }
101
102 pub fn is_streaming(self) -> bool {
104 match self {
105 Self::LlmInference => true, Self::ImageGeneration => false, Self::VideoGeneration => true, }
109 }
110}
111
112#[cfg(test)]
113mod tests {
114 use super::*;
115
116 #[test]
117 fn test_priority_ordering() {
118 assert!(Priority::Critical > Priority::High);
119 assert!(Priority::High > Priority::Normal);
120 assert!(Priority::Normal > Priority::Low);
121 assert!(Priority::Low > Priority::Background);
122 }
123
124 #[test]
125 fn test_preemption() {
126 assert!(Priority::Critical.can_preempt(Priority::Normal));
127 assert!(Priority::Critical.can_preempt(Priority::Low));
128 assert!(!Priority::High.can_preempt(Priority::Normal));
129 assert!(!Priority::Normal.can_preempt(Priority::Normal));
130 }
131
132 #[test]
133 fn test_quality_multipliers() {
134 assert!(Priority::Critical.quality_multiplier() > Priority::Normal.quality_multiplier());
135 assert!(Priority::Normal.quality_multiplier() > Priority::Background.quality_multiplier());
136 }
137
138 #[test]
139 fn test_workload_min_quality() {
140 assert!(
141 WorkloadType::LlmInference.min_quality() > WorkloadType::VideoGeneration.min_quality()
142 );
143 }
144}