Skip to main content

ReplicatedTextSession

Struct ReplicatedTextSession 

Source
pub struct ReplicatedTextSession<A, B, M, D = DirectReplicatedTextExecution>{ /* private fields */ }
Expand description

Complete backend-neutral replicated-text session.

Implementations§

Source§

impl<A, B, M, D> ReplicatedTextSession<A, B, M, D>

Source

pub const fn materialization_report( &self, ) -> Option<&WeightMaterializationReport>

Returns the aggregate report captured by the neutral construction driver after exact materialization preparation completed.

Source

pub const fn execution_strategy(&self) -> &D

Borrows the statically paired unit-execution strategy for generic telemetry.

Source

pub fn forward( &mut self, tokens: &B::Tensor, mask: Option<&B::Tensor>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs one direct forward and returns the complete architecture output.

Source

pub fn forward_with_observer<O>( &mut self, tokens: &B::Tensor, mask: Option<&B::Tensor>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, observer: &mut O, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs one direct forward with unit and final-logits observation and intervention.

Source

pub fn prefill( &mut self, tokens: &B::Tensor, mask: Option<&B::Tensor>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs prompt processing and selects the architecture-declared text output.

Source

pub fn prefill_with_observer<O>( &mut self, tokens: &B::Tensor, mask: Option<&B::Tensor>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, observer: &mut O, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs observed prompt processing and selects the declared text output.

Source

pub fn prefill_prediction_target( &mut self, tokens: &B::Tensor, mask: Option<&B::Tensor>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(B::Tensor, B::Tensor), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs ordinary target prefill and returns its architecture-owned prediction capture.

Both tensors come from the same transaction and are returned only after canonical output publication succeeds. Missing capture rolls state back exactly like a failed output projection.

Source

pub fn prefill_input_prediction_target<'a>( &mut self, input: A::Input<'a>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(B::Tensor, B::Tensor), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs architecture-prepared target prefill and returns its exact additive capture.

Source

pub fn prefill_input<'a>( &mut self, input: A::Input<'a>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs prompt processing from an architecture-prepared input.

Additive ingress drivers use this entry after architecture admission has coupled native tensors to their semantic identity. Output selection, rollback, observation, state publication, and completion remain owned by this session.

Source

pub fn prefill_input_with_capture<'a, O, C, F>( &mut self, input: A::Input<'a>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, observer: &mut O, capture: F, ) -> Result<(B::Tensor, C), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>
where O: ActivationObserver<B::Tensor, A::Error> + ?Sized, F: FnOnce(&A::ForwardContext) -> Result<C, A::Error>,

Runs one ordinary non-partitioned target pass and atomically retains an additive capture.

The capture is derived from the same forward context and observed unit outputs as the canonical target logits. Capture failure restores target state before either value is published. Partitioned capture requires an admitted multi-tensor publication contract and therefore remains unavailable through this local-only seam.

Source

pub fn prefill_input_with_cache_identity<'a>( &mut self, input: A::Input<'a>, identity: PreparedInputCacheIdentity, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs composite prompt processing and commits its cache-relevant input identity only after successful state publication and exact completion.

Source

pub fn prefill_input_with_observer_and_cache_identity<'a, O>( &mut self, input: A::Input<'a>, identity: PreparedInputCacheIdentity, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, observer: &mut O, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>
where O: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs observed prompt processing and commits its exact prepared-input identity on success.

Source

pub fn prefill_input_with_observer<'a, O>( &mut self, input: A::Input<'a>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, observer: &mut O, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>
where O: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs observed prompt processing from an architecture-prepared input.

Source

pub fn decode_input<'a>( &mut self, input: A::Input<'a>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs one decode step from an architecture-prepared input.

Source

pub fn decode_input_with_capture<'a, O, C, F>( &mut self, input: A::Input<'a>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, observer: &mut O, capture: F, ) -> Result<(B::Tensor, C), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>
where O: ActivationObserver<B::Tensor, A::Error> + ?Sized, F: FnOnce(&A::ForwardContext) -> Result<C, A::Error>,

Runs one ordinary non-partitioned decode pass and atomically retains an additive capture.

Source

pub fn decode_input_with_observer<'a, O>( &mut self, input: A::Input<'a>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, observer: &mut O, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>
where O: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs one observed decode step from an architecture-prepared input.

Source

pub fn decode( &mut self, tokens: &B::Tensor, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs one decode step and selects the architecture-declared text output.

Source

pub fn decode_prediction_target( &mut self, tokens: &B::Tensor, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(B::Tensor, B::Tensor), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs ordinary target decode and returns its architecture-owned prediction capture.

Source

pub fn decode_input_prediction_target<'a>( &mut self, input: A::Input<'a>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(B::Tensor, B::Tensor), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs architecture-prepared target decode and returns its exact additive capture.

Source

pub fn decode_with_observer<O>( &mut self, tokens: &B::Tensor, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, observer: &mut O, ) -> Result<B::Tensor, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Runs one observed decode step and selects the declared text output.

Source

pub const fn successful_state_restoration_generation(&self) -> Option<u64>

Snapshots successful state-restoration evidence for one execution call.

Snapshots of this counter prove only a successful neutral state restore, never completion of backend work. Overflow permanently disables the witness; checkpoint restoration never rewinds it.

Source

pub fn checkpoint( &mut self, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<M::StateCheckpoint, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Captures all mutable state for a later transactional rollback.

Source

pub fn exchange_prediction_target_state( &mut self, replacement: &mut M::State, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Exchanges the canonical target state with one prediction-lane state after all-rank proof.

The returned state is the previously installed target state. A speculative adapter uses this operation before and after a target pass so lane-local caches never become a second owner of target execution. Validation or agreement failure leaves the canonical state untouched.

Source

pub fn recover_prediction_target_state_after_failure( &mut self, replacement: &mut M::State, ) -> Result<(), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Restores local target-state ownership after a failed prediction-lane pass.

This is a one-shot ownership repair, not a second distributed operation: the preceding successful exchange already proved both states, and a failed pass may poison the selected communication authority before the ordinary agreement-backed exchange can run again. The caller must still return the original distributed failure; this swap does not clear a poison, publish state, or make the session reusable.

Source

pub fn prepare_prediction_target_state( &mut self, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<M::State, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Forks one prediction-lane target state from the exact canonical state.

This preserves any prompt-cache restoration already installed in the ordinary target. Every rank realizes, restores, and validates its local fork before any caller may retain the lane; failure leaves the canonical state untouched.

Source

pub fn apply_prediction_target_operation<O>( &mut self, operation: O, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<O::Output, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>
where O: PredictionTargetOperation<A, B, M::State>,

Runs one typed prediction-only operation against the neutral target modules and lane state.

The operation is checkpointed and agreed independently of ordinary output publication. Any local or remote failure restores the installed lane state before returning.

Source

pub fn checkpoint_complete( &mut self, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<ReplicatedTextSessionCheckpoint<M::StateCheckpoint>, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Captures mutable state together with the committed composite prompt identity.

Source

pub fn checkpoint_distributed( &mut self, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<DistributedStateCheckpoint<M::StateCheckpoint>, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Captures a state-only checkpoint only when every partition rank succeeds.

Source

pub fn checkpoint_complete_distributed( &mut self, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<DistributedSessionCheckpoint<M::StateCheckpoint>, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Captures state and session commit metadata only on all-rank success.

Source

pub fn rollback( &mut self, checkpoint: M::StateCheckpoint, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Restores every mutable component from a session checkpoint.

Source

pub fn rollback_complete( &mut self, checkpoint: ReplicatedTextSessionCheckpoint<M::StateCheckpoint>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Restores every mutable component and its committed composite prompt identity atomically.

Source

pub fn rollback_distributed( &mut self, checkpoint: DistributedStateCheckpoint<M::StateCheckpoint>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Restores a state-only partition checkpoint after all ranks prepare it provisionally.

Source

pub fn rollback_complete_distributed( &mut self, checkpoint: DistributedSessionCheckpoint<M::StateCheckpoint>, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Restores partition state and session metadata after all ranks prepare it provisionally.

Source

pub fn reset_distributed( &mut self, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Replaces every rank-local state only after all ranks realize a provisional replacement.

Source

pub fn reset( &mut self, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<(), ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Replaces mutable state with a newly realized selected state.

Source

pub fn load_prompt_cache( &mut self, directory: &Path, expected: &PromptCacheDescriptor, prefix_token_ids: &[u32], context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<PromptCacheManifest, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Validates and replaces state from a reusable prompt cache.

Source

pub fn load_prompt_cache_for_input( &mut self, directory: &Path, expected: &PromptCacheDescriptor, prefix_token_ids: &[u32], input_identity: PreparedInputCacheIdentity, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<PromptCacheManifest, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Opens a prompt cache only when its content identity matches the admitted prepared input.

Source

pub fn load_prompt_cache_distributed( &mut self, directory: &Path, expected: &PromptCacheDescriptor, prefix_token_ids: &[u32], context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<Option<PromptCacheManifest>, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Atomically replaces partition state from rank-local cache shards.

Stateful ranks load into provisional state while stateless ranks still participate in both selected-session agreements. No live state or distributed-commit metadata changes unless every rank validates its preflight and provisional shard.

Source

pub fn load_prompt_cache_for_input_distributed( &mut self, directory: &Path, expected: &PromptCacheDescriptor, prefix_token_ids: &[u32], input_identity: PreparedInputCacheIdentity, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<Option<PromptCacheManifest>, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Atomically loads partition state after all ranks validate one prepared input.

Source

pub fn save_prompt_cache( &mut self, destination: &Path, descriptor: PromptCacheDescriptor, prefix_token_ids: &[u32], options: &PromptCacheOptions, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<PromptCacheManifest, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Validates identity and persists the current state through native bytes.

Source

pub fn save_prompt_cache_for_input( &mut self, destination: &Path, descriptor: PromptCacheDescriptor, prefix_token_ids: &[u32], options: &PromptCacheOptions, input_identity: &PreparedInputCacheIdentity, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<PromptCacheManifest, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Persists state only when the descriptor names the successfully committed prepared input.

Source

pub const fn committed_prompt_input_identity( &self, ) -> Option<&PreparedInputCacheIdentity>

Returns the prepared-input identity associated with the currently committed prompt state.

Source

pub fn report( &self, ) -> Result<ReplicatedTextSessionReport<M::ExecutionReport, M::StateReport>, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Returns one coherent execution and state residency report.

Source§

impl<A, B, M, D> ReplicatedTextSession<A, B, M, D>

Source

pub fn save_prompt_cache_distributed( &mut self, destination: &Path, descriptor: PromptCacheDescriptor, prefix_token_ids: &[u32], options: &PromptCacheOptions, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<Option<PromptCacheManifest>, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Atomically publishes rank-local cache shards after all ranks prepare them.

Source

pub fn save_prompt_cache_for_input_distributed( &mut self, destination: &Path, descriptor: PromptCacheDescriptor, prefix_token_ids: &[u32], options: &PromptCacheOptions, input_identity: &PreparedInputCacheIdentity, context: &<<B as NeuralBackend>::Tensor as Tensor>::Context, ) -> Result<Option<PromptCacheManifest>, ReplicatedTextSessionError<A::Error, M::PolicyError, M::Error>>

Atomically publishes shards only for the globally committed prepared input.

Auto Trait Implementations§

§

impl<A, B, M, D> Freeze for ReplicatedTextSession<A, B, M, D>

§

impl<A, B, M, D> RefUnwindSafe for ReplicatedTextSession<A, B, M, D>

§

impl<A, B, M, D> Send for ReplicatedTextSession<A, B, M, D>

§

impl<A, B, M, D> Sync for ReplicatedTextSession<A, B, M, D>

§

impl<A, B, M, D> Unpin for ReplicatedTextSession<A, B, M, D>

§

impl<A, B, M, D> UnsafeUnpin for ReplicatedTextSession<A, B, M, D>

§

impl<A, B, M, D> UnwindSafe for ReplicatedTextSession<A, B, M, D>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.