Skip to main content

TensorCheckpointManagerV2

Struct TensorCheckpointManagerV2 

Source
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: CheckpointPolicy

Policy governing eviction and storage format.

§stats: CheckpointStats

Running statistics.

§next_version: u64

Version that will be assigned to the next call to save.

Implementations§

Source§

impl TensorCheckpointManagerV2

Source

pub fn new(policy: CheckpointPolicy) -> Self

Create a new, empty manager with the given policy.

Source

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).

Source

pub fn get(&self, version: u64) -> Option<&CheckpointEntry>

Look up a checkpoint by exact version number.

Source

pub fn latest(&self) -> Option<&CheckpointEntry>

Return the checkpoint with the highest version number, or None when the manager is empty.

Source

pub fn versions(&self) -> Vec<u64>

Return all retained version numbers in ascending order.

Source

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.

Source

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).

Source

pub fn stats(&self) -> &CheckpointStats

Return a reference to the current aggregate statistics.

Trait Implementations§

Source§

impl Debug for TensorCheckpointManagerV2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more