pub trait TextGenerationBackend: BackendProvider {
type Prompt;
type Token: TokenOutput<Error = Self::Error>;
type TextGenerationState;
type TextCompletion: Completion<Error = Self::Error>;
Show 13 methods
// Required methods
fn start_text_generation(
backend: &Self,
config: TextGenerationConfig,
) -> Result<Self::TextGenerationState, Self::Error>;
fn prepare_text_prompt(
backend: &Self,
prompt_token_ids: Vec<u32>,
) -> Result<Self::Prompt, Self::Error>;
fn submit_text_prefill(
runtime: &mut ModelRuntime<Self>,
prompt: Self::Prompt,
filter: &TokenFilter,
state: &mut Self::TextGenerationState,
) -> Result<Submission<Self::Token, Self::TextCompletion>, Self::Error>;
fn submit_text_decode(
runtime: &mut ModelRuntime<Self>,
token: Self::Token,
filter: &TokenFilter,
state: &mut Self::TextGenerationState,
) -> Result<Submission<Self::Token, Self::TextCompletion>, Self::Error>;
// Provided methods
fn text_execution_control_support(
_runtime: &ModelRuntime<Self>,
) -> ControlSupport { ... }
fn text_sampling_control_support(
_runtime: &ModelRuntime<Self>,
) -> ControlSupport { ... }
fn intervention_discovery(
_runtime: &ModelRuntime<Self>,
) -> Result<InterventionDiscovery, CaptureError> { ... }
fn validate_text_interventions(
runtime: &ModelRuntime<Self>,
capture: &AdmittedCapturePlan,
plan: &AdmittedInterventionPlan,
) -> Result<(), CaptureError> { ... }
fn configure_text_interventions(
runtime: &ModelRuntime<Self>,
state: &mut Self::TextGenerationState,
capture: AdmittedCapturePlan,
plan: AdmittedInterventionPlan,
) -> Result<(), CaptureError> { ... }
fn capture_discovery(
_runtime: &ModelRuntime<Self>,
) -> Result<CaptureDiscovery, CaptureError> { ... }
fn configure_text_capture(
_runtime: &ModelRuntime<Self>,
_state: &mut Self::TextGenerationState,
plan: AdmittedCapturePlan,
) -> Result<(), CaptureError> { ... }
fn validate_text_capture(
_runtime: &ModelRuntime<Self>,
plan: &AdmittedCapturePlan,
) -> Result<(), CaptureError> { ... }
fn take_text_capture(
_state: &mut Self::TextGenerationState,
) -> Option<CapturedStep> { ... }
}Expand description
High-level text-generation extension implemented once per backend.
The contract deliberately combines model execution and sampling. Core does not see logits or ask a backend to implement tensor primitives. The token, sampling state, cache state, and exact completion remain backend-owned.
Required Associated Types§
Sourcetype Token: TokenOutput<Error = Self::Error>
type Token: TokenOutput<Error = Self::Error>
Backend-owned generated token handle.
Sourcetype TextGenerationState
type TextGenerationState
Backend-owned sampler and randomness state for one sequence.
Sourcetype TextCompletion: Completion<Error = Self::Error>
type TextCompletion: Completion<Error = Self::Error>
Exact completion retaining model execution and token sampling.
Required Methods§
Sourcefn start_text_generation(
backend: &Self,
config: TextGenerationConfig,
) -> Result<Self::TextGenerationState, Self::Error>
fn start_text_generation( backend: &Self, config: TextGenerationConfig, ) -> Result<Self::TextGenerationState, Self::Error>
Creates backend sampling state for one sequence.
Sourcefn prepare_text_prompt(
backend: &Self,
prompt_token_ids: Vec<u32>,
) -> Result<Self::Prompt, Self::Error>
fn prepare_text_prompt( backend: &Self, prompt_token_ids: Vec<u32>, ) -> Result<Self::Prompt, Self::Error>
Converts portable tokenizer ids into a backend-owned text prompt.
Sourcefn submit_text_prefill(
runtime: &mut ModelRuntime<Self>,
prompt: Self::Prompt,
filter: &TokenFilter,
state: &mut Self::TextGenerationState,
) -> Result<Submission<Self::Token, Self::TextCompletion>, Self::Error>
fn submit_text_prefill( runtime: &mut ModelRuntime<Self>, prompt: Self::Prompt, filter: &TokenFilter, state: &mut Self::TextGenerationState, ) -> Result<Submission<Self::Token, Self::TextCompletion>, Self::Error>
Submits prompt prefill followed by sampling one token.
Sourcefn submit_text_decode(
runtime: &mut ModelRuntime<Self>,
token: Self::Token,
filter: &TokenFilter,
state: &mut Self::TextGenerationState,
) -> Result<Submission<Self::Token, Self::TextCompletion>, Self::Error>
fn submit_text_decode( runtime: &mut ModelRuntime<Self>, token: Self::Token, filter: &TokenFilter, state: &mut Self::TextGenerationState, ) -> Result<Submission<Self::Token, Self::TextCompletion>, Self::Error>
Submits cached decode from the preceding token and samples its successor.
Provided Methods§
Sourcefn text_execution_control_support(
_runtime: &ModelRuntime<Self>,
) -> ControlSupport
fn text_execution_control_support( _runtime: &ModelRuntime<Self>, ) -> ControlSupport
Exact support for serial, completed-token control on this loaded session. Backends opt in only for verified ordinary single-sequence execution. Snapshot mechanisms and complete facade-state support are separate facts.
Sourcefn text_sampling_control_support(
_runtime: &ModelRuntime<Self>,
) -> ControlSupport
fn text_sampling_control_support( _runtime: &ModelRuntime<Self>, ) -> ControlSupport
Exact support for prospective temperature changes and explicit reseeding. The runtime validates policy; the adapter supplies atomic native changes.
Sourcefn intervention_discovery(
_runtime: &ModelRuntime<Self>,
) -> Result<InterventionDiscovery, CaptureError>
fn intervention_discovery( _runtime: &ModelRuntime<Self>, ) -> Result<InterventionDiscovery, CaptureError>
Returns genuine mutable points for this exact loaded session.
Sourcefn validate_text_interventions(
runtime: &ModelRuntime<Self>,
capture: &AdmittedCapturePlan,
plan: &AdmittedInterventionPlan,
) -> Result<(), CaptureError>
fn validate_text_interventions( runtime: &ModelRuntime<Self>, capture: &AdmittedCapturePlan, plan: &AdmittedInterventionPlan, ) -> Result<(), CaptureError>
Checks both plans without submitting work or changing model/sampler state.
Sourcefn configure_text_interventions(
runtime: &ModelRuntime<Self>,
state: &mut Self::TextGenerationState,
capture: AdmittedCapturePlan,
plan: AdmittedInterventionPlan,
) -> Result<(), CaptureError>
fn configure_text_interventions( runtime: &ModelRuntime<Self>, state: &mut Self::TextGenerationState, capture: AdmittedCapturePlan, plan: AdmittedInterventionPlan, ) -> Result<(), CaptureError>
Installs immutable plans before the first submission. Diagnostics and evidence must share capture accounting and ordinary completion ownership.
Sourcefn capture_discovery(
_runtime: &ModelRuntime<Self>,
) -> Result<CaptureDiscovery, CaptureError>
fn capture_discovery( _runtime: &ModelRuntime<Self>, ) -> Result<CaptureDiscovery, CaptureError>
Returns observation facts retained from this session’s admitted preparation.
Sourcefn configure_text_capture(
_runtime: &ModelRuntime<Self>,
_state: &mut Self::TextGenerationState,
plan: AdmittedCapturePlan,
) -> Result<(), CaptureError>
fn configure_text_capture( _runtime: &ModelRuntime<Self>, _state: &mut Self::TextGenerationState, plan: AdmittedCapturePlan, ) -> Result<(), CaptureError>
Enables an immutable capture plan before the first submission. Implementations must validate it against this session and reject unsupported combinations.
Sourcefn validate_text_capture(
_runtime: &ModelRuntime<Self>,
plan: &AdmittedCapturePlan,
) -> Result<(), CaptureError>
fn validate_text_capture( _runtime: &ModelRuntime<Self>, plan: &AdmittedCapturePlan, ) -> Result<(), CaptureError>
Validates known capture costs and execution combinations without submitting native work or advancing sampler state.
Sourcefn take_text_capture(
_state: &mut Self::TextGenerationState,
) -> Option<CapturedStep>
fn take_text_capture( _state: &mut Self::TextGenerationState, ) -> Option<CapturedStep>
Moves out at most one completed capture step. No implementation may queue unconsumed steps without a separately admitted finite buffering contract.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".