pub struct TextGenerationDriver<'a, B: TextGenerationBackend> { /* private fields */ }Expand description
Exclusive execution owner for detached ordinary continuations.
The same machine drives the existing borrowed iterators. This owner allows a
facade to retain separate continuations while serially switching independently
saved native model states. It does not switch those native states itself: the
facade must compose the backend’s validated state-exchange mechanism. Native
objects need not implement Send or Sync.
Implementations§
Source§impl<'a, B: TextGenerationBackend> TextGenerationDriver<'a, B>
impl<'a, B: TextGenerationBackend> TextGenerationDriver<'a, B>
Sourcepub fn new(runtime: &'a mut ModelRuntime<B>) -> Self
pub fn new(runtime: &'a mut ModelRuntime<B>) -> Self
Exclusively borrows the runtime while this driver exists. A continuation retained after driver drop can be cleaned up but cannot attach to another driver, even one borrowing the same runtime.
Sourcepub fn runtime(&self) -> &ModelRuntime<B>
pub fn runtime(&self) -> &ModelRuntime<B>
Read-only access for exact loaded-session discovery and native estimates.
Sourcepub fn start<C: TokenFilterController>(
&mut self,
prompt: B::Prompt,
config: TextGenerationConfig,
controller: C,
) -> Result<TextGenerationContinuation<B, C>, ControlledTextGenerationError<B::Error, C::Error>>
pub fn start<C: TokenFilterController>( &mut self, prompt: B::Prompt, config: TextGenerationConfig, controller: C, ) -> Result<TextGenerationContinuation<B, C>, ControlledTextGenerationError<B::Error, C::Error>>
Starts the existing ordinary machine with an opaque prepared prompt. Neither model execution nor token sampling occurs here.
Sourcepub fn quiescent<'d, 's, C: TokenFilterController>(
&'d mut self,
state: &'s mut TextGenerationContinuation<B, C>,
) -> Result<TextContinuationBoundary<'d, 's, B, C>, TextContinuationError<B::Error, C::Error>>
pub fn quiescent<'d, 's, C: TokenFilterController>( &'d mut self, state: &'s mut TextGenerationContinuation<B, C>, ) -> Result<TextContinuationBoundary<'d, 's, B, C>, TextContinuationError<B::Error, C::Error>>
Lends the completed ordinary state to portable snapshot composition. All native work and the preceding bounded record batch must be settled. The guard holds both mutable borrows, preventing advancement while native copies, compatibility validation and host-state installation are composed.
Sourcepub fn advance<C: TokenFilterController>(
&mut self,
state: &mut TextGenerationContinuation<B, C>,
) -> Result<Option<ControlledToken<B::Token>>, TextContinuationError<B::Error, C::Error>>
pub fn advance<C: TokenFilterController>( &mut self, state: &mut TextGenerationContinuation<B, C>, ) -> Result<Option<ControlledToken<B::Token>>, TextContinuationError<B::Error, C::Error>>
Advances at most one constraint-committed canonical token using the
ordinary sampler and pending input. Call take_completed_step before
advancing again or composing a pause/snapshot boundary.
Sourcepub fn take_completed_step<C: TokenFilterController>(
&mut self,
state: &mut TextGenerationContinuation<B, C>,
) -> Result<Option<CapturedStep>, TextContinuationError<B::Error, C::Error>>
pub fn take_completed_step<C: TokenFilterController>( &mut self, state: &mut TextGenerationContinuation<B, C>, ) -> Result<Option<CapturedStep>, TextContinuationError<B::Error, C::Error>>
Settles exact native completion and moves out the single bounded record batch. It remains available after failure for attributed error evidence; draining never turns a failed continuation into a resumable one.
Sourcepub fn enable_capture<C: TokenFilterController>(
&mut self,
state: &mut TextGenerationContinuation<B, C>,
plan: AdmittedCapturePlan,
) -> Result<(), CaptureError>
pub fn enable_capture<C: TokenFilterController>( &mut self, state: &mut TextGenerationContinuation<B, C>, plan: AdmittedCapturePlan, ) -> Result<(), CaptureError>
Installs observations before the first model prediction.
Sourcepub fn enable_interventions<C: TokenFilterController>(
&mut self,
state: &mut TextGenerationContinuation<B, C>,
capture: AdmittedCapturePlan,
plan: AdmittedInterventionPlan,
) -> Result<(), CaptureError>
pub fn enable_interventions<C: TokenFilterController>( &mut self, state: &mut TextGenerationContinuation<B, C>, capture: AdmittedCapturePlan, plan: AdmittedInterventionPlan, ) -> Result<(), CaptureError>
Installs immutable observation/intervention admissions before execution.
Source§impl<B: NativeTextStateBackend> TextGenerationDriver<'_, B>
impl<B: NativeTextStateBackend> TextGenerationDriver<'_, B>
Sourcepub fn estimate_native_state<C: TokenFilterController>(
&self,
state: &TextGenerationContinuation<B, C>,
saved: Option<&B::NativeTextState>,
) -> Result<Option<SnapshotEstimate>, TextContinuationError<B::Error, C::Error>>
pub fn estimate_native_state<C: TokenFilterController>( &self, state: &TextGenerationContinuation<B, C>, saved: Option<&B::NativeTextState>, ) -> Result<Option<SnapshotEstimate>, TextContinuationError<B::Error, C::Error>>
Estimates installed or saved native state at a completed continuation boundary. Portable composition adds all host-state estimates and reserves resources before calling either copying operation below.
Sourcepub fn capture_native_state<C: TokenFilterController>(
&mut self,
state: &TextGenerationContinuation<B, C>,
) -> Result<B::NativeTextState, TextContinuationError<B::Error, C::Error>>
pub fn capture_native_state<C: TokenFilterController>( &mut self, state: &TextGenerationContinuation<B, C>, ) -> Result<B::NativeTextState, TextContinuationError<B::Error, C::Error>>
Copies the installed model state through its existing completion owner. Caller must first reserve the complete snapshot’s resource estimate.
Sourcepub fn copy_native_state<C: TokenFilterController>(
&mut self,
state: &TextGenerationContinuation<B, C>,
saved: &B::NativeTextState,
) -> Result<B::NativeTextState, TextContinuationError<B::Error, C::Error>>
pub fn copy_native_state<C: TokenFilterController>( &mut self, state: &TextGenerationContinuation<B, C>, saved: &B::NativeTextState, ) -> Result<B::NativeTextState, TextContinuationError<B::Error, C::Error>>
Independently copies a compatible saved slot after resource reservation. The currently installed continuation remains unchanged.
Sourcepub fn exchange_native_state<C: TokenFilterController>(
&mut self,
state: &TextGenerationContinuation<B, C>,
slot: &mut B::NativeTextState,
) -> Result<(), TextContinuationError<B::Error, C::Error>>
pub fn exchange_native_state<C: TokenFilterController>( &mut self, state: &TextGenerationContinuation<B, C>, slot: &mut B::NativeTextState, ) -> Result<(), TextContinuationError<B::Error, C::Error>>
Exchanges the installed native state with a previously copied slot. The facade pairs this with the corresponding detached continuation and semantic state before advancing again. No token or sampler advances here.