Skip to main content

LayerwiseRuntime

Struct LayerwiseRuntime 

Source
pub struct LayerwiseRuntime<A, B, S, P>
where B: SubmissionBackend<Executor = <<B as NeuralBackend>::Tensor as Tensor>::Context>, S: RuntimeState<B>, A: LayeredArchitecture<B, S>, P: LayerwisePolicy<B, A::Unit>,
{ /* private fields */ }
Expand description

Bounded-unit runtime invoking the same architecture lifecycle as resident execution.

Implementations§

Source§

impl<A, B, S, P> LayerwiseRuntime<A, B, S, P>
where B: SubmissionBackend<Executor = <<B as NeuralBackend>::Tensor as Tensor>::Context>, S: RuntimeState<B>, A: LayeredArchitecture<B, S>, P: LayerwisePolicy<B, A::Unit>, A::Error: Display, P::Error: Display,

Source

pub const fn new(architecture: A, policy: P) -> Self

Creates a layerwise runtime from concrete architecture, state, and policy.

Source

pub const fn new_policy_first(policy: P, architecture: A) -> Self

Creates a layerwise runtime while evaluating the policy before moving the architecture. This is useful when policy realization needs to borrow the architecture’s canonical unit constructor first.

Source

pub const fn architecture(&self) -> &A

Borrows the concrete architecture instance.

Source

pub fn architecture_mut(&mut self) -> &mut A

Mutably borrows the concrete architecture instance.

Source

pub const fn policy(&self) -> &P

Borrows the concrete execution policy for cold-path diagnostics.

Source

pub fn policy_mut(&mut self) -> &mut P

Mutably borrows the concrete execution policy.

Source

pub fn forward<'a>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>

Runs one complete prefill or decode pass with exact unit release points.

Source

pub fn forward_with_context_hook<'a, H>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, hook: H, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where H: FnMut(usize, usize, &mut A::ForwardContext) -> Result<(), A::Error>,

Runs one pass and exposes mutable architecture context after each unit.

Source

pub fn forward_with_unit_executor<'a, E>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, execute: E, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>
where E: FnMut(&mut A, usize, usize, &mut A::Unit, &B::Tensor, &mut S, &mut A::ForwardContext, &<B::Tensor as Tensor>::Context) -> Result<B::Tensor, A::Error>,

Runs one pass with a statically dispatched architecture-unit executor.

Composition can use this cold API to inject routed expert execution or observation while the runtime retains graph traversal, residency, and exact completion ownership.

Source

pub fn forward_with_observer<'a, Observer>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, observer: &mut Observer, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>
where Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs the production sequential traversal with stable unit-boundary observation.

Source

pub fn forward_with_observer_and_context<'a, Observer>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, observer: &mut Observer, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs observed sequential traversal and retains architecture forward resources for the caller’s completion boundary.

Source

pub fn forward_with_unit_executor_and_observer<'a, E, Observer>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, execute: E, observer: &mut Observer, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>
where E: FnMut(&mut A, usize, usize, &mut A::Unit, &B::Tensor, &mut S, &mut A::ForwardContext, &<B::Tensor as Tensor>::Context) -> Result<B::Tensor, A::Error>, Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs a custom production unit executor with stable boundary observation.

Source

pub fn forward_with_unit_executor_and_observer_and_context<'a, E, Observer>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, execute: E, observer: &mut Observer, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where E: FnMut(&mut A, usize, usize, &mut A::Unit, &B::Tensor, &mut S, &mut A::ForwardContext, &<B::Tensor as Tensor>::Context) -> Result<B::Tensor, A::Error>, Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs a custom observed executor while returning its retained forward resources.

Source

pub fn forward_with_provider_and_observer<'a, Provider, Observer>( &mut self, input: A::Input<'a>, state: &mut S, pass: ExpertPass, provider: &mut Provider, context: &<B::Tensor as Tensor>::Context, observer: &mut Observer, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>
where B: GroupedNeuralBackend, A: RoutedLayeredArchitecture<B, S>, A::Error: Display, Provider: RoutedExpertProvider<B>, Provider::Error: Display, Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs canonical provider-backed unit execution with unit-boundary and routed-expert observation.

Observation wraps RoutedLayeredArchitecture::forward_unit_with_provider instead of replacing it. Architecture-owned validation, state lookup, shape handling, routing, and provider dispatch therefore remain shared with ordinary execution.

Source

pub fn forward_with_provider_and_observer_and_context<'a, Provider, Observer>( &mut self, input: A::Input<'a>, state: &mut S, pass: ExpertPass, provider: &mut Provider, context: &<B::Tensor as Tensor>::Context, observer: &mut Observer, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where B: GroupedNeuralBackend, A: RoutedLayeredArchitecture<B, S>, A::Error: Display, Provider: RoutedExpertProvider<B>, Provider::Error: Display, Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs provider-backed observed execution while retaining architecture forward resources.

Source

pub fn forward_with_inferred_provider_and_observer<'a, Provider, Observer>( &mut self, input: A::Input<'a>, state: &mut S, provider: &mut Provider, context: &<B::Tensor as Tensor>::Context, observer: &mut Observer, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>
where B: GroupedNeuralBackend, A: RoutedLayeredArchitecture<B, S>, A::Error: Display, Provider: RoutedExpertProvider<B>, Provider::Error: Display, Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs provider-backed observed execution with architecture-owned pass classification.

Source

pub fn forward_with_inferred_provider_and_observer_and_context<'a, Provider, Observer>( &mut self, input: A::Input<'a>, state: &mut S, provider: &mut Provider, context: &<B::Tensor as Tensor>::Context, observer: &mut Observer, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where B: GroupedNeuralBackend, A: RoutedLayeredArchitecture<B, S>, A::Error: Display, Provider: RoutedExpertProvider<B>, Provider::Error: Display, Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs provider-backed observed execution with architecture-owned pass classification while retaining forward resources.

Source

pub fn forward_with_unit_executor_and_context_hook<'a, E, H>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, execute: E, hook: H, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where E: FnMut(&mut A, usize, usize, &mut A::Unit, &B::Tensor, &mut S, &mut A::ForwardContext, &<B::Tensor as Tensor>::Context) -> Result<B::Tensor, A::Error>, H: FnMut(usize, usize, &mut A::ForwardContext) -> Result<(), A::Error>,

Runs one pass with both a custom unit executor and post-unit context hook.

Source

pub fn forward_with_unit_executor_and_activation_hook<'a, E, H>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, execute: E, hook: H, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where E: FnMut(&mut A, usize, usize, &mut A::Unit, &B::Tensor, &mut S, &mut A::ForwardContext, &<B::Tensor as Tensor>::Context) -> Result<B::Tensor, A::Error>, H: FnMut(usize, usize, &B::Tensor, &mut A::ForwardContext) -> Result<(), A::Error>,

Runs one pass with a custom unit executor and exposes each post-unit activation together with the mutable architecture context.

The activation is the ordinary output of the execution unit. Target state taps and inspection therefore observe the production forward without requiring a second family-specific model path.

Source

pub fn forward_with_traversal_hook<'a, H>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, hook: &mut H, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>

Runs one bounded pass through a statically dispatched traversal hook.

Source

pub fn forward_with_unit_executor_and_traversal_hook<'a, E, H>( &mut self, input: A::Input<'a>, state: &mut S, context: &<B::Tensor as Tensor>::Context, execute: E, hook: &mut H, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where E: FnMut(&mut A, usize, usize, &mut A::Unit, &B::Tensor, &mut S, &mut A::ForwardContext, &<B::Tensor as Tensor>::Context) -> Result<B::Tensor, A::Error>, H: LayeredTraversalHook<B, A::ForwardContext, A::Error> + ?Sized,

Runs one bounded pass with custom unit execution and a shared traversal hook.

Source

pub fn forward_parallel<'a>( &mut self, input: A::Input<'a>, state: &mut S, parallel: &B::ParallelContext, context: &<B::Tensor as Tensor>::Context, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>

Runs one complete rank-local pass through the neutral parallel lifecycle.

Source

pub fn forward_parallel_with_context_hook<'a, H>( &mut self, input: A::Input<'a>, state: &mut S, parallel: &B::ParallelContext, context: &<B::Tensor as Tensor>::Context, hook: H, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where A: ParallelLayeredArchitecture<B, S>, H: FnMut(usize, usize, &mut A::ForwardContext) -> Result<(), A::Error>,

Runs one rank-local pass and exposes mutable context after each unit.

Source

pub fn forward_parallel_with_unit_executor<'a, E>( &mut self, input: A::Input<'a>, state: &mut S, parallel: &B::ParallelContext, context: &<B::Tensor as Tensor>::Context, execute: E, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>
where A: ParallelLayeredArchitecture<B, S>, E: FnMut(&mut A, usize, usize, &mut A::Unit, &B::Tensor, &mut S, &mut A::ForwardContext, &B::ParallelContext, &<B::Tensor as Tensor>::Context) -> Result<B::Tensor, A::Error>,

Runs one parallel pass with a custom statically dispatched unit executor.

Source

pub fn forward_parallel_with_observer<'a, Observer>( &mut self, input: A::Input<'a>, state: &mut S, parallel: &B::ParallelContext, context: &<B::Tensor as Tensor>::Context, observer: &mut Observer, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>
where A: ParallelLayeredArchitecture<B, S>, Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs the production parallel traversal with stable unit-boundary observation.

Source

pub fn forward_parallel_with_unit_executor_and_observer<'a, E, Observer>( &mut self, input: A::Input<'a>, state: &mut S, parallel: &B::ParallelContext, context: &<B::Tensor as Tensor>::Context, execute: E, observer: &mut Observer, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>
where A: ParallelLayeredArchitecture<B, S>, E: FnMut(&mut A, usize, usize, &mut A::Unit, &B::Tensor, &mut S, &mut A::ForwardContext, &B::ParallelContext, &<B::Tensor as Tensor>::Context) -> Result<B::Tensor, A::Error>, Observer: ActivationObserver<B::Tensor, A::Error> + ?Sized,

Runs a custom parallel unit executor with stable boundary observation.

Source

pub fn forward_parallel_with_provider_and_observer<'a, Provider, Observer>( &mut self, input: A::Input<'a>, state: &mut S, pass: ExpertPass, provider: &mut Provider, parallel: &B::ParallelContext, context: &<B::Tensor as Tensor>::Context, observer: &mut Observer, ) -> Result<B::Tensor, LayerwiseRuntimeError<A::Error, P::Error>>

Runs provider-backed parallel execution with boundary and routing observation.

Source

pub fn forward_parallel_with_unit_executor_and_context_hook<'a, E, H>( &mut self, input: A::Input<'a>, state: &mut S, parallel: &B::ParallelContext, context: &<B::Tensor as Tensor>::Context, execute: E, hook: H, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>
where A: ParallelLayeredArchitecture<B, S>, E: FnMut(&mut A, usize, usize, &mut A::Unit, &B::Tensor, &mut S, &mut A::ForwardContext, &B::ParallelContext, &<B::Tensor as Tensor>::Context) -> Result<B::Tensor, A::Error>, H: FnMut(usize, usize, &mut A::ForwardContext) -> Result<(), A::Error>,

Runs one parallel pass with custom unit execution and a post-unit hook.

Source

pub fn forward_parallel_with_traversal_hook<'a, H>( &mut self, input: A::Input<'a>, state: &mut S, parallel: &B::ParallelContext, context: &<B::Tensor as Tensor>::Context, hook: &mut H, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>

Runs one parallel pass through a statically dispatched traversal hook.

Source

pub fn forward_parallel_with_unit_executor_and_traversal_hook<'a, E, H>( &mut self, input: A::Input<'a>, state: &mut S, parallel: &B::ParallelContext, context: &<B::Tensor as Tensor>::Context, execute: E, hook: &mut H, ) -> Result<(B::Tensor, A::ForwardContext), LayerwiseRuntimeError<A::Error, P::Error>>

Runs one parallel pass with custom unit execution and a shared traversal hook.

Auto Trait Implementations§

§

impl<A, B, S, P> Freeze for LayerwiseRuntime<A, B, S, P>

§

impl<A, B, S, P> RefUnwindSafe for LayerwiseRuntime<A, B, S, P>

§

impl<A, B, S, P> Send for LayerwiseRuntime<A, B, S, P>

§

impl<A, B, S, P> Sync for LayerwiseRuntime<A, B, S, P>

§

impl<A, B, S, P> Unpin for LayerwiseRuntime<A, B, S, P>

§

impl<A, B, S, P> UnsafeUnpin for LayerwiseRuntime<A, B, S, P>

§

impl<A, B, S, P> UnwindSafe for LayerwiseRuntime<A, B, S, P>

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.