Skip to main content

CheckpointManager

Struct CheckpointManager 

Source
pub struct CheckpointManager<'runtime> { /* private fields */ }
Expand description

Stateful checkpoint selection and bounded incremental-retention policy.

Implementations§

Source§

impl<'runtime> CheckpointManager<'runtime>

Source

pub fn new( runtime: &'runtime Runtime, config: CheckpointManagerConfig, ) -> Result<Self>

Construct a manager around the one execution owner.

§Errors

Returns an error when a filename component or metric name is invalid.

Source

pub fn model_directory(&self) -> PathBuf

Return the directory containing master and incremental checkpoints.

Source

pub fn incremental_directory(&self) -> PathBuf

Return the incremental checkpoint directory.

Source

pub fn master_path(&self) -> PathBuf

Return the master/best checkpoint path.

Source

pub fn is_better(&self, metric: f64) -> bool

Return whether metric improves the currently retained best value.

Source

pub const fn best_metric(&self) -> f64

Return the best metric admitted in this manager session.

Source

pub fn restore_best_metric(&mut self, best_metric: f64) -> Result<()>

Restore historical best-metric selection state from an exact-resume checkpoint companion.

Rejects NaN and an infinite sentinel whose sign disagrees with config.lower_is_better.

§Errors

Returns an error when best_metric is NaN or carries the opposite infinity sentinel for this manager’s improvement direction.

Source

pub fn metric_name(&self) -> &str

Return the configured metric name.

Source

pub fn maybe_save( &mut self, model: &dyn Module, optimizer: &dyn CheckpointOptimizer, step: u64, metric: f64, force: bool, ) -> Result<bool>

Save an incremental checkpoint and update the master file on improvement.

When force is false, a non-improving metric performs no write. When it is true, the incremental file is still written but the master changes only on improvement.

§Errors

Returns an error for non-finite metrics, optimizer/progress mismatch, serialization, directory creation, rotation, or filesystem failure.

Source

pub fn maybe_save_with_run_state( &mut self, model: &dyn Module, optimizer: &dyn CheckpointOptimizer, step: u64, metric: f64, force: bool, run_state: &RunState, ) -> Result<bool>

maybe_save additionally committing exact-resume run state beside the incremental checkpoint; see Self::save_incremental_with_run_state.

§Errors

Returns the errors of Self::maybe_save plus run-state commit failure.

Source

pub fn save_incremental( &mut self, model: &dyn Module, optimizer: &dyn CheckpointOptimizer, step: u64, metric: f64, metric_name: Option<&str>, ) -> Result<PathBuf>

Save a resumable incremental checkpoint without changing best selection.

§Errors

Returns an error for invalid metric/progress state, serialization, directory creation, rotation, or filesystem failure.

Source

pub fn save_incremental_with_run_state( &mut self, model: &dyn Module, optimizer: &dyn CheckpointOptimizer, step: u64, metric: f64, metric_name: Option<&str>, run_state: Option<&RunState>, ) -> Result<PathBuf>

Save a resumable incremental checkpoint together with its exact-resume run state. The .oam artifact writes first and the run state then commits atomically beside it as a same-stem .runstate sibling; rotation removes the pair together, so a retained checkpoint never outlives its training-loop position. A checkpoint whose sibling is absent or corrupt fails the resume contract clearly at load time rather than guessing a partial position.

§Errors

Returns the errors of Self::save_incremental plus run-state serialization and commit failures.

Source

pub fn load_best_into( &self, model: &dyn Module, optimizer: &mut dyn CheckpointOptimizer, ) -> Result<()>

Restore the master/best checkpoint into existing owners.

§Errors

Returns the native load, validation, allocation, or filesystem error.

Source

pub fn load_latest_into( &self, model: &dyn Module, optimizer: &mut dyn CheckpointOptimizer, ) -> Result<u64>

Restore the highest-step incremental checkpoint into existing owners.

The manager prefers files recorded in this session and otherwise scans its incremental directory using the same strict filename grammar it writes. The returned value is the exact completed step restored into the optimizer.

§Errors

Returns an error when no checkpoint exists or loading fails.

Source

pub fn resume_latest_into( &mut self, model: &dyn Module, optimizer: &mut dyn CheckpointOptimizer, ) -> Result<u64>

Restore the latest incremental state and recover historical best-metric selection from the master checkpoint when it exists.

This joins model, optimizer, completed step, and best-checkpoint policy at one restart boundary. A master file written for another metric or ordering policy is rejected instead of silently resetting selection history.

§Errors

Returns the same errors as Self::load_latest_into, plus malformed or incompatible master progress metadata.

Source

pub fn load_latest_run_state(&self) -> Result<RunState>

Load the run state committed beside the latest incremental checkpoint.

§Errors

Returns an error when no incremental checkpoint exists, its sibling run state is absent, or the state fails its format contract.

Auto Trait Implementations§

§

impl<'runtime> !RefUnwindSafe for CheckpointManager<'runtime>

§

impl<'runtime> !Send for CheckpointManager<'runtime>

§

impl<'runtime> !Sync for CheckpointManager<'runtime>

§

impl<'runtime> !UnwindSafe for CheckpointManager<'runtime>

§

impl<'runtime> Forget for CheckpointManager<'runtime>

§

impl<'runtime> Freeze for CheckpointManager<'runtime>
where &'runtime Runtime: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<SavedCheckpoint>: Freeze,

§

impl<'runtime> Move for CheckpointManager<'runtime>

§

impl<'runtime> Unpin for CheckpointManager<'runtime>
where &'runtime Runtime: Unpin, *const u8 is !null: Unpin,

§

impl<'runtime> UnsafeUnpin for CheckpointManager<'runtime>
where &'runtime Runtime: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<SavedCheckpoint>: UnsafeUnpin,

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.