pub struct ContinuousBatchEngine { /* private fields */ }Expand description
Continuous batching inference engine.
Wraps an Arc<EngineInner> so it can be cloned and shared freely.
Multiple concurrent infer() / infer_stream() calls are safe —
an internal iteration_lock serializes engine steps while allowing
all pending requests to be processed in each iteration’s batch.
Implementations§
Source§impl ContinuousBatchEngine
impl ContinuousBatchEngine
pub fn new( config: EngineConfig, scheduler: Arc<ContinuousBatchScheduler>, tokenizer: Arc<dyn Tokenizer + Send + Sync>, sampler: Arc<dyn Sampler + Send + Sync>, kv_cache: Arc<dyn KvCacheManager + Send + Sync>, model_executor: Arc<dyn ModelExecutor + Send + Sync>, tensor_factory: Arc<dyn TensorFactory>, ) -> Result<Self>
Sourcepub fn new_with_speculation(
config: EngineConfig,
scheduler: Arc<ContinuousBatchScheduler>,
tokenizer: Arc<dyn Tokenizer + Send + Sync>,
sampler: Arc<dyn Sampler + Send + Sync>,
kv_cache: Arc<dyn KvCacheManager + Send + Sync>,
model_executor: Arc<dyn ModelExecutor + Send + Sync>,
tensor_factory: Arc<dyn TensorFactory>,
draft_executor: Option<Arc<dyn ModelExecutor + Send + Sync>>,
spec_config: Option<SpeculativeDecodingConfig>,
) -> Result<Self>
pub fn new_with_speculation( config: EngineConfig, scheduler: Arc<ContinuousBatchScheduler>, tokenizer: Arc<dyn Tokenizer + Send + Sync>, sampler: Arc<dyn Sampler + Send + Sync>, kv_cache: Arc<dyn KvCacheManager + Send + Sync>, model_executor: Arc<dyn ModelExecutor + Send + Sync>, tensor_factory: Arc<dyn TensorFactory>, draft_executor: Option<Arc<dyn ModelExecutor + Send + Sync>>, spec_config: Option<SpeculativeDecodingConfig>, ) -> Result<Self>
Build an engine with optional speculative decoding. Pass both the draft executor AND the config together — either both or neither.
Sourcepub fn new_with_speculation_and_recurrent_state_manager(
config: EngineConfig,
scheduler: Arc<ContinuousBatchScheduler>,
tokenizer: Arc<dyn Tokenizer + Send + Sync>,
sampler: Arc<dyn Sampler + Send + Sync>,
kv_cache: Arc<dyn KvCacheManager + Send + Sync>,
model_executor: Arc<dyn ModelExecutor + Send + Sync>,
tensor_factory: Arc<dyn TensorFactory>,
draft_executor: Option<Arc<dyn ModelExecutor + Send + Sync>>,
spec_config: Option<SpeculativeDecodingConfig>,
recurrent_state_manager: Option<Arc<dyn RecurrentStateManager + Send + Sync>>,
) -> Result<Self>
pub fn new_with_speculation_and_recurrent_state_manager( config: EngineConfig, scheduler: Arc<ContinuousBatchScheduler>, tokenizer: Arc<dyn Tokenizer + Send + Sync>, sampler: Arc<dyn Sampler + Send + Sync>, kv_cache: Arc<dyn KvCacheManager + Send + Sync>, model_executor: Arc<dyn ModelExecutor + Send + Sync>, tensor_factory: Arc<dyn TensorFactory>, draft_executor: Option<Arc<dyn ModelExecutor + Send + Sync>>, spec_config: Option<SpeculativeDecodingConfig>, recurrent_state_manager: Option<Arc<dyn RecurrentStateManager + Send + Sync>>, ) -> Result<Self>
Build an engine with optional speculative decoding and an optional recurrent-state manager for state-space / hybrid models.
Sourcepub fn new_plan_runtime(
config: EngineConfig,
scheduler: Arc<ContinuousBatchScheduler>,
tokenizer: Arc<dyn Tokenizer + Send + Sync>,
sampler: Arc<dyn Sampler + Send + Sync>,
model_executor: Arc<dyn ModelExecutor + Send + Sync>,
tensor_factory: Arc<dyn TensorFactory>,
) -> Result<Self>
pub fn new_plan_runtime( config: EngineConfig, scheduler: Arc<ContinuousBatchScheduler>, tokenizer: Arc<dyn Tokenizer + Send + Sync>, sampler: Arc<dyn Sampler + Send + Sync>, model_executor: Arc<dyn ModelExecutor + Send + Sync>, tensor_factory: Arc<dyn TensorFactory>, ) -> Result<Self>
Build an engine bound to the shared plan runtime, which is the sole owner of request-lifetime KV, recurrent state, and backing capacity. The model executor adapts that runtime but does not own a second resource manager; no legacy engine manager is created or retained.
Sourcepub fn prefix_cache_hits(&self) -> u64
pub fn prefix_cache_hits(&self) -> u64
Hit count since engine construction (prefix cache). Exposed for tests + /metrics endpoint; monotonic, Relaxed-ordered.
Sourcepub fn prefix_cache_stats(&self) -> PrefixCacheStats
pub fn prefix_cache_stats(&self) -> PrefixCacheStats
Snapshot of prefix cache stats (hits/misses/evictions/active entries).
Sourcepub fn start_loop(&self) -> JoinHandle<()> ⓘ
pub fn start_loop(&self) -> JoinHandle<()> ⓘ
Start a background iteration loop. Returns a JoinHandle that
runs until shutdown() is called. When a background loop is
active, infer() / infer_stream() simply submit and wait.
Trait Implementations§
Source§impl Debug for ContinuousBatchEngine
impl Debug for ContinuousBatchEngine
Source§impl InferenceEngine for ContinuousBatchEngine
impl InferenceEngine for ContinuousBatchEngine
Source§fn status<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = EngineStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn status<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = EngineStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn config(&self) -> &EngineConfig
fn config(&self) -> &EngineConfig
Source§fn metrics(&self) -> EngineMetrics
fn metrics(&self) -> EngineMetrics
Source§fn cache_metrics_snapshot(&self) -> Option<Value>
fn cache_metrics_snapshot(&self) -> Option<Value>
Source§fn admission_snapshot(&self) -> Result<Option<ExecutorAdmissionSnapshot>>
fn admission_snapshot(&self) -> Result<Option<ExecutorAdmissionSnapshot>>
Source§fn lora_metrics_snapshot(&self) -> Option<Value>
fn lora_metrics_snapshot(&self) -> Option<Value>
Source§fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health_check<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = HealthStatus> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§impl LlmInferenceEngine for ContinuousBatchEngine
impl LlmInferenceEngine for ContinuousBatchEngine
Source§fn infer<'life0, 'async_trait>(
&'life0 self,
request: InferenceRequest,
) -> Pin<Box<dyn Future<Output = Result<InferenceResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn infer<'life0, 'async_trait>(
&'life0 self,
request: InferenceRequest,
) -> Pin<Box<dyn Future<Output = Result<InferenceResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn infer_stream<'life0, 'async_trait>(
&'life0 self,
request: InferenceRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn infer_stream<'life0, 'async_trait>(
&'life0 self,
request: InferenceRequest,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<StreamChunk>> + Send>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for ContinuousBatchEngine
impl !UnwindSafe for ContinuousBatchEngine
impl Freeze for ContinuousBatchEngine
impl Send for ContinuousBatchEngine
impl Sync for ContinuousBatchEngine
impl Unpin for ContinuousBatchEngine
impl UnsafeUnpin for ContinuousBatchEngine
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
impl<T> ErasedDestructor for Twhere
T: 'static,
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 more