RealtimeOptimizer

Struct RealtimeOptimizer 

Source
pub struct RealtimeOptimizer { /* private fields */ }
Expand description

Real-time optimizer for LLM inference

Implementations§

Source§

impl RealtimeOptimizer

Source

pub fn new(config: RealtimeConfig) -> Self

Create a new realtime optimizer

Source

pub fn optimize_batch_size(&self, recent_latencies: &[f32]) -> usize

Optimize batch size based on recent latency measurements

Source

pub fn should_evict_kv_cache(&self) -> bool

Check if KV cache eviction is needed

Source

pub fn update_kv_cache_pressure(&self, pressure: f32)

Update KV cache pressure

Source

pub fn kv_cache_pressure(&self) -> f32

Get KV cache pressure

Source

pub fn allocate_token_budget( &self, requests: &[Request], ) -> Vec<TokenBudgetAllocation>

Allocate token budgets for a set of requests

Source

pub fn enable_speculative_decoding(&self, draft_model: &str)

Enable speculative decoding

Source

pub fn disable_speculative_decoding(&self)

Disable speculative decoding

Source

pub fn update_speculation_stats( &self, accepted_count: usize, total_drafted: usize, )

Update speculation statistics for learning/monitoring

This records the acceptance rate of speculative decoding rounds to help tune the lookahead parameter adaptively.

§Arguments
  • accepted_count - Number of draft tokens that were accepted
  • total_drafted - Total number of draft tokens generated
Source

pub fn is_speculative_active(&self) -> bool

Check if speculative decoding is active

Source

pub fn draft_model(&self) -> Option<String>

Get the draft model identifier

Source

pub fn record_latency(&self, latency_ms: f32)

Record a latency measurement

Source

pub fn record_throughput(&self, tps: f32)

Record a throughput measurement

Source

pub fn average_latency(&self) -> f32

Get average latency

Source

pub fn average_throughput(&self) -> f32

Get average throughput

Source

pub fn update_memory_usage(&self, bytes: usize)

Update memory usage

Source

pub fn memory_pressure(&self) -> f32

Get memory pressure (0.0 - 1.0)

Source

pub fn optimize(&self, metrics: &InferenceMetrics) -> OptimizationDecision

Make a comprehensive optimization decision

Source

pub fn add_request(&self, request: Request)

Add a pending request

Source

pub fn remove_request(&self, request_id: &str)

Remove a completed request

Source

pub fn pending_request_count(&self) -> usize

Get pending request count

Source

pub fn current_batch_size(&self) -> usize

Get current batch size

Source

pub fn update_config(&self, config: RealtimeConfig)

Update configuration

Source

pub fn config(&self) -> RealtimeConfig

Get current configuration

Source§

impl RealtimeOptimizer

Source

pub fn should_use_speculative(&self, params: &GenerateParams) -> bool

Check if speculative decoding should be used for these generation parameters

Returns true when:

  • Temperature is low (< 0.5) - deterministic generation benefits most
  • Greedy decoding (top_k = 1)
  • Speculative decoding is enabled in config
Source

pub fn get_speculative_config(&self) -> SpeculativeConfig

Get recommended speculative decoding configuration based on current metrics

Trait Implementations§

Source§

impl Default for RealtimeOptimizer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,