Skip to main content

InferenceSession

Struct InferenceSession 

Source
pub struct InferenceSession<E: InferenceEngine> { /* private fields */ }
Expand description

One live generation. Constructing it requires a LoadPermit, so a model that has not passed the provenance gate (ADR-006) cannot reach the runtime — the Conformist relationship is enforced in the type system.

Implementations§

Source§

impl<E: InferenceEngine> InferenceSession<E>

Source

pub fn new( id: SessionId, config: SessionConfig, engine: E, permit: LoadPermit, ) -> Self

Source

pub fn phase(&self) -> Phase

Source

pub fn output(&self) -> &[Token]

Source

pub fn kv_len(&self) -> u32

Source

pub fn config(&self) -> &SessionConfig

Source

pub fn permit(&self) -> LoadPermit

The load permit this session was constructed with — evidence the model passed the provenance gate (ADR-006).

Source

pub fn drain_events(&mut self) -> Vec<EventEnvelope>

Take the buffered domain events (a real build would stream these to the Telemetry subscriber).

Source

pub fn load_prompt(&mut self, ports: &Ports, prompt: &[Token]) -> Result<()>

Compress (optional) → prefill → build KV. Valid only from Initialized.

Source

pub fn generate(&mut self, ports: &Ports, max_tokens: u32) -> Result<StopReason>

Run the decode loop until EOS or max_tokens, deriving the rollback policy from the session’s device tier and safety mode (ADR-005/ADR-012).

Source

pub fn generate_with_policy( &mut self, ports: &Ports, max_tokens: u32, policy: RollbackPolicy, ) -> Result<StopReason>

The checkpointed-rollback safety control loop (ADR-012).

Every step preserves the invariant order grammar mask → safety adjust → sample → commit (ADR-005). When a ChunkGuard is wired and the policy enables guarding, the loop additionally captures a checkpoint at each guard-verified-safe boundary, scores recent output every guard_every tokens, and on a hard-threshold breach rolls the KV cache and the committed output back to the last safe checkpoint — banning the offending token through the grammar mask so the resumed decode necessarily diverges. Rollbacks are bounded by max_rollbacks; on exhaustion — or with no checkpoint (e.g. under memory pressure) — the loop fails closed with a deterministic refusal (StopReason::Stopped).

Termination (EOS or max_tokens) is gated behind a mandatory final guard check: the loop scores the trailing chunk before honouring either stop condition, so no completion is ever returned unscored — including one shorter than guard_every or whose unsafe tail ends in EOS. A final check coincident with a cadence boundary is idempotent (re-scoring identical output yields the same verdict).

Source

pub fn reset(&mut self)

Clear KV/output for a fresh conversation (volatile memory only).

Source

pub fn consult_relay( &mut self, ports: &Ports, query: &[Token], ) -> Result<Vec<Token>>

Consult the opt-in LAN relay. Hard-fails with EdgeError::AirGapViolation unless hybrid_mode is enabled AND a relay is wired (ADR-004).

Auto Trait Implementations§

§

impl<E> Freeze for InferenceSession<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for InferenceSession<E>
where E: RefUnwindSafe,

§

impl<E> Send for InferenceSession<E>
where E: Send,

§

impl<E> Sync for InferenceSession<E>
where E: Sync,

§

impl<E> Unpin for InferenceSession<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for InferenceSession<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for InferenceSession<E>
where E: UnwindSafe,

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, 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, 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.