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>
impl<'owner, 'runtime> CheckpointCallback<'owner, 'runtime>
Sourcepub fn new(
manager: &'owner mut CheckpointManager<'runtime>,
model: &'owner dyn Module,
) -> Self
pub fn new( manager: &'owner mut CheckpointManager<'runtime>, model: &'owner dyn Module, ) -> Self
Borrow the checkpoint manager and model for one training lifecycle.
Sourcepub fn set_save_every(&mut self, steps: u64)
pub fn set_save_every(&mut self, steps: u64)
Add a resumable mid-epoch checkpoint every steps completed steps.
Zero disables interval checkpoints.
Sourcepub fn set_validation_metric(&mut self, metric: ValidationMetric)
pub fn set_validation_metric(&mut self, metric: ValidationMetric)
Select a preceding validation callback’s completed metric.
Sourcepub fn set_committed_monitor(
&mut self,
split: impl Into<String>,
name: impl Into<String>,
)
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.
Sourcepub fn set_run_state_provider(
&mut self,
provider: impl FnMut(TrainingSnapshot) -> Result<RunState> + 'owner,
)
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.
Sourcepub fn set_restore_best(&mut self, restore: bool)
pub fn set_restore_best(&mut self, restore: bool)
Enable or disable restoring the best epoch at training end.
Sourcepub fn set_verbose(&mut self, verbose: bool)
pub fn set_verbose(&mut self, verbose: bool)
Enable or suppress checkpoint status output.
Sourcepub const fn best_epoch(&self) -> u64
pub const fn best_epoch(&self) -> u64
Return the one-based best epoch observed by this callback.
Sourcepub const fn capture_state(&self) -> CheckpointCriteriaState
pub const fn capture_state(&self) -> CheckpointCriteriaState
Capture best-metric and best-epoch criteria for .runstate persistence.
Sourcepub fn restore_state(&mut self, state: CheckpointCriteriaState) -> Result<()>
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.