ICheckpointManager<T, TInput, TOutput>
Interfaces · AiDotNet.Interfaces
Defines the contract for checkpoint management systems that save and restore training state.
Known implementations: CheckpointManagerBase<T, TInput, TOutput>
How It Works
A checkpoint manager handles saving and restoring the complete state of model training, allowing you to pause and resume training, recover from failures, and track model evolution.
For Beginners: Think of checkpoints like save points in a video game. They let you:
- Save your progress so you can come back later
- Go back to an earlier point if something goes wrong
- Keep the best version you’ve found so far
Checkpoints typically save:
- Model parameters (weights and biases)
- Optimizer state (momentum, learning rate schedule, etc.)
- Training metadata (epoch number, step count)
- Performance metrics
Why checkpoint management matters:
- Training can be interrupted (crashes, time limits)
- You want to keep the best model even if later training makes it worse
- Long training runs need progress saved periodically
- Enables experimentation with different training strategies from same point
Methods
| Method | Summary |
|---|---|
Checkpoint<T, TInput, TOutput> LoadBestCheckpoint(string metricName, MetricOptimizationDirection direction) |
Loads the checkpoint with the best metric value. |
Checkpoint<T, TInput, TOutput> LoadCheckpoint(string checkpointId) |
Loads a checkpoint and restores the training state. |
Checkpoint<T, TInput, TOutput> LoadLatestCheckpoint() |
Loads the most recent checkpoint. |
List<CheckpointMetadata<T>> ListCheckpoints(string sortBy, bool descending) |
Lists all available checkpoints. |
bool ShouldAutoSaveCheckpoint(int currentStep, double? metricValue, bool shouldMinimize) |
Determines whether an automatic checkpoint should be saved based on current configuration. |
int CleanupKeepBest(string metricName, int keepBest, MetricOptimizationDirection direction) |
Deletes checkpoints except the best N according to a metric. |
int CleanupOldCheckpoints(int keepLast) |
Deletes old checkpoints, keeping only a specified number of the most recent ones. |
string GetCheckpointDirectory() |
Gets the storage path for checkpoints. |
string SaveCheckpoint(IModel<TInput, TOutput, TMetadata> model, IOptimizer<T, TInput, TOutput> optimizer, int epoch, int step, Dictionary<string, T> metrics, Dictionary<string, object> metadata) |
Saves a checkpoint of the current training state. |
string TryAutoSaveCheckpoint(IModel<TInput, TOutput, TMetadata> model, IOptimizer<T, TInput, TOutput> optimizer, int epoch, int step, Dictionary<string, T> metrics, double? metricValue, bool shouldMinimize, Dictionary<string, object> metadata) |
Attempts to save a checkpoint automatically based on configured auto-checkpoint settings. |
void ConfigureAutoCheckpointing(AutoCheckpointingOptions options) |
Sets up automatic checkpointing during training using an AutoCheckpointingOptions object, including optional monotonic wall-clock interval saving and explicit metric optimization direction. |
void ConfigureAutoCheckpointing(int saveFrequency, int keepLast, bool saveOnImprovement, string metricName) |
Sets up automatic checkpointing during training. |
void DeleteCheckpoint(string checkpointId) |
Deletes a specific checkpoint. |
void UpdateAutoSaveState(int step, double? metricValue, bool shouldMinimize) |
Updates the auto-save state after a checkpoint is saved. |