pub struct LazyExecutor { /* private fields */ }Expand description
A lazy executor that caches computed tensors by node index.
All tensor operations are delegated to an inner Scirs2Exec; the cache
layer sits above it and avoids redundant work when the same node is
requested multiple times (e.g. during iterative training with a static
graph).
Implementations§
Source§impl LazyExecutor
impl LazyExecutor
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a LazyExecutor with a pre-allocated cache capacity.
Sourcepub fn invalidate_cache(&mut self)
pub fn invalidate_cache(&mut self)
Discard all cached tensors.
Sourcepub fn invalidate_node(&mut self, node_id: usize)
pub fn invalidate_node(&mut self, node_id: usize)
Remove a single node from the cache. The next access to that node will
be a miss and will increment tensors_recomputed.
Sourcepub fn memory_estimate_for(&self, graph: &EinsumGraph) -> usize
pub fn memory_estimate_for(&self, graph: &EinsumGraph) -> usize
Rough total memory estimate for all tensors currently held by graph.
Computed as number_of_nodes * average_cached_tensor_size — a simple
heuristic based on what is already in the cache.
Sourcepub fn cached_count(&self) -> usize
pub fn cached_count(&self) -> usize
Number of tensors currently in the cache.
Source§impl LazyExecutor
impl LazyExecutor
Sourcepub fn get_cached(&mut self, node_id: usize) -> Option<Scirs2Tensor>
pub fn get_cached(&mut self, node_id: usize) -> Option<Scirs2Tensor>
Retrieve a cached tensor for the given node index (if available).
This is the primary entry-point for lazy graph traversal: call this before scheduling a node for execution. On a hit the value is returned without calling any inner operations.
Sourcepub fn put_cached(&mut self, node_id: usize, tensor: Scirs2Tensor)
pub fn put_cached(&mut self, node_id: usize, tensor: Scirs2Tensor)
Store a tensor result for a node. Subsequent calls to
get_cached(node_id) will return this value.
Sourcepub fn inner_mut(&mut self) -> &mut Scirs2Exec
pub fn inner_mut(&mut self) -> &mut Scirs2Exec
Access the inner Scirs2Exec (e.g. to register input tensors).
Trait Implementations§
Source§impl Default for LazyExecutor
impl Default for LazyExecutor
Source§impl TlAutodiff for LazyExecutor
impl TlAutodiff for LazyExecutor
Source§fn forward(&mut self, graph: &EinsumGraph) -> Result<Self::Tensor, Self::Error>
fn forward(&mut self, graph: &EinsumGraph) -> Result<Self::Tensor, Self::Error>
Execute the forward pass, caching every node output.
Node outputs are stored in self.cache keyed by their index in
graph.nodes so that subsequent forward calls on the same (or an
overlapping) graph reuse already-computed tensors.
Source§fn backward(
&mut self,
graph: &EinsumGraph,
loss: &Self::Tensor,
) -> Result<Self::Tape, Self::Error>
fn backward( &mut self, graph: &EinsumGraph, loss: &Self::Tensor, ) -> Result<Self::Tape, Self::Error>
Execute the backward pass, delegating to the inner executor.
type Tape = ForwardTape
Source§impl TlExecutor for LazyExecutor
impl TlExecutor for LazyExecutor
type Tensor = ArrayBase<OwnedRepr<f64>, Dim<IxDynImpl>>
type Error = ExecutorError
Source§fn einsum(
&mut self,
spec: &str,
inputs: &[Self::Tensor],
) -> Result<Self::Tensor, Self::Error>
fn einsum( &mut self, spec: &str, inputs: &[Self::Tensor], ) -> Result<Self::Tensor, Self::Error>
Source§fn elem_op(
&mut self,
op: ElemOp,
x: &Self::Tensor,
) -> Result<Self::Tensor, Self::Error>
fn elem_op( &mut self, op: ElemOp, x: &Self::Tensor, ) -> Result<Self::Tensor, Self::Error>
Auto Trait Implementations§
impl Freeze for LazyExecutor
impl RefUnwindSafe for LazyExecutor
impl Send for LazyExecutor
impl Sync for LazyExecutor
impl Unpin for LazyExecutor
impl UnsafeUnpin for LazyExecutor
impl UnwindSafe for LazyExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more