Skip to main content

CheckpointCallback

Struct CheckpointCallback 

Source
pub struct CheckpointCallback<'owner, 'runtime> { /* private fields */ }
Expand description

Epoch, interval, best-model, and restore-best checkpoint policy.

Implementations§

Source§

impl<'owner, 'runtime> CheckpointCallback<'owner, 'runtime>

Source

pub fn new( manager: &'owner mut CheckpointManager<'runtime>, model: &'owner dyn Module, ) -> Self

Borrow the checkpoint manager and model for one training lifecycle.

Source

pub fn set_save_every(&mut self, steps: u64)

Add a resumable mid-epoch checkpoint every steps completed steps.

Zero disables interval checkpoints.

Source

pub fn set_validation_metric(&mut self, metric: ValidationMetric)

Select a preceding validation callback’s completed metric.

Source

pub fn set_committed_monitor( &mut self, split: impl Into<String>, name: impl Into<String>, )

Monitor the latest value committed to the shared history bus under split/name for best-epoch selection.

The committing callback must register before the checkpoint callback so the value exists at the boundary; a missing committed value reads as not-a-number and never improves the best epoch.

Source

pub fn set_run_state_provider( &mut self, provider: impl FnMut(TrainingSnapshot) -> Result<RunState> + 'owner, )

Supply a .runstate provider committed atomically beside every mid-epoch and epoch-boundary incremental checkpoint.

When the returned RunState leaves checkpoint as None, the callback populates it with the post-comparison CheckpointCriteriaState before writing the companion file.

Source

pub fn set_restore_best(&mut self, restore: bool)

Enable or disable restoring the best epoch at training end.

Source

pub fn set_verbose(&mut self, verbose: bool)

Enable or suppress checkpoint status output.

Source

pub const fn best_epoch(&self) -> u64

Return the one-based best epoch observed by this callback.

Source

pub const fn capture_state(&self) -> CheckpointCriteriaState

Capture best-metric and best-epoch criteria for .runstate persistence.

Source

pub fn restore_state(&mut self, state: CheckpointCriteriaState) -> Result<()>

Restore best-metric and best-epoch criteria from a .runstate companion.

§Errors

Returns an error when best_epoch is Some(0), best_epoch is set alongside a non-finite best_metric, or best_metric disagrees with the manager’s improvement direction.

Trait Implementations§

Auto Trait Implementations§

§

impl<'owner, 'runtime> !RefUnwindSafe for CheckpointCallback<'owner, 'runtime>

§

impl<'owner, 'runtime> !Send for CheckpointCallback<'owner, 'runtime>

§

impl<'owner, 'runtime> !Sync for CheckpointCallback<'owner, 'runtime>

§

impl<'owner, 'runtime> !UnwindSafe for CheckpointCallback<'owner, 'runtime>

§

impl<'owner, 'runtime> Forget for CheckpointCallback<'owner, 'runtime>

§

impl<'owner, 'runtime> Freeze for CheckpointCallback<'owner, 'runtime>
where &'owner mut CheckpointManager<'runtime>: Freeze, &'owner dyn Module: Freeze, *const RcInner<str> is !null: Freeze, PhantomData<RcInner<str>>: Freeze, *const RcInner<Cell<Option<f64>>> is !null: Freeze, PhantomData<RcInner<Cell<Option<f64>>>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const dyn FnMut(TrainingSnapshot) -> Result<RunState, Error> + 'owner is !null: Freeze, PhantomData<dyn FnMut(TrainingSnapshot) -> Result<RunState, Error> + 'owner>: Freeze,

§

impl<'owner, 'runtime> Move for CheckpointCallback<'owner, 'runtime>

§

impl<'owner, 'runtime> Unpin for CheckpointCallback<'owner, 'runtime>
where &'owner mut CheckpointManager<'runtime>: Unpin, &'owner dyn Module: Unpin, Rc<str>: Unpin, Rc<Cell<Option<f64>>>: Unpin, *const u8 is !null: Unpin, Box<dyn FnMut(TrainingSnapshot) -> Result<RunState, Error> + 'owner>: Unpin,

§

impl<'owner, 'runtime> UnsafeUnpin for CheckpointCallback<'owner, 'runtime>

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.