CheckpointManagerBase<T, TInput, TOutput>

Base Classes · AiDotNet.CheckpointManagement

Base class for checkpoint management implementations.

Implements: ICheckpointManager<T, TInput, TOutput>

Known derived types: CheckpointManager<T, TInput, TOutput>

How It Works

For Beginners: This abstract base class provides common functionality for checkpoint management systems. It handles storage path management, security validation, and JSON serialization while leaving the specific storage implementation to derived classes.

Key features:

  • Path security validation to prevent traversal attacks
  • Consistent JSON serialization settings
  • Thread-safe checkpoint tracking
  • Auto-checkpointing configuration support

Methods

Method Summary
AutoCheckpointState GetAutoCheckpointState() Gets the current auto-checkpointing state.
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 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.