Skip to main content

ModelRuntime

Struct ModelRuntime 

Source
pub struct ModelRuntime<B: BackendProvider> { /* private fields */ }
Expand description

A prepared model, its selected backend, and its backend-owned session.

This is the canonical client-side execution owner. Keeping the backend and session together makes backend selection a whole-model decision and makes it impossible to submit a session through a different backend instance. Backend-owned executable, cache, tensor, and completion types remain associated types and never enter the portable API.

Implementations§

Source§

impl<B: BackendProvider> ModelRuntime<B>

Source

pub fn prepare(backend: B, config: B::ModelConfig) -> Result<Self, B::Error>

Prepares config and creates its sole execution session.

Source

pub fn from_prepared( backend: B, model: PreparedModel<B::Model>, ) -> Result<Self, B::Error>

Creates the sole execution session for an already prepared model.

Source

pub const fn backend(&self) -> &B

Returns the selected backend.

Source

pub const fn session(&self) -> &B::Session

Returns the backend-owned session for optional backend capabilities.

Source

pub fn session_mut(&mut self) -> &mut B::Session

Returns the backend-owned session for optional backend capabilities.

Source

pub fn parts_mut(&mut self) -> (&B, &mut B::Session)

Borrows the selected backend and its mutable session together.

Source

pub fn capabilities(&self) -> SessionCapabilities

Reports capabilities of the exact prepared model session.

Source

pub fn prefill( &mut self, input: <B::Session as BackendSession<B>>::PrefillInput, ) -> Result<SessionSubmission<B>, B::Error>

Submits prompt prefill through the selected backend and session.

Source

pub fn decode( &mut self, input: <B::Session as BackendSession<B>>::DecodeInput, ) -> Result<SessionSubmission<B>, B::Error>

Submits cached decode through the selected backend and session.

Source

pub fn observe_output( &self, output: &<B::Session as BackendSession<B>>::Output, ) -> Result<ObservationSet, B::Error>

Materializes portable observations from an already completed output.

Source§

impl<B> ModelRuntime<B>

Source

pub fn inspect_prefill( &mut self, input: <B::Session as BackendSession<B>>::PrefillInput, request: &ObservationRequest, ) -> Result<InspectedOutput<<B::Session as BackendSession<B>>::Output>, B::Error>

Executes a completed, explicitly instrumented prefill operation.

Source

pub fn inspect_decode( &mut self, input: <B::Session as BackendSession<B>>::DecodeInput, request: &ObservationRequest, ) -> Result<InspectedOutput<<B::Session as BackendSession<B>>::Output>, B::Error>

Executes a completed, explicitly instrumented decode operation.

Source§

impl<B: ModelLoadingBackend> ModelRuntime<B>

Source

pub fn load( backend: B, artifact: impl AsRef<Path>, options: B::LoadOptions, ) -> Result<Self, ModelLoadError<B::Error>>

Loads an artifact and creates its sole session on backend.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.