pub struct CheckpointedNetwork<R: Recomputable<Input = Vec<f32>, Output = Vec<f32>>> { /* private fields */ }Expand description
A sequential network where every layer boundary is checkpointed.
During the forward pass, each segment’s output is fed as input to the next
segment, but only the inputs are retained — outputs are discarded. On
demand (e.g., during the backward pass) any segment’s output can be
recovered by calling checkpoint.recompute().
This type is generic over any Recomputable whose Input and Output are
both Vec<f32>, making it suitable for chain-of-linear-segments networks.
Implementations§
Source§impl<R: Recomputable<Input = Vec<f32>, Output = Vec<f32>>> CheckpointedNetwork<R>
impl<R: Recomputable<Input = Vec<f32>, Output = Vec<f32>>> CheckpointedNetwork<R>
Sourcepub fn new(segments: Vec<Checkpoint<R>>) -> Self
pub fn new(segments: Vec<Checkpoint<R>>) -> Self
Construct the network from pre-built checkpoints.
Sourcepub fn forward(&self, _input: &[f32]) -> Vec<f32>
pub fn forward(&self, _input: &[f32]) -> Vec<f32>
Execute the full forward pass, returning the output of the final segment.
Internally each segment is run in order; the checkpointed inputs are already stored so we merely recompute each in sequence.
Returns an error if segments is empty.
Sourcepub fn memory_bytes(&self) -> usize
pub fn memory_bytes(&self) -> usize
Total bytes used by all checkpointed inputs.
Sourcepub fn full_memory_bytes(&self) -> usize
pub fn full_memory_bytes(&self) -> usize
Hypothetical memory if we stored every segment’s output instead of its input.
For a typical expanding network (out_dim > in_dim) this will be larger
than memory_bytes, demonstrating the checkpointing advantage.
Sourcepub fn memory_savings(&self) -> f32
pub fn memory_savings(&self) -> f32
Fraction of memory saved relative to storing all outputs.
Returns a value in [0, 1). A result of 0.0 means no savings (input
== output size everywhere); values near 1.0 mean the full-storage cost
would be much higher.
Auto Trait Implementations§
impl<R> Freeze for CheckpointedNetwork<R>
impl<R> RefUnwindSafe for CheckpointedNetwork<R>where
R: RefUnwindSafe,
impl<R> Send for CheckpointedNetwork<R>
impl<R> Sync for CheckpointedNetwork<R>
impl<R> Unpin for CheckpointedNetwork<R>where
R: Unpin,
impl<R> UnsafeUnpin for CheckpointedNetwork<R>
impl<R> UnwindSafe for CheckpointedNetwork<R>where
R: UnwindSafe,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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