pub struct TensorCheckpointManagerV2 {
pub checkpoints: Vec<CheckpointEntry>,
pub policy: CheckpointPolicy,
pub stats: CheckpointStats,
pub next_version: u64,
}Expand description
Versioned tensor checkpoint manager with delta compression.
§Example
use ipfrs_tensorlogic::checkpoint_v2::{CheckpointPolicy, TensorCheckpointManagerV2};
let mut mgr = TensorCheckpointManagerV2::new(CheckpointPolicy::default());
let v1 = mgr.save(vec!["w1".into(), "b1".into()], 2_000_000, 1_000, vec![]);
let v2 = mgr.save(vec!["w1".into(), "b1".into(), "w2".into()], 2_000_000, 2_000, vec!["best".into()]);
assert_eq!(mgr.latest().expect("example: should succeed in docs").version, v2);Fields§
§checkpoints: Vec<CheckpointEntry>All retained checkpoints, kept sorted by ascending version.
policy: CheckpointPolicyPolicy governing eviction and storage format.
stats: CheckpointStatsRunning statistics.
next_version: u64Version that will be assigned to the next call to save.
Implementations§
Source§impl TensorCheckpointManagerV2
impl TensorCheckpointManagerV2
Sourcepub fn new(policy: CheckpointPolicy) -> Self
pub fn new(policy: CheckpointPolicy) -> Self
Create a new, empty manager with the given policy.
Sourcepub fn save(
&mut self,
tensor_names: Vec<String>,
full_bytes: u64,
timestamp_secs: u64,
tags: Vec<String>,
) -> u64
pub fn save( &mut self, tensor_names: Vec<String>, full_bytes: u64, timestamp_secs: u64, tags: Vec<String>, ) -> u64
Persist a new checkpoint and return its assigned version number.
§Storage format selection
A full checkpoint is stored when any of the following is true:
- There are no prior checkpoints.
version % keep_every_n == 0.full_bytes <= delta_threshold_bytes.
Otherwise a delta checkpoint is stored referencing the previous
version. Its changed_tensors field lists tensors absent from the
previous checkpoint (i.e. newly added tensors).
§Eviction
Before inserting, if the manager is already at max_checkpoints
capacity, the oldest entry with no tags is evicted. If every entry
is tagged the new checkpoint is still pushed (the list grows beyond the
configured maximum).
Sourcepub fn get(&self, version: u64) -> Option<&CheckpointEntry>
pub fn get(&self, version: u64) -> Option<&CheckpointEntry>
Look up a checkpoint by exact version number.
Sourcepub fn latest(&self) -> Option<&CheckpointEntry>
pub fn latest(&self) -> Option<&CheckpointEntry>
Return the checkpoint with the highest version number, or None when
the manager is empty.
Sourcepub fn compute_delta(&self, v1: u64, v2: u64) -> Option<CheckpointDelta>
pub fn compute_delta(&self, v1: u64, v2: u64) -> Option<CheckpointDelta>
Compute a CheckpointDelta between two existing versions.
v1— the from version (must exist).v2— the to version (must exist, should be> v1).
Returns None if either version is not found.
Changed tensors are those present in v2 but not in v1 (newly added).
delta_bytes is estimated as full_bytes(v2) * 0.3.
Sourcepub fn tag_checkpoint(&mut self, version: u64, tag: String) -> bool
pub fn tag_checkpoint(&mut self, version: u64, tag: String) -> bool
Attach tag to the checkpoint at version.
Returns true if the version exists and the tag was added, false
otherwise (including when version does not exist).
Sourcepub fn stats(&self) -> &CheckpointStats
pub fn stats(&self) -> &CheckpointStats
Return a reference to the current aggregate statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TensorCheckpointManagerV2
impl RefUnwindSafe for TensorCheckpointManagerV2
impl Send for TensorCheckpointManagerV2
impl Sync for TensorCheckpointManagerV2
impl Unpin for TensorCheckpointManagerV2
impl UnsafeUnpin for TensorCheckpointManagerV2
impl UnwindSafe for TensorCheckpointManagerV2
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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