pub struct Supervisor { /* private fields */ }Expand description
The per-node supervisor. Cheap to clone.
Implementations§
Source§impl Supervisor
impl Supervisor
pub fn new( engines: Vec<EngineConfig>, models: Vec<ModelLaunch>, opts: SupervisorOptions, ) -> Self
Sourcepub fn add_adapter(
&self,
base: &str,
adapter: LoraAdapter,
) -> Result<AdapterChange, RemoteError>
pub fn add_adapter( &self, base: &str, adapter: LoraAdapter, ) -> Result<AdapterChange, RemoteError>
Adds LoRA adapter adapter to model base, after ModelLaunch::check_adapters. Its id
must be free on the node. Returns AdapterChange::Live when the base isn’t running or
its engine already has the adapter loaded (on llama.cpp: the same file, for example one
removed and added back), else AdapterChange::NextLoad. It never touches the engine:
Supervisor::add_adapter_live also loads it into a running vLLM engine. Emits
SupervisorEvent::Added for the adapter.
Sourcepub async fn add_adapter_live(
&self,
base: &str,
adapter: LoraAdapter,
) -> Result<AdapterChange, RemoteError>
pub async fn add_adapter_live( &self, base: &str, adapter: LoraAdapter, ) -> Result<AdapterChange, RemoteError>
Supervisor::add_adapter, then, when the base runs on vLLM with LoRA on
(ModelLaunch::runtime_lora), loads the adapter into the running engine
(/v1/load_lora_adapter) so it serves at once, without restarting the base. If the engine
refuses it, the adapter is taken off the base again and the engine’s error returned.
On llama.cpp an adapter file the engine didn’t start with still waits for the next load
(AdapterChange::NextLoad).
Sourcepub async fn remove_adapter_live(
&self,
base: &str,
id: &str,
) -> Result<LoraAdapter, RemoteError>
pub async fn remove_adapter_live( &self, base: &str, id: &str, ) -> Result<LoraAdapter, RemoteError>
Supervisor::remove_adapter, then, on a running vLLM engine with run-time LoRA, unloads
it from the engine too (/v1/unload_lora_adapter), freeing its memory. llama-server keeps
the file loaded (unused) until the base’s next load; adding it back is then live.
Sourcepub fn set_adapter_scale(
&self,
id: &str,
scale: Option<f32>,
) -> Result<(), RemoteError>
pub fn set_adapter_scale( &self, id: &str, scale: Option<f32>, ) -> Result<(), RemoteError>
Changes how strongly adapter id applies, from the next request on (None: 1.0). Live:
llama.cpp takes the scale per request, so the base keeps running. Requests may still set
their own (Request::adapter_scale). vLLM applies adapters at full strength and refuses.
Sourcepub fn remove_adapter(
&self,
base: &str,
id: &str,
) -> Result<LoraAdapter, RemoteError>
pub fn remove_adapter( &self, base: &str, id: &str, ) -> Result<LoraAdapter, RemoteError>
Stops serving adapter id on base (requests for it fail from now on; the engine keeps
it loaded until the base’s next load, see Supervisor::remove_adapter_live). Emits
SupervisorEvent::Removed.
Sourcepub async fn set_projector_live(
&self,
id: &str,
mmproj: Option<String>,
) -> Result<AdapterChange, RemoteError>
pub async fn set_projector_live( &self, id: &str, mmproj: Option<String>, ) -> Result<AdapterChange, RemoteError>
Sets (or with None clears) llama.cpp model id’s multimodal projector
(ModelLaunch::mmproj), from the next load on: its capabilities change at once, and
AdapterChange::NextLoad says the running engine started with another projector
(llama-server reads it only at start; loading the model restarts it).
Sourcepub fn add_model(&self, launch: ModelLaunch) -> Result<(), RemoteError>
pub fn add_model(&self, launch: ModelLaunch) -> Result<(), RemoteError>
Adds a model the node may load from now on, without a restart (for example one just
downloaded). It starts unloaded. Refused when the id is taken; Supervisor::remove_model
first to replace one. Emits SupervisorEvent::Added.
Sourcepub async fn remove_model(&self, id: &str) -> Result<ModelLaunch, RemoteError>
pub async fn remove_model(&self, id: &str) -> Result<ModelLaunch, RemoteError>
Unloads id (draining requests under way) and forgets it, with its adapters. Emits
SupervisorEvent::Removed for each. Returns its launch settings. An adapter’s id is
refused: use Supervisor::remove_adapter.
Sourcepub fn launches(&self) -> Vec<ModelLaunch>
pub fn launches(&self) -> Vec<ModelLaunch>
The configured models’ launch settings, sorted by id.
Sourcepub fn subscribe(&self) -> Receiver<SupervisorEvent>
pub fn subscribe(&self) -> Receiver<SupervisorEvent>
Engine events from now on.
Sourcepub fn status(&self) -> Vec<ModelStatus>
pub fn status(&self) -> Vec<ModelStatus>
One row per model, and one per adapter (with ModelStatus::base set, the base’s engine,
capabilities and state; Unloaded while the base runs without it).
Sourcepub fn state(&self, id: &str) -> Option<ModelState>
pub fn state(&self, id: &str) -> Option<ModelState>
id’s state; an adapter has its base’s (Unloaded while the base runs without it).
Sourcepub fn capabilities(&self, id: &str) -> Option<Capabilities>
pub fn capabilities(&self, id: &str) -> Option<Capabilities>
What id takes (ModelLaunch::capabilities); an adapter takes what its base does.
Sourcepub async fn load(&self, id: &str) -> Result<(), RemoteError>
pub async fn load(&self, id: &str) -> Result<(), RemoteError>
Starts id and waits until it is ready (see Supervisor::load_with).
Sourcepub async fn load_with(&self, id: &str, force: bool) -> Result<(), RemoteError>
pub async fn load_with(&self, id: &str, force: bool) -> Result<(), RemoteError>
Starts id and waits until its engine is ready. Loading a model in a swap group unloads the
group’s other models first. Already ready: returns at once. A model in a crash loop or
waiting for its restart refuses unless force (an operator’s explicit load), which also
clears the crash history.
An adapter loads its base. When the base is ready without it (added after the base started), the base is restarted.
While the node is reserved (Supervisor::reserve) every load is refused, force too.
Sourcepub async fn unload(&self, id: &str) -> Result<(), RemoteError>
pub async fn unload(&self, id: &str) -> Result<(), RemoteError>
Drains and stops id. A wrapped server is only detached (the node doesn’t own it).
An adapter’s id is refused: unload its base.
Sourcepub async fn reserve(&self, holder: &str) -> Result<Reservation, RemoteError>
pub async fn reserve(&self, holder: &str) -> Result<Reservation, RemoteError>
Reserves the node for holder: from now on no engine starts (loads, loads on demand,
crash restarts and swaps are refused as unavailable), and every running engine is drained
(waiting up to drain_timeout for requests under way) and stopped. Returns once they are
stopped. Taking it again under the same holder is a no-op; another holder’s reservation is
refused as unavailable. Held in memory until Supervisor::release: an application that
must keep it across a restart records it and reserves again at start.
Sourcepub fn release(&self, holder: &str) -> Result<bool, RemoteError>
pub fn release(&self, holder: &str) -> Result<bool, RemoteError>
Ends holder’s reservation; models load again on the next request or load. false when
the node was not reserved; another holder’s reservation is refused as a bad request.
Sourcepub fn reservation(&self) -> Option<Reservation>
pub fn reservation(&self) -> Option<Reservation>
The node’s reservation, if any.
Sourcepub fn reservation_changes(&self) -> Receiver<Option<Reservation>>
pub fn reservation_changes(&self) -> Receiver<Option<Reservation>>
Changes to the reservation, from now on.
Sourcepub async fn reap_idle(&self) -> Vec<String>
pub async fn reap_idle(&self) -> Vec<String>
Unloads ready models idle past their idle_ttl. Returns what it unloaded. Run it every few
seconds (Supervisor::spawn_reaper).
Sourcepub fn spawn_reaper(&self, every: Duration) -> JoinHandle<()> ⓘ
pub fn spawn_reaper(&self, every: Duration) -> JoinHandle<()> ⓘ
Runs Supervisor::reap_idle every every until the returned handle is aborted.
Sourcepub async fn chat(
&self,
id: &str,
request: &Request,
) -> Result<ChunkStream, RemoteError>
pub async fn chat( &self, id: &str, request: &Request, ) -> Result<ChunkStream, RemoteError>
Streams a chat answer from id, which must be ready. Dropping the stream aborts the engine
request. For an adapter on llama.cpp, Request::adapter_scale overrides its scale.
Sourcepub async fn complete(
&self,
id: &str,
prompt: &str,
sampling: &Sampling,
seed: Option<u64>,
) -> Result<ChunkStream, RemoteError>
pub async fn complete( &self, id: &str, prompt: &str, sampling: &Sampling, seed: Option<u64>, ) -> Result<ChunkStream, RemoteError>
Streams a raw text completion of prompt from id, which must be ready. Response
formats and tools don’t apply.
Sourcepub async fn complete_scaled(
&self,
id: &str,
prompt: &str,
sampling: &Sampling,
seed: Option<u64>,
adapter_scale: Option<f32>,
) -> Result<ChunkStream, RemoteError>
pub async fn complete_scaled( &self, id: &str, prompt: &str, sampling: &Sampling, seed: Option<u64>, adapter_scale: Option<f32>, ) -> Result<ChunkStream, RemoteError>
Supervisor::complete with an adapter scale for this request (llama.cpp adapters only;
None uses the adapter’s own).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Supervisor
impl !UnwindSafe for Supervisor
impl Forget for Supervisor
impl Freeze for Supervisor
impl Move for Supervisor
impl Send for Supervisor
impl Sync for Supervisor
impl Unpin for Supervisor
impl UnsafeUnpin for Supervisor
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.