pub struct ModelSwitcher { /* private fields */ }Expand description
The model switcher coordinates wake/sleep transitions.
Implementations§
Source§impl ModelSwitcher
impl ModelSwitcher
pub fn new(hooks: Arc<HookRunner>, policy: Box<dyn SwitchPolicy>) -> Self
pub async fn state(&self) -> SwitcherState
pub async fn active_model(&self) -> Option<String>
pub fn registered_models(&self) -> Vec<String>
pub fn hooks(&self) -> &Arc<HookRunner>
pub fn is_registered(&self, model: &str) -> bool
pub fn model_port(&self, model: &str) -> Option<u16>
pub fn in_flight_count(&self, model: &str) -> usize
Sourcepub fn estimated_switch_cost(
&self,
from: Option<&str>,
to: &str,
) -> Option<Duration>
pub fn estimated_switch_cost( &self, from: Option<&str>, to: &str, ) -> Option<Duration>
Estimated cost of switching between two models, based on observed durations.
from is None for cold starts from Idle.
Sourcepub async fn force_switch(&self, model: &str) -> Result<(), SwitchError>
pub async fn force_switch(&self, model: &str) -> Result<(), SwitchError>
Force a switch to the given model, bypassing policy.
Sourcepub fn acquire_in_flight(&self, model: &str) -> Option<InFlightGuard>
pub fn acquire_in_flight(&self, model: &str) -> Option<InFlightGuard>
Acquire an in-flight guard.
Returns None if the model is not registered or if it is currently
draining. Uses increment-then-check to close the TOCTOU window.
Sourcepub async fn queue_depths(&self) -> HashMap<String, usize>
pub async fn queue_depths(&self) -> HashMap<String, usize>
Get queue depths for every registered model.
Sourcepub fn spawn_scheduler(self) -> Option<JoinHandle<()>>
pub fn spawn_scheduler(self) -> Option<JoinHandle<()>>
Spawn a background scheduler task if the policy requests one.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ModelSwitcher
impl !RefUnwindSafe for ModelSwitcher
impl Send for ModelSwitcher
impl Sync for ModelSwitcher
impl Unpin for ModelSwitcher
impl UnsafeUnpin for ModelSwitcher
impl !UnwindSafe for ModelSwitcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more