pub struct CheckpointManager<'runtime> { /* private fields */ }Expand description
Stateful checkpoint selection and bounded incremental-retention policy.
Implementations§
Source§impl<'runtime> CheckpointManager<'runtime>
impl<'runtime> CheckpointManager<'runtime>
Sourcepub fn new(
runtime: &'runtime Runtime,
config: CheckpointManagerConfig,
) -> Result<Self>
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.
Sourcepub fn model_directory(&self) -> PathBuf
pub fn model_directory(&self) -> PathBuf
Return the directory containing master and incremental checkpoints.
Sourcepub fn incremental_directory(&self) -> PathBuf
pub fn incremental_directory(&self) -> PathBuf
Return the incremental checkpoint directory.
Sourcepub fn master_path(&self) -> PathBuf
pub fn master_path(&self) -> PathBuf
Return the master/best checkpoint path.
Sourcepub fn is_better(&self, metric: f64) -> bool
pub fn is_better(&self, metric: f64) -> bool
Return whether metric improves the currently retained best value.
Sourcepub const fn best_metric(&self) -> f64
pub const fn best_metric(&self) -> f64
Return the best metric admitted in this manager session.
Sourcepub fn restore_best_metric(&mut self, best_metric: f64) -> Result<()>
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.
Sourcepub fn metric_name(&self) -> &str
pub fn metric_name(&self) -> &str
Return the configured metric name.
Sourcepub fn maybe_save(
&mut self,
model: &dyn Module,
optimizer: &dyn CheckpointOptimizer,
step: u64,
metric: f64,
force: bool,
) -> Result<bool>
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.
Sourcepub 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>
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.
Sourcepub fn save_incremental(
&mut self,
model: &dyn Module,
optimizer: &dyn CheckpointOptimizer,
step: u64,
metric: f64,
metric_name: Option<&str>,
) -> Result<PathBuf>
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.
Sourcepub 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>
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.
Sourcepub fn load_best_into(
&self,
model: &dyn Module,
optimizer: &mut dyn CheckpointOptimizer,
) -> Result<()>
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.
Sourcepub fn load_latest_into(
&self,
model: &dyn Module,
optimizer: &mut dyn CheckpointOptimizer,
) -> Result<u64>
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.
Sourcepub fn resume_latest_into(
&mut self,
model: &dyn Module,
optimizer: &mut dyn CheckpointOptimizer,
) -> Result<u64>
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.
Sourcepub fn load_latest_run_state(&self) -> Result<RunState>
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.